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 58 YDialogColorMode colorMode )
59 : QWidget( chooseParent( dialogType ),
60 dialogType == YPopupDialog ? YQPopupDialogWFlags : YQMainDialogWFlags )
61 , YDialog( dialogType, colorMode )
68 _highlightedChild = 0;
71 setFocusPolicy( Qt::StrongFocus );
72 setAutoFillBackground(
true );
74 if ( colorMode != YDialogNormalColor )
76 QColor normalBackground ( 240, 100, 36 );
77 QColor inputFieldBackground ( 0xbb, 0xff, 0xbb );
78 QColor text = Qt::black;
80 if ( colorMode == YDialogInfoColor )
82 normalBackground = QColor ( 238, 232, 170 );
85 QPalette warnPalette( normalBackground );
86 warnPalette.setColor( QPalette::Text, text );
87 warnPalette.setColor( QPalette::Base, inputFieldBackground );
88 setPalette( warnPalette );
91 qApp->setApplicationName(
YQUI::ui()->applicationTitle());
92 topLevelWidget()->setWindowTitle (
YQUI::ui()->applicationTitle() );
93 QGuiApplication::setApplicationDisplayName(
YQUI::ui()->applicationTitle() );
97 setWindowFlags( YQPopupDialogWFlags );
100 if ( ! isMainDialog() )
101 setWindowModality( Qt::ApplicationModal );
108 _eventLoop =
new QEventLoop(
this );
109 YUI_CHECK_NEW( _eventLoop );
111 _waitForEventTimer =
new QTimer(
this );
112 YUI_CHECK_NEW( _waitForEventTimer );
113 _waitForEventTimer->setSingleShot(
true );
115 QObject::connect( _waitForEventTimer, &pclass(_waitForEventTimer)::timeout,
127 if ( isMainDialog() )
133 if ( _defaultButton )
134 _defaultButton->forgetDialog();
137 _focusButton->forgetDialog();
154 if ( dialogType == YPopupDialog)
156 YDialog * currentDialog = YDialog::currentDialog(
false );
158 parent = (QWidget *) currentDialog->widgetRep();
161 if ( ( dialogType == YMainDialog || dialogType == YWizardDialog ) &&
164 yuiDebug() <<
"Adding dialog to mainWinDock" << endl;
195 if ( isMainDialog() )
207 int screenWidth = qApp->desktop()->width();
211 yuiWarning() <<
"Limiting dialog width to screen width (" << screenWidth
213 <<
" - check the layout!" 226 if ( isMainDialog() )
238 int screenHeight = qApp->desktop()->height();
242 yuiWarning() <<
"Limiting dialog height to screen height (" << screenHeight
244 <<
" - check the layout!" 255 QWidget::setEnabled( enabled );
256 YDialog::setEnabled( enabled );
265 if ( newWidth > qApp->desktop()->width() )
266 newWidth = qApp->desktop()->width();
268 if ( newHeight > qApp->desktop()->height() )
269 newHeight = qApp->desktop()->height();
271 resize( newWidth, newHeight );
275 firstChild()->setSize( newWidth, newHeight );
276 ( ( QWidget* )firstChild()->widgetRep() )->show();
282 YQDialog::resizeEvent( QResizeEvent * event )
287 setSize ( event->size().width(),
event->size().height() );
288 _userSize =
event->size();
290 if ( QWidget::parent() )
299 if ( _defaultButton )
300 return _defaultButton;
304 YDialog::setDefaultButton( 0 );
305 YDialog::setDefaultButton( _defaultButton );
307 return _defaultButton;
313 YWidgetListConstIterator end )
const 315 for ( YWidgetListConstIterator it = begin; it != end; ++it )
317 YWidget * widget = *it;
325 if ( button && button->isDefaultButton() )
335 if ( widget->hasChildren() )
338 widget->childrenEnd() );
350 YWidgetListConstIterator end )
355 for ( YWidgetListConstIterator it = begin; it != end; ++it )
361 wizard =
dynamic_cast<YQWizard *
> (*it);
369 if ( button->isDefaultButton() )
371 if ( _defaultButton && button != _defaultButton )
373 yuiError() <<
"Too many default buttons: " << button << endl;
374 yuiError() <<
"Using old default button: " << _defaultButton << endl;
378 _defaultButton = button;
386 if ( (*it)->hasChildren() )
389 (*it)->childrenEnd() );
405 if ( ! _defaultButton && wizard )
410 if ( _defaultButton )
412 YDialog::setDefaultButton( 0 );
413 YDialog::setDefaultButton( _defaultButton );
427 return findWizard( childrenBegin(), childrenEnd() );
433 YWidgetListConstIterator end )
const 435 for ( YWidgetListConstIterator it = begin; it != end; ++it )
437 YWidget * widget = *it;
443 if ( widget->hasChildren() )
446 widget->childrenEnd() );
468 if ( wizard->
direction() == YQWizard::Backward )
480 if ( wizard->nextButton()
481 && wizard->nextButton()->
isShown()
484 def = wizard->nextButton();
496 if ( _defaultButton &&
498 newDefaultButton != _defaultButton )
500 if ( dynamic_cast<YQWizardButton *>( _defaultButton ) )
503 _defaultButton->setDefaultButton(
false );
507 yuiError() <<
"Too many `opt(`default) PushButtons: " << newDefaultButton << endl;
508 newDefaultButton->setDefaultButton(
false );
515 if ( _defaultButton )
517 _defaultButton->setDefaultButton(
true );
518 yuiDebug() <<
"New default button: " << _defaultButton << endl;
520 if ( _defaultButton && ! _focusButton )
528 YDialog::setDefaultButton( 0 );
529 YDialog::setDefaultButton( _defaultButton );
542 yuiDebug() <<
"Activating focus button: " << _focusButton << endl;
552 if ( _defaultButton &&
556 yuiDebug() <<
"Activating default button: " << _defaultButton << endl;
564 yuiWarning() <<
"No default button in this dialog - ignoring [Return]" << endl;
575 if ( button == _focusButton )
577 if ( _focusButton && _focusButton != _defaultButton )
583 if ( ! _focusButton && _defaultButton )
591 if ( _focusButton && _focusButton != button )
594 if ( _defaultButton && _defaultButton != button )
597 _focusButton = button;
609 if ( event->key() == Qt::Key_Print )
614 else if ( event->key() == Qt::Key_F4 &&
615 event->modifiers() == Qt::ShiftModifier )
619 if ( QY2Styler::styler()->usingAlternateStyleSheet() )
622 YDialog * currentDialog = YDialog::currentDialog(
false );
624 parent = (QWidget *) currentDialog->widgetRep();
626 yuiMilestone() <<
"Switched to vision impaired palette" << endl;
627 QMessageBox::information( parent,
628 _(
"Color switching"),
629 _(
"Switching to color palette for vision impaired users -\n" 630 "press Shift-F4 again to switch back to normal colors." ),
631 QMessageBox::Ok | QMessageBox::Default,
632 QMessageBox::NoButton,
633 QMessageBox::NoButton );
637 else if ( event->key() == Qt::Key_F6 &&
638 event->modifiers() == Qt::ShiftModifier )
642 else if ( event->key() == Qt::Key_F7 &&
643 event->modifiers() == Qt::ShiftModifier )
648 else if ( event->key() == Qt::Key_F8 &&
649 event->modifiers() == Qt::ShiftModifier )
654 else if ( event->modifiers() == Qt::NoModifier )
656 if ( event->key() == Qt::Key_Return ||
657 event->key() == Qt::Key_Enter )
663 else if ( event->modifiers() == ( Qt::ControlModifier | Qt::ShiftModifier | Qt::AltModifier ) )
667 yuiMilestone() <<
"Caught YaST2 magic key combination" << endl;
669 if ( event->key() == Qt::Key_M )
674 else if ( event->key() == Qt::Key_P )
679 else if ( event->key() == Qt::Key_D )
684 else if ( event->key() == Qt::Key_T )
686 yuiMilestone() <<
"*** Dumping widget tree ***" << endl;
688 yuiMilestone() <<
"*** Widget tree end ***" << endl;
691 else if ( event->key() == Qt::Key_Y )
693 yuiMilestone() <<
"Opening dialog spy" << endl;
694 YDialogSpy::showDialogSpy();
697 else if ( event->key() == Qt::Key_X )
700 yuiMilestone() <<
"Starting xterm" << endl;
701 result = system(
"/usr/bin/xterm &" );
703 yuiError() <<
"/usr/bin/xterm not found" << endl;
706 else if ( event->key() == Qt::Key_S )
708 yuiMilestone() <<
"Opening style editor" << endl;
710 _styleEditor->show();
711 _styleEditor->raise();
712 _styleEditor->activateWindow();
719 QWidget::keyPressEvent( event );
730 yuiMilestone() <<
"Caught window manager close event - returning with YCancelEvent" << endl;
737 YQDialog::focusInEvent( QFocusEvent * event )
744 if ( event->reason() == Qt::TabFocusReason )
746 focusNextPrevChild(
true );
750 if ( _defaultButton )
753 focusNextPrevChild(
true );
762 _eventLoop->wakeUp();
766 _waitForEventTimer->stop();
768 if ( timeout_millisec > 0 )
769 _waitForEventTimer->start( timeout_millisec );
771 if ( qApp->focusWidget() )
772 qApp->focusWidget()->setFocus();
776 if ( ! _eventLoop->isRunning() )
778 #if VERBOSE_EVENT_LOOP 779 yuiDebug() <<
"Executing event loop for " <<
this << endl;
783 #if VERBOSE_EVENT_LOOP 784 yuiDebug() <<
"Event loop finished for " <<
this << endl;
789 #if VERBOSE_EVENT_LOOP 790 yuiDebug() <<
"Event loop still running for " <<
this << endl;
794 _waitForEventTimer->stop();
811 _eventLoop->wakeUp();
815 _waitForEventTimer->stop();
820 _eventLoop->processEvents( QEventLoop::AllEvents, 10 );
833 if ( !
YQUI::ui()->pendingEvent() && isTopmostDialog() )
847 if ( ! dialog || ! parent )
850 QPoint pos( ( parent->width() - dialog->width() ) / 2,
851 ( parent->height() - dialog->height() ) / 2 );
853 pos += parent->mapToGlobal( QPoint( 0, 0 ) );
854 pos = dialog->mapToParent( dialog->mapFromGlobal( pos ) );
863 if ( _highlightedChild && _highlightedChild->isValid() )
867 QWidget * qw = (QWidget *) _highlightedChild->widgetRep();
871 qw->setPalette( _preHighlightPalette );
872 qw->setAutoFillBackground( _preHighlightAutoFill );
876 _highlightedChild = child;
880 QWidget * qw = (QWidget *) child->widgetRep();
884 _preHighlightPalette = qw->palette();
885 _preHighlightAutoFill = qw->autoFillBackground();
887 qw->setAutoFillBackground(
true );
888 QPalette pal( QColor( 0xff, 0x66, 0x00 ) );
889 pal.setBrush( QPalette::Window, QColor( 0xff, 0xaa, 0x00 ) );
890 pal.setBrush( QPalette::Base , QColor( 0xff, 0xee, 0x00 ) );
892 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()