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();
96 YQUI::busyCursor( void )
98 qApp->setOverrideCursor( Qt::BusyCursor );
103 YQUI::normalCursor( void )
105 if ( _busy_cursor_timer->isActive() )
106 _busy_cursor_timer->stop();
108 while ( qApp->overrideCursor() )
109 qApp->restoreOverrideCursor();
113 void YQUI::toggleVisionImpairedPalette()
115 if ( _usingVisionImpairedPalette )
117 qApp->setPalette( normalPalette()); // informWidgets
119 _usingVisionImpairedPalette = false;
123 qApp->setPalette( visionImpairedPalette() ); // informWidgets
125 _usingVisionImpairedPalette = true;
130 QPalette YQUI::visionImpairedPalette()
132 const QColor dark ( 0x20, 0x20, 0x20 );
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 );
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 );
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 );
167 sendEvent( new YCancelEvent() );
173 * UI-specific conversion from logical layout spacing units (80x25)
174 * to device dependent units (640x480).
176 int YQUI::deviceUnits( YUIDimension dim, float size )
178 if ( dim==YD_HORIZ ) size *= ( 640.0/80 );
179 else size *= ( 480.0/25 );
181 return (int) ( size + 0.5 );
186 * Default conversion from device dependent layout spacing units (640x480)
187 * to logical layout units (80x25).
189 * This default function assumes 80x25 units.
190 * Derived UIs may want to reimplement this.
192 float YQUI::layoutUnits( YUIDimension dim, int device_units )
194 float size = (float) device_units;
196 if ( dim==YD_HORIZ ) size *= ( 80/640.0 );
197 else size *= ( 25/480.0 );
203 void YQUI::maybeLeftHandedUser()
205 if ( _askedForLeftHandedMouse )
210 _( "You clicked the right mouse button "
211 "where a left-click was expected."
213 "Switch left and right mouse buttons?"
215 int button = QMessageBox::question( 0,
216 // Popup dialog caption
217 _( "Unexpected Click" ),
219 QMessageBox::Yes | QMessageBox::Default,
221 QMessageBox::Cancel | QMessageBox::Escape );
223 if ( button == QMessageBox::Yes )
226 const char * command =
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
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 );
237 else if ( button == 1 ) // No
239 _askedForLeftHandedMouse = true;