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,
119 QY2Styler::styler()->registerWidget(
this );
125 if ( isMainDialog() )
131 if ( _defaultButton )
132 _defaultButton->forgetDialog();
135 _focusButton->forgetDialog();
140 QY2Styler::styler()->unregisterWidget(
this );
149 if ( dialogType == YPopupDialog)
151 YDialog * currentDialog = YDialog::currentDialog(
false );
153 parent = (QWidget *) currentDialog->widgetRep();
156 if ( ( dialogType == YMainDialog || dialogType == YWizardDialog ) &&
159 yuiDebug() <<
"Adding dialog to mainWinDock" << std::endl;
190 if ( isMainDialog() )
193 preferredWidth = _userSize.width();
199 preferredWidth = YDialog::preferredWidth();
202 int screenWidth = qApp->desktop()->width();
204 if ( preferredWidth > screenWidth )
206 yuiWarning() <<
"Limiting dialog width to screen width (" << screenWidth
207 <<
") instead of " << preferredWidth
208 <<
" - check the layout!"
221 if ( isMainDialog() )
224 preferredHeight = _userSize.height();
230 preferredHeight = YDialog::preferredHeight();
233 int screenHeight = qApp->desktop()->height();
235 if ( preferredHeight > screenHeight )
237 yuiWarning() <<
"Limiting dialog height to screen height (" << screenHeight
238 <<
") instead of " << preferredHeight
239 <<
" - check the layout!"
250 QWidget::setEnabled( enabled );
251 YDialog::setEnabled( enabled );
260 if ( newWidth > qApp->desktop()->width() )
261 newWidth = qApp->desktop()->width();
263 if ( newHeight > qApp->desktop()->height() )
264 newHeight = qApp->desktop()->height();
266 resize( newWidth, newHeight );
270 firstChild()->setSize( newWidth, newHeight );
271 ( ( QWidget* )firstChild()->widgetRep() )->show();
277 YQDialog::resizeEvent( QResizeEvent * event )
282 setSize ( event->size().width(),
event->size().height() );
283 _userSize =
event->size();
285 if ( QWidget::parent() )
294 if ( _defaultButton )
295 return _defaultButton;
299 YDialog::setDefaultButton( 0 );
300 YDialog::setDefaultButton( _defaultButton );
302 return _defaultButton;
308 YWidgetListConstIterator end )
const
310 for ( YWidgetListConstIterator it = begin; it != end; ++it )
312 YWidget * widget = *it;
320 if ( button && button->isDefaultButton() )
330 if ( widget->hasChildren() )
333 widget->childrenEnd() );
345 YWidgetListConstIterator end )
350 for ( YWidgetListConstIterator it = begin; it != end; ++it )
356 wizard =
dynamic_cast<YQWizard *
> (*it);
364 if ( button->isDefaultButton() )
366 if ( _defaultButton && button != _defaultButton )
368 yuiError() <<
"Too many default buttons: " << button << std::endl;
369 yuiError() <<
"Using old default button: " << _defaultButton << std::endl;
373 _defaultButton = button;
381 if ( (*it)->hasChildren() )
384 (*it)->childrenEnd() );
400 if ( ! _defaultButton && wizard )
405 if ( _defaultButton )
407 YDialog::setDefaultButton( 0 );
408 YDialog::setDefaultButton( _defaultButton );
422 return findWizard( childrenBegin(), childrenEnd() );
428 YWidgetListConstIterator end )
const
430 for ( YWidgetListConstIterator it = begin; it != end; ++it )
432 YWidget * widget = *it;
438 if ( widget->hasChildren() )
441 widget->childrenEnd() );
463 if ( wizard->
direction() == YQWizard::Backward )
475 if ( wizard->nextButton()
476 && wizard->nextButton()->
isShown()
479 def = wizard->nextButton();
491 if ( _defaultButton &&
493 newDefaultButton != _defaultButton )
495 if ( dynamic_cast<YQWizardButton *>( _defaultButton ) )
498 _defaultButton->setDefaultButton(
false );
502 yuiError() <<
"Too many `opt(`default) PushButtons: " << newDefaultButton << std::endl;
503 newDefaultButton->setDefaultButton(
false );
510 if ( _defaultButton )
512 _defaultButton->setDefaultButton(
true );
513 yuiDebug() <<
"New default button: " << _defaultButton << std::endl;
515 if ( _defaultButton && ! _focusButton )
523 YDialog::setDefaultButton( 0 );
524 YDialog::setDefaultButton( _defaultButton );
537 yuiDebug() <<
"Activating focus button: " << _focusButton << std::endl;
547 if ( _defaultButton &&
551 yuiDebug() <<
"Activating default button: " << _defaultButton << std::endl;
559 yuiWarning() <<
"No default button in this dialog - ignoring [Return]" << std::endl;
570 if ( button == _focusButton )
572 if ( _focusButton && _focusButton != _defaultButton )
578 if ( ! _focusButton && _defaultButton )
586 if ( _focusButton && _focusButton != button )
589 if ( _defaultButton && _defaultButton != button )
592 _focusButton = button;
604 if ( event->key() == Qt::Key_Print )
609 else if ( event->key() == Qt::Key_F4 &&
610 event->modifiers() == Qt::ShiftModifier )
614 if (
YQUI::ui()->usingVisionImpairedPalette() )
617 YDialog * currentDialog = YDialog::currentDialog(
false );
619 parent = (QWidget *) currentDialog->widgetRep();
621 yuiMilestone() <<
"Switched to vision impaired palette" << std::endl;
622 QMessageBox::information( parent,
623 _(
"Color switching"),
624 _(
"Switching to color palette for vision impaired users -\n"
625 "press Shift-F4 again to switch back to normal colors." ),
626 QMessageBox::Ok | QMessageBox::Default,
627 QMessageBox::NoButton,
628 QMessageBox::NoButton );
632 else if ( event->key() == Qt::Key_F7 &&
633 event->modifiers() == Qt::ShiftModifier )
638 else if ( event->key() == Qt::Key_F8 &&
639 event->modifiers() == Qt::ShiftModifier )
644 else if ( event->modifiers() == Qt::NoModifier )
646 if ( event->key() == Qt::Key_Return ||
647 event->key() == Qt::Key_Enter )
653 else if ( event->modifiers() == ( Qt::ControlModifier | Qt::ShiftModifier | Qt::AltModifier ) )
657 yuiMilestone() <<
"Caught YaST2 magic key combination" << std::endl;
659 if ( event->key() == Qt::Key_M )
664 else if ( event->key() == Qt::Key_P )
669 else if ( event->key() == Qt::Key_D )
674 else if ( event->key() == Qt::Key_T )
676 yuiMilestone() <<
"*** Dumping widget tree ***" << std::endl;
678 yuiMilestone() <<
"*** Widget tree end ***" << std::endl;
681 else if ( event->key() == Qt::Key_Y )
683 yuiMilestone() <<
"Opening dialog spy" << std::endl;
684 YDialogSpy::showDialogSpy();
687 else if ( event->key() == Qt::Key_X )
690 yuiMilestone() <<
"Starting xterm" << std::endl;
691 result = system(
"/usr/bin/xterm &" );
693 yuiError() <<
"/usr/bin/xterm not found" << std::endl;
696 else if ( event->key() == Qt::Key_S )
698 yuiMilestone() <<
"Opening style editor" << std::endl;
700 _styleEditor->show();
701 _styleEditor->raise();
702 _styleEditor->activateWindow();
709 QWidget::keyPressEvent( event );
720 yuiMilestone() <<
"Caught window manager close event - returning with YCancelEvent" << std::endl;
727 YQDialog::focusInEvent( QFocusEvent * event )
734 if ( event->reason() == Qt::TabFocusReason )
736 focusNextPrevChild(
true );
740 if ( _defaultButton )
743 focusNextPrevChild(
true );
752 _eventLoop->wakeUp();
756 _waitForEventTimer->stop();
758 if ( timeout_millisec > 0 )
759 _waitForEventTimer->start( timeout_millisec );
761 if ( qApp->focusWidget() )
762 qApp->focusWidget()->setFocus();
766 if ( ! _eventLoop->isRunning() )
768 #if VERBOSE_EVENT_LOOP
769 yuiDebug() <<
"Executing event loop for " <<
this << std::endl;
773 #if VERBOSE_EVENT_LOOP
774 yuiDebug() <<
"Event loop finished for " <<
this << std::endl;
779 #if VERBOSE_EVENT_LOOP
780 yuiDebug() <<
"Event loop still running for " <<
this << std::endl;
784 _waitForEventTimer->stop();
803 _waitForEventTimer->stop();
808 _eventLoop->processEvents( QEventLoop::AllEvents, 10 );
833 if ( ! dialog || ! parent )
836 QPoint pos( ( parent->width() - dialog->width() ) / 2,
837 ( parent->height() - dialog->height() ) / 2 );
839 pos += parent->mapToGlobal( QPoint( 0, 0 ) );
840 pos = dialog->mapToParent( dialog->mapFromGlobal( pos ) );
849 if ( _highlightedChild && _highlightedChild->isValid() )
853 QWidget * qw = (QWidget *) _highlightedChild->widgetRep();
857 qw->setPalette( _preHighlightPalette );
858 qw->setAutoFillBackground( _preHighlightAutoFill );
862 _highlightedChild = child;
866 QWidget * qw = (QWidget *) child->widgetRep();
870 _preHighlightPalette = qw->palette();
871 _preHighlightAutoFill = qw->autoFillBackground();
873 qw->setAutoFillBackground(
true );
874 QPalette pal( QColor( 0xff, 0x66, 0x00 ) );
875 pal.setBrush( QPalette::Window, QColor( 0xff, 0xaa, 0x00 ) );
876 pal.setBrush( QPalette::Base , QColor( 0xff, 0xee, 0x00 ) );
878 qw->setPalette( pal );
884 #include "YQDialog.moc"
YQGenericButton * findDefaultButton()
Stylesheet Editor Dialog.
void askConfigureLogging()
void forceUnblockEvents()
void remove(YQDialog *dialog=0)
virtual void highlight(YWidget *child)
int defaultSize(YUIDimension dim) const
virtual void keyPressEvent(QKeyEvent *event)
Direction direction() const
void makeScreenShot(std::string filename)
YQWizard * findWizard() const
void add(YQDialog *dialog)
virtual int preferredWidth()
virtual YEvent * waitForEventInternal(int timeout_millisec)
static void center(QWidget *dialog, QWidget *parent=0)
virtual void setEnabled(bool enabled)
void gettingFocus(YQGenericButton *button)
virtual YQWizardButton * backButton() const
static YQMainWinDock * mainWinDock()
void setDefaultButton(YPushButton *newDefaultButton)
void sendEvent(YEvent *event)
virtual void openInternal()
YQDialog(YDialogType dialogType, YDialogColorMode colorMode=YDialogNormalColor)
bool activateDefaultButton(bool warn=true)
static QWidget * chooseParent(YDialogType dialogType)
void losingFocus(YQGenericButton *button)
virtual void setSize(int newWidth, int newHeight)
YEvent * consumePendingEvent()
YQGenericButton * wizardDefaultButton(YQWizard *wizard) const
virtual YEvent * pollEventInternal()
void ensureOnlyOneDefaultButton()
virtual int preferredHeight()
void closeEvent(QCloseEvent *ev)
void toggleVisionImpairedPalette()
void waitForEventTimeout()