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 <QColorGroup>
32 #include <QtGui/qdesktopwidget.h>
35 #define y2log_component "qt-ui"
36 #include <ycp/y2log.h>
41 #include "QY2Settings.h"
44 // Include low-level X headers AFTER Qt headers:
45 // X.h pollutes the global namespace (!!!) with pretty useless #defines
46 // like "Above", "Below" etc. that clash with some Qt headers.
50 int YQUI::getDisplayWidth()
52 return qApp->desktop()->width();
56 int YQUI::getDisplayHeight()
58 return qApp->desktop()->height();
62 int YQUI::getDisplayDepth()
64 return qApp->desktop()->depth();
68 long YQUI::getDisplayColors()
70 return 1L << qApp->desktop()->depth();
74 int YQUI::getDefaultWidth()
76 return _default_size.width();
80 int YQUI::getDefaultHeight()
82 return _default_size.height();
86 int YQUI::defaultSize(YUIDimension dim) const
89 return dim == YD_HORIZ ? _default_size.width() : _default_size.height();
91 return dim == YD_HORIZ ? qApp->desktop()->width() : qApp->desktop()->height();
95 QWidget* YQUI::mainWidget()
108 YQUI::busyCursor( void )
110 qApp->setOverrideCursor( Qt::BusyCursor );
115 YQUI::normalCursor( void )
117 if ( _busy_cursor_timer->isActive() )
118 _busy_cursor_timer->stop();
120 while ( qApp->overrideCursor() )
121 qApp->restoreOverrideCursor();
125 void YQUI::toggleVisionImpairedPalette()
127 if ( _usingVisionImpairedPalette )
129 qApp->setPalette( normalPalette(),
130 true ); // informWidgets
132 _usingVisionImpairedPalette = false;
136 qApp->setPalette( visionImpairedPalette(),
137 true ); // informWidgets
139 _usingVisionImpairedPalette = true;
144 QPalette YQUI::visionImpairedPalette()
146 const QColor dark ( 0x20, 0x20, 0x20 );
148 QColorGroup activeCg; // for the active window (the one with the keyboard focus)
150 activeCg.setColor( QColorGroup::Background, Qt::black );
151 activeCg.setColor( QColorGroup::Foreground, Qt::cyan );
152 activeCg.setColor( QColorGroup::Text, Qt::cyan );
153 activeCg.setColor( QColorGroup::Base, dark );
154 activeCg.setColor( QColorGroup::Button, dark );
155 activeCg.setColor( QColorGroup::ButtonText, Qt::green );
156 activeCg.setColor( QColorGroup::Highlight, Qt::yellow );
157 activeCg.setColor( QColorGroup::HighlightedText, Qt::black );
159 QColorGroup inactiveCg; // for other windows (those that don't have the keyboard focus)
161 inactiveCg.setColor( QColorGroup::Background, Qt::black );
162 inactiveCg.setColor( QColorGroup::Foreground, Qt::cyan );
163 inactiveCg.setColor( QColorGroup::Text, Qt::cyan );
164 inactiveCg.setColor( QColorGroup::Base, dark );
165 inactiveCg.setColor( QColorGroup::Button, dark );
166 inactiveCg.setColor( QColorGroup::ButtonText, Qt::green );
168 QColorGroup disabledCg; // for disabled widgets
170 disabledCg.setColor( QColorGroup::Background, Qt::black );
171 disabledCg.setColor( QColorGroup::Foreground, Qt::gray );
172 disabledCg.setColor( QColorGroup::Text, Qt::gray );
173 disabledCg.setColor( QColorGroup::Base, dark );
174 disabledCg.setColor( QColorGroup::Button, dark );
175 disabledCg.setColor( QColorGroup::ButtonText, Qt::gray );
177 QPalette pal( activeCg, disabledCg, inactiveCg );
185 sendEvent( new YCancelEvent() );
190 bool YQUI::eventFilter( QObject * obj, QEvent * ev )
192 if ( ev->type() == QEvent::Close )
194 // Handle WM_CLOSE - but only if it comes from a dialog that is managed by the UI,
195 // not from an independent Qt dialog (such as the package selector popups)
197 QWidget * objDialog = 0;
199 if ( obj && obj->isWidgetType() )
201 objDialog = (QWidget *) obj;
202 objDialog = objDialog->topLevelWidget();
206 ( objDialog == mainWidget() ||
207 objDialog == (QObject *) YDialog::currentDialog()->widgetRep() ) )
211 if ( ! _wm_close_blocked )
213 // Don't simply close the application window, return from UserInput()
214 // with `id(`cancel) and let the YCP application decide how to handle
215 // that (e.g., ask for confirmation).
217 y2debug( "Caught window close event - returning with `cancel" );
218 sendEvent( new YCancelEvent() );
221 return true; // Event processed
224 else if ( ev->type() == QEvent::Show )
226 if ( obj == _main_win )
228 #ifdef FIXME_PROBABLY_OBSOLETE
229 if ( _widget_stack->count() > 0 )
231 // Work around QWidgetStack bug: The last raiseWidget() call
232 // (from closeDialog() ) might have failed if the widget was
233 // invisible at that time, e.g., because the user had switched to
234 // some other virtual desktop (bugzilla bug #11310)
236 _widget_stack->setCurrentWidget( whatever );
242 return showEventFilter( obj, ev );
245 return QObject::eventFilter( obj, ev );
249 bool YQUI::showEventFilter( QObject * obj, QEvent * ev )
253 // Make sure newly opened windows get the keyboard focus even without a
254 // window manager. Otherwise the app might be unusable without a mouse.
256 QWidget * widget = dynamic_cast<QWidget *> (obj);
259 widget->setActiveWindow();
262 return false; // Don't stop event processing
267 * UI-specific conversion from logical layout spacing units (80x25)
268 * to device dependent units (640x480).
270 int YQUI::deviceUnits( YUIDimension dim, float size )
272 if ( dim==YD_HORIZ ) size *= ( 640.0/80 );
273 else size *= ( 480.0/25 );
275 return (int) ( size + 0.5 );
280 * Default conversion from device dependent layout spacing units (640x480)
281 * to logical layout units (80x25).
283 * This default function assumes 80x25 units.
284 * Derived UIs may want to reimplement this.
286 float YQUI::layoutUnits( YUIDimension dim, int device_units )
288 float size = (float) device_units;
290 if ( dim==YD_HORIZ ) size *= ( 80/640.0 );
291 else size *= ( 25/480.0 );
297 void YQUI::maybeLeftHandedUser()
299 if ( _askedForLeftHandedMouse )
304 _( "You clicked the right mouse button "
305 "where a left-click was expected."
307 "Switch left and right mouse buttons?"
309 int button = QMessageBox::question( 0,
310 // Popup dialog caption
311 _( "Unexpected Click" ),
313 QMessageBox::Yes | QMessageBox::Default,
315 QMessageBox::Cancel | QMessageBox::Escape );
317 if ( button == QMessageBox::Yes )
320 const char * command =
322 "xmodmap -e \"pointer = 1 2 3\"": // switch back to right-handed mouse
323 "xmodmap -e \"pointer = 3 2 1\""; // switch to left-handed mouse
325 _leftHandedMouse = ! _leftHandedMouse; // might be set repeatedly!
326 _askedForLeftHandedMouse = false; // give the user a chance to switch back
327 y2milestone( "Switching mouse buttons: %s", command );
331 else if ( button == 1 ) // No
333 _askedForLeftHandedMouse = true;