-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexampleplugin.cpp
More file actions
86 lines (76 loc) · 2.63 KB
/
exampleplugin.cpp
File metadata and controls
86 lines (76 loc) · 2.63 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
/* BEGIN_COMMON_COPYRIGHT_HEADER
* (c)LGPL2+
*
* LXQt - a lightweight, Qt based, desktop toolset
* https://lxqt.org
*
* Copyright: 2021 LXQt team
*
* This program or library is free software; you can redistribute it
* and/or modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*
* END_COMMON_COPYRIGHT_HEADER */
#include "exampleplugin.h"
#include "exampleconfiguration.h"
#include <QIcon>
#include <QMessageBox>
#include <QTimer>
#define QSL(text) QStringLiteral(text)
ExamplePlugin::ExamplePlugin(const ILXQtPanelPluginStartupInfo& startupInfo)
: QObject()
, ILXQtPanelPlugin(startupInfo)
{
mWidget = new QToolButton;
mWidget->setAutoRaise(true);
mWidget->setMinimumWidth(1);
mWidget->setMinimumHeight(1);
QTimer::singleShot(0, [this] {
this->settingsChanged();
});
connect(mWidget, &QToolButton::clicked, this, [this] {
QMessageBox::aboutQt(mWidget);
});
}
ExamplePlugin::~ExamplePlugin() = default;
void ExamplePlugin::settingsChanged()
{
mShowIcon = settings()->value(QSL("showIcon"), true).toBool();
mIcon = settings()->value(QSL("icon"), QSL("plugins")).toString();
mShowText = settings()->value(QSL("showText"), true).toBool();
mText = settings()->value(QSL("text"), QSL("About")).toString();
mWidget->setIcon(QIcon::fromTheme(mIcon));
mWidget->setText(mText);
if (!mShowIcon && !mShowText) {
mWidget->hide();
} else {
mWidget->show();
if (mShowIcon && mShowText) {
mWidget->setToolButtonStyle(Qt::ToolButtonStyle::ToolButtonTextBesideIcon);
} else if (mShowIcon) {
mWidget->setToolButtonStyle(Qt::ToolButtonStyle::ToolButtonIconOnly);
} else if (mShowText) {
mWidget->setToolButtonStyle(Qt::ToolButtonStyle::ToolButtonTextOnly);
}
}
mWidget->update();
}
void ExamplePlugin::realign()
{
mWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
}
QDialog* ExamplePlugin::configureDialog()
{
return new ExampleConfiguration(settings());
}