Subversion Repositories Scribus

Rev

Rev 24442 | 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
 
21304 jghali 10
#include <QSignalBlocker>
11
 
23607 craig 12
#include "localemgr.h"
19080 craig 13
#include "scribus.h"
23607 craig 14
#include "scribusapp.h"
16546 jghali 15
#include "scribusdoc.h"
17388 jghali 16
#include "selection.h"
16546 jghali 17
 
18
PropertyWidget_PathText::PropertyWidget_PathText(QWidget* parent) : QFrame(parent)
19
{
20
        setupUi(this);
21
 
24442 jghali 22
        layout()->setAlignment(Qt::AlignTop);
24533 jghali 23
 
16546 jghali 24
        startOffset->setValues(0, 30000, 2, 0);
25
        startOffset->setSingleStep(10);
26
 
27
        distFromCurve->setValues(-300, 300, 2, 0);
28
        distFromCurve->setSingleStep(10);
29
 
23607 craig 30
        connect(ScQApp, SIGNAL(localeChanged()), this, SLOT(localeChange()));
31
 
16546 jghali 32
        languageChange();
33
}
34
 
17388 jghali 35
void PropertyWidget_PathText::setMainWindow(ScribusMainWindow* mw)
36
{
37
        m_ScMW = mw;
38
 
39
        connect(m_ScMW, SIGNAL(UpdateRequest(int)), this  , SLOT(handleUpdateRequest(int)));
40
}
41
 
16546 jghali 42
void PropertyWidget_PathText::setDoc(ScribusDoc *d)
43
{
44
        if(d == (ScribusDoc*) m_doc)
45
                return;
46
 
17388 jghali 47
        if (m_doc)
48
        {
49
                disconnect(m_doc->m_Selection, SIGNAL(selectionChanged()), this, SLOT(handleSelectionChanged()));
50
                disconnect(m_doc             , SIGNAL(docChanged())      , this, SLOT(handleSelectionChanged()));
51
        }
52
 
16546 jghali 53
        m_doc  = d;
22521 craig 54
        m_item = nullptr;
16546 jghali 55
 
56
        if (m_doc.isNull())
17388 jghali 57
        {
58
                disconnectSignals();
16546 jghali 59
                return;
17388 jghali 60
        }
16546 jghali 61
 
22601 craig 62
        m_unitRatio = m_doc->unitRatio();
63
        m_unitIndex = m_doc->unitIndex();
16546 jghali 64
 
65
        startOffset->setMaximum( 30000 );
66
        startOffset->setMinimum( 0 );
67
        startOffset->setSingleStep(10);
68
        distFromCurve->setMaximum( 300 );
69
        distFromCurve->setMinimum( -300 );
70
        distFromCurve->setSingleStep(10);
17388 jghali 71
 
72
        connect(m_doc->m_Selection, SIGNAL(selectionChanged()), this, SLOT(handleSelectionChanged()));
73
        connect(m_doc             , SIGNAL(docChanged())      , this, SLOT(handleSelectionChanged()));
16546 jghali 74
}
75
 
