2
* Copyright 2009 Marco Martin <notmart@gmail.com>
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as
6
* published by the Free Software Foundation; either version 2,
7
* or (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details
14
* You should have received a copy of the GNU Library General Public
15
* License along with this program; if not, write to the
16
* Free Software Foundation, Inc.,
17
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
#include "panelspacer.h"
25
#include <Plasma/PaintUtils>
26
#include <Plasma/Containment>
27
#include <Plasma/Theme>
29
K_EXPORT_PLASMA_APPLET(panelspacer_internal, PanelSpacer)
31
PanelSpacer::PanelSpacer(QObject *parent, const QVariantList &args)
32
: Plasma::Applet(parent, args),
33
m_configurationMode(false),
36
setAspectRatioMode(Plasma::IgnoreAspectRatio);
37
setHasConfigurationInterface(false);
38
QAction *toggleFixed = new QAction(i18n("Set Flexible Size"), this);
39
toggleFixed->setCheckable(true);
40
m_actions.append(toggleFixed);
41
addAction(QLatin1String("toggle fixed"), toggleFixed);
42
connect(toggleFixed, SIGNAL(toggled(bool)), this, SLOT(toggleFixed(bool)));
43
setCacheMode(DeviceCoordinateCache);
46
PanelSpacer::~PanelSpacer()
50
QList<QAction *> PanelSpacer::contextualActions()
55
void PanelSpacer::toggleFixed(bool flexible)
57
m_fixedSize = !flexible;
60
setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
62
} else if (formFactor() == Plasma::Horizontal) {
63
setMaximumWidth(size().width());
64
setMinimumWidth(size().width());
65
} else if (formFactor() == Plasma::Vertical) {
66
setMaximumHeight(size().height());
67
setMinimumHeight(size().height());
70
config().writeEntry("FixedSize", m_fixedSize);
71
emit configNeedsSaving();
74
void PanelSpacer::init()
77
connect(containment(), SIGNAL(toolBoxVisibilityChanged(bool)), this, SLOT(updateConfigurationMode(bool)));
83
void PanelSpacer::configChanged()
85
m_fixedSize = config().readEntry("FixedSize", false);
86
toggleFixed(!m_fixedSize);
87
QAction *fixedAction = action(QLatin1String("toggle fixed"));
89
fixedAction->setChecked(!m_fixedSize);
93
void PanelSpacer::constraintsEvent(Plasma::Constraints constraints)
95
if (constraints & Plasma::FormFactorConstraint) {
96
if (formFactor() == Plasma::Horizontal) {
97
setMinimumWidth(minimumHeight());
98
setMaximumWidth(maximumHeight());
99
setMaximumHeight(QWIDGETSIZE_MAX);
101
} else if (formFactor() == Plasma::Vertical) {
102
setMinimumHeight(minimumWidth());
103
setMaximumHeight(maximumWidth());
104
setMaximumWidth(QWIDGETSIZE_MAX);
109
if (constraints & Plasma::StartupCompletedConstraint) {
111
setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
113
} else if (formFactor() == Plasma::Horizontal) {
114
setMaximumWidth(size().width());
115
setMinimumWidth(size().width());
116
} else if (formFactor() == Plasma::Vertical) {
117
setMaximumHeight(size().height());
118
setMinimumHeight(size().height());
122
if (constraints & Plasma::SizeConstraint) {
123
m_fixedSize = ((formFactor() == Plasma::Horizontal && maximumWidth() == minimumWidth()) || (formFactor() == Plasma::Vertical && maximumHeight() == minimumHeight()));
124
config().writeEntry("FixedSize", m_fixedSize);
126
QAction *fixedAction = action(QLatin1String("toggle fixed"));
128
fixedAction->setChecked(!m_fixedSize);
131
setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
134
void PanelSpacer::paintInterface(QPainter *painter, const QStyleOptionGraphicsItem *option, const QRect &contentsRect)
138
if (!m_configurationMode) {
141
painter->setRenderHint(QPainter::Antialiasing);
142
QPainterPath p = Plasma::PaintUtils::roundedRectangle(contentsRect.adjusted(1, 1, -2, -2), 4);
143
QColor c = Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor);
146
painter->fillPath(p, c);
148
painter->setRenderHint(QPainter::Antialiasing);
149
c = Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor);
152
const int margin = 8;
155
if (formFactor() == Plasma::Horizontal) {
156
path = Plasma::PaintUtils::roundedRectangle(contentsRect.adjusted(1, 1, -contentsRect.width()+margin-1, -2), 4);
157
painter->fillPath(path, c);
158
path = Plasma::PaintUtils::roundedRectangle(contentsRect.adjusted(contentsRect.width()-margin, 1, -2, -2), 4);
159
} else if (formFactor() == Plasma::Vertical) {
160
path = Plasma::PaintUtils::roundedRectangle(contentsRect.adjusted(1, 1, -2, -contentsRect.height()+margin-1), 4);
161
painter->fillPath(path, c);
162
path = Plasma::PaintUtils::roundedRectangle(contentsRect.adjusted(1, contentsRect.height()-margin, -2, -2), 4);
164
painter->fillPath(path, c);
167
void PanelSpacer::updateConfigurationMode(bool config)
169
if (containment() && containment()->immutability() != Plasma::Mutable) {
173
if (config != m_configurationMode) {
174
m_configurationMode = config;
180
#include "panelspacer.moc"