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

#include <kis_selection_actions_panel.h>

+ Inheritance diagram for KisSelectionActionsPanel:

Classes

struct  Private
 

Public Member Functions

void canvasWidgetChanged (KisCanvasWidgetBase *canvas)
 
void draw (QPainter &painter)
 
bool eventFilter (QObject *obj, QEvent *event) override
 
 KisSelectionActionsPanel ()=delete
 
 KisSelectionActionsPanel (KisViewManager *viewManager)
 
void setEnabled (bool enabled)
 
void setVisible (bool visible)
 
 ~KisSelectionActionsPanel ()
 

Private Member Functions

void drawActionBarBackground (QPainter &gc) const
 
bool handleMove (QEvent *event, const QPoint &pos)
 
bool handlePress (QEvent *event, const QPoint &pos, Qt::MouseButton button=Qt::LeftButton)
 
bool handleRelease (QEvent *event, const QPoint &pos)
 
QPoint initialDragHandlePosition () const
 
QPoint mouseEventPos (const QMouseEvent *mouseEvent)
 
void movePanelWidgets ()
 Moves all the widgets that are a part of the panel.
 
QPoint tabletEventPos (const QTabletEvent *tabletEvent)
 
bool touchEventPos (const QTouchEvent *touchEvent, QPoint &outPos)
 
QPoint transformHandleCoords (QPoint pos)
 
QPoint updateCanvasBoundaries (QPoint position, QWidget *canvasWidget) const
 

Private Attributes

QScopedPointer< Privated
 

Detailed Description

Definition at line 30 of file kis_selection_actions_panel.h.

Constructor & Destructor Documentation

◆ KisSelectionActionsPanel() [1/2]

KisSelectionActionsPanel::KisSelectionActionsPanel ( )
delete

◆ KisSelectionActionsPanel() [2/2]

KisSelectionActionsPanel::KisSelectionActionsPanel ( KisViewManager * viewManager)

Definition at line 88 of file kis_selection_actions_panel.cpp.

89 : d(new Private)
90{
91 d->m_viewManager = viewManager;
92 d->m_selectionManager = viewManager->selectionManager();
93
94 // Setup buttons...
95 for (const ActionButtonData &buttonData : Private::buttonData()) {
96 KisSelectionActionsPanelButton *button = new KisSelectionActionsPanelButton(buttonData.iconName, buttonData.tooltip, BUTTON_SIZE, viewManager->canvas());
97 connect(button, &QAbstractButton::clicked, d->m_selectionManager, buttonData.slot);
98 d->m_buttons.append(button);
99 }
100
101 d->m_handleWidget = new KisSelectionActionsPanelHandle(BUTTON_SIZE, viewManager->canvas());
102}
Custom widget for selection actions panel buttons, to prevent them being drawn over the pop-up palett...
QWidget * canvas() const
Return the actual widget that is displaying the current image.
KisSelectionManager * selectionManager()
static constexpr int BUTTON_SIZE
QString button(const QWheelEvent &ev)

References button(), BUTTON_SIZE, KisSelectionActionsPanel::Private::buttonData(), KisViewManager::canvas(), d, and KisViewManager::selectionManager().

◆ ~KisSelectionActionsPanel()

KisSelectionActionsPanel::~KisSelectionActionsPanel ( )

Definition at line 104 of file kis_selection_actions_panel.cpp.

105{
106}

Member Function Documentation

◆ canvasWidgetChanged()

void KisSelectionActionsPanel::canvasWidgetChanged ( KisCanvasWidgetBase * canvas)

Definition at line 234 of file kis_selection_actions_panel.cpp.

235{
236
237 Q_FOREACH(QWidget* btn, d->m_buttons) {
238 btn->setParent(canvas->widget());
239 btn->show();
240 }
241
242 d->m_handleWidget->setParent(canvas->widget());
243 d->m_handleWidget->show();
244}
virtual QWidget * widget()=0

References d, and KisAbstractCanvasWidget::widget().

◆ draw()

void KisSelectionActionsPanel::draw ( QPainter & painter)

Definition at line 108 of file kis_selection_actions_panel.cpp.

109{
110 KisSelectionSP selection = d->m_viewManager->selection();
111
112 if (!selection || !d->m_enabled || !d->m_visible) {
113 return;
114 }
115
117 Q_FOREACH(KisSelectionActionsPanelButton* button, d->m_buttons){
118 button->draw(painter);
119 }
120
121 d->m_handleWidget->draw(painter);
122}
void drawActionBarBackground(QPainter &gc) const

References button(), d, and drawActionBarBackground().

◆ drawActionBarBackground()

void KisSelectionActionsPanel::drawActionBarBackground ( QPainter & gc) const
private

Definition at line 296 of file kis_selection_actions_panel.cpp.

297{
298 const int cornerRadius = 4;
299 QColor outlineColor = qApp->palette().window().color();
300
301 QColor bgColor = qApp->palette().window().color();
302
303 //Slightly lighten the color, to force `dragColor` to move it in the lighter direction, without this it will always darken the color
305 bgColor = bgColor.lighter(120);
306 }
307
308 KisPaintingTweaks::dragColor(&bgColor, outlineColor, 0.25);
309
310 QColor bgColorTrans = bgColor;
311 bgColorTrans.setAlpha(80);
312 const int outline_width = 4;
313
314 //an outer 1px wide outline for contrast against the background
315 QRectF contrastOutline(d->m_dragHandle->position - QPoint(outline_width + 1,outline_width + 1), QSize(d->m_actionBarWidth, BUTTON_SIZE) +QSize(outline_width + 1,outline_width + 1) * 2);
316 QRectF midOutline(d->m_dragHandle->position - QPoint(outline_width,outline_width), QSize(d->m_actionBarWidth, BUTTON_SIZE) +QSize(outline_width,outline_width) * 2);
317 //Add a bit of padding here for the icons
318 QRectF centerBackground(d->m_dragHandle->position - QPoint(outline_width,outline_width) / 2, QSize(d->m_actionBarWidth - BUTTON_SIZE, BUTTON_SIZE) +QSize(outline_width,outline_width));
319 QPainterPath bgPath;
320 QPainterPath outlinePath;
321 QPainterPath contrastOutlinePath;
322
323 bgPath.addRoundedRect(centerBackground, cornerRadius, cornerRadius);
324 outlinePath.addRoundedRect(midOutline, cornerRadius, cornerRadius);
325 contrastOutlinePath.addRoundedRect(contrastOutline, cornerRadius, cornerRadius);
326
327 painter.fillPath(contrastOutlinePath, bgColorTrans);
328 painter.fillPath(outlinePath, outlineColor);
329 painter.fillPath(bgPath, bgColor);
330}
void dragColor(QColor *color, const QColor &baseColor, qreal threshold)

References BUTTON_SIZE, d, KisPaintingTweaks::dragColor(), and KisIconUtils::useDarkIcons().

◆ eventFilter()

bool KisSelectionActionsPanel::eventFilter ( QObject * obj,
QEvent * event )
override

Definition at line 171 of file kis_selection_actions_panel.cpp.

172{
173 Q_UNUSED(obj);
174
175 switch (event->type()) {
176 case QEvent::MouseButtonPress: {
177 const QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
178 return handlePress(event, mouseEventPos(mouseEvent), mouseEvent->button());
179 }
180 case QEvent::TabletPress: {
181 const QTabletEvent *tabletEvent = static_cast<QTabletEvent *>(event);
182 return handlePress(event, tabletEventPos(tabletEvent));
183 }
184 case QEvent::TouchBegin: {
185 const QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
186 QPoint pos;
187 if (touchEventPos(touchEvent, pos)) {
188 return handlePress(event, pos);
189 }
190 break;
191 }
192
193 case QEvent::MouseMove:
194 if (d->m_pressed) {
195 const QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
196 return handleMove(event, mouseEventPos(mouseEvent));
197 }
198 break;
199 case QEvent::TabletMove:
200 if (d->m_pressed) {
201 const QTabletEvent *tabletEvent = static_cast<QTabletEvent *>(event);
202 return handleMove(event, tabletEventPos(tabletEvent));
203 }
204 break;
205 case QEvent::TouchUpdate:
206 if (d->m_pressed) {
207 const QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
208 QPoint pos;
209 if (touchEventPos(touchEvent, pos)) {
210 return handleMove(event, pos);
211 }
212 }
213 break;
214
215 case QEvent::MouseButtonRelease:
216 case QEvent::TabletRelease:
217 case QEvent::TouchEnd:
218 case QEvent::TouchCancel:
219 if (d->m_pressed) {
220 d->m_handleWidget->set_held(false);
221 d->m_pressed = false;
222 event->accept();
223 return true;
224 }
225 break;
226
227 default:
228 break;
229 }
230 return false;
231}
bool handlePress(QEvent *event, const QPoint &pos, Qt::MouseButton button=Qt::LeftButton)
QPoint tabletEventPos(const QTabletEvent *tabletEvent)
bool handleMove(QEvent *event, const QPoint &pos)
QPoint mouseEventPos(const QMouseEvent *mouseEvent)
bool touchEventPos(const QTouchEvent *touchEvent, QPoint &outPos)

References d, handleMove(), handlePress(), mouseEventPos(), tabletEventPos(), and touchEventPos().

◆ handleMove()

