1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
//===========================================
// Lumina-desktop source code
// Copyright (c) 2018, Ken Moore
// Available under the 3-clause BSD license
// See the LICENSE file for full details
//===========================================
#include "Panel.h"
// PUBLIC
Panel::Panel(PanelObject *pobj) : QWidget(0, Qt::Window | Qt::FramelessWindowHint){
this->setObjectName("LuminaPanelBackgroundWidget");
obj = pobj;
layout = new QBoxLayout(QBoxLayout::LeftToRight, this);
layout->setContentsMargins(0,0,0,0);
this->setBackgroundRole(QPalette::AlternateBase);
connect(obj, SIGNAL(backgroundChanged()), this, SLOT(updateBackground()) );
connect(obj, SIGNAL(geomChanged()), this, SLOT(updateGeom()) );
connect(obj, SIGNAL(pluginsChanged()), this, SLOT(updatePlugins()) );
connect(obj, SIGNAL(destroyed(QObject*)), this, SLOT(objectDestroyed(QObject*)) );
updateGeom();
updateBackground();
updatePlugins();
this->showNormal();
}
Panel::~Panel(){
}
// PRIVATE
Plugin* Panel::findPlugin(QString id){
for(int i=0; i<PLUGINS.count(); i++){
if(PLUGINS[i]->id()==id){ return PLUGINS[i]; }
}
return 0;
}
Plugin* Panel::createPlugin(QString id){
Plugin* tmp = Plugin::createPlugin(this, id, true, obj->isVertical());
return tmp;
}
// PRIVATE SLOTS
void Panel::objectDestroyed(QObject *dobj){
if(dobj == Q_NULLPTR || dobj == obj){
//Make sure this widget is also cleaned up when the base object is deleted
this->deleteLater();
}
}
void Panel::updateGeom(){
this->setGeometry(obj->geometry());
this->setFixedSize(obj->geometry().size());
layout->setDirection( obj->isVertical() ? QBoxLayout::TopToBottom : QBoxLayout::LeftToRight );
for(int i=0; i<PLUGINS.length(); i++){
PLUGINS[i]->setVertical( obj->isVertical() );
}
}
void Panel::updateBackground(){
static QString PANELTEMPLATE = "QToolButton::menu-indicator{ image: none; } QWidget#LuminaPanelBackgroundWidget{ background: %1; }";
QString bg = obj->background();
//qDebug() << "Got panel BG:" << obj->name() << bg;
this->setStyleSheet(PANELTEMPLATE.arg(bg));
}
void Panel::updatePlugins(){
QStringList plugs = obj->plugins();
qDebug() << "Got panel plugins:" << obj->name() << plugs;
for(int i=0; i<plugs.length(); i++){
lastplugins.removeAll(plugs[i]); //remove this from the last list (handled)
Plugin *plug = findPlugin(plugs[i]);
if(plug==0){ plug = createPlugin(plugs[i]); }
if(plug==0){ continue; } //not a valid plugin - just skip it
//Now setup the order of the plugins properly
if( layout->indexOf(plug) >=0 ){
layout->removeWidget(plug); //remove from the layout for a moment
}
layout->insertWidget(i, plug);
plug->setupSizing();
}
//Now remove any plugins which were deleted from config
for(int i=0; i<lastplugins.length(); i++){
Plugin *plug = findPlugin(lastplugins[i]);
if(plug==0){ continue; }
plug->deleteLater();
}
lastplugins = plugs;
}
|