libyui-qt  2.49.16
YQDialog.cc
1 /*
2  Copyright (C) 2000-2012 Novell, Inc
3  This library is free software; you can redistribute it and/or modify
4  it under the terms of the GNU Lesser General Public License as
5  published by the Free Software Foundation; either version 2.1 of the
6  License, or (at your option) version 3.0 of the License. This library
7  is distributed in the hope that it will be useful, but WITHOUT ANY
8  WARRANTY; without even the implied warranty of MERCHANTABILITY or
9  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10  License for more details. You should have received a copy of the GNU
11  Lesser General Public License along with this library; if not, write
12  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
13  Floor, Boston, MA 02110-1301 USA
14 */
15 
16 
17 /*-/
18 
19  File: YQDialog.cc
20 
21  Author: Stefan Hundhammer <sh@suse.de>
22 
23  Textdomain "qt"
24 
25 /-*/
26 
27 
28 #define YUILogComponent "qt-ui"
29 #include <yui/YUILog.h>
30 #include <qpushbutton.h>
31 #include <qmessagebox.h>
32 #include <QDesktopWidget>
33 #include <QDebug>
34 
35 #include "YQUI.h"
36 #include "YQi18n.h"
37 #include <yui/YEvent.h>
38 #include "YQDialog.h"
39 #include "YQGenericButton.h"
40 #include "YQWizardButton.h"
41 #include "YQWizard.h"
42 #include "YQMainWinDock.h"
43 #include <yui/YDialogSpy.h>
44 #include <yui/YApplication.h>
45 #include "QY2Styler.h"
46 #include "QY2StyleEditor.h"
47 
48 // Include low-level X headers AFTER Qt headers:
49 // X.h pollutes the global namespace (!!!) with pretty useless #defines
50 // like "Above", "Below" etc. that clash with some Qt headers.
51 #include <X11/Xlib.h>
52 
53 #define YQMainDialogWFlags Qt::Widget
54 #define YQPopupDialogWFlags Qt::Dialog
55 
56 #define VERBOSE_EVENT_LOOP 0
57 
58 
59 
60 YQDialog::YQDialog( YDialogType dialogType,
61  YDialogColorMode colorMode )
62  : QWidget( chooseParent( dialogType ),
63  dialogType == YPopupDialog ? YQPopupDialogWFlags : YQMainDialogWFlags )
64  , YDialog( dialogType, colorMode )
65 {
66  setWidgetRep( this );
67 
68  _userResized = false;
69  _focusButton = 0;
70  _defaultButton = 0;
71  _highlightedChild = 0;
72  _styleEditor = 0;
73 
74  setFocusPolicy( Qt::StrongFocus );
75  setAutoFillBackground( true );
76 
77  if ( colorMode != YDialogNormalColor )
78  {
79  QColor normalBackground ( 240, 100, 36 );
80  QColor inputFieldBackground ( 0xbb, 0xff, 0xbb );
81  QColor text = Qt::black;
82 
83  if ( colorMode == YDialogInfoColor )
84  {
85  normalBackground = QColor ( 238, 232, 170 ); // PaleGoldenrod
86  }
87 
88  QPalette warnPalette( normalBackground );
89  warnPalette.setColor( QPalette::Text, text );
90  warnPalette.setColor( QPalette::Base, inputFieldBackground );
91  setPalette( warnPalette );
92  }
93  qApp->setApplicationName(YQUI::ui()->applicationTitle());
94  topLevelWidget()->setWindowTitle ( YQUI::ui()->applicationTitle() );
95  QGuiApplication::setApplicationDisplayName( YQUI::ui()->applicationTitle() );
96 
97  if ( isMainDialog() && QWidget::parent() != YQMainWinDock::mainWinDock() )
98  {
99  setWindowFlags( YQPopupDialogWFlags );
100  }
101 
102  if ( ! isMainDialog() )
103  setWindowModality( Qt::ApplicationModal );
104 
105  if ( isMainDialog() && QWidget::parent() == YQMainWinDock::mainWinDock() )
106  {
107  YQMainWinDock::mainWinDock()->add( this );
108  }
109 
110  _eventLoop = new QEventLoop( this );
111  YUI_CHECK_NEW( _eventLoop );
112 
113  _waitForEventTimer = new QTimer( this );
114  YUI_CHECK_NEW( _waitForEventTimer );
115  _waitForEventTimer->setSingleShot( true );
116 
117  QObject::connect( _waitForEventTimer, &pclass(_waitForEventTimer)::timeout,
118  this, &pclass(this)::waitForEventTimeout );
119 
120  if ( isMainDialog() && QWidget::parent() == YQMainWinDock::mainWinDock() )
121  QY2Styler::styler()->registerWidget( YQMainWinDock::mainWinDock() );
122  else
123  QY2Styler::styler()->registerWidget( this );
124 }
125 
126 
128 {
129  if ( isMainDialog() )
130  {
132  // orphaned main dialogs are handled gracefully in YQWMainWinDock::remove()
133  }
134 
135  if ( _defaultButton )
136  _defaultButton->forgetDialog();
137 
138  if ( _focusButton )
139  _focusButton->forgetDialog();
140 
141  if ( _styleEditor )
142  delete _styleEditor;
143 
144  if ( isMainDialog() && QWidget::parent() == YQMainWinDock::mainWinDock() )
145  QY2Styler::styler()->unregisterWidget( YQMainWinDock::mainWinDock() );
146  else
147  QY2Styler::styler()->unregisterWidget( this );
148 }
149 
150 
151 QWidget *
152 YQDialog::chooseParent( YDialogType dialogType )
153 {
154  QWidget * parent = YQMainWinDock::mainWinDock()->window();
155 
156  if ( dialogType == YPopupDialog)
157  {
158  YDialog * currentDialog = YDialog::currentDialog( false );
159  if (currentDialog)
160  parent = (QWidget *) currentDialog->widgetRep();
161  }
162 
163  if ( ( dialogType == YMainDialog || dialogType == YWizardDialog ) &&
164  YQMainWinDock::mainWinDock()->couldDock() )
165  {
166  yuiDebug() << "Adding dialog to mainWinDock" << std::endl;
167  parent = YQMainWinDock::mainWinDock();
168  }
169 
170  return parent;
171 }
172 
173 
174 void
176 {
178  QWidget::show();
179  QWidget::raise(); // FIXME: is this really necessary?
180  QWidget::update();
181 }
182 
183 
184 void
186 {
187  QWidget::raise();
188  QWidget::update();
189 }
190 
191 
192 int
194 {
195  int preferredWidth;
196 
197  if ( isMainDialog() )
198  {
199  if ( userResized() )
200  preferredWidth = _userSize.width();
201  else
202  preferredWidth = YQUI::ui()->defaultSize( YD_HORIZ );
203  }
204  else
205  {
206  preferredWidth = YDialog::preferredWidth();
207  }
208 
209  int screenWidth = qApp->desktop()->width();
210 
211  if ( preferredWidth > screenWidth )
212  {
213  yuiWarning() << "Limiting dialog width to screen width (" << screenWidth
214  << ") instead of " << preferredWidth
215  << " - check the layout!"
216  << std::endl;
217  }
218 
219  return preferredWidth;
220 }
221 
222 
223 int
225 {
226  int preferredHeight;
227 
228  if ( isMainDialog() )
229  {
230  if ( userResized() )
231  preferredHeight = _userSize.height();
232  else
233  preferredHeight = YQUI::ui()->defaultSize( YD_VERT );
234  }
235  else
236  {
237  preferredHeight = YDialog::preferredHeight();
238  }
239 
240  int screenHeight = qApp->desktop()->height();
241 
242  if ( preferredHeight > screenHeight )
243  {
244  yuiWarning() << "Limiting dialog height to screen height (" << screenHeight
245  << ") instead of " << preferredHeight
246  << " - check the layout!"
247  << std::endl;
248  }
249 
250  return preferredHeight;
251 }
252 
253 
254 void
255 YQDialog::setEnabled( bool enabled )
256 {
257  QWidget::setEnabled( enabled );
258  YDialog::setEnabled( enabled );
259 }
260 
261 
262 void
263 YQDialog::setSize( int newWidth, int newHeight )
264 {
265  // yuiDebug() << "Resizing dialog to " << newWidth << " x " << newHeight << std::endl;
266 
267  if ( newWidth > qApp->desktop()->width() )
268  newWidth = qApp->desktop()->width();
269 
270  if ( newHeight > qApp->desktop()->height() )
271  newHeight = qApp->desktop()->height();
272 
273  resize( newWidth, newHeight );
274 
275  if ( hasChildren() )
276  {
277  firstChild()->setSize( newWidth, newHeight );
278  ( ( QWidget* )firstChild()->widgetRep() )->show();
279  }
280 }
281 
282 
283 void
284 YQDialog::resizeEvent( QResizeEvent * event )
285 {
286  if ( event )
287  {
288  // yuiDebug() << "Resize event: " << event->size().width() << " x " << event->size().height() << std::endl;
289  setSize ( event->size().width(), event->size().height() );
290  _userSize = event->size();
291 
292  if ( QWidget::parent() )
293  _userResized = true;
294  }
295 }
296 
297 
300 {
301  if ( _defaultButton )
302  return _defaultButton;
303 
304  _defaultButton = findDefaultButton( childrenBegin(), childrenEnd() );
305 
306  YDialog::setDefaultButton( 0 ); // prevent complaints about multiple default buttons
307  YDialog::setDefaultButton( _defaultButton );
308 
309  return _defaultButton;
310 }
311 
312 
314 YQDialog::findDefaultButton( YWidgetListConstIterator begin,
315  YWidgetListConstIterator end ) const
316 {
317  for ( YWidgetListConstIterator it = begin; it != end; ++it )
318  {
319  YWidget * widget = *it;
320 
321  //
322  // Check this widget
323  //
324 
325  YQGenericButton * button = dynamic_cast<YQGenericButton *> (widget);
326 
327  if ( button && button->isDefaultButton() )
328  {
329  return button;
330  }
331 
332 
333  //
334  // Recurse over the children of this widget
335  //
336 
337  if ( widget->hasChildren() )
338  {
339  button = findDefaultButton( widget->childrenBegin(),
340  widget->childrenEnd() );
341  if ( button )
342  return button;
343  }
344  }
345 
346  return 0;
347 }
348 
349 
350 YQWizard *
351 YQDialog::ensureOnlyOneDefaultButton( YWidgetListConstIterator begin,
352  YWidgetListConstIterator end )
353 {
354  YQGenericButton * def = _focusButton ? _focusButton : _defaultButton;
355  YQWizard * wizard = 0;
356 
357  for ( YWidgetListConstIterator it = begin; it != end; ++it )
358  {
359  YQGenericButton * button = dynamic_cast<YQGenericButton *> (*it);
360  YQWizardButton * wizardButton = dynamic_cast<YQWizardButton * > (*it);
361 
362  if ( ! wizard )
363  wizard = dynamic_cast<YQWizard *> (*it);
364 
365  if ( wizardButton )
366  {
367  wizardButton->showAsDefault( false );
368  }
369  else if ( button )
370  {
371  if ( button->isDefaultButton() )
372  {
373  if ( _defaultButton && button != _defaultButton )
374  {
375  yuiError() << "Too many default buttons: " << button << std::endl;
376  yuiError() << "Using old default button: " << _defaultButton << std::endl;
377  }
378  else
379  {
380  _defaultButton = button;
381  }
382  }
383 
384  if ( button->isShownAsDefault() && button != def )
385  button->showAsDefault( false );
386  }
387 
388  if ( (*it)->hasChildren() )
389  {
390  YQWizard * wiz = ensureOnlyOneDefaultButton( (*it)->childrenBegin(),
391  (*it)->childrenEnd() );
392  if ( wiz )
393  wizard = wiz;
394  }
395  }
396 
397  return wizard;
398 }
399 
400 
401 void
403 {
404  _defaultButton = 0;
405  YQWizard * wizard = ensureOnlyOneDefaultButton( childrenBegin(), childrenEnd() );
406 
407  if ( ! _defaultButton && wizard )
408  {
409  _defaultButton = wizardDefaultButton( wizard );
410  }
411 
412  if ( _defaultButton )
413  {
414  YDialog::setDefaultButton( 0 ); // prevent complaints about multiple default buttons
415  YDialog::setDefaultButton( _defaultButton );
416  }
417 
418 
419  YQGenericButton * def = _focusButton ? _focusButton : _defaultButton;
420 
421  if ( def )
422  def->showAsDefault();
423 }
424 
425 
426 YQWizard *
428 {
429  return findWizard( childrenBegin(), childrenEnd() );
430 }
431 
432 
433 YQWizard *
434 YQDialog::findWizard( YWidgetListConstIterator begin,
435  YWidgetListConstIterator end ) const
436 {
437  for ( YWidgetListConstIterator it = begin; it != end; ++it )
438  {
439  YWidget * widget = *it;
440  YQWizard * wizard = dynamic_cast<YQWizard *> (widget);
441 
442  if ( wizard )
443  return wizard;
444 
445  if ( widget->hasChildren() )
446  {
447  wizard = findWizard( widget->childrenBegin(),
448  widget->childrenEnd() );
449  if ( wizard )
450  return wizard;
451  }
452  }
453 
454  return 0;
455 }
456 
457 
460 {
461  YQGenericButton * def = 0;
462 
463  if ( ! wizard )
464  wizard = findWizard();
465 
466  if ( wizard )
467  {
468  // Pick one of the wizard buttons
469 
470  if ( wizard->direction() == YQWizard::Backward )
471  {
472  if ( wizard->backButton()
473  && wizard->backButton()->isShown()
474  && wizard->backButton()->isEnabled() )
475  {
476  def = wizard->backButton();
477  }
478  }
479 
480  if ( ! def )
481  {
482  if ( wizard->nextButton()
483  && wizard->nextButton()->isShown()
484  && wizard->nextButton()->isEnabled() )
485  {
486  def = wizard->nextButton();
487  }
488  }
489  }
490 
491  return def;
492 }
493 
494 
495 void
496 YQDialog::setDefaultButton( YPushButton * newDefaultButton )
497 {
498  if ( _defaultButton &&
499  newDefaultButton &&
500  newDefaultButton != _defaultButton )
501  {
502  if ( dynamic_cast<YQWizardButton *>( _defaultButton ) )
503  {
504  // Let app defined default buttons override wizard buttons
505  _defaultButton->setDefaultButton( false );
506  }
507  else
508  {
509  yuiError() << "Too many `opt(`default) PushButtons: " << newDefaultButton << std::endl;
510  newDefaultButton->setDefaultButton( false );
511  return;
512  }
513  }
514 
515  _defaultButton = dynamic_cast<YQGenericButton*>(newDefaultButton);
516 
517  if ( _defaultButton )
518  {
519  _defaultButton->setDefaultButton( true );
520  yuiDebug() << "New default button: " << _defaultButton << std::endl;
521 
522  if ( _defaultButton && ! _focusButton )
523  {
524  _defaultButton->showAsDefault( true );
525  _defaultButton->setKeyboardFocus();
526  }
527  }
528 
529 
530  YDialog::setDefaultButton( 0 ); // prevent complaints about multiple default buttons
531  YDialog::setDefaultButton( _defaultButton );
532 }
533 
534 
535 bool
537 {
538  // Try the focus button first, if there is any.
539 
540  if ( _focusButton &&
541  _focusButton->isEnabled() &&
542  _focusButton->isShownAsDefault() )
543  {
544  yuiDebug() << "Activating focus button: " << _focusButton << std::endl;
545  _focusButton->activate();
546  return true;
547  }
548 
549 
550  // No focus button - try the default button, if there is any.
551 
552  _defaultButton = findDefaultButton();
553 
554  if ( _defaultButton &&
555  _defaultButton->isEnabled() &&
556  _defaultButton->isShownAsDefault() )
557  {
558  yuiDebug() << "Activating default button: " << _defaultButton << std::endl;
559  _defaultButton->activate();
560  return true;
561  }
562  else
563  {
564  if ( warn )
565  {
566  yuiWarning() << "No default button in this dialog - ignoring [Return]" << std::endl;
567  }
568  }
569 
570  return false;
571 }
572 
573 
574 void
576 {
577  if ( button == _focusButton )
578  {
579  if ( _focusButton && _focusButton != _defaultButton )
580  _focusButton->showAsDefault( false );
581 
582  _focusButton = 0;
583  }
584 
585  if ( ! _focusButton && _defaultButton )
586  _defaultButton->showAsDefault( true );
587 }
588 
589 
590 void
592 {
593  if ( _focusButton && _focusButton != button )
594  _focusButton->showAsDefault( false );
595 
596  if ( _defaultButton && _defaultButton != button )
597  _defaultButton->showAsDefault( false );
598 
599  _focusButton = button;
600 
601  if ( _focusButton )
602  _focusButton->showAsDefault( true );
603 }
604 
605 
606 void
607 YQDialog::keyPressEvent( QKeyEvent * event )
608 {
609  if ( event )
610  {
611  if ( event->key() == Qt::Key_Print )
612  {
613  YQUI::ui()->makeScreenShot( "" );
614  return;
615  }
616  else if ( event->key() == Qt::Key_F4 && // Shift-F4: toggle colors for vision impaired users
617  event->modifiers() == Qt::ShiftModifier )
618  {
619  QY2Styler::styler()->toggleAlternateStyleSheet();
620 
621  if ( QY2Styler::styler()->usingAlternateStyleSheet() )
622  {
623  QWidget* parent = 0;
624  YDialog * currentDialog = YDialog::currentDialog( false );
625  if (currentDialog)
626  parent = (QWidget *) currentDialog->widgetRep();
627 
628  yuiMilestone() << "Switched to vision impaired palette" << std::endl;
629  QMessageBox::information( parent, // parent
630  _("Color switching"), // caption
631  _( "Switching to color palette for vision impaired users -\n"
632  "press Shift-F4 again to switch back to normal colors." ), // text
633  QMessageBox::Ok | QMessageBox::Default, // button0
634  QMessageBox::NoButton, // button1
635  QMessageBox::NoButton ); // button2
636  }
637  return;
638  }
639  else if ( event->key() == Qt::Key_F6 && // Shift-F6: ask for a widget ID and send it
640  event->modifiers() == Qt::ShiftModifier )
641  {
643  }
644  else if ( event->key() == Qt::Key_F7 && // Shift-F7: toggle debug logging
645  event->modifiers() == Qt::ShiftModifier )
646  {
648  return;
649  }
650  else if ( event->key() == Qt::Key_F8 && // Shift-F8: save y2logs
651  event->modifiers() == Qt::ShiftModifier )
652  {
653  YQUI::ui()->askSaveLogs();
654  return;
655  }
656  else if ( event->modifiers() == Qt::NoModifier ) // No Ctrl / Alt / Shift etc. pressed
657  {
658  if ( event->key() == Qt::Key_Return ||
659  event->key() == Qt::Key_Enter )
660  {
661  (void) activateDefaultButton();
662  return;
663  }
664  }
665  else if ( event->modifiers() == ( Qt::ControlModifier | Qt::ShiftModifier | Qt::AltModifier ) )
666  {
667  // Qt-UI special keys - all with Ctrl-Shift-Alt
668 
669  yuiMilestone() << "Caught YaST2 magic key combination" << std::endl;
670 
671  if ( event->key() == Qt::Key_M )
672  {
674  return;
675  }
676  else if ( event->key() == Qt::Key_P )
677  {
678  YQUI::ui()->askPlayMacro();
679  return;
680  }
681  else if ( event->key() == Qt::Key_D )
682  {
683  YQUI::ui()->sendEvent( new YDebugEvent() );
684  return;
685  }
686  else if ( event->key() == Qt::Key_T )
687  {
688  yuiMilestone() << "*** Dumping widget tree ***" << std::endl;
689  dumpWidgetTree();
690  yuiMilestone() << "*** Widget tree end ***" << std::endl;
691  return;
692  }
693  else if ( event->key() == Qt::Key_Y )
694  {
695  yuiMilestone() << "Opening dialog spy" << std::endl;
696  YDialogSpy::showDialogSpy();
697  YQUI::ui()->normalCursor();
698  }
699  else if ( event->key() == Qt::Key_X )
700  {
701  int result;
702  yuiMilestone() << "Starting xterm" << std::endl;
703  result = system( "/usr/bin/xterm &" );
704  if (result < 0)
705  yuiError() << "/usr/bin/xterm not found" << std::endl;
706  return;
707  }
708  else if ( event->key() == Qt::Key_S )
709  {
710  yuiMilestone() << "Opening style editor" << std::endl;
711  _styleEditor = new QY2StyleEditor(this);
712  _styleEditor->show();
713  _styleEditor->raise();
714  _styleEditor->activateWindow();
715  return;
716  }
717 
718  }
719  }
720 
721  QWidget::keyPressEvent( event );
722 }
723 
724 
725 void
726 YQDialog::closeEvent( QCloseEvent * event )
727 {
728  // The window manager "close window" button (and WM menu, e.g. Alt-F4) will be
729  // handled just like the user had clicked on the `id`( `cancel ) button in
730  // that dialog. It's up to the YCP application to handle this (if desired).
731 
732  yuiMilestone() << "Caught window manager close event - returning with YCancelEvent" << std::endl;
733  event->ignore();
734  YQUI::ui()->sendEvent( new YCancelEvent() );
735 }
736 
737 
738 void
739 YQDialog::focusInEvent( QFocusEvent * event )
740 {
741  // The dialog itself doesn't need or want the keyboard focus, but obviously
742  // (since Qt 2.3?) it needs QFocusPolicy::StrongFocus for the default
743  // button mechanism to work. So let's accept the focus and give it to some
744  // child widget.
745 
746  if ( event->reason() == Qt::TabFocusReason )
747  {
748  focusNextPrevChild( true );
749  }
750  else
751  {
752  if ( _defaultButton )
753  _defaultButton->setKeyboardFocus();
754  else
755  focusNextPrevChild( true );
756  }
757 }
758 
759 
760 YEvent *
761 YQDialog::waitForEventInternal( int timeout_millisec )
762 {
764  _eventLoop->wakeUp();
765 
766  YEvent * event = 0;
767 
768  _waitForEventTimer->stop();
769 
770  if ( timeout_millisec > 0 )
771  _waitForEventTimer->start( timeout_millisec ); // single shot
772 
773  if ( qApp->focusWidget() )
774  qApp->focusWidget()->setFocus();
775 
776  YQUI::ui()->normalCursor();
777 
778  if ( ! _eventLoop->isRunning() )
779  {
780 #if VERBOSE_EVENT_LOOP
781  yuiDebug() << "Executing event loop for " << this << std::endl;
782 #endif
783  _eventLoop->exec();
784 
785 #if VERBOSE_EVENT_LOOP
786  yuiDebug() << "Event loop finished for " << this << std::endl;
787 #endif
788  }
789  else
790  {
791 #if VERBOSE_EVENT_LOOP
792  yuiDebug() << "Event loop still running for " << this << std::endl;
793 #endif
794  }
795 
796  _waitForEventTimer->stop();
797  event = YQUI::ui()->consumePendingEvent();
798 
799 
800  // Prepare a busy cursor if the UI cannot respond to user input within the
801  // next 200 milliseconds (if the application doesn't call waitForEvent()
802  // within this time again)
803 
805 
806  return event;
807 }
808 
809 
810 YEvent *
812 {
813  YEvent * event = 0;
814 
815  _waitForEventTimer->stop(); // just in case it's still running
816 
817  if ( ! YQUI::ui()->pendingEvent() )
818  {
819  // Very short (10 millisec) event loop
820  _eventLoop->processEvents( QEventLoop::AllEvents, 10 );
821  }
822 
823  if ( YQUI::ui()->pendingEvent() )
824  event = YQUI::ui()->consumePendingEvent();
825 
826  return event;
827 }
828 
829 
830 void
832 {
833  if ( ! YQUI::ui()->pendingEvent() && isTopmostDialog() )
834  {
835  // Don't override a pending event with a timeout event
836  // and don't deliver the timeout event if another dialog opened in the
837  // meantime
838 
839  YQUI::ui()->sendEvent( new YTimeoutEvent() );
840  }
841 }
842 
843 
844 void
845 YQDialog::center( QWidget * dialog, QWidget * parent )
846 {
847  if ( ! dialog || ! parent )
848  return;
849 
850  QPoint pos( ( parent->width() - dialog->width() ) / 2,
851  ( parent->height() - dialog->height() ) / 2 );
852 
853  pos += parent->mapToGlobal( QPoint( 0, 0 ) );
854  pos = dialog->mapToParent( dialog->mapFromGlobal( pos ) );
855  qDebug() << pos;
856  dialog->move( pos );
857 }
858 
859 
860 void
861 YQDialog::highlight( YWidget * child )
862 {
863  if ( _highlightedChild && _highlightedChild->isValid() )
864  {
865  // Un-highlight old highlighted child widget
866 
867  QWidget * qw = (QWidget *) _highlightedChild->widgetRep();
868 
869  if ( qw )
870  {
871  qw->setPalette( _preHighlightPalette );
872  qw->setAutoFillBackground( _preHighlightAutoFill );
873  }
874  }
875 
876  _highlightedChild = child;
877 
878  if ( child )
879  {
880  QWidget * qw = (QWidget *) child->widgetRep();
881 
882  if ( qw )
883  {
884  _preHighlightPalette = qw->palette();
885  _preHighlightAutoFill = qw->autoFillBackground();
886 
887  qw->setAutoFillBackground( true );
888  QPalette pal( QColor( 0xff, 0x66, 0x00 ) ); // Button color
889  pal.setBrush( QPalette::Window, QColor( 0xff, 0xaa, 0x00 ) ); // Window background
890  pal.setBrush( QPalette::Base , QColor( 0xff, 0xee, 0x00 ) ); // Table etc. background
891 
892  qw->setPalette( pal );
893  }
894  }
895 }
896 
897 
898 
int defaultSize(YUIDimension dim) const
Returns size for opt(defaultsize) dialogs (in one dimension).
Definition: YQUI.cc:576
YQWizard * findWizard() const
Find the first wizard in that dialog, if there is any.
Definition: YQDialog.cc:427
YQGenericButton * findDefaultButton()
Return this dialog&#39;s (first) default button or 0 if none.
Definition: YQDialog.cc:299
Stylesheet Editor Dialog.
void activate()
Activate (animated) this button.
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...
Definition: YQUI.cc:537
void remove(YQDialog *dialog=0)
Remove a dialog from the MainWinDock (if it belongs to the MainWinDock).
void showAsDefault(bool show=true)
Show this button as the dialog&#39;s default button.
Direction direction() const
Returns the current direction of wizard operations - going forward or going backward.
Definition: YQWizard.h:101
virtual void highlight(YWidget *child)
Highlight a child widget of this dialog.
Definition: YQDialog.cc:861
virtual void keyPressEvent(QKeyEvent *event)
Qt event handlers.
Definition: YQDialog.cc:607
bool isEnabled() const
Returns &#39;true&#39; if this button is enabled, &#39;false&#39; otherwise.
void makeScreenShot(std::string filename)
Make a screen shot in .png format and save it to &#39;filename&#39;.
void askSaveLogs()
Open file selection box and let the user save y2logs to that location.
virtual ~YQDialog()
Destructor.
Definition: YQDialog.cc:127
void toggleAlternateStyleSheet()
Toggle between default/alternate style sheets.
Definition: QY2Styler.cc:193
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.
Definition: QY2Styler.cc:268
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.
Definition: YQWizard.h:112
virtual int preferredWidth()
Preferred width of the widget.
Definition: YQDialog.cc:193
virtual YEvent * waitForEventInternal(int timeout_millisec)
Wait for a user event.
Definition: YQDialog.cc:761
static void center(QWidget *dialog, QWidget *parent=0)
Center a dialog relative to &#39;parent&#39;.
Definition: YQDialog.cc:845
bool isShown() const
Returns &#39;true&#39; if the associated QPushButton (!) is shown.
void askSendWidgetID()
Open a pop-up dialog to ask the user for a widget ID and then send it with sendWidgetID().
Definition: YQUI.cc:602
virtual bool setKeyboardFocus()
Accept the keyboard focus.
bool isShownAsDefault() const
Returns &#39;true&#39; if this button is shown as a default button - which may mean that this really is the d...
virtual void activate()
Activate this dialog: Make sure that it is shown as the topmost dialog of this application and that i...
Definition: YQDialog.cc:185
virtual void setEnabled(bool enabled)
Set enabled/disabled state.
Definition: YQDialog.cc:255
void gettingFocus(YQGenericButton *button)
Notification that a button gets the keyboard focus.
Definition: YQDialog.cc:591
static YQMainWinDock * mainWinDock()
Static method to access the singleton for this class.
void setDefaultButton(YPushButton *newDefaultButton)
Set the dialog&#39;s default button - the button that is activated with [Return] if no other button has t...
Definition: YQDialog.cc:496
Abstract base class for push button and similar widgets - all that can become a YQDialog&#39;s "default b...
void sendEvent(YEvent *event)
Widget event handlers (slots) call this when an event occured that should be the answer to a UserInpu...
Definition: YQUI.cc:469
virtual void openInternal()
Internal open() method, called exactly once during the life time of the dialog in open()...
Definition: YQDialog.cc:175
bool userResized()
Return &#39;true&#39; if the user resized this dialog.
Definition: YQDialog.h:116
YQDialog(YDialogType dialogType, YDialogColorMode colorMode=YDialogNormalColor)
Constructor.
Definition: YQDialog.cc:60
YQGenericButton * wizardDefaultButton(YQWizard *wizard) const
Find a wizard button that would make sense as a default button.
Definition: YQDialog.cc:459
bool activateDefaultButton(bool warn=true)
Activate (i.e.
Definition: YQDialog.cc:536
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 ...
Definition: YQDialog.cc:152
void losingFocus(YQGenericButton *button)
Notification that a button loses the keyboard focus.
Definition: YQDialog.cc:575
virtual void setSize(int newWidth, int newHeight)
Set the new size of the widget.
Definition: YQDialog.cc:263
YEvent * consumePendingEvent()
Return the pending event, if there is one, and mark it as "consumed".
Definition: YQUI.h:155
virtual YEvent * pollEventInternal()
Check if a user event is pending.
Definition: YQDialog.cc:811
void timeoutBusyCursor()
Show mouse cursor indicating busy state if the UI is unable to respond to user input for more than a ...
Definition: YQUI.cc:567
void ensureOnlyOneDefaultButton()
Ensure presence of no more than one single default button.
Definition: YQDialog.cc:402
virtual int preferredHeight()
Preferred height of the widget.
Definition: YQDialog.cc:224
void normalCursor()
Show normal mouse cursor not indicating busy status.
Definition: YQUI.cc:557
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.
Definition: YQDialog.cc:726
void unregisterWidget(QWidget *widget)
Unregisters a widget.
Definition: QY2Styler.cc:277
static YQUI * ui()
Access the global Qt-UI.
Definition: YQUI.h:81
void waitForEventTimeout()
Timeout during waitForEvent()
Definition: YQDialog.cc:831