aboutsummaryrefslogtreecommitdiff
path: root/src-qt5/src-glwidgets/glw-base.cpp
diff options
context:
space:
mode:
authorKen Moore <ken@ixsystems.com>2017-09-26 13:42:19 -0400
committerKen Moore <ken@ixsystems.com>2017-09-26 13:42:19 -0400
commitbf7e372df336263ccdc9d0ab22554fb1ff6f629a (patch)
treed30c8ad898484380ba81dafcaaaee4c3057b5adc /src-qt5/src-glwidgets/glw-base.cpp
parentGet the window embed routine cleaned up and demo-ready. (diff)
downloadlumina-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-base.cpp')
-rw-r--r--src-qt5/src-glwidgets/glw-base.cpp63
1 files changed, 63 insertions, 0 deletions
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);
+ }
+ }
+ }
+}
bgstack15