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" 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() );
95 QGuiApplication::setApplicationDisplayName(
YQUI::ui()->applicationTitle() );
99 setWindowFlags( YQPopupDialogWFlags );
102 if ( ! isMainDialog() )
103 setWindowModality( Qt::ApplicationModal );
110 _eventLoop =
new QEventLoop(
this );
111 YUI_CHECK_NEW( _eventLoop );
113 _waitForEventTimer =
new QTimer(
this );
114 YUI_CHECK_NEW( _waitForEventTimer );
115 _waitForEventTimer->setSingleShot(
true );
117 QObject::connect( _waitForEventTimer, &pclass(_waitForEventTimer)::timeout,
129 if ( isMainDialog() )
135 if ( _defaultButton )
136 _defaultButton->forgetDialog();
139 _focusButton->forgetDialog();
156 if ( dialogType == YPopupDialog)
158 YDialog * currentDialog = YDialog::currentDialog(
false );
160 parent = (QWidget *) currentDialog->widgetRep();
163 if ( ( dialogType == YMainDialog || dialogType == YWizardDialog ) &&
166 yuiDebug() <<
"Adding dialog to mainWinDock" << std::endl;
197 if ( isMainDialog() )
209 int screenWidth = qApp->desktop()->width();
213 yuiWarning() <<
"Limiting dialog width to screen width (" << screenWidth
215 <<
" - check the layout!" 228 if ( isMainDialog() )
240 int screenHeight = qApp->desktop()->height();
244 yuiWarning() <<
"Limiting dialog height to screen height (" << screenHeight
246 <<
" - check the layout!" 257 QWidget::setEnabled( enabled );
258 YDialog::setEnabled( enabled );
267 if ( newWidth > qApp->desktop()->width() )
268 newWidth = qApp->desktop()->width();
270 if ( newHeight > qApp->desktop()->height() )
271 newHeight = qApp->desktop()->height();
273 resize( newWidth, newHeight );
277 firstChild()->setSize( newWidth, newHeight );
278 ( ( QWidget* )firstChild()->widgetRep() )->show();
284 YQDialog::resizeEvent( QResizeEvent * event )
289 setSize ( event->size().width(),
event->size().height() );
290 _userSize =
event->size();
292 if ( QWidget::parent() )
301 if ( _defaultButton )
302 return _defaultButton;
306 YDialog::setDefaultButton( 0 );
307 YDialog::setDefaultButton( _defaultButton );
309 return _defaultButton;
315 YWidgetListConstIterator end )
const 317 for ( YWidgetListConstIterator it = begin; it != end; ++it )
319 YWidget * widget = *it;
327 if ( button && button->isDefaultButton() )
337 if ( widget->hasChildren() )
340 widget->childrenEnd() );
352 YWidgetListConstIterator end )
357 for ( YWidgetListConstIterator it = begin; it != end; ++it )
363 wizard =
dynamic_cast<YQWizard *
> (*it);
371 if ( button->isDefaultButton() )
373 if ( _defaultButton && button != _defaultButton )
375 yuiError() <<
"Too many default buttons: " << button << std::endl;
376 yuiError() <<
"Using old default button: " << _defaultButton << std::endl;
380 _defaultButton = button;
388 if ( (*it)->hasChildren() )
391 (*it)->childrenEnd() );
407 if ( ! _defaultButton && wizard )
412 if ( _defaultButton )
414 YDialog::setDefaultButton( 0 );
415 YDialog::setDefaultButton( _defaultButton );
429 return findWizard( childrenBegin(), childrenEnd() );
435 YWidgetListConstIterator end )
const 437 for ( YWidgetListConstIterator it = begin; it != end; ++it )
439 YWidget * widget = *it;
445 if ( widget->hasChildren() )
448 widget->childrenEnd() );
470 if ( wizard->
direction() == YQWizard::Backward )
482 if ( wizard->nextButton()
483 && wizard->nextButton()->
isShown()
486 def = wizard->nextButton();
498 if ( _defaultButton &&
500 newDefaultButton != _defaultButton )
502 if ( dynamic_cast<YQWizardButton *>( _defaultButton ) )
505 _defaultButton->setDefaultButton(
false );
509 yuiError() <<
"Too many `opt(`default) PushButtons: " << newDefaultButton << std::endl;
510 newDefaultButton->setDefaultButton(
false );
517 if ( _defaultButton )
519 _defaultButton->setDefaultButton(
true );
520 yuiDebug() <<
"New default button: " << _defaultButton << std::endl;
522 if ( _defaultButton && ! _focusButton )
530 YDialog::setDefaultButton( 0 );
531 YDialog::setDefaultButton( _defaultButton );
544 yuiDebug() <<
"Activating focus button: " << _focusButton << std::endl;
554 if ( _defaultButton &&
558 yuiDebug() <<
"Activating default button: " << _defaultButton << std::endl;
566 yuiWarning() <<
"No default button in this dialog - ignoring [Return]" << std::endl;
577 if ( button == _focusButton )
579 if ( _focusButton && _focusButton != _defaultButton )
585 if ( ! _focusButton && _defaultButton )
593 if ( _focusButton && _focusButton != button )
596 if ( _defaultButton && _defaultButton != button )
599 _focusButton = button;
611 if ( event->key() == Qt::Key_Print )
616 else if ( event->key() == Qt::Key_F4 &&
617 event->modifiers() == Qt::ShiftModifier )
621 if ( QY2Styler::styler()->usingAlternateStyleSheet() )
624 YDialog * currentDialog = YDialog::currentDialog(
false );
626 parent = (QWidget *) currentDialog->widgetRep();
628 yuiMilestone() <<
"Switched to vision impaired palette" << std::endl;
629 QMessageBox::information( parent,
630 _(
"Color switching"),
631 _(
"Switching to color palette for vision impaired users -\n" 632 "press Shift-F4 again to switch back to normal colors." ),
633 QMessageBox::Ok | QMessageBox::Default,
634 QMessageBox::NoButton,
635 QMessageBox::NoButton );
639 else if ( event->key() == Qt::Key_F6 &&
640 event->modifiers() == Qt::ShiftModifier )
644 else if ( event->key() == Qt::Key_F7 &&
645 event->modifiers() == Qt::ShiftModifier )
650 else if ( event->key() == Qt::Key_F8 &&
651 event->modifiers() == Qt::ShiftModifier )
656 else if ( event->modifiers() == Qt::NoModifier )
658 if ( event->key() == Qt::Key_Return ||
659 event->key() == Qt::Key_Enter )
665 else if ( event->modifiers() == ( Qt::ControlModifier | Qt::ShiftModifier | Qt::AltModifier ) )
669 yuiMilestone() <<
"Caught YaST2 magic key combination" << std::endl;
671 if ( event->key() == Qt::Key_M )
676 else if ( event->key() == Qt::Key_P )
681 else if ( event->key() == Qt::Key_D )
686 else if ( event->key() == Qt::Key_T )
688 yuiMilestone() <<
"*** Dumping widget tree ***" << std::endl;
690 yuiMilestone() <<
"*** Widget tree end ***" << std::endl;
693 else if ( event->key() == Qt::Key_Y )
695 yuiMilestone() <<
"Opening dialog spy" << std::endl;
696 YDialogSpy::showDialogSpy();
699 else if ( event->key() == Qt::Key_X )
702 yuiMilestone() <<
"Starting xterm" << std::endl;
703 result = system(
"/usr/bin/xterm &" );
705 yuiError() <<
"/usr/bin/xterm not found" << std::endl;
708 else if ( event->key() == Qt::Key_S )
710 yuiMilestone() <<
"Opening style editor" << std::endl;
712 _styleEditor->show();
713 _styleEditor->raise();
714 _styleEditor->activateWindow();
721 QWidget::keyPressEvent( event );
732 yuiMilestone() <<
"Caught window manager close event - returning with YCancelEvent" << std::endl;
739 YQDialog::focusInEvent( QFocusEvent * event )
746 if ( event->reason() == Qt::TabFocusReason )
748 focusNextPrevChild(
true );
752 if ( _defaultButton )
755 focusNextPrevChild(
true );
764 _eventLoop->wakeUp();
768 _waitForEventTimer->stop();
770 if ( timeout_millisec > 0 )
771 _waitForEventTimer->start( timeout_millisec );
773 if ( qApp->focusWidget() )
774 qApp->focusWidget()->setFocus();
778 if ( ! _eventLoop->isRunning() )
780 #if VERBOSE_EVENT_LOOP 781 yuiDebug() <<
"Executing event loop for " <<
this << std::endl;
785 #if VERBOSE_EVENT_LOOP 786 yuiDebug() <<
"Event loop finished for " <<
this << std::endl;
791 #if VERBOSE_EVENT_LOOP 792 yuiDebug() <<
"Event loop still running for " <<
this << std::endl;
796 _waitForEventTimer->stop();
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()