]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/YQUI_x11.cc
clicking packages work! so the package selector is now
[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 void
95 YQUI_Ui::slotBusyCursor()
96 {
97     YQUI::ui()->busyCursor();
98 }
99
100 void
101 YQUI::busyCursor( void )
102 {
103     qApp->setOverrideCursor( Qt::BusyCursor );
104 }
105
106
107 void
108 YQUI::normalCursor( void )
109 {
110     if ( _busy_cursor_timer->isActive() )
111         _busy_cursor_timer->stop();
112
113     while ( qApp->overrideCursor() )
114         qApp->restoreOverrideCursor();
115 }
116
117
118 void YQUI::toggleVisionImpairedPalette()
119 {
120     if ( _usingVisionImpairedPalette )
121     {
122         qApp->setPalette( normalPalette());  // informWidgets
123
124         _usingVisionImpairedPalette = false;
125     }
126     else
127     {
128         qApp->setPalette( visionImpairedPalette() );  // informWidgets
129
130         _usingVisionImpairedPalette = true;
131     }
132 }
133
134
135 QPalette YQUI::visionImpairedPalette()
136 {
137     const QColor dark  ( 0x20, 0x20, 0x20 );
138     QPalette pal;
139
140     // for the active window (the one with the keyboard focus)
141     pal.setColor( QPalette::Active, QPalette::Background,               Qt::black       );
142     pal.setColor( QPalette::Active, QPalette::Foreground,               Qt::cyan        );
143     pal.setColor( QPalette::Active, QPalette::Text,             Qt::cyan        );
144     pal.setColor( QPalette::Active, QPalette::Base,             dark            );
145     pal.setColor( QPalette::Active, QPalette::Button,           dark            );
146     pal.setColor( QPalette::Active, QPalette::ButtonText,               Qt::green       );
147     pal.setColor( QPalette::Active, QPalette::Highlight,                Qt::yellow      );
148     pal.setColor( QPalette::Active, QPalette::HighlightedText,  Qt::black       );
149
150     // for other windows (those that don't have the keyboard focus)
151     pal.setColor( QPalette::Inactive, QPalette::Background,     Qt::black       );
152     pal.setColor( QPalette::Inactive, QPalette::Foreground,     Qt::cyan        );
153     pal.setColor( QPalette::Inactive, QPalette::Text,           Qt::cyan        );
154     pal.setColor( QPalette::Inactive, QPalette::Base,           dark            );
155     pal.setColor( QPalette::Inactive, QPalette::Button,         dark            );
156     pal.setColor( QPalette::Inactive, QPalette::ButtonText,     Qt::green       );
157
158     // for disabled widgets
159     pal.setColor( QPalette::Disabled, QPalette::Background,     Qt::black       );
160     pal.setColor( QPalette::Disabled, QPalette::Foreground,     Qt::gray        );
161     pal.setColor( QPalette::Disabled, QPalette::Text,           Qt::gray        );
162     pal.setColor( QPalette::Disabled, QPalette::Base,           dark            );
163     pal.setColor( QPalette::Disabled, QPalette::Button,         dark            );
164     pal.setColor( QPalette::Disabled, QPalette::ButtonText,     Qt::gray        );
165
166     return pal;
167 }
168
169
170 bool YQUI::close()
171 {
172     sendEvent( new YCancelEvent() );
173     return true;
174 }
175
176
177 /**
178  * UI-specific conversion from logical layout spacing units (80x25)
179  * to device dependent units (640x480).
180  **/
181 int YQUI::deviceUnits( YUIDimension dim, float size )
182 {
183     if ( dim==YD_HORIZ )        size *= ( 640.0/80 );
184     else                        size *= ( 480.0/25 );
185
186     return (int) ( size + 0.5 );
187 }
188
189
190 /**
191  * Default conversion from device dependent layout spacing units (640x480)
192  * to logical layout units (80x25).
193  *
194  * This default function assumes 80x25 units.
195  * Derived UIs may want to reimplement this.
196  **/
197 float YQUI::layoutUnits( YUIDimension dim, int device_units )
198 {
199     float size = (float) device_units;
200
201     if ( dim==YD_HORIZ )        size *= ( 80/640.0 );
202     else                        size *= ( 25/480.0 );
203
204     return size;
205 }
206
207
208 void YQUI::maybeLeftHandedUser()
209 {
210     if ( _askedForLeftHandedMouse )
211         return;
212
213
214     QString message =
215         _( "You clicked the right mouse button "
216            "where a left-click was expected."
217            "\n"
218            "Switch left and right mouse buttons?"
219            );
220     int button = QMessageBox::question( 0,
221                                         // Popup dialog caption
222                                         _( "Unexpected Click" ),
223                                         message,
224                                         QMessageBox::Yes | QMessageBox::Default,
225                                         QMessageBox::No,
226                                         QMessageBox::Cancel | QMessageBox::Escape );
227
228     if ( button == QMessageBox::Yes )
229     {
230
231         const char * command =
232             _leftHandedMouse ?
233             "xmodmap -e \"pointer = 1 2 3\"":   // switch back to right-handed mouse
234             "xmodmap -e \"pointer = 3 2 1\"";   // switch to left-handed mouse
235
236         _leftHandedMouse         = ! _leftHandedMouse;  // might be set repeatedly!
237         _askedForLeftHandedMouse = false;       // give the user a chance to switch back
238         y2milestone( "Switching mouse buttons: %s", command );
239
240         system( command );
241     }
242     else if ( button == 1 )     // No
243     {
244         _askedForLeftHandedMouse = true;
245     }
246 }
247
248
249
250 // EOF