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 <yui/YApplication.h> 45 #include "QY2Styler.h" 46 #include "QY2StyleEditor.h" 48 #define YQMainDialogWFlags Qt::Widget 49 #define YQPopupDialogWFlags Qt::Dialog 51 #define VERBOSE_EVENT_LOOP 0 56 YDialogColorMode colorMode )
57 : QWidget( chooseParent( dialogType ),
58 dialogType == YPopupDialog ? YQPopupDialogWFlags : YQMainDialogWFlags )
59 , YDialog( dialogType, colorMode )
66 _highlightedChild = 0;
69 setFocusPolicy( Qt::StrongFocus );
70 setAutoFillBackground(
true );
72 if ( colorMode != YDialogNormalColor )
74 QColor normalBackground ( 240, 100, 36 );
75 QColor inputFieldBackground ( 0xbb, 0xff, 0xbb );
76 QColor text = Qt::black;
78 if ( colorMode == YDialogInfoColor )
80 normalBackground = QColor ( 238, 232, 170 );
83 QPalette warnPalette( normalBackground );
84 warnPalette.setColor( QPalette::Text, text );
85 warnPalette.setColor( QPalette::Base, inputFieldBackground );
86 setPalette( warnPalette );
89 qApp->setApplicationName(
YQUI::ui()->applicationTitle());
90 topLevelWidget()->setWindowTitle (
YQUI::ui()->applicationTitle() );
91 QGuiApplication::setApplicationDisplayName(
YQUI::ui()->applicationTitle() );
95 setWindowFlags( YQPopupDialogWFlags );
98 if ( ! isMainDialog() )
99 setWindowModality( Qt::ApplicationModal );
106 _eventLoop =
new QEventLoop(
this );
107 YUI_CHECK_NEW( _eventLoop );
109 _waitForEventTimer =
new QTimer(
this );
110 YUI_CHECK_NEW( _waitForEventTimer );
111 _waitForEventTimer->setSingleShot(
true );
113 QObject::connect( _waitForEventTimer, &pclass(_waitForEventTimer)::timeout,
125 if ( isMainDialog() )
131 if ( _defaultButton )
132 _defaultButton->forgetDialog();
135 _focusButton->forgetDialog();
152 if ( dialogType == YPopupDialog)
154 YDialog * currentDialog = YDialog::currentDialog(
false );
156 parent = (QWidget *) currentDialog->widgetRep();
159 if ( ( dialogType == YMainDialog || dialogType == YWizardDialog ) &&
162 yuiDebug() <<
"Adding dialog to mainWinDock" << endl;
193 if ( isMainDialog() )
205 int screenWidth = qApp->desktop()->width();
209 yuiWarning() <<
"Limiting dialog width to screen width (" << screenWidth
211 <<
" - check the layout!" 224 if ( isMainDialog() )
236 int screenHeight = qApp->desktop()->height();
240 yuiWarning() <<
"Limiting dialog height to screen height (" << screenHeight
242 <<
" - check the layout!" 253 QWidget::setEnabled( enabled );
254 YDialog::setEnabled( enabled );
263 if ( newWidth > qApp->desktop()->width() )
264 newWidth = qApp->desktop()->width();
266 if ( newHeight > qApp->desktop()->height() )
267 newHeight = qApp->desktop()->height();
269 resize( newWidth, newHeight );
273 firstChild()->setSize( newWidth, newHeight );
274 ( ( QWidget* )firstChild()->widgetRep() )->show();
280 YQDialog::resizeEvent( QResizeEvent * event )
285 setSize ( event->size().width(),
event->size().height() );
286 _userSize =
event->size();
288 if ( QWidget::parent() )
297 if ( _defaultButton )
298 return _defaultButton;
302 YDialog::setDefaultButton( 0 );
303 YDialog::setDefaultButton( _defaultButton );
305 return _defaultButton;
311 YWidgetListConstIterator end )
const 313 for ( YWidgetListConstIterator it = begin; it != end; ++it )
315 YWidget * widget = *it;
323 if ( button && button->isDefaultButton() )
333 if ( widget->hasChildren() )
336 widget->childrenEnd() );
348 YWidgetListConstIterator end )
353 for ( YWidgetListConstIterator it = begin; it != end; ++it )
359 wizard =
dynamic_cast<YQWizard *
> (*it);
367 if ( button->isDefaultButton() )
369 if ( _defaultButton && button != _defaultButton )
371 yuiError() <<
"Too many default buttons: " << button << endl;
372 yuiError() <<
"Using old default button: " << _defaultButton << endl;
376 _defaultButton = button;
384 if ( (*it)->hasChildren() )
387 (*it)->childrenEnd() );
403 if ( ! _defaultButton && wizard )
408 if ( _defaultButton )
410 YDialog::setDefaultButton( 0 );
411 YDialog::setDefaultButton( _defaultButton );
425 return findWizard( childrenBegin(), childrenEnd() );
431 YWidgetListConstIterator end )
const 433 for ( YWidgetListConstIterator it = begin; it != end; ++it )
435 YWidget * widget = *it;
441 if ( widget->hasChildren() )
444 widget->childrenEnd() );
466 if ( wizard->
direction() == YQWizard::Backward )
478 if ( wizard->nextButton()
479 && wizard->nextButton()->
isShown()
482 def = wizard->nextButton();
494 if ( _defaultButton &&
496 newDefaultButton != _defaultButton )
498 if ( dynamic_cast<YQWizardButton *>( _defaultButton ) )
501 _defaultButton->setDefaultButton(
false );
505 yuiError() <<
"Too many `opt(`default) PushButtons: " << newDefaultButton << endl;
506 newDefaultButton->setDefaultButton(
false );
513 if ( _defaultButton )
515 _defaultButton->setDefaultButton(
true );
516 yuiDebug() <<
"New default button: " << _defaultButton << endl;
518 if ( _defaultButton && ! _focusButton )
526 YDialog::setDefaultButton( 0 );
527 YDialog::setDefaultButton( _defaultButton );
540 yuiDebug() <<
"Activating focus button: " << _focusButton << endl;
550 if ( _defaultButton &&
554 yuiDebug() <<
"Activating default button: " << _defaultButton << endl;
562 yuiWarning() <<
"No default button in this dialog - ignoring [Return]" << endl;
573 if ( button == _focusButton )
575 if ( _focusButton && _focusButton != _defaultButton )
581 if ( ! _focusButton && _defaultButton )
589 if ( _focusButton && _focusButton != button )
592 if ( _defaultButton && _defaultButton != button )
595 _focusButton = button;
607 if ( event->key() == Qt::Key_Print )
612 else if ( event->key() == Qt::Key_F4 &&
613 event->modifiers() == Qt::ShiftModifier )
617 if ( QY2Styler::styler()->usingAlternateStyleSheet() )
620 YDialog * currentDialog = YDialog::currentDialog(
false );
622 parent = (QWidget *) currentDialog->widgetRep();
624 yuiMilestone() <<
"Switched to vision impaired palette" << endl;
625 QMessageBox::information( parent,
626 _(
"Color switching"),
627 _(
"Switching to color palette for vision impaired users -\n" 628 "press Shift-F4 again to switch back to normal colors." ),
629 QMessageBox::Ok | QMessageBox::Default,
630 QMessageBox::NoButton,
631 QMessageBox::NoButton );
635 else if ( event->key() == Qt::Key_F6 &&
636 event->modifiers() == Qt::ShiftModifier )
640 else if ( event->key() == Qt::Key_F7 &&
641 event->modifiers() == Qt::ShiftModifier )
646 else if ( event->key() == Qt::Key_F8 &&
647 event->modifiers() == Qt::ShiftModifier )
652 else if ( event->modifiers() == Qt::NoModifier )
654 if ( event->key() == Qt::Key_Return ||
655 event->key() == Qt::Key_Enter )
661 else if ( event->modifiers() == ( Qt::ControlModifier | Qt::ShiftModifier | Qt::AltModifier ) )
665 yuiMilestone() <<
"Caught YaST2 magic key combination" << endl;
667 if ( event->key() == Qt::Key_M )
672 else if ( event->key() == Qt::Key_P )
677 else if ( event->key() == Qt::Key_D )
682 else if ( event->key() == Qt::Key_T )
684 yuiMilestone() <<
"*** Dumping widget tree ***" << endl;
686 yuiMilestone() <<
"*** Widget tree end ***" << endl;
689 else if ( event->key() == Qt::Key_Y )
691 yuiMilestone() <<
"Opening dialog spy" << endl;
692 YDialogSpy::showDialogSpy();
695 else if ( event->key() == Qt::Key_X )
698 yuiMilestone() <<
"Starting xterm" << endl;
699 result = system(
"/usr/bin/xterm &" );
701 yuiError() <<
"/usr/bin/xterm not found" << endl;
704 else if ( event->key() == Qt::Key_S )
706 yuiMilestone() <<
"Opening style editor" << endl;
708 _styleEditor->show();
709 _styleEditor->raise();
710 _styleEditor->activateWindow();
717 QWidget::keyPressEvent( event );
728 yuiMilestone() <<
"Caught window manager close event - returning with YCancelEvent" << endl;
735 YQDialog::focusInEvent( QFocusEvent * event )
742 if ( event->reason() == Qt::TabFocusReason )
744 focusNextPrevChild(
true );
748 if ( _defaultButton )
751 focusNextPrevChild(
true );
760 _eventLoop->wakeUp();
764 _waitForEventTimer->stop();
766 if ( timeout_millisec > 0 )
767 _waitForEventTimer->start( timeout_millisec );
769 if ( qApp->focusWidget() )
770 qApp->focusWidget()->setFocus();
774 if ( ! _eventLoop->isRunning() )
776 #if VERBOSE_EVENT_LOOP 777 yuiDebug() <<
"Executing event loop for " <<
this << endl;
781 #if VERBOSE_EVENT_LOOP 782 yuiDebug() <<
"Event loop finished for " <<
this << endl;
787 #if VERBOSE_EVENT_LOOP 788 yuiDebug() <<
"Event loop still running for " <<
this << endl;
792 _waitForEventTimer->stop();
809 _eventLoop->wakeUp();
813 _waitForEventTimer->stop();
818 _eventLoop->processEvents( QEventLoop::AllEvents, 10 );
831 if ( !
YQUI::ui()->pendingEvent() && isTopmostDialog() )
845 if ( ! dialog || ! parent )
848 QPoint pos( ( parent->width() - dialog->width() ) / 2,
849 ( parent->height() - dialog->height() ) / 2 );
851 pos += parent->mapToGlobal( QPoint( 0, 0 ) );
852 pos = dialog->mapToParent( dialog->mapFromGlobal( pos ) );
861 if ( _highlightedChild && _highlightedChild->isValid() )
865 QWidget * qw = (QWidget *) _highlightedChild->widgetRep();
869 qw->setPalette( _preHighlightPalette );
870 qw->setAutoFillBackground( _preHighlightAutoFill );
874 _highlightedChild = child;
878 QWidget * qw = (QWidget *) child->widgetRep();
882 _preHighlightPalette = qw->palette();
883 _preHighlightAutoFill = qw->autoFillBackground();
885 qw->setAutoFillBackground(
true );
886 QPalette pal( QColor( 0xff, 0x66, 0x00 ) );
887 pal.setBrush( QPalette::Window, QColor( 0xff, 0xaa, 0x00 ) );
888 pal.setBrush( QPalette::Base , QColor( 0xff, 0xee, 0x00 ) );
890 qw->setPalette( pal );
int defaultSize(YUIDimension dim) const
Returns size for opt(defaultsize) dialogs (in one dimension).
YQWizard * findWizard() const
Find the first wizard in that dialog, if there is any.
YQGenericButton * findDefaultButton()
Return this dialog's (first) default button or 0 if none.
Stylesheet Editor Dialog.
void askConfigureLogging()
Open dialog to configure logging.
void forceUnblockEvents()
Force unblocking all events, no matter how many times blockEvents() has This returns 0 if there is no...
void remove(YQDialog *dialog=0)
Remove a dialog from the MainWinDock (if it belongs to the MainWinDock).
Direction direction() const
Returns the current direction of wizard operations - going forward or going backward.
virtual void highlight(YWidget *child)
Highlight a child widget of this dialog.
virtual void keyPressEvent(QKeyEvent *event)
Qt event handlers.
void makeScreenShot(std::string filename)
Make a screen shot in .png format and save it to 'filename'.
void askSaveLogs()
Open file selection box and let the user save y2logs to that location.
virtual ~YQDialog()
Destructor.
void toggleAlternateStyleSheet()
Toggle between default/alternate style sheets.
void toggleRecordMacro()
Toggle macro recording (activated by Ctrl-Shift-Alt-M): Stop macro recording if it is in progress...
void registerWidget(QWidget *widget)
Registers a widget and applies the style sheet.
void add(YQDialog *dialog)
Add a dialog (the widgetRep() of a YQDialog) to the MainWinDock (on top of its widget stack...
virtual YQWizardButton * backButton() const
Return internal widgets.
virtual int preferredWidth()
Preferred width of the widget.
virtual YEvent * waitForEventInternal(int timeout_millisec)
Wait for a user event.
static void center(QWidget *dialog, QWidget *parent=0)
Center a dialog relative to 'parent'.
void askSendWidgetID()
Open a pop-up dialog to ask the user for a widget ID and then send it with sendWidgetID().
virtual void activate()
Activate this dialog: Make sure that it is shown as the topmost dialog of this application and that i...
virtual void setEnabled(bool enabled)
Set enabled/disabled state.
void gettingFocus(YQGenericButton *button)
Notification that a button gets the keyboard focus.
static YQMainWinDock * mainWinDock()
Static method to access the singleton for this class.
void setDefaultButton(YPushButton *newDefaultButton)
Set the dialog's default button - the button that is activated with [Return] if no other button has t...
void sendEvent(YEvent *event)
Widget event handlers (slots) call this when an event occured that should be the answer to a UserInpu...
virtual void openInternal()
Internal open() method, called exactly once during the life time of the dialog in open()...
bool userResized()
Return 'true' if the user resized this dialog.
YQDialog(YDialogType dialogType, YDialogColorMode colorMode=YDialogNormalColor)
Constructor.
YQGenericButton * wizardDefaultButton(YQWizard *wizard) const
Find a wizard button that would make sense as a default button.
bool activateDefaultButton(bool warn=true)
Activate (i.e.
static QWidget * chooseParent(YDialogType dialogType)
Choose a parent widget for a dialog of the specified type: Either the main window dock (if this is a ...
void losingFocus(YQGenericButton *button)
Notification that a button loses the keyboard focus.
virtual void setSize(int newWidth, int newHeight)
Set the new size of the widget.
YEvent * consumePendingEvent()
Return the pending event, if there is one, and mark it as "consumed".
virtual YEvent * pollEventInternal()
Check if a user event is pending.
void timeoutBusyCursor()
Show mouse cursor indicating busy state if the UI is unable to respond to user input for more than a ...
void ensureOnlyOneDefaultButton()
Ensure presence of no more than one single default button.
virtual int preferredHeight()
Preferred height of the widget.
void normalCursor()
Show normal mouse cursor not indicating busy status.
void askPlayMacro()
Open file selection box and ask for a macro file to play (activated by Ctrl-Shift-Alt-P) ...
void closeEvent(QCloseEvent *ev)
Interited from QDialog: The window was closed via the window manager close button.
void unregisterWidget(QWidget *widget)
Unregisters a widget.
static YQUI * ui()
Access the global Qt-UI.
void waitForEventTimeout()
Timeout during waitForEvent()