Subversion Repositories Scribus

Rev

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