2
* Copyright (C) 2007, 2008, 2009, 2010 Ivan Cukic <ivan.cukic(at)kde.org>
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU Lesser/Library General Public License version 2,
6
* or (at your option) any later version, as published by the Free
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 Lesser/Library General Public License for more details
14
* You should have received a copy of the GNU Lesser/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 "FlipLayout.h"
22
#include <QGraphicsWidget>
29
FlipLayoutManager * FlipLayoutManager::m_instance = NULL;
31
class FlipLayoutManager::Private {
33
Plasma::Flip globalFlip;
34
QSet < QGraphicsLayout * > globalFlipLayouts;
35
QMap < QGraphicsLayout *, Plasma::Flip > flips;
38
FlipLayoutManager::FlipLayoutManager()
44
FlipLayoutManager::~FlipLayoutManager()
49
FlipLayoutManager * FlipLayoutManager::self()
51
if (m_instance == NULL) {
52
m_instance = new FlipLayoutManager();
57
void FlipLayoutManager::setGlobalFlip(Plasma::Flip flip)
62
Plasma::Flip FlipLayoutManager::globalFlip() const
67
void FlipLayoutManager::setFlip(const QGraphicsLayout * layout, Plasma::Flip flip)
69
QGraphicsLayout * l = const_cast<QGraphicsLayout *>(layout);
70
d->globalFlipLayouts.remove(l);
72
if (d->flips[l] != flip) {
74
l->setGeometry(l->geometry());
78
void FlipLayoutManager::setUseGlobalFlip(const QGraphicsLayout * layout)
80
QGraphicsLayout * l = const_cast<QGraphicsLayout *>(layout);
82
d->globalFlipLayouts.insert(l);
85
Plasma::Flip FlipLayoutManager::flip(const QGraphicsLayout * layout) const
87
QGraphicsLayout * l = const_cast<QGraphicsLayout *>(layout);
88
if (d->globalFlipLayouts.contains(l)) {
90
} else if (d->flips.contains(l)) {
96
void FlipLayoutManager::setGeometry(QGraphicsLayout * layout) const
98
int count = layout->count();
99
QRectF rect = layout->geometry();
101
if (flip(layout) == Plasma::NoFlip) {
105
QRectF childGeometry;
106
for (int i = 0; i < count; i++) {
107
QGraphicsLayoutItem * item = layout->itemAt(i);
111
childGeometry = item->geometry();
112
if (flip(layout) & Plasma::HorizontalFlip) {
113
childGeometry.moveLeft(rect.left() + rect.right() - childGeometry.right());
115
if (flip(layout) & Plasma::VerticalFlip) {
116
childGeometry.moveTop(rect.top() + rect.bottom() - childGeometry.bottom());
118
item->setGeometry(childGeometry);