Subversion Repositories Scribus

Rev

Rev 20694 | Rev 21026 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
16546 jghali 1
/*
2
For general Scribus (>=1.3.2) copyright and licensing information please refer
3
to the COPYING file provided with the program. Following this notice may exist
4
a copyright and/or license notice that predates the release of Scribus 1.3.2
5
for which a new license (GPL+exception) is in place.
6
*/
7
 
8
#include "propertywidget_pathtext.h"
9
 
19080 craig 10
#include "scribus.h"
16546 jghali 11
#include "scribusdoc.h"
17388 jghali 12
#include "selection.h"
16546 jghali 13
#include "units.h"
14
 
19080 craig 15
 
16546 jghali 16
PropertyWidget_PathText::PropertyWidget_PathText(QWidget* parent) : QFrame(parent)
17
{
17388 jghali 18
        m_ScMW = 0;
19
        m_doc  = 0;
20732 jghali 20
        m_item = 0;
21
        m_unitRatio = 1.0;
22
        m_unitIndex = 0;
17388 jghali 23
 
16546 jghali 24
        setupUi(this);
25
 
26
        setFrameStyle(QFrame::Box | QFrame::Plain);
27
        setLineWidth(1);
28
        layout()->setAlignment( Qt::AlignTop );
29
 
30
        startOffset->setValues(0, 30000, 2, 0);
31
        startOffset->setSingleStep(10);
32
 
33
        distFromCurve->setValues(-300, 300, 2, 0);
34
        distFromCurve->setSingleStep(10);
35
 
36
        languageChange();
37
}
38
 
17388 jghali 39
void PropertyWidget_PathText::setMainWindow(ScribusMainWindow* mw)
40
{
41
        m_ScMW = mw;
42
 
43
        connect(m_ScMW, SIGNAL(UpdateRequest(int)), this  , SLOT(handleUpdateRequest(int)));
44
}
45
 
16546 jghali 46
void PropertyWidget_PathText::setDoc(ScribusDoc *d)
47
{
48
        if(d == (ScribusDoc*) m_doc)
49
                return;
50
 
17388 jghali 51
        if (m_doc)
52
        {
53
                disconnect(m_doc->m_Selection, SIGNAL(selectionChanged()), this, SLOT(handleSelectionChanged()));
54
                disconnect(m_doc             , SIGNAL(docChanged())      , this, SLOT(handleSelectionChanged()));
55
        }
56
 
16546 jghali 57
        m_doc  = d;
17388 jghali 58
        m_item = NULL;
16546 jghali 59
 
60
        if (m_doc.isNull())
17388 jghali 61
        {
62
                disconnectSignals();
16546 jghali 63
                return;
17388 jghali 64
        }
16546 jghali 65
 
66
        m_unitRatio   = m_doc->unitRatio();
67
        m_unitIndex   = m_doc->unitIndex();
68
 
69
        startOffset->setMaximum( 30000 );
70
        startOffset->setMinimum( 0 );
71
        startOffset->setSingleStep(10);
72
        distFromCurve->setMaximum( 300 );
73
        distFromCurve->setMinimum( -300 );
74
        distFromCurve->setSingleStep(10);
17388 jghali 75
 
76
        connect(m_doc->m_Selection, SIGNAL(selectionChanged()), this, SLOT(handleSelectionChanged()));
77
        connect(m_doc             , SIGNAL(docChanged())      , this, SLOT(handleSelectionChanged()));
16546 jghali 78
}
79
 
17388 jghali 80
void PropertyWidget_PathText::setCurrentItem(PageItem *item)
16546 jghali 81
{
17388 jghali 82
        if (!m_ScMW || m_ScMW->scriptIsRunning())
83
                return;
84
        //CB We shouldnt really need to process this if our item is the same one
85
        //maybe we do if the item has been changed by scripter.. but that should probably
86
        //set some status if so.
87
        //FIXME: This wont work until when a canvas deselect happens, m_item must be NULL.
88
        //if (m_item == i)
89
        //      return;
90
 
91
        if (item && m_doc.isNull())
92
                setDoc(item->doc());
93
 
94
        m_item = item;
95
 
96
        disconnectSignals();
97
        configureWidgets();
98
 
99
        if (m_item)
16546 jghali 100
        {
17388 jghali 101
                if (m_item->asPathText())
102
                {
103
                        pathTextType->setCurrentIndex(m_item->textPathType);
104
                        flippedPathText->setChecked(m_item->textPathFlipped);
105
                        showCurveCheckBox->setChecked(m_item->PoShow);
106
                        distFromCurve->setValue(m_item->BaseOffs * -1);
107
                        startOffset->setValue(m_item->textToFrameDistLeft());
108
                }
109
                connectSignals();
16546 jghali 110
        }
111
}
112
 
17388 jghali 113
void PropertyWidget_PathText::connectSignals()
16546 jghali 114
{
17388 jghali 115
        connect(showCurveCheckBox, SIGNAL(clicked())     , this, SLOT(handlePathLine()));
116
        connect(pathTextType     , SIGNAL(activated(int)), this, SLOT(handlePathType()));
117
        connect(flippedPathText  , SIGNAL(clicked())     , this, SLOT(handlePathFlip()));
118
        connect(startOffset      , SIGNAL(valueChanged(double)), this, SLOT(handlePathDist()));
119
        connect(distFromCurve    , SIGNAL(valueChanged(double)), this, SLOT(handlePathOffs()));
120
}
121
 
