Krita Source Code Documentation
Loading...
Searching...
No Matches
KoLineStyleSelector.cpp
Go to the documentation of this file.
1/* This file is part of the KDE project
2 * SPDX-FileCopyrightText: 2007 Jan Hambrecht <jaham@gmx.net>
3 *
4 * SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6
10
11#include <QPen>
12#include <QPainter>
13
14class Q_DECL_HIDDEN KoLineStyleSelector::Private
15{
16public:
17 Private(QWidget *parent)
18 : model(new KoLineStyleModel(parent))
19 {
20 }
21
23};
24
26 : QComboBox(parent), d(new Private(this))
27{
28 setModel(d->model);
29 setItemDelegate(new KoLineStyleItemDelegate(this));
30}
31
36
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
59{
60 return d->model->addCustomStyle(style);
61}
62
63void 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
71{
72 QPen pen = itemData(currentIndex(), Qt::DecorationRole).value<QPen>();
73 return pen.style();
74}
75
77{
78 QPen pen = itemData(currentIndex(), Qt::DecorationRole).value<QPen>();
79 return pen.dashPattern();
80}
The line style item delegate for rendering the styles.
The line style model managing the style data.
KoLineStyleModel * model
void setLineStyle(Qt::PenStyle style, const QVector< qreal > &dashes=QVector< qreal >())
KoLineStyleSelector(QWidget *parent=0)
bool addCustomStyle(const QVector< qreal > &style)
Qt::PenStyle lineStyle() const
Returns the current line style.
QVector< qreal > lineDashes() const
Returns the dashes of the current line style.
void paintEvent(QPaintEvent *pe) override