Changeset View
Changeset View
Standalone View
Standalone View
widgets/toolbars/options/kpToolWidgetBase.cpp
Show First 20 Lines • Show All 58 Lines • ▼ Show 20 Line(s) | 56 | { | |||
---|---|---|---|---|---|
59 | setFrameStyle (QFrame::Panel | QFrame::Sunken); | 59 | setFrameStyle (QFrame::Panel | QFrame::Sunken); | ||
60 | 60 | | |||
61 | setFixedSize (44, 66); | 61 | setFixedSize (44, 66); | ||
62 | setSizePolicy (QSizePolicy::Minimum, QSizePolicy::Minimum); | 62 | setSizePolicy (QSizePolicy::Minimum, QSizePolicy::Minimum); | ||
63 | } | 63 | } | ||
64 | 64 | | |||
65 | //--------------------------------------------------------------------- | 65 | //--------------------------------------------------------------------- | ||
66 | 66 | | |||
67 | kpToolWidgetBase::~kpToolWidgetBase () | 67 | kpToolWidgetBase::~kpToolWidgetBase () = default; | ||
68 | { | | |||
69 | } | | |||
70 | 68 | | |||
71 | //--------------------------------------------------------------------- | 69 | //--------------------------------------------------------------------- | ||
72 | 70 | | |||
73 | // public | 71 | // public | ||
74 | void kpToolWidgetBase::addOption (const QPixmap &pixmap, const QString &toolTip) | 72 | void kpToolWidgetBase::addOption (const QPixmap &pixmap, const QString &toolTip) | ||
75 | { | 73 | { | ||
76 | if (m_pixmaps.isEmpty ()) | 74 | if (m_pixmaps.isEmpty ()) { | ||
77 | startNewOptionRow (); | 75 | startNewOptionRow (); | ||
76 | } | ||||
78 | 77 | | |||
79 | m_pixmaps.last ().append (pixmap); | 78 | m_pixmaps.last ().append (pixmap); | ||
80 | m_pixmapRects.last ().append (QRect ()); | 79 | m_pixmapRects.last ().append (QRect ()); | ||
81 | m_toolTips.last ().append (toolTip); | 80 | m_toolTips.last ().append (toolTip); | ||
82 | } | 81 | } | ||
83 | 82 | | |||
84 | //--------------------------------------------------------------------- | 83 | //--------------------------------------------------------------------- | ||
85 | 84 | | |||
Show All 9 Lines | |||||
95 | 94 | | |||
96 | // public | 95 | // public | ||
97 | void kpToolWidgetBase::finishConstruction (int fallBackRow, int fallBackCol) | 96 | void kpToolWidgetBase::finishConstruction (int fallBackRow, int fallBackCol) | ||
98 | { | 97 | { | ||
99 | #if DEBUG_KP_TOOL_WIDGET_BASE | 98 | #if DEBUG_KP_TOOL_WIDGET_BASE | ||
100 | qCDebug(kpLogWidgets) << "kpToolWidgetBase(" << objectName () | 99 | qCDebug(kpLogWidgets) << "kpToolWidgetBase(" << objectName () | ||
101 | << ")::kpToolWidgetBase(fallBack:row=" << fallBackRow | 100 | << ")::kpToolWidgetBase(fallBack:row=" << fallBackRow | ||
102 | << ",col=" << fallBackCol | 101 | << ",col=" << fallBackCol | ||
103 | << ")" | 102 | << ")"; | ||
104 | << endl; | | |||
105 | #endif | 103 | #endif | ||
106 | 104 | | |||
107 | relayoutOptions (); | 105 | relayoutOptions (); | ||
108 | 106 | | |||
109 | // HACK: Undo the maximum half of setFixedSize() in the ctor to avoid | 107 | // HACK: Undo the maximum half of setFixedSize() in the ctor to avoid | ||
110 | // bizarre redraw errors when tool widgets are hidden and others | 108 | // bizarre redraw errors when tool widgets are hidden and others | ||
111 | // are shown. | 109 | // are shown. | ||
112 | // | 110 | // | ||
113 | // The reason why we didn't just use setMinimumSize() in the ctor is | 111 | // The reason why we didn't just use setMinimumSize() in the ctor is | ||
114 | // because all tool widgets construct pixmaps whose sizes are dependent | 112 | // because all tool widgets construct pixmaps whose sizes are dependent | ||
115 | // on the size() in the ctor, so we needed to get the correct size | 113 | // on the size() in the ctor, so we needed to get the correct size | ||
116 | // in there. This is bad design because it means that tool widgets | 114 | // in there. This is bad design because it means that tool widgets | ||
117 | // can't really be resized. | 115 | // can't really be resized. | ||
118 | setMaximumSize (QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); | 116 | setMaximumSize (QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); | ||
119 | 117 | | |||
120 | const QPair <int, int> rowColPair = defaultSelectedRowAndCol (); | 118 | const QPair <int, int> rowColPair = defaultSelectedRowAndCol (); | ||
121 | if (!setSelected (rowColPair.first, rowColPair.second, false/*don't save*/)) | 119 | if (!setSelected (rowColPair.first, rowColPair.second, false/*don't save*/)) | ||
122 | { | 120 | { | ||
123 | if (!setSelected (fallBackRow, fallBackCol)) | 121 | if (!setSelected (fallBackRow, fallBackCol)) | ||
124 | { | 122 | { | ||
125 | if (!setSelected (0, 0)) | 123 | if (!setSelected (0, 0)) | ||
126 | { | 124 | { | ||
127 | qCCritical(kpLogWidgets) << "kpToolWidgetBase::finishConstruction() " | 125 | qCCritical(kpLogWidgets) << "kpToolWidgetBase::finishConstruction() " | ||
128 | "can't even fall back to setSelected(row=0,col=0)" << endl; | 126 | "can't even fall back to setSelected(row=0,col=0)"; | ||
129 | } | 127 | } | ||
130 | } | 128 | } | ||
131 | } | 129 | } | ||
132 | } | 130 | } | ||
133 | 131 | | |||
134 | //--------------------------------------------------------------------- | 132 | //--------------------------------------------------------------------- | ||
135 | 133 | | |||
136 | // private | 134 | // private | ||
137 | QList <int> kpToolWidgetBase::spreadOutElements (const QList <int> &sizes, int max) | 135 | QList <int> kpToolWidgetBase::spreadOutElements (const QList <int> &sizes, int max) | ||
138 | { | 136 | { | ||
139 | if (sizes.count () == 0) | 137 | if (sizes.count () == 0) { | ||
140 | return QList <int> (); | 138 | return QList <int> (); | ||
141 | else if (sizes.count () == 1) | 139 | } | ||
140 | | ||||
141 | if (sizes.count () == 1) | ||||
142 | { | 142 | { | ||
143 | QList <int> ret; | 143 | QList <int> ret; | ||
144 | ret.append (sizes.first () > max ? 0 : 1/*margin*/); | 144 | ret.append (sizes.first () > max ? 0 : 1/*margin*/); | ||
145 | return ret; | 145 | return ret; | ||
146 | } | 146 | } | ||
147 | 147 | | |||
148 | QList <int> retOffsets; | 148 | QList <int> retOffsets; | ||
149 | for (int i = 0; i < sizes.count (); i++) | 149 | for (int i = 0; i < sizes.count (); i++) { | ||
150 | retOffsets.append (0); | 150 | retOffsets.append (0); | ||
151 | } | ||||
151 | 152 | | |||
152 | int totalSize = 0; | 153 | int totalSize = 0; | ||
153 | for (int i = 0; i < sizes.count (); i++) | 154 | for (int i = 0; i < sizes.count (); i++) { | ||
154 | totalSize += sizes [i]; | 155 | totalSize += sizes [i]; | ||
156 | } | ||||
155 | 157 | | |||
156 | int margin = 1; | 158 | int margin = 1; | ||
157 | 159 | | |||
158 | // if don't fit with margin, then just return elements | 160 | // if don't fit with margin, then just return elements | ||
159 | // packed right next to each other | 161 | // packed right next to each other | ||
160 | if (totalSize + margin * 2 > max) | 162 | if (totalSize + margin * 2 > max) | ||
161 | { | 163 | { | ||
162 | retOffsets [0] = 0; | 164 | retOffsets [0] = 0; | ||
163 | for (int i = 1; i < sizes.count (); i++) | 165 | for (int i = 1; i < sizes.count (); i++) { | ||
164 | retOffsets [i] = retOffsets [i - 1] + sizes [i - 1]; | 166 | retOffsets [i] = retOffsets [i - 1] + sizes [i - 1]; | ||
167 | } | ||||
165 | 168 | | |||
166 | return retOffsets; | 169 | return retOffsets; | ||
167 | } | 170 | } | ||
168 | 171 | | |||
169 | int maxLeftOver = max - (totalSize + margin * 2 * sizes.count()); | 172 | int maxLeftOver = max - (totalSize + margin * 2 * sizes.count()); | ||
170 | 173 | | |||
171 | int startCompensating = -1; | 174 | int startCompensating = -1; | ||
172 | int numCompensate = 0; | 175 | int numCompensate = 0; | ||
Show All 34 Lines | 208 | { | |||
207 | 210 | | |||
208 | row = cfg.readEntry (objectName () + QLatin1String (" Row"), -1); | 211 | row = cfg.readEntry (objectName () + QLatin1String (" Row"), -1); | ||
209 | col = cfg.readEntry (objectName () + QLatin1String (" Col"), -1); | 212 | col = cfg.readEntry (objectName () + QLatin1String (" Col"), -1); | ||
210 | } | 213 | } | ||
211 | 214 | | |||
212 | #if DEBUG_KP_TOOL_WIDGET_BASE | 215 | #if DEBUG_KP_TOOL_WIDGET_BASE | ||
213 | qCDebug(kpLogWidgets) << "kpToolWidgetBase(" << objectName () | 216 | qCDebug(kpLogWidgets) << "kpToolWidgetBase(" << objectName () | ||
214 | << ")::defaultSelectedRowAndCol() returning row=" << row | 217 | << ")::defaultSelectedRowAndCol() returning row=" << row | ||
215 | << " col=" << col | 218 | << " col=" << col; | ||
216 | << endl; | | |||
217 | #endif | 219 | #endif | ||
218 | 220 | | |||
219 | return qMakePair (row, col); | 221 | return qMakePair (row, col); | ||
220 | } | 222 | } | ||
221 | 223 | | |||
222 | //--------------------------------------------------------------------- | 224 | //--------------------------------------------------------------------- | ||
223 | 225 | | |||
224 | // public | 226 | // public | ||
Show All 13 Lines | |||||
238 | //--------------------------------------------------------------------- | 240 | //--------------------------------------------------------------------- | ||
239 | 241 | | |||
240 | // public | 242 | // public | ||
241 | void kpToolWidgetBase::saveSelectedAsDefault () const | 243 | void kpToolWidgetBase::saveSelectedAsDefault () const | ||
242 | { | 244 | { | ||
243 | #if DEBUG_KP_TOOL_WIDGET_BASE | 245 | #if DEBUG_KP_TOOL_WIDGET_BASE | ||
244 | qCDebug(kpLogWidgets) << "kpToolWidgetBase(" << objectName () | 246 | qCDebug(kpLogWidgets) << "kpToolWidgetBase(" << objectName () | ||
245 | << ")::saveSelectedAsDefault() row=" << m_selectedRow | 247 | << ")::saveSelectedAsDefault() row=" << m_selectedRow | ||
246 | << " col=" << m_selectedCol << endl; | 248 | << " col=" << m_selectedCol; | ||
247 | #endif | 249 | #endif | ||
248 | 250 | | |||
249 | if (objectName ().isEmpty ()) | 251 | if (objectName ().isEmpty ()) { | ||
250 | return; | 252 | return; | ||
253 | } | ||||
251 | 254 | | |||
252 | KConfigGroup cfg (KSharedConfig::openConfig (), kpSettingsGroupTools); | 255 | KConfigGroup cfg (KSharedConfig::openConfig (), kpSettingsGroupTools); | ||
253 | 256 | | |||
254 | cfg.writeEntry (objectName () + QLatin1String (" Row"), m_selectedRow); | 257 | cfg.writeEntry (objectName () + QLatin1String (" Row"), m_selectedRow); | ||
255 | cfg.writeEntry (objectName () + QLatin1String (" Col"), m_selectedCol); | 258 | cfg.writeEntry (objectName () + QLatin1String (" Col"), m_selectedCol); | ||
256 | cfg.sync (); | 259 | cfg.sync (); | ||
257 | } | 260 | } | ||
258 | 261 | | |||
Show All 11 Lines | 269 | #endif | |||
270 | #if DEBUG_KP_TOOL_WIDGET_BASE | 273 | #if DEBUG_KP_TOOL_WIDGET_BASE | ||
271 | qCDebug(kpLogWidgets) << "\tkilling #" << m_pixmaps.count () - 1; | 274 | qCDebug(kpLogWidgets) << "\tkilling #" << m_pixmaps.count () - 1; | ||
272 | #endif | 275 | #endif | ||
273 | m_pixmaps.removeLast (); | 276 | m_pixmaps.removeLast (); | ||
274 | m_pixmapRects.removeLast (); | 277 | m_pixmapRects.removeLast (); | ||
275 | m_toolTips.removeLast (); | 278 | m_toolTips.removeLast (); | ||
276 | } | 279 | } | ||
277 | 280 | | |||
278 | if (m_pixmaps.isEmpty ()) | 281 | if (m_pixmaps.isEmpty ()) { | ||
279 | return; | 282 | return; | ||
283 | } | ||||
280 | 284 | | |||
281 | #if DEBUG_KP_TOOL_WIDGET_BASE | 285 | #if DEBUG_KP_TOOL_WIDGET_BASE | ||
282 | qCDebug(kpLogWidgets) << "\tsurvived killing of empty rows"; | 286 | qCDebug(kpLogWidgets) << "\tsurvived killing of empty rows"; | ||
283 | qCDebug(kpLogWidgets) << "\tfinding heights of rows:"; | 287 | qCDebug(kpLogWidgets) << "\tfinding heights of rows:"; | ||
284 | #endif | 288 | #endif | ||
285 | 289 | | |||
286 | QList <int> maxHeightOfRow; | 290 | QList <int> maxHeightOfRow; | ||
287 | for (int r = 0; r < m_pixmaps.count (); r++) | 291 | for (int r = 0; r < m_pixmaps.count (); r++) { | ||
288 | maxHeightOfRow.append (0); | 292 | maxHeightOfRow.append (0); | ||
293 | } | ||||
289 | 294 | | |||
290 | for (int r = 0; r < m_pixmaps.count (); r++) | 295 | for (int r = 0; r < m_pixmaps.count (); r++) | ||
291 | { | 296 | { | ||
292 | for (int c = 0; c < m_pixmaps [r].count (); c++) | 297 | for (int c = 0; c < m_pixmaps [r].count (); c++) | ||
293 | { | 298 | { | ||
294 | if (c == 0 || m_pixmaps [r][c].height () > maxHeightOfRow [r]) | 299 | if (c == 0 || m_pixmaps [r][c].height () > maxHeightOfRow [r]) { | ||
295 | maxHeightOfRow [r] = m_pixmaps [r][c].height (); | 300 | maxHeightOfRow [r] = m_pixmaps [r][c].height (); | ||
296 | } | 301 | } | ||
302 | } | ||||
297 | #if DEBUG_KP_TOOL_WIDGET_BASE | 303 | #if DEBUG_KP_TOOL_WIDGET_BASE | ||
298 | qCDebug(kpLogWidgets) << "\t\t" << r << ": " << maxHeightOfRow [r]; | 304 | qCDebug(kpLogWidgets) << "\t\t" << r << ": " << maxHeightOfRow [r]; | ||
299 | #endif | 305 | #endif | ||
300 | } | 306 | } | ||
301 | 307 | | |||
302 | QList <int> rowYOffset = spreadOutElements (maxHeightOfRow, height ()); | 308 | QList <int> rowYOffset = spreadOutElements (maxHeightOfRow, height ()); | ||
303 | #if DEBUG_KP_TOOL_WIDGET_BASE | 309 | #if DEBUG_KP_TOOL_WIDGET_BASE | ||
304 | qCDebug(kpLogWidgets) << "\tspread out offsets of rows:"; | 310 | qCDebug(kpLogWidgets) << "\tspread out offsets of rows:"; | ||
305 | for (int r = 0; r < (int) rowYOffset.count (); r++) | 311 | for (int r = 0; r < (int) rowYOffset.count (); r++) { | ||
306 | qCDebug(kpLogWidgets) << "\t\t" << r << ": " << rowYOffset [r]; | 312 | qCDebug(kpLogWidgets) << "\t\t" << r << ": " << rowYOffset [r]; | ||
313 | } | ||||
307 | #endif | 314 | #endif | ||
308 | 315 | | |||
309 | for (int r = 0; r < m_pixmaps.count (); r++) | 316 | for (int r = 0; r < m_pixmaps.count (); r++) | ||
310 | { | 317 | { | ||
311 | #if DEBUG_KP_TOOL_WIDGET_BASE | 318 | #if DEBUG_KP_TOOL_WIDGET_BASE | ||
312 | qCDebug(kpLogWidgets) << "\tlaying out row " << r << ":"; | 319 | qCDebug(kpLogWidgets) << "\tlaying out row " << r << ":"; | ||
313 | #endif | 320 | #endif | ||
314 | 321 | | |||
315 | QList <int> widths; | 322 | QList <int> widths; | ||
316 | for (int c = 0; c < m_pixmaps [r].count (); c++) | 323 | for (int c = 0; c < m_pixmaps [r].count (); c++) | ||
317 | widths.append (m_pixmaps [r][c].width ()); | 324 | widths.append (m_pixmaps [r][c].width ()); | ||
318 | #if DEBUG_KP_TOOL_WIDGET_BASE | 325 | #if DEBUG_KP_TOOL_WIDGET_BASE | ||
319 | qCDebug(kpLogWidgets) << "\t\twidths of cols:"; | 326 | qCDebug(kpLogWidgets) << "\t\twidths of cols:"; | ||
320 | for (int c = 0; c < m_pixmaps [r].count (); c++) | 327 | for (int c = 0; c < m_pixmaps [r].count (); c++) { | ||
321 | qCDebug(kpLogWidgets) << "\t\t\t" << c << ": " << widths [c]; | 328 | qCDebug(kpLogWidgets) << "\t\t\t" << c << ": " << widths [c]; | ||
329 | } | ||||
322 | #endif | 330 | #endif | ||
323 | 331 | | |||
324 | QList <int> colXOffset = spreadOutElements (widths, width ()); | 332 | QList <int> colXOffset = spreadOutElements (widths, width ()); | ||
325 | #if DEBUG_KP_TOOL_WIDGET_BASE | 333 | #if DEBUG_KP_TOOL_WIDGET_BASE | ||
326 | qCDebug(kpLogWidgets) << "\t\tspread out offsets of cols:"; | 334 | qCDebug(kpLogWidgets) << "\t\tspread out offsets of cols:"; | ||
327 | for (int c = 0; c < colXOffset.count (); c++) | 335 | for (int c = 0; c < colXOffset.count (); c++) { | ||
328 | qCDebug(kpLogWidgets) << "\t\t\t" << c << ": " << colXOffset [c]; | 336 | qCDebug(kpLogWidgets) << "\t\t\t" << c << ": " << colXOffset [c]; | ||
337 | } | ||||
329 | #endif | 338 | #endif | ||
330 | 339 | | |||
331 | for (int c = 0; c < colXOffset.count (); c++) | 340 | for (int c = 0; c < colXOffset.count (); c++) | ||
332 | { | 341 | { | ||
333 | int x = colXOffset [c]; | 342 | int x = colXOffset [c]; | ||
334 | int y = rowYOffset [r]; | 343 | int y = rowYOffset [r]; | ||
335 | int w, h; | 344 | int w, h; | ||
336 | 345 | | |||
337 | if (c == colXOffset.count () - 1) | 346 | if (c == colXOffset.count () - 1) | ||
338 | { | 347 | { | ||
339 | if (x + m_pixmaps [r][c].width () >= width ()) | 348 | if (x + m_pixmaps [r][c].width () >= width ()) { | ||
340 | w = m_pixmaps [r][c].width (); | 349 | w = m_pixmaps [r][c].width (); | ||
341 | else | 350 | } | ||
351 | else { | ||||
342 | w = width () - 1 - x; | 352 | w = width () - 1 - x; | ||
343 | } | 353 | } | ||
344 | else | 354 | } | ||
355 | else { | ||||
345 | w = colXOffset [c + 1] - x; | 356 | w = colXOffset [c + 1] - x; | ||
357 | } | ||||
346 | 358 | | |||
347 | if (r == m_pixmaps.count () - 1) | 359 | if (r == m_pixmaps.count () - 1) | ||
348 | { | 360 | { | ||
349 | if (y + m_pixmaps [r][c].height () >= height ()) | 361 | if (y + m_pixmaps [r][c].height () >= height ()) { | ||
350 | h = m_pixmaps [r][c].height (); | 362 | h = m_pixmaps [r][c].height (); | ||
351 | else | 363 | } | ||
364 | else { | ||||
352 | h = height () - 1 - y; | 365 | h = height () - 1 - y; | ||
353 | } | 366 | } | ||
354 | else | 367 | } | ||
368 | else { | ||||
355 | h = rowYOffset [r + 1] - y; | 369 | h = rowYOffset [r + 1] - y; | ||
370 | } | ||||
356 | 371 | | |||
357 | m_pixmapRects [r][c] = QRect (x, y, w, h); | 372 | m_pixmapRects [r][c] = QRect (x, y, w, h); | ||
358 | } | 373 | } | ||
359 | } | 374 | } | ||
360 | 375 | | |||
361 | update (); | 376 | update (); | ||
362 | } | 377 | } | ||
363 | 378 | | |||
Show All 22 Lines | 400 | { | |||
386 | if (m_selectedRow < 0 || | 401 | if (m_selectedRow < 0 || | ||
387 | m_selectedRow >= m_pixmaps.count () || | 402 | m_selectedRow >= m_pixmaps.count () || | ||
388 | m_selectedCol < 0) | 403 | m_selectedCol < 0) | ||
389 | { | 404 | { | ||
390 | return -1; | 405 | return -1; | ||
391 | } | 406 | } | ||
392 | 407 | | |||
393 | int upto = 0; | 408 | int upto = 0; | ||
394 | for (int y = 0; y < m_selectedRow; y++) | 409 | for (int y = 0; y < m_selectedRow; y++) { | ||
395 | upto += m_pixmaps [y].count (); | 410 | upto += m_pixmaps [y].count (); | ||
411 | } | ||||
396 | 412 | | |||
397 | if (m_selectedCol >= m_pixmaps [m_selectedRow].count ()) | 413 | if (m_selectedCol >= m_pixmaps [m_selectedRow].count ()) { | ||
398 | return -1; | 414 | return -1; | ||
415 | } | ||||
399 | 416 | | |||
400 | upto += m_selectedCol; | 417 | upto += m_selectedCol; | ||
401 | 418 | | |||
402 | return upto; | 419 | return upto; | ||
403 | } | 420 | } | ||
404 | 421 | | |||
405 | //--------------------------------------------------------------------- | 422 | //--------------------------------------------------------------------- | ||
406 | 423 | | |||
407 | 424 | | |||
408 | // public | 425 | // public | ||
409 | bool kpToolWidgetBase::hasPreviousOption (int *row, int *col) const | 426 | bool kpToolWidgetBase::hasPreviousOption (int *row, int *col) const | ||
410 | { | 427 | { | ||
411 | #if DEBUG_KP_TOOL_WIDGET_BASE | 428 | #if DEBUG_KP_TOOL_WIDGET_BASE | ||
412 | qCDebug(kpLogWidgets) << "kpToolWidgetBase(" << objectName () | 429 | qCDebug(kpLogWidgets) << "kpToolWidgetBase(" << objectName () | ||
413 | << ")::hasPreviousOption() current row=" << m_selectedRow | 430 | << ")::hasPreviousOption() current row=" << m_selectedRow | ||
414 | << " col=" << m_selectedCol | 431 | << " col=" << m_selectedCol; | ||
415 | << endl; | | |||
416 | #endif | 432 | #endif | ||
417 | if (row) | 433 | if (row) { | ||
418 | *row = -1; | 434 | *row = -1; | ||
419 | if (col) | 435 | } | ||
436 | if (col) { | ||||
420 | *col = -1; | 437 | *col = -1; | ||
438 | } | ||||
421 | 439 | | |||
422 | 440 | | |||
423 | if (m_selectedRow < 0 || m_selectedCol < 0) | 441 | if (m_selectedRow < 0 || m_selectedCol < 0) { | ||
424 | return false; | 442 | return false; | ||
443 | } | ||||
425 | 444 | | |||
426 | int newRow = m_selectedRow, | 445 | int newRow = m_selectedRow, | ||
427 | newCol = m_selectedCol; | 446 | newCol = m_selectedCol; | ||
428 | 447 | | |||
429 | newCol--; | 448 | newCol--; | ||
430 | if (newCol < 0) | 449 | if (newCol < 0) | ||
431 | { | 450 | { | ||
432 | newRow--; | 451 | newRow--; | ||
433 | if (newRow < 0) | 452 | if (newRow < 0) { | ||
434 | return false; | 453 | return false; | ||
454 | } | ||||
435 | 455 | | |||
436 | newCol = m_pixmaps [newRow].count () - 1; | 456 | newCol = m_pixmaps [newRow].count () - 1; | ||
437 | if (newCol < 0) | 457 | if (newCol < 0) { | ||
438 | return false; | 458 | return false; | ||
439 | } | 459 | } | ||
460 | } | ||||
440 | 461 | | |||
441 | 462 | | |||
442 | if (row) | 463 | if (row) { | ||
443 | *row = newRow; | 464 | *row = newRow; | ||
444 | if (col) | 465 | } | ||
466 | if (col) { | ||||
445 | *col = newCol; | 467 | *col = newCol; | ||
468 | } | ||||
446 | 469 | | |||
447 | return true; | 470 | return true; | ||
448 | } | 471 | } | ||
449 | 472 | | |||
450 | //--------------------------------------------------------------------- | 473 | //--------------------------------------------------------------------- | ||
451 | 474 | | |||
452 | // public | 475 | // public | ||
453 | bool kpToolWidgetBase::hasNextOption (int *row, int *col) const | 476 | bool kpToolWidgetBase::hasNextOption (int *row, int *col) const | ||
454 | { | 477 | { | ||
455 | #if DEBUG_KP_TOOL_WIDGET_BASE | 478 | #if DEBUG_KP_TOOL_WIDGET_BASE | ||
456 | qCDebug(kpLogWidgets) << "kpToolWidgetBase(" << objectName () | 479 | qCDebug(kpLogWidgets) << "kpToolWidgetBase(" << objectName () | ||
457 | << ")::hasNextOption() current row=" << m_selectedRow | 480 | << ")::hasNextOption() current row=" << m_selectedRow | ||
458 | << " col=" << m_selectedCol | 481 | << " col=" << m_selectedCol; | ||
459 | << endl; | | |||
460 | #endif | 482 | #endif | ||
461 | 483 | | |||
462 | if (row) | 484 | if (row) { | ||
463 | *row = -1; | 485 | *row = -1; | ||
464 | if (col) | 486 | } | ||
487 | if (col) { | ||||
465 | *col = -1; | 488 | *col = -1; | ||
489 | } | ||||
466 | 490 | | |||
467 | 491 | | |||
468 | if (m_selectedRow < 0 || m_selectedCol < 0) | 492 | if (m_selectedRow < 0 || m_selectedCol < 0) { | ||
469 | return false; | 493 | return false; | ||
494 | } | ||||
470 | 495 | | |||
471 | int newRow = m_selectedRow, | 496 | int newRow = m_selectedRow, | ||
472 | newCol = m_selectedCol; | 497 | newCol = m_selectedCol; | ||
473 | 498 | | |||
474 | newCol++; | 499 | newCol++; | ||
475 | if (newCol >= m_pixmaps [newRow].count ()) | 500 | if (newCol >= m_pixmaps [newRow].count ()) | ||
476 | { | 501 | { | ||
477 | newRow++; | 502 | newRow++; | ||
478 | if (newRow >= m_pixmaps.count ()) | 503 | if (newRow >= m_pixmaps.count ()) { | ||
479 | return false; | 504 | return false; | ||
505 | } | ||||
480 | 506 | | |||
481 | newCol = 0; | 507 | newCol = 0; | ||
482 | if (newCol >= m_pixmaps [newRow].count ()) | 508 | if (newCol >= m_pixmaps [newRow].count ()) { | ||
483 | return false; | 509 | return false; | ||
484 | } | 510 | } | ||
511 | } | ||||
485 | 512 | | |||
486 | 513 | | |||
487 | if (row) | 514 | if (row) { | ||
488 | *row = newRow; | 515 | *row = newRow; | ||
489 | if (col) | 516 | } | ||
517 | if (col) { | ||||
490 | *col = newCol; | 518 | *col = newCol; | ||
519 | } | ||||
491 | 520 | | |||
492 | return true; | 521 | return true; | ||
493 | } | 522 | } | ||
494 | 523 | | |||
495 | //--------------------------------------------------------------------- | 524 | //--------------------------------------------------------------------- | ||
496 | 525 | | |||
497 | 526 | | |||
498 | // public slot virtual | 527 | // public slot virtual | ||
499 | bool kpToolWidgetBase::setSelected (int row, int col, bool saveAsDefault) | 528 | bool kpToolWidgetBase::setSelected (int row, int col, bool saveAsDefault) | ||
500 | { | 529 | { | ||
501 | #if DEBUG_KP_TOOL_WIDGET_BASE | 530 | #if DEBUG_KP_TOOL_WIDGET_BASE | ||
502 | qCDebug(kpLogWidgets) << "kpToolWidgetBase::setSelected(row=" << row | 531 | qCDebug(kpLogWidgets) << "kpToolWidgetBase::setSelected(row=" << row | ||
503 | << ",col=" << col | 532 | << ",col=" << col | ||
504 | << ",saveAsDefault=" << saveAsDefault | 533 | << ",saveAsDefault=" << saveAsDefault | ||
505 | << ")" | 534 | << ")"; | ||
506 | << endl; | | |||
507 | #endif | 535 | #endif | ||
508 | 536 | | |||
509 | if (row < 0 || col < 0 || | 537 | if (row < 0 || col < 0 || | ||
510 | row >= m_pixmapRects.count () || col >= m_pixmapRects [row].count ()) | 538 | row >= m_pixmapRects.count () || col >= m_pixmapRects [row].count ()) | ||
511 | { | 539 | { | ||
512 | #if DEBUG_KP_TOOL_WIDGET_BASE | 540 | #if DEBUG_KP_TOOL_WIDGET_BASE | ||
513 | qCDebug(kpLogWidgets) << "\tout of range"; | 541 | qCDebug(kpLogWidgets) << "\tout of range"; | ||
514 | #endif | 542 | #endif | ||
515 | return false; | 543 | return false; | ||
516 | } | 544 | } | ||
517 | 545 | | |||
518 | if (row == m_selectedRow && col == m_selectedCol) | 546 | if (row == m_selectedRow && col == m_selectedCol) | ||
519 | { | 547 | { | ||
520 | #if DEBUG_KP_TOOL_WIDGET_BASE | 548 | #if DEBUG_KP_TOOL_WIDGET_BASE | ||
521 | qCDebug(kpLogWidgets) << "\tNOP"; | 549 | qCDebug(kpLogWidgets) << "\tNOP"; | ||
522 | #endif | 550 | #endif | ||
523 | 551 | | |||
524 | if (saveAsDefault) | 552 | if (saveAsDefault) { | ||
525 | saveSelectedAsDefault (); | 553 | saveSelectedAsDefault (); | ||
554 | } | ||||
526 | 555 | | |||
527 | return true; | 556 | return true; | ||
528 | } | 557 | } | ||
529 | 558 | | |||
530 | const int wasSelectedRow = m_selectedRow; | 559 | const int wasSelectedRow = m_selectedRow; | ||
531 | const int wasSelectedCol = m_selectedCol; | 560 | const int wasSelectedCol = m_selectedCol; | ||
532 | 561 | | |||
533 | m_selectedRow = row; | 562 | m_selectedRow = row; | ||
534 | m_selectedCol = col; | 563 | m_selectedCol = col; | ||
535 | 564 | | |||
536 | if (wasSelectedRow >= 0 && wasSelectedCol >= 0) | 565 | if (wasSelectedRow >= 0 && wasSelectedCol >= 0) | ||
537 | { | 566 | { | ||
538 | // unhighlight old option | 567 | // unhighlight old option | ||
539 | update (m_pixmapRects [wasSelectedRow][wasSelectedCol]); | 568 | update (m_pixmapRects [wasSelectedRow][wasSelectedCol]); | ||
540 | } | 569 | } | ||
541 | 570 | | |||
542 | // highlight new option | 571 | // highlight new option | ||
543 | update (m_pixmapRects [row][col]); | 572 | update (m_pixmapRects [row][col]); | ||
544 | 573 | | |||
545 | #if DEBUG_KP_TOOL_WIDGET_BASE | 574 | #if DEBUG_KP_TOOL_WIDGET_BASE | ||
546 | qCDebug(kpLogWidgets) << "\tOK"; | 575 | qCDebug(kpLogWidgets) << "\tOK"; | ||
547 | #endif | 576 | #endif | ||
548 | 577 | | |||
549 | if (saveAsDefault) | 578 | if (saveAsDefault) { | ||
550 | saveSelectedAsDefault (); | 579 | saveSelectedAsDefault (); | ||
580 | } | ||||
551 | 581 | | |||
552 | emit optionSelected (row, col); | 582 | emit optionSelected (row, col); | ||
553 | return true; | 583 | return true; | ||
554 | } | 584 | } | ||
555 | 585 | | |||
556 | //--------------------------------------------------------------------- | 586 | //--------------------------------------------------------------------- | ||
557 | 587 | | |||
558 | // public slot | 588 | // public slot | ||
559 | bool kpToolWidgetBase::setSelected (int row, int col) | 589 | bool kpToolWidgetBase::setSelected (int row, int col) | ||
560 | { | 590 | { | ||
561 | return setSelected (row, col, true/*set as default*/); | 591 | return setSelected (row, col, true/*set as default*/); | ||
562 | } | 592 | } | ||
563 | 593 | | |||
564 | //--------------------------------------------------------------------- | 594 | //--------------------------------------------------------------------- | ||
565 | 595 | | |||
566 | 596 | | |||
567 | // public slot | 597 | // public slot | ||
568 | bool kpToolWidgetBase::selectPreviousOption () | 598 | bool kpToolWidgetBase::selectPreviousOption () | ||
569 | { | 599 | { | ||
570 | int newRow, newCol; | 600 | int newRow, newCol; | ||
571 | if (!hasPreviousOption (&newRow, &newCol)) | 601 | if (!hasPreviousOption (&newRow, &newCol)) { | ||
572 | return false; | 602 | return false; | ||
603 | } | ||||
573 | 604 | | |||
574 | return setSelected (newRow, newCol); | 605 | return setSelected (newRow, newCol); | ||
575 | } | 606 | } | ||
576 | 607 | | |||
577 | //--------------------------------------------------------------------- | 608 | //--------------------------------------------------------------------- | ||
578 | 609 | | |||
579 | // public slot | 610 | // public slot | ||
580 | bool kpToolWidgetBase::selectNextOption () | 611 | bool kpToolWidgetBase::selectNextOption () | ||
581 | { | 612 | { | ||
582 | int newRow, newCol; | 613 | int newRow, newCol; | ||
583 | if (!hasNextOption (&newRow, &newCol)) | 614 | if (!hasNextOption (&newRow, &newCol)) { | ||
584 | return false; | 615 | return false; | ||
616 | } | ||||
585 | 617 | | |||
586 | return setSelected (newRow, newCol); | 618 | return setSelected (newRow, newCol); | ||
587 | } | 619 | } | ||
588 | 620 | | |||
589 | //--------------------------------------------------------------------- | 621 | //--------------------------------------------------------------------- | ||
590 | 622 | | |||
591 | 623 | | |||
592 | // protected virtual [base QWidget] | 624 | // protected virtual [base QWidget] | ||
593 | bool kpToolWidgetBase::event (QEvent *e) | 625 | bool kpToolWidgetBase::event (QEvent *e) | ||
594 | { | 626 | { | ||
595 | // TODO: It's unclear when we should call the base, call accept() and | 627 | // TODO: It's unclear when we should call the base, call accept() and | ||
596 | // return true or false. Look at other event() handlers. The | 628 | // return true or false. Look at other event() handlers. The | ||
597 | // kpToolText one is wrong since after calling accept(), it calls | 629 | // kpToolText one is wrong since after calling accept(), it calls | ||
598 | // its base which calls ignore() :) | 630 | // its base which calls ignore() :) | ||
599 | if (e->type () == QEvent::ToolTip) | 631 | if (e->type () == QEvent::ToolTip) | ||
600 | { | 632 | { | ||
601 | QHelpEvent *he = dynamic_cast<QHelpEvent *> (e); | 633 | auto *he = dynamic_cast<QHelpEvent *> (e); | ||
602 | #if DEBUG_KP_TOOL_WIDGET_BASE | 634 | #if DEBUG_KP_TOOL_WIDGET_BASE | ||
603 | qCDebug(kpLogWidgets) << "kpToolWidgetBase::event() QHelpEvent pos=" << he->pos (); | 635 | qCDebug(kpLogWidgets) << "kpToolWidgetBase::event() QHelpEvent pos=" << he->pos (); | ||
604 | #endif | 636 | #endif | ||
605 | 637 | | |||
606 | bool showedText = false; | 638 | bool showedText = false; | ||
607 | for (int r = 0; r < m_pixmapRects.count (); r++) | 639 | for (int r = 0; r < m_pixmapRects.count (); r++) | ||
608 | { | 640 | { | ||
609 | for (int c = 0; c < m_pixmapRects [r].count (); c++) | 641 | for (int c = 0; c < m_pixmapRects [r].count (); c++) | ||
610 | { | 642 | { | ||
611 | if (m_pixmapRects [r][c].contains (he->pos ())) | 643 | if (m_pixmapRects [r][c].contains (he->pos ())) | ||
612 | { | 644 | { | ||
613 | const QString tip = m_toolTips [r][c]; | 645 | const QString tip = m_toolTips [r][c]; | ||
614 | #if DEBUG_KP_TOOL_WIDGET_BASE | 646 | #if DEBUG_KP_TOOL_WIDGET_BASE | ||
615 | qCDebug(kpLogWidgets) << "\tin option: r=" << r << "c=" << c | 647 | qCDebug(kpLogWidgets) << "\tin option: r=" << r << "c=" << c | ||
616 | << "tip='" << tip << "'" << endl; | 648 | << "tip='" << tip << "'"; | ||
617 | #endif | 649 | #endif | ||
618 | if (!tip.isEmpty ()) | 650 | if (!tip.isEmpty ()) | ||
619 | { | 651 | { | ||
620 | QToolTip::showText (he->globalPos (), tip, this); | 652 | QToolTip::showText (he->globalPos (), tip, this); | ||
621 | showedText = true; | 653 | showedText = true; | ||
622 | } | 654 | } | ||
623 | 655 | | |||
624 | e->accept (); | 656 | e->accept (); | ||
625 | goto exit_loops; | 657 | goto exit_loops; | ||
626 | } | 658 | } | ||
627 | } | 659 | } | ||
628 | } | 660 | } | ||
629 | 661 | | |||
630 | exit_loops: | 662 | exit_loops: | ||
631 | if (!showedText) | 663 | if (!showedText) | ||
632 | { | 664 | { | ||
633 | #if DEBUG_KP_TOOL_WIDGET_BASE | 665 | #if DEBUG_KP_TOOL_WIDGET_BASE | ||
634 | qCDebug(kpLogWidgets) << "\thiding text"; | 666 | qCDebug(kpLogWidgets) << "\thiding text"; | ||
635 | #endif | 667 | #endif | ||
636 | QToolTip::hideText (); | 668 | QToolTip::hideText (); | ||
637 | } | 669 | } | ||
638 | 670 | | |||
639 | return true; | 671 | return true; | ||
640 | } | 672 | } | ||
641 | else | 673 | | ||
642 | return QWidget::event (e); | 674 | return QWidget::event (e); | ||
643 | } | 675 | } | ||
644 | 676 | | |||
645 | //--------------------------------------------------------------------- | 677 | //--------------------------------------------------------------------- | ||
646 | 678 | | |||
647 | 679 | | |||
648 | // protected virtual [base QWidget] | 680 | // protected virtual [base QWidget] | ||
649 | void kpToolWidgetBase::mousePressEvent (QMouseEvent *e) | 681 | void kpToolWidgetBase::mousePressEvent (QMouseEvent *e) | ||
650 | { | 682 | { | ||
651 | e->ignore (); | 683 | e->ignore (); | ||
652 | 684 | | |||
653 | if (e->button () != Qt::LeftButton) | 685 | if (e->button () != Qt::LeftButton) { | ||
654 | return; | 686 | return; | ||
687 | } | ||||
655 | 688 | | |||
656 | 689 | | |||
657 | for (int i = 0; i < m_pixmapRects.count (); i++) | 690 | for (int i = 0; i < m_pixmapRects.count (); i++) | ||
658 | { | 691 | { | ||
659 | for (int j = 0; j < m_pixmapRects [i].count (); j++) | 692 | for (int j = 0; j < m_pixmapRects [i].count (); j++) | ||
660 | { | 693 | { | ||
661 | if (m_pixmapRects [i][j].contains (e->pos ())) | 694 | if (m_pixmapRects [i][j].contains (e->pos ())) | ||
662 | { | 695 | { | ||
Show All 38 Lines | 731 | #endif | |||
701 | { | 734 | { | ||
702 | painter.fillRect(rect, palette().color(QPalette::Highlight).rgb()); | 735 | painter.fillRect(rect, palette().color(QPalette::Highlight).rgb()); | ||
703 | } | 736 | } | ||
704 | 737 | | |||
705 | #if DEBUG_KP_TOOL_WIDGET_BASE && 1 | 738 | #if DEBUG_KP_TOOL_WIDGET_BASE && 1 | ||
706 | qCDebug(kpLogWidgets) << "\t\t\tdraw pixmap @ x=" | 739 | qCDebug(kpLogWidgets) << "\t\t\tdraw pixmap @ x=" | ||
707 | << rect.x () + (rect.width () - pixmap.width ()) / 2 | 740 | << rect.x () + (rect.width () - pixmap.width ()) / 2 | ||
708 | << " y=" | 741 | << " y=" | ||
709 | << rect.y () + (rect.height () - pixmap.height ()) / 2 | 742 | << rect.y () + (rect.height () - pixmap.height ()) / 2; | ||
710 | << endl; | | |||
711 | 743 | | |||
712 | #endif | 744 | #endif | ||
713 | 745 | | |||
714 | painter.drawPixmap(QPoint(rect.x () + (rect.width () - pixmap.width ()) / 2, | 746 | painter.drawPixmap(QPoint(rect.x () + (rect.width () - pixmap.width ()) / 2, | ||
715 | rect.y () + (rect.height () - pixmap.height ()) / 2), | 747 | rect.y () + (rect.height () - pixmap.height ()) / 2), | ||
716 | pixmap); | 748 | pixmap); | ||
717 | } | 749 | } | ||
718 | } | 750 | } | ||
719 | } | 751 | } | ||
720 | 752 | | |||
721 | //--------------------------------------------------------------------- | 753 | //--------------------------------------------------------------------- | ||
722 | 754 | |