src/mainwindow.cpp

changeset 974
b2fa5f89798a
parent 972
a34b73114823
child 975
24ba5aa3393f
equal deleted inserted replaced
973:c1b60c7d5135 974:b2fa5f89798a
50 #include "ui_mainwindow.h" 50 #include "ui_mainwindow.h"
51 #include "primitives.h" 51 #include "primitives.h"
52 #include "editmodes/abstractEditMode.h" 52 #include "editmodes/abstractEditMode.h"
53 #include "toolsets/extprogramtoolset.h" 53 #include "toolsets/extprogramtoolset.h"
54 #include "toolsets/toolset.h" 54 #include "toolsets/toolset.h"
55 #include "guiutilities.h"
55 56
56 static bool g_isSelectionLocked = false; 57 static bool g_isSelectionLocked = false;
57 static QMap<QAction*, QKeySequence> g_defaultShortcuts; 58 static QMap<QAction*, QKeySequence> g_defaultShortcuts;
58 59
59 ConfigOption (bool ColorizeObjectsList = true) 60 ConfigOption (bool ColorizeObjectsList = true)
64 // --------------------------------------------------------------------------------------------------------------------- 65 // ---------------------------------------------------------------------------------------------------------------------
65 // 66 //
66 MainWindow::MainWindow (QWidget* parent, Qt::WindowFlags flags) : 67 MainWindow::MainWindow (QWidget* parent, Qt::WindowFlags flags) :
67 QMainWindow (parent, flags), 68 QMainWindow (parent, flags),
68 m_configOptions (this), 69 m_configOptions (this),
70 m_guiUtilities (new GuiUtilities (this)),
69 ui (*new Ui_MainWindow), 71 ui (*new Ui_MainWindow),
70 m_externalPrograms (nullptr), 72 m_externalPrograms (nullptr),
71 m_settings (makeSettings (this)) 73 m_settings (makeSettings (this))
72 { 74 {
73 g_win = this; 75 g_win = this;
287 ui.toolBarColors->addSeparator(); 289 ui.toolBarColors->addSeparator();
288 } 290 }
289 else 291 else
290 { 292 {
291 QToolButton* colorButton = new QToolButton; 293 QToolButton* colorButton = new QToolButton;
292 colorButton->setIcon (MakeColorIcon (entry.color(), 16)); 294 colorButton->setIcon (m_guiUtilities->makeColorIcon (entry.color(), 16));
293 colorButton->setIconSize (QSize (16, 16)); 295 colorButton->setIconSize (QSize (16, 16));
294 colorButton->setToolTip (entry.color().name()); 296 colorButton->setToolTip (entry.color().name());
295 297
296 connect (colorButton, SIGNAL (clicked()), this, SLOT (slot_quickColor())); 298 connect (colorButton, SIGNAL (clicked()), this, SLOT (slot_quickColor()));
297 ui.toolBarColors->addWidget (colorButton); 299 ui.toolBarColors->addWidget (colorButton);
914 (QMessageBox::Close), QMessageBox::Close); 916 (QMessageBox::Close), QMessageBox::Close);
915 } 917 }
916 918
917 // --------------------------------------------------------------------------------------------------------------------- 919 // ---------------------------------------------------------------------------------------------------------------------
918 // 920 //
919 QIcon MakeColorIcon (LDColor colinfo, const int size)
920 {
921 // Create an image object and link a painter to it.
922 QImage img (size, size, QImage::Format_ARGB32);
923 QPainter paint (&img);
924 QColor col = colinfo.faceColor();
925
926 if (colinfo == MainColor)
927 {
928 // Use the user preferences for main color here
929 col = g_win->configBag()->mainColor();
930 col.setAlphaF (g_win->configBag()->mainColorAlpha());
931 }
932
933 // Paint the icon border
934 paint.fillRect (QRect (0, 0, size, size), colinfo.edgeColor());
935
936 // Paint the checkerboard background, visible with translucent icons
937 paint.drawPixmap (QRect (1, 1, size - 2, size - 2), GetIcon ("checkerboard"), QRect (0, 0, 8, 8));
938
939 // Paint the color above the checkerboard
940 paint.fillRect (QRect (1, 1, size - 2, size - 2), col);
941 return QIcon (QPixmap::fromImage (img));
942 }
943
944 // ---------------------------------------------------------------------------------------------------------------------
945 //
946 void MakeColorComboBox (QComboBox* box)
947 {
948 std::map<LDColor, int> counts;
949
950 for (LDObject* obj : CurrentDocument()->objects())
951 {
952 if (not obj->isColored() or not obj->color().isValid())
953 continue;
954
955 if (counts.find (obj->color()) == counts.end())
956 counts[obj->color()] = 1;
957 else
958 counts[obj->color()]++;
959 }
960
961 box->clear();
962 int row = 0;
963
964 for (const auto& pair : counts)
965 {
966 QIcon ico = MakeColorIcon (pair.first, 16);
967 box->addItem (ico, format ("[%1] %2 (%3 object%4)",
968 pair.first, pair.first.name(), pair.second, plural (pair.second)));
969 box->setItemData (row, pair.first.index());
970
971 ++row;
972 }
973 }
974
975 // ---------------------------------------------------------------------------------------------------------------------
976 //
977 void MainWindow::updateDocumentList() 921 void MainWindow::updateDocumentList()
978 { 922 {
979 m_updatingTabs = true; 923 m_updatingTabs = true;
980 924
981 while (m_tabs->count() > 0) 925 while (m_tabs->count() > 0)

mercurial