source: lumina/lumina-desktop/desktop-plugins/LDPluginContainer.h @ 59fa950

enter/10releng/10.0.3releng/10.1releng/10.1.1releng/10.1.2
Last change on this file since 59fa950 was 59fa950, checked in by Ken Moore <ken@…>, 11 months ago

Now the desktop plugins look and function a lot better. I might need to add a "snap to grid" ability later though...

  • Property mode set to 100644
File size: 2.9 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, setup;
27       
28public:
29        LDPluginContainer(LDPlugin *plugin = 0, bool islocked = true) : QMdiSubWindow(){
30          locked = islocked;
31          setup=true;
32          if(locked){ this->setWindowFlags(Qt::FramelessWindowHint); }
33          else{ this->setWindowFlags(Qt::CustomizeWindowHint); }
34          settings = plugin->settings; //save this pointer for access later
35          this->setContentsMargins(0,0,0,0);
36          if(!locked){
37            this->setWindowTitle(plugin->type());
38            this->setWidget( new QWidget() );
39            //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;}");
40          }else{
41            this->setStyleSheet("LDPluginContainer{ padding: 0px; background: transparent; border: none;}");
42            this->setWidget(plugin);
43          }
44        }
45       
46        ~LDPluginContainer(){
47        }
48
49        void loadInitialPosition(){
50          QRect set(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());
51          qDebug() << "Initial Plugin Location:" << set.x() << set.y() << set.width() << set.height();
52            if(set.height() < 10){ set.setHeight(10); } //to prevent foot-shooting
53            if(set.width() < 10){ set.setWidth(10); } //to prevent foot-shooting
54            this->setGeometry(set);
55          setup=false; //done with setup
56        }
57       
58protected:
59        void moveEvent(QMoveEvent *event){
60          //Save this location to the settings
61          if(!locked && !setup){
62            //qDebug() << "DP Move:" << event->pos().x() << event->pos().y();
63            settings->setValue("location/x", event->pos().x());
64            settings->setValue("location/y", event->pos().y());
65            settings->sync();
66          }
67          event->ignore();
68        }
69        void resizeEvent(QResizeEvent *event){
70          //Save this size info to the settings
71          if(!locked && !setup){
72            //qDebug() << "DP Resize:" << event->size().width() << event->size().height();
73            settings->setValue("location/width", event->size().width());
74            settings->setValue("location/height", event->size().height());
75            settings->sync();
76          }
77          event->ignore();
78        }
79       
80};
81
82#endif
Note: See TracBrowser for help on using the repository browser.