Krita Source Code Documentation
Loading...
Searching...
No Matches
KisColorFilterCombo Class Reference

#include <kis_color_filter_combo.h>

+ Inheritance diagram for KisColorFilterCombo:

Classes

struct  Private
 

Signals

void selectedColorsChanged ()
 

Public Member Functions

 KisColorFilterCombo (QWidget *parent, bool filterMode=true, bool circleMode=true)
 
QSize minimumSizeHint () const override
 
QList< int > selectedColors () const
 
void setModes (bool filterMode, bool circleMode)
 
QSize sizeHint () const override
 
void updateAvailableLabels (const QSet< int > &labels)
 
void updateAvailableLabels (KisNodeSP rootNode)
 
 ~KisColorFilterCombo () override
 

Static Public Member Functions

static void paintColorPie (QStylePainter &painter, const QPalette &palette, const QList< int > &selectedColors, const QRect &rect, const int &baseSize)
 

Private Member Functions

void paintEvent (QPaintEvent *event) override
 

Private Attributes

const QScopedPointer< Privatem_d
 
QList< ComboEventFilter * > m_eventFilters
 

Detailed Description

Definition at line 18 of file kis_color_filter_combo.h.

Constructor & Destructor Documentation

◆ KisColorFilterCombo()

KisColorFilterCombo::KisColorFilterCombo ( QWidget * parent,
bool filterMode = true,
bool circleMode = true )

Definition at line 188 of file kis_color_filter_combo.cpp.

189 : QComboBox(parent),
190 m_d(new Private)
191{
192 m_d->filterMode = filterMode;
193 m_d->circleMode = circleMode;
194
195
196 QStandardItemModel *newModel = new QStandardItemModel(this);
197 setModel(newModel);
198
199 QStyle* newStyle = QStyleFactory::create(style()->objectName());
200 // proxy style steals the ownership of the style and deletes it later
201 PopupComboBoxStyle *proxyStyle = new PopupComboBoxStyle(newStyle);
202
203 proxyStyle->setParent(this);
204 setStyle(proxyStyle);
205
206 setView(new FullSizedListView);
207 m_eventFilters.append(new ComboEventFilter(this));
208 m_eventFilters.append(new ComboEventFilter(this));
209
210 view()->installEventFilter(m_eventFilters[0]);
211 view()->viewport()->installEventFilter(m_eventFilters[1]);
212
214
215 QStandardItem* item = new QStandardItem(i18nc("combo box: show all layers", "All"));
216 item->setCheckable(true);
217 item->setCheckState(Qt::Unchecked);
218 item->setData(QColor(Qt::transparent), Qt::BackgroundRole);
219 item->setData(int(-1), OriginalLabelIndex);
220 item->setData(QSize(30, scm.rowHeight()), Qt::SizeHintRole);
221 newModel->appendRow(item);
222
223 int labelIndex = 0;
224 foreach (const QColor &color, scm.allColorLabels()) {
225 const QString title = color.alpha() > 0 ? "" : i18nc("combo box: select all layers without a label", "No Label");
226
227 QStandardItem* item = new QStandardItem(title);
228 item->setCheckable(true);
229 item->setCheckState(Qt::Unchecked);
230 item->setData(color, Qt::BackgroundRole);
231 item->setData(labelIndex, OriginalLabelIndex);
232 item->setData(QSize(30, scm.rowHeight()), Qt::SizeHintRole);
233 newModel->appendRow(item);
234
235 labelIndex++;
236 }
237
238 m_d->filteringModel = new LabelFilteringModel(this);
239 QAbstractItemModel *originalModel = model();
240 originalModel->setParent(m_d->filteringModel);
241
242 m_d->filteringModel->setSourceModel(originalModel);
243 setModel(m_d->filteringModel);
244}
const QScopedPointer< Private > m_d
QList< ComboEventFilter * > m_eventFilters
QVector< QColor > allColorLabels() const

References KisNodeViewColorScheme::allColorLabels(), m_d, m_eventFilters, OriginalLabelIndex, and KisNodeViewColorScheme::rowHeight().

◆ ~KisColorFilterCombo()

KisColorFilterCombo::~KisColorFilterCombo ( )
override

Definition at line 246 of file kis_color_filter_combo.cpp.

247{
248 qDeleteAll(m_eventFilters);
249}

References m_eventFilters.

Member Function Documentation

◆ minimumSizeHint()

QSize KisColorFilterCombo::minimumSizeHint ( ) const
override

