diff options
author | Ken Moore <ken@ixsystems.com> | 2017-09-26 13:42:19 -0400 |
---|---|---|
committer | Ken Moore <ken@ixsystems.com> | 2017-09-26 13:42:19 -0400 |
commit | bf7e372df336263ccdc9d0ab22554fb1ff6f629a (patch) | |
tree | d30c8ad898484380ba81dafcaaaee4c3057b5adc /src-qt5/src-glwidgets/glw-widget.cpp | |
parent | Get the window embed routine cleaned up and demo-ready. (diff) | |
download | lumina-bf7e372df336263ccdc9d0ab22554fb1ff6f629a.tar.gz lumina-bf7e372df336263ccdc9d0ab22554fb1ff6f629a.tar.bz2 lumina-bf7e372df336263ccdc9d0ab22554fb1ff6f629a.zip |
Add a bunch of new files specifically for providing a new OpenGL-backed basis for doing visuals within Qt/Lumina.
Diffstat (limited to 'src-qt5/src-glwidgets/glw-widget.cpp')
-rw-r--r-- | src-qt5/src-glwidgets/glw-widget.cpp | 76 |
1 files changed, 76 insertions, 0 deletions
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; +} |