-
Notifications
You must be signed in to change notification settings - Fork 11
/
panelapplication.cpp
130 lines (112 loc) · 3.37 KB
/
panelapplication.cpp
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include "panelapplication.h"
#include <QtCore/QSettings>
#include <QtCore/QTimer>
#include "iconloader.h"
#include "x11support.h"
#include "dpisupport.h"
#include "desktopapplications.h"
#include "ui_panelapplicationsettings.h"
PanelApplication* PanelApplication::m_instance = NULL;
PanelApplication::PanelApplication(int& argc, char** argv)
: QApplication(argc, argv)
{
m_instance = this;
m_defaultIconThemeName = QIcon::themeName();
setOrganizationName("madfish");
setApplicationName("qtpanel");
m_iconLoader = new IconLoader();
m_x11support = new X11Support();
m_desktopApplications = new DesktopApplications();
}
PanelApplication::~PanelApplication()
{
reset();
delete m_desktopApplications;
delete m_x11support;
delete m_iconLoader;
m_instance = NULL;
}
bool PanelApplication::x11EventFilter(XEvent* event)
{
m_x11support->onX11Event(event);
return false;
}
void PanelApplication::showConfigurationDialog()
{
QDialog dialog;
Ui::PanelApplicationSettings settingsUi;
settingsUi.setupUi(&dialog);
settingsUi.fontName->setText(m_fontName);
settingsUi.iconThemeName->setText(m_iconThemeName);
settingsUi.verticalPosition->setCurrentIndex(m_verticalAnchor == PanelWindow::Max ? 1 : 0);
if(dialog.exec() == QDialog::Accepted)
{
QSettings settings;
settings.setValue("fontName", settingsUi.fontName->text());
settings.setValue("iconThemeName", settingsUi.iconThemeName->text());
settings.setValue("verticalPosition", settingsUi.verticalPosition->currentText());
// Don't want to delete objects right now (because we're called from those objects), schedule it for later.
QTimer::singleShot(1, this, SLOT(reinit()));
}
}
void PanelApplication::reinit()
{
reset();
init();
}
void PanelApplication::init()
{
QSettings settings;
setFontName(settings.value("fontName", "default").toString());
setIconThemeName(settings.value("iconThemeName", "default").toString());
QString verticalPosition = settings.value("verticalPosition", "Top").toString();
if(verticalPosition == "Top")
m_verticalAnchor = PanelWindow::Min;
else if(verticalPosition == "Bottom")
m_verticalAnchor = PanelWindow::Max;
PanelWindow* panelWindow = new PanelWindow();
panelWindow->resize(adjustHardcodedPixelSize(128), adjustHardcodedPixelSize(32));
panelWindow->setLayoutPolicy(PanelWindow::FillSpace);
panelWindow->setVerticalAnchor(m_verticalAnchor);
panelWindow->setDockMode(true);
panelWindow->init();
panelWindow->show();
m_panelWindows.append(panelWindow);
}
void PanelApplication::reset()
{
for(int i = 0; i < m_panelWindows.size(); i++)
{
delete m_panelWindows[i];
}
m_panelWindows.clear();
}
void PanelApplication::setFontName(const QString& fontName)
{
m_fontName = fontName;
if(m_fontName != "default")
{
// Parse font name. Example: "Droid Sans 11".
int lastSpacePos = m_fontName.lastIndexOf(' ');
// Should have at least one space, otherwise string is malformed, keep default in that case.
if(lastSpacePos != -1)
{
int fontSize = m_fontName.mid(lastSpacePos).toInt();
QString fontFamily = m_fontName;
fontFamily.truncate(lastSpacePos);
m_panelFont = QFont(fontFamily, fontSize);
}
}
else
{
m_panelFont = QApplication::font();
}
}
void PanelApplication::setIconThemeName(const QString& iconThemeName)
{
m_iconThemeName = iconThemeName;
if(m_iconThemeName != "default")
QIcon::setThemeName(m_iconThemeName);
else
QIcon::setThemeName(m_defaultIconThemeName);
}