1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
15 Author: Stefan Hundhammer <sh@suse.de>
17 Textdomain "packages-qt"
27 #include <QMessageBox>
28 #include <QColorGroup>
29 #include <QDesktopWidget>
32 #define y2log_component "qt-ui"
33 #include <ycp/y2log.h>
38 #include "QY2Settings.h"
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.
47 int YQUI::getDisplayWidth()
49 return qApp->desktop()->width();
53 int YQUI::getDisplayHeight()
55 return qApp->desktop()->height();
59 int YQUI::getDisplayDepth()
61 return qApp->desktop()->depth();
65 long YQUI::getDisplayColors()
67 return 1L << qApp->desktop()->depth();
71 int YQUI::getDefaultWidth()
73 return _default_size.width();
77 int YQUI::getDefaultHeight()
79 return _default_size.height();
83 int YQUI::defaultSize(YUIDimension dim) const
85 return dim == YD_HORIZ ? _default_size.width() : _default_size.height();
95 YQUI_Ui::slotBusyCursor()
97 YQUI::ui()->busyCursor();
101 YQUI::busyCursor( void )
103 qApp->setOverrideCursor( Qt::BusyCursor );
108 YQUI::normalCursor( void )
110 if ( _busy_cursor_timer->isActive() )
111 _busy_cursor_timer->stop();
113 while ( qApp->overrideCursor() )
114 qApp->restoreOverrideCursor();
118 void YQUI::toggleVisionImpairedPalette()
120 if ( _usingVisionImpairedPalette )
122 qApp->setPalette( normalPalette()); // informWidgets
124 _usingVisionImpairedPalette = false;
128 qApp->setPalette( visionImpairedPalette() ); // informWidgets
130 _usingVisionImpairedPalette = true;
135 QPalette YQUI::visionImpairedPalette()
137 const QColor dark ( 0x20, 0x20, 0x20 );
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 );
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 );
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 );
172 sendEvent( new YCancelEvent() );
178 * UI-specific conversion from logical layout spacing units (80x25)
179 * to device dependent units (640x480).
181 int YQUI::deviceUnits( YUIDimension dim, float size )
183 if ( dim==YD_HORIZ ) size *= ( 640.0/80 );
184 else size *= ( 480.0/25 );
186 return (int) ( size + 0.5 );
191 * Default conversion from device dependent layout spacing units (640x480)
192 * to logical layout units (80x25).
194 * This default function assumes 80x25 units.
195 * Derived UIs may want to reimplement this.
197 float YQUI::layoutUnits( YUIDimension dim, int device_units )
199 float size = (float) device_units;
201 if ( dim==YD_HORIZ ) size *= ( 80/640.0 );
202 else size *= ( 25/480.0 );
208 void YQUI::maybeLeftHandedUser()
210 if ( _askedForLeftHandedMouse )
215 _( "You clicked the right mouse button "
216 "where a left-click was expected."
218 "Switch left and right mouse buttons?"
220 int button = QMessageBox::question( 0,
221 // Popup dialog caption
222 _( "Unexpected Click" ),
224 QMessageBox::Yes | QMessageBox::Default,
226 QMessageBox::Cancel | QMessageBox::Escape );
228 if ( button == QMessageBox::Yes )
231 const char * command =
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
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 );
242 else if ( button == 1 ) // No
244 _askedForLeftHandedMouse = true;