--- a/src/mainwindow.cpp Wed Apr 04 11:43:15 2018 +0300 +++ b/src/mainwindow.cpp Wed Apr 04 12:08:45 2018 +0300 @@ -263,16 +263,29 @@ } else { - QToolButton* colorButton = new QToolButton; - colorButton->setIcon (makeColorIcon (entry.color(), 16)); - colorButton->setIconSize (QSize (16, 16)); - colorButton->setToolTip (entry.color().name()); - - connect (colorButton, SIGNAL (clicked()), this, SLOT (quickColorClicked())); + QToolButton* colorButton = new QToolButton {this}; + colorButton->setIcon(makeColorIcon(entry.color(), 16)); + colorButton->setIconSize({16, 16}); + colorButton->setToolTip(entry.color().name()); + colorButton->setStatusTip(format( + tr("Changes the color of selected objects to %1"), + entry.color().name() + )); ui.toolBarColors->addWidget (colorButton); m_colorButtons << colorButton; + connect(colorButton, + &QToolButton::clicked, + [&]() + { + for (LDObject* object : selectedObjects()) + { + if (object->isColored()) + object->setColor(entry.color()); + } - entry.setToolButton (colorButton); + endAction(); + } + ); } } @@ -352,37 +365,6 @@ // --------------------------------------------------------------------------------------------------------------------- // -void MainWindow::quickColorClicked() -{ - QToolButton* button = static_cast<QToolButton*> (sender()); - LDColor color = LDColor::nullColor; - - for (const ColorToolbarItem& entry : m_quickColors) - { - if (entry.toolButton() == button) - { - color = entry.color(); - break; - } - } - - if (not color.isValid()) - return; - - for (LDObject* obj : selectedObjects()) - { - if (not obj->isColored()) - continue; // uncolored object - - obj->setColor (color); - } - - endAction(); - refresh(); -} - -// --------------------------------------------------------------------------------------------------------------------- -// // Returns the suggested position to place a new object at. // int MainWindow::suggestInsertPoint() @@ -1050,13 +1032,12 @@ // --------------------------------------------------------------------------------------------------------------------- // -ColorToolbarItem::ColorToolbarItem (LDColor color, QToolButton* toolButton) : - m_color (color), - m_toolButton (toolButton) {} +ColorToolbarItem::ColorToolbarItem(LDColor color) : + m_color (color) {} ColorToolbarItem ColorToolbarItem::makeSeparator() { - return ColorToolbarItem (LDColor::nullColor, nullptr); + return {LDColor::nullColor}; } bool ColorToolbarItem::isSeparator() const @@ -1073,13 +1054,3 @@ { m_color = color; } - -QToolButton* ColorToolbarItem::toolButton() const -{ - return m_toolButton; -} - -void ColorToolbarItem::setToolButton (QToolButton* value) -{ - m_toolButton = value; -}