Subversion Repositories Scribus

Rev

Rev 21214 | Rev 21304 | 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;
21026 craig 84
        //CB We shouldn't really need to process this if our item is the same one
17388 jghali 85
        //maybe we do if the item has been changed by scripter.. but that should probably
86
        //set some status if so.
21026 craig 87
        //FIXME: This won't work until when a canvas deselect happens, m_item must be NULL.
17388 jghali 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);
21214 jghali 106
                        distFromCurve->showValue(m_item->BaseOffs * -1 * m_unitRatio);
21223 fschmid 107
                        if (m_item->itemText.paragraphStyle(0).alignment() == 1)
108
                                startOffset->setMinimum(-3000);
109
                        else
110
                        {
111
                                if (m_item->textToFrameDistLeft() < 0)
112
                                        m_item->setTextToFrameDistLeft(0);
113
                                startOffset->setMinimum(0);
114
                        }
21214 jghali 115
                        startOffset->showValue(m_item->textToFrameDistLeft() * m_unitRatio);
17388 jghali 116
                }
117
                connectSignals();
16546 jghali 118
        }
119
}
120
 
17388 jghali 121
void PropertyWidget_PathText::connectSignals()
16546 jghali 122
{
17388 jghali 123
        connect(showCurveCheckBox, SIGNAL(clicked())     , this, SLOT(handlePathLine()));
124
        connect(pathTextType     , SIGNAL(activated(int)), this, SLOT(handlePathType()));
125
        connect(flippedPathText  , SIGNAL(clicked())     , this, SLOT(handlePathFlip()));
126
        connect(startOffset      , SIGNAL(valueChanged(double)), this, SLOT(handlePathDist()));
127
        connect(distFromCurve    , SIGNAL(valueChanged(double)), this, SLOT(handlePathOffs()));
128
}
129
 
130
void PropertyWidget_PathText::disconnectSignals()
131
{
132
        disconnect(showCurveCheckBox, SIGNAL(clicked())     , this, SLOT(handlePathLine()));
133
        disconnect(pathTextType     , SIGNAL(activated(int)), this, SLOT(handlePathType()));
134
        disconnect(flippedPathText  , SIGNAL(clicked())     , this, SLOT(handlePathFlip()));
135
        disconnect(startOffset      , SIGNAL(valueChanged(double)), this, SLOT(handlePathDist()));
136
        disconnect(distFromCurve    , SIGNAL(valueChanged(double)), this, SLOT(handlePathOffs()));
137
}
138
 
139
void PropertyWidget_PathText::configureWidgets(void)
140
{
141
        bool enabled = false;
142
        if (m_item && m_doc)
143
        {
144
                enabled  = m_item->isPathText();
145
                enabled &= (m_doc->m_Selection->count() == 1);
146
        }
147
        setEnabled(enabled);
148
}
149
 
150
void PropertyWidget_PathText::handleSelectionChanged()
151
{
152
        if (!m_doc || !m_ScMW || m_ScMW->scriptIsRunning())
16546 jghali 153
                return;
154
 
17388 jghali 155
        PageItem* currItem = currentItemFromSelection();
156
        setCurrentItem(currItem);
157
        updateGeometry();
158
        repaint();
159
}
16546 jghali 160
 
17388 jghali 161
void PropertyWidget_PathText::handleUpdateRequest(int /*updateFlags*/)
162
{
163
        // Nothing to do
16546 jghali 164
}
165
 
17388 jghali 166
void PropertyWidget_PathText::handlePathDist()
167
{
168
        if (!m_doc || !m_item || !m_ScMW || m_ScMW->scriptIsRunning())
169
                return;
21214 jghali 170
        m_item->setTextToFrameDistLeft(startOffset->value() / m_unitRatio);
20694 craig 171
        m_doc->adjustItemSize(m_item);
17388 jghali 172
        m_item->updatePolyClip();
173
        m_item->update();
174
        m_doc->regionsChanged()->update(QRect());
175
}
176
 
177
void PropertyWidget_PathText::handlePathFlip()
178
{
179
        if (!m_doc || !m_item || !m_ScMW || m_ScMW->scriptIsRunning())
180
                return;
181
        m_item->textPathFlipped = flippedPathText->isChecked();
182
        m_item->updatePolyClip();
183
        m_item->update();
184
        m_doc->regionsChanged()->update(QRect());
185
}
186
 
187
void PropertyWidget_PathText::handlePathLine()
188
{
189
        if (!m_doc || !m_item || !m_ScMW || m_ScMW->scriptIsRunning())
190
                return;
191
        m_item->PoShow = showCurveCheckBox->isChecked();
192
        m_item->update();
193
}
194
 
195
void PropertyWidget_PathText::handlePathOffs()
196
{
197
        if (!m_doc || !m_item || !m_ScMW || m_ScMW->scriptIsRunning())
198
                return;
21214 jghali 199
        m_item->BaseOffs = -distFromCurve->value() / m_unitRatio;
20694 craig 200
        m_doc->adjustItemSize(m_item);
17388 jghali 201
        m_item->updatePolyClip();
202
        m_item->update();
21223 fschmid 203
        m_doc->regionsChanged()->update(QRect());
17388 jghali 204
}
205
 
206
void PropertyWidget_PathText::handlePathType()
207
{
208
        if (!m_doc || !m_item || !m_ScMW || m_ScMW->scriptIsRunning())
209
                return;
210
        m_item->textPathType = pathTextType->currentIndex();
211
        m_item->update();
212
        m_doc->regionsChanged()->update(QRect());
213
}
214
 
215
void PropertyWidget_PathText::changeEvent(QEvent *e)
216
{
217
        if (e->type() == QEvent::LanguageChange)
218
        {
219
                languageChange();
220
                return;
221
        }
222
        QWidget::changeEvent(e);
223
}
224
 
16546 jghali 225
void PropertyWidget_PathText::languageChange()
226
{
227
        int oldPathType = pathTextType->currentIndex();
228
        pathTextType->clear();
229
        pathTextType->addItem( tr("Default"));
230
        pathTextType->addItem( tr("Stair Step"));
231
        pathTextType->addItem( tr("Skew"));
232
        pathTextType->setCurrentIndex(oldPathType);
233
 
234
        flippedPathText->setText( tr("Flip Text"));
235
        showCurveCheckBox->setText( tr("Show Curve"));
236
        pathTextTypeLabel->setText( tr("Type:"));
237
        startOffsetLabel->setText( tr("Start Offset:"));
238
        distFromCurveLabel->setText( tr("Distance from Curve:"));
239
 
240
        QString ptSuffix = tr(" pt");
21214 jghali 241
        QString unitSuffix = m_doc ? unitGetSuffixFromIndex(m_doc->unitIndex()) : ptSuffix;
242
        startOffset->setSuffix(unitSuffix);
243
        distFromCurve->setSuffix(unitSuffix);
17388 jghali 244
}
245
 
246
void PropertyWidget_PathText::unitChange()
247
{
248
        if (!m_doc)
249
                return;
250
 
251
        m_unitRatio = m_doc->unitRatio();
252
        m_unitIndex = m_doc->unitIndex();
253
 
254
        startOffset->setNewUnit( m_unitIndex );
255
        distFromCurve->setNewUnit( m_unitIndex );
256
}