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