Definition at line 420 of file kis_color_filter_combo.cpp.

421{
422 return sizeHint();
423}
QSize sizeHint() const override

References sizeHint().

◆ paintColorPie()

void KisColorFilterCombo::paintColorPie ( QStylePainter & painter,
const QPalette & palette,
const QList< int > & selectedColors,
const QRect & rect,
const int & baseSize )
static

Definition at line 299 of file kis_color_filter_combo.cpp.

300{
302 const QPen oldPen = painter.pen();
303 const QBrush oldBrush = painter.brush();
304 const int border = 0;
305 QColor shadowColor = palette.shadow().color();
306 shadowColor.setAlpha(64);
307
308 QRect pieRect(0, 0, baseSize - 2 * border, baseSize - 2 * border);
309 pieRect.moveCenter(rect.center());
310
311 if (selectedColors.size() == 1) {
312 const int currentLabel = selectedColors.first();
313 const QColor currentColor = scm.colorFromLabelIndex(currentLabel);
314 const QBrush brush = QBrush(currentColor);
315 painter.setBrush(brush);
316 painter.setPen(QPen(shadowColor, 1));
317
318 if (currentColor.alpha() > 0) {
319 painter.drawEllipse(rect);
320 } else if (currentLabel == 0) {
321 QColor white = Qt::white;
322 QColor grey = QColor(220,220,220);
323 painter.setBrush(QBrush(shadowColor));
324 painter.setRenderHint(QPainter::Antialiasing);
325 painter.drawEllipse(rect);
326 const int step = 16 * 360 / 4;
327 const int checkerSteps = 4;
328
329 for (int i = 0; i < checkerSteps; i++) {
330 QBrush checkerBrush = QBrush((i % 2) ? grey : white);
331 painter.setPen(Qt::NoPen);
332 painter.setBrush(checkerBrush);
333 painter.drawPie(pieRect, step * i, step);
334 }
335
336 }
337 } else {
338 const int numColors = selectedColors.size();
339 const int step = 16 * 360 / numColors;
340
341 painter.setPen(QPen(shadowColor, 1));
342 painter.setBrush(QColor(0,0,0,0));
343 painter.setRenderHint(QPainter::Antialiasing);
344 painter.drawEllipse(rect);
345 for (int i = 0; i < numColors; i++) {
346 QColor color = scm.colorFromLabelIndex(selectedColors[i]);
347 QBrush brush = color.alpha() > 0 ? QBrush(color) : QBrush(Qt::black, Qt::Dense4Pattern);
348 painter.setPen(Qt::NoPen);
349 painter.setBrush(brush);
350
351 painter.drawPie(pieRect, step * i, step);
352 }
353 }
354
355 painter.setPen(oldPen);
356 painter.setBrush(oldBrush);
357}
QList< int > selectedColors() const
QColor colorFromLabelIndex(int index) const
KoColor currentColor(ResourceProvider *provider, ColorRole role)
rgba palette[MAX_PALETTE]
Definition palette.c:35

References KisNodeViewColorScheme::colorFromLabelIndex(), palette, and selectedColors().

◆ paintEvent()

void KisColorFilterCombo::paintEvent ( QPaintEvent * event)
overrideprivate

Definition at line 360 of file kis_color_filter_combo.cpp.

