Krita Source Code Documentation
Loading...
Searching...
No Matches
KoMarkerSelector.cpp
Go to the documentation of this file.
1/* This file is part of the KDE project
2 * SPDX-FileCopyrightText: 2011 Thorsten Zachmann <zachmann@kde.org>
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"
12#include "KoPathShape.h"
13
14#include <QPainter>
15#include <QPainterPath>
16
18{
19public:
20 Private(KoFlake::MarkerPosition position, QWidget *parent)
21 : model(new KoMarkerModel(QList<KoMarker*>(), position, parent))
22 {}
23
25};
26
28: QComboBox(parent)
29, d(new Private(position, this))
30{
31 setModel(d->model);
32 setItemDelegate(new KoMarkerItemDelegate(position, this));
33}
34
39
40void 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*>();
64
65 if (!antialiasing) {
66 painter.setRenderHint(QPainter::Antialiasing, false);
67 }
68}
69
71{
72 int index = d->model->markerIndex(marker);
73 if (index >= 0) {
74 setCurrentIndex(index);
75 if (index != d->model->temporaryMarkerPosition()) {
77 }
78 } else {
79 setCurrentIndex(d->model->addTemporaryMarker(marker));
80 }
81}
82
84{
85 return itemData(currentIndex(), Qt::DecorationRole).value<KoMarker*>();
86}
87
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
96QVariant KoMarkerSelector::itemData(int index, int role) const
97{
98 return d->model->marker(index, role);
99}
static void drawMarkerPreview(QPainter *painter, const QRect &rect, const QPen &pen, KoMarker *marker, KoFlake::MarkerPosition position)
QVariant marker(int index, int role=Qt::UserRole) const
int temporaryMarkerPosition() const
KoFlake::MarkerPosition position() const
void removeTemporaryMarker()
int addTemporaryMarker(KoMarker *marker)
int markerIndex(KoMarker *marker) const
Private(KoFlake::MarkerPosition position, QWidget *parent)
void paintEvent(QPaintEvent *pe) override
void setMarker(KoMarker *marker)
Private *const d
~KoMarkerSelector() override
QVariant itemData(int index, int role=Qt::UserRole) const
reimplement
KoMarker * marker() const
KoMarkerSelector(KoFlake::MarkerPosition position, QWidget *parent=0)
void updateMarkers(const QList< KoMarker * > markers)
MarkerPosition
Definition KoFlake.h:41