~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to libs/kephal/kephal/desktopwidgetscreens.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
Copyright 2010 Will Stephenson <wstephenson@kde.org>
 
3
 
 
4
This program is free software; you can redistribute it and/or
 
5
modify it under the terms of the GNU General Public License as
 
6
published by the Free Software Foundation; either version 2 of
 
7
the License or (at your option) version 3 or any later version
 
8
accepted by the membership of KDE e.V. (or its successor approved
 
9
by the membership of KDE e.V.), which shall act as a proxy
 
10
defined in Section 14 of version 3 of the license.
 
11
 
 
12
This program is distributed in the hope that it will be useful,
 
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
GNU General Public License for more details.
 
16
 
 
17
You should have received a copy of the GNU General Public License
 
18
along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
19
*/
 
20
 
 
21
#include "desktopwidgetscreens.h"
 
22
 
 
23
#include <QDesktopWidget>
 
24
#include <QApplication>
 
25
 
 
26
#include <KDebug>
 
27
 
 
28
#include "simplescreen.h"
 
29
 
 
30
Kephal::DesktopWidgetScreens::DesktopWidgetScreens(QObject * parent)
 
31
    : Screens(parent)
 
32
{
 
33
    QDesktopWidget * desktop = QApplication::desktop();
 
34
    connect(desktop, SIGNAL(screenCountChanged(int)), this, SLOT(handleScreenCountChanged(int)));
 
35
    connect(desktop, SIGNAL(resized(int)), this, SLOT(handleScreenResized(int)));
 
36
 
 
37
    for (int i = 0; i < desktop->numScreens(); i++) {
 
38
        QRect geometry = desktop->screenGeometry(i);
 
39
        Kephal::SimpleScreen * screen =
 
40
            new Kephal::SimpleScreen(i, geometry.size(), geometry.topLeft(), false, this);
 
41
        m_screens.append(screen);
 
42
    }
 
43
}
 
44
 
 
45
Kephal::DesktopWidgetScreens::~DesktopWidgetScreens()
 
46
{
 
47
    foreach (Kephal::SimpleScreen * screen, m_screens) {
 
48
        int id = screen->id();
 
49
        delete screen;
 
50
        emit screenRemoved(id);
 
51
    }
 
52
}
 
53
 
 
54
QList<Kephal::Screen*> Kephal::DesktopWidgetScreens::screens()
 
55
{
 
56
    QList<Kephal::Screen*> list;
 
57
    foreach (Kephal::SimpleScreen * screen, m_screens) {
 
58
        list.append(screen);
 
59
    }
 
60
    return list;
 
61
}
 
62
 
 
63
void Kephal::DesktopWidgetScreens::handleScreenResized(int id)
 
64
{
 
65
    Kephal::SimpleScreen * screen = m_screens.value(id);
 
66
    QSize oldSize = screen->size();
 
67
    QPoint oldPosition = screen->position();
 
68
    //FIXME: find a better way to restrict changing Screen to Screens - friend modifier class?
 
69
    screen->_setGeom(QApplication::desktop()->screenGeometry(id));
 
70
    if (oldSize != screen->size()) {
 
71
        emit screenResized(screen, oldSize, screen->size());
 
72
    }
 
73
    if (oldPosition != screen->position()) {
 
74
        emit screenMoved(screen, oldPosition, screen->position());
 
75
    }
 
76
}
 
77
 
 
78
void Kephal::DesktopWidgetScreens::handleScreenCountChanged(int newCount)
 
79
{
 
80
    // add new Screens
 
81
    for (int i = m_screens.count(); i < newCount; i++) {
 
82
        QRect geometry = QApplication::desktop()->screenGeometry(i);
 
83
        Kephal::SimpleScreen * screen =
 
84
            new Kephal::SimpleScreen(i, geometry.size(), geometry.topLeft(), false, this);
 
85
        m_screens.append(screen);
 
86
        emit screenAdded(screen);
 
87
    }
 
88
 
 
89
    // remove no longer existing Screens
 
90
    while (m_screens.count() > newCount) {
 
91
        Kephal::SimpleScreen * screen = m_screens.takeLast();
 
92
        if (screen) {
 
93
            int id = screen->id();
 
94
            delete screen;
 
95
            emit screenRemoved(id);
 
96
        }
 
97
    }
 
98
}
 
99
 
 
100
// vim: sw=4 sts=4 et tw=100