Make a branch to make krunner Good Enough For Aaron™.
[kdebase/uwolfer.git] / workspace / kcontrol / randr / randr.cpp
blob1c45903ffd93a6a42e97fad64bda0311b08995bb
1 /*
2 * Copyright (c) 2007 Gustavo Pichorim Boiko <gustavo.boiko@kdemail.net>
3 * Copyright (c) 2002,2003 Hamish Rodda <rodda@kde.org>
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.
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.
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.
20 #include "randr.h"
21 #include <KIconLoader>
23 bool RandR::has_1_2 = false;
24 Time RandR::timestamp = 0;
26 QString RandR::rotationName(int rotation, bool pastTense, bool capitalised)
28 if (!pastTense)
29 switch (rotation) {
30 case RR_Rotate_0:
31 return i18n("No Rotation");
32 case RR_Rotate_90:
33 return i18n("Left (90 degrees)");
34 case RR_Rotate_180:
35 return i18n("Upside-down (180 degrees)");
36 case RR_Rotate_270:
37 return i18n("Right (270 degrees)");
38 case RR_Reflect_X:
39 return i18n("Mirror horizontally");
40 case RR_Reflect_Y:
41 return i18n("Mirror vertically");
42 default:
43 return i18n("Unknown orientation");
46 switch (rotation) {
47 case RR_Rotate_0:
48 return i18n("Not rotated");
49 case RR_Rotate_90:
50 return i18n("Rotated 90 degrees counterclockwise");
51 case RR_Rotate_180:
52 return i18n("Rotated 180 degrees counterclockwise");
53 case RR_Rotate_270:
54 return i18n("Rotated 270 degrees counterclockwise");
55 default:
56 if (rotation & RR_Reflect_X)
57 if (rotation & RR_Reflect_Y)
58 if (capitalised)
59 return i18n("Mirrored horizontally and vertically");
60 else
61 return i18n("mirrored horizontally and vertically");
62 else
63 if (capitalised)
64 return i18n("Mirrored horizontally");
65 else
66 return i18n("mirrored horizontally");
67 else if (rotation & RR_Reflect_Y)
68 if (capitalised)
69 return i18n("Mirrored vertically");
70 else
71 return i18n("mirrored vertically");
72 else
73 if (capitalised)
74 return i18n("Unknown orientation");
75 else
76 return i18n("unknown orientation");
80 QPixmap RandR::rotationIcon(int rotation, int currentRotation)
82 // Adjust icons for current screen orientation
83 if (!(currentRotation & RR_Rotate_0) && rotation & (RR_Rotate_0 | RR_Rotate_90 | RR_Rotate_180 | RR_Rotate_270)) {
84 int currentAngle = currentRotation & (RR_Rotate_90 | RR_Rotate_180 | RR_Rotate_270);
85 switch (currentAngle) {
86 case RR_Rotate_90:
87 rotation <<= 3;
88 break;
89 case RR_Rotate_180:
90 rotation <<= 2;
91 break;
92 case RR_Rotate_270:
93 rotation <<= 1;
94 break;
97 // Fix overflow
98 if (rotation > RR_Rotate_270) {
99 rotation >>= 4;
103 switch (rotation) {
104 case RR_Rotate_0:
105 return SmallIcon("go-up");
106 case RR_Rotate_90:
107 return SmallIcon("go-previous");
108 case RR_Rotate_180:
109 return SmallIcon("go-down");
110 case RR_Rotate_270:
111 return SmallIcon("go-next");
112 case RR_Reflect_X:
113 case RR_Reflect_Y:
114 default:
115 return SmallIcon("process-stop");
119 bool RandR::confirm(const QRect &rect)
121 Q_UNUSED(rect);
122 // FIXME remember to put the dialog on the right screen
124 KTimerDialog acceptDialog(15000, KTimerDialog::CountDown,
125 0, "mainKTimerDialog", true,
126 i18n("Confirm Display Setting Change"),
127 KTimerDialog::Ok|KTimerDialog::Cancel,
128 KTimerDialog::Cancel);
130 acceptDialog.setButtonGuiItem(KDialog::Ok, KGuiItem(i18n("&Accept Configuration"), "dialog-ok"));
131 acceptDialog.setButtonGuiItem(KDialog::Cancel, KGuiItem(i18n("&Revert to Previous Configuration"), "dialog-cancel"));
133 QLabel *label = new QLabel(i18n("Your screen configuration has been "
134 "changed to the requested settings. Please indicate whether you wish to keep "
135 "this configuration. In 15 seconds the display will revert to your previous "
136 "settings."), &acceptDialog);
137 label->setWordWrap( true );
138 acceptDialog.setMainWidget(label);
140 //FIXME: this should be changed to use the rect instead of centerOnScreen
141 //KDialog::centerOnScreen(&acceptDialog, m_screen);
143 return acceptDialog.exec();
146 SizeList RandR::sortSizes(const SizeList &sizes)
148 int *sizeSort = new int[sizes.count()];
149 int numSizes = sizes.count();
150 SizeList sorted;
152 int i = 0;
153 foreach(QSize size, sizes)
154 sizeSort[i++] = size.width() * size.height();
156 for (int j = 0; j < numSizes; j++)
158 int highest = -1, highestIndex = -1;
160 for (int i = 0; i < numSizes; i++)
162 if (sizeSort[i] && sizeSort[i] > highest)
164 highest = sizeSort[i];
165 highestIndex = i;
168 sizeSort[highestIndex] = -1;
169 Q_ASSERT(highestIndex != -1);
171 sorted.append(sizes[highestIndex]);
173 delete [] sizeSort;
174 sizeSort = 0L;
176 return sorted;