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.
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
)
31 return i18n("No Rotation");
33 return i18n("Left (90 degrees)");
35 return i18n("Upside-down (180 degrees)");
37 return i18n("Right (270 degrees)");
39 return i18n("Mirror horizontally");
41 return i18n("Mirror vertically");
43 return i18n("Unknown orientation");
48 return i18n("Not rotated");
50 return i18n("Rotated 90 degrees counterclockwise");
52 return i18n("Rotated 180 degrees counterclockwise");
54 return i18n("Rotated 270 degrees counterclockwise");
56 if (rotation
& RR_Reflect_X
)
57 if (rotation
& RR_Reflect_Y
)
59 return i18n("Mirrored horizontally and vertically");
61 return i18n("mirrored horizontally and vertically");
64 return i18n("Mirrored horizontally");
66 return i18n("mirrored horizontally");
67 else if (rotation
& RR_Reflect_Y
)
69 return i18n("Mirrored vertically");
71 return i18n("mirrored vertically");
74 return i18n("Unknown orientation");
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
) {
98 if (rotation
> RR_Rotate_270
) {
105 return SmallIcon("go-up");
107 return SmallIcon("go-previous");
109 return SmallIcon("go-down");
111 return SmallIcon("go-next");
115 return SmallIcon("process-stop");
119 bool RandR::confirm(const QRect
&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();
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
];
168 sizeSort
[highestIndex
] = -1;
169 Q_ASSERT(highestIndex
!= -1);
171 sorted
.append(sizes
[highestIndex
]);