MCPcopy Create free account
hub / github.com/ccMSC/ckb / paintEvent

Method paintEvent

src/ckb/gradientdialogwidget.cpp:172–220  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

170}
171
172void GradientDialogWidget::paintEvent(QPaintEvent*){
173 QPainter painter(this);
174 QRect fill = fillRect();
175 int x = fill.x(), y = fill.y(), w = fill.width(), h = fill.height();
176
177 // Draw border around gradient
178 painter.setPen(palette().color(QPalette::Dark));
179 painter.drawLine(x - 1, y - 1, x + w, y - 1);
180 painter.drawLine(x - 1, y - 1, x - 1, y + h);
181 painter.setPen(palette().color(QPalette::Light));
182 painter.drawLine(x - 1, y + h, x + w, y + h);
183 painter.drawLine(x + w, y - 1, x + w, y + h);
184 // Draw background grid
185 for(int i = 0; i < w; i += 16){
186 for(int iy = 0; iy < h; iy += 16){
187 if(i % 32 != iy % 32)
188 painter.fillRect(x + i, y + iy, 16, 16, QColor(192, 192, 192));
189 else
190 painter.fillRect(x + i, y + iy, 16, 16, QColor(255, 255, 255));
191 }
192 }
193 // Draw gradient
194 painter.setRenderHint(QPainter::Antialiasing);
195 QLinearGradient gradient(x, 0, x + w, 0);
196 gradient.setStops(_stops);
197 painter.fillRect(fill, QBrush(gradient));
198
199 // Draw stops
200 QMapIterator<int, QColor> i(_colors);
201 painter.setPen(palette().color(QPalette::Shadow));
202 while(i.hasNext()){
203 i.next();
204 painter.setBrush(QBrush(i.value()));
205 int index = i.key();
206 if(index == _current){
207 // Highlight currently-edited stop
208 painter.setPen(QPen(palette().color(QPalette::Highlight), 2));
209 painter.drawRoundedRect(stopRect(index), 4, 4);
210 painter.setPen(palette().color(QPalette::Shadow));
211 } else
212 painter.drawRoundedRect(stopRect(index), 4, 4);
213 }
214 // Draw selection (if any)
215 if(selected.isValid() && selectedPos >= x && selectedPos <= x + w){
216 painter.setPen(QPen(palette().color(QPalette::Highlight), 2.5));
217 painter.setBrush(selected);
218 painter.drawRoundedRect(selectedPos - 6, height() - 18 - 2, 12, 18, 4, 4);
219 }
220}
221
222void GradientDialogWidget::mousePressEvent(QMouseEvent* event){
223 int x = event->x(), y = event->y();

Callers

nothing calls this directly

Calls 8

heightEnum · 0.85
widthMethod · 0.80
heightMethod · 0.80
fillRectMethod · 0.80
setStopsMethod · 0.80
keyMethod · 0.80
colorMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected