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

#include <kis_color_label_button.h>

+ Inheritance diagram for KisColorLabelMouseDragFilter:

Public Member Functions

 KisColorLabelMouseDragFilter (QObject *parent=nullptr)
 

Protected Member Functions

void checkSlideOverNeighborButtons (QMouseEvent *mouseEvent, class QAbstractButton *startingButton)
 
bool eventFilter (QObject *obj, QEvent *event) override
 

Private Types

enum  State { Idle , WaitingForDragLeave , WaitingForDragEnter }
 

Private Attributes

State currentState
 
QPoint lastKnownMousePosition
 

Detailed Description

Definition at line 77 of file kis_color_label_button.h.

Member Enumeration Documentation

◆ State

Enumerator
Idle 
WaitingForDragLeave 
WaitingForDragEnter 

Definition at line 78 of file kis_color_label_button.h.

78 {
79 Idle,
80 WaitingForDragLeave, //Waiting for mouse to exit first clicked while the mouse button is down.
81 WaitingForDragEnter //Waiting for mouse to slide across buttons within the same button group.
82 };

Constructor & Destructor Documentation

◆ KisColorLabelMouseDragFilter()

KisColorLabelMouseDragFilter::KisColorLabelMouseDragFilter ( QObject * parent = nullptr)

Definition at line 306 of file kis_color_label_button.cpp.

306 : QObject(parent)
307{
308 lastKnownMousePosition = QPoint(0,0);
310}

References currentState, Idle, and lastKnownMousePosition.

Member Function Documentation

◆ checkSlideOverNeighborButtons()

void KisColorLabelMouseDragFilter::checkSlideOverNeighborButtons ( QMouseEvent * mouseEvent,
class QAbstractButton * startingButton )
protected

Definition at line 391 of file kis_color_label_button.cpp.

392{
393 const QPoint currentPosition = mouseEvent->globalPos();
394
395 if (startingButton->group()) {
396 QList<QAbstractButton*> allButtons = startingButton->group()->buttons();
397
398 Q_FOREACH(QAbstractButton* button, allButtons) {
399 const QRect bounds = QRect(button->mapToGlobal(QPoint(0,0)), button->size());
400 const QPoint upperLeft = QPoint(qMin(lastKnownMousePosition.x(), currentPosition.x()), qMin(lastKnownMousePosition.y(), currentPosition.y()));
401 const QPoint lowerRight = QPoint(qMax(lastKnownMousePosition.x(), currentPosition.x()), qMax(lastKnownMousePosition.y(), currentPosition.y()));
402 const QRect mouseMovement = QRect(upperLeft, lowerRight);
403 if( bounds.intersects(mouseMovement) && !bounds.contains(lastKnownMousePosition)) {
404 button->click();
405 }
406 }
407 }
408}
#define bounds(x, a, b)
QString button(const QWheelEvent &ev)

References bounds, button(), and lastKnownMousePosition.

◆ eventFilter()

bool KisColorLabelMouseDragFilter::eventFilter ( QObject * obj,
QEvent * event )
overrideprotected

Definition at line 312 of file kis_color_label_button.cpp.

313{
314 if (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::MouseButtonDblClick) {
315 QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event);
316
318 lastKnownMousePosition = mouseEvent->globalPos();
319
320 return true;
321
322 } else if (event->type() == QEvent::MouseButtonRelease) {
323 QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event);
324 QAbstractButton* startingButton = static_cast<QAbstractButton*>(obj);
325
326 //If we never left, toggle the original button.
328 if ( startingButton->group() && (mouseEvent->modifiers() & Qt::SHIFT)) {
329 KisColorLabelFilterGroup* const group = static_cast<KisColorLabelFilterGroup*>(startingButton->group());
330 const QList<QAbstractButton*> viableCheckedButtons = group->checkedViableButtons();
331
332 const int buttonsEnabled = viableCheckedButtons.count();
333 const bool shouldChangeIsolation = (buttonsEnabled == 1) && (viableCheckedButtons.first() == startingButton);
334 const bool shouldIsolate = (buttonsEnabled != 1) || !shouldChangeIsolation;
335
336 Q_FOREACH(QAbstractButton* otherBtn, group->viableButtons()) {
337 if (otherBtn == startingButton){
338 startingButton->setChecked(true);
339 } else {
340 otherBtn->setChecked(!shouldIsolate);
341 }
342 }
343
344 } else {
345 startingButton->click();
346 }
347 }
348
350 lastKnownMousePosition = mouseEvent->globalPos();
351
352 return true;
353
354 } else if (event->type() == QEvent::MouseMove) {
355
357 QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event);
358 QWidget* firstClicked = static_cast<QWidget*>(obj);
359 const QPointF localPosition = mouseEvent->localPos();
360
361 if (!firstClicked->rect().contains(localPosition.x(), localPosition.y())) {
362 QAbstractButton* btn = static_cast<QAbstractButton*>(obj);
363 btn->click();
364
365 checkSlideOverNeighborButtons(mouseEvent, btn);
366
368 }
369
370 lastKnownMousePosition = mouseEvent->globalPos();
371
372 return true;
373
374 } else if (currentState == WaitingForDragEnter) {
375 QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event);
376 QAbstractButton* startingButton = static_cast<QAbstractButton*>(obj);
377 const QPoint currentPosition = mouseEvent->globalPos();
378
379 checkSlideOverNeighborButtons(mouseEvent, startingButton);
380
381 lastKnownMousePosition = currentPosition;
382
383 return true;
384 }
385
386 }
387
388 return false;
389}
QList< QAbstractButton * > viableButtons() const
QList< QAbstractButton * > checkedViableButtons() const
void checkSlideOverNeighborButtons(QMouseEvent *mouseEvent, class QAbstractButton *startingButton)

References KisColorLabelFilterGroup::checkedViableButtons(), checkSlideOverNeighborButtons(), currentState, Idle, lastKnownMousePosition, KisColorLabelFilterGroup::viableButtons(), WaitingForDragEnter, and WaitingForDragLeave.

Member Data Documentation

◆ currentState

State KisColorLabelMouseDragFilter::currentState
private

Definition at line 84 of file kis_color_label_button.h.

◆ lastKnownMousePosition

QPoint KisColorLabelMouseDragFilter::lastKnownMousePosition
private

Definition at line 85 of file kis_color_label_button.h.


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