• 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
KoMarkerSelector.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE project
2  * SPDX-FileCopyrightText: 2011 Thorsten Zachmann <[email protected]>
3  *
4  * SPDX-License-Identifier: LGPL-2.0-or-later
5  */
6 
7 #include "KoMarkerSelector.h"
8 
9 #include "KoMarker.h"
10 #include "KoMarkerModel.h"
11 #include "KoMarkerItemDelegate.h"
12 #include "KoPathShape.h"
13 
14 #include <QPainter>
15 #include <QPainterPath>
16 
17 class KoMarkerSelector::Private
18 {
19 public:
20  Private(KoFlake::MarkerPosition position, QWidget *parent)
21  : model(new KoMarkerModel(QList<KoMarker*>(), position, parent))
22  {}
23 
24  KoMarkerModel *model;
25 };
26 
27 KoMarkerSelector::KoMarkerSelector(KoFlake::MarkerPosition position, QWidget *parent)
28 : QComboBox(parent)
29 , d(new Private(position, this))
30 {
31  setModel(d->model);
32  setItemDelegate(new KoMarkerItemDelegate(position, this));
33 }
34 
35 KoMarkerSelector::~KoMarkerSelector()
36 {
37  delete d;
38 }
39 
40 void KoMarkerSelector::paintEvent(QPaintEvent *pe)
41 {
42  QComboBox::paintEvent(pe);
43 
44  QStyleOptionComboBox option;
45  option.initFrom(this);
46  option.frame = hasFrame();
47  QRect rect = style()->subControlRect(QStyle::CC_ComboBox, &option, QStyle::SC_ComboBoxEditField, this);
48  if (!option.frame) { // frameless combo boxes have smaller margins but styles do not take this into account
49  rect.adjust(-14, 0, 14, 1);
50  }
51 
52  QPainter painter(this);
53  bool antialiasing = painter.testRenderHint(QPainter::Antialiasing);
54  if (!antialiasing) {
55  painter.setRenderHint(QPainter::Antialiasing, true);
56  }
57 
58  if (!(option.state & QStyle::State_Enabled)) {
59  painter.setOpacity(0.5);
60  }
61  QPen pen(Qt::black, 2);
62  KoMarker *marker = itemData(currentIndex(), Qt::DecorationRole).value<KoMarker*>();
63  KoMarkerItemDelegate::drawMarkerPreview(&painter, rect, pen, marker, d->model->position());
64 
65  if (!antialiasing) {
66  painter.setRenderHint(QPainter::Antialiasing, false);
67  }
68 }
69 
70 void KoMarkerSelector::setMarker(KoMarker *marker)
71 {
72  int index = d->model->markerIndex(marker);
73  if (index >= 0) {
74  setCurrentIndex(index);
75  if (index != d->model->temporaryMarkerPosition()) {
76  d->model->removeTemporaryMarker();
77  }
78  } else {
79  setCurrentIndex(d->model->addTemporaryMarker(marker));
80  }
81 }
82 
83 KoMarker *KoMarkerSelector::marker() const
84 {
85  return itemData(currentIndex(), Qt::DecorationRole).value<KoMarker*>();
86 }
87 
88 void KoMarkerSelector::updateMarkers(const QList<KoMarker*> markers)
89 {
90  KoMarkerModel *model = new KoMarkerModel(markers, d->model->position(), this);
91  d->model = model;
92  // this deletes the old model
93  setModel(model);
94 }
95 
96 QVariant KoMarkerSelector::itemData(int index, int role) const
97 {
98  return d->model->marker(index, role);
99 }
KoMarkerSelector::updateMarkers
void updateMarkers(const QList< KoMarker * > markers)
Set the available markers in the document.
Definition: KoMarkerSelector.cpp:88
QRect
QWidget::rect
QRect rect() const
QVariant::value
T value() const
QWidget
QStyle::subControlRect
virtual QRect subControlRect(ComplexControl control, const QStyleOptionComplex *option, SubControl subControl, const QWidget *widget) const=0
QRect::adjust
void adjust(int dx1, int dy1, int dx2, int dy2)
QComboBox::currentIndex
int currentIndex() const
QStyleOption::initFrom
void initFrom(const QWidget *widget)
QComboBox::model
QAbstractItemModel * model() const
KoMarkerSelector::setMarker
void setMarker(KoMarker *marker)
Definition: KoMarkerSelector.cpp:70
KoMarkerModel
Definition: KoMarkerModel.h:17
QList
QPainter
QPainter::testRenderHint
bool testRenderHint(RenderHint hint) const
QPen
KoMarkerSelector::marker
KoMarker * marker() const
Definition: KoMarkerSelector.cpp:83
KoMarkerItemDelegate.h
QComboBox
KoMarkerSelector::paintEvent
void paintEvent(QPaintEvent *pe) override
Definition: KoMarkerSelector.cpp:40
QWidget::style
QStyle * style() const
KoMarkerItemDelegate
Definition: KoMarkerItemDelegate.h:17
QComboBox::setModel
void setModel(QAbstractItemModel *model)
QComboBox::setItemDelegate
void setItemDelegate(QAbstractItemDelegate *delegate)
KoMarkerSelector::KoMarkerSelector
KoMarkerSelector(KoFlake::MarkerPosition position, QWidget *parent=0)
Definition: KoMarkerSelector.cpp:27
KoMarkerSelector::itemData
QVariant itemData(int index, int role=Qt::UserRole) const
reimplement
Definition: KoMarkerSelector.cpp:96
QPainter::setOpacity
void setOpacity(qreal opacity)
KoMarkerModel.h
QPaintEvent
QComboBox::hasFrame
bool hasFrame() const
KoMarkerSelector.h
QComboBox::paintEvent
virtual void paintEvent(QPaintEvent *e)
Private
KoMarkerSelector::~KoMarkerSelector
~KoMarkerSelector() override
Definition: KoMarkerSelector.cpp:35
QVariant
QPainter::setRenderHint
void setRenderHint(RenderHint hint, bool on)
QObject::parent
QObject * parent() const
KoMarkerItemDelegate::drawMarkerPreview
static void drawMarkerPreview(QPainter *painter, const QRect &rect, const QPen &pen, KoMarker *marker, KoFlake::MarkerPosition position)
Definition: KoMarkerItemDelegate.cpp:46
QStyleOptionComboBox
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