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
86 return dim == YD_HORIZ ? _default_size.width() : _default_size.height();
88 return dim == YD_HORIZ ? qApp->desktop()->width() : qApp->desktop()->height();
92 QWidget* YQUI::mainWidget()
105 YQUI::busyCursor( void )
107 qApp->setOverrideCursor( Qt::BusyCursor );
112 YQUI::normalCursor( void )
114 if ( _busy_cursor_timer->isActive() )
115 _busy_cursor_timer->stop();
117 while ( qApp->overrideCursor() )
118 qApp->restoreOverrideCursor();
122 void YQUI::toggleVisionImpairedPalette()
124 if ( _usingVisionImpairedPalette )
126 qApp->setPalette( normalPalette()); // informWidgets
128 _usingVisionImpairedPalette = false;
132 qApp->setPalette( visionImpairedPalette() ); // informWidgets
134 _usingVisionImpairedPalette = true;
139 QPalette YQUI::visionImpairedPalette()
141 const QColor dark ( 0x20, 0x20, 0x20 );
144 // for the active window (the one with the keyboard focus)
145 pal.setColor( QPalette::Active, QPalette::Background, Qt::black );
146 pal.setColor( QPalette::Active, QPalette::Foreground, Qt::cyan );
147 pal.setColor( QPalette::Active, QPalette::Text, Qt::cyan );
148 pal.setColor( QPalette::Active, QPalette::Base, dark );
149 pal.setColor( QPalette::Active, QPalette::Button, dark );
150 pal.setColor( QPalette::Active, QPalette::ButtonText, Qt::green );
151 pal.setColor( QPalette::Active, QPalette::Highlight, Qt::yellow );
152 pal.setColor( QPalette::Active, QPalette::HighlightedText, Qt::black );
154 // for other windows (those that don't have the keyboard focus)
155 pal.setColor( QPalette::Inactive, QPalette::Background, Qt::black );
156 pal.setColor( QPalette::Inactive, QPalette::Foreground, Qt::cyan );
157 pal.setColor( QPalette::Inactive, QPalette::Text, Qt::cyan );
158 pal.setColor( QPalette::Inactive, QPalette::Base, dark );
159 pal.setColor( QPalette::Inactive, QPalette::Button, dark );
160 pal.setColor( QPalette::Inactive, QPalette::ButtonText, Qt::green );
162 // for disabled widgets
163 pal.setColor( QPalette::Disabled, QPalette::Background, Qt::black );
164 pal.setColor( QPalette::Disabled, QPalette::Foreground, Qt::gray );
165 pal.setColor( QPalette::Disabled, QPalette::Text, Qt::gray );
166 pal.setColor( QPalette::Disabled, QPalette::Base, dark );
167 pal.setColor( QPalette::Disabled, QPalette::Button, dark );
168 pal.setColor( QPalette::Disabled, QPalette::ButtonText, Qt::gray );
176 sendEvent( new YCancelEvent() );
181 bool YQUI::eventFilter( QObject * obj, QEvent * ev )
183 if ( ev->type() == QEvent::Close )
185 // Handle WM_CLOSE - but only if it comes from a dialog that is managed by the UI,
186 // not from an independent Qt dialog (such as the package selector popups)
188 QWidget * objDialog = 0;
190 if ( obj && obj->isWidgetType() )
192 objDialog = (QWidget *) obj;
193 objDialog = objDialog->topLevelWidget();
197 ( objDialog == mainWidget() ||
198 objDialog == (QObject *) YDialog::currentDialog()->widgetRep() ) )
202 if ( ! _wm_close_blocked )
204 // Don't simply close the application window, return from UserInput()
205 // with `id(`cancel) and let the YCP application decide how to handle
206 // that (e.g., ask for confirmation).
208 y2debug( "Caught window close event - returning with `cancel" );
209 sendEvent( new YCancelEvent() );
212 return true; // Event processed
215 else if ( ev->type() == QEvent::Show )
217 if ( obj == _main_win )
219 #ifdef FIXME_PROBABLY_OBSOLETE
220 if ( _widget_stack->count() > 0 )
222 // Work around QWidgetStack bug: The last raiseWidget() call
223 // (from closeDialog() ) might have failed if the widget was
224 // invisible at that time, e.g., because the user had switched to
225 // some other virtual desktop (bugzilla bug #11310)
227 _widget_stack->setCurrentWidget( whatever );
233 return showEventFilter( obj, ev );
236 return QObject::eventFilter( obj, ev );
240 bool YQUI::showEventFilter( QObject * obj, QEvent * ev )
244 // Make sure newly opened windows get the keyboard focus even without a
245 // window manager. Otherwise the app might be unusable without a mouse.
247 QWidget * widget = dynamic_cast<QWidget *> (obj);
250 widget->activateWindow();
253 return false; // Don't stop event processing
258 * UI-specific conversion from logical layout spacing units (80x25)
259 * to device dependent units (640x480).
261 int YQUI::deviceUnits( YUIDimension dim, float size )
263 if ( dim==YD_HORIZ ) size *= ( 640.0/80 );
264 else size *= ( 480.0/25 );
266 return (int) ( size + 0.5 );
271 * Default conversion from device dependent layout spacing units (640x480)
272 * to logical layout units (80x25).
274 * This default function assumes 80x25 units.
275 * Derived UIs may want to reimplement this.
277 float YQUI::layoutUnits( YUIDimension dim, int device_units )
279 float size = (float) device_units;
281 if ( dim==YD_HORIZ ) size *= ( 80/640.0 );
282 else size *= ( 25/480.0 );
288 void YQUI::maybeLeftHandedUser()
290 if ( _askedForLeftHandedMouse )
295 _( "You clicked the right mouse button "
296 "where a left-click was expected."
298 "Switch left and right mouse buttons?"
300 int button = QMessageBox::question( 0,
301 // Popup dialog caption
302 _( "Unexpected Click" ),
304 QMessageBox::Yes | QMessageBox::Default,
306 QMessageBox::Cancel | QMessageBox::Escape );
308 if ( button == QMessageBox::Yes )
311 const char * command =
313 "xmodmap -e \"pointer = 1 2 3\"": // switch back to right-handed mouse
314 "xmodmap -e \"pointer = 3 2 1\""; // switch to left-handed mouse
316 _leftHandedMouse = ! _leftHandedMouse; // might be set repeatedly!
317 _askedForLeftHandedMouse = false; // give the user a chance to switch back
318 y2milestone( "Switching mouse buttons: %s", command );
322 else if ( button == 1 ) // No
324 _askedForLeftHandedMouse = true;