source: lumina/lumina-desktop/desktop-plugins/LDPluginContainer.h @ 130bc0e

releng/10.0.3releng/10.1releng/10.1.1
Last change on this file since 130bc0e was 130bc0e, checked in by Ken Moore <ken@…>, 8 months ago

Get the Lumina Desktop Plugin system working completely. It is still a bit ugly and needs a visual update to the "unlocked" plugin container, but at least it works fine right now.

  • Property mode set to 100644
File size: 3.7 KB
Line 
1//===========================================
2//  Lumina-DE source code
3//  Copyright (c) 2014, Ken Moore
4//  Available under the 3-clause BSD license
5//  See the LICENSE file for full details
6//===========================================
7//  This class is the generic container for a desktop plugin that handles
8//    saving/restoring all the movement and sizing
9//===========================================
10#ifndef _LUMINA_DESKTOP_DESKTOP_PLUGIN_CONTAINER_H
11#define _LUMINA_DESKTOP_DESKTOP_PLUGIN_CONTAINER_H
12
13#include <QObject>
14#include <QMdiSubWindow>
15#include <QSettings>
16#include <QMoveEvent>
17#include <QResizeEvent>
18
19#include "LDPlugin.h"
20
21class LDPluginContainer : public QMdiSubWindow{
22        Q_OBJECT
23       
24private:
25        QSettings *settings;
26        bool locked;
27       
28public:
29        LDPluginContainer(LDPlugin *plugin = 0, bool islocked = true) : QMdiSubWindow(){
30          this->setWidget(plugin);
31          locked = islocked;
32          settings = plugin->settings; //save this pointer for access later
33          this->setContentsMargins(0,0,0,0);
34          QRect set(settings->value("location/x",0).toInt(), settings->value("location/y",0).toInt(), settings->value("location/width",plugin->sizeHint().width()).toInt(), settings->value("location/height",plugin->sizeHint().height()).toInt());
35          qDebug() << "Initial Plugin Location:" << set.x() << set.y() << set.width() << set.height();
36          if(!locked){
37            this->setWindowTitle(tr("Drag to move"));
38            //this->setStyleSheet("QMdiSubWindow{ padding: 0px; background: lightgrey; border: 2px solid grey; border-radius: 1px;} QMdiSubWindow::title{ background-color: lightgrey; height: 10px;  border: none; font: bold 8;}");
39            QRect ipt = this->widget()->geometry();
40            this->setGeometry( set.x()-ipt.x(), set.y()-ipt.y(), set.width()+(this->frameGeometry().width()-ipt.width()), set.height()+(this->frameGeometry().height()-ipt.height()) );
41          }else{
42            this->setStyleSheet("LDPluginContainer{ padding: 0px; background: transparent; border: none;}");
43            this->setGeometry( settings->value("location/x",0).toInt(), settings->value("location/y",0).toInt(), settings->value("location/width",plugin->sizeHint().width()).toInt(), settings->value("location/height",plugin->sizeHint().height()).toInt());
44          }
45        }
46       
47        ~LDPluginContainer(){
48        }
49
50        void loadInitialPosition(){
51          //qDebug() << "Initial Plugin Location:" << settings->value("location/x",0).toInt() << settings->value("location/y",0).toInt() << settings->value("location/width",this->widget()->sizeHint().width()).toInt() << settings->value("location/height",this->widget()->sizeHint().height()).toInt();
52          if(!locked){
53            this->setGeometry( settings->value("location/x",0).toInt()-2, settings->value("location/y",0).toInt()-12, settings->value("location/width",this->widget()->sizeHint().width()).toInt()+4, settings->value("location/height",this->widget()->sizeHint().height()+14).toInt());
54          }else{
55            this->setGeometry( settings->value("location/x",0).toInt(), settings->value("location/y",0).toInt(), settings->value("location/width",this->widget()->sizeHint().width()).toInt(), settings->value("location/height",this->widget()->sizeHint().height()).toInt());
56          }
57        }
58       
59protected:
60        void moveEvent(QMoveEvent *event){
61          //Save this location to the settings
62          if(!locked){
63            //qDebug() << "DP Move:" << event->pos().x() << event->pos().y();
64            settings->setValue("location/x", event->pos().x()+2);
65            settings->setValue("location/y", event->pos().y()+12);
66            settings->sync();
67          }
68        }
69        void resizeEvent(QResizeEvent *event){
70          //Save this size info to the settings
71          if(!locked){
72            //qDebug() << "DP Resize:" << event->size().width() << event->size().height();
73            settings->setValue("location/width", event->size().width()-4);
74            settings->setValue("location/height", event->size().height()-14);
75            settings->sync();
76          }
77        }
78       
79};
80
81#endif
Note: See TracBrowser for help on using the repository browser.