aboutsummaryrefslogtreecommitdiff
path: root/src-qt5/src-glwidgets
diff options
context:
space:
mode:
authorKen Moore <ken@ixsystems.com>2017-09-26 14:04:24 -0400
committerKen Moore <ken@ixsystems.com>2017-09-26 14:04:24 -0400
commita8ab0934e4782a14206cba544c846a34947cce36 (patch)
treef032428eca9b7938b43b6f06f67da554d0faf2b0 /src-qt5/src-glwidgets
parentFix up the close event handling in lumina-textedit. Now it will actually clos... (diff)
parentMerge branch 'master' of github.com:trueos/lumina (diff)
downloadlumina-a8ab0934e4782a14206cba544c846a34947cce36.tar.gz
lumina-a8ab0934e4782a14206cba544c846a34947cce36.tar.bz2
lumina-a8ab0934e4782a14206cba544c846a34947cce36.zip
Merge branch 'master' of github.com:trueos/lumina
Diffstat (limited to 'src-qt5/src-glwidgets')
-rw-r--r--src-qt5/src-glwidgets/gltest/colorchange.h35
-rw-r--r--src-qt5/src-glwidgets/gltest/main.cpp26
-rwxr-xr-xsrc-qt5/src-glwidgets/gltest/testbin0 -> 50927 bytes
-rw-r--r--src-qt5/src-glwidgets/gltest/test.pro9
-rw-r--r--src-qt5/src-glwidgets/glw-base.cpp63
-rw-r--r--src-qt5/src-glwidgets/glw-base.h43
-rw-r--r--src-qt5/src-glwidgets/glw-widget.cpp76
-rw-r--r--src-qt5/src-glwidgets/glw-widget.h50
-rw-r--r--src-qt5/src-glwidgets/glwidgets.pri7
9 files changed, 309 insertions, 0 deletions
diff --git a/src-qt5/src-glwidgets/gltest/colorchange.h b/src-qt5/src-glwidgets/gltest/colorchange.h
new file mode 100644
index 00000000..d62fcd5c
--- /dev/null
+++ b/src-qt5/src-glwidgets/gltest/colorchange.h
@@ -0,0 +1,35 @@
+#include <QDebug>
+#include <QApplication>
+#include <QTimer>
+#include <QColor>
+
+#include "../glw-base.h"
+
+class colorchange : public QObject{
+ Q_OBJECT
+private:
+ GLW_Base *base;
+ QTimer *timer;
+
+public slots:
+ void toggle(){
+ static int current = 0;
+ if(current==0){
+ base->setBackgroundColor(QColor(Qt::red));
+ }else{
+ base->setBackgroundColor(QColor(Qt::blue));
+ current = -1;
+ }
+ current++;
+ }
+
+public:
+ colorchange(GLW_Base *parent) : QObject(){
+ base = parent;
+ timer = new QTimer(this);
+ timer->setInterval(5000);
+ connect(timer, SIGNAL(timeout()), this, SLOT(toggle()) );
+ timer->start();
+ }
+
+};
diff --git a/src-qt5/src-glwidgets/gltest/main.cpp b/src-qt5/src-glwidgets/gltest/main.cpp
new file mode 100644
index 00000000..041ee5ff
--- /dev/null
+++ b/src-qt5/src-glwidgets/gltest/main.cpp
@@ -0,0 +1,26 @@
+#include <QDebug>
+#include <QApplication>
+#include <QTimer>
+#include <QColor>
+
+#include "../glw-base.h"
+#include "../glw-widget.h"
+
+#include "colorchange.h"
+
+int main(int argc, char** argv){
+ QApplication A(argc,argv);
+ qDebug() << "Creating base widget";
+ GLW_Base base;
+ qDebug() << "Resize base widget";
+ base.resize(200,200);
+ qDebug() << "Create colorchange";
+ GLW_Widget wgt(&base);
+ wgt.setGLBase(&base);
+ wgt.setGeometry(50,50,50,50);
+ colorchange CC(&base);
+ qDebug() << "Start Event loop";
+ base.show();
+ A.exec();
+ qDebug() << " - Finished";
+}
diff --git a/src-qt5/src-glwidgets/gltest/test b/src-qt5/src-glwidgets/gltest/test
new file mode 100755
index 00000000..5a69b0c3
--- /dev/null
+++ b/src-qt5/src-glwidgets/gltest/test
Binary files differ
diff --git a/src-qt5/src-glwidgets/gltest/test.pro b/src-qt5/src-glwidgets/gltest/test.pro
new file mode 100644
index 00000000..cba315c3
--- /dev/null
+++ b/src-qt5/src-glwidgets/gltest/test.pro
@@ -0,0 +1,9 @@
+QT = core gui widgets
+
+TARGET = test
+
+SOURCES += main.cpp
+
+HEADERS += colorchange.h
+
+include(../glwidgets.pri);
diff --git a/src-qt5/src-glwidgets/glw-base.cpp b/src-qt5/src-glwidgets/glw-base.cpp
new file mode 100644
index 00000000..e828df7f
--- /dev/null
+++ b/src-qt5/src-glwidgets/glw-base.cpp
@@ -0,0 +1,63 @@
+//===========================================
+// Lumina-desktop source code
+// Copyright (c) 2017, Ken Moore
+// Available under the 3-clause BSD license
+// See the LICENSE file for full details
+//===========================================
+#include "glw-base.h"
+#include "glw-widget.h"
+
+GLW_Base::GLW_Base(QWidget *parent, Qt::WindowFlags f) : QOpenGLWidget(parent,f){
+ bg_color = QColor(Qt::black);
+}
+
+GLW_Base::~GLW_Base(){
+
+}
+
+// --- PUBLIC SLOTS ---
+void GLW_Base::setBackgroundColor(QColor color){
+ bg_color = color;
+ this->update(); //repaint the entire widget (just in case you can see through the image)
+
+}
+
+void GLW_Base::setBackground(QRect geom, QImage img){
+ QPainter P(&bg_img);
+ P.drawImage(geom, img);
+ this->update();
+}
+
+void GLW_Base::repaintArea(QRect rect){
+ paintEvent(new QPaintEvent(rect));
+}
+
+// --- PROTECTED ---
+void GLW_Base::resizeEvent(QResizeEvent *ev){
+ QOpenGLWidget::resizeEvent(ev);
+ if(!bg_img.isNull()){
+ bg_img = bg_img.scaled(ev->size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
+ }
+ emit BaseResized();
+}
+
+void GLW_Base::paintEvent(QPaintEvent *ev){
+ QStylePainter painter(this);
+ painter.setClipRegion(ev->rect());
+ //Fill in the background color first
+ painter.fillRect(ev->rect(), bg_color);
+ //Now paint any background image over that
+ painter.drawImage(ev->rect(), bg_img, ev->rect(), Qt::AutoColor | Qt::PreferDither | Qt::NoOpaqueDetection);
+ //Now find any children widgets and paint them if they are in that area
+ QObjectList child = this->children(); //Note: This is returned in stacking order (lowest -> highest)
+ for(int i=0; i<child.length(); i++){
+ 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())){
+ glww->paintYourself(&painter, ev);
+ glww->paintChildren(&painter,ev);
+ }
+ }
+ }
+}
diff --git a/src-qt5/src-glwidgets/glw-base.h b/src-qt5/src-glwidgets/glw-base.h
new file mode 100644
index 00000000..729aa68e
--- /dev/null
+++ b/src-qt5/src-glwidgets/glw-base.h
@@ -0,0 +1,43 @@
+//===========================================
+// Lumina-desktop source code
+// Copyright (c) 2017, Ken Moore
+// Available under the 3-clause BSD license
+// See the LICENSE file for full details
+//===========================================
+#ifndef _LUMINA_OPENGL_WIDGETS_BASE_H
+#define _LUMINA_OPENGL_WIDGETS_BASE_H
+
+#include <QOpenGLWidget>
+#include <QImage>
+#include <QPaintEvent>
+#include <QPainter>
+#include <QResizeEvent>
+#include <QStylePainter>
+
+class GLW_Base : public QOpenGLWidget{
+ Q_OBJECT
+private:
+ QColor bg_color;
+ QImage bg_img;
+
+public:
+ GLW_Base(QWidget *parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags());
+ ~GLW_Base();
+
+
+private slots:
+
+public slots:
+ void setBackgroundColor(QColor color);
+ void setBackground(QRect geom, QImage img);
+ void repaintArea(QRect);
+
+signals:
+ void BaseResized();
+
+protected:
+ void resizeEvent(QResizeEvent *ev);
+ void paintEvent(QPaintEvent *ev);
+};
+
+#endif
diff --git a/src-qt5/src-glwidgets/glw-widget.cpp b/src-qt5/src-glwidgets/glw-widget.cpp
new file mode 100644
index 00000000..e24d8166
--- /dev/null
+++ b/src-qt5/src-glwidgets/glw-widget.cpp
@@ -0,0 +1,76 @@
+//===========================================
+// Lumina-desktop source code
+// Copyright (c) 2017, Ken Moore
+// Available under the 3-clause BSD license
+// See the LICENSE file for full details
+//===========================================
+#include "glw-widget.h"
+#include <QDebug>
+
+// --- PUBLIC ---
+GLW_Widget::GLW_Widget(QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f){
+ glw_base = 0;
+ this->setMouseTracking(true);
+}
+
+GLW_Widget::~GLW_Widget(){
+
+}
+
+QRect GLW_Widget::widgetRect(){
+ QPoint pos = this->mapTo(glw_base, QPoint(0,0));
+ return QRect(pos, this->size());
+}
+
+bool GLW_Widget::mouseOverWidget(){
+ QPoint pos = this->mapFromGlobal(QCursor::pos());
+ QRect geom(QPoint(0,0), this->size());
+ return geom.contains(pos);
+
+}
+
+void GLW_Widget::setGLBase(GLW_Base *base){
+ if(glw_base!=0){ this->disconnect(glw_base, SLOT(repaintArea(QRect))); }
+ glw_base=base;
+ connect(this, SIGNAL(repaintArea(QRect)), glw_base, SLOT(repaintArea(QRect)) );
+}
+
+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);
+ painter->fillRect(rect, color);
+}
+
+void GLW_Widget::paintChildren(QStylePainter *painter, QPaintEvent *ev){
+ QObjectList child = this->children(); //Note: This is returned in stacking order (lowest -> highest)
+ for(int i=0; i<child.length(); i++){
+ 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())){
+ glww->paintYourself(painter, ev);
+ glww->paintChildren(painter,ev);
+ }
+ }
+ }
+}
+
+
+// --- PROTECTED ---
+void GLW_Widget::resizeEvent(QResizeEvent *ev){
+ if(glw_base==0){ return; }
+ QPoint pos = this->mapTo(glw_base, QPoint(0,0));
+ QSize sz = ev->oldSize();
+ if(ev->size().width() > sz.width()){ sz.setWidth(ev->size().width()); }
+ if(ev->size().height() > sz.height()){ sz.setHeight(ev->size().height()); }
+ emit repaintArea(QRect(pos, sz));
+}
+
+void GLW_Widget::paintEvent(QPaintEvent *ev){
+ //qDebug() << "Got paint event:" << ev->rect();
+ QPoint pos = this->mapTo(glw_base, ev->rect().topLeft());
+ emit repaintArea(QRect(pos, ev->rect().size()) );
+ return;
+}
diff --git a/src-qt5/src-glwidgets/glw-widget.h b/src-qt5/src-glwidgets/glw-widget.h
new file mode 100644
index 00000000..1d6caa77
--- /dev/null
+++ b/src-qt5/src-glwidgets/glw-widget.h
@@ -0,0 +1,50 @@
+//===========================================
+// Lumina-desktop source code
+// Copyright (c) 2017, Ken Moore
+// Available under the 3-clause BSD license
+// See the LICENSE file for full details
+//===========================================
+#ifndef _LUMINA_OPENGL_WIDGETS_WIDGET_H
+#define _LUMINA_OPENGL_WIDGETS_WIDGET_H
+
+#include <QWidget>
+#include <QPaintEvent>
+#include <QStylePainter>
+#include <QResizeEvent>
+#include <QStylePainter>
+
+#include "glw-base.h"
+
+class GLW_Widget : public QWidget{
+ Q_OBJECT
+private:
+ GLW_Base *glw_base;
+
+public:
+ GLW_Widget(QWidget *parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags());
+ ~GLW_Widget();
+
+ QRect widgetRect(); //converts to the coordinate scheme of the base widget
+ bool mouseOverWidget();
+
+ void setGLBase(GLW_Base *base);
+
+ virtual void paintYourself(QStylePainter *painter, QPaintEvent *ev);
+ void paintChildren(QStylePainter *painter, QPaintEvent *ev);
+
+private slots:
+
+public slots:
+
+protected:
+ void enterEvent(QEvent*){ this->update(); }
+ void leaveEvent(QEvent*){ this->update(); }
+ void resizeEvent(QResizeEvent *ev);
+ void paintEvent(QPaintEvent *ev);
+
+signals:
+ void repaintArea(QRect);
+};
+
+Q_DECLARE_INTERFACE(GLW_Widget, "GLW_Widget");
+#endif
diff --git a/src-qt5/src-glwidgets/glwidgets.pri b/src-qt5/src-glwidgets/glwidgets.pri
new file mode 100644
index 00000000..e391aef0
--- /dev/null
+++ b/src-qt5/src-glwidgets/glwidgets.pri
@@ -0,0 +1,7 @@
+QT *= widgets
+
+SOURCES *= $${PWD}/glw-base.cpp \
+ $${PWD}/glw-widget.cpp
+
+HEADERS *= $${PWD}/glw-base.h \
+ $${PWD}/glw-widget.h
bgstack15