2
* Copyright 2009 Aaron Seigo <aseigo@kde.org>
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU Library General Public License as
6
* published by the Free Software Foundation; either version 2, or
7
* (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.
24
#include <Plasma/Corona>
25
#include <Plasma/Containment>
27
#include "panelview.h"
28
#include "plasmaapp.h"
29
#include <plasmagenericshell/scripting/scriptengine.h>
30
#include <plasmagenericshell/scripting/widget.h>
32
namespace WorkspaceScripting
35
Panel::Panel(Plasma::Containment *containment, QObject *parent)
36
: Containment(containment, parent)
44
QString Panel::location() const
46
Plasma::Containment *c = containment();
51
switch (c->location()) {
52
case Plasma::Floating:
58
case Plasma::FullScreen:
64
case Plasma::BottomEdge:
67
case Plasma::LeftEdge:
70
case Plasma::RightEdge:
78
void Panel::setLocation(const QString &locationString)
80
Plasma::Containment *c = containment();
85
const QString lower = locationString.toLower();
86
Plasma::Location loc = Plasma::Floating;
87
if (lower == "desktop") {
88
loc = Plasma::Desktop;
89
} else if (lower == "fullscreen") {
90
loc = Plasma::FullScreen;
91
} else if (lower == "top") {
92
loc = Plasma::TopEdge;
93
} else if (lower == "bottom") {
94
loc = Plasma::BottomEdge;
95
} else if (lower == "left") {
96
loc = Plasma::LeftEdge;
97
} else if (lower == "right") {
98
loc = Plasma::RightEdge;
104
PanelView *Panel::panel() const
106
Plasma::Containment *c = containment();
111
foreach (PanelView *v, PlasmaApp::self()->panelViews()) {
112
if (v->containment() == c) {
120
QString Panel::alignment() const
122
PanelView *v = panel();
127
switch (v->alignment()) {
131
case Qt::AlignCenter:
142
void Panel::setAlignment(const QString &alignment)
144
PanelView *v = panel();
146
bool success = false;
148
if (alignment.compare("left", Qt::CaseInsensitive) == 0) {
149
if (v->alignment() != Qt::AlignLeft) {
151
v->setAlignment(Qt::AlignLeft);
153
} else if (alignment.compare("right", Qt::CaseInsensitive) == 0) {
154
if (v->alignment() != Qt::AlignRight) {
156
v->setAlignment(Qt::AlignRight);
158
} else if (alignment.compare("center", Qt::CaseInsensitive) == 0) {
159
if (v->alignment() != Qt::AlignCenter) {
161
v->setAlignment(Qt::AlignCenter);
171
int Panel::offset() const
173
PanelView *v = panel();
181
void Panel::setOffset(int pixels)
183
Plasma::Containment *c = containment();
184
if (pixels < 0 || !c) {
188
PanelView *v = panel();
190
QRectF screen = c->corona()->screenGeometry(v->screen());
191
QSizeF size = c->size();
193
if (c->formFactor() == Plasma::Vertical) {
194
if (pixels > screen.height()) {
198
if (size.height() + pixels > screen.height()) {
199
c->resize(size.width(), screen.height() - pixels);
201
} else if (pixels > screen.width()) {
203
} else if (size.width() + pixels > screen.width()) {
204
size.setWidth(screen.width() - pixels);
206
c->setMinimumSize(size);
207
c->setMaximumSize(size);
210
v->setOffset(pixels);
214
int Panel::length() const
216
Plasma::Containment *c = containment();
221
if (c->formFactor() == Plasma::Vertical) {
222
return c->size().height();
224
return c->size().width();
228
void Panel::setLength(int pixels)
230
Plasma::Containment *c = containment();
231
if (pixels < 0 || !c) {
235
PanelView *v = panel();
237
QRectF screen = c->corona()->screenGeometry(v->screen());
238
QSizeF s = c->size();
239
if (c->formFactor() == Plasma::Vertical) {
240
if (pixels > screen.height() - v->offset()) {
245
} else if (pixels > screen.width() - v->offset()) {
252
c->setMinimumSize(s);
253
c->setMaximumSize(s);
257
int Panel::height() const
259
Plasma::Containment *c = containment();
264
return c->formFactor() == Plasma::Vertical ? c->size().width()
265
: c->size().height();
268
void Panel::setHeight(int height)
270
Plasma::Containment *c = containment();
271
if (height < 16 || !c) {
275
PanelView *v = panel();
277
QRect screen = c->corona()->screenGeometry(v->screen());
278
QSizeF size = c->size();
279
const int max = (c->formFactor() == Plasma::Vertical ? screen.width() : screen.height()) / 3;
280
height = qBound(16, height, max);
282
if (c->formFactor() == Plasma::Vertical) {
283
size.setWidth(height);
285
size.setHeight(height);
289
c->setMinimumSize(size);
290
c->setMaximumSize(size);
294
QString Panel::hiding() const
296
PanelView *v = panel();
298
switch (v->visibilityMode()) {
299
case PanelView::NormalPanel:
302
case PanelView::AutoHide:
305
case PanelView::LetWindowsCover:
306
return "windowscover";
308
case PanelView::WindowsGoBelow:
309
return "windowsbelow";
317
void Panel::setHiding(const QString &mode)
319
PanelView *v = panel();
321
if (mode.compare("autohide", Qt::CaseInsensitive) == 0) {
322
v->setVisibilityMode(PanelView::AutoHide);
323
} else if (mode.compare("windowscover", Qt::CaseInsensitive) == 0) {
324
v->setVisibilityMode(PanelView::LetWindowsCover);
325
} else if (mode.compare("windowsbelow", Qt::CaseInsensitive) == 0) {
326
v->setVisibilityMode(PanelView::WindowsGoBelow);
328
v->setVisibilityMode(PanelView::NormalPanel);