-
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathDesktopApplet.cxx
More file actions
145 lines (117 loc) · 4.08 KB
/
DesktopApplet.cxx
File metadata and controls
145 lines (117 loc) · 4.08 KB
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*
This file is part of liquidshell.
SPDX-FileCopyrightText: 2017 - 2024 Martin Koller <martin@kollix.at>
SPDX-License-Identifier: GPL-3.0-or-later
*/
#include <DesktopApplet.hxx>
#include <KWinCompat.hxx>
#include <QAction>
#include <QIcon>
#include <QAbstractButton>
#include <QMessageBox>
#include <QDebug>
#include <KLocalizedString>
#include <KConfig>
#include <KConfigGroup>
#include <KWindowInfo>
//--------------------------------------------------------------------------------
DesktopApplet::DesktopApplet(QWidget *parent, const QString &theId, bool addConfigureAction)
: QFrame(parent), id(theId)
{
setFrameShape(QFrame::NoFrame);
setContextMenuPolicy(Qt::ActionsContextMenu);
if ( addConfigureAction )
{
QAction *action = new QAction(this);
action->setText(i18n("Configure..."));
action->setIcon(QIcon::fromTheme("configure"));
addAction(action);
connect(action, &QAction::triggered, this, &DesktopApplet::configure);
}
QAction *action = new QAction(this);
action->setIcon(QIcon::fromTheme("preferences-system-windows-move"));
action->setText(i18n("Change Size && Position"));
addAction(action);
connect(action, &QAction::triggered, this, &DesktopApplet::startGeometryChange);
action = new QAction(this);
action->setIcon(QIcon::fromTheme("window-close"));
action->setText(i18n("Remove this Applet"));
addAction(action);
connect(action, &QAction::triggered, this, &DesktopApplet::removeThisApplet);
buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
buttons->adjustSize();
buttons->hide();
connect(buttons, &QDialogButtonBox::clicked, this, &DesktopApplet::finishGeometryChange);
}
//--------------------------------------------------------------------------------
void DesktopApplet::loadConfig()
{
KConfig config;
KConfigGroup group = config.group(id);
setGeometry(group.readEntry("rect", QRect(QPoint(30, 30), sizeHint())));
onDesktop = group.readEntry("onDesktop", int(NET::OnAllDesktops));
QColor textCol = group.readEntry("textCol", QColor(Qt::white));
QColor backCol = group.readEntry("backCol", QColor(32, 56, 92, 190));
QPalette pal = palette();
pal.setColor(foregroundRole(), textCol);
pal.setColor(backgroundRole(), backCol);
setPalette(pal);
}
//--------------------------------------------------------------------------------
void DesktopApplet::saveConfig()
{
KConfig config;
KConfigGroup group = config.group(id);
group.writeEntry("rect", geometry());
group.writeEntry("onDesktop", onDesktop);
group.writeEntry("textCol", palette().color(foregroundRole()));
group.writeEntry("backCol", palette().color(backgroundRole()));
}
//--------------------------------------------------------------------------------
void DesktopApplet::startGeometryChange()
{
buttons->raise();
buttons->show();
oldRect = geometry();
setWindowFlags(Qt::Window);
setWindowTitle(i18n("%1: Change Size & Position", id));
if ( onDesktop == NET::OnAllDesktops )
KWinCompat::setOnAllDesktops(winId(), true);
show();
setGeometry(oldRect);
}
//--------------------------------------------------------------------------------
void DesktopApplet::finishGeometryChange(QAbstractButton *clicked)
{
KWindowInfo info(winId(), NET::WMDesktop);
if ( info.valid() )
onDesktop = info.desktop();
buttons->hide();
QRect rect = geometry();
setWindowFlags(Qt::Widget);
show();
if ( buttons->buttonRole(clicked) == QDialogButtonBox::AcceptRole )
{
setGeometry(rect);
KConfig config;
KConfigGroup group = config.group(id);
group.writeEntry("rect", rect);
group.writeEntry("onDesktop", onDesktop);
}
else
{
setGeometry(oldRect);
}
}
//--------------------------------------------------------------------------------
void DesktopApplet::removeThisApplet()
{
if ( QMessageBox::question(this, i18n("Remove Applet"),
i18n("Really remove this applet?")) == QMessageBox::Yes )
{
KConfig config;
config.deleteGroup(id);
emit removeThis(this);
}
}
//--------------------------------------------------------------------------------