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