1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
15 Author: Stefan Hundhammer <sh@suse.de>
17 Textdomain "packages-qt"
24 #include <q3widgetstack.h>
27 #include <qtextcodec.h>
30 #include <qmessagebox.h>
31 #include <QtGui/qdesktopwidget.h>
34 #define y2log_component "qt-ui"
35 #include <ycp/y2log.h>
40 #include "QY2Settings.h"
43 // Include low-level X headers AFTER Qt headers:
44 // X.h pollutes the global namespace (!!!) with pretty useless #defines
45 // like "Above", "Below" etc. that clash with some Qt headers.
49 int YQUI::getDisplayWidth()
51 return qApp->desktop()->width();
55 int YQUI::getDisplayHeight()
57 return qApp->desktop()->height();
61 int YQUI::getDisplayDepth()
63 return qApp->desktop()->depth();
67 long YQUI::getDisplayColors()
69 return 1L << qApp->desktop()->depth();
73 int YQUI::getDefaultWidth()
75 return _default_size.width();
79 int YQUI::getDefaultHeight()
81 return _default_size.height();
85 int YQUI::defaultSize(YUIDimension dim) const
88 return dim == YD_HORIZ ? _default_size.width() : _default_size.height();
90 return dim == YD_HORIZ ? qApp->desktop()->width() : qApp->desktop()->height();
94 QWidget* YQUI::mainWidget()
107 YQUI::busyCursor( void )
109 qApp->setOverrideCursor( Qt::BusyCursor );
114 YQUI::normalCursor( void )
116 if ( _busy_cursor_timer->isActive() )
117 _busy_cursor_timer->stop();
119 while ( qApp->overrideCursor() )
120 qApp->restoreOverrideCursor();
124 void YQUI::toggleVisionImpairedPalette()
126 if ( _usingVisionImpairedPalette )
128 qApp->setPalette( normalPalette(),
129 true ); // informWidgets
131 _usingVisionImpairedPalette = false;
135 qApp->setPalette( visionImpairedPalette(),
136 true ); // informWidgets
138 _usingVisionImpairedPalette = true;
143 QPalette YQUI::visionImpairedPalette()
145 const QColor dark ( 0x20, 0x20, 0x20 );
147 QColorGroup activeCg; // for the active window (the one with the keyboard focus)
149 activeCg.setColor( QColorGroup::Background, Qt::black );
150 activeCg.setColor( QColorGroup::Foreground, Qt::cyan );
151 activeCg.setColor( QColorGroup::Text, Qt::cyan );
152 activeCg.setColor( QColorGroup::Base, dark );
153 activeCg.setColor( QColorGroup::Button, dark );
154 activeCg.setColor( QColorGroup::ButtonText, Qt::green );
155 activeCg.setColor( QColorGroup::Highlight, Qt::yellow );
156 activeCg.setColor( QColorGroup::HighlightedText, Qt::black );
158 QColorGroup inactiveCg; // for other windows (those that don't have the keyboard focus)
160 inactiveCg.setColor( QColorGroup::Background, Qt::black );
161 inactiveCg.setColor( QColorGroup::Foreground, Qt::cyan );
162 inactiveCg.setColor( QColorGroup::Text, Qt::cyan );
163 inactiveCg.setColor( QColorGroup::Base, dark );
164 inactiveCg.setColor( QColorGroup::Button, dark );
165 inactiveCg.setColor( QColorGroup::ButtonText, Qt::green );
167 QColorGroup disabledCg; // for disabled widgets
169 disabledCg.setColor( QColorGroup::Background, Qt::black );
170 disabledCg.setColor( QColorGroup::Foreground, Qt::gray );
171 disabledCg.setColor( QColorGroup::Text, Qt::gray );
172 disabledCg.setColor( QColorGroup::Base, dark );
173 disabledCg.setColor( QColorGroup::Button, dark );
174 disabledCg.setColor( QColorGroup::ButtonText, Qt::gray );
176 QPalette pal( activeCg, disabledCg, inactiveCg );
184 sendEvent( new YCancelEvent() );
189 bool YQUI::eventFilter( QObject * obj, QEvent * ev )
191 if ( ev->type() == QEvent::Close )
193 // Handle WM_CLOSE - but only if it comes from a dialog that is managed by the UI,
194 // not from an independent Qt dialog (such as the package selector popups)
196 QWidget * objDialog = 0;
198 if ( obj && obj->isWidgetType() )
200 objDialog = (QWidget *) obj;
201 objDialog = objDialog->topLevelWidget();
205 ( objDialog == mainWidget() ||
206 objDialog == (QObject *) YDialog::currentDialog()->widgetRep() ) )
210 if ( ! _wm_close_blocked )
212 // Don't simply close the application window, return from UserInput()
213 // with `id(`cancel) and let the YCP application decide how to handle
214 // that (e.g., ask for confirmation).
216 y2debug( "Caught window close event - returning with `cancel" );
217 sendEvent( new YCancelEvent() );
220 return true; // Event processed
223 else if ( ev->type() == QEvent::Show )
225 if ( obj == _main_win )
227 #ifdef FIXME_PROBABLY_OBSOLETE
228 if ( _widget_stack->count() > 0 )
230 // Work around QWidgetStack bug: The last raiseWidget() call
231 // (from closeDialog() ) might have failed if the widget was
232 // invisible at that time, e.g., because the user had switched to
233 // some other virtual desktop (bugzilla bug #11310)
235 _widget_stack->setCurrentWidget( whatever );
241 return showEventFilter( obj, ev );
244 return QObject::eventFilter( obj, ev );
248 bool YQUI::showEventFilter( QObject * obj, QEvent * ev )
252 // Make sure newly opened windows get the keyboard focus even without a
253 // window manager. Otherwise the app might be unusable without a mouse.
255 QWidget * widget = dynamic_cast<QWidget *> (obj);
258 widget->setActiveWindow();
261 return false; // Don't stop event processing
266 * UI-specific conversion from logical layout spacing units (80x25)
267 * to device dependent units (640x480).
269 int YQUI::deviceUnits( YUIDimension dim, float size )
271 if ( dim==YD_HORIZ ) size *= ( 640.0/80 );
272 else size *= ( 480.0/25 );
274 return (int) ( size + 0.5 );
279 * Default conversion from device dependent layout spacing units (640x480)
280 * to logical layout units (80x25).
282 * This default function assumes 80x25 units.
283 * Derived UIs may want to reimplement this.
285 float YQUI::layoutUnits( YUIDimension dim, int device_units )
287 float size = (float) device_units;
289 if ( dim==YD_HORIZ ) size *= ( 80/640.0 );
290 else size *= ( 25/480.0 );
296 void YQUI::maybeLeftHandedUser()
298 if ( _askedForLeftHandedMouse )
303 _( "You clicked the right mouse button "
304 "where a left-click was expected."
306 "Switch left and right mouse buttons?"
308 int button = QMessageBox::question( 0,
309 // Popup dialog caption
310 _( "Unexpected Click" ),
312 QMessageBox::Yes | QMessageBox::Default,
314 QMessageBox::Cancel | QMessageBox::Escape );
316 if ( button == QMessageBox::Yes )
319 const char * command =
321 "xmodmap -e \"pointer = 1 2 3\"": // switch back to right-handed mouse
322 "xmodmap -e \"pointer = 3 2 1\""; // switch to left-handed mouse
324 _leftHandedMouse = ! _leftHandedMouse; // might be set repeatedly!
325 _askedForLeftHandedMouse = false; // give the user a chance to switch back
326 y2milestone( "Switching mouse buttons: %s", command );
330 else if ( button == 1 ) // No
332 _askedForLeftHandedMouse = true;