src/colorSelector.cc

changeset 806
4240f47aa2d4
parent 801
f6abc9eb4217
child 840
d077dd19bf9a
equal deleted inserted replaced
805:d88c0354de97 806:4240f47aa2d4
102 102
103 const double x = (i % numCols) * square; 103 const double x = (i % numCols) * square;
104 const double y = (i / numCols) * square; 104 const double y = (i / numCols) * square;
105 const double w = square - (penWidth / 2); 105 const double w = square - (penWidth / 2);
106 106
107 QColor col (info->faceColor()); 107 QColor col (info.faceColor());
108 108
109 if (i == mainColorIndex) 109 if (i == mainColorIndex)
110 { 110 {
111 // Use the user preferences for main color here 111 // Use the user preferences for main color here
112 col = QColor (cfg::mainColor); 112 col = QColor (cfg::mainColor);
113 col.setAlpha (cfg::mainColorAlpha * 255.0f); 113 col.setAlpha (cfg::mainColorAlpha * 255.0f);
114 } 114 }
115 115
116 QPen pen (info->edgeColor(), penWidth, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin); 116 QPen pen (info.edgeColor(), penWidth, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
117 m_scene->addRect (x, y, w, w, pen, col); 117 m_scene->addRect (x, y, w, w, pen, col);
118 QGraphicsTextItem* numtext = m_scene->addText (format ("%1", i)); 118 QGraphicsTextItem* numtext = m_scene->addText (format ("%1", i));
119 numtext->setDefaultTextColor ((luma (col) < 80) ? Qt::white : Qt::black); 119 numtext->setDefaultTextColor ((luma (col) < 80) ? Qt::white : Qt::black);
120 numtext->setPos (x, y); 120 numtext->setPos (x, y);
121 121
122 if (selection() && i == selection()->index()) 122 if (selection() && i == selection().index())
123 { 123 {
124 auto curspic = m_scene->addPixmap (getIcon ("colorcursor")); 124 auto curspic = m_scene->addPixmap (getIcon ("colorcursor"));
125 curspic->setPos (x, y); 125 curspic->setPos (x, y);
126 } 126 }
127 } 127 }
151 ui->iconLabel->setPixmap (null); 151 ui->iconLabel->setPixmap (null);
152 ui->transparentDirectColor->setChecked (false); 152 ui->transparentDirectColor->setChecked (false);
153 return; 153 return;
154 } 154 }
155 155
156 ui->colorLabel->setText (format ("%1 - %2", selection()->indexString(), 156 ui->colorLabel->setText (format ("%1 - %2", selection().indexString(),
157 (selection()->isDirect() ? "<direct color>" : selection()->name()))); 157 (selection().isDirect() ? "<direct color>" : selection().name())));
158 ui->iconLabel->setPixmap (makeColorIcon (selection(), 16).pixmap (16, 16)); 158 ui->iconLabel->setPixmap (makeColorIcon (selection(), 16).pixmap (16, 16));
159 159
160 #ifdef TRANSPARENT_DIRECT_COLORS 160 #ifdef TRANSPARENT_DIRECT_COLORS
161 ui->transparentDirectColor->setEnabled (selection()->isDirect()); 161 ui->transparentDirectColor->setEnabled (selection().isDirect());
162 ui->transparentDirectColor->setChecked (selection()->isDirect() && selection()->faceColor().alphaF() < 1.0); 162 ui->transparentDirectColor->setChecked (selection().isDirect() && selection().faceColor().alphaF() < 1.0);
163 #else 163 #else
164 ui->transparentDirectColor->setChecked (false); 164 ui->transparentDirectColor->setChecked (false);
165 ui->transparentDirectColor->setEnabled (false); 165 ui->transparentDirectColor->setEnabled (false);
166 #endif 166 #endif
167 } 167 }
172 { 172 {
173 // If this is the first resize, check if we need to scroll down to see the 173 // If this is the first resize, check if we need to scroll down to see the
174 // currently selected color. We cannot do this in the constructor because the 174 // currently selected color. We cannot do this in the constructor because the
175 // height is not set properly there. Though don't do this if we selected a 175 // height is not set properly there. Though don't do this if we selected a
176 // direct color. 176 // direct color.
177 if (m_firstResize && selection()->index() >= numLDConfigColors()) 177 if (m_firstResize && selection().index() >= numLDConfigColors())
178 { 178 {
179 int visibleColors = (ui->viewport->height() / g_squareSize) * g_numColumns; 179 int visibleColors = (ui->viewport->height() / g_squareSize) * g_numColumns;
180 180
181 if (selection() && selection()->index() >= visibleColors) 181 if (selection() && selection().index() >= visibleColors)
182 { 182 {
183 int y = (selection()->index() / g_numColumns) * g_squareSize; 183 int y = (selection().index() / g_numColumns) * g_squareSize;
184 ui->viewport->verticalScrollBar()->setValue (y); 184 ui->viewport->verticalScrollBar()->setValue (y);
185 } 185 }
186 } 186 }
187 187
188 m_firstResize = false; 188 m_firstResize = false;
221 221
222 // ============================================================================= 222 // =============================================================================
223 // 223 //
224 void ColorSelector::chooseDirectColor() 224 void ColorSelector::chooseDirectColor()
225 { 225 {
226 QColor defcolor = selection() != null ? selection()->faceColor() : Qt::white; 226 QColor defcolor = selection() != null ? selection().faceColor() : Qt::white;
227 QColor newcolor = QColorDialog::getColor (defcolor); 227 QColor newcolor = QColorDialog::getColor (defcolor);
228 228
229 if (not newcolor.isValid()) 229 if (not newcolor.isValid())
230 return; // canceled 230 return; // canceled
231 231
234 234
235 // ============================================================================= 235 // =============================================================================
236 // 236 //
237 void ColorSelector::transparentCheckboxClicked() 237 void ColorSelector::transparentCheckboxClicked()
238 { 238 {
239 if (selection() == null || not selection()->isDirect()) 239 if (selection() == null || not selection().isDirect())
240 return; 240 return;
241 241
242 selectDirectColor (selection()->faceColor()); 242 selectDirectColor (selection().faceColor());
243 } 243 }
244 244
245 // ============================================================================= 245 // =============================================================================
246 // 246 //
247 bool ColorSelector::selectColor (LDColor& val, LDColor defval, QWidget* parent) 247 bool ColorSelector::selectColor (LDColor& val, LDColor defval, QWidget* parent)

mercurial