28 #define YUILogComponent "qt-ui"
29 #include <yui/YUILog.h>
30 #include <qpushbutton.h>
31 #include <qmessagebox.h>
32 #include <QDesktopWidget>
37 #include <yui/YEvent.h>
39 #include "YQGenericButton.h"
40 #include "YQWizardButton.h"
42 #include "YQMainWinDock.h"
43 #include <yui/YDialogSpy.h>
44 #include <YApplication.h>
45 #include "QY2Styler.h"
46 #include "QY2StyleEditor.h"
53 #define YQMainDialogWFlags Qt::Widget
54 #define YQPopupDialogWFlags Qt::Dialog
56 #define VERBOSE_EVENT_LOOP 0
61 YDialogColorMode colorMode )
62 : QWidget( chooseParent( dialogType ),
63 dialogType == YPopupDialog ? YQPopupDialogWFlags : YQMainDialogWFlags )
64 , YDialog( dialogType, colorMode )
71 _highlightedChild = 0;
74 setFocusPolicy( Qt::StrongFocus );
75 setAutoFillBackground(
true );
77 if ( colorMode != YDialogNormalColor )
79 QColor normalBackground ( 240, 100, 36 );
80 QColor inputFieldBackground ( 0xbb, 0xff, 0xbb );
81 QColor text = Qt::black;
83 if ( colorMode == YDialogInfoColor )
85 normalBackground = QColor ( 238, 232, 170 );
88 QPalette warnPalette( normalBackground );
89 warnPalette.setColor( QPalette::Text, text );
90 warnPalette.setColor( QPalette::Base, inputFieldBackground );
91 setPalette( warnPalette );
93 qApp->setApplicationName(
YQUI::ui()->applicationTitle());
94 topLevelWidget()->setWindowTitle (
YQUI::ui()->applicationTitle() );
98 setWindowFlags( YQPopupDialogWFlags );
101 if ( ! isMainDialog() )
102 setWindowModality( Qt::ApplicationModal );
109 _eventLoop =
new QEventLoop(
this );
110 YUI_CHECK_NEW( _eventLoop );
112 _waitForEventTimer =
new QTimer(
this );
113 YUI_CHECK_NEW( _waitForEventTimer );
114 _waitForEventTimer->setSingleShot(
true );
116 QObject::connect( _waitForEventTimer, &pclass(_waitForEventTimer)::timeout,
128 if ( isMainDialog() )
134 if ( _defaultButton )
135 _defaultButton->forgetDialog();
138 _focusButton->forgetDialog();
155 if ( dialogType == YPopupDialog)
157 YDialog * currentDialog = YDialog::currentDialog(
false );
159 parent = (QWidget *) currentDialog->widgetRep();
162 if ( ( dialogType == YMainDialog || dialogType == YWizardDialog ) &&
165 yuiDebug() <<
"Adding dialog to mainWinDock" << std::endl;
196 if ( isMainDialog() )
208 int screenWidth = qApp->desktop()->width();
212 yuiWarning() <<
"Limiting dialog width to screen width (" << screenWidth
214 <<
" - check the layout!"
227 if ( isMainDialog() )
239 int screenHeight = qApp->desktop()->height();
243 yuiWarning() <<
"Limiting dialog height to screen height (" << screenHeight
245 <<
" - check the layout!"
256 QWidget::setEnabled( enabled );
257 YDialog::setEnabled( enabled );
266 if ( newWidth > qApp->desktop()->width() )
267 newWidth = qApp->desktop()->width();
269 if ( newHeight > qApp->desktop()->height() )
270 newHeight = qApp->desktop()->height();
272 resize( newWidth, newHeight );
276 firstChild()->setSize( newWidth, newHeight );
277 ( ( QWidget* )firstChild()->widgetRep() )->show();
283 YQDialog::resizeEvent( QResizeEvent * event )
288 setSize ( event->size().width(), event->size().height() );
289 _userSize =
event->size();
291 if ( QWidget::parent() )
300 if ( _defaultButton )
301 return _defaultButton;
305 YDialog::setDefaultButton( 0 );
306 YDialog::setDefaultButton( _defaultButton );
308 return _defaultButton;
314 YWidgetListConstIterator end )
const
316 for ( YWidgetListConstIterator it = begin; it != end; ++it )
318 YWidget * widget = *it;
326 if ( button && button->isDefaultButton() )
336 if ( widget->hasChildren() )
339 widget->childrenEnd() );
351 YWidgetListConstIterator end )
356 for ( YWidgetListConstIterator it = begin; it != end; ++it )
362 wizard =
dynamic_cast<YQWizard *
> (*it);
370 if ( button->isDefaultButton() )
372 if ( _defaultButton && button != _defaultButton )
374 yuiError() <<
"Too many default buttons: " << button << std::endl;
375 yuiError() <<
"Using old default button: " << _defaultButton << std::endl;
379 _defaultButton = button;
387 if ( (*it)->hasChildren() )
390 (*it)->childrenEnd() );
406 if ( ! _defaultButton && wizard )
411 if ( _defaultButton )
413 YDialog::setDefaultButton( 0 );
414 YDialog::setDefaultButton( _defaultButton );
428 return findWizard( childrenBegin(), childrenEnd() );
434 YWidgetListConstIterator end )
const
436 for ( YWidgetListConstIterator it = begin; it != end; ++it )
438 YWidget * widget = *it;
444 if ( widget->hasChildren() )
447 widget->childrenEnd() );
469 if ( wizard->
direction() == YQWizard::Backward )
481 if ( wizard->nextButton()
482 && wizard->nextButton()->
isShown()
485 def = wizard->nextButton();
497 if ( _defaultButton &&
499 newDefaultButton != _defaultButton )
504 _defaultButton->setDefaultButton(
false );
508 yuiError() <<
"Too many `opt(`default) PushButtons: " << newDefaultButton << std::endl;
509 newDefaultButton->setDefaultButton(
false );
516 if ( _defaultButton )
518 _defaultButton->setDefaultButton(
true );
519 yuiDebug() <<
"New default button: " << _defaultButton << std::endl;
521 if ( _defaultButton && ! _focusButton )
529 YDialog::setDefaultButton( 0 );
530 YDialog::setDefaultButton( _defaultButton );
543 yuiDebug() <<
"Activating focus button: " << _focusButton << std::endl;
553 if ( _defaultButton &&
557 yuiDebug() <<
"Activating default button: " << _defaultButton << std::endl;
565 yuiWarning() <<
"No default button in this dialog - ignoring [Return]" << std::endl;
576 if ( button == _focusButton )
578 if ( _focusButton && _focusButton != _defaultButton )
584 if ( ! _focusButton && _defaultButton )
592 if ( _focusButton && _focusButton != button )
595 if ( _defaultButton && _defaultButton != button )
598 _focusButton = button;
610 if ( event->key() == Qt::Key_Print )
615 else if ( event->key() == Qt::Key_F4 &&
616 event->modifiers() == Qt::ShiftModifier )
620 if ( QY2Styler::styler()->usingAlternateStyleSheet() )
623 YDialog * currentDialog = YDialog::currentDialog(
false );
625 parent = (QWidget *) currentDialog->widgetRep();
627 yuiMilestone() <<
"Switched to vision impaired palette" << std::endl;
628 QMessageBox::information( parent,
629 _(
"Color switching"),
630 _(
"Switching to color palette for vision impaired users -\n"
631 "press Shift-F4 again to switch back to normal colors." ),
632 QMessageBox::Ok | QMessageBox::Default,
633 QMessageBox::NoButton,
634 QMessageBox::NoButton );
638 else if ( event->key() == Qt::Key_F7 &&
639 event->modifiers() == Qt::ShiftModifier )
644 else if ( event->key() == Qt::Key_F8 &&
645 event->modifiers() == Qt::ShiftModifier )
650 else if ( event->modifiers() == Qt::NoModifier )
652 if ( event->key() == Qt::Key_Return ||
653 event->key() == Qt::Key_Enter )
659 else if ( event->modifiers() == ( Qt::ControlModifier | Qt::ShiftModifier | Qt::AltModifier ) )
663 yuiMilestone() <<
"Caught YaST2 magic key combination" << std::endl;
665 if ( event->key() == Qt::Key_M )
670 else if ( event->key() == Qt::Key_P )
675 else if ( event->key() == Qt::Key_D )
680 else if ( event->key() == Qt::Key_T )
682 yuiMilestone() <<
"*** Dumping widget tree ***" << std::endl;
684 yuiMilestone() <<
"*** Widget tree end ***" << std::endl;
687 else if ( event->key() == Qt::Key_Y )
689 yuiMilestone() <<
"Opening dialog spy" << std::endl;
690 YDialogSpy::showDialogSpy();
693 else if ( event->key() == Qt::Key_X )
696 yuiMilestone() <<
"Starting xterm" << std::endl;
697 result = system(
"/usr/bin/xterm &" );
699 yuiError() <<
"/usr/bin/xterm not found" << std::endl;
702 else if ( event->key() == Qt::Key_S )
704 yuiMilestone() <<
"Opening style editor" << std::endl;
706 _styleEditor->show();
707 _styleEditor->raise();
708 _styleEditor->activateWindow();
715 QWidget::keyPressEvent( event );
726 yuiMilestone() <<
"Caught window manager close event - returning with YCancelEvent" << std::endl;
733 YQDialog::focusInEvent( QFocusEvent * event )
740 if ( event->reason() == Qt::TabFocusReason )
742 focusNextPrevChild(
true );
746 if ( _defaultButton )
749 focusNextPrevChild(
true );
758 _eventLoop->wakeUp();
762 _waitForEventTimer->stop();
764 if ( timeout_millisec > 0 )
765 _waitForEventTimer->start( timeout_millisec );
767 if ( qApp->focusWidget() )
768 qApp->focusWidget()->setFocus();
772 if ( ! _eventLoop->isRunning() )
774 #if VERBOSE_EVENT_LOOP
775 yuiDebug() <<
"Executing event loop for " <<
this << std::endl;
779 #if VERBOSE_EVENT_LOOP
780 yuiDebug() <<
"Event loop finished for " <<
this << std::endl;
785 #if VERBOSE_EVENT_LOOP
786 yuiDebug() <<
"Event loop still running for " <<
this << std::endl;
790 _waitForEventTimer->stop();
809 _waitForEventTimer->stop();
814 _eventLoop->processEvents( QEventLoop::AllEvents, 10 );
827 if ( !
YQUI::ui()->pendingEvent() && isTopmostDialog() )
841 if ( ! dialog || ! parent )
844 QPoint pos( ( parent->width() - dialog->width() ) / 2,
845 ( parent->height() - dialog->height() ) / 2 );
847 pos += parent->mapToGlobal( QPoint( 0, 0 ) );
848 pos = dialog->mapToParent( dialog->mapFromGlobal( pos ) );
857 if ( _highlightedChild && _highlightedChild->isValid() )
861 QWidget * qw = (QWidget *) _highlightedChild->widgetRep();
865 qw->setPalette( _preHighlightPalette );
866 qw->setAutoFillBackground( _preHighlightAutoFill );
870 _highlightedChild = child;
874 QWidget * qw = (QWidget *) child->widgetRep();
878 _preHighlightPalette = qw->palette();
879 _preHighlightAutoFill = qw->autoFillBackground();
881 qw->setAutoFillBackground(
true );
882 QPalette pal( QColor( 0xff, 0x66, 0x00 ) );
883 pal.setBrush( QPalette::Window, QColor( 0xff, 0xaa, 0x00 ) );
884 pal.setBrush( QPalette::Base , QColor( 0xff, 0xee, 0x00 ) );
886 qw->setPalette( pal );
892 #include "YQDialog.moc"