bool KisSelectionActionsPanel::handleMove ( QEvent * event,
const QPoint & pos )
private

Definition at line 351 of file kis_selection_actions_panel.cpp.

352{
353 QWidget *canvasWidget = d->m_viewManager->canvas();
354 QPoint newPos = pos - d->m_dragHandle->dragOrigin;
355 d->m_dragHandle->position = updateCanvasBoundaries(newPos, canvasWidget);
357 canvasWidget->update();
358 event->accept();
359 return true;
360}
void movePanelWidgets()
Moves all the widgets that are a part of the panel.
QPoint updateCanvasBoundaries(QPoint position, QWidget *canvasWidget) const

References d, movePanelWidgets(), and updateCanvasBoundaries().

◆ handlePress()

bool KisSelectionActionsPanel::handlePress ( QEvent * event,
const QPoint & pos,
Qt::MouseButton button = Qt::LeftButton )
private

Definition at line 332 of file kis_selection_actions_panel.cpp.

333{
334 if (d->m_pressed) {
335 event->accept();
336 return true;
337 }
338
339 if (button == Qt::LeftButton) {
340 d->m_pressed = true;
341 d->m_dragHandle->dragOrigin = pos - d->m_dragHandle->position;
342 d->m_handleWidget->set_held(true);
343
344 event->accept();
345 return true;
346 }
347
348 return false;
349}

References button(), and d.

◆ handleRelease()

bool KisSelectionActionsPanel::handleRelease ( QEvent * event,
const QPoint & pos )
private

◆ initialDragHandlePosition()

QPoint KisSelectionActionsPanel::initialDragHandlePosition ( ) const
private

Definition at line 276 of file kis_selection_actions_panel.cpp.

277{
278 KisSelectionSP selection = d->m_viewManager->selection();
279 KisCanvasWidgetBase *canvas = dynamic_cast<KisCanvasWidgetBase*>(d->m_viewManager->canvas());
280 KIS_ASSERT(selection);
281 KIS_ASSERT(canvas);
282
283 QRectF selectionBounds = selection->selectedRect();
284 int selectionBottom = selectionBounds.bottom();
285 QPointF selectionCenter = selectionBounds.center();
286 QPointF bottomCenter(selectionCenter.x(), selectionBottom);
287
288 QPointF widgetBottomCenter = canvas->coordinatesConverter()->imageToWidget(bottomCenter); // converts current selection's QPointF into canvasWidget's QPointF space
289
290 widgetBottomCenter.setX(widgetBottomCenter.x() - (d->m_actionBarWidth / 2)); // centers toolbar midpoint with the selection center
291 widgetBottomCenter.setY(widgetBottomCenter.y() + BUFFER_SPACE);
292
293 return updateCanvasBoundaries(widgetBottomCenter.toPoint(), d->m_viewManager->canvas());
294}
KisCoordinatesConverter * coordinatesConverter() const
_Private::Traits< T >::Result imageToWidget(const T &obj) const
#define KIS_ASSERT(cond)
Definition kis_assert.h:33
static constexpr int BUFFER_SPACE
QRect selectedRect() const

References BUFFER_SPACE, KisCanvasWidgetBase::coordinatesConverter(), d, KisCoordinatesConverter::imageToWidget(), KIS_ASSERT, KisSelection::selectedRect(), and updateCanvasBoundaries().

◆ mouseEventPos()

QPoint KisSelectionActionsPanel::mouseEventPos ( const QMouseEvent * mouseEvent)
private

Definition at line 376 of file kis_selection_actions_panel.cpp.

377{
378#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
379 return transformHandleCoords(mouseEvent->position().toPoint());
380#else
381 return transformHandleCoords(mouseEvent->pos());
382#endif
383}

References transformHandleCoords().

◆ movePanelWidgets()

void KisSelectionActionsPanel::movePanelWidgets ( )
private

Moves all the widgets that are a part of the panel.

Definition at line 362 of file kis_selection_actions_panel.cpp.

363{
364 d->m_handleWidget->move(d->m_dragHandle->position.x() + d->m_buttons.size() * BUTTON_SIZE, d->m_dragHandle->position.y());
365 d->m_handleWidget->show();
366
367 int i = 0;
368 Q_FOREACH(KisSelectionActionsPanelButton *button, d->m_buttons) {
369 int buttonPosition = i * BUTTON_SIZE;
370 button->move(d->m_dragHandle->position.x() + buttonPosition, d->m_dragHandle->position.y());
371 button->show();
372 i++;
373 }
374}

References button(), BUTTON_SIZE, and d.

◆ setEnabled()

void KisSelectionActionsPanel::setEnabled ( bool enabled)

Definition at line 161 of file kis_selection_actions_panel.cpp.

