]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/YQUI_x11.cc
Duncan, for you
[duncan/yast2-qt4.git] / src / YQUI_x11.cc
1 /*---------------------------------------------------------------------\
2 |                                                                      |
3 |                      __   __    ____ _____ ____                      |
4 |                      \ \ / /_ _/ ___|_   _|___ \                     |
5 |                       \ V / _` \___ \ | |   __) |                    |
6 |                        | | (_| |___) || |  / __/                     |
7 |                        |_|\__,_|____/ |_| |_____|                    |
8 |                                                                      |
9 |                               core system                            |
10 |                                                        (C) SuSE GmbH |
11 \----------------------------------------------------------------------/
12
13   File:         YUIQt_x11.cc
14
15   Author:       Stefan Hundhammer <sh@suse.de>
16
17   Textdomain "packages-qt"
18
19 /-*/
20
21 #include <QEvent>
22 #include <QCursor>
23 #include <QWidget>
24 #include <QTextCodec>
25 #include <QRegExp>
26 #include <QLocale>
27 #include <QMessageBox>
28 #include <QColorGroup>
29 #include <QDesktopWidget>
30
31
32 #define y2log_component "qt-ui"
33 #include <ycp/y2log.h>
34
35 #include "YEvent.h"
36 #include "YQDialog.h"
37 #include "YQi18n.h"
38 #include "QY2Settings.h"
39 #include "YQUI.h"
40
41 // Include low-level X headers AFTER Qt headers:
42 // X.h pollutes the global namespace (!!!) with pretty useless #defines
43 // like "Above", "Below" etc. that clash with some Qt headers.
44 #include <X11/Xlib.h>
45
46
47 int YQUI::getDisplayWidth()
48 {
49     return qApp->desktop()->width();
50 }
51
52
53 int YQUI::getDisplayHeight()
54 {
55     return qApp->desktop()->height();
56 }
57
58
59 int YQUI::getDisplayDepth()
60 {
61     return qApp->desktop()->depth();
62 }
63
64
65 long YQUI::getDisplayColors()
66 {
67     return 1L << qApp->desktop()->depth();
68 }
69
70
71 int YQUI::getDefaultWidth()
72 {
73     return _default_size.width();
74 }
75
76
77 int YQUI::getDefaultHeight()
78 {
79     return _default_size.height();
80 }
81
82
83 int YQUI::defaultSize(YUIDimension dim) const
84 {
85     return dim == YD_HORIZ ? _default_size.width() : _default_size.height();
86 }
87
88
89 void YQUI::beep()
90 {
91     qApp->beep();
92 }
93
94
95 void
96 YQUI::busyCursor( void )
97 {
98     qApp->setOverrideCursor( Qt::BusyCursor );
99 }
100
101
102 void
103 YQUI::normalCursor( void )
104 {
105     if ( _busy_cursor_timer->isActive() )
106         _busy_cursor_timer->stop();
107
108     while ( qApp->overrideCursor() )
109         qApp->restoreOverrideCursor();
110 }
111
112
113 void YQUI::toggleVisionImpairedPalette()
114 {
115     if ( _usingVisionImpairedPalette )
116     {
117         qApp->setPalette( normalPalette());  // informWidgets
118
119         _usingVisionImpairedPalette = false;
120     }
121     else
122     {
123         qApp->setPalette( visionImpairedPalette() );  // informWidgets
124
125         _usingVisionImpairedPalette = true;
126     }
127 }
128
129
130 QPalette YQUI::visionImpairedPalette()
131 {
132     const QColor dark  ( 0x20, 0x20, 0x20 );
133     QPalette pal;
134
135     // for the active window (the one with the keyboard focus)
136     pal.setColor( QPalette::Active, QPalette::Background,               Qt::black       );
137     pal.setColor( QPalette::Active, QPalette::Foreground,               Qt::cyan        );
138     pal.setColor( QPalette::Active, QPalette::Text,             Qt::cyan        );
139     pal.setColor( QPalette::Active, QPalette::Base,             dark            );
140     pal.setColor( QPalette::Active, QPalette::Button,           dark            );
141     pal.setColor( QPalette::Active, QPalette::ButtonText,               Qt::green       );
142     pal.setColor( QPalette::Active, QPalette::Highlight,                Qt::yellow      );
143     pal.setColor( QPalette::Active, QPalette::HighlightedText,  Qt::black       );
144
145     // for other windows (those that don't have the keyboard focus)
146     pal.setColor( QPalette::Inactive, QPalette::Background,     Qt::black       );
147     pal.setColor( QPalette::Inactive, QPalette::Foreground,     Qt::cyan        );
148     pal.setColor( QPalette::Inactive, QPalette::Text,           Qt::cyan        );
149     pal.setColor( QPalette::Inactive, QPalette::Base,           dark            );
150     pal.setColor( QPalette::Inactive, QPalette::Button,         dark            );
151     pal.setColor( QPalette::Inactive, QPalette::ButtonText,     Qt::green       );
152
153     // for disabled widgets
154     pal.setColor( QPalette::Disabled, QPalette::Background,     Qt::black       );
155     pal.setColor( QPalette::Disabled, QPalette::Foreground,     Qt::gray        );
156     pal.setColor( QPalette::Disabled, QPalette::Text,           Qt::gray        );
157     pal.setColor( QPalette::Disabled, QPalette::Base,           dark            );
158     pal.setColor( QPalette::Disabled, QPalette::Button,         dark            );
159     pal.setColor( QPalette::Disabled, QPalette::ButtonText,     Qt::gray        );
160
161     return pal;
162 }
163
164
165 bool YQUI::close()
166 {
167     sendEvent( new YCancelEvent() );
168     return true;
169 }
170
171
172 /**
173  * UI-specific conversion from logical layout spacing units (80x25)
174  * to device dependent units (640x480).
175  **/
176 int YQUI::deviceUnits( YUIDimension dim, float size )
177 {
178     if ( dim==YD_HORIZ )        size *= ( 640.0/80 );
179     else                        size *= ( 480.0/25 );
180
181     return (int) ( size + 0.5 );
182 }
183
184
185 /**
186  * Default conversion from device dependent layout spacing units (640x480)
187  * to logical layout units (80x25).
188  *
189  * This default function assumes 80x25 units.
190  * Derived UIs may want to reimplement this.
191  **/
192 float YQUI::layoutUnits( YUIDimension dim, int device_units )
193 {
194     float size = (float) device_units;
195
196     if ( dim==YD_HORIZ )        size *= ( 80/640.0 );
197     else                        size *= ( 25/480.0 );
198
199     return size;
200 }
201
202
203 void YQUI::maybeLeftHandedUser()
204 {
205     if ( _askedForLeftHandedMouse )
206         return;
207
208
209     QString message =
210         _( "You clicked the right mouse button "
211            "where a left-click was expected."
212            "\n"
213            "Switch left and right mouse buttons?"
214            );
215     int button = QMessageBox::question( 0,
216                                         // Popup dialog caption
217                                         _( "Unexpected Click" ),
218                                         message,
219                                         QMessageBox::Yes | QMessageBox::Default,
220                                         QMessageBox::No,
221                                         QMessageBox::Cancel | QMessageBox::Escape );
222
223     if ( button == QMessageBox::Yes )
224     {
225
226         const char * command =
227             _leftHandedMouse ?
228             "xmodmap -e \"pointer = 1 2 3\"":   // switch back to right-handed mouse
229             "xmodmap -e \"pointer = 3 2 1\"";   // switch to left-handed mouse
230
231         _leftHandedMouse         = ! _leftHandedMouse;  // might be set repeatedly!
232         _askedForLeftHandedMouse = false;       // give the user a chance to switch back
233         y2milestone( "Switching mouse buttons: %s", command );
234
235         system( command );
236     }
237     else if ( button == 1 )     // No
238     {
239         _askedForLeftHandedMouse = true;
240     }
241 }
242
243
244
245 // EOF