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
|
//===========================================
// Lumina-desktop source code
// Copyright (c) 2017, Ken Moore
// Available under the 3-clause BSD license
// See the LICENSE file for full details
//===========================================
#include "PanelObject.h"
#include <global-objects.h>
#include <QQmlEngine>
#include <QDebug>
PanelObject::PanelObject(QString id, QObject *parent) : QObject(parent){
panel_id = id;
}
void PanelObject::RegisterType(){
static bool done = false;
if(done){ return; }
done=true;
qmlRegisterType<PanelObject>("Lumina.Backend.PanelObject",2,0, "PanelObject");
}
QString PanelObject::name(){ return panel_id; }
QString PanelObject::background(){
if(bg.isEmpty()){ return "transparent"; }
return bg;
}
int PanelObject::x(){ return geom.x(); }
int PanelObject::y(){ return geom.y(); }
int PanelObject::width(){ return geom.width(); }
int PanelObject::height(){ return geom.height(); }
void PanelObject::setBackground(QString fileOrColor){
if(bg!=fileOrColor){
bg = fileOrColor;
emit backgroundChanged();
}
}
void PanelObject::setGeometry( QRect newgeom ){
if(geom!=newgeom){
geom = newgeom;
emit geomChanged();
}
}
void PanelObject::syncWithSettings(QRect parent_geom){
//Read off all the settings
//qDebug() << "Sync Panel Settings:" << panel_id << parent_geom;
QString anchor = DesktopSettings::instance()->value(DesktopSettings::Panels, panel_id+"/anchor", "bottom").toString().toLower();
QString align = DesktopSettings::instance()->value(DesktopSettings::Panels, panel_id+"/align", "center").toString().toLower();
double length = DesktopSettings::instance()->value(DesktopSettings::Panels, panel_id+"/length_percent", 100).toDouble()/100.0;
double width = DesktopSettings::instance()->value(DesktopSettings::Panels, panel_id+"/width_font_percent", 2.1).toDouble();
width = qRound(width * QApplication::fontMetrics().height() );
this->setBackground( DesktopSettings::instance()->value(DesktopSettings::Panels, panel_id+"/background", "rgba(0,0,0,120)").toString() );
// qDebug() << "Update Panel:" << panel_id << anchor+"/"+align << length << width;
//Now calculate the geometry of the panel
QRect newgeom;
//Figure out the size of the panel
if(anchor=="top" || anchor=="bottom"){ newgeom.setWidth( parent_geom.width()*length ); newgeom.setHeight(width); }
else{ newgeom.setWidth(width); newgeom.setHeight(parent_geom.height()*length); }
//qDebug() << " - Size:" << newgeom;
//Now figure out the location of the panel
if(align=="left" || align=="top"){
if(anchor=="top" || anchor=="left"){ newgeom.moveTopLeft(QPoint(0,0)); }
else if(anchor=="right"){ newgeom.moveTopRight(QPoint(parent_geom.width(), 0)); }
else{ newgeom.moveBottomLeft(QPoint(0, parent_geom.height()) ); } //bottom by default
}else if(align=="right" || align=="bottom"){
if(anchor=="top"){ newgeom.moveTopRight(QPoint(parent_geom.width(),0)); }
else if(anchor=="left"){ newgeom.moveBottomLeft(QPoint(0, parent_geom.height())); }
else if(anchor=="right"){ newgeom.moveBottomRight(QPoint(parent_geom.width(), parent_geom.height())); }
else{ newgeom.moveBottomRight(QPoint(parent_geom.width(), parent_geom.height()) ); }
}else{ //center
if(anchor=="top"){ newgeom.moveTopLeft(QPoint( (parent_geom.width()-newgeom.width())/2,0)); }
else if(anchor=="left"){ newgeom.moveTopLeft(QPoint(0, (parent_geom.height()-newgeom.height())/2 )); }
else if(anchor=="right"){ newgeom.moveTopRight(QPoint(parent_geom.width(), (parent_geom.height()-newgeom.height())/2 )); }
else{ newgeom.moveBottomLeft(QPoint( (parent_geom.width()-newgeom.width())/2, parent_geom.height()) ); }
}
//qDebug() << " - Calculated Geometry:" << newgeom;
this->setGeometry(newgeom); //Note: This is in parent-relative coordinates (not global)
}
|