• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • krita API Reference
  • KDE Home
  • Contact Us
 

KritaWidgets

  • sources
  • kfour-appscomplete
  • krita
  • libs
  • widgets
KisPaletteDelegate.cpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2016 Dmitry Kazakov <[email protected]>
3  *
4  * SPDX-License-Identifier: GPL-2.0-or-later
5  */
6 
7 #include <QPen>
8 #include <QPainter>
9 #include <QtMath> // qBound
10 
11 #include <kis_global.h>
12 #include <KisPaletteModel.h>
13 #include "kis_debug.h"
14 
15 #include "KisPaletteDelegate.h"
16 
17 const int KisPaletteDelegate::BORDER_WIDTH = 3;
18 
19 KisPaletteDelegate::KisPaletteDelegate(QObject *parent)
20  : QAbstractItemDelegate(parent)
21 { }
22 
23 KisPaletteDelegate::~KisPaletteDelegate()
24 { }
25 
26 void KisPaletteDelegate::paintCrossedLine(const QStyleOptionViewItem &option, QPainter *painter) const
27 {
28  QRect crossRect = kisGrowRect(option.rect, -qBound(2, option.rect.width() / 6, 4));
29 
30  painter->save();
31  painter->setRenderHint(QPainter::Antialiasing, true);
32  painter->setPen(QPen(Qt::white, 2.5));
33  painter->drawLine(crossRect.topLeft(), crossRect.bottomRight());
34  painter->setPen(QPen(Qt::red, 1.0));
35  painter->drawLine(crossRect.topLeft(), crossRect.bottomRight());
36  painter->restore();
37 }
38 
39 void KisPaletteDelegate::paintNonCrossed(QPainter */*painter*/, const QStyleOptionViewItem &/*option*/,
40  const QModelIndex &/*index*/, const bool /*isSelected*/) const
41 {
42 }
43 
44 void KisPaletteDelegate::paintGroupName(QPainter *painter, const QStyleOptionViewItem &option,
45  const QModelIndex &index, const bool isSelected) const
46 {
47  QString name = qvariant_cast<QString>(index.data(Qt::DisplayRole));
48  if (isSelected) {
49  painter->fillRect(option.rect, option.palette.highlight());
50  }
51  QRect paintRect = kisGrowRect(option.rect, -BORDER_WIDTH);
52  painter->setBrush(QBrush(Qt::lightGray));
53  painter->drawText(paintRect, name);
54 }
55 
56 void KisPaletteDelegate::paint(QPainter *painter,
57  const QStyleOptionViewItem &option,
58  const QModelIndex &index) const
59 {
60  if (!index.isValid())
61  return;
62 
63  painter->save();
64  const bool isSelected = option.state & QStyle::State_Selected;
65 
66  if (qvariant_cast<bool>(index.data(KisPaletteModel::IsGroupNameRole))) {
67  paintGroupName(painter, option, index, isSelected);
68  } else {
69  QRect paintRect = option.rect;
70  if (isSelected) {
71  painter->fillRect(option.rect, option.palette.highlight());
72  paintRect = kisGrowRect(option.rect, -BORDER_WIDTH);
73  }
74  if (qvariant_cast<bool>(index.data(KisPaletteModel::CheckSlotRole))) {
75  QBrush brush = qvariant_cast<QBrush>(index.data(Qt::BackgroundRole));
76  painter->fillRect(paintRect, brush);
77  } else {
78  QBrush lightBrush(Qt::gray);
79  QBrush darkBrush(Qt::darkGray);
80  painter->fillRect(paintRect, lightBrush);
81  painter->fillRect(QRect(paintRect.topLeft(), paintRect.center()), darkBrush);
82  painter->fillRect(QRect(paintRect.center(), paintRect.bottomRight()), darkBrush);
83  }
84 
85  QString name = qvariant_cast<QString>(index.data(Qt::DisplayRole));
86  if (!m_crossedKeyword.isNull() && name.toLower().contains(m_crossedKeyword)) {
87  paintCrossedLine(option, painter);
88  }
89  }
90 
91  painter->restore();
92 }
93 
94 QSize KisPaletteDelegate::sizeHint(const QStyleOptionViewItem &option,
95  const QModelIndex &) const
96 {
97  return option.decorationSize;
98 }
KisPaletteModel::IsGroupNameRole
Definition: KisPaletteModel.h:36
QString::isNull
bool isNull() const
QPainter::setPen
void setPen(const QColor &color)
KisPaletteDelegate::sizeHint
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &) const override
Definition: kis_palette_delegate.cpp:74
QRect::topLeft
QPoint topLeft() const
KisPaletteDelegate.h
QRect
KisPaletteDelegate::paint
void paint(QPainter *, const QStyleOptionViewItem &, const QModelIndex &) const override
Definition: kis_palette_delegate.cpp:31
QSize
KisPaletteDelegate::~KisPaletteDelegate
~KisPaletteDelegate() override
Definition: kis_palette_delegate.cpp:22
QRect::bottomRight
QPoint bottomRight() const
QPainter
QPainter::drawText
void drawText(const QPointF &position, const QString &text)
QPainter::fillRect
void fillRect(const QRectF &rectangle, const QBrush &brush)
KisPaletteModel.h
QPen
KisPaletteDelegate::KisPaletteDelegate
KisPaletteDelegate(QObject *parent=0)
Definition: kis_palette_delegate.cpp:17
QModelIndex::data
QVariant data(int role) const
QAbstractItemDelegate
QObject
QString
QRect::center
QPoint center() const
QStyleOptionViewItem
QModelIndex::isValid
bool isValid() const
QBrush
QPainter::setBrush
void setBrush(const QBrush &brush)
KisPaletteModel::CheckSlotRole
Definition: KisPaletteModel.h:37
QPainter::drawLine
void drawLine(const QLineF &line)
QObject::name
const char * name() const
QPainter::restore
void restore()
QPainter::save
void save()
QModelIndex
QPainter::setRenderHint
void setRenderHint(RenderHint hint, bool on)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sat Jan 23 2021 11:48:22 by doxygen 1.8.16 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KritaWidgets

Skip menu "KritaWidgets"
  • Main Page
  • Namespace List
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

krita API Reference

Skip menu "krita API Reference"
  • libs
  •   KritaBasicFlakes
  •   brush
  •   KritaUndo2
  •   KritaFlake
  •   image
  •   KritaPlugin
  •   Krita
  •   KritaPigment
  •   KritaResources
  •   KritaStore
  •   ui
  •   KritaWidgets
  •   KritaWidgetUtils
  • plugins
  •   Assitants
  •   Extensions
  •   Filters
  •   Generators
  •   Formats
  •           src
  •   PaintOps
  •     libpaintop

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal