29#include <QApplication>
37#include <core/config.h>
107 QWidget *pThisWidget =
dynamic_cast< QWidget *
>( this );
109 QWidget *pParent =
dynamic_cast< QWidget *
>( pThisWidget->parent() );
111 QScrollArea *pScrollArea =
dynamic_cast< QScrollArea *
>( pParent->parent() );
163 QPoint pos = pWidget->mapFromGlobal( QCursor::pos() );
289 if ( pOther !=
this ) {
342 std::vector<Elem> v { e };
343 if ( !bCheck ||
m_pWidget->checkDeselectElements( v ) ) {
355 if ( !bCheck ||
m_pWidget->checkDeselectElements( v ) ) {
370 typedef typename std::set<Elem>::iterator
iterator;
419 && ev->button() == Qt::RightButton
420 && ev->buttons() == Qt::LeftButton
421 && ev->modifiers() & Qt::MetaModifier) {
442#ifdef H2CORE_HAVE_QT6
444 QEvent::MouseButtonPress,
445 pEv->position(), pEv->scenePosition(), pEv->globalPosition(),
447 Qt::MouseEventSynthesizedByApplication);
448#elif (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
450 QEvent::MouseButtonPress,
451 ev->localPos(), ev->windowPos(), ev->screenPos(),
453 Qt::MouseEventSynthesizedByApplication);
456 QEvent::MouseButtonPress,
457 ev->localPos(), ev->windowPos(), ev->screenPos(),
470 if ( (pEv->position() - pClickEv->position() ).manhattanLength() > QApplication::startDragDistance()
471 || (ev->timestamp() -
m_pClickEvent->timestamp()) > QApplication::startDragTime() ) {
506 ->m_selectionHighlightColor );
507 pen.setStyle( Qt::DotLine );
509 painter->setPen( pen );
510 painter->setBrush( Qt::NoBrush );
527 if ( ev->modifiers() & Qt::ControlModifier ) {
529 QRect r = QRect( pEv->position().toPoint(),
530 pEv->position().toPoint() );
531 std::vector<Elem> elems =
m_pWidget->elementsIntersecting( r );
532 for ( Elem e : elems) {
542 if ( ev->button() != Qt::RightButton && !
m_pSelectionGroup->m_selectedElements.empty() ) {
547 }
else if ( ev->button() == Qt::RightButton &&
m_pSelectionGroup->m_selectedElements.empty() ) {
550 QRect r = QRect( pEv->position().toPoint(),
551 pEv->position().toPoint() );
552 std::vector<Elem> elems =
m_pWidget->elementsIntersecting( r );
553 for ( Elem e : elems) {
573 if ( ev->button() == Qt::LeftButton) {
574 QRect r = QRect( pClickEv->position().toPoint(),
575 pEv->position().toPoint() );
576 std::vector<Elem> elems =
m_pWidget->elementsIntersecting( r );
580 bool bHitSelected =
false, bHitAny =
false;
581 for ( Elem elem : elems ) {
589 if ( bHitSelected ) {
591 if ( bHitSelected ) {
594 pClickEv->position().toPoint();
597 }
else if ( bHitAny &&
m_pWidget->canDragElements() ) {
604 m_lasso.setTopLeft( pClickEv->position().toPoint() );
605 m_lasso.setBottomRight( pEv->position().toPoint() );
621 m_lasso.setBottomRight( pEv->position().toPoint() );
623 if ( ev->modifiers() & Qt::ControlModifier ) {
632 for (
auto s : selected ) {
641 pClickEv->position().toPoint();
642 m_pWidget->selectionMoveUpdateEvent( ev );
690 if ( ev->matches( QKeySequence::SelectNextChar )
691 || ev->matches( QKeySequence::SelectPreviousChar )
692 || ev->matches( QKeySequence::SelectNextLine )
693 || ev->matches( QKeySequence::SelectPreviousLine )
694 || ev->matches( QKeySequence::SelectStartOfLine)
695 || ev->matches( QKeySequence::SelectEndOfLine )
696 || ev->matches( QKeySequence::SelectStartOfDocument )
697 || ev->matches( QKeySequence::SelectEndOfDocument ) ) {
712 }
else if ( ev->key() == Qt::Key_Enter || ev->key() == Qt::Key_Return ) {
717 bool bHitselected =
false;
718 for ( Elem e :
m_pWidget->elementsIntersecting(
m_pWidget->getKeyboardCursorRect() ) ) {
725 if ( bHitselected ) {
752 }
else if ( ev->key() == Qt::Key_Escape ) {
792 for (
auto s : selected ) {
797 QRect cursorPosition =
m_pWidget->getKeyboardCursorRect();
static Preferences * get_instance()
Returns a pointer to the current Preferences singleton stored in __instance.
Compatibility class to support QMouseEvent more esily in Qt5 and Qt6.
void paintSelection(QPainter *painter)
Paint selection-related elements (ie lasso)
bool isLasso() const
Is there an ongoing lasso gesture?
void addToSelection(Elem e)
void mouseReleaseEvent(QMouseEvent *ev)
void mouseClick(QMouseEvent *ev)
QMouseEvent * m_pClickEvent
Mouse event to deliver as 'click' or 'drag' events.
Qt::MouseButton m_mouseButton
Mouse button that began the gesture.
std::set< Elem >::iterator iterator
void removeFromSelection(Elem e, bool bCheck=true)
void updateWidgetGroup()
Update any widgets in this selection group.
QPoint m_movingOffset
Offset that a selection has been moved by.
void mouseDragUpdate(QMouseEvent *ev)
enum Selection::MouseState m_mouseState
enum Selection::SelectionState m_selectionState
void clearSelection(bool bCheck=true)
void merge(Selection *pOther)
Merge the selection groups of two Selection widgets.
DragScroller * m_pDragScroller
Scroller to use while dragging selections.
void cancelGesture()
Cancel any selection gesture (lasso, move, with keyboard or mouse) in progress.
QRect m_keyboardCursorStart
Keyboard cursor position at the start of a keyboard gesture.
bool keyPressEvent(QKeyEvent *ev)
Key press event filter.
bool isMouseGesture() const
Is there a mouse gesture in progress?
Selection(SelectionWidget< Elem > *w)
void updateKeyboardCursorPosition(QRect cursor)
Update the keyboard cursor.
bool isSelected(Elem e) const
Is an element in the set of currently selected elements?
std::shared_ptr< SelectionGroup > m_pSelectionGroup
void mousePressEvent(QMouseEvent *ev)
void mouseDragEnd(QMouseEvent *ev=nullptr)
bool isMoving() const
Is there an ongoing (and incomplete) selection movement gesture?
QPoint movingOffset() const
During a selection "move" gesture, return the current movement position relative to the start positio...
void mouseDragStart(QMouseEvent *ev)
std::set< Elem > m_checkpointSelectedElements
For gestures modifying a selection, store the initial selection set as a checkpoint to restore when r...
SelectionWidget< Elem > * m_pWidget
QRect m_lasso
Dimensions of a current selection lasso.
void mouseMoveEvent(QMouseEvent *ev)
Group of SelectionWidget objects sharing the same selection set.
std::set< Elem > m_selectedElements
std::set< SelectionWidget< Elem > * > m_selectionWidgets