361{
362 Q_UNUSED(event);
363
364 QStylePainter painter(this);
365 painter.setPen(palette().color(QPalette::Text));
366
367 // draw the combobox frame, focusrect and selected etc.
368 QStyleOptionComboBox opt;
369 initStyleOption(&opt);
370 painter.drawComplexControl(QStyle::CC_ComboBox, opt);
371
372
373 {
374 const QRect editRect = style()->subControlRect(QStyle::CC_ComboBox, &opt, QStyle::SC_ComboBoxEditField, this);
375 const int size = qMin(editRect.width(), editRect.height());
376
378
379 if (selectedColors.size() == 0 || selectedColors.size() == model()->rowCount() - 1) {
380 QIcon icon = KisIconUtils::loadIcon(m_d->filterMode ? "view-filter" : "tag");
381 QPixmap pixmap = icon.pixmap(QSize(size, size), !isEnabled() ? QIcon::Disabled : QIcon::Normal);
382 painter.drawPixmap(editRect.right() - size, editRect.top(), pixmap);
383
384 } else {
385 const int numColors = selectedColors.size();
386 if (m_d->circleMode) {
387 KisColorFilterCombo::paintColorPie(painter, opt.palette, selectedColors, editRect, size );
388 } else {
389 // show all colors in a rectangle
391
392 int oneColorWidth = editRect.width()/numColors;
393 int currentWidth = 0;
394 for (int i = 0; i < numColors; i++) {
395 QColor color = scm.colorFromLabelIndex(selectedColors[i]);
396 QBrush brush = color.alpha() > 0 ? QBrush(color) : QBrush(Qt::black, Qt::Dense4Pattern);
397 painter.setPen(color);
398 painter.setBrush(brush);
399 if (i == numColors - 1) {
400 // last color; let's fill up
401 painter.fillRect(currentWidth, editRect.top(), editRect.width() - currentWidth, editRect.height(), brush);
402 } else {
403 painter.fillRect(currentWidth, editRect.top(), oneColorWidth, editRect.height(), brush);
404 }
405
406 currentWidth += oneColorWidth;
407 }
408
409
410
411
412 }
413 }
414 }
415
416 // draw the icon and text
417 //painter.drawControl(QStyle::CE_ComboBoxLabel, opt);
418}
static void paintColorPie(QStylePainter &painter, const QPalette &palette, const QList< int > &selectedColors, const QRect &rect, const int &baseSize)
int size(const Forest< T > &forest)
Definition KisForest.h:1232
QIcon loadIcon(const QString &name)

References KisNodeViewColorScheme::colorFromLabelIndex(), KisIconUtils::loadIcon(), m_d, paintColorPie(), palette, and selectedColors().

◆ selectedColors()

QList< int > KisColorFilterCombo::selectedColors ( ) const

Definition at line 283 of file kis_color_filter_combo.cpp.

284{
285 QList<int> colors;
286 for (int i = 0; i < model()->rowCount(); i++) {
287 const QModelIndex &other = model()->index(i, 0);
288 const int label = other.data(OriginalLabelIndex).toInt();
289
290 if (label != -1 &&
291 other.data(Qt::CheckStateRole) == Qt::Checked) {
292
293 colors << label;
294 }
295 }
296 return colors;
297}

References OriginalLabelIndex.

◆ selectedColorsChanged

void KisColorFilterCombo::selectedColorsChanged ( )
signal

◆ setModes()

void KisColorFilterCombo::setModes ( bool filterMode,
bool circleMode )

Definition at line 277 of file kis_color_filter_combo.cpp.

278{
279 m_d->filterMode = filterMode;
280 m_d->circleMode = circleMode;
281}

References m_d.

◆ sizeHint()

QSize KisColorFilterCombo::sizeHint ( ) const
override

Definition at line 425 of file kis_color_filter_combo.cpp.

426{
427 QStyleOptionComboBox opt;
428 initStyleOption(&opt);
429
430 const QStyleOption *baseOption = qstyleoption_cast<const QStyleOption *>(&opt);
431 const int arrowSize = style()->pixelMetric(QStyle::PM_ScrollBarExtent, baseOption, this);
432
433 const QSize originalHint = QComboBox::sizeHint();
434 QSize sh(3 * arrowSize, originalHint.height());
435
436 return sh;
437}

◆ updateAvailableLabels() [1/2]

void KisColorFilterCombo::updateAvailableLabels ( const QSet< int > & labels)

Definition at line 272 of file kis_color_filter_combo.cpp.

273{
274 m_d->filteringModel->setAcceptedLabels(labels);
275}

References m_d.

◆ updateAvailableLabels() [2/2]

void KisColorFilterCombo::updateAvailableLabels ( KisNodeSP rootNode)

Definition at line 262 of file kis_color_filter_combo.cpp.

263{
264 QSet<int> labels;
265 if (!rootNode.isNull()) {
266 collectAvailableLabels(rootNode, &labels);
267 }
268
269 updateAvailableLabels(labels);
270}
void updateAvailableLabels(KisNodeSP rootNode)
bool isNull() const
void collectAvailableLabels(KisNodeSP root, QSet< int > *labels)

References collectAvailableLabels(), KisSharedPtr< T >::isNull(), and updateAvailableLabels().

Member Data Documentation

◆ m_d

const QScopedPointer<Private> KisColorFilterCombo::m_d
private

Definition at line 45 of file kis_color_filter_combo.h.

◆ m_eventFilters

QList<ComboEventFilter *> KisColorFilterCombo::m_eventFilters
private

Definition at line 46 of file kis_color_filter_combo.h.


The documentation for this class was generated from the following files: