37 |
37 |
38 extern_cfg (String, gl_maincolor); |
38 extern_cfg (String, gl_maincolor); |
39 extern_cfg (Float, gl_maincolor_alpha); |
39 extern_cfg (Float, gl_maincolor_alpha); |
40 |
40 |
41 // ============================================================================= |
41 // ============================================================================= |
42 // ----------------------------------------------------------------------------- |
42 // ============================================================================= |
43 ColorSelector::ColorSelector (int defval, QWidget* parent) : QDialog (parent) |
43 ColorSelector::ColorSelector (int defval, QWidget* parent) : QDialog (parent) |
44 { |
44 { |
45 // Remove the default color if it's invalid |
45 // Remove the default color if it's invalid |
46 if (!getColor (defval)) |
46 if (!getColor (defval)) |
47 defval = -1; |
47 defval = -1; |
64 |
64 |
65 drawColorInfo(); |
65 drawColorInfo(); |
66 } |
66 } |
67 |
67 |
68 // ============================================================================= |
68 // ============================================================================= |
69 // ----------------------------------------------------------------------------- |
69 // ============================================================================= |
70 ColorSelector::~ColorSelector() |
70 ColorSelector::~ColorSelector() |
71 { |
71 { |
72 delete ui; |
72 delete ui; |
73 } |
73 } |
74 |
74 |
75 // ============================================================================= |
75 // ============================================================================= |
76 // ----------------------------------------------------------------------------- |
76 // ============================================================================= |
77 void ColorSelector::drawScene() |
77 void ColorSelector::drawScene() |
78 { |
78 { |
79 const int numCols = g_numColumns; |
79 const int numCols = g_numColumns; |
80 const int square = g_squareSize; |
80 const int square = g_squareSize; |
81 const int g_maxHeight = (numRows() * square); |
81 const int g_maxHeight = (numRows() * square); |
109 col.setAlpha (gl_maincolor_alpha * 255.0f); |
109 col.setAlpha (gl_maincolor_alpha * 255.0f); |
110 } |
110 } |
111 |
111 |
112 QPen pen (info->edgeColor, penWidth, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin); |
112 QPen pen (info->edgeColor, penWidth, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin); |
113 m_scene->addRect (x, y, w, w, pen, col); |
113 m_scene->addRect (x, y, w, w, pen, col); |
114 QGraphicsTextItem* numtext = m_scene->addText (fmt ("%1", i)); |
114 QGraphicsTextItem* numtext = m_scene->addText (format ("%1", i)); |
115 numtext->setDefaultTextColor ( (luma (col) < 80) ? Qt::white : Qt::black); |
115 numtext->setDefaultTextColor ( (luma (col) < 80) ? Qt::white : Qt::black); |
116 numtext->setPos (x, y); |
116 numtext->setPos (x, y); |
117 |
117 |
118 if (getSelection() && i == getSelection()->index) |
118 if (selection() && i == selection()->index) |
119 { |
119 { |
120 auto curspic = m_scene->addPixmap (getIcon ("colorcursor")); |
120 auto curspic = m_scene->addPixmap (getIcon ("colorcursor")); |
121 curspic->setPos (x, y); |
121 curspic->setPos (x, y); |
122 } |
122 } |
123 } |
123 } |
124 } |
124 } |
125 |
125 |
126 // ============================================================================= |
126 // ============================================================================= |
127 // ----------------------------------------------------------------------------- |
127 // ============================================================================= |
128 int ColorSelector::numRows() const |
128 int ColorSelector::numRows() const |
129 { |
129 { |
130 return (MAX_COLORS / g_numColumns); |
130 return (MAX_COLORS / g_numColumns); |
131 } |
131 } |
132 |
132 |
133 // ============================================================================= |
133 // ============================================================================= |
134 // ----------------------------------------------------------------------------- |
134 // ============================================================================= |
135 int ColorSelector::viewportWidth() const |
135 int ColorSelector::viewportWidth() const |
136 { |
136 { |
137 return g_numColumns * g_squareSize + 21; |
137 return g_numColumns * g_squareSize + 21; |
138 } |
138 } |
139 |
139 |
140 // ============================================================================= |
140 // ============================================================================= |
141 // ----------------------------------------------------------------------------- |
141 // ============================================================================= |
142 void ColorSelector::drawColorInfo() |
142 void ColorSelector::drawColorInfo() |
143 { |
143 { |
144 if (!getSelection()) |
144 if (!selection()) |
145 { |
145 { |
146 ui->colorLabel->setText ("---"); |
146 ui->colorLabel->setText ("---"); |
147 return; |
147 return; |
148 } |
148 } |
149 |
149 |
150 ui->colorLabel->setText (fmt ("%1 - %2", getSelection()->index, getSelection()->name)); |
150 ui->colorLabel->setText (format ("%1 - %2", selection()->index, selection()->name)); |
151 } |
151 } |
152 |
152 |
153 // ============================================================================= |
153 // ============================================================================= |
154 // ----------------------------------------------------------------------------- |
154 // ============================================================================= |
155 void ColorSelector::resizeEvent (QResizeEvent* ev) |
155 void ColorSelector::resizeEvent (QResizeEvent* ev) |
156 { |
156 { |
157 // If this is the first resize, check if we need to scroll down to see the |
157 // If this is the first resize, check if we need to scroll down to see the |
158 // currently selected color. We cannot do this in the constructor because the |
158 // currently selected color. We cannot do this in the constructor because the |
159 // height is not set properly there. |
159 // height is not set properly there. |
160 if (m_firstResize) |
160 if (m_firstResize) |
161 { |
161 { |
162 int visibleColors = (ui->viewport->height() / g_squareSize) * g_numColumns; |
162 int visibleColors = (ui->viewport->height() / g_squareSize) * g_numColumns; |
163 |
163 |
164 if (getSelection() && getSelection()->index >= visibleColors) |
164 if (selection() && selection()->index >= visibleColors) |
165 { |
165 { |
166 int y = (getSelection()->index / g_numColumns) * g_squareSize; |
166 int y = (selection()->index / g_numColumns) * g_squareSize; |
167 ui->viewport->verticalScrollBar()->setValue (y); |
167 ui->viewport->verticalScrollBar()->setValue (y); |
168 } |
168 } |
169 |
169 |
170 m_firstResize = false; |
170 m_firstResize = false; |
171 } |
171 } |