aboutsummaryrefslogtreecommitdiff
path: root/src-qt5
diff options
context:
space:
mode:
Diffstat (limited to 'src-qt5')
-rw-r--r--src-qt5/src-glwidgets/gltest/main.cpp25
-rwxr-xr-xsrc-qt5/src-glwidgets/gltest/testbin50927 -> 56367 bytes
-rw-r--r--src-qt5/src-glwidgets/glw-base.cpp7
-rw-r--r--src-qt5/src-glwidgets/glw-widget.cpp36
-rw-r--r--src-qt5/src-glwidgets/glw-widget.h21
5 files changed, 78 insertions, 11 deletions
diff --git a/src-qt5/src-glwidgets/gltest/main.cpp b/src-qt5/src-glwidgets/gltest/main.cpp
index 041ee5ff..c3edd088 100644
--- a/src-qt5/src-glwidgets/gltest/main.cpp
+++ b/src-qt5/src-glwidgets/gltest/main.cpp
@@ -2,7 +2,8 @@
#include <QApplication>
#include <QTimer>
#include <QColor>
-
+#include <QPushButton>
+#include <QPropertyAnimation>
#include "../glw-base.h"
#include "../glw-widget.h"
@@ -14,10 +15,28 @@ int main(int argc, char** argv){
GLW_Base base;
qDebug() << "Resize base widget";
base.resize(200,200);
- qDebug() << "Create colorchange";
+ qDebug() << "Create Other widgets";
+ GLW_Widget wgt1(&base);
+ wgt1.setGLBase(&base);
+ wgt1.setGeometry(50,50,50,50);
+ wgt1.setDraggable(true);
GLW_Widget wgt(&base);
wgt.setGLBase(&base);
- wgt.setGeometry(50,50,50,50);
+ wgt.setGeometry(75,50,50,50);
+ QPropertyAnimation anim(&wgt);
+ anim.setTargetObject(&wgt);
+ anim.setPropertyName("geometry");
+ //anim.setStartValue(QRect(-50,-50,50,50));
+ //anim.setEndValue(QRect(200,200,50,50));
+ anim.setStartValue(QRect(100,100,0,0));
+ anim.setEndValue(QRect(0,0,200,200));
+ anim.setDuration(1500);
+ anim.setLoopCount(-1);
+ anim.start();
+ /*QPushButton but(&base);
+ but.setText("button");
+ but.setGeometry(100,100,50,50);
+ but.setStyleSheet("background: rgba(0,150,0,125)");*/
colorchange CC(&base);
qDebug() << "Start Event loop";
base.show();
diff --git a/src-qt5/src-glwidgets/gltest/test b/src-qt5/src-glwidgets/gltest/test
index 5a69b0c3..cb8fe872 100755
--- a/src-qt5/src-glwidgets/gltest/test
+++ b/src-qt5/src-glwidgets/gltest/test
Binary files differ
diff --git a/src-qt5/src-glwidgets/glw-base.cpp b/src-qt5/src-glwidgets/glw-base.cpp
index e828df7f..8841743d 100644
--- a/src-qt5/src-glwidgets/glw-base.cpp
+++ b/src-qt5/src-glwidgets/glw-base.cpp
@@ -54,10 +54,13 @@ void GLW_Base::paintEvent(QPaintEvent *ev){
if( !child[i]->isWidgetType() ){ continue; } //not a widget
GLW_Widget *glww = qobject_cast<GLW_Widget*>(child[i]);
if(glww!=0){
- if(ev->rect().contains(glww->widgetRect())){
+ if(!ev->rect().intersected(glww->widgetRect()).isNull()){
glww->paintYourself(&painter, ev);
glww->paintChildren(&painter,ev);
}
- }
+ }/*else{
+ QWidget *widg = qobject_cast<QWidget*>(child[i]);
+ widg->render(&painter, widg->geometry().topLeft());
+ }*/
}
}
diff --git a/src-qt5/src-glwidgets/glw-widget.cpp b/src-qt5/src-glwidgets/glw-widget.cpp
index e24d8166..d07c0431 100644
--- a/src-qt5/src-glwidgets/glw-widget.cpp
+++ b/src-qt5/src-glwidgets/glw-widget.cpp
@@ -11,6 +11,8 @@
GLW_Widget::GLW_Widget(QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f){
glw_base = 0;
this->setMouseTracking(true);
+ draggable = false;
+ drag_offset = QPoint();
}
GLW_Widget::~GLW_Widget(){
@@ -25,7 +27,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);
+ return geom.contains(pos) || (draggable && !drag_offset.isNull());
}
@@ -39,7 +41,9 @@ void GLW_Widget::paintYourself(QStylePainter *painter, QPaintEvent *ev){
QRect rect = widgetRect();
rect = rect.intersected(ev->rect());
QColor color( mouseOverWidget() ? Qt::gray : Qt::yellow);
- color.setAlpha(125);
+ //if(this->windowOpacity()!=1.0){ qDebug() << "Opacity:" << this->windowOpacity(); }
+ //color.setAlpha( qRound(this->windowOpacity()*255) );
+ color.setAlpha( 125);
painter->fillRect(rect, color);
}
@@ -59,6 +63,34 @@ void GLW_Widget::paintChildren(QStylePainter *painter, QPaintEvent *ev){
// --- PROTECTED ---
+void GLW_Widget::mousePressEvent(QMouseEvent *ev){
+ if(!draggable){ QWidget::mousePressEvent(ev); return; }
+ if(ev->button()==Qt::LeftButton){
+ drag_offset = ev->pos();
+ }
+}
+
+void GLW_Widget::mouseReleaseEvent(QMouseEvent *ev){
+ if(!draggable){ QWidget::mouseReleaseEvent(ev); return; }
+ if(ev->button()==Qt::LeftButton){
+ if(drag_offset!=ev->pos()){ emit doneDragging(); }
+ drag_offset = QPoint(); } //reset offset
+}
+
+void GLW_Widget::mouseMoveEvent(QMouseEvent *ev){
+ if(!draggable){ QWidget::mouseMoveEvent(ev); return; }
+ if(!drag_offset.isNull()){
+ this->move( this->mapTo(glw_base, ev->pos()-drag_offset) );
+ }
+}
+
+
+void GLW_Widget::moveEvent(QMoveEvent *ev){
+ QRect oldgeom = QRect(ev->oldPos(), this->size());
+ QRect newgeom = QRect(ev->pos(), this->size());
+ emit repaintArea( oldgeom.united(newgeom) );
+}
+
void GLW_Widget::resizeEvent(QResizeEvent *ev){
if(glw_base==0){ return; }
QPoint pos = this->mapTo(glw_base, QPoint(0,0));
diff --git a/src-qt5/src-glwidgets/glw-widget.h b/src-qt5/src-glwidgets/glw-widget.h
index 1d6caa77..91a1ae69 100644
--- a/src-qt5/src-glwidgets/glw-widget.h
+++ b/src-qt5/src-glwidgets/glw-widget.h
@@ -19,6 +19,8 @@ class GLW_Widget : public QWidget{
Q_OBJECT
private:
GLW_Base *glw_base;
+ QPoint drag_offset;
+ bool draggable;
public:
GLW_Widget(QWidget *parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags());
@@ -32,18 +34,29 @@ public:
virtual void paintYourself(QStylePainter *painter, QPaintEvent *ev);
void paintChildren(QStylePainter *painter, QPaintEvent *ev);
+ //Properties
+ bool isDraggable(){ return draggable; }
+
private slots:
public slots:
+ void setDraggable(bool drag){ draggable = drag; }
+
protected:
- void enterEvent(QEvent*){ this->update(); }
- void leaveEvent(QEvent*){ this->update(); }
- void resizeEvent(QResizeEvent *ev);
- void paintEvent(QPaintEvent *ev);
+ virtual void enterEvent(QEvent*){ this->update(); }
+ virtual void leaveEvent(QEvent*){ this->update(); }
+
+ virtual void mousePressEvent(QMouseEvent *ev);
+ virtual void mouseReleaseEvent(QMouseEvent *ev);
+ virtual void mouseMoveEvent(QMouseEvent *ev);
+ virtual void moveEvent(QMoveEvent *ev);
+ virtual void resizeEvent(QResizeEvent *ev);
+ virtual void paintEvent(QPaintEvent *ev);
signals:
void repaintArea(QRect);
+ void doneDragging();
};
Q_DECLARE_INTERFACE(GLW_Widget, "GLW_Widget");
bgstack15