Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_selection_actions_panel_handle.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2026 Luna Lovecraft <ciubix8514@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-3.0-or-later
5 */
6
8#include "kis_icon_utils.h"
9#include <qapplication.h>
11#include <qevent.h>
12
22
24 : QWidget(parent)
25 , d(new Private(size))
26{
27 d->orientation = orientation;
28 d->default_cursor = Qt::OpenHandCursor;
29 d->held_cursor = Qt::ClosedHandCursor;
30 d->handle_icon = KisIconUtils::loadIcon("drag-handle");
31 this->setCursor(d->default_cursor);
32 setFixedSize(size, size);
33 setAttribute(Qt::WA_AcceptTouchEvents);
34}
35
39
41{
42 if(held)
43 {
44 this->setCursor(d->held_cursor);
45 }
46 else
47 {
48 this->setCursor(d->default_cursor);
49 }
50}
51
52void KisSelectionActionsPanelHandle::draw(QPainter& painter, const KoColorDisplayRendererInterface *renderInterface)
53{
54 QRect rect = geometry();
55 QPoint offset;
56
57 // Adjust the rect a bit to fill the right side of the bar properly
58 if (d->orientation == Orientation::Horizontal) {
59 painter.fillRect(rect.marginsAdded(QMargins(-3, 4, 1, 4)),
60 renderInterface->systemPaletteForDisplayColorSpace().window().color());
61 offset = QPoint(3, 0);
62 } else {
63 painter.fillRect(rect.marginsAdded(QMargins(4, -3, 4, 1)),
64 renderInterface->systemPaletteForDisplayColorSpace().window().color());
65 offset = QPoint(0, 3);
66 }
67
68 // Adjusting the icon location a bit to be properly centered
69
70
71#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
72 d->handle_icon.paint(&painter, QRect(QPoint(rect.topLeft() + offset), QSize(d->size, d->size)));
73#else
74 QImage ic = renderInterface->convertImageToDisplayColorSpace(d->handle_icon.pixmap(d->size, d->size).toImage());
75 QRect target = QRect(QPoint(0, 0), ic.deviceIndependentSize().toSize());
76 target.moveCenter(rect.center() + offset);
77 painter.drawImage(target, ic);
78#endif
79}
80
82{
83 Q_EMIT customContextMenuRequested(mapToGlobal(event->pos()));
84 event->accept();
85}
86
88{
89 //Do not propagate the rmb event, to prevent other tool context menus from appearing
90 if (event->button() == Qt::RightButton) {
91 event->accept();
92 } else {
93 QWidget::mousePressEvent(event);
94 }
95}
96
98{
99 d->orientation = orientation;
100}
101
103{
104 d->handle_icon = KisIconUtils::loadIcon(d->handle_icon.name());
105}
KisMagneticGraph::vertex_descriptor target(typename KisMagneticGraph::edge_descriptor e, KisMagneticGraph g)
SelectionActionsBarOrientation
Definition kis_config.h:791
void mousePressEvent(QMouseEvent *event) override
void contextMenuEvent(QContextMenuEvent *event) override
KisSelectionActionsPanelHandle(int size, Orientation orientation, QWidget *parent)
void draw(QPainter &painter, const KoColorDisplayRendererInterface *renderInterface)
virtual QImage convertImageToDisplayColorSpace(const QImage source) const =0
convertImageToDisplayColorSpace
virtual QPalette systemPaletteForDisplayColorSpace() const =0
systemPaletteForDisplayColorSpace
QIcon loadIcon(const QString &name)