libyui-qt
2.43.5
|
00001 /* 00002 Copyright (C) 2000-2012 Novell, Inc 00003 This library is free software; you can redistribute it and/or modify 00004 it under the terms of the GNU Lesser General Public License as 00005 published by the Free Software Foundation; either version 2.1 of the 00006 License, or (at your option) version 3.0 of the License. This library 00007 is distributed in the hope that it will be useful, but WITHOUT ANY 00008 WARRANTY; without even the implied warranty of MERCHANTABILITY or 00009 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 00010 License for more details. You should have received a copy of the GNU 00011 Lesser General Public License along with this library; if not, write 00012 to the Free Software Foundation, Inc., 51 Franklin Street, Fifth 00013 Floor, Boston, MA 02110-1301 USA 00014 */ 00015 00016 00017 /*-/ 00018 00019 File: YQDialog.cc 00020 00021 Author: Stefan Hundhammer <sh@suse.de> 00022 00023 Textdomain "qt" 00024 00025 /-*/ 00026 00027 00028 #define YUILogComponent "qt-ui" 00029 #include <yui/YUILog.h> 00030 #include <qpushbutton.h> 00031 #include <qmessagebox.h> 00032 #include <QDesktopWidget> 00033 #include <QDebug> 00034 00035 #include "YQUI.h" 00036 #include "YQi18n.h" 00037 #include <yui/YEvent.h> 00038 #include "YQDialog.h" 00039 #include "YQGenericButton.h" 00040 #include "YQWizardButton.h" 00041 #include "YQWizard.h" 00042 #include "YQMainWinDock.h" 00043 #include <yui/YDialogSpy.h> 00044 #include <YApplication.h> 00045 #include "QY2Styler.h" 00046 #include "QY2StyleEditor.h" 00047 00048 // Include low-level X headers AFTER Qt headers: 00049 // X.h pollutes the global namespace (!!!) with pretty useless #defines 00050 // like "Above", "Below" etc. that clash with some Qt headers. 00051 #include <X11/Xlib.h> 00052 00053 #define YQMainDialogWFlags Qt::Widget 00054 #define YQPopupDialogWFlags Qt::Dialog 00055 00056 #define VERBOSE_EVENT_LOOP 0 00057 00058 00059 00060 YQDialog::YQDialog( YDialogType dialogType, 00061 YDialogColorMode colorMode ) 00062 : QWidget( chooseParent( dialogType ), 00063 dialogType == YPopupDialog ? YQPopupDialogWFlags : YQMainDialogWFlags ) 00064 , YDialog( dialogType, colorMode ) 00065 { 00066 setWidgetRep( this ); 00067 00068 _userResized = false; 00069 _focusButton = 0; 00070 _defaultButton = 0; 00071 _highlightedChild = 0; 00072 _styleEditor = 0; 00073 00074 setFocusPolicy( Qt::StrongFocus ); 00075 setAutoFillBackground( true ); 00076 00077 if ( colorMode != YDialogNormalColor ) 00078 { 00079 QColor normalBackground ( 240, 100, 36 ); 00080 QColor inputFieldBackground ( 0xbb, 0xff, 0xbb ); 00081 QColor text = Qt::black; 00082 00083 if ( colorMode == YDialogInfoColor ) 00084 { 00085 normalBackground = QColor ( 238, 232, 170 ); // PaleGoldenrod 00086 } 00087 00088 QPalette warnPalette( normalBackground ); 00089 warnPalette.setColor( QPalette::Text, text ); 00090 warnPalette.setColor( QPalette::Base, inputFieldBackground ); 00091 setPalette( warnPalette ); 00092 } 00093 qApp->setApplicationName(YQUI::ui()->applicationTitle()); 00094 topLevelWidget()->setWindowTitle ( YQUI::ui()->applicationTitle() ); 00095 00096 if ( isMainDialog() && QWidget::parent() != YQMainWinDock::mainWinDock() ) 00097 { 00098 setWindowFlags( YQPopupDialogWFlags ); 00099 } 00100 00101 if ( ! isMainDialog() ) 00102 setWindowModality( Qt::ApplicationModal ); 00103 00104 if ( isMainDialog() && QWidget::parent() == YQMainWinDock::mainWinDock() ) 00105 { 00106 YQMainWinDock::mainWinDock()->add( this ); 00107 } 00108 00109 _eventLoop = new QEventLoop( this ); 00110 YUI_CHECK_NEW( _eventLoop ); 00111 00112 _waitForEventTimer = new QTimer( this ); 00113 YUI_CHECK_NEW( _waitForEventTimer ); 00114 _waitForEventTimer->setSingleShot( true ); 00115 00116 QObject::connect( _waitForEventTimer, SIGNAL( timeout() ), 00117 this, SLOT ( waitForEventTimeout() ) ); 00118 00119 QY2Styler::styler()->registerWidget( this ); 00120 } 00121 00122 00123 YQDialog::~YQDialog() 00124 { 00125 if ( isMainDialog() ) 00126 { 00127 YQMainWinDock::mainWinDock()->remove( this ); 00128 // orphaned main dialogs are handled gracefully in YQWMainWinDock::remove() 00129 } 00130 00131 if ( _defaultButton ) 00132 _defaultButton->forgetDialog(); 00133 00134 if ( _focusButton ) 00135 _focusButton->forgetDialog(); 00136 00137 if ( _styleEditor ) 00138 delete _styleEditor; 00139 00140 QY2Styler::styler()->unregisterWidget( this ); 00141 } 00142 00143 00144 QWidget * 00145 YQDialog::chooseParent( YDialogType dialogType ) 00146 { 00147 QWidget * parent = YQMainWinDock::mainWinDock()->window(); 00148 00149 if ( dialogType == YPopupDialog) 00150 { 00151 YDialog * currentDialog = YDialog::currentDialog( false ); 00152 if (currentDialog) 00153 parent = (QWidget *) currentDialog->widgetRep(); 00154 } 00155 00156 if ( ( dialogType == YMainDialog || dialogType == YWizardDialog ) && 00157 YQMainWinDock::mainWinDock()->couldDock() ) 00158 { 00159 yuiDebug() << "Adding dialog to mainWinDock" << std::endl; 00160 parent = YQMainWinDock::mainWinDock(); 00161 } 00162 00163 return parent; 00164 } 00165 00166 00167 void 00168 YQDialog::openInternal() 00169 { 00170 ensureOnlyOneDefaultButton(); 00171 QWidget::show(); 00172 QWidget::raise(); // FIXME: is this really necessary? 00173 QWidget::update(); 00174 } 00175 00176 00177 void 00178 YQDialog::activate() 00179 { 00180 QWidget::raise(); 00181 QWidget::update(); 00182 } 00183 00184 00185 int 00186 YQDialog::preferredWidth() 00187 { 00188 int preferredWidth; 00189 00190 if ( isMainDialog() ) 00191 { 00192 if ( userResized() ) 00193 preferredWidth = _userSize.width(); 00194 else 00195 preferredWidth = YQUI::ui()->defaultSize( YD_HORIZ ); 00196 } 00197 else 00198 { 00199 preferredWidth = YDialog::preferredWidth(); 00200 } 00201 00202 int screenWidth = qApp->desktop()->width(); 00203 00204 if ( preferredWidth > screenWidth ) 00205 { 00206 yuiWarning() << "Limiting dialog width to screen width (" << screenWidth 00207 << ") instead of " << preferredWidth 00208 << " - check the layout!" 00209 << std::endl; 00210 } 00211 00212 return preferredWidth; 00213 } 00214 00215 00216 int 00217 YQDialog::preferredHeight() 00218 { 00219 int preferredHeight; 00220 00221 if ( isMainDialog() ) 00222 { 00223 if ( userResized() ) 00224 preferredHeight = _userSize.height(); 00225 else 00226 preferredHeight = YQUI::ui()->defaultSize( YD_VERT ); 00227 } 00228 else 00229 { 00230 preferredHeight = YDialog::preferredHeight(); 00231 } 00232 00233 int screenHeight = qApp->desktop()->height(); 00234 00235 if ( preferredHeight > screenHeight ) 00236 { 00237 yuiWarning() << "Limiting dialog height to screen height (" << screenHeight 00238 << ") instead of " << preferredHeight 00239 << " - check the layout!" 00240 << std::endl; 00241 } 00242 00243 return preferredHeight; 00244 } 00245 00246 00247 void 00248 YQDialog::setEnabled( bool enabled ) 00249 { 00250 QWidget::setEnabled( enabled ); 00251 YDialog::setEnabled( enabled ); 00252 } 00253 00254 00255 void 00256 YQDialog::setSize( int newWidth, int newHeight ) 00257 { 00258 // yuiDebug() << "Resizing dialog to " << newWidth << " x " << newHeight << std::endl; 00259 00260 if ( newWidth > qApp->desktop()->width() ) 00261 newWidth = qApp->desktop()->width(); 00262 00263 if ( newHeight > qApp->desktop()->height() ) 00264 newHeight = qApp->desktop()->height(); 00265 00266 resize( newWidth, newHeight ); 00267 00268 if ( hasChildren() ) 00269 { 00270 firstChild()->setSize( newWidth, newHeight ); 00271 ( ( QWidget* )firstChild()->widgetRep() )->show(); 00272 } 00273 } 00274 00275 00276 void 00277 YQDialog::resizeEvent( QResizeEvent * event ) 00278 { 00279 if ( event ) 00280 { 00281 // yuiDebug() << "Resize event: " << event->size().width() << " x " << event->size().height() << std::endl; 00282 setSize ( event->size().width(), event->size().height() ); 00283 _userSize = event->size(); 00284 00285 if ( QWidget::parent() ) 00286 _userResized = true; 00287 } 00288 } 00289 00290 00291 YQGenericButton * 00292 YQDialog::findDefaultButton() 00293 { 00294 if ( _defaultButton ) 00295 return _defaultButton; 00296 00297 _defaultButton = findDefaultButton( childrenBegin(), childrenEnd() ); 00298 00299 YDialog::setDefaultButton( 0 ); // prevent complaints about multiple default buttons 00300 YDialog::setDefaultButton( _defaultButton ); 00301 00302 return _defaultButton; 00303 } 00304 00305 00306 YQGenericButton * 00307 YQDialog::findDefaultButton( YWidgetListConstIterator begin, 00308 YWidgetListConstIterator end ) const 00309 { 00310 for ( YWidgetListConstIterator it = begin; it != end; ++it ) 00311 { 00312 YWidget * widget = *it; 00313 00314 // 00315 // Check this widget 00316 // 00317 00318 YQGenericButton * button = dynamic_cast<YQGenericButton *> (widget); 00319 00320 if ( button && button->isDefaultButton() ) 00321 { 00322 return button; 00323 } 00324 00325 00326 // 00327 // Recurse over the children of this widget 00328 // 00329 00330 if ( widget->hasChildren() ) 00331 { 00332 button = findDefaultButton( widget->childrenBegin(), 00333 widget->childrenEnd() ); 00334 if ( button ) 00335 return button; 00336 } 00337 } 00338 00339 return 0; 00340 } 00341 00342 00343 YQWizard * 00344 YQDialog::ensureOnlyOneDefaultButton( YWidgetListConstIterator begin, 00345 YWidgetListConstIterator end ) 00346 { 00347 YQGenericButton * def = _focusButton ? _focusButton : _defaultButton; 00348 YQWizard * wizard = 0; 00349 00350 for ( YWidgetListConstIterator it = begin; it != end; ++it ) 00351 { 00352 YQGenericButton * button = dynamic_cast<YQGenericButton *> (*it); 00353 YQWizardButton * wizardButton = dynamic_cast<YQWizardButton * > (*it); 00354 00355 if ( ! wizard ) 00356 wizard = dynamic_cast<YQWizard *> (*it); 00357 00358 if ( wizardButton ) 00359 { 00360 wizardButton->showAsDefault( false ); 00361 } 00362 else if ( button ) 00363 { 00364 if ( button->isDefaultButton() ) 00365 { 00366 if ( _defaultButton && button != _defaultButton ) 00367 { 00368 yuiError() << "Too many default buttons: " << button << std::endl; 00369 yuiError() << "Using old default button: " << _defaultButton << std::endl; 00370 } 00371 else 00372 { 00373 _defaultButton = button; 00374 } 00375 } 00376 00377 if ( button->isShownAsDefault() && button != def ) 00378 button->showAsDefault( false ); 00379 } 00380 00381 if ( (*it)->hasChildren() ) 00382 { 00383 YQWizard * wiz = ensureOnlyOneDefaultButton( (*it)->childrenBegin(), 00384 (*it)->childrenEnd() ); 00385 if ( wiz ) 00386 wizard = wiz; 00387 } 00388 } 00389 00390 return wizard; 00391 } 00392 00393 00394 void 00395 YQDialog::ensureOnlyOneDefaultButton() 00396 { 00397 _defaultButton = 0; 00398 YQWizard * wizard = ensureOnlyOneDefaultButton( childrenBegin(), childrenEnd() ); 00399 00400 if ( ! _defaultButton && wizard ) 00401 { 00402 _defaultButton = wizardDefaultButton( wizard ); 00403 } 00404 00405 if ( _defaultButton ) 00406 { 00407 YDialog::setDefaultButton( 0 ); // prevent complaints about multiple default buttons 00408 YDialog::setDefaultButton( _defaultButton ); 00409 } 00410 00411 00412 YQGenericButton * def = _focusButton ? _focusButton : _defaultButton; 00413 00414 if ( def ) 00415 def->showAsDefault(); 00416 } 00417 00418 00419 YQWizard * 00420 YQDialog::findWizard() const 00421 { 00422 return findWizard( childrenBegin(), childrenEnd() ); 00423 } 00424 00425 00426 YQWizard * 00427 YQDialog::findWizard( YWidgetListConstIterator begin, 00428 YWidgetListConstIterator end ) const 00429 { 00430 for ( YWidgetListConstIterator it = begin; it != end; ++it ) 00431 { 00432 YWidget * widget = *it; 00433 YQWizard * wizard = dynamic_cast<YQWizard *> (widget); 00434 00435 if ( wizard ) 00436 return wizard; 00437 00438 if ( widget->hasChildren() ) 00439 { 00440 wizard = findWizard( widget->childrenBegin(), 00441 widget->childrenEnd() ); 00442 if ( wizard ) 00443 return wizard; 00444 } 00445 } 00446 00447 return 0; 00448 } 00449 00450 00451 YQGenericButton * 00452 YQDialog::wizardDefaultButton( YQWizard * wizard ) const 00453 { 00454 YQGenericButton * def = 0; 00455 00456 if ( ! wizard ) 00457 wizard = findWizard(); 00458 00459 if ( wizard ) 00460 { 00461 // Pick one of the wizard buttons 00462 00463 if ( wizard->direction() == YQWizard::Backward ) 00464 { 00465 if ( wizard->backButton() 00466 && wizard->backButton()->isShown() 00467 && wizard->backButton()->isEnabled() ) 00468 { 00469 def = wizard->backButton(); 00470 } 00471 } 00472 00473 if ( ! def ) 00474 { 00475 if ( wizard->nextButton() 00476 && wizard->nextButton()->isShown() 00477 && wizard->nextButton()->isEnabled() ) 00478 { 00479 def = wizard->nextButton(); 00480 } 00481 } 00482 } 00483 00484 return def; 00485 } 00486 00487 00488 void 00489 YQDialog::setDefaultButton( YPushButton * newDefaultButton ) 00490 { 00491 if ( _defaultButton && 00492 newDefaultButton && 00493 newDefaultButton != _defaultButton ) 00494 { 00495 if ( dynamic_cast<YQWizardButton *>( _defaultButton ) ) 00496 { 00497 // Let app defined default buttons override wizard buttons 00498 _defaultButton->setDefaultButton( false ); 00499 } 00500 else 00501 { 00502 yuiError() << "Too many `opt(`default) PushButtons: " << newDefaultButton << std::endl; 00503 newDefaultButton->setDefaultButton( false ); 00504 return; 00505 } 00506 } 00507 00508 _defaultButton = dynamic_cast<YQGenericButton*>(newDefaultButton); 00509 00510 if ( _defaultButton ) 00511 { 00512 _defaultButton->setDefaultButton( true ); 00513 yuiDebug() << "New default button: " << _defaultButton << std::endl; 00514 00515 if ( _defaultButton && ! _focusButton ) 00516 { 00517 _defaultButton->showAsDefault( true ); 00518 _defaultButton->setKeyboardFocus(); 00519 } 00520 } 00521 00522 00523 YDialog::setDefaultButton( 0 ); // prevent complaints about multiple default buttons 00524 YDialog::setDefaultButton( _defaultButton ); 00525 } 00526 00527 00528 bool 00529 YQDialog::activateDefaultButton( bool warn ) 00530 { 00531 // Try the focus button first, if there is any. 00532 00533 if ( _focusButton && 00534 _focusButton->isEnabled() && 00535 _focusButton->isShownAsDefault() ) 00536 { 00537 yuiDebug() << "Activating focus button: " << _focusButton << std::endl; 00538 _focusButton->activate(); 00539 return true; 00540 } 00541 00542 00543 // No focus button - try the default button, if there is any. 00544 00545 _defaultButton = findDefaultButton(); 00546 00547 if ( _defaultButton && 00548 _defaultButton->isEnabled() && 00549 _defaultButton->isShownAsDefault() ) 00550 { 00551 yuiDebug() << "Activating default button: " << _defaultButton << std::endl; 00552 _defaultButton->activate(); 00553 return true; 00554 } 00555 else 00556 { 00557 if ( warn ) 00558 { 00559 yuiWarning() << "No default button in this dialog - ignoring [Return]" << std::endl; 00560 } 00561 } 00562 00563 return false; 00564 } 00565 00566 00567 void 00568 YQDialog::losingFocus( YQGenericButton * button ) 00569 { 00570 if ( button == _focusButton ) 00571 { 00572 if ( _focusButton && _focusButton != _defaultButton ) 00573 _focusButton->showAsDefault( false ); 00574 00575 _focusButton = 0; 00576 } 00577 00578 if ( ! _focusButton && _defaultButton ) 00579 _defaultButton->showAsDefault( true ); 00580 } 00581 00582 00583 void 00584 YQDialog::gettingFocus( YQGenericButton * button ) 00585 { 00586 if ( _focusButton && _focusButton != button ) 00587 _focusButton->showAsDefault( false ); 00588 00589 if ( _defaultButton && _defaultButton != button ) 00590 _defaultButton->showAsDefault( false ); 00591 00592 _focusButton = button; 00593 00594 if ( _focusButton ) 00595 _focusButton->showAsDefault( true ); 00596 } 00597 00598 00599 void 00600 YQDialog::keyPressEvent( QKeyEvent * event ) 00601 { 00602 if ( event ) 00603 { 00604 if ( event->key() == Qt::Key_Print ) 00605 { 00606 YQUI::ui()->makeScreenShot( "" ); 00607 return; 00608 } 00609 else if ( event->key() == Qt::Key_F4 && // Shift-F4: toggle colors for vision impaired users 00610 event->modifiers() == Qt::ShiftModifier ) 00611 { 00612 YQUI::ui()->toggleVisionImpairedPalette(); 00613 00614 if ( YQUI::ui()->usingVisionImpairedPalette() ) 00615 { 00616 QWidget* parent = 0; 00617 YDialog * currentDialog = YDialog::currentDialog( false ); 00618 if (currentDialog) 00619 parent = (QWidget *) currentDialog->widgetRep(); 00620 00621 yuiMilestone() << "Switched to vision impaired palette" << std::endl; 00622 QMessageBox::information( parent, // parent 00623 _("Color switching"), // caption 00624 _( "Switching to color palette for vision impaired users -\n" 00625 "press Shift-F4 again to switch back to normal colors." ), // text 00626 QMessageBox::Ok | QMessageBox::Default, // button0 00627 QMessageBox::NoButton, // button1 00628 QMessageBox::NoButton ); // button2 00629 } 00630 return; 00631 } 00632 else if ( event->key() == Qt::Key_F7 && // Shift-F7: toggle debug logging 00633 event->modifiers() == Qt::ShiftModifier ) 00634 { 00635 YQUI::ui()->askConfigureLogging(); 00636 return; 00637 } 00638 else if ( event->key() == Qt::Key_F8 && // Shift-F8: save y2logs 00639 event->modifiers() == Qt::ShiftModifier ) 00640 { 00641 YQUI::ui()->askSaveLogs(); 00642 return; 00643 } 00644 else if ( event->modifiers() == Qt::NoModifier ) // No Ctrl / Alt / Shift etc. pressed 00645 { 00646 if ( event->key() == Qt::Key_Return || 00647 event->key() == Qt::Key_Enter ) 00648 { 00649 (void) activateDefaultButton(); 00650 return; 00651 } 00652 } 00653 else if ( event->modifiers() == ( Qt::ControlModifier | Qt::ShiftModifier | Qt::AltModifier ) ) 00654 { 00655 // Qt-UI special keys - all with Ctrl-Shift-Alt 00656 00657 yuiMilestone() << "Caught YaST2 magic key combination" << std::endl; 00658 00659 if ( event->key() == Qt::Key_M ) 00660 { 00661 YQUI::ui()->toggleRecordMacro(); 00662 return; 00663 } 00664 else if ( event->key() == Qt::Key_P ) 00665 { 00666 YQUI::ui()->askPlayMacro(); 00667 return; 00668 } 00669 else if ( event->key() == Qt::Key_D ) 00670 { 00671 YQUI::ui()->sendEvent( new YDebugEvent() ); 00672 return; 00673 } 00674 else if ( event->key() == Qt::Key_T ) 00675 { 00676 yuiMilestone() << "*** Dumping widget tree ***" << std::endl; 00677 dumpWidgetTree(); 00678 yuiMilestone() << "*** Widget tree end ***" << std::endl; 00679 return; 00680 } 00681 else if ( event->key() == Qt::Key_Y ) 00682 { 00683 yuiMilestone() << "Opening dialog spy" << std::endl; 00684 YDialogSpy::showDialogSpy(); 00685 YQUI::ui()->normalCursor(); 00686 } 00687 else if ( event->key() == Qt::Key_X ) 00688 { 00689 int result; 00690 yuiMilestone() << "Starting xterm" << std::endl; 00691 result = system( "/usr/bin/xterm &" ); 00692 if (result < 0) 00693 yuiError() << "/usr/bin/xterm not found" << std::endl; 00694 return; 00695 } 00696 else if ( event->key() == Qt::Key_S ) 00697 { 00698 yuiMilestone() << "Opening style editor" << std::endl; 00699 _styleEditor = new QY2StyleEditor(this); 00700 _styleEditor->show(); 00701 _styleEditor->raise(); 00702 _styleEditor->activateWindow(); 00703 return; 00704 } 00705 00706 } 00707 } 00708 00709 QWidget::keyPressEvent( event ); 00710 } 00711 00712 00713 void 00714 YQDialog::closeEvent( QCloseEvent * event ) 00715 { 00716 // The window manager "close window" button (and WM menu, e.g. Alt-F4) will be 00717 // handled just like the user had clicked on the `id`( `cancel ) button in 00718 // that dialog. It's up to the YCP application to handle this (if desired). 00719 00720 yuiMilestone() << "Caught window manager close event - returning with YCancelEvent" << std::endl; 00721 event->ignore(); 00722 YQUI::ui()->sendEvent( new YCancelEvent() ); 00723 } 00724 00725 00726 void 00727 YQDialog::focusInEvent( QFocusEvent * event ) 00728 { 00729 // The dialog itself doesn't need or want the keyboard focus, but obviously 00730 // (since Qt 2.3?) it needs QFocusPolicy::StrongFocus for the default 00731 // button mechanism to work. So let's accept the focus and give it to some 00732 // child widget. 00733 00734 if ( event->reason() == Qt::TabFocusReason ) 00735 { 00736 focusNextPrevChild( true ); 00737 } 00738 else 00739 { 00740 if ( _defaultButton ) 00741 _defaultButton->setKeyboardFocus(); 00742 else 00743 focusNextPrevChild( true ); 00744 } 00745 } 00746 00747 00748 YEvent * 00749 YQDialog::waitForEventInternal( int timeout_millisec ) 00750 { 00751 YQUI::ui()->forceUnblockEvents(); 00752 _eventLoop->wakeUp(); 00753 00754 YEvent * event = 0; 00755 00756 _waitForEventTimer->stop(); 00757 00758 if ( timeout_millisec > 0 ) 00759 _waitForEventTimer->start( timeout_millisec ); // single shot 00760 00761 if ( qApp->focusWidget() ) 00762 qApp->focusWidget()->setFocus(); 00763 00764 YQUI::ui()->normalCursor(); 00765 00766 if ( ! _eventLoop->isRunning() ) 00767 { 00768 #if VERBOSE_EVENT_LOOP 00769 yuiDebug() << "Executing event loop for " << this << std::endl; 00770 #endif 00771 _eventLoop->exec(); 00772 00773 #if VERBOSE_EVENT_LOOP 00774 yuiDebug() << "Event loop finished for " << this << std::endl; 00775 #endif 00776 } 00777 else 00778 { 00779 #if VERBOSE_EVENT_LOOP 00780 yuiDebug() << "Event loop still running for " << this << std::endl; 00781 #endif 00782 } 00783 00784 _waitForEventTimer->stop(); 00785 event = YQUI::ui()->consumePendingEvent(); 00786 00787 00788 // Prepare a busy cursor if the UI cannot respond to user input within the 00789 // next 200 milliseconds (if the application doesn't call waitForEvent() 00790 // within this time again) 00791 00792 YQUI::ui()->timeoutBusyCursor(); 00793 00794 return event; 00795 } 00796 00797 00798 YEvent * 00799 YQDialog::pollEventInternal() 00800 { 00801 YEvent * event = 0; 00802 00803 _waitForEventTimer->stop(); // just in case it's still running 00804 00805 if ( ! YQUI::ui()->pendingEvent() ) 00806 { 00807 // Very short (10 millisec) event loop 00808 _eventLoop->processEvents( QEventLoop::AllEvents, 10 ); 00809 } 00810 00811 if ( YQUI::ui()->pendingEvent() ) 00812 event = YQUI::ui()->consumePendingEvent(); 00813 00814 return event; 00815 } 00816 00817 00818 void 00819 YQDialog::waitForEventTimeout() 00820 { 00821 if ( ! YQUI::ui()->pendingEvent() ) 00822 { 00823 // Don't override a pending event with a timeout event 00824 00825 YQUI::ui()->sendEvent( new YTimeoutEvent() ); 00826 } 00827 } 00828 00829 00830 void 00831 YQDialog::center( QWidget * dialog, QWidget * parent ) 00832 { 00833 if ( ! dialog || ! parent ) 00834 return; 00835 00836 QPoint pos( ( parent->width() - dialog->width() ) / 2, 00837 ( parent->height() - dialog->height() ) / 2 ); 00838 00839 pos += parent->mapToGlobal( QPoint( 0, 0 ) ); 00840 pos = dialog->mapToParent( dialog->mapFromGlobal( pos ) ); 00841 qDebug() << pos; 00842 dialog->move( pos ); 00843 } 00844 00845 00846 void 00847 YQDialog::highlight( YWidget * child ) 00848 { 00849 if ( _highlightedChild && _highlightedChild->isValid() ) 00850 { 00851 // Un-highlight old highlighted child widget 00852 00853 QWidget * qw = (QWidget *) _highlightedChild->widgetRep(); 00854 00855 if ( qw ) 00856 { 00857 qw->setPalette( _preHighlightPalette ); 00858 qw->setAutoFillBackground( _preHighlightAutoFill ); 00859 } 00860 } 00861 00862 _highlightedChild = child; 00863 00864 if ( child ) 00865 { 00866 QWidget * qw = (QWidget *) child->widgetRep(); 00867 00868 if ( qw ) 00869 { 00870 _preHighlightPalette = qw->palette(); 00871 _preHighlightAutoFill = qw->autoFillBackground(); 00872 00873 qw->setAutoFillBackground( true ); 00874 QPalette pal( QColor( 0xff, 0x66, 0x00 ) ); // Button color 00875 pal.setBrush( QPalette::Window, QColor( 0xff, 0xaa, 0x00 ) ); // Window background 00876 pal.setBrush( QPalette::Base , QColor( 0xff, 0xee, 0x00 ) ); // Table etc. background 00877 00878 qw->setPalette( pal ); 00879 } 00880 } 00881 } 00882 00883 00884 #include "YQDialog.moc"