Warning, file /sdk/ktechlab/src/eventinfo.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /*************************************************************************** 0002 * Copyright (C) 2005 by David Saxton * 0003 * david@bluehaze.org * 0004 * * 0005 * This program is free software; you can redistribute it and/or modify * 0006 * it under the terms of the GNU General Public License as published by * 0007 * the Free Software Foundation; either version 2 of the License, or * 0008 * (at your option) any later version. * 0009 ***************************************************************************/ 0010 0011 #include "eventinfo.h" 0012 #include "itemdocument.h" 0013 #include "itemview.h" 0014 0015 #include <QMouseEvent> 0016 0017 EventInfo::EventInfo() 0018 { 0019 reset(); 0020 } 0021 0022 EventInfo::EventInfo(ItemView *itemView, QEvent *e) 0023 { 0024 Q_UNUSED(itemView); 0025 Q_UNUSED(e); 0026 reset(); 0027 } 0028 0029 void EventInfo::extractPos(ItemView *itemView, const QPoint &contentsMouseClick) 0030 { 0031 pos = itemView->mousePosToCanvasPos(contentsMouseClick); 0032 } 0033 0034 EventInfo::EventInfo(ItemView *itemView, QMouseEvent *e) 0035 { 0036 reset(); 0037 0038 extractPos(itemView, e->pos()); 0039 globalPos = e->globalPos(); 0040 isRightClick = e->button() == Qt::RightButton; 0041 isMiddleClick = e->button() == Qt::MidButton; 0042 ctrlPressed = e->modifiers() & Qt::ControlModifier; // QMouseEvent::ControlButton; 0043 shiftPressed = e->modifiers() & Qt::ShiftModifier; // QMouseEvent::ShiftButton; 0044 altPressed = e->modifiers() & Qt::AltModifier; // QMouseEvent::AltButton; 0045 if (ItemDocument *id = dynamic_cast<ItemDocument *>(itemView->document())) 0046 qcanvasItemClickedOn = id->itemAtTop(pos); 0047 scrollDelta = 0; 0048 scrollOrientation = Qt::Vertical; 0049 } 0050 0051 EventInfo::EventInfo(ItemView *itemView, QWheelEvent *e) 0052 { 0053 reset(); 0054 0055 extractPos(itemView, e->pos()); 0056 globalPos = e->globalPos(); 0057 ctrlPressed = e->modifiers() & Qt::ControlModifier; // QMouseEvent::ControlButton; 0058 shiftPressed = e->modifiers() & Qt::ShiftModifier; // QMouseEvent::ShiftButton; 0059 altPressed = e->modifiers() & Qt::AltModifier; // QMouseEvent::AltButton; 0060 if (ItemDocument *id = dynamic_cast<ItemDocument *>(itemView->document())) 0061 qcanvasItemClickedOn = id->itemAtTop(pos); 0062 scrollDelta = e->delta(); 0063 scrollOrientation = e->orientation(); 0064 } 0065 0066 void EventInfo::reset() 0067 { 0068 isRightClick = false; 0069 isMiddleClick = false; 0070 ctrlPressed = false; 0071 shiftPressed = false; 0072 altPressed = false; 0073 qcanvasItemClickedOn = nullptr; 0074 scrollDelta = 0; 0075 scrollOrientation = Qt::Vertical; 0076 } 0077 0078 QMouseEvent *EventInfo::mousePressEvent(int dx, int dy) const 0079 { 0080 return new QMouseEvent(QEvent::MouseButtonPress, 0081 pos + QPoint(dx, dy), 0082 (isRightClick ? Qt::RightButton : Qt::LeftButton), 0083 (isRightClick ? Qt::RightButton : Qt::LeftButton), 0084 (ctrlPressed ? Qt::ControlModifier : Qt::NoModifier) | (shiftPressed ? Qt::ShiftModifier : Qt::NoModifier) | (altPressed ? Qt::AltModifier : Qt::NoModifier)); 0085 } 0086 0087 QMouseEvent *EventInfo::mouseReleaseEvent(int dx, int dy) const 0088 { 0089 return new QMouseEvent(QEvent::MouseButtonRelease, 0090 pos + QPoint(dx, dy), 0091 (isRightClick ? Qt::RightButton : Qt::LeftButton), 0092 Qt::NoButton 0093 /*(isRightClick ? Qt::RightButton : Qt::LeftButton) 0094 * - 2017.09.18 - this is the state after the mouse has been released */ 0095 , 0096 (ctrlPressed ? Qt::ControlModifier : Qt::NoModifier) | (shiftPressed ? Qt::ShiftModifier : Qt::NoModifier) | (altPressed ? Qt::AltModifier : Qt::NoModifier)); 0097 } 0098 0099 QMouseEvent *EventInfo::mouseDoubleClickEvent(int dx, int dy) const 0100 { 0101 return new QMouseEvent(QEvent::MouseButtonDblClick, 0102 pos + QPoint(dx, dy), 0103 (isRightClick ? Qt::RightButton : Qt::LeftButton), 0104 (isRightClick ? Qt::RightButton : Qt::LeftButton), 0105 (ctrlPressed ? Qt::ControlModifier : Qt::NoModifier) | (shiftPressed ? Qt::ShiftModifier : Qt::NoModifier) | (altPressed ? Qt::AltModifier : Qt::NoModifier)); 0106 } 0107 0108 QMouseEvent *EventInfo::mouseMoveEvent(int dx, int dy) const 0109 { 0110 return new QMouseEvent( 0111 QEvent::MouseMove, pos + QPoint(dx, dy), Qt::NoButton, Qt::NoButton, (ctrlPressed ? Qt::ControlModifier : Qt::NoModifier) | (shiftPressed ? Qt::ShiftModifier : Qt::NoModifier) | (altPressed ? Qt::AltModifier : Qt::NoModifier)); 0112 } 0113 0114 QWheelEvent *EventInfo::wheelEvent(int dx, int dy) const 0115 { 0116 return new QWheelEvent( 0117 pos + QPoint(dx, dy), scrollDelta, Qt::NoButton, (ctrlPressed ? Qt::ControlModifier : Qt::NoModifier) | (shiftPressed ? Qt::ShiftModifier : Qt::NoModifier) | (altPressed ? Qt::AltModifier : Qt::NoModifier), scrollOrientation); 0118 }