43 cfg (bool, lv_colorize, true); |
43 cfg (bool, lv_colorize, true); |
44 cfg (int, gui_toolbar_iconsize, 24); |
44 cfg (int, gui_toolbar_iconsize, 24); |
45 cfg (str, gui_colortoolbar, "16:24:|:0:1:2:3:4:5:6:7"); |
45 cfg (str, gui_colortoolbar, "16:24:|:0:1:2:3:4:5:6:7"); |
46 extern_cfg (str, io_recentfiles); |
46 extern_cfg (str, io_recentfiles); |
47 extern_cfg (bool, gl_axes); |
47 extern_cfg (bool, gl_axes); |
|
48 extern_cfg (str, gl_maincolor); |
|
49 extern_cfg (float, gl_maincolor_alpha); |
48 |
50 |
49 // ============================================================================= |
51 // ============================================================================= |
50 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
52 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
51 // ============================================================================= |
53 // ============================================================================= |
52 ForgeWindow::ForgeWindow () { |
54 ForgeWindow::ForgeWindow () { |
402 |
404 |
403 // ============================================================================= |
405 // ============================================================================= |
404 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
406 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
405 // ============================================================================= |
407 // ============================================================================= |
406 void ForgeWindow::updateToolBars () { |
408 void ForgeWindow::updateToolBars () { |
|
409 const QSize iconsize (gui_toolbar_iconsize, gui_toolbar_iconsize); |
|
410 |
407 for (QToolBar* bar : m_toolBars) |
411 for (QToolBar* bar : m_toolBars) |
408 bar->setIconSize (QSize (gui_toolbar_iconsize, gui_toolbar_iconsize)); |
412 bar->setIconSize (iconsize); |
409 |
413 |
410 // Update the quick color toolbar. |
414 // Update the quick color toolbar. |
411 for (QPushButton* btn : m_colorButtons) |
415 for (QToolButton* btn : m_colorButtons) |
412 delete btn; |
416 delete btn; |
413 |
417 |
414 m_colorButtons.clear (); |
418 m_colorButtons.clear (); |
415 |
419 |
416 // Clear the toolbar to remove separators |
420 // Clear the toolbar to remove separators |
418 |
422 |
419 for (quickColorMetaEntry& entry : m_colorMeta) { |
423 for (quickColorMetaEntry& entry : m_colorMeta) { |
420 if (entry.bSeparator) |
424 if (entry.bSeparator) |
421 m_colorToolBar->addSeparator (); |
425 m_colorToolBar->addSeparator (); |
422 else { |
426 else { |
423 QPushButton* colorButton = new QPushButton; |
427 QToolButton* colorButton = new QToolButton; |
424 colorButton->setAutoFillBackground (true); |
428 colorButton->setIcon (makeColorIcon (entry.col, gui_toolbar_iconsize)); |
425 colorButton->setStyleSheet (fmt ("background-color: %s", entry.col->zColorString.chars())); |
429 colorButton->setIconSize (iconsize); |
426 colorButton->setToolTip (entry.col->zName); |
430 colorButton->setToolTip (entry.col->zName); |
427 |
431 |
428 connect (colorButton, SIGNAL (clicked ()), this, SLOT (slot_quickColor ())); |
432 connect (colorButton, SIGNAL (clicked ()), this, SLOT (slot_quickColor ())); |
429 m_colorToolBar->addWidget (colorButton); |
433 m_colorToolBar->addWidget (colorButton); |
430 m_colorButtons.push_back (colorButton); |
434 m_colorButtons.push_back (colorButton); |
735 |
739 |
736 // ============================================================================= |
740 // ============================================================================= |
737 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
741 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
738 // ============================================================================= |
742 // ============================================================================= |
739 void ForgeWindow::slot_quickColor () { |
743 void ForgeWindow::slot_quickColor () { |
740 QPushButton* button = static_cast<QPushButton*> (sender ()); |
744 QToolButton* button = static_cast<QToolButton*> (sender ()); |
741 color* col = null; |
745 color* col = null; |
742 |
746 |
743 for (quickColorMetaEntry entry : m_colorMeta) { |
747 for (quickColorMetaEntry entry : m_colorMeta) { |
744 if (entry.btn == button) { |
748 if (entry.btn == button) { |
745 col = entry.col; |
749 col = entry.col; |
992 assert (false); |
996 assert (false); |
993 return null; |
997 return null; |
994 } |
998 } |
995 |
999 |
996 // ============================================================================= |
1000 // ============================================================================= |
|
1001 QIcon makeColorIcon (color* colinfo, const ushort size) { |
|
1002 // Create an image object and link a painter to it. |
|
1003 QImage img (size, size, QImage::Format_ARGB32); |
|
1004 QPainter paint (&img); |
|
1005 |
|
1006 QColor col = colinfo->qColor; |
|
1007 if (colinfo->index () == maincolor) { |
|
1008 // Use the user preferences for main color here |
|
1009 col = gl_maincolor.value.chars (); |
|
1010 col.setAlpha (gl_maincolor_alpha * 255.0f); |
|
1011 } |
|
1012 |
|
1013 // Paint the icon |
|
1014 paint.fillRect (QRect (0, 0, size, size), Qt::black); |
|
1015 paint.drawPixmap (QRect (1, 1, size - 2, size - 2), getIcon ("checkerboard"), QRect (0, 0, 8, 8)); |
|
1016 paint.fillRect (QRect (1, 1, size - 2, size - 2), col); |
|
1017 return QIcon (QPixmap::fromImage (img)); |
|
1018 } |
|
1019 |
|
1020 // ============================================================================= |
997 void makeColorSelector (QComboBox* box) { |
1021 void makeColorSelector (QComboBox* box) { |
998 std::map<short, ulong> counts; |
1022 std::map<short, ulong> counts; |
999 |
1023 |
1000 for (LDObject* obj : g_curfile->m_objs) { |
1024 for (LDObject* obj : g_curfile->m_objs) { |
1001 if (!obj->isColored ()) |
1025 if (!obj->isColored ()) |
1008 } |
1032 } |
1009 |
1033 |
1010 box->clear (); |
1034 box->clear (); |
1011 ulong row = 0; |
1035 ulong row = 0; |
1012 for (const auto& pair : counts) { |
1036 for (const auto& pair : counts) { |
1013 const ushort size = 16; |
|
1014 color* col = getColor (pair.first); |
1037 color* col = getColor (pair.first); |
1015 assert (col != null); |
1038 assert (col != null); |
1016 |
1039 |
1017 // Paint an icon for this color |
1040 QIcon ico = makeColorIcon (col, 16); |
1018 QIcon ico; |
|
1019 QImage img (size, size, QImage::Format_ARGB32); |
|
1020 QPainter paint (&img); |
|
1021 paint.fillRect (QRect (0, 0, size, size), Qt::black); |
|
1022 paint.drawPixmap (QRect (1, 1, size - 2, size - 2), getIcon ("checkerboard"), QRect (0, 0, 8, 8)); |
|
1023 paint.fillRect (QRect (1, 1, size - 2, size - 2), QColor (col->qColor)); |
|
1024 ico = QIcon (QPixmap::fromImage (img)); |
|
1025 |
|
1026 box->addItem (ico, fmt ("[%d] %s (%lu object%s)", |
1041 box->addItem (ico, fmt ("[%d] %s (%lu object%s)", |
1027 pair.first, col->zName.chars (), pair.second, PLURAL (pair.second))); |
1042 pair.first, col->zName.chars (), pair.second, PLURAL (pair.second))); |
1028 box->setItemData (row, pair.first); |
1043 box->setItemData (row, pair.first); |
1029 |
1044 |
1030 ++row; |
1045 ++row; |