Changeset View
Changeset View
Standalone View
Standalone View
tools/selection/text/kpToolText_TextStyle.cpp
Show First 20 Lines • Show All 49 Lines • ▼ Show 20 Line(s) | |||||
50 | 50 | | |||
51 | // protected | 51 | // protected | ||
52 | bool kpToolText::shouldChangeTextStyle () const | 52 | bool kpToolText::shouldChangeTextStyle () const | ||
53 | { | 53 | { | ||
54 | if (environ ()->settingTextStyle ()) | 54 | if (environ ()->settingTextStyle ()) | ||
55 | { | 55 | { | ||
56 | #if DEBUG_KP_TOOL_TEXT | 56 | #if DEBUG_KP_TOOL_TEXT | ||
57 | qCDebug(kpLogTools) << "\trecursion - abort setting text style: " | 57 | qCDebug(kpLogTools) << "\trecursion - abort setting text style: " | ||
58 | << environ ()->settingTextStyle () | 58 | << environ ()->settingTextStyle (); | ||
59 | << endl; | | |||
60 | #endif | 59 | #endif | ||
61 | return false; | 60 | return false; | ||
62 | } | 61 | } | ||
63 | 62 | | |||
64 | if (!document ()->textSelection ()) | 63 | if (!document ()->textSelection ()) | ||
65 | { | 64 | { | ||
66 | #if DEBUG_KP_TOOL_TEXT | 65 | #if DEBUG_KP_TOOL_TEXT | ||
67 | qCDebug(kpLogTools) << "\tno text selection - abort setting text style"; | 66 | qCDebug(kpLogTools) << "\tno text selection - abort setting text style"; | ||
68 | #endif | 67 | #endif | ||
69 | return false; | 68 | return false; | ||
70 | } | 69 | } | ||
71 | 70 | | |||
72 | return true; | 71 | return true; | ||
73 | } | 72 | } | ||
74 | 73 | | |||
75 | // protected | 74 | // protected | ||
76 | void kpToolText::changeTextStyle (const QString &name, | 75 | void kpToolText::changeTextStyle (const QString &name, | ||
77 | const kpTextStyle &newTextStyle, | 76 | const kpTextStyle &newTextStyle, | ||
78 | const kpTextStyle &oldTextStyle) | 77 | const kpTextStyle &oldTextStyle) | ||
79 | { | 78 | { | ||
80 | #if DEBUG_KP_TOOL_TEXT | 79 | #if DEBUG_KP_TOOL_TEXT | ||
81 | qCDebug(kpLogTools) << "kpToolText::changeTextStyle(" << name << ")"; | 80 | qCDebug(kpLogTools) << "kpToolText::changeTextStyle(" << name << ")"; | ||
82 | #endif | 81 | #endif | ||
83 | 82 | | |||
84 | if (hasBegunShape ()) | 83 | if (hasBegunShape ()) { | ||
85 | endShape (currentPoint (), normalizedRect ()); | 84 | endShape (currentPoint (), normalizedRect ()); | ||
85 | } | ||||
86 | 86 | | |||
87 | commandHistory ()->addCommand ( | 87 | commandHistory ()->addCommand ( | ||
88 | new kpToolTextChangeStyleCommand ( | 88 | new kpToolTextChangeStyleCommand ( | ||
89 | name, | 89 | name, | ||
90 | newTextStyle, | 90 | newTextStyle, | ||
91 | oldTextStyle, | 91 | oldTextStyle, | ||
92 | environ ()->commandEnvironment ())); | 92 | environ ()->commandEnvironment ())); | ||
93 | } | 93 | } | ||
94 | 94 | | |||
95 | 95 | | |||
96 | // protected slot virtual [base kpAbstractSelectionTool] | 96 | // protected slot virtual [base kpAbstractSelectionTool] | ||
97 | void kpToolText::slotIsOpaqueChanged (bool isOpaque) | 97 | void kpToolText::slotIsOpaqueChanged (bool isOpaque) | ||
98 | { | 98 | { | ||
99 | #if DEBUG_KP_TOOL_TEXT | 99 | #if DEBUG_KP_TOOL_TEXT | ||
100 | qCDebug(kpLogTools) << "kpToolText::slotIsOpaqueChanged()"; | 100 | qCDebug(kpLogTools) << "kpToolText::slotIsOpaqueChanged()"; | ||
101 | #endif | 101 | #endif | ||
102 | 102 | | |||
103 | if (!shouldChangeTextStyle ()) | 103 | if (!shouldChangeTextStyle ()) { | ||
104 | return; | 104 | return; | ||
105 | } | ||||
105 | 106 | | |||
106 | kpTextStyle newTextStyle = environ ()->textStyle (); | 107 | kpTextStyle newTextStyle = environ ()->textStyle (); | ||
107 | 108 | | |||
108 | kpTextStyle oldTextStyle = newTextStyle; | 109 | kpTextStyle oldTextStyle = newTextStyle; | ||
109 | oldTextStyle.setBackgroundOpaque (!isOpaque); | 110 | oldTextStyle.setBackgroundOpaque (!isOpaque); | ||
110 | 111 | | |||
111 | changeTextStyle (newTextStyle.isBackgroundOpaque () ? | 112 | changeTextStyle (newTextStyle.isBackgroundOpaque () ? | ||
112 | i18n ("Text: Opaque Background") : | 113 | i18n ("Text: Opaque Background") : | ||
113 | i18n ("Text: Transparent Background"), | 114 | i18n ("Text: Transparent Background"), | ||
114 | newTextStyle, | 115 | newTextStyle, | ||
115 | oldTextStyle); | 116 | oldTextStyle); | ||
116 | } | 117 | } | ||
117 | 118 | | |||
118 | // protected slot virtual [base kpTool] | 119 | // protected slot virtual [base kpTool] | ||
119 | void kpToolText::slotColorsSwapped (const kpColor &newForegroundColor, | 120 | void kpToolText::slotColorsSwapped (const kpColor &newForegroundColor, | ||
120 | const kpColor &newBackgroundColor) | 121 | const kpColor &newBackgroundColor) | ||
121 | { | 122 | { | ||
122 | #if DEBUG_KP_TOOL_TEXT | 123 | #if DEBUG_KP_TOOL_TEXT | ||
123 | qCDebug(kpLogTools) << "kpToolText::slotColorsSwapped()"; | 124 | qCDebug(kpLogTools) << "kpToolText::slotColorsSwapped()"; | ||
124 | #endif | 125 | #endif | ||
125 | 126 | | |||
126 | if (!shouldChangeTextStyle ()) | 127 | if (!shouldChangeTextStyle ()) { | ||
127 | return; | 128 | return; | ||
129 | } | ||||
128 | 130 | | |||
129 | kpTextStyle newTextStyle = environ ()->textStyle (); | 131 | kpTextStyle newTextStyle = environ ()->textStyle (); | ||
130 | 132 | | |||
131 | kpTextStyle oldTextStyle = newTextStyle; | 133 | kpTextStyle oldTextStyle = newTextStyle; | ||
132 | oldTextStyle.setForegroundColor (newBackgroundColor); | 134 | oldTextStyle.setForegroundColor (newBackgroundColor); | ||
133 | oldTextStyle.setBackgroundColor (newForegroundColor); | 135 | oldTextStyle.setBackgroundColor (newForegroundColor); | ||
134 | 136 | | |||
135 | changeTextStyle (i18n ("Text: Swap Colors"), | 137 | changeTextStyle (i18n ("Text: Swap Colors"), | ||
136 | newTextStyle, | 138 | newTextStyle, | ||
137 | oldTextStyle); | 139 | oldTextStyle); | ||
138 | } | 140 | } | ||
139 | 141 | | |||
140 | // protected slot virtual [base kpTool] | 142 | // protected slot virtual [base kpTool] | ||
141 | void kpToolText::slotForegroundColorChanged (const kpColor & /*color*/) | 143 | void kpToolText::slotForegroundColorChanged (const kpColor & /*color*/) | ||
142 | { | 144 | { | ||
143 | #if DEBUG_KP_TOOL_TEXT | 145 | #if DEBUG_KP_TOOL_TEXT | ||
144 | qCDebug(kpLogTools) << "kpToolText::slotForegroundColorChanged()"; | 146 | qCDebug(kpLogTools) << "kpToolText::slotForegroundColorChanged()"; | ||
145 | #endif | 147 | #endif | ||
146 | 148 | | |||
147 | if (!shouldChangeTextStyle ()) | 149 | if (!shouldChangeTextStyle ()) { | ||
148 | return; | 150 | return; | ||
151 | } | ||||
149 | 152 | | |||
150 | kpTextStyle newTextStyle = environ ()->textStyle (); | 153 | kpTextStyle newTextStyle = environ ()->textStyle (); | ||
151 | 154 | | |||
152 | kpTextStyle oldTextStyle = newTextStyle; | 155 | kpTextStyle oldTextStyle = newTextStyle; | ||
153 | oldTextStyle.setForegroundColor (oldForegroundColor ()); | 156 | oldTextStyle.setForegroundColor (oldForegroundColor ()); | ||
154 | 157 | | |||
155 | changeTextStyle (i18n ("Text: Foreground Color"), | 158 | changeTextStyle (i18n ("Text: Foreground Color"), | ||
156 | newTextStyle, | 159 | newTextStyle, | ||
157 | oldTextStyle); | 160 | oldTextStyle); | ||
158 | } | 161 | } | ||
159 | 162 | | |||
160 | // protected slot virtual [base kpAbstractSelectionTool] | 163 | // protected slot virtual [base kpAbstractSelectionTool] | ||
161 | void kpToolText::slotBackgroundColorChanged (const kpColor & /*color*/) | 164 | void kpToolText::slotBackgroundColorChanged (const kpColor & /*color*/) | ||
162 | { | 165 | { | ||
163 | #if DEBUG_KP_TOOL_TEXT | 166 | #if DEBUG_KP_TOOL_TEXT | ||
164 | qCDebug(kpLogTools) << "kpToolText::slotBackgroundColorChanged()"; | 167 | qCDebug(kpLogTools) << "kpToolText::slotBackgroundColorChanged()"; | ||
165 | #endif | 168 | #endif | ||
166 | 169 | | |||
167 | if (!shouldChangeTextStyle ()) | 170 | if (!shouldChangeTextStyle ()) { | ||
168 | return; | 171 | return; | ||
172 | } | ||||
169 | 173 | | |||
170 | kpTextStyle newTextStyle = environ ()->textStyle (); | 174 | kpTextStyle newTextStyle = environ ()->textStyle (); | ||
171 | 175 | | |||
172 | kpTextStyle oldTextStyle = newTextStyle; | 176 | kpTextStyle oldTextStyle = newTextStyle; | ||
173 | oldTextStyle.setBackgroundColor (oldBackgroundColor ()); | 177 | oldTextStyle.setBackgroundColor (oldBackgroundColor ()); | ||
174 | 178 | | |||
175 | changeTextStyle (i18n ("Text: Background Color"), | 179 | changeTextStyle (i18n ("Text: Background Color"), | ||
176 | newTextStyle, | 180 | newTextStyle, | ||
Show All 11 Lines | |||||
188 | // public slot | 192 | // public slot | ||
189 | void kpToolText::slotFontFamilyChanged (const QString &fontFamily, | 193 | void kpToolText::slotFontFamilyChanged (const QString &fontFamily, | ||
190 | const QString &oldFontFamily) | 194 | const QString &oldFontFamily) | ||
191 | { | 195 | { | ||
192 | #if DEBUG_KP_TOOL_TEXT | 196 | #if DEBUG_KP_TOOL_TEXT | ||
193 | qCDebug(kpLogTools) << "kpToolText::slotFontFamilyChanged() new=" | 197 | qCDebug(kpLogTools) << "kpToolText::slotFontFamilyChanged() new=" | ||
194 | << fontFamily | 198 | << fontFamily | ||
195 | << " old=" | 199 | << " old=" | ||
196 | << oldFontFamily | 200 | << oldFontFamily; | ||
197 | << endl; | | |||
198 | #else | 201 | #else | ||
199 | (void) fontFamily; | 202 | (void) fontFamily; | ||
200 | #endif | 203 | #endif | ||
201 | 204 | | |||
202 | if (!shouldChangeTextStyle ()) | 205 | if (!shouldChangeTextStyle ()) { | ||
203 | return; | 206 | return; | ||
207 | } | ||||
204 | 208 | | |||
205 | kpTextStyle newTextStyle = environ ()->textStyle (); | 209 | kpTextStyle newTextStyle = environ ()->textStyle (); | ||
206 | 210 | | |||
207 | // Figure out old text style. | 211 | // Figure out old text style. | ||
208 | kpTextStyle oldTextStyle = newTextStyle; | 212 | kpTextStyle oldTextStyle = newTextStyle; | ||
209 | oldTextStyle.setFontFamily (oldFontFamily); | 213 | oldTextStyle.setFontFamily (oldFontFamily); | ||
210 | 214 | | |||
211 | changeTextStyle (i18n ("Text: Font"), | 215 | changeTextStyle (i18n ("Text: Font"), | ||
212 | newTextStyle, | 216 | newTextStyle, | ||
213 | oldTextStyle); | 217 | oldTextStyle); | ||
214 | } | 218 | } | ||
215 | 219 | | |||
216 | // public slot | 220 | // public slot | ||
217 | void kpToolText::slotFontSizeChanged (int fontSize, int oldFontSize) | 221 | void kpToolText::slotFontSizeChanged (int fontSize, int oldFontSize) | ||
218 | { | 222 | { | ||
219 | #if DEBUG_KP_TOOL_TEXT | 223 | #if DEBUG_KP_TOOL_TEXT | ||
220 | qCDebug(kpLogTools) << "kpToolText::slotFontSizeChanged() new=" | 224 | qCDebug(kpLogTools) << "kpToolText::slotFontSizeChanged() new=" | ||
221 | << fontSize | 225 | << fontSize | ||
222 | << " old=" | 226 | << " old=" | ||
223 | << oldFontSize | 227 | << oldFontSize; | ||
224 | << endl; | | |||
225 | #else | 228 | #else | ||
226 | (void) fontSize; | 229 | (void) fontSize; | ||
227 | #endif | 230 | #endif | ||
228 | 231 | | |||
229 | if (!shouldChangeTextStyle ()) | 232 | if (!shouldChangeTextStyle ()) { | ||
230 | return; | 233 | return; | ||
234 | } | ||||
231 | 235 | | |||
232 | kpTextStyle newTextStyle = environ ()->textStyle (); | 236 | kpTextStyle newTextStyle = environ ()->textStyle (); | ||
233 | 237 | | |||
234 | // Figure out old text style. | 238 | // Figure out old text style. | ||
235 | kpTextStyle oldTextStyle = newTextStyle; | 239 | kpTextStyle oldTextStyle = newTextStyle; | ||
236 | oldTextStyle.setFontSize (oldFontSize); | 240 | oldTextStyle.setFontSize (oldFontSize); | ||
237 | 241 | | |||
238 | changeTextStyle (i18n ("Text: Font Size"), | 242 | changeTextStyle (i18n ("Text: Font Size"), | ||
239 | newTextStyle, | 243 | newTextStyle, | ||
240 | oldTextStyle); | 244 | oldTextStyle); | ||
241 | } | 245 | } | ||
242 | 246 | | |||
243 | 247 | | |||
244 | // public slot | 248 | // public slot | ||
245 | void kpToolText::slotBoldChanged (bool isBold) | 249 | void kpToolText::slotBoldChanged (bool isBold) | ||
246 | { | 250 | { | ||
247 | #if DEBUG_KP_TOOL_TEXT | 251 | #if DEBUG_KP_TOOL_TEXT | ||
248 | qCDebug(kpLogTools) << "kpToolText::slotBoldChanged(" << isBold << ")"; | 252 | qCDebug(kpLogTools) << "kpToolText::slotBoldChanged(" << isBold << ")"; | ||
249 | #endif | 253 | #endif | ||
250 | 254 | | |||
251 | if (!shouldChangeTextStyle ()) | 255 | if (!shouldChangeTextStyle ()) { | ||
252 | return; | 256 | return; | ||
257 | } | ||||
253 | 258 | | |||
254 | kpTextStyle newTextStyle = environ ()->textStyle (); | 259 | kpTextStyle newTextStyle = environ ()->textStyle (); | ||
255 | 260 | | |||
256 | // Figure out old text style. | 261 | // Figure out old text style. | ||
257 | kpTextStyle oldTextStyle = newTextStyle; | 262 | kpTextStyle oldTextStyle = newTextStyle; | ||
258 | oldTextStyle.setBold (!isBold); | 263 | oldTextStyle.setBold (!isBold); | ||
259 | 264 | | |||
260 | changeTextStyle (i18n ("Text: Bold"), | 265 | changeTextStyle (i18n ("Text: Bold"), | ||
261 | newTextStyle, | 266 | newTextStyle, | ||
262 | oldTextStyle); | 267 | oldTextStyle); | ||
263 | } | 268 | } | ||
264 | 269 | | |||
265 | // public slot | 270 | // public slot | ||
266 | void kpToolText::slotItalicChanged (bool isItalic) | 271 | void kpToolText::slotItalicChanged (bool isItalic) | ||
267 | { | 272 | { | ||
268 | #if DEBUG_KP_TOOL_TEXT | 273 | #if DEBUG_KP_TOOL_TEXT | ||
269 | qCDebug(kpLogTools) << "kpToolText::slotItalicChanged(" << isItalic << ")"; | 274 | qCDebug(kpLogTools) << "kpToolText::slotItalicChanged(" << isItalic << ")"; | ||
270 | #endif | 275 | #endif | ||
271 | 276 | | |||
272 | if (!shouldChangeTextStyle ()) | 277 | if (!shouldChangeTextStyle ()) { | ||
273 | return; | 278 | return; | ||
279 | } | ||||
274 | 280 | | |||
275 | kpTextStyle newTextStyle = environ ()->textStyle (); | 281 | kpTextStyle newTextStyle = environ ()->textStyle (); | ||
276 | 282 | | |||
277 | // Figure out old text style. | 283 | // Figure out old text style. | ||
278 | kpTextStyle oldTextStyle = newTextStyle; | 284 | kpTextStyle oldTextStyle = newTextStyle; | ||
279 | oldTextStyle.setItalic (!isItalic); | 285 | oldTextStyle.setItalic (!isItalic); | ||
280 | 286 | | |||
281 | changeTextStyle (i18n ("Text: Italic"), | 287 | changeTextStyle (i18n ("Text: Italic"), | ||
282 | newTextStyle, | 288 | newTextStyle, | ||
283 | oldTextStyle); | 289 | oldTextStyle); | ||
284 | } | 290 | } | ||
285 | 291 | | |||
286 | // public slot | 292 | // public slot | ||
287 | void kpToolText::slotUnderlineChanged (bool isUnderline) | 293 | void kpToolText::slotUnderlineChanged (bool isUnderline) | ||
288 | { | 294 | { | ||
289 | #if DEBUG_KP_TOOL_TEXT | 295 | #if DEBUG_KP_TOOL_TEXT | ||
290 | qCDebug(kpLogTools) << "kpToolText::slotUnderlineChanged(" << isUnderline << ")"; | 296 | qCDebug(kpLogTools) << "kpToolText::slotUnderlineChanged(" << isUnderline << ")"; | ||
291 | #endif | 297 | #endif | ||
292 | 298 | | |||
293 | if (!shouldChangeTextStyle ()) | 299 | if (!shouldChangeTextStyle ()) { | ||
294 | return; | 300 | return; | ||
301 | } | ||||
295 | 302 | | |||
296 | kpTextStyle newTextStyle = environ ()->textStyle (); | 303 | kpTextStyle newTextStyle = environ ()->textStyle (); | ||
297 | 304 | | |||
298 | // Figure out old text style. | 305 | // Figure out old text style. | ||
299 | kpTextStyle oldTextStyle = newTextStyle; | 306 | kpTextStyle oldTextStyle = newTextStyle; | ||
300 | oldTextStyle.setUnderline (!isUnderline); | 307 | oldTextStyle.setUnderline (!isUnderline); | ||
301 | 308 | | |||
302 | changeTextStyle (i18n ("Text: Underline"), | 309 | changeTextStyle (i18n ("Text: Underline"), | ||
303 | newTextStyle, | 310 | newTextStyle, | ||
304 | oldTextStyle); | 311 | oldTextStyle); | ||
305 | } | 312 | } | ||
306 | 313 | | |||
307 | // public slot | 314 | // public slot | ||
308 | void kpToolText::slotStrikeThruChanged (bool isStrikeThru) | 315 | void kpToolText::slotStrikeThruChanged (bool isStrikeThru) | ||
309 | { | 316 | { | ||
310 | #if DEBUG_KP_TOOL_TEXT | 317 | #if DEBUG_KP_TOOL_TEXT | ||
311 | qCDebug(kpLogTools) << "kpToolText::slotStrikeThruChanged(" << isStrikeThru << ")"; | 318 | qCDebug(kpLogTools) << "kpToolText::slotStrikeThruChanged(" << isStrikeThru << ")"; | ||
312 | #endif | 319 | #endif | ||
313 | 320 | | |||
314 | if (!shouldChangeTextStyle ()) | 321 | if (!shouldChangeTextStyle ()) { | ||
315 | return; | 322 | return; | ||
323 | } | ||||
316 | 324 | | |||
317 | kpTextStyle newTextStyle = environ ()->textStyle (); | 325 | kpTextStyle newTextStyle = environ ()->textStyle (); | ||
318 | 326 | | |||
319 | // Figure out old text style. | 327 | // Figure out old text style. | ||
320 | kpTextStyle oldTextStyle = newTextStyle; | 328 | kpTextStyle oldTextStyle = newTextStyle; | ||
321 | oldTextStyle.setStrikeThru (!isStrikeThru); | 329 | oldTextStyle.setStrikeThru (!isStrikeThru); | ||
322 | 330 | | |||
323 | changeTextStyle (i18n ("Text: Strike Through"), | 331 | changeTextStyle (i18n ("Text: Strike Through"), | ||
324 | newTextStyle, | 332 | newTextStyle, | ||
325 | oldTextStyle); | 333 | oldTextStyle); | ||
326 | } | 334 | } |