17388 jghali 76
void PropertyWidget_PathText::setCurrentItem(PageItem *item)
16546 jghali 77
{
17388 jghali 78
        if (!m_ScMW || m_ScMW->scriptIsRunning())
79
                return;
21026 craig 80
        //CB We shouldn't really need to process this if our item is the same one
17388 jghali 81
        //maybe we do if the item has been changed by scripter.. but that should probably
82
        //set some status if so.
22521 craig 83
        //FIXME: This won't work until when a canvas deselect happens, m_item must be nullptr.
17388 jghali 84
        //if (m_item == i)
85
        //      return;
86
 
87
        if (item && m_doc.isNull())
88
                setDoc(item->doc());
89
 
90
        m_item = item;
91
 
92
        disconnectSignals();
93
        configureWidgets();
94
 
95
        if (m_item)
16546 jghali 96
        {
23797 jghali 97
                if (m_item->isPathText())
17388 jghali 98
                {
99
                        pathTextType->setCurrentIndex(m_item->textPathType);
100
                        flippedPathText->setChecked(m_item->textPathFlipped);
101
                        showCurveCheckBox->setChecked(m_item->PoShow);
21214 jghali 102
                        distFromCurve->showValue(m_item->BaseOffs * -1 * m_unitRatio);
21223 fschmid 103
                        if (m_item->itemText.paragraphStyle(0).alignment() == 1)
104
                                startOffset->setMinimum(-3000);
105
                        else
106
                        {
107
                                if (m_item->textToFrameDistLeft() < 0)
108
                                        m_item->setTextToFrameDistLeft(0);
109
                                startOffset->setMinimum(0);
110
                        }
21214 jghali 111
                        startOffset->showValue(m_item->textToFrameDistLeft() * m_unitRatio);
17388 jghali 112
                }
113
                connectSignals();
16546 jghali 114
        }
115
}
116
 
17388 jghali 117
void PropertyWidget_PathText::connectSignals()
16546 jghali 118
{
17388 jghali 119
        connect(showCurveCheckBox, SIGNAL(clicked())     , this, SLOT(handlePathLine()));
120
        connect(pathTextType     , SIGNAL(activated(int)), this, SLOT(handlePathType()));
121
        connect(flippedPathText  , SIGNAL(clicked())     , this, SLOT(handlePathFlip()));
122
        connect(startOffset      , SIGNAL(valueChanged(double)), this, SLOT(handlePathDist()));
123
        connect(distFromCurve    , SIGNAL(valueChanged(double)), this, SLOT(handlePathOffs()));
124
}
125
 
126
void PropertyWidget_PathText::disconnectSignals()
127
{
128
        disconnect(showCurveCheckBox, SIGNAL(clicked())     , this, SLOT(handlePathLine()));
129
        disconnect(pathTextType     , SIGNAL(activated(int)), this, SLOT(handlePathType()));
130
        disconnect(flippedPathText  , SIGNAL(clicked())     , this, SLOT(handlePathFlip()));
131
        disconnect(startOffset      , SIGNAL(valueChanged(double)), this, SLOT(handlePathDist()));
132
        disconnect(distFromCurve    , SIGNAL(valueChanged(double)), this, SLOT(handlePathOffs()));
133
}
134
 
22601 craig 135
void PropertyWidget_PathText::configureWidgets()
17388 jghali 136
{
137
        bool enabled = false;
138
        if (m_item && m_doc)
139
        {
140
                enabled  = m_item->isPathText();
141
                enabled &= (m_doc->m_Selection->count() == 1);
142
        }
143
        setEnabled(enabled);
144
}
145
 
146
void PropertyWidget_PathText::handleSelectionChanged()
147
{
148
        if (!m_doc || !m_ScMW || m_ScMW->scriptIsRunning())
16546 jghali 149
                return;
150
 
17388 jghali 151
        PageItem* currItem = currentItemFromSelection();
152
        setCurrentItem(currItem);
153
        updateGeometry();
154
}
16546 jghali 155
 
17388 jghali 156
void PropertyWidget_PathText::handleUpdateRequest(int /*updateFlags*/)
157
{
158
        // Nothing to do
16546 jghali 159
}
160
 
17388 jghali 161
void PropertyWidget_PathText::handlePathDist()
162
{
163
        if (!m_doc || !m_item || !m_ScMW || m_ScMW->scriptIsRunning())
164
                return;
21214 jghali 165
        m_item->setTextToFrameDistLeft(startOffset->value() / m_unitRatio);
20694 craig 166
        m_doc->adjustItemSize(m_item);
17388 jghali 167
        m_item->updatePolyClip();
168
        m_item->update();
169
        m_doc->regionsChanged()->update(QRect());
170
}
171
 
