Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First applet is a weather applet
- Loading branch information
Showing
15 changed files
with
1,217 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
/* | ||
Copyright 2017 Martin Koller, kollix@aon.at | ||
This file is part of liquidshell. | ||
liquidshell is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
liquidshell is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with liquidshell. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include <DesktopApplet.hxx> | ||
|
||
#include <QAction> | ||
#include <QIcon> | ||
#include <QAbstractButton> | ||
#include <QMessageBox> | ||
#include <QDebug> | ||
|
||
#include <KLocalizedString> | ||
#include <KConfig> | ||
#include <KConfigGroup> | ||
|
||
//-------------------------------------------------------------------------------- | ||
|
||
DesktopApplet::DesktopApplet(QWidget *parent, const QString &theId) | ||
: QFrame(parent), id(theId) | ||
{ | ||
setFrameShape(QFrame::StyledPanel); | ||
setContextMenuPolicy(Qt::ActionsContextMenu); | ||
|
||
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(30, 30, 600, 400))); | ||
onDesktop = group.readEntry("onDesktop", int(NET::OnAllDesktops)); | ||
} | ||
|
||
//-------------------------------------------------------------------------------- | ||
|
||
void DesktopApplet::saveConfig() | ||
{ | ||
KConfig config; | ||
KConfigGroup group = config.group(id); | ||
group.writeEntry("rect", geometry()); | ||
group.writeEntry("onDesktop", onDesktop); | ||
} | ||
|
||
//-------------------------------------------------------------------------------- | ||
|
||
void DesktopApplet::startGeometryChange() | ||
{ | ||
buttons->raise(); | ||
buttons->show(); | ||
|
||
oldRect = geometry(); | ||
setWindowFlags(Qt::Window); | ||
setWindowTitle(i18n("%1: Change Size & Position").arg(id)); | ||
|
||
if ( onDesktop == NET::OnAllDesktops ) | ||
KWindowSystem::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); | ||
} | ||
} | ||
|
||
//-------------------------------------------------------------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
Copyright 2017 Martin Koller, kollix@aon.at | ||
This file is part of liquidshell. | ||
liquidshell is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
liquidshell is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with liquidshell. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef _DesktopApplet_H_ | ||
#define _DesktopApplet_H_ | ||
|
||
#include <QFrame> | ||
#include <QDialogButtonBox> | ||
#include <KWindowSystem> | ||
|
||
class DesktopApplet : public QFrame | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
DesktopApplet(QWidget *parent, const QString &theId); | ||
|
||
virtual void loadConfig(); | ||
virtual void saveConfig(); | ||
|
||
bool isConfiguring() const { return buttons->isVisible(); } | ||
|
||
const QString &getId() const { return id; } | ||
int isOnDesktop(int d) const { return (onDesktop == NET::OnAllDesktops) || (onDesktop == d); } | ||
|
||
signals: | ||
void geometryChanged(); | ||
void removeThis(DesktopApplet *); | ||
|
||
protected: | ||
QString id; | ||
|
||
private slots: | ||
void startGeometryChange(); | ||
void finishGeometryChange(QAbstractButton *clicked); | ||
void removeThisApplet(); | ||
|
||
private: | ||
QDialogButtonBox *buttons = nullptr; | ||
QRect oldRect; | ||
int onDesktop = NET::OnAllDesktops; | ||
}; | ||
|
||
#endif |
Oops, something went wrong.