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 );
88 qApp->setApplicationName(
YQUI::ui()->applicationTitle());
89 topLevelWidget()->setWindowTitle (
YQUI::ui()->applicationTitle() );
90 QGuiApplication::setApplicationDisplayName(
YQUI::ui()->applicationTitle() );
94 setWindowFlags( YQPopupDialogWFlags );
97 if ( ! isMainDialog() )
98 setWindowModality( Qt::ApplicationModal );
105 _eventLoop =
new QEventLoop(
this );
106 YUI_CHECK_NEW( _eventLoop );
108 _waitForEventTimer =
new QTimer(
this );
109 YUI_CHECK_NEW( _waitForEventTimer );
110 _waitForEventTimer->setSingleShot(
true );
112 QObject::connect( _waitForEventTimer, &pclass(_waitForEventTimer)::timeout,
124 if ( isMainDialog() )
130 if ( _defaultButton )
131 _defaultButton->forgetDialog();
134 _focusButton->forgetDialog();
151 if ( dialogType == YPopupDialog)
153 YDialog * currentDialog = YDialog::currentDialog(
false );
155 parent = (QWidget *) currentDialog->widgetRep();
158 if ( ( dialogType == YMainDialog || dialogType == YWizardDialog ) &&
161 yuiDebug() <<
"Adding dialog to mainWinDock" << std::endl;
192 if ( isMainDialog() )
204 int screenWidth = qApp->desktop()->width();
208 yuiWarning() <<
"Limiting dialog width to screen width (" << screenWidth
210 <<
" - check the layout!" 223 if ( isMainDialog() )
235 int screenHeight = qApp->desktop()->height();
239 yuiWarning() <<
"Limiting dialog height to screen height (" << screenHeight
241 <<
" - check the layout!" 252 QWidget::setEnabled( enabled );
253 YDialog::setEnabled( enabled );
262 if ( newWidth > qApp->desktop()->width() )
263 newWidth = qApp->desktop()->width();
265 if ( newHeight > qApp->desktop()->height() )
266 newHeight = qApp->desktop()->height();
268 resize( newWidth, newHeight );
272 firstChild()->setSize( newWidth, newHeight );
273 ( ( QWidget* )firstChild()->widgetRep() )->show();
279 YQDialog::resizeEvent( QResizeEvent * event )
284 setSize ( event->size().width(),
event->size().height() );
285 _userSize =
event->size();
287 if ( QWidget::parent() )
296 if ( _defaultButton )
297 return _defaultButton;
301 YDialog::setDefaultButton( 0 );
302 YDialog::setDefaultButton( _defaultButton );
304 return _defaultButton;
310 YWidgetListConstIterator end )
const 312 for ( YWidgetListConstIterator it = begin; it != end; ++it )
314 YWidget * widget = *it;
322 if ( button && button->isDefaultButton() )
332 if ( widget->hasChildren() )
335 widget->childrenEnd() );
347 YWidgetListConstIterator end )
352 for ( YWidgetListConstIterator it = begin; it != end; ++it )
358 wizard =
dynamic_cast<YQWizard *
> (*it);
366 if ( button->isDefaultButton() )
368 if ( _defaultButton && button != _defaultButton )
370 yuiError() <<
"Too many default buttons: " << button << std::endl;
371 yuiError() <<
"Using old default button: " << _defaultButton << std::endl;
375 _defaultButton = button;
383 if ( (*it)->hasChildren() )
386 (*it)->childrenEnd() );
402 if ( ! _defaultButton && wizard )
407 if ( _defaultButton )
409 YDialog::setDefaultButton( 0 );
410 YDialog::setDefaultButton( _defaultButton );
424 return findWizard( childrenBegin(), childrenEnd() );
430 YWidgetListConstIterator end )
const 432 for ( YWidgetListConstIterator it = begin; it != end; ++it )
434 YWidget * widget = *it;
440 if ( widget->hasChildren() )
443 widget->childrenEnd() );
465 if ( wizard->
direction() == YQWizard::Backward )
477 if ( wizard->nextButton()
478 && wizard->nextButton()->
isShown()
481 def = wizard->nextButton();
493 if ( _defaultButton &&
495 newDefaultButton != _defaultButton )
497 if ( dynamic_cast<YQWizardButton *>( _defaultButton ) )
500 _defaultButton->setDefaultButton(
false );
504 yuiError() <<
"Too many `opt(`default) PushButtons: " << newDefaultButton << std::endl;
505 newDefaultButton->setDefaultButton(
false );
512 if ( _defaultButton )
514 _defaultButton->setDefaultButton(
true );
515 yuiDebug() <<
"New default button: " << _defaultButton << std::endl;
517 if ( _defaultButton && ! _focusButton )
525 YDialog::setDefaultButton( 0 );
526 YDialog::setDefaultButton( _defaultButton );
539 yuiDebug() <<
"Activating focus button: " << _focusButton << std::endl;
549 if ( _defaultButton &&
553 yuiDebug() <<
"Activating default button: " << _defaultButton << std::endl;
561 yuiWarning() <<
"No default button in this dialog - ignoring [Return]" << std::endl;
572 if ( button == _focusButton )
574 if ( _focusButton && _focusButton != _defaultButton )
580 if ( ! _focusButton && _defaultButton )
588 if ( _focusButton && _focusButton != button )
591 if ( _defaultButton && _defaultButton != button )
594 _focusButton = button;
606 if ( event->key() == Qt::Key_Print )
611 else if ( event->key() == Qt::Key_F4 &&
612 event->modifiers() == Qt::ShiftModifier )
616 if ( QY2Styler::styler()->usingAlternateStyleSheet() )
619 YDialog * currentDialog = YDialog::currentDialog(
false );
621 parent = (QWidget *) currentDialog->widgetRep();
623 yuiMilestone() <<
"Switched to vision impaired palette" << std::endl;
624 QMessageBox::information( parent,
625 _(
"Color switching"),
626 _(
"Switching to color palette for vision impaired users -\n" 627 "press Shift-F4 again to switch back to normal colors." ),
628 QMessageBox::Ok | QMessageBox::Default,
629 QMessageBox::NoButton,
630 QMessageBox::NoButton );
634 else if ( event->key() == Qt::Key_F6 &&
635 event->modifiers() == Qt::ShiftModifier )
639 else if ( event->key() == Qt::Key_F7 &&
640 event->modifiers() == Qt::ShiftModifier )
645 else if ( event->key() == Qt::Key_F8 &&
646 event->modifiers() == Qt::ShiftModifier )
651 else if ( event->modifiers() == Qt::NoModifier )
653 if ( event->key() == Qt::Key_Return ||
654 event->key() == Qt::Key_Enter )
660 else if ( event->modifiers() == ( Qt::ControlModifier | Qt::ShiftModifier | Qt::AltModifier ) )
664 yuiMilestone() <<
"Caught YaST2 magic key combination" << std::endl;
666 if ( event->key() == Qt::Key_M )
671 else if ( event->key() == Qt::Key_P )
676 else if ( event->key() == Qt::Key_D )
681 else if ( event->key() == Qt::Key_T )
683 yuiMilestone() <<
"*** Dumping widget tree ***" << std::endl;
685 yuiMilestone() <<
"*** Widget tree end ***" << std::endl;
688 else if ( event->key() == Qt::Key_Y )
690 yuiMilestone() <<
"Opening dialog spy" << std::endl;
691 YDialogSpy::showDialogSpy();
694 else if ( event->key() == Qt::Key_X )
697 yuiMilestone() <<
"Starting xterm" << std::endl;
698 result = system(
"/usr/bin/xterm &" );
700 yuiError() <<
"/usr/bin/xterm not found" << std::endl;
703 else if ( event->key() == Qt::Key_S )
705 yuiMilestone() <<
"Opening style editor" << std::endl;
707 _styleEditor->show();
708 _styleEditor->raise();
709 _styleEditor->activateWindow();
716 QWidget::keyPressEvent( event );
727 yuiMilestone() <<
"Caught window manager close event - returning with YCancelEvent" << std::endl;
734 YQDialog::focusInEvent( QFocusEvent * event )
741 if ( event->reason() == Qt::TabFocusReason )
743 focusNextPrevChild(
true );
747 if ( _defaultButton )
750 focusNextPrevChild(
true );
759 _eventLoop->wakeUp();
763 _waitForEventTimer->stop();
765 if ( timeout_millisec > 0 )
766 _waitForEventTimer->start( timeout_millisec );
768 if ( qApp->focusWidget() )
769 qApp->focusWidget()->setFocus();
773 if ( ! _eventLoop->isRunning() )
775 #if VERBOSE_EVENT_LOOP 776 yuiDebug() <<
"Executing event loop for " <<
this << std::endl;
780 #if VERBOSE_EVENT_LOOP 781 yuiDebug() <<
"Event loop finished for " <<
this << std::endl;
786 #if VERBOSE_EVENT_LOOP 787 yuiDebug() <<
"Event loop still running for " <<
this << std::endl;
791 _waitForEventTimer->stop();
810 _waitForEventTimer->stop();
815 _eventLoop->processEvents( QEventLoop::AllEvents, 10 );
828 if ( !
YQUI::ui()->pendingEvent() && isTopmostDialog() )
842 if ( ! dialog || ! parent )
845 QPoint pos( ( parent->width() - dialog->width() ) / 2,
846 ( parent->height() - dialog->height() ) / 2 );
848 pos += parent->mapToGlobal( QPoint( 0, 0 ) );
849 pos = dialog->mapToParent( dialog->mapFromGlobal( pos ) );
858 if ( _highlightedChild && _highlightedChild->isValid() )
862 QWidget * qw = (QWidget *) _highlightedChild->widgetRep();
866 qw->setPalette( _preHighlightPalette );
867 qw->setAutoFillBackground( _preHighlightAutoFill );
871 _highlightedChild = child;
875 QWidget * qw = (QWidget *) child->widgetRep();
879 _preHighlightPalette = qw->palette();
880 _preHighlightAutoFill = qw->autoFillBackground();
882 qw->setAutoFillBackground(
true );
883 QPalette pal( QColor( 0xff, 0x66, 0x00 ) );
884 pal.setBrush( QPalette::Window, QColor( 0xff, 0xaa, 0x00 ) );
885 pal.setBrush( QPalette::Base , QColor( 0xff, 0xee, 0x00 ) );
887 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()