172
void PropertyWidget_PathText::handlePathFlip()
173
{
174
        if (!m_doc || !m_item || !m_ScMW || m_ScMW->scriptIsRunning())
175
                return;
176
        m_item->textPathFlipped = flippedPathText->isChecked();
177
        m_item->updatePolyClip();
178
        m_item->update();
179
        m_doc->regionsChanged()->update(QRect());
180
}
181
 
182
void PropertyWidget_PathText::handlePathLine()
183
{
184
        if (!m_doc || !m_item || !m_ScMW || m_ScMW->scriptIsRunning())
185
                return;
186
        m_item->PoShow = showCurveCheckBox->isChecked();
187
        m_item->update();
188
}
189
 
190
void PropertyWidget_PathText::handlePathOffs()
191
{
192
        if (!m_doc || !m_item || !m_ScMW || m_ScMW->scriptIsRunning())
193
                return;
21214 jghali 194
        m_item->BaseOffs = -distFromCurve->value() / m_unitRatio;
20694 craig 195
        m_doc->adjustItemSize(m_item);
17388 jghali 196
        m_item->updatePolyClip();
197
        m_item->update();
21223 fschmid 198
        m_doc->regionsChanged()->update(QRect());
17388 jghali 199
}
200
 
201
void PropertyWidget_PathText::handlePathType()
202
{
203
        if (!m_doc || !m_item || !m_ScMW || m_ScMW->scriptIsRunning())
204
                return;
205
        m_item->textPathType = pathTextType->currentIndex();
206
        m_item->update();
207
        m_doc->regionsChanged()->update(QRect());
208
}
209
 
210
void PropertyWidget_PathText::changeEvent(QEvent *e)
211
{
212
        if (e->type() == QEvent::LanguageChange)
213
        {
214
                languageChange();
215
                return;
216
        }
217
        QWidget::changeEvent(e);
218
}
219
 
16546 jghali 220
void PropertyWidget_PathText::languageChange()
221
{
21304 jghali 222
        QSignalBlocker pathTextTypeBlocker(pathTextType);
16546 jghali 223
        int oldPathType = pathTextType->currentIndex();
224
        pathTextType->clear();
225
        pathTextType->addItem( tr("Default"));
226
        pathTextType->addItem( tr("Stair Step"));
227
        pathTextType->addItem( tr("Skew"));
228
        pathTextType->setCurrentIndex(oldPathType);
229
 
230
        flippedPathText->setText( tr("Flip Text"));
231
        showCurveCheckBox->setText( tr("Show Curve"));
232
        pathTextTypeLabel->setText( tr("Type:"));
233
        startOffsetLabel->setText( tr("Start Offset:"));
234
        distFromCurveLabel->setText( tr("Distance from Curve:"));
235
 
236
        QString ptSuffix = tr(" pt");
21214 jghali 237
        QString unitSuffix = m_doc ? unitGetSuffixFromIndex(m_doc->unitIndex()) : ptSuffix;
238
        startOffset->setSuffix(unitSuffix);
239
        distFromCurve->setSuffix(unitSuffix);
17388 jghali 240
}
241
 
242
void PropertyWidget_PathText::unitChange()
243
{
244
        if (!m_doc)
245
                return;
246
 
23888 jghali 247
        QSignalBlocker startOffsetBlocker(startOffset);
248
        QSignalBlocker distFromCurveBlocker(distFromCurve);
249
 
17388 jghali 250
        m_unitRatio = m_doc->unitRatio();
251
        m_unitIndex = m_doc->unitIndex();
252
 
23888 jghali 253
        startOffset->setNewUnit(m_unitIndex);
254
        distFromCurve->setNewUnit(m_unitIndex);
17388 jghali 255
}
23607 craig 256
 
257
void PropertyWidget_PathText::localeChange()
258
{
259
        const QLocale& l(LocaleManager::instance().userPreferredLocale());
260
        startOffset->setLocale(l);
261
        distFromCurve->setLocale(l);
262
}