Sat, 24 Aug 2013 15:00:46 +0300
rework quick color code a tad
src/configDialog.cpp | file | annotate | diff | comparison | revisions | |
src/gui.cpp | file | annotate | diff | comparison | revisions | |
src/gui.h | file | annotate | diff | comparison | revisions |
--- a/src/configDialog.cpp Fri Aug 23 13:01:36 2013 +0300 +++ b/src/configDialog.cpp Sat Aug 24 15:00:46 2013 +0300 @@ -357,11 +357,11 @@ for (LDQuickColor& entry : quickColors) { QListWidgetItem* item = new QListWidgetItem; - if (entry.isSeparator) { + if (entry.isSeparator()) { item->setText ("--------"); item->setIcon (getIcon ("empty")); } else { - LDColor* col = entry.col; + LDColor* col = entry.color(); if (col == null) { item->setText ("[[unknown color]]"); @@ -375,7 +375,7 @@ ui->quickColorList->addItem (item); quickColorItems << item; - if (sel && &entry == sel) { + if (sel &&& entry == sel) { ui->quickColorList->setCurrentItem (item); ui->quickColorList->scrollToItem (item); } @@ -399,20 +399,20 @@ ulong i = getItemRow (item, quickColorItems); entry = &quickColors[i]; - if (entry->isSeparator == true) + if (entry->isSeparator() == true) return; // don't color separators } - short defval = entry ? entry->col->index : -1; + short defval = entry ? entry->color()->index : -1; short val; if (ColorSelector::getColor (val, defval, this) == false) return; if (entry) - entry->col = getColor (val); + entry->setColor (getColor (val)); else { - LDQuickColor entry = {getColor (val), null, false}; + LDQuickColor entry (getColor (val), null); item = getSelectedQuickColor(); ulong idx; @@ -468,7 +468,7 @@ // Add a separator to quick colors // ----------------------------------------------------------------------------- void ConfigDialog::slot_addColorSeparator() { - quickColors << LDQuickColor ({null, null, true}); + quickColors << LDQuickColor::getSeparator(); updateQuickColorList (&quickColors[quickColors.size() - 1]); } @@ -638,14 +638,14 @@ str ConfigDialog::quickColorString() { str val; - for (LDQuickColor entry : quickColors) { + for (const LDQuickColor& entry : quickColors) { if (val.length() > 0) val += ':'; - if (entry.isSeparator) + if (entry.isSeparator()) val += '|'; else - val += fmt ("%1", entry.col->index); + val += fmt ("%1", entry.color()->index); } return val;
--- a/src/gui.cpp Fri Aug 23 13:01:36 2013 +0300 +++ b/src/gui.cpp Sat Aug 24 15:00:46 2013 +0300 @@ -174,12 +174,13 @@ List<LDQuickColor> colors; for (str colorname : gui_colortoolbar.value.split (":")) { - if (colorname == "|") { - colors << LDQuickColor ({null, null, true}); - } else { + if (colorname == "|") + colors << LDQuickColor::getSeparator(); + else { LDColor* col = getColor (colorname.toLong()); - assert (col != null); - colors << LDQuickColor ({col, null, false}); + + if (col != null) + colors << LDQuickColor (col, null); } } @@ -193,19 +194,19 @@ ui->colorToolbar->clear(); for (LDQuickColor& entry : m_quickColors) { - if (entry.isSeparator) + if (entry.isSeparator()) ui->colorToolbar->addSeparator(); else { QToolButton* colorButton = new QToolButton; - colorButton->setIcon (makeColorIcon (entry.col, 22)); + colorButton->setIcon (makeColorIcon (entry.color(), 22)); colorButton->setIconSize (QSize (22, 22)); - colorButton->setToolTip (entry.col->name); + colorButton->setToolTip (entry.color()->name); connect (colorButton, SIGNAL (clicked()), this, SLOT (slot_quickColor())); ui->colorToolbar->addWidget (colorButton); m_colorButtons << colorButton; - entry.btn = colorButton; + entry.setToolButton (colorButton); } } @@ -445,9 +446,9 @@ QToolButton* button = static_cast<QToolButton*> (sender()); LDColor* col = null; - for (LDQuickColor entry : m_quickColors) { - if (entry.btn == button) { - col = entry.col; + for (const LDQuickColor& entry : m_quickColors) { + if (entry.toolButton() == button) { + col = entry.color(); break; } } @@ -488,6 +489,8 @@ m_renderer->hardRefresh(); } +// ============================================================================= +// ----------------------------------------------------------------------------- void ForgeWindow::refresh() { buildObjList(); m_renderer->update(); @@ -919,3 +922,16 @@ return QImage (data, w, h, QImage::Format_ARGB32).rgbSwapped().mirrored(); } +// ============================================================================= +// ----------------------------------------------------------------------------- +LDQuickColor::LDQuickColor (LDColor* color, QToolButton* toolButton) : + m_color (color), + m_toolButton (toolButton) {} + +LDQuickColor LDQuickColor::getSeparator() { + return LDQuickColor (null, null); +} + +bool LDQuickColor::isSeparator() const { + return color() == null; +} \ No newline at end of file
--- a/src/gui.h Fri Aug 23 13:01:36 2013 +0300 +++ b/src/gui.h Sat Aug 24 15:00:46 2013 +0300 @@ -58,10 +58,15 @@ #define CTRL_SHIFT(N) (Qt::CTRL | Qt::SHIFT | Qt::Key_##N) // ============================================================================= -struct LDQuickColor { - LDColor* col; - QToolButton* btn; - bool isSeparator; +class LDQuickColor { + PROPERTY (LDColor*, color, setColor) + PROPERTY (QToolButton*, toolButton, setToolButton) + +public: + LDQuickColor (LDColor* color, QToolButton* toolButton); + bool isSeparator() const; + + static LDQuickColor getSeparator(); }; // =============================================================================