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
14{
15 Private(int size) { this->size = size;};
17 QCursor held_cursor;
19 int size;
20};
21
23 QWidget(parent),
24 d(new Private(size))
25{
26 d->default_cursor = Qt::OpenHandCursor;
27 d->held_cursor = Qt::ClosedHandCursor;
28 d->handle_icon = KisIconUtils::loadIcon("drag-handle");
29 this->setCursor(d->default_cursor);
30 setFixedSize(size, size);
31 setAttribute(Qt::WA_AcceptTouchEvents);
32}
33
37
39{
40 if(held)
41 {
42 this->setCursor(d->held_cursor);
43 }
44 else
45 {
46 this->setCursor(d->default_cursor);
47 }
48}
49
50void KisSelectionActionsPanelHandle::draw(QPainter& painter, const KoColorDisplayRendererInterface *renderInterface)
51{
52 QRect rect = geometry();
53
54 // Adjust the rect a bit to fill the right side of the bar properly
55 painter.fillRect(rect.marginsAdded(QMargins(-3, 4, 1, 4)), renderInterface->systemPaletteForDisplayColorSpace().window().color());
56
57 // Adjusting the icon location a bit to be properly centered
58 QImage ic = renderInterface->convertImageToDisplayColorSpace(d->handle_icon.pixmap(d->size, d->size).toImage());
59#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
60 QRect target = QRect(QPoint(0, 0), ic.size()/ic.devicePixelRatioF());
61#else
62 QRect target = QRect(QPoint(0, 0), ic.deviceIndependentSize().toSize());
63#endif
64 target.moveCenter(rect.center() + QPoint(3, 0));
65 painter.drawImage(target, ic);
66}
67
69{
70 Q_EMIT customContextMenuRequested(mapToGlobal(event->pos()));
71 event->accept();
72}
73
75{
76 //Do not propagate the rmb event, to prevent other tool context menus from appearing
77 if (event->button() == Qt::RightButton) {
78 event->accept();
79 } else {
80 QWidget::mousePressEvent(event);
81 }
82}
KisMagneticGraph::vertex_descriptor target(typename KisMagneticGraph::edge_descriptor e, KisMagneticGraph g)
void mousePressEvent(QMouseEvent *event) override
void contextMenuEvent(QContextMenuEvent *event) override
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)