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

« back to all changes in this revision

Viewing changes to kcontrol/randr/randr.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 (c) 2007      Gustavo Pichorim Boiko <gustavo.boiko@kdemail.net>
 
3
 * Copyright (c) 2002,2003 Hamish Rodda <rodda@kde.org>
 
4
 *
 
5
 *  This program is free software; you can redistribute it and/or modify
 
6
 *  it under the terms of the GNU General Public License as published by
 
7
 *  the Free Software Foundation; either version 2 of the License, or
 
8
 *  (at your option) any later version.
 
9
 *
 
10
 *  This program is distributed in the hope that it will be useful,
 
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 *  GNU General Public License for more details.
 
14
 *
 
15
 *  You should have received a copy of the GNU General Public License
 
16
 *  along with this program; if not, write to the Free Software
 
17
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
18
 */
 
19
 
 
20
#include "randr.h"
 
21
#include <KIconLoader>
 
22
 
 
23
bool RandR::has_1_2 = false;
 
24
bool RandR::has_1_3 = false;
 
25
Time RandR::timestamp = 0;
 
26
 
 
27
QString RandR::rotationName(int rotation, bool pastTense, bool capitalised)
 
28
{
 
29
        if (!pastTense)
 
30
                switch (rotation) {
 
31
                        case RR_Rotate_0:
 
32
                                return i18n("No Rotation");
 
33
                        case RR_Rotate_90:
 
34
                                return i18n("Left (90 degrees)");
 
35
                        case RR_Rotate_180:
 
36
                                return i18n("Upside-Down (180 degrees)");
 
37
                        case RR_Rotate_270:
 
38
                                return i18n("Right (270 degrees)");
 
39
                        case RR_Reflect_X:
 
40
                                return i18n("Mirror Horizontally");
 
41
                        case RR_Reflect_Y:
 
42
                                return i18n("Mirror Vertically");
 
43
                        default:
 
44
                                return i18n("Unknown Orientation");
 
45
                }
 
46
 
 
47
        switch (rotation) {
 
48
                case RR_Rotate_0:
 
49
                        return i18n("Not Rotated");
 
50
                case RR_Rotate_90:
 
51
                        return i18n("Rotated 90 Degrees Counterclockwise");
 
52
                case RR_Rotate_180:
 
53
                        return i18n("Rotated 180 Degrees Counterclockwise");
 
54
                case RR_Rotate_270:
 
55
                        return i18n("Rotated 270 Degrees Counterclockwise");
 
56
                default:
 
57
                        if (rotation & RR_Reflect_X)
 
58
                                if (rotation & RR_Reflect_Y)
 
59
                                        if (capitalised)
 
60
                                                return i18n("Mirrored Horizontally And Vertically");
 
61
                                        else
 
62
                                                return i18n("mirrored horizontally and vertically");
 
63
                                else
 
64
                                        if (capitalised)
 
65
                                                return i18n("Mirrored Horizontally");
 
66
                                        else
 
67
                                                return i18n("mirrored horizontally");
 
68
                        else if (rotation & RR_Reflect_Y)
 
69
                                if (capitalised)
 
70
                                        return i18n("Mirrored Vertically");
 
71
                                else
 
72
                                        return i18n("mirrored vertically");
 
73
                        else
 
74
                                if (capitalised)
 
75
                                        return i18n("Unknown Orientation");
 
76
                                else
 
77
                                        return i18n("unknown orientation");
 
78
        }
 
79
}
 
80
 
 
81
QPixmap RandR::rotationIcon(int rotation, int currentRotation)
 
