src/guiutilities.cpp

changeset 1217
314e12e23c3a
parent 1215
77a0270352a3
child 1222
34def2630300
equal deleted inserted replaced
1216:12f9ea615cbc 1217:314e12e23c3a
21 #include "colors.h" 21 #include "colors.h"
22 #include "guiutilities.h" 22 #include "guiutilities.h"
23 #include "ldDocument.h" 23 #include "ldDocument.h"
24 #include "mainwindow.h" 24 #include "mainwindow.h"
25 25
26 GuiUtilities::GuiUtilities (QObject* parent) : 26 GuiUtilities::GuiUtilities(QObject* parent) :
27 QObject (parent), 27 QObject(parent),
28 HierarchyElement (parent) {} 28 HierarchyElement(parent) {}
29 29
30 QIcon GuiUtilities::makeColorIcon (LDColor ldcolor, int size) 30 QIcon GuiUtilities::makeColorIcon(LDColor ldcolor, int size)
31 { 31 {
32 // Create an image object and link a painter to it. 32 // Create an image object and link a painter to it.
33 QImage img (size, size, QImage::Format_ARGB32); 33 QImage img(size, size, QImage::Format_ARGB32);
34 QPainter painter (&img); 34 QPainter painter(&img);
35 QColor color = ldcolor.faceColor(); 35 QColor color = ldcolor.faceColor();
36 36
37 if (ldcolor == MainColor) 37 if (ldcolor == MainColor)
38 { 38 {
39 // Use the user preferences for main color here 39 // Use the user preferences for main color here
40 color = config.mainColor(); 40 color = config.mainColor();
41 color.setAlphaF (config.mainColorAlpha()); 41 color.setAlphaF(config.mainColorAlpha());
42 } 42 }
43 43
44 // Paint the icon border 44 // Paint the icon border
45 painter.fillRect (QRect (0, 0, size, size), ldcolor.edgeColor()); 45 painter.fillRect(QRect(0, 0, size, size), ldcolor.edgeColor());
46 46
47 // Paint the checkerboard background, visible with translucent icons 47 // Paint the checkerboard background, visible with translucent icons
48 painter.drawPixmap (QRect (1, 1, size - 2, size - 2), GetIcon ("checkerboard"), QRect (0, 0, 8, 8)); 48 painter.drawPixmap(QRect(1, 1, size - 2, size - 2), GetIcon("checkerboard"), QRect(0, 0, 8, 8));
49 49
50 // Paint the color above the checkerboard 50 // Paint the color above the checkerboard
51 painter.fillRect (QRect (1, 1, size - 2, size - 2), color); 51 painter.fillRect(QRect(1, 1, size - 2, size - 2), color);
52 return QIcon (QPixmap::fromImage (img)); 52 return QIcon(QPixmap::fromImage(img));
53 } 53 }
54 54
55 void GuiUtilities::fillUsedColorsToComboBox (QComboBox* box) 55 void GuiUtilities::fillUsedColorsToComboBox(QComboBox* box)
56 { 56 {
57 QMap<LDColor, int> counts; 57 QMap<LDColor, int> counts;
58 58
59 for (LDObject* obj : currentDocument()->objects()) 59 for (LDObject* obj : currentDocument()->objects())
60 { 60 {
61 if (not obj->isColored() or not obj->color().isValid()) 61 if (not obj->isColored() or not obj->color().isValid())
62 continue; 62 continue;
63 63
64 if (not counts.contains (obj->color())) 64 if (not counts.contains(obj->color()))
65 counts[obj->color()] = 1; 65 counts[obj->color()] = 1;
66 else 66 else
67 counts[obj->color()] += 1; 67 counts[obj->color()] += 1;
68 } 68 }
69 69
70 box->clear(); 70 box->clear();
71 int row = 0; 71 int row = 0;
72 72
73 QMapIterator<LDColor, int> it (counts); 73 QMapIterator<LDColor, int> it(counts);
74 while (it.hasNext()) 74 while (it.hasNext())
75 { 75 {
76 it.next(); 76 it.next();
77 QIcon ico = makeColorIcon (it.key(), 16); 77 QIcon ico = makeColorIcon(it.key(), 16);
78 box->addItem (ico, format ("[%1] %2 (%3 object%4)", 78 box->addItem(ico, format("[%1] %2(%3 object%4)",
79 it.key(), it.key().name(), it.value(), plural (it.value()))); 79 it.key(), it.key().name(), it.value(), plural(it.value())));
80 box->setItemData (row, it.key().index()); 80 box->setItemData(row, it.key().index());
81 ++row; 81 ++row;
82 } 82 }
83 } 83 }
84 84
85 QColor GuiUtilities::mainColorRepresentation() 85 QColor GuiUtilities::mainColorRepresentation()
86 { 86 {
87 QColor col (config.mainColor()); 87 QColor col(config.mainColor());
88 88
89 if (not col.isValid()) 89 if (not col.isValid())
90 return QColor (0, 0, 0); 90 return QColor(0, 0, 0);
91 91
92 col.setAlpha (config.mainColorAlpha() * 255.f); 92 col.setAlpha(config.mainColorAlpha() * 255.f);
93 return col; 93 return col;
94 } 94 }

mercurial