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

#include <KoLineStyleSelector.h>

+ Inheritance diagram for KoLineStyleSelector:

Public Member Functions

bool addCustomStyle (const QVector< qreal > &style)
 
 KoLineStyleSelector (QWidget *parent=0)
 
QVector< qreal > lineDashes () const
 Returns the dashes of the current line style.
 
Qt::PenStyle lineStyle () const
 Returns the current line style.
 
 Private (QWidget *parent)
 
void setLineStyle (Qt::PenStyle style, const QVector< qreal > &dashes=QVector< qreal >())
 
 ~KoLineStyleSelector () override
 

Public Attributes

KoLineStyleModelmodel
 

Protected Member Functions

void paintEvent (QPaintEvent *pe) override
 

Private Attributes

Private *const d
 
- Private Attributes inherited from Private
KisCanvas2canvas
 
int displayedFrame
 
int intendedFrame
 

Additional Inherited Members

- Private Member Functions inherited from Private
 Private (KisCanvas2 *c)
 

Detailed Description

A custom combobox widget for selecting line styles.

Definition at line 14 of file KoLineStyleSelector.cpp.

Constructor & Destructor Documentation

◆ KoLineStyleSelector()

KoLineStyleSelector::KoLineStyleSelector ( QWidget * parent = 0)
explicit

Definition at line 25 of file KoLineStyleSelector.cpp.

26 : QComboBox(parent), d(new Private(this))
27{
28 setModel(d->model);
29 setItemDelegate(new KoLineStyleItemDelegate(this));
30}
The line style item delegate for rendering the styles.

References d.

◆ ~KoLineStyleSelector()

KoLineStyleSelector::~KoLineStyleSelector ( )
override

Definition at line 32 of file KoLineStyleSelector.cpp.

33{
34 delete d;
35}

References d.

Member Function Documentation

◆ addCustomStyle()

bool KoLineStyleSelector::addCustomStyle ( const QVector< qreal > & style)

Adds a new line style to the combobox.

If the style already exists, it is not added to the selector.

Parameters
stylethe line style to add
Returns
true if style is unique among the existing styles and was added, else false

Definition at line 58 of file KoLineStyleSelector.cpp.

59{
60 return d->model->addCustomStyle(style);
61}

References d.

◆ lineDashes()

QVector< qreal > KoLineStyleSelector::lineDashes ( ) const

Returns the dashes of the current line style.

Definition at line 76 of file KoLineStyleSelector.cpp.

77{
78 QPen pen = itemData(currentIndex(), Qt::DecorationRole).value<QPen>();
79 return pen.dashPattern();
80}

◆ lineStyle()

Qt::PenStyle KoLineStyleSelector::lineStyle ( ) const

Returns the current line style.

Definition at line 70 of file KoLineStyleSelector.cpp.

71{
72 QPen pen = itemData(currentIndex(), Qt::DecorationRole).value<QPen>();
73 return pen.style();
74}

◆ paintEvent()

void KoLineStyleSelector::paintEvent ( QPaintEvent * pe)
overrideprotected

Definition at line 37 of file KoLineStyleSelector.cpp.

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}

◆ Private()

KoLineStyleSelector::Private ( QWidget * parent)
inline

Definition at line 17 of file KoLineStyleSelector.cpp.

18 : model(new KoLineStyleModel(parent))
19 {
20 }
The line style model managing the style data.
KoLineStyleModel * model

◆ setLineStyle()

void KoLineStyleSelector::setLineStyle ( Qt::PenStyle style,
const QVector< qreal > & dashes = QVector<qreal>() )

Selects the specified style.

If the style was already added it gets selected. If the style was not added already it gets temporary added and selected.

Parameters
stylethe style to display
dashesthe dashes of the style if style == Qt::CustomDashLine

Definition at line 63 of file KoLineStyleSelector.cpp.

64{
65 int index = d->model->setLineStyle(style, dashes);
66 if (index >= 0)
67 setCurrentIndex(index);
68}

References d.

Member Data Documentation

◆ d

Private* const KoLineStyleSelector::d
private

Definition at line 54 of file KoLineStyleSelector.h.

◆ model

KoLineStyleModel* KoLineStyleSelector::model

Definition at line 22 of file KoLineStyleSelector.cpp.


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