82
{
 
83
        // Adjust icons for current screen orientation
 
84
        if (!(currentRotation & RR_Rotate_0) && rotation & (RR_Rotate_0 | RR_Rotate_90 | RR_Rotate_180 | RR_Rotate_270)) {
 
85
                int currentAngle = currentRotation & (RR_Rotate_90 | RR_Rotate_180 | RR_Rotate_270);
 
86
                switch (currentAngle) {
 
87
                        case RR_Rotate_90:
 
88
                                rotation <<= 3;
 
89
                                break;
 
90
                        case RR_Rotate_180:
 
91
                                rotation <<= 2;
 
92
                                break;
 
93
                        case RR_Rotate_270:
 
94
                                rotation <<= 1;
 
95
                                break;
 
96
                }
 
97
 
 
98
                // Fix overflow
 
99
                if (rotation > RR_Rotate_270) {
 
100
                        rotation >>= 4;
 
101
                }
 
102
        }
 
103
 
 
104
        switch (rotation) {
 
105
                case RR_Rotate_0:
 
106
                        return SmallIcon("go-up");
 
107
                case RR_Rotate_90:
 
108
                        return SmallIcon("go-previous");
 
109
                case RR_Rotate_180:
 
110
                        return SmallIcon("go-down");
 
111
                case RR_Rotate_270:
 
112
                        return SmallIcon("go-next");
 
113
                case RR_Reflect_X:
 
114
                case RR_Reflect_Y:
 
115
                default:
 
116
                        return SmallIcon("process-stop");
 
117
        }
 
118
}
 
119
 
 
120
bool RandR::confirm(const QRect &rect)
 
121
{
 
122
        Q_UNUSED(rect);
 
123
        // FIXME remember to put the dialog on the right screen
 
124
 
 
125
        KTimerDialog acceptDialog(15000, KTimerDialog::CountDown,
 
126
                                  0, "mainKTimerDialog", true,
 
127
                                  i18n("Confirm Display Setting Change"),
 
128
                                  KTimerDialog::Ok|KTimerDialog::Cancel,
 
129
                                  KTimerDialog::Cancel);
 
130
 
 
131
        acceptDialog.setButtonGuiItem(KDialog::Ok, KGuiItem(i18n("&Accept Configuration"), "dialog-ok"));
 
132
        acceptDialog.setButtonGuiItem(KDialog::Cancel, KGuiItem(i18n("&Revert to Previous Configuration"), "dialog-cancel"));
 
133
 
 
134
        QLabel *label = new QLabel(i18n("Your screen configuration has been "
 
135
                    "changed to the requested settings. Please indicate whether you wish to keep "
 
136
                    "this configuration. In 15 seconds the display will revert to your previous "
 
137
                    "settings."), &acceptDialog);
 
138
        label->setWordWrap( true );
 
139
        acceptDialog.setMainWidget(label);
 
140
 
 
141
        //FIXME: this should be changed to use the rect instead of centerOnScreen
 
142
        //KDialog::centerOnScreen(&acceptDialog, m_screen);
 
143
 
 
144
        return acceptDialog.exec();
 
145
}
 
146
 
 
147
SizeList RandR::sortSizes(const SizeList &sizes)
 
148
{
 
149
        int *sizeSort = new int[sizes.count()];
 
150
        int numSizes = sizes.count();
 
151
        SizeList sorted;
 
152
 
 
153
        int i = 0;
 
154
        foreach(const QSize &size, sizes)
 
155
                sizeSort[i++] = size.width() * size.height();
 
156
 
 
157
        for (int j = 0; j < numSizes; j++) 
 
158
        {
 
159
                int highest = -1, highestIndex = -1;
 
160
 
 
161
                for (int i = 0; i < numSizes; i++) 
 
162
                {
 
163
                        if (sizeSort[i] && sizeSort[i] > highest) 
 
164
                        {
 
165
                                highest = sizeSort[i];
 
166
                                highestIndex = i;
 
167
                        }
 
168
                }
 
169
                sizeSort[highestIndex] = -1;
 
170
                Q_ASSERT(highestIndex != -1);
 
171
 
 
172
                sorted.append(sizes[highestIndex]);
 
173
        }
 
174
        delete [] sizeSort;
 
175
    sizeSort = 0L;
 
176
 
 
177
        return sorted;
 
178
}
 
179
 
 
180
 
 
181