Changeset View
Changeset View
Standalone View
Standalone View
widgets/toolbars/kpToolToolBar.cpp
Show First 20 Lines • Show All 59 Lines • ▼ Show 20 Line(s) | 56 | public: | |||
---|---|---|---|---|---|
60 | { | 60 | { | ||
61 | } | 61 | } | ||
62 | 62 | | |||
63 | kpTool *tool() const { return m_tool; } | 63 | kpTool *tool() const { return m_tool; } | ||
64 | 64 | | |||
65 | protected: | 65 | protected: | ||
66 | void mouseDoubleClickEvent(QMouseEvent *e) override | 66 | void mouseDoubleClickEvent(QMouseEvent *e) override | ||
67 | { | 67 | { | ||
68 | if (e->button () == Qt::LeftButton && m_tool) | 68 | if (e->button () == Qt::LeftButton && m_tool) { | ||
69 | m_tool->globalDraw (); | 69 | m_tool->globalDraw (); | ||
70 | } | 70 | } | ||
71 | } | ||||
71 | 72 | | |||
72 | kpTool *m_tool; | 73 | kpTool *m_tool; | ||
73 | }; | 74 | }; | ||
74 | 75 | | |||
75 | //--------------------------------------------------------------------- | 76 | //--------------------------------------------------------------------- | ||
76 | 77 | | |||
77 | kpToolToolBar::kpToolToolBar(const QString &name, int colsOrRows, QMainWindow *parent) | 78 | kpToolToolBar::kpToolToolBar(const QString &name, int colsOrRows, QMainWindow *parent) | ||
78 | : KToolBar(name, parent, Qt::LeftToolBarArea), | 79 | : KToolBar(name, parent, Qt::LeftToolBarArea), | ||
Show All 14 Lines | 93 | m_toolWidgets.append (m_toolWidgetFillStyle = | |||
93 | new kpToolWidgetFillStyle (m_baseWidget, "Tool Widget Fill Style")); | 94 | new kpToolWidgetFillStyle (m_baseWidget, "Tool Widget Fill Style")); | ||
94 | m_toolWidgets.append (m_toolWidgetLineWidth = | 95 | m_toolWidgets.append (m_toolWidgetLineWidth = | ||
95 | new kpToolWidgetLineWidth (m_baseWidget, "Tool Widget Line Width")); | 96 | new kpToolWidgetLineWidth (m_baseWidget, "Tool Widget Line Width")); | ||
96 | m_toolWidgets.append (m_toolWidgetOpaqueOrTransparent = | 97 | m_toolWidgets.append (m_toolWidgetOpaqueOrTransparent = | ||
97 | new kpToolWidgetOpaqueOrTransparent (m_baseWidget, "Tool Widget Opaque/Transparent")); | 98 | new kpToolWidgetOpaqueOrTransparent (m_baseWidget, "Tool Widget Opaque/Transparent")); | ||
98 | m_toolWidgets.append (m_toolWidgetSpraycanSize = | 99 | m_toolWidgets.append (m_toolWidgetSpraycanSize = | ||
99 | new kpToolWidgetSpraycanSize (m_baseWidget, "Tool Widget Spraycan Size")); | 100 | new kpToolWidgetSpraycanSize (m_baseWidget, "Tool Widget Spraycan Size")); | ||
100 | 101 | | |||
101 | foreach(kpToolWidgetBase *w, m_toolWidgets) | 102 | for (auto *w : m_toolWidgets) | ||
102 | { | 103 | { | ||
103 | connect (w, &kpToolWidgetBase::optionSelected, | 104 | connect (w, &kpToolWidgetBase::optionSelected, | ||
104 | this, &kpToolToolBar::toolWidgetOptionSelected); | 105 | this, &kpToolToolBar::toolWidgetOptionSelected); | ||
105 | } | 106 | } | ||
106 | 107 | | |||
107 | adjustToOrientation(orientation()); | 108 | adjustToOrientation(orientation()); | ||
108 | connect (this, &kpToolToolBar::orientationChanged, | 109 | connect (this, &kpToolToolBar::orientationChanged, | ||
109 | this, &kpToolToolBar::adjustToOrientation); | 110 | this, &kpToolToolBar::adjustToOrientation); | ||
Show All 13 Lines | |||||
123 | connect (this, &kpToolToolBar::toolButtonStyleChanged, | 124 | connect (this, &kpToolToolBar::toolButtonStyleChanged, | ||
124 | this, &kpToolToolBar::slotToolButtonStyleChanged); | 125 | this, &kpToolToolBar::slotToolButtonStyleChanged); | ||
125 | } | 126 | } | ||
126 | 127 | | |||
127 | //--------------------------------------------------------------------- | 128 | //--------------------------------------------------------------------- | ||
128 | 129 | | |||
129 | kpToolToolBar::~kpToolToolBar() | 130 | kpToolToolBar::~kpToolToolBar() | ||
130 | { | 131 | { | ||
131 | while ( !m_toolButtons.isEmpty() ) | 132 | while ( !m_toolButtons.isEmpty() ) { | ||
132 | delete m_toolButtons.takeFirst(); | 133 | delete m_toolButtons.takeFirst(); | ||
133 | } | 134 | } | ||
135 | } | ||||
134 | 136 | | |||
135 | //--------------------------------------------------------------------- | 137 | //--------------------------------------------------------------------- | ||
136 | 138 | | |||
137 | // public | 139 | // public | ||
138 | void kpToolToolBar::registerTool (kpTool *tool) | 140 | void kpToolToolBar::registerTool (kpTool *tool) | ||
139 | { | 141 | { | ||
140 | foreach (const kpToolButton *b, m_toolButtons) | 142 | for (const auto *b : m_toolButtons) | ||
141 | { | 143 | { | ||
142 | if ( b->tool() == tool ) // already given | 144 | if ( b->tool() == tool ) { // already given | ||
143 | return; | 145 | return; | ||
144 | } | 146 | } | ||
147 | } | ||||
145 | 148 | | |||
146 | kpToolButton *b = new kpToolButton(tool, m_baseWidget); | 149 | auto *b = new kpToolButton(tool, m_baseWidget); | ||
147 | 150 | | |||
148 | b->setToolButtonStyle(toolButtonStyle()); | 151 | b->setToolButtonStyle(toolButtonStyle()); | ||
149 | b->setIconSize(iconSize()); | 152 | b->setIconSize(iconSize()); | ||
150 | b->setAutoRaise(true); | 153 | b->setAutoRaise(true); | ||
151 | 154 | | |||
152 | // tell layout to make all with equal width (much better when text-below-icon) | 155 | // tell layout to make all with equal width (much better when text-below-icon) | ||
153 | b->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); | 156 | b->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); | ||
154 | 157 | | |||
Show All 38 Lines | |||||
193 | //--------------------------------------------------------------------- | 196 | //--------------------------------------------------------------------- | ||
194 | 197 | | |||
195 | // public | 198 | // public | ||
196 | void kpToolToolBar::selectTool (const kpTool *tool, bool reselectIfSameTool) | 199 | void kpToolToolBar::selectTool (const kpTool *tool, bool reselectIfSameTool) | ||
197 | { | 200 | { | ||
198 | qCDebug(kpLogWidgets) << "kpToolToolBar::selectTool (tool=" << tool | 201 | qCDebug(kpLogWidgets) << "kpToolToolBar::selectTool (tool=" << tool | ||
199 | << ") currentTool=" << m_currentTool; | 202 | << ") currentTool=" << m_currentTool; | ||
200 | 203 | | |||
201 | if (!reselectIfSameTool && tool == m_currentTool) | 204 | if (!reselectIfSameTool && tool == m_currentTool) { | ||
202 | return; | 205 | return; | ||
206 | } | ||||
203 | 207 | | |||
204 | if (tool) | 208 | if (tool) | ||
205 | { | 209 | { | ||
206 | tool->action()->setChecked(true); | 210 | tool->action()->setChecked(true); | ||
207 | slotToolButtonClicked(); | 211 | slotToolButtonClicked(); | ||
208 | } | 212 | } | ||
209 | else | 213 | else | ||
210 | { | 214 | { | ||
Show All 33 Lines | 247 | { | |||
244 | selectTool (m_previousTool); | 248 | selectTool (m_previousTool); | ||
245 | } | 249 | } | ||
246 | 250 | | |||
247 | //--------------------------------------------------------------------- | 251 | //--------------------------------------------------------------------- | ||
248 | 252 | | |||
249 | // public | 253 | // public | ||
250 | void kpToolToolBar::hideAllToolWidgets () | 254 | void kpToolToolBar::hideAllToolWidgets () | ||
251 | { | 255 | { | ||
252 | foreach(kpToolWidgetBase *w, m_toolWidgets) | 256 | for (auto *w : m_toolWidgets) { | ||
253 | w->hide (); | 257 | w->hide (); | ||
254 | } | 258 | } | ||
259 | } | ||||
255 | 260 | | |||
256 | //--------------------------------------------------------------------- | 261 | //--------------------------------------------------------------------- | ||
257 | 262 | | |||
258 | // public | 263 | // public | ||
259 | kpToolWidgetBase *kpToolToolBar::shownToolWidget (int which) const | 264 | kpToolWidgetBase *kpToolToolBar::shownToolWidget (int which) const | ||
260 | { | 265 | { | ||
261 | int uptoVisibleWidget = 0; | 266 | int uptoVisibleWidget = 0; | ||
262 | 267 | | |||
263 | foreach(kpToolWidgetBase *w, m_toolWidgets) | 268 | for(auto *w : m_toolWidgets) | ||
264 | { | 269 | { | ||
265 | if ( !w->isHidden() ) | 270 | if ( !w->isHidden() ) | ||
266 | { | 271 | { | ||
267 | if (which == uptoVisibleWidget) | 272 | if (which == uptoVisibleWidget) { | ||
268 | return w; | 273 | return w; | ||
274 | } | ||||
269 | 275 | | |||
270 | uptoVisibleWidget++; | 276 | uptoVisibleWidget++; | ||
271 | } | 277 | } | ||
272 | } | 278 | } | ||
273 | 279 | | |||
274 | return nullptr; | 280 | return nullptr; | ||
275 | } | 281 | } | ||
276 | 282 | | |||
277 | //--------------------------------------------------------------------- | 283 | //--------------------------------------------------------------------- | ||
278 | 284 | | |||
279 | // private slot | 285 | // private slot | ||
280 | void kpToolToolBar::slotToolButtonClicked () | 286 | void kpToolToolBar::slotToolButtonClicked () | ||
281 | { | 287 | { | ||
282 | QAbstractButton *b = m_buttonGroup->checkedButton(); | 288 | QAbstractButton *b = m_buttonGroup->checkedButton(); | ||
283 | 289 | | |||
284 | qCDebug(kpLogWidgets) << "kpToolToolBar::slotToolButtonClicked() button=" << b; | 290 | qCDebug(kpLogWidgets) << "kpToolToolBar::slotToolButtonClicked() button=" << b; | ||
285 | 291 | | |||
286 | kpTool *tool = nullptr; | 292 | kpTool *tool = nullptr; | ||
287 | foreach (const kpToolButton *button, m_toolButtons) | 293 | for (const auto *button : m_toolButtons) | ||
288 | { | 294 | { | ||
289 | if ( button == b ) | 295 | if ( button == b ) | ||
290 | { | 296 | { | ||
291 | tool = button->tool(); | 297 | tool = button->tool(); | ||
292 | break; | 298 | break; | ||
293 | } | 299 | } | ||
294 | } | 300 | } | ||
295 | 301 | | |||
296 | qCDebug(kpLogWidgets) << "\ttool=" << tool | 302 | qCDebug(kpLogWidgets) << "\ttool=" << tool | ||
297 | << " currentTool=" << m_currentTool; | 303 | << " currentTool=" << m_currentTool; | ||
298 | 304 | | |||
299 | if (tool == m_currentTool) | 305 | if (tool == m_currentTool) | ||
300 | { | 306 | { | ||
301 | if (m_currentTool) | 307 | if (m_currentTool) { | ||
302 | m_currentTool->reselect (); | 308 | m_currentTool->reselect (); | ||
309 | } | ||||
303 | 310 | | |||
304 | return; | 311 | return; | ||
305 | } | 312 | } | ||
306 | 313 | | |||
307 | if (m_currentTool) | 314 | if (m_currentTool) { | ||
308 | m_currentTool->endInternal (); | 315 | m_currentTool->endInternal (); | ||
316 | } | ||||
309 | 317 | | |||
310 | m_previousTool = m_currentTool; | 318 | m_previousTool = m_currentTool; | ||
311 | m_currentTool = tool; | 319 | m_currentTool = tool; | ||
312 | 320 | | |||
313 | if (m_currentTool) | 321 | if (m_currentTool) | ||
314 | { | 322 | { | ||
315 | kpToolAction *action = m_currentTool->action (); | 323 | kpToolAction *action = m_currentTool->action (); | ||
316 | if (action) | 324 | if (action) | ||
Show All 9 Lines | |||||
326 | adjustSizeConstraint(); | 334 | adjustSizeConstraint(); | ||
327 | } | 335 | } | ||
328 | 336 | | |||
329 | //--------------------------------------------------------------------- | 337 | //--------------------------------------------------------------------- | ||
330 | 338 | | |||
331 | // private slot | 339 | // private slot | ||
332 | void kpToolToolBar::slotToolActionActivated () | 340 | void kpToolToolBar::slotToolActionActivated () | ||
333 | { | 341 | { | ||
334 | const kpTool *tool = dynamic_cast<const kpTool *>(sender()); | 342 | const auto *tool = dynamic_cast<const kpTool *>(sender()); | ||
335 | 343 | | |||
336 | qCDebug(kpLogWidgets) << "kpToolToolBar::slotToolActionActivated() tool=" | 344 | qCDebug(kpLogWidgets) << "kpToolToolBar::slotToolActionActivated() tool=" | ||
337 | << (tool ? tool->objectName () : "null"); | 345 | << (tool ? tool->objectName () : "null"); | ||
338 | 346 | | |||
339 | selectTool (tool, true/*reselect if same tool*/); | 347 | selectTool (tool, true/*reselect if same tool*/); | ||
340 | } | 348 | } | ||
341 | 349 | | |||
342 | //--------------------------------------------------------------------- | 350 | //--------------------------------------------------------------------- | ||
Show All 18 Lines | 354 | { | |||
361 | m_baseLayout->setContentsMargins(0, 0, 0, 0); | 369 | m_baseLayout->setContentsMargins(0, 0, 0, 0); | ||
362 | 370 | | |||
363 | m_toolLayout = new QGridLayout(); | 371 | m_toolLayout = new QGridLayout(); | ||
364 | m_toolLayout->setContentsMargins(0, 0, 0, 0); | 372 | m_toolLayout->setContentsMargins(0, 0, 0, 0); | ||
365 | 373 | | |||
366 | // (ownership is transferred to m_baseLayout) | 374 | // (ownership is transferred to m_baseLayout) | ||
367 | m_baseLayout->addItem (m_toolLayout); | 375 | m_baseLayout->addItem (m_toolLayout); | ||
368 | 376 | | |||
369 | int num = 0; | 377 | auto num = 0; | ||
370 | 378 | | |||
371 | foreach (kpToolButton *b, m_toolButtons) | 379 | for (auto *b : m_toolButtons) | ||
372 | { | 380 | { | ||
373 | addButton(b, o, num); | 381 | addButton(b, o, num); | ||
374 | num++; | 382 | num++; | ||
375 | } | 383 | } | ||
376 | 384 | | |||
377 | foreach(kpToolWidgetBase *w, m_toolWidgets) | 385 | for (auto *w : m_toolWidgets) | ||
378 | { | 386 | { | ||
379 | m_baseLayout->addWidget(w, | 387 | m_baseLayout->addWidget(w, | ||
380 | 0/*stretch*/, | 388 | 0/*stretch*/, | ||
381 | o == Qt::Vertical ? Qt::AlignHCenter : Qt::AlignVCenter); | 389 | o == Qt::Vertical ? Qt::AlignHCenter : Qt::AlignVCenter); | ||
382 | } | 390 | } | ||
383 | 391 | | |||
384 | adjustSizeConstraint(); | 392 | adjustSizeConstraint(); | ||
385 | } | 393 | } | ||
Show All 20 Lines | 399 | { | |||
406 | } | 414 | } | ||
407 | } | 415 | } | ||
408 | 416 | | |||
409 | //--------------------------------------------------------------------- | 417 | //--------------------------------------------------------------------- | ||
410 | 418 | | |||
411 | // private | 419 | // private | ||
412 | void kpToolToolBar::addButton(QAbstractButton *button, Qt::Orientation o, int num) | 420 | void kpToolToolBar::addButton(QAbstractButton *button, Qt::Orientation o, int num) | ||
413 | { | 421 | { | ||
414 | if (o == Qt::Vertical) | 422 | if (o == Qt::Vertical) { | ||
415 | m_toolLayout->addWidget (button, num / m_vertCols, num % m_vertCols); | 423 | m_toolLayout->addWidget (button, num / m_vertCols, num % m_vertCols); | ||
424 | } | ||||
416 | else | 425 | else | ||
417 | { | 426 | { | ||
418 | // maps Left (o = vertical) to Bottom (o = horizontal) | 427 | // maps Left (o = vertical) to Bottom (o = horizontal) | ||
419 | int row = (m_vertCols - 1) - (num % m_vertCols); | 428 | int row = (m_vertCols - 1) - (num % m_vertCols); | ||
420 | m_toolLayout->addWidget (button, row, num / m_vertCols); | 429 | m_toolLayout->addWidget (button, row, num / m_vertCols); | ||
421 | } | 430 | } | ||
422 | } | 431 | } | ||
423 | 432 | | |||
424 | //--------------------------------------------------------------------- | 433 | //--------------------------------------------------------------------- | ||
425 | 434 | | |||
426 | void kpToolToolBar::slotIconSizeChanged(const QSize &size) | 435 | void kpToolToolBar::slotIconSizeChanged(const QSize &size) | ||
427 | { | 436 | { | ||
428 | foreach (kpToolButton *b, m_toolButtons) | 437 | for (auto *b : m_toolButtons) { | ||
429 | b->setIconSize(size); | 438 | b->setIconSize(size); | ||
439 | } | ||||
430 | 440 | | |||
431 | m_baseLayout->activate(); | 441 | m_baseLayout->activate(); | ||
432 | adjustSizeConstraint(); | 442 | adjustSizeConstraint(); | ||
433 | } | 443 | } | ||
434 | 444 | | |||
435 | //--------------------------------------------------------------------- | 445 | //--------------------------------------------------------------------- | ||
436 | 446 | | |||
437 | void kpToolToolBar::slotToolButtonStyleChanged(Qt::ToolButtonStyle style) | 447 | void kpToolToolBar::slotToolButtonStyleChanged(Qt::ToolButtonStyle style) | ||
438 | { | 448 | { | ||
439 | foreach (kpToolButton *b, m_toolButtons) | 449 | for (auto *b : m_toolButtons) { | ||
440 | b->setToolButtonStyle(style); | 450 | b->setToolButtonStyle(style); | ||
451 | } | ||||
441 | 452 | | |||
442 | m_baseLayout->activate(); | 453 | m_baseLayout->activate(); | ||
443 | adjustSizeConstraint(); | 454 | adjustSizeConstraint(); | ||
444 | } | 455 | } | ||
445 | 456 | | |||
446 | //--------------------------------------------------------------------- | 457 | //--------------------------------------------------------------------- | ||
447 | 458 | |