122
void PropertyWidget_PathText::disconnectSignals()
123
{
124
        disconnect(showCurveCheckBox, SIGNAL(clicked())     , this, SLOT(handlePathLine()));
125
        disconnect(pathTextType     , SIGNAL(activated(int)), this, SLOT(handlePathType()));
126
        disconnect(flippedPathText  , SIGNAL(clicked())     , this, SLOT(handlePathFlip()));
127
        disconnect(startOffset      , SIGNAL(valueChanged(double)), this, SLOT(handlePathDist()));
128
        disconnect(distFromCurve    , SIGNAL(valueChanged(double)), this, SLOT(handlePathOffs()));
129
}
130
 
131
void PropertyWidget_PathText::configureWidgets(void)
132
{
133
        bool enabled = false;
134
        if (m_item && m_doc)
135
        {
136
                enabled  = m_item->isPathText();
137
                enabled &= (m_doc->m_Selection->count() == 1);
138
        }
139
        setEnabled(enabled);
140
}
141
 
142
void PropertyWidget_PathText::handleSelectionChanged()
143
{
144
        if (!m_doc || !m_ScMW || m_ScMW->scriptIsRunning())
16546 jghali 145
                return;
146
 
17388 jghali 147
        PageItem* currItem = currentItemFromSelection();
148
        setCurrentItem(currItem);
149
        updateGeometry();
150
        repaint();
151
}
16546 jghali 152
 
17388 jghali 153
void PropertyWidget_PathText::handleUpdateRequest(int /*updateFlags*/)
154
{
155
        // Nothing to do
16546 jghali 156
}
157
 
17388 jghali 158
void PropertyWidget_PathText::handlePathDist()
159
{
160
        if (!m_doc || !m_item || !m_ScMW || m_ScMW->scriptIsRunning())
161
                return;
162
        m_item->setTextToFrameDistLeft(startOffset->value());
20694 craig 163
        m_doc->adjustItemSize(m_item);
17388 jghali 164
        m_item->updatePolyClip();
165
        m_item->update();
166
        m_doc->regionsChanged()->update(QRect());
167
}
168
 
169
void PropertyWidget_PathText::handlePathFlip()
170
{
171
        if (!m_doc || !m_item || !m_ScMW || m_ScMW->scriptIsRunning())
172
                return;
173
        m_item->textPathFlipped = flippedPathText->isChecked();
174
        m_item->updatePolyClip();
175
        m_item->update();
176
        m_doc->regionsChanged()->update(QRect());
177
}
178
 
179
void PropertyWidget_PathText::handlePathLine()
180
{
181
        if (!m_doc || !m_item || !m_ScMW || m_ScMW->scriptIsRunning())
182
                return;
183
        m_item->PoShow = showCurveCheckBox->isChecked();
184
        m_item->update();
185
}
186
 
187
void PropertyWidget_PathText::handlePathOffs()
188
{
189
        if (!m_doc || !m_item || !m_ScMW || m_ScMW->scriptIsRunning())
190
                return;
191
        m_item->BaseOffs = -distFromCurve->value();
20694 craig 192
        m_doc->adjustItemSize(m_item);
17388 jghali 193
        m_item->updatePolyClip();
194
        m_item->update();
195
}
196
 
197
void PropertyWidget_PathText::handlePathType()
198
{
199
        if (!m_doc || !m_item || !m_ScMW || m_ScMW->scriptIsRunning())
200
                return;
201
        m_item->textPathType = pathTextType->currentIndex();
202
        m_item->update();
203
        m_doc->regionsChanged()->update(QRect());
204
}
205
 
206
void PropertyWidget_PathText::changeEvent(QEvent *e)
207
{
208
        if (e->type() == QEvent::LanguageChange)
209
        {
210
                languageChange();
211
                return;
212
        }
213
        QWidget::changeEvent(e);
214
}
215
 
16546 jghali 216
void PropertyWidget_PathText::languageChange()
217
{
218
        int oldPathType = pathTextType->currentIndex();
219
        pathTextType->clear();
220
        pathTextType->addItem( tr("Default"));
221
        pathTextType->addItem( tr("Stair Step"));
222
        pathTextType->addItem( tr("Skew"));
223
        pathTextType->setCurrentIndex(oldPathType);
224
 
225
        flippedPathText->setText( tr("Flip Text"));
226
        showCurveCheckBox->setText( tr("Show Curve"));
227
        pathTextTypeLabel->setText( tr("Type:"));
228
        startOffsetLabel->setText( tr("Start Offset:"));
229
        distFromCurveLabel->setText( tr("Distance from Curve:"));
230
 
231
        QString ptSuffix = tr(" pt");
232
        startOffset->setSuffix(ptSuffix);
233
        distFromCurve->setSuffix(ptSuffix);
17388 jghali 234
}
235
 
236
void PropertyWidget_PathText::unitChange()
237
{
238
        if (!m_doc)
239
                return;
240
 
241
        m_unitRatio = m_doc->unitRatio();
242
        m_unitIndex = m_doc->unitIndex();
243
 
244
        startOffset->setNewUnit( m_unitIndex );
245
        distFromCurve->setNewUnit( m_unitIndex );
246
}