diff options
Diffstat (limited to 'src-qt5')
-rw-r--r-- | src-qt5/src-glwidgets/gltest/main.cpp | 2 | ||||
-rwxr-xr-x | src-qt5/src-glwidgets/gltest/test | bin | 56367 -> 58021 bytes | |||
-rw-r--r-- | src-qt5/src-glwidgets/glw-base.cpp | 14 | ||||
-rw-r--r-- | src-qt5/src-glwidgets/glw-base.h | 4 | ||||
-rw-r--r-- | src-qt5/src-glwidgets/glw-widget.cpp | 17 | ||||
-rw-r--r-- | src-qt5/src-glwidgets/glw-widget.h | 4 |
6 files changed, 33 insertions, 8 deletions
diff --git a/src-qt5/src-glwidgets/gltest/main.cpp b/src-qt5/src-glwidgets/gltest/main.cpp index c3edd088..972c4225 100644 --- a/src-qt5/src-glwidgets/gltest/main.cpp +++ b/src-qt5/src-glwidgets/gltest/main.cpp @@ -32,7 +32,7 @@ int main(int argc, char** argv){ anim.setEndValue(QRect(0,0,200,200)); anim.setDuration(1500); anim.setLoopCount(-1); - anim.start(); + //anim.start(); /*QPushButton but(&base); but.setText("button"); but.setGeometry(100,100,50,50); diff --git a/src-qt5/src-glwidgets/gltest/test b/src-qt5/src-glwidgets/gltest/test Binary files differindex cb8fe872..cf9d2c31 100755 --- a/src-qt5/src-glwidgets/gltest/test +++ b/src-qt5/src-glwidgets/gltest/test diff --git a/src-qt5/src-glwidgets/glw-base.cpp b/src-qt5/src-glwidgets/glw-base.cpp index 8841743d..d4279c61 100644 --- a/src-qt5/src-glwidgets/glw-base.cpp +++ b/src-qt5/src-glwidgets/glw-base.cpp @@ -9,12 +9,17 @@ GLW_Base::GLW_Base(QWidget *parent, Qt::WindowFlags f) : QOpenGLWidget(parent,f){ bg_color = QColor(Qt::black); + mouse_over_child = 0; } GLW_Base::~GLW_Base(){ } +QWidget * GLW_Base::mouseOverWidget(){ + return mouse_over_child; +} + // --- PUBLIC SLOTS --- void GLW_Base::setBackgroundColor(QColor color){ bg_color = color; @@ -32,7 +37,16 @@ void GLW_Base::repaintArea(QRect rect){ paintEvent(new QPaintEvent(rect)); } +void GLW_Base::setMouseOverWidget(QWidget *child){ + mouse_over_child = child; +} + // --- PROTECTED --- +void GLW_Base::mouseMoveEvent(QMouseEvent *ev){ + mouse_over_child = 0; //reset this flag - mouse is over the base right now + QWidget::mouseMoveEvent(ev); +} + void GLW_Base::resizeEvent(QResizeEvent *ev){ QOpenGLWidget::resizeEvent(ev); if(!bg_img.isNull()){ diff --git a/src-qt5/src-glwidgets/glw-base.h b/src-qt5/src-glwidgets/glw-base.h index 729aa68e..3c3d1d4e 100644 --- a/src-qt5/src-glwidgets/glw-base.h +++ b/src-qt5/src-glwidgets/glw-base.h @@ -19,11 +19,13 @@ class GLW_Base : public QOpenGLWidget{ private: QColor bg_color; QImage bg_img; + QWidget *mouse_over_child; public: GLW_Base(QWidget *parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags()); ~GLW_Base(); + QWidget * mouseOverWidget(); private slots: @@ -31,11 +33,13 @@ public slots: void setBackgroundColor(QColor color); void setBackground(QRect geom, QImage img); void repaintArea(QRect); + void setMouseOverWidget(QWidget*); signals: void BaseResized(); protected: + void mouseMoveEvent(QMouseEvent *ev); void resizeEvent(QResizeEvent *ev); void paintEvent(QPaintEvent *ev); }; diff --git a/src-qt5/src-glwidgets/glw-widget.cpp b/src-qt5/src-glwidgets/glw-widget.cpp index d07c0431..e6c98d74 100644 --- a/src-qt5/src-glwidgets/glw-widget.cpp +++ b/src-qt5/src-glwidgets/glw-widget.cpp @@ -10,7 +10,6 @@ // --- PUBLIC --- GLW_Widget::GLW_Widget(QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f){ glw_base = 0; - this->setMouseTracking(true); draggable = false; drag_offset = QPoint(); } @@ -25,10 +24,7 @@ QRect GLW_Widget::widgetRect(){ } bool GLW_Widget::mouseOverWidget(){ - QPoint pos = this->mapFromGlobal(QCursor::pos()); - QRect geom(QPoint(0,0), this->size()); - return geom.contains(pos) || (draggable && !drag_offset.isNull()); - + return (glw_base->mouseOverWidget()==this); } void GLW_Widget::setGLBase(GLW_Base *base){ @@ -63,6 +59,16 @@ void GLW_Widget::paintChildren(QStylePainter *painter, QPaintEvent *ev){ // --- PROTECTED --- +void GLW_Widget::enterEvent(QEvent*){ + if(!mouseOverWidget()){ glw_base->setMouseOverWidget(this); } + this->update(); +} + +void GLW_Widget::leaveEvent(QEvent*){ + if(mouseOverWidget()){ glw_base->setMouseOverWidget(0); } + this->update(); +} + void GLW_Widget::mousePressEvent(QMouseEvent *ev){ if(!draggable){ QWidget::mousePressEvent(ev); return; } if(ev->button()==Qt::LeftButton){ @@ -78,6 +84,7 @@ void GLW_Widget::mouseReleaseEvent(QMouseEvent *ev){ } void GLW_Widget::mouseMoveEvent(QMouseEvent *ev){ + if(!mouseOverWidget()){ glw_base->setMouseOverWidget(this); } if(!draggable){ QWidget::mouseMoveEvent(ev); return; } if(!drag_offset.isNull()){ this->move( this->mapTo(glw_base, ev->pos()-drag_offset) ); diff --git a/src-qt5/src-glwidgets/glw-widget.h b/src-qt5/src-glwidgets/glw-widget.h index 91a1ae69..e4d7aa37 100644 --- a/src-qt5/src-glwidgets/glw-widget.h +++ b/src-qt5/src-glwidgets/glw-widget.h @@ -44,8 +44,8 @@ public slots: protected: - virtual void enterEvent(QEvent*){ this->update(); } - virtual void leaveEvent(QEvent*){ this->update(); } + virtual void enterEvent(QEvent*); + virtual void leaveEvent(QEvent*); virtual void mousePressEvent(QMouseEvent *ev); virtual void mouseReleaseEvent(QMouseEvent *ev); |