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 )
501 if ( dynamic_cast<YQWizardButton *>( _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_F6 &&
639 event->modifiers() == Qt::ShiftModifier )
643 else if ( event->key() == Qt::Key_F7 &&
644 event->modifiers() == Qt::ShiftModifier )
649 else if ( event->key() == Qt::Key_F8 &&
650 event->modifiers() == Qt::ShiftModifier )
655 else if ( event->modifiers() == Qt::NoModifier )
657 if ( event->key() == Qt::Key_Return ||
658 event->key() == Qt::Key_Enter )
664 else if ( event->modifiers() == ( Qt::ControlModifier | Qt::ShiftModifier | Qt::AltModifier ) )
668 yuiMilestone() <<
"Caught YaST2 magic key combination" << std::endl;
670 if ( event->key() == Qt::Key_M )
675 else if ( event->key() == Qt::Key_P )
680 else if ( event->key() == Qt::Key_D )
685 else if ( event->key() == Qt::Key_T )
687 yuiMilestone() <<
"*** Dumping widget tree ***" << std::endl;
689 yuiMilestone() <<
"*** Widget tree end ***" << std::endl;
692 else if ( event->key() == Qt::Key_Y )
694 yuiMilestone() <<
"Opening dialog spy" << std::endl;
695 YDialogSpy::showDialogSpy();
698 else if ( event->key() == Qt::Key_X )
701 yuiMilestone() <<
"Starting xterm" << std::endl;
702 result = system(
"/usr/bin/xterm &" );
704 yuiError() <<
"/usr/bin/xterm not found" << std::endl;
707 else if ( event->key() == Qt::Key_S )
709 yuiMilestone() <<
"Opening style editor" << std::endl;
711 _styleEditor->show();
712 _styleEditor->raise();
713 _styleEditor->activateWindow();
720 QWidget::keyPressEvent( event );
731 yuiMilestone() <<
"Caught window manager close event - returning with YCancelEvent" << std::endl;
738 YQDialog::focusInEvent( QFocusEvent * event )
745 if ( event->reason() == Qt::TabFocusReason )
747 focusNextPrevChild(
true );
751 if ( _defaultButton )
754 focusNextPrevChild(
true );
763 _eventLoop->wakeUp();
767 _waitForEventTimer->stop();
769 if ( timeout_millisec > 0 )
770 _waitForEventTimer->start( timeout_millisec );
772 if ( qApp->focusWidget() )
773 qApp->focusWidget()->setFocus();
777 if ( ! _eventLoop->isRunning() )
779 #if VERBOSE_EVENT_LOOP 780 yuiDebug() <<
"Executing event loop for " <<
this << std::endl;
784 #if VERBOSE_EVENT_LOOP 785 yuiDebug() <<
"Event loop finished for " <<
this << std::endl;
790 #if VERBOSE_EVENT_LOOP 791 yuiDebug() <<
"Event loop still running for " <<
this << std::endl;
795 _waitForEventTimer->stop();
814 _waitForEventTimer->stop();
819 _eventLoop->processEvents( QEventLoop::AllEvents, 10 );
832 if ( !
YQUI::ui()->pendingEvent() && isTopmostDialog() )
846 if ( ! dialog || ! parent )
849 QPoint pos( ( parent->width() - dialog->width() ) / 2,
850 ( parent->height() - dialog->height() ) / 2 );
852 pos += parent->mapToGlobal( QPoint( 0, 0 ) );
853 pos = dialog->mapToParent( dialog->mapFromGlobal( pos ) );
862 if ( _highlightedChild && _highlightedChild->isValid() )
866 QWidget * qw = (QWidget *) _highlightedChild->widgetRep();
870 qw->setPalette( _preHighlightPalette );
871 qw->setAutoFillBackground( _preHighlightAutoFill );
875 _highlightedChild = child;
879 QWidget * qw = (QWidget *) child->widgetRep();
883 _preHighlightPalette = qw->palette();
884 _preHighlightAutoFill = qw->autoFillBackground();
886 qw->setAutoFillBackground(
true );
887 QPalette pal( QColor( 0xff, 0x66, 0x00 ) );
888 pal.setBrush( QPalette::Window, QColor( 0xff, 0xaa, 0x00 ) );
889 pal.setBrush( QPalette::Base , QColor( 0xff, 0xee, 0x00 ) );
891 qw->setPalette( pal );
897 #include "YQDialog.moc" 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()