• 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
KoLineStyleSelector.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE project
2  * SPDX-FileCopyrightText: 2007 Jan Hambrecht <[email protected]>
3  *
4  * SPDX-License-Identifier: LGPL-2.0-or-later
5  */
6 
7 #include "KoLineStyleSelector.h"
8 #include "KoLineStyleModel_p.h"
9 #include "KoLineStyleItemDelegate_p.h"
10 
11 #include <QPen>
12 #include <QPainter>
13 
14 class Q_DECL_HIDDEN KoLineStyleSelector::Private
15 {
16 public:
17  Private(QWidget *parent)
18  : model(new KoLineStyleModel(parent))
19  {
20  }
21 
22  KoLineStyleModel *model;
23 };
24 
25 KoLineStyleSelector::KoLineStyleSelector(QWidget *parent)
26  : QComboBox(parent), d(new Private(this))
27 {
28  setModel(d->model);
29  setItemDelegate(new KoLineStyleItemDelegate(this));
30 }
31 
32 KoLineStyleSelector::~KoLineStyleSelector()
33 {
34  delete d;
35 }
36 
37 void KoLineStyleSelector::paintEvent(QPaintEvent *pe)
38 {
39  QComboBox::paintEvent(pe);
40 
41  QStyleOptionComboBox option;
42  option.initFrom(this);
43  option.frame = hasFrame();
44  QRect r = style()->subControlRect(QStyle::CC_ComboBox, &option, QStyle::SC_ComboBoxEditField, this);
45  if (!option.frame) // frameless combo boxes have smaller margins but styles do not take this into account
46  r.adjust(-14, 0, 14, 1);
47 
48  QPen pen = itemData(currentIndex(), Qt::DecorationRole).value<QPen>();
49 
50  QPainter painter(this);
51  painter.setPen(pen);
52  if (!(option.state & QStyle::State_Enabled)) {
53  painter.setOpacity(0.5);
54  }
55  painter.drawLine(r.left(), r.center().y(), r.right(), r.center().y());
56 }
57 
58 bool KoLineStyleSelector::addCustomStyle(const QVector<qreal> &style)
59 {
60  return d->model->addCustomStyle(style);
61 }
62 
63 void KoLineStyleSelector::setLineStyle(Qt::PenStyle style, const QVector<qreal> &dashes)
64 {
65  int index = d->model->setLineStyle(style, dashes);
66  if (index >= 0)
67  setCurrentIndex(index);
68 }
69 
70 Qt::PenStyle KoLineStyleSelector::lineStyle() const
71 {
72  QPen pen = itemData(currentIndex(), Qt::DecorationRole).value<QPen>();
73  return pen.style();
74 }
75 
76 QVector<qreal> KoLineStyleSelector::lineDashes() const
77 {
78  QPen pen = itemData(currentIndex(), Qt::DecorationRole).value<QPen>();
79  return pen.dashPattern();
80 }
KoLineStyleItemDelegate
The line style item delegate for rendering the styles.
Definition: KoLineStyleItemDelegate_p.h:12
QRect
QRect::right
int right() const
KoLineStyleItemDelegate_p.h
QWidget
QRect::adjust
void adjust(int dx1, int dy1, int dx2, int dy2)
QStyleOption::initFrom
void initFrom(const QWidget *widget)
QPoint::y
int y() const
QPainter
QPen
QRect::left
int left() const
QComboBox
QPen::style
Qt::PenStyle style() const
KoLineStyleModel
The line style model managing the style data.
Definition: KoLineStyleModel_p.h:14
QRect::center
QPoint center() const
KoLineStyleSelector.h
QPen::dashPattern
QVector< qreal > dashPattern() const
QPaintEvent
KoLineStyleModel_p.h
QComboBox::paintEvent
virtual void paintEvent(QPaintEvent *e)
Private
QVector< qreal >
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