162{
163 bool configurationChanged = enabled != d->m_enabled;
164 d->m_enabled = enabled;
165 if (configurationChanged) {
166 // Reset visibility when configuration changes
167 setVisible(enabled);
168 }
169}

References d, and setVisible().

◆ setVisible()

void KisSelectionActionsPanel::setVisible ( bool visible)

Definition at line 124 of file kis_selection_actions_panel.cpp.

125{
126 QWidget *canvasWidget = dynamic_cast<QWidget *>(d->m_viewManager->canvas());
127 if (!canvasWidget) {
128 return;
129 }
130
131 p_visible &= d->m_enabled;
132
133 const bool VISIBILITY_CHANGED = d->m_visible != p_visible;
134 if (!VISIBILITY_CHANGED) {
135 return;
136 }
137
138 if (d->m_viewManager->selection() && p_visible) { // Now visible!
139 d->m_handleWidget->installEventFilter(this);
140
141 if (!d->m_dragHandle) {
142 d->m_dragHandle.reset(new Private::DragHandle());
143 d->m_dragHandle->position = initialDragHandlePosition();
145 }
146 } else { // Now hidden!
147 d->m_handleWidget->removeEventFilter(this);
148
149 for (KisSelectionActionsPanelButton *button : d->m_buttons) {
150 button->hide();
151 }
152 d->m_handleWidget->hide();
153
154 d->m_pressed = false;
155 d->m_dragHandle.reset();
156 }
157
158 d->m_visible = p_visible;
159}

References button(), d, initialDragHandlePosition(), and movePanelWidgets().

◆ tabletEventPos()

QPoint KisSelectionActionsPanel::tabletEventPos ( const QTabletEvent * tabletEvent)
private

Definition at line 385 of file kis_selection_actions_panel.cpp.

386{
387#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
388 return transformHandleCoords(tabletEvent->position().toPoint());
389#else
390 return transformHandleCoords(tabletEvent->pos());
391#endif
392}

References transformHandleCoords().

◆ touchEventPos()

bool KisSelectionActionsPanel::touchEventPos ( const QTouchEvent * touchEvent,
QPoint & outPos )
private

Definition at line 394 of file kis_selection_actions_panel.cpp.

395{
396#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
397 if (touchEvent->pointCount() < 1) {
398 return false;
399 } else {
400 outPos = transformHandleCoords(touchEvent->points().first().position().toPoint());
401 return true;
402 }
403#else
404 const QList<QTouchEvent::TouchPoint> &touchPoints = touchEvent->touchPoints();
405 if (touchPoints.isEmpty()) {
406 return false;
407 } else {
408 outPos = transformHandleCoords(touchPoints.first().pos().toPoint());
409 return true;
410 }
411#endif
412}

References transformHandleCoords().

◆ transformHandleCoords()

QPoint KisSelectionActionsPanel::transformHandleCoords ( QPoint pos)
private

Definition at line 414 of file kis_selection_actions_panel.cpp.

414 {
415 return d->m_dragHandle->position + pos;
416}

References d.

◆ updateCanvasBoundaries()

QPoint KisSelectionActionsPanel::updateCanvasBoundaries ( QPoint position,
QWidget * canvasWidget ) const
private

Definition at line 246 of file kis_selection_actions_panel.cpp.

247{
248 QRect canvasBounds = canvasWidget->rect();
249
250 const int ACTION_BAR_WIDTH = d->m_actionBarWidth;
251 const int ACTION_BAR_HEIGHT = BUTTON_SIZE;
252
253 int pos_x_min = canvasBounds.left() + BUFFER_SPACE;
254 int pos_x_max = canvasBounds.right() - ACTION_BAR_WIDTH - BUFFER_SPACE;
255
256 int pos_y_min = canvasBounds.top() + BUFFER_SPACE;
257 int pos_y_max = canvasBounds.bottom() - ACTION_BAR_HEIGHT - BUFFER_SPACE;
258
259 //Ensure that max is always bigger than min
260 //If the window is small enough max could be smaller than min
261 if (pos_x_max < pos_x_min) {
262 pos_x_max = pos_x_min;
263 }
264
265 //It is pretty implausible for it to happen vertically but better safe than sorry
266 if (pos_y_max < pos_y_min) {
267 pos_y_max = pos_y_min;
268 }
269
270 position.setX(qBound(pos_x_min, position.x(), pos_x_max));
271 position.setY(qBound(pos_y_min, position.y(), pos_y_max));
272
273 return position;
274}

References BUFFER_SPACE, BUTTON_SIZE, and d.

Member Data Documentation

◆ d

QScopedPointer<Private> KisSelectionActionsPanel::d
private

Definition at line 65 of file kis_selection_actions_panel.h.


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