29#include <QApplication>
105 QWidget *pThisWidget =
dynamic_cast< QWidget *
>( this );
107 QWidget *pParent =
dynamic_cast< QWidget *
>( pThisWidget->parent() );
109 QScrollArea *pScrollArea =
dynamic_cast< QScrollArea *
>( pParent->parent() );
161 QPoint pos = pWidget->mapFromGlobal( QCursor::pos() );
287 if ( pOther !=
this ) {
340 std::vector<Elem> v { e };
341 if ( !bCheck ||
m_pWidget->checkDeselectElements( v ) ) {
353 if ( !bCheck ||
m_pWidget->checkDeselectElements( v ) ) {
368 typedef typename std::set<Elem>::iterator
iterator;
417 && ev->button() == Qt::RightButton
418 && ev->buttons() == Qt::LeftButton
419 && ev->modifiers() & Qt::MetaModifier) {
437#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
439 ev->localPos(), ev->windowPos(), ev->screenPos(),
441 Qt::MouseEventSynthesizedByApplication);
444 ev->localPos(), ev->windowPos(), ev->screenPos(),
454 if ( (ev->pos() -
m_pClickEvent->pos() ).manhattanLength() > QApplication::startDragDistance()
455 || (ev->timestamp() -
m_pClickEvent->timestamp()) > QApplication::startDragTime() ) {
490 ->m_selectionHighlightColor );
491 pen.setStyle( Qt::DotLine );
493 painter->setPen( pen );
494 painter->setBrush( Qt::NoBrush );
509 if ( ev->modifiers() & Qt::ControlModifier ) {
511 QRect r = QRect( ev->pos(), ev->pos() );
512 std::vector<Elem> elems =
m_pWidget->elementsIntersecting( r );
513 for ( Elem e : elems) {
523 if ( ev->button() != Qt::RightButton && !
m_pSelectionGroup->m_selectedElements.empty() ) {
528 }
else if ( ev->button() == Qt::RightButton &&
m_pSelectionGroup->m_selectedElements.empty() ) {
531 QRect r = QRect( ev->pos(), ev->pos() );
532 std::vector<Elem> elems =
m_pWidget->elementsIntersecting( r );
533 for ( Elem e : elems) {
550 if ( ev->button() == Qt::LeftButton) {
552 std::vector<Elem> elems =
m_pWidget->elementsIntersecting( r );
556 bool bHitSelected =
false, bHitAny =
false;
557 for ( Elem elem : elems ) {
565 if ( bHitSelected ) {
567 if ( bHitSelected ) {
572 }
else if ( bHitAny &&
m_pWidget->canDragElements() ) {
580 m_lasso.setBottomRight( ev->pos() );
593 m_lasso.setBottomRight( ev->pos() );
595 if ( ev->modifiers() & Qt::ControlModifier ) {
604 for (
auto s : selected ) {
613 m_pWidget->selectionMoveUpdateEvent( ev );
661 if ( ev->matches( QKeySequence::SelectNextChar )
662 || ev->matches( QKeySequence::SelectPreviousChar )
663 || ev->matches( QKeySequence::SelectNextLine )
664 || ev->matches( QKeySequence::SelectPreviousLine )
665 || ev->matches( QKeySequence::SelectStartOfLine)
666 || ev->matches( QKeySequence::SelectEndOfLine )
667 || ev->matches( QKeySequence::SelectStartOfDocument )
668 || ev->matches( QKeySequence::SelectEndOfDocument ) ) {
683 }
else if ( ev->key() == Qt::Key_Enter || ev->key() == Qt::Key_Return ) {
688 bool bHitselected =
false;
689 for ( Elem e :
m_pWidget->elementsIntersecting(
m_pWidget->getKeyboardCursorRect() ) ) {
696 if ( bHitselected ) {
723 }
else if ( ev->key() == Qt::Key_Escape ) {
763 for (
auto s : selected ) {
768 QRect cursorPosition =
m_pWidget->getKeyboardCursorRect();
static Preferences * get_instance()
Returns a pointer to the current Preferences singleton stored in __instance.
Selection management for editor widgets.
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