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,
119 QY2Styler::styler()->registerWidget(
this );
125 if ( isMainDialog() )
131 if ( _defaultButton )
132 _defaultButton->forgetDialog();
135 _focusButton->forgetDialog();
140 QY2Styler::styler()->unregisterWidget(
this );
149 if ( dialogType == YPopupDialog)
151 YDialog * currentDialog = YDialog::currentDialog(
false );
153 parent = (QWidget *) currentDialog->widgetRep();
156 if ( ( dialogType == YMainDialog || dialogType == YWizardDialog ) &&
159 yuiDebug() <<
"Adding dialog to mainWinDock" << std::endl;
190 if ( isMainDialog() )
193 preferredWidth = _userSize.width();
199 preferredWidth = YDialog::preferredWidth();
202 int screenWidth = qApp->desktop()->width();
204 if ( preferredWidth > screenWidth )
206 yuiWarning() <<
"Limiting dialog width to screen width (" << screenWidth
207 <<
") instead of " << preferredWidth
208 <<
" - check the layout!"
221 if ( isMainDialog() )
224 preferredHeight = _userSize.height();
230 preferredHeight = YDialog::preferredHeight();
233 int screenHeight = qApp->desktop()->height();
235 if ( preferredHeight > screenHeight )
237 yuiWarning() <<
"Limiting dialog height to screen height (" << screenHeight
238 <<
") instead of " << preferredHeight
239 <<
" - check the layout!"
250 QWidget::setEnabled( enabled );
251 YDialog::setEnabled( enabled );
260 if ( newWidth > qApp->desktop()->width() )
261 newWidth = qApp->desktop()->width();
263 if ( newHeight > qApp->desktop()->height() )
264 newHeight = qApp->desktop()->height();
266 resize( newWidth, newHeight );
270 firstChild()->setSize( newWidth, newHeight );
271 ( ( QWidget* )firstChild()->widgetRep() )->show();
277 YQDialog::resizeEvent( QResizeEvent * event )
282 setSize ( event->size().width(),
event->size().height() );
283 _userSize =
event->size();
285 if ( QWidget::parent() )
294 if ( _defaultButton )
295 return _defaultButton;
299 YDialog::setDefaultButton( 0 );
300 YDialog::setDefaultButton( _defaultButton );
302 return _defaultButton;
308 YWidgetListConstIterator end )
const
310 for ( YWidgetListConstIterator it = begin; it != end; ++it )
312 YWidget * widget = *it;
320 if ( button && button->isDefaultButton() )
330 if ( widget->hasChildren() )
333 widget->childrenEnd() );
345 YWidgetListConstIterator end )
350 for ( YWidgetListConstIterator it = begin; it != end; ++it )
356 wizard =
dynamic_cast<YQWizard *
> (*it);
364 if ( button->isDefaultButton() )
366 if ( _defaultButton && button != _defaultButton )
368 yuiError() <<
"Too many default buttons: " << button << std::endl;
369 yuiError() <<
"Using old default button: " << _defaultButton << std::endl;
373 _defaultButton = button;
381 if ( (*it)->hasChildren() )
384 (*it)->childrenEnd() );
400 if ( ! _defaultButton && wizard )
405 if ( _defaultButton )
407 YDialog::setDefaultButton( 0 );
408 YDialog::setDefaultButton( _defaultButton );
422 return findWizard( childrenBegin(), childrenEnd() );
428 YWidgetListConstIterator end )
const
430 for ( YWidgetListConstIterator it = begin; it != end; ++it )
432 YWidget * widget = *it;
438 if ( widget->hasChildren() )
441 widget->childrenEnd() );
463 if ( wizard->
direction() == YQWizard::Backward )
475 if ( wizard->nextButton()
476 && wizard->nextButton()->
isShown()
479 def = wizard->nextButton();
491 if ( _defaultButton &&
493 newDefaultButton != _defaultButton )
495 if ( dynamic_cast<YQWizardButton *>( _defaultButton ) )
498 _defaultButton->setDefaultButton(
false );
502 yuiError() <<
"Too many `opt(`default) PushButtons: " << newDefaultButton << std::endl;
503 newDefaultButton->setDefaultButton(
false );
510 if ( _defaultButton )
512 _defaultButton->setDefaultButton(
true );
513 yuiDebug() <<
"New default button: " << _defaultButton << std::endl;
515 if ( _defaultButton && ! _focusButton )
523 YDialog::setDefaultButton( 0 );
524 YDialog::setDefaultButton( _defaultButton );
537 yuiDebug() <<
"Activating focus button: " << _focusButton << std::endl;
547 if ( _defaultButton &&
551 yuiDebug() <<
"Activating default button: " << _defaultButton << std::endl;
559 yuiWarning() <<
"No default button in this dialog - ignoring [Return]" << std::endl;
570 if ( button == _focusButton )
572 if ( _focusButton && _focusButton != _defaultButton )
578 if ( ! _focusButton && _defaultButton )
586 if ( _focusButton && _focusButton != button )
589 if ( _defaultButton && _defaultButton != button )
592 _focusButton = button;
604 if ( event->key() == Qt::Key_Print )
609 else if ( event->key() == Qt::Key_F4 &&
610 event->modifiers() == Qt::ShiftModifier )
614 if (
YQUI::ui()->usingVisionImpairedPalette() )
617 YDialog * currentDialog = YDialog::currentDialog(
false );
619 parent = (QWidget *) currentDialog->widgetRep();
621 yuiMilestone() <<
"Switched to vision impaired palette" << std::endl;
622 QMessageBox::information( parent,
623 _(
"Color switching"),
624 _(
"Switching to color palette for vision impaired users -\n"
625 "press Shift-F4 again to switch back to normal colors." ),
626 QMessageBox::Ok | QMessageBox::Default,
627 QMessageBox::NoButton,
628 QMessageBox::NoButton );
632 else if ( event->key() == Qt::Key_F7 &&
633 event->modifiers() == Qt::ShiftModifier )
638 else if ( event->key() == Qt::Key_F8 &&
639 event->modifiers() == Qt::ShiftModifier )
644 else if ( event->modifiers() == Qt::NoModifier )
646 if ( event->key() == Qt::Key_Return ||
647 event->key() == Qt::Key_Enter )
653 else if ( event->modifiers() == ( Qt::ControlModifier | Qt::ShiftModifier | Qt::AltModifier ) )
657 yuiMilestone() <<
"Caught YaST2 magic key combination" << std::endl;
659 if ( event->key() == Qt::Key_M )
664 else if ( event->key() == Qt::Key_P )
669 else if ( event->key() == Qt::Key_D )
674 else if ( event->key() == Qt::Key_T )
676 yuiMilestone() <<
"*** Dumping widget tree ***" << std::endl;
678 yuiMilestone() <<
"*** Widget tree end ***" << std::endl;
681 else if ( event->key() == Qt::Key_Y )
683 yuiMilestone() <<
"Opening dialog spy" << std::endl;
684 YDialogSpy::showDialogSpy();
687 else if ( event->key() == Qt::Key_X )
690 yuiMilestone() <<
"Starting xterm" << std::endl;
691 result = system(
"/usr/bin/xterm &" );
693 yuiError() <<
"/usr/bin/xterm not found" << std::endl;
696 else if ( event->key() == Qt::Key_S )
698 yuiMilestone() <<
"Opening style editor" << std::endl;
700 _styleEditor->show();
701 _styleEditor->raise();
702 _styleEditor->activateWindow();
709 QWidget::keyPressEvent( event );
720 yuiMilestone() <<
"Caught window manager close event - returning with YCancelEvent" << std::endl;
727 YQDialog::focusInEvent( QFocusEvent * event )
734 if ( event->reason() == Qt::TabFocusReason )
736 focusNextPrevChild(
true );
740 if ( _defaultButton )
743 focusNextPrevChild(
true );
752 _eventLoop->wakeUp();
756 _waitForEventTimer->stop();
758 if ( timeout_millisec > 0 )
759 _waitForEventTimer->start( timeout_millisec );
761 if ( qApp->focusWidget() )
762 qApp->focusWidget()->setFocus();
766 if ( ! _eventLoop->isRunning() )
768 #if VERBOSE_EVENT_LOOP
769 yuiDebug() <<
"Executing event loop for " <<
this << std::endl;
773 #if VERBOSE_EVENT_LOOP
774 yuiDebug() <<
"Event loop finished for " <<
this << std::endl;
779 #if VERBOSE_EVENT_LOOP
780 yuiDebug() <<
"Event loop still running for " <<
this << std::endl;
784 _waitForEventTimer->stop();
803 _waitForEventTimer->stop();
808 _eventLoop->processEvents( QEventLoop::AllEvents, 10 );
833 if ( ! dialog || ! parent )
836 QPoint pos( ( parent->width() - dialog->width() ) / 2,
837 ( parent->height() - dialog->height() ) / 2 );
839 pos += parent->mapToGlobal( QPoint( 0, 0 ) );
840 pos = dialog->mapToParent( dialog->mapFromGlobal( pos ) );
849 if ( _highlightedChild && _highlightedChild->isValid() )
853 QWidget * qw = (QWidget *) _highlightedChild->widgetRep();
857 qw->setPalette( _preHighlightPalette );
858 qw->setAutoFillBackground( _preHighlightAutoFill );
862 _highlightedChild = child;
866 QWidget * qw = (QWidget *) child->widgetRep();
870 _preHighlightPalette = qw->palette();
871 _preHighlightAutoFill = qw->autoFillBackground();
873 qw->setAutoFillBackground(
true );
874 QPalette pal( QColor( 0xff, 0x66, 0x00 ) );
875 pal.setBrush( QPalette::Window, QColor( 0xff, 0xaa, 0x00 ) );
876 pal.setBrush( QPalette::Base , QColor( 0xff, 0xee, 0x00 ) );
878 qw->setPalette( pal );
884 #include "YQDialog.moc"
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).
virtual void highlight(YWidget *child)
Highlight a child widget of this dialog.
int defaultSize(YUIDimension dim) const
Returns size for opt(defaultsize) dialogs (in one dimension).
virtual void keyPressEvent(QKeyEvent *event)
Qt event handlers.
Direction direction() const
Returns the current direction of wizard operations - going forward or going backward.
void makeScreenShot(std::string filename)
Make a screen shot in .png format and save it to 'filename'.
YQWizard * findWizard() const
Find the first wizard in that dialog, if there is any.
void askSaveLogs()
Open file selection box and let the user save y2logs to that location.
virtual ~YQDialog()
Destructor.
void toggleRecordMacro()
Toggle macro recording (activated by Ctrl-Shift-Alt-M): Stop macro recording if it is in progress...
void add(YQDialog *dialog)
Add a dialog (the widgetRep() of a YQDialog) to the MainWinDock (on top of its widget stack...
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'.
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.
virtual YQWizardButton * backButton() const
Return internal widgets.
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.
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".
YQGenericButton * wizardDefaultButton(YQWizard *wizard) const
Find a wizard button that would make sense as a default button.
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 toggleVisionImpairedPalette()
Toggle between the vision impaired and the normal color palette.
static YQUI * ui()
Access the global Qt-UI.
void waitForEventTimeout()
Timeout during waitForEvent()