~ubuntu-branches/ubuntu/oneiric/kdeplasma-addons/oneiric

« back to all changes in this revision

Viewing changes to libs/lancelot/layouts/FlipLayout.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Thomas
  • Date: 2010-05-25 09:50:14 UTC
  • mfrom: (1.1.28 upstream)
  • Revision ID: james.westby@ubuntu.com-20100525095014-6mlrm9z9bkws0zkt
Tags: 4:4.4.80-0ubuntu1
* New upstream beta release:
  - Bump kde-sc-dev-latest build-dep version to 4.4.80
  - Refresh kubuntu_04_kimpanel_disable_scim.diff
  - Update various .install files
  - Drop liblancelot0a and liblancelot-dev packages; Upstream has broken ABI
    without an .so version bump, and after discussion with Debian it was
    decided it was not worth it to ship an unstable library.
  - Add liblancelot files to plasma-widget-lancelot, adding appropriate
    Replaces: entries
* Switch to source format 3.0 (quilt):
  - Bump debhelper build-depend version to 7.3.16 or greater

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *   Copyright (C) 2007, 2008, 2009, 2010 Ivan Cukic <ivan.cukic(at)kde.org>
 
3
 *
 
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
 
7
 *   Software Foundation
 
8
 *
 
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
 
13
 *
 
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.
 
18
 */
 
19
 
 
20
#include "FlipLayout.h"
 
21
 
 
22
#include <QGraphicsWidget>
 
23
#include <QMap>
 
24
#include <QSet>
 
25
 
 
26
namespace Lancelot
 
27
{
 
28
 
 
29
FlipLayoutManager * FlipLayoutManager::m_instance = NULL;
 
30
 
 
31
class FlipLayoutManager::Private {
 
32
public:
 
33
    Plasma::Flip globalFlip;
 
34
    QSet < QGraphicsLayout * > globalFlipLayouts;
 
35
    QMap < QGraphicsLayout *, Plasma::Flip > flips;
 
36
};
 
37
 
 
38
FlipLayoutManager::FlipLayoutManager()
 
39
    : d(new Private())
 
40
{
 
41
 
 
42
}
 
43
 
 
44
FlipLayoutManager::~FlipLayoutManager()
 
45
{
 
46
    delete d;
 
47
}
 
48
 
 
49
FlipLayoutManager * FlipLayoutManager::self()
 
50
{
 
51
    if (m_instance == NULL) {
 
52
        m_instance = new FlipLayoutManager();
 
53
    }
 
54
    return m_instance;
 
55
}
 
56
 
 
57
void FlipLayoutManager::setGlobalFlip(Plasma::Flip flip)
 
58
{
 
59
    d->globalFlip = flip;
 
60
}
 
61
 
 
62
Plasma::Flip FlipLayoutManager::globalFlip() const
 
63
{
 
64
    return d->globalFlip;
 
65
}
 
66
 
 
67
void FlipLayoutManager::setFlip(const QGraphicsLayout * layout, Plasma::Flip flip)
 
68
{
 
69
    QGraphicsLayout * l = const_cast<QGraphicsLayout *>(layout);
 
70
    d->globalFlipLayouts.remove(l);
 
71
 
 
72
    if (d->flips[l] != flip) {
 
73
        d->flips[l] = flip;
 
74
        l->setGeometry(l->geometry());
 
75
    }
 
76
}
 
77
 
 
78
void FlipLayoutManager::setUseGlobalFlip(const QGraphicsLayout * layout)
 
79
{
 
80
    QGraphicsLayout * l = const_cast<QGraphicsLayout *>(layout);
 
81
    d->flips.remove(l);
 
82
    d->globalFlipLayouts.insert(l);
 
83
}
 
84
 
 
85
Plasma::Flip FlipLayoutManager::flip(const QGraphicsLayout * layout) const
 
86
{
 
87
    QGraphicsLayout * l = const_cast<QGraphicsLayout *>(layout);
 
88
    if (d->globalFlipLayouts.contains(l)) {
 
89
        return d->globalFlip;
 
90
    } else if (d->flips.contains(l)) {
 
91
        return d->flips[l];
 
92
    }
 
93
    return 0;
 
94
}
 
95
 
 
96
void FlipLayoutManager::setGeometry(QGraphicsLayout * layout) const
 
97
{
 
98
    int count = layout->count();
 
99
    QRectF rect = layout->geometry();
 
100
 
 
101
    if (flip(layout) == Plasma::NoFlip) {
 
102
        return;
 
103
    }
 
104
 
 
105
    QRectF childGeometry;
 
106
    for (int i = 0; i < count; i++) {
 
107
        QGraphicsLayoutItem * item = layout->itemAt(i);
 
108
 
 
109
        if (!item) continue;
 
110
 
 
111
        childGeometry = item->geometry();
 
112
        if (flip(layout) & Plasma::HorizontalFlip) {
 
113
            childGeometry.moveLeft(rect.left() + rect.right() - childGeometry.right());
 
114
        }
 
115
        if (flip(layout) & Plasma::VerticalFlip) {
 
116
            childGeometry.moveTop(rect.top() + rect.bottom() - childGeometry.bottom());
 
117
        }
 
118
        item->setGeometry(childGeometry);
 
119
    }
 
120
}
 
121
 
 
122
}
 
123