libyui-qt  2.53.0
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 #define YQMainDialogWFlags Qt::Widget
49 #define YQPopupDialogWFlags Qt::Dialog
50 
51 #define VERBOSE_EVENT_LOOP 0
52 
53 using std::endl;
54 
55 
56 
57 YQDialog::YQDialog( YDialogType dialogType,
58  YDialogColorMode colorMode )
59 : QWidget( chooseParent( dialogType ),
60  dialogType == YPopupDialog ? YQPopupDialogWFlags : YQMainDialogWFlags )
61 , YDialog( dialogType, colorMode )
62 {
63  setWidgetRep( this );
64 
65  _userResized = false;
66  _focusButton = 0;
67  _defaultButton = 0;
68  _highlightedChild = 0;
69  _styleEditor = 0;
70 
71  setFocusPolicy( Qt::StrongFocus );
72  setAutoFillBackground( true );
73 
74  if ( colorMode != YDialogNormalColor )
75  {
76  QColor normalBackground ( 240, 100, 36 );
77  QColor inputFieldBackground ( 0xbb, 0xff, 0xbb );
78  QColor text = Qt::black;
79 
80  if ( colorMode == YDialogInfoColor )
81  {
82  normalBackground = QColor ( 238, 232, 170 ); // PaleGoldenrod
83  }
84 
85  QPalette warnPalette( normalBackground );
86  warnPalette.setColor( QPalette::Text, text );
87  warnPalette.setColor( QPalette::Base, inputFieldBackground );
88  setPalette( warnPalette );
89  }
90 
91  qApp->setApplicationName(YQUI::ui()->applicationTitle());
92  topLevelWidget()->setWindowTitle ( YQUI::ui()->applicationTitle() );
93  QGuiApplication::setApplicationDisplayName( YQUI::ui()->applicationTitle() );
94 
95  if ( isMainDialog() && QWidget::parent() != YQMainWinDock::mainWinDock() )
96  {
97  setWindowFlags( YQPopupDialogWFlags );
98  }
99 
100  if ( ! isMainDialog() )
101  setWindowModality( Qt::ApplicationModal );
102 
103  if ( isMainDialog() && QWidget::parent() == YQMainWinDock::mainWinDock() )
104  {
105  YQMainWinDock::mainWinDock()->add( this );
106  }
107 
108  _eventLoop = new QEventLoop( this );
109  YUI_CHECK_NEW( _eventLoop );
110 
111  _waitForEventTimer = new QTimer( this );
112  YUI_CHECK_NEW( _waitForEventTimer );
113  _waitForEventTimer->setSingleShot( true );
114 
115  QObject::connect( _waitForEventTimer, &pclass(_waitForEventTimer)::timeout,
116  this, &pclass(this)::waitForEventTimeout );
117 
118  if ( isMainDialog() && QWidget::parent() == YQMainWinDock::mainWinDock() )
119  QY2Styler::styler()->registerWidget( YQMainWinDock::mainWinDock() );
120  else
121  QY2Styler::styler()->registerWidget( this );
122 }
123 
124 
126 {
127  if ( isMainDialog() )
128  {
130  // orphaned main dialogs are handled gracefully in YQWMainWinDock::remove()
131  }
132 
133  if ( _defaultButton )
134  _defaultButton->forgetDialog();
135 
136  if ( _focusButton )
137  _focusButton->forgetDialog();
138 
139  if ( _styleEditor )
140  delete _styleEditor;
141 
142  if ( isMainDialog() && QWidget::parent() == YQMainWinDock::mainWinDock() )
143  QY2Styler::styler()->unregisterWidget( YQMainWinDock::mainWinDock() );
144  else
145  QY2Styler::styler()->unregisterWidget( this );
146 }
147 
148 
149 QWidget *
150 YQDialog::chooseParent( YDialogType dialogType )
151 {
152  QWidget * parent = YQMainWinDock::mainWinDock()->window();
153 
154  if ( dialogType == YPopupDialog)
155  {
156  YDialog * currentDialog = YDialog::currentDialog( false );
157  if (currentDialog)
158  parent = (QWidget *) currentDialog->widgetRep();
159  }
160 
161  if ( ( dialogType == YMainDialog || dialogType == YWizardDialog ) &&
163  {
164  yuiDebug() << "Adding dialog to mainWinDock" << endl;
165  parent = YQMainWinDock::mainWinDock();
166  }
167 
168  return parent;
169 }
170 
171 
172 void
174 {
176  QWidget::show();
177  QWidget::raise(); // FIXME: is this really necessary?
178  QWidget::update();
179 }
180 
181 
182 void
184 {
185  QWidget::raise();
186  QWidget::update();
187 }
188 
189 
190 int
192 {
193  int preferredWidth;
194 
195  if ( isMainDialog() )
196  {
197  if ( userResized() )
198  preferredWidth = _userSize.width();
199  else
200  preferredWidth = YQUI::ui()->defaultSize( YD_HORIZ );
201  }
202  else
203  {
204  preferredWidth = YDialog::preferredWidth();
205  }
206 
207  int screenWidth = qApp->desktop()->width();
208 
209  if ( preferredWidth > screenWidth )
210  {
211  yuiWarning() << "Limiting dialog width to screen width (" << screenWidth
212  << ") instead of " << preferredWidth
213  << " - check the layout!"
214  << endl;
215  }
216 
217  return preferredWidth;
218 }
219 
220 
221 int
223 {
224  int preferredHeight;
225 
226  if ( isMainDialog() )
227  {
228  if ( userResized() )
229  preferredHeight = _userSize.height();
230  else
231  preferredHeight = YQUI::ui()->defaultSize( YD_VERT );
232  }
233  else
234  {
235  preferredHeight = YDialog::preferredHeight();
236  }
237 
238  int screenHeight = qApp->desktop()->height();
239 
240  if ( preferredHeight > screenHeight )
241  {
242  yuiWarning() << "Limiting dialog height to screen height (" << screenHeight
243  << ") instead of " << preferredHeight
244  << " - check the layout!"
245  << endl;
246  }
247 
248  return preferredHeight;
249 }
250 
251 
252 void
253 YQDialog::setEnabled( bool enabled )
254 {
255  QWidget::setEnabled( enabled );
256  YDialog::setEnabled( enabled );
257 }
258 
259 
260 void
261 YQDialog::setSize( int newWidth, int newHeight )
262 {
263  // yuiDebug() << "Resizing dialog to " << newWidth << " x " << newHeight << endl;
264 
265  if ( newWidth > qApp->desktop()->width() )
266  newWidth = qApp->desktop()->width();
267 
268  if ( newHeight > qApp->desktop()->height() )
269  newHeight = qApp->desktop()->height();
270 
271  resize( newWidth, newHeight );
272 
273  if ( hasChildren() )
274  {
275  firstChild()->setSize( newWidth, newHeight );
276  ( ( QWidget* )firstChild()->widgetRep() )->show();
277  }
278 }
279 
280 
281 void
282 YQDialog::resizeEvent( QResizeEvent * event )
283 {
284  if ( event )
285  {
286  // yuiDebug() << "Resize event: " << event->size().width() << " x " << event->size().height() << endl;
287  setSize ( event->size().width(), event->size().height() );
288  _userSize = event->size();
289 
290  if ( QWidget::parent() )
291  _userResized = true;
292  }
293 }
294 
295 
298 {
299  if ( _defaultButton )
300  return _defaultButton;
301 
302  _defaultButton = findDefaultButton( childrenBegin(), childrenEnd() );
303 
304  YDialog::setDefaultButton( 0 ); // prevent complaints about multiple default buttons
305  YDialog::setDefaultButton( _defaultButton );
306 
307  return _defaultButton;
308 }
309 
310 
312 YQDialog::findDefaultButton( YWidgetListConstIterator begin,
313  YWidgetListConstIterator end ) const
314 {
315  for ( YWidgetListConstIterator it = begin; it != end; ++it )
316  {
317  YWidget * widget = *it;
318 
319  //
320  // Check this widget
321  //
322 
323  YQGenericButton * button = dynamic_cast<YQGenericButton *> (widget);
324 
325  if ( button && button->isDefaultButton() )
326  {
327  return button;
328  }
329 
330 
331  //
332  // Recurse over the children of this widget
333  //
334 
335  if ( widget->hasChildren() )
336  {
337  button = findDefaultButton( widget->childrenBegin(),
338  widget->childrenEnd() );
339  if ( button )
340  return button;
341  }
342  }
343 
344  return 0;
345 }
346 
347 
348 YQWizard *
349 YQDialog::ensureOnlyOneDefaultButton( YWidgetListConstIterator begin,
350  YWidgetListConstIterator end )
351 {
352  YQGenericButton * def = _focusButton ? _focusButton : _defaultButton;
353  YQWizard * wizard = 0;
354 
355  for ( YWidgetListConstIterator it = begin; it != end; ++it )
356  {
357  YQGenericButton * button = dynamic_cast<YQGenericButton *> (*it);
358  YQWizardButton * wizardButton = dynamic_cast<YQWizardButton * > (*it);
359 
360  if ( ! wizard )
361  wizard = dynamic_cast<YQWizard *> (*it);
362 
363  if ( wizardButton )
364  {
365  wizardButton->showAsDefault( false );
366  }
367  else if ( button )
368  {
369  if ( button->isDefaultButton() )
370  {
371  if ( _defaultButton && button != _defaultButton )
372  {
373  yuiError() << "Too many default buttons: " << button << endl;
374  yuiError() << "Using old default button: " << _defaultButton << endl;
375  }
376  else
377  {
378  _defaultButton = button;
379  }
380  }
381 
382  if ( button->isShownAsDefault() && button != def )
383  button->showAsDefault( false );
384  }
385 
386  if ( (*it)->hasChildren() )
387  {
388  YQWizard * wiz = ensureOnlyOneDefaultButton( (*it)->childrenBegin(),
389  (*it)->childrenEnd() );
390  if ( wiz )
391  wizard = wiz;
392  }
393  }
394 
395  return wizard;
396 }
397 
398 
399 void
401 {
402  _defaultButton = 0;
403  YQWizard * wizard = ensureOnlyOneDefaultButton( childrenBegin(), childrenEnd() );
404 
405  if ( ! _defaultButton && wizard )
406  {
407  _defaultButton = wizardDefaultButton( wizard );
408  }
409 
410  if ( _defaultButton )
411  {
412  YDialog::setDefaultButton( 0 ); // prevent complaints about multiple default buttons
413  YDialog::setDefaultButton( _defaultButton );
414  }
415 
416 
417  YQGenericButton * def = _focusButton ? _focusButton : _defaultButton;
418 
419  if ( def )
420  def->showAsDefault();
421 }
422 
423 
424 YQWizard *
426 {
427  return findWizard( childrenBegin(), childrenEnd() );
428 }
429 
430 
431 YQWizard *
432 YQDialog::findWizard( YWidgetListConstIterator begin,
433  YWidgetListConstIterator end ) const
434 {
435  for ( YWidgetListConstIterator it = begin; it != end; ++it )
436  {
437  YWidget * widget = *it;
438  YQWizard * wizard = dynamic_cast<YQWizard *> (widget);
439 
440  if ( wizard )
441  return wizard;
442 
443  if ( widget->hasChildren() )
444  {
445  wizard = findWizard( widget->childrenBegin(),
446  widget->childrenEnd() );
447  if ( wizard )
448  return wizard;
449  }
450  }
451 
452  return 0;
453 }
454 
455 
458 {
459  YQGenericButton * def = 0;
460 
461  if ( ! wizard )
462  wizard = findWizard();
463 
464  if ( wizard )
465  {
466  // Pick one of the wizard buttons
467 
468  if ( wizard->direction() == YQWizard::Backward )
469  {
470  if ( wizard->backButton()
471  && wizard->backButton()->isShown()
472  && wizard->backButton()->isEnabled() )
473  {
474  def = wizard->backButton();
475  }
476  }
477 
478  if ( ! def )
479  {
480  if ( wizard->nextButton()
481  && wizard->nextButton()->isShown()
482  && wizard->nextButton()->isEnabled() )
483  {
484  def = wizard->nextButton();
485  }
486  }
487  }
488 
489  return def;
490 }
491 
492 
493 void
494 YQDialog::setDefaultButton( YPushButton * newDefaultButton )
495 {
496  if ( _defaultButton &&
497  newDefaultButton &&
498  newDefaultButton != _defaultButton )
499  {
500  if ( dynamic_cast<YQWizardButton *>( _defaultButton ) )
501  {
502  // Let app defined default buttons override wizard buttons
503  _defaultButton->setDefaultButton( false );
504  }
505  else
506  {
507  yuiError() << "Too many `opt(`default) PushButtons: " << newDefaultButton << endl;
508  newDefaultButton->setDefaultButton( false );
509  return;
510  }
511  }
512 
513  _defaultButton = dynamic_cast<YQGenericButton*>(newDefaultButton);
514 
515  if ( _defaultButton )
516  {
517  _defaultButton->setDefaultButton( true );
518  yuiDebug() << "New default button: " << _defaultButton << endl;
519 
520  if ( _defaultButton && ! _focusButton )
521  {
522  _defaultButton->showAsDefault( true );
523  _defaultButton->setKeyboardFocus();
524  }
525  }
526 
527 
528  YDialog::setDefaultButton( 0 ); // prevent complaints about multiple default buttons
529  YDialog::setDefaultButton( _defaultButton );
530 }
531 
532 
533 bool
535 {
536  // Try the focus button first, if there is any.
537 
538  if ( _focusButton &&
539  _focusButton->isEnabled() &&
540  _focusButton->isShownAsDefault() )
541  {
542  yuiDebug() << "Activating focus button: " << _focusButton << endl;
543  _focusButton->activate();
544  return true;
545  }
546 
547 
548  // No focus button - try the default button, if there is any.
549 
550  _defaultButton = findDefaultButton();
551 
552  if ( _defaultButton &&
553  _defaultButton->isEnabled() &&
554  _defaultButton->isShownAsDefault() )
555  {
556  yuiDebug() << "Activating default button: " << _defaultButton << endl;
557  _defaultButton->activate();
558  return true;
559  }
560  else
561  {
562  if ( warn )
563  {
564  yuiWarning() << "No default button in this dialog - ignoring [Return]" << endl;
565  }
566  }
567 
568  return false;
569 }
570 
571 
572 void
574 {
575  if ( button == _focusButton )
576  {
577  if ( _focusButton && _focusButton != _defaultButton )
578  _focusButton->showAsDefault( false );
579 
580  _focusButton = 0;
581  }
582 
583  if ( ! _focusButton && _defaultButton )
584  _defaultButton->showAsDefault( true );
585 }
586 
587 
588 void
590 {
591  if ( _focusButton && _focusButton != button )
592  _focusButton->showAsDefault( false );
593 
594  if ( _defaultButton && _defaultButton != button )
595  _defaultButton->showAsDefault( false );
596 
597  _focusButton = button;
598 
599  if ( _focusButton )
600  _focusButton->showAsDefault( true );
601 }
602 
603 
604 void
605 YQDialog::keyPressEvent( QKeyEvent * event )
606 {
607  if ( event )
608  {
609  if ( event->key() == Qt::Key_Print )
610  {
611  YQUI::ui()->makeScreenShot( "" );
612  return;
613  }
614  else if ( event->key() == Qt::Key_F4 && // Shift-F4: toggle colors for vision impaired users
615  event->modifiers() == Qt::ShiftModifier )
616  {
617  QY2Styler::styler()->toggleAlternateStyleSheet();
618 
619  if ( QY2Styler::styler()->usingAlternateStyleSheet() )
620  {
621  QWidget* parent = 0;
622  YDialog * currentDialog = YDialog::currentDialog( false );
623  if (currentDialog)
624  parent = (QWidget *) currentDialog->widgetRep();
625 
626  yuiMilestone() << "Switched to vision impaired palette" << endl;
627  QMessageBox::information( parent, // parent
628  _("Color switching"), // caption
629  _( "Switching to color palette for vision impaired users -\n"
630  "press Shift-F4 again to switch back to normal colors." ), // text
631  QMessageBox::Ok | QMessageBox::Default, // button0
632  QMessageBox::NoButton, // button1
633  QMessageBox::NoButton ); // button2
634  }
635  return;
636  }
637  else if ( event->key() == Qt::Key_F6 && // Shift-F6: ask for a widget ID and send it
638  event->modifiers() == Qt::ShiftModifier )
639  {
641  }
642  else if ( event->key() == Qt::Key_F7 && // Shift-F7: toggle debug logging
643  event->modifiers() == Qt::ShiftModifier )
644  {
646  return;
647  }
648  else if ( event->key() == Qt::Key_F8 && // Shift-F8: save y2logs
649  event->modifiers() == Qt::ShiftModifier )
650  {
651  YQUI::ui()->askSaveLogs();
652  return;
653  }
654  else if ( event->modifiers() == Qt::NoModifier ) // No Ctrl / Alt / Shift etc. pressed
655  {
656  if ( event->key() == Qt::Key_Return ||
657  event->key() == Qt::Key_Enter )
658  {
659  (void) activateDefaultButton();
660  return;
661  }
662  }
663  else if ( event->modifiers() == ( Qt::ControlModifier | Qt::ShiftModifier | Qt::AltModifier ) )
664  {
665  // Qt-UI special keys - all with Ctrl-Shift-Alt
666 
667  yuiMilestone() << "Caught YaST2 magic key combination" << endl;
668 
669  if ( event->key() == Qt::Key_M )
670  {
672  return;
673  }
674  else if ( event->key() == Qt::Key_P )
675  {
676  YQUI::ui()->askPlayMacro();
677  return;
678  }
679  else if ( event->key() == Qt::Key_D )
680  {
681  YQUI::ui()->sendEvent( new YDebugEvent() );
682  return;
683  }
684  else if ( event->key() == Qt::Key_T )
685  {
686  yuiMilestone() << "*** Dumping widget tree ***" << endl;
687  dumpWidgetTree();
688  yuiMilestone() << "*** Widget tree end ***" << endl;
689  return;
690  }
691  else if ( event->key() == Qt::Key_Y )
692  {
693  yuiMilestone() << "Opening dialog spy" << endl;
694  YDialogSpy::showDialogSpy();
695  YQUI::ui()->normalCursor();
696  }
697  else if ( event->key() == Qt::Key_X )
698  {
699  int result;
700  yuiMilestone() << "Starting xterm" << endl;
701  result = system( "/usr/bin/xterm &" );
702  if (result < 0)
703  yuiError() << "/usr/bin/xterm not found" << endl;
704  return;
705  }
706  else if ( event->key() == Qt::Key_S )
707  {
708  yuiMilestone() << "Opening style editor" << endl;
709  _styleEditor = new QY2StyleEditor(this);
710  _styleEditor->show();
711  _styleEditor->raise();
712  _styleEditor->activateWindow();
713  return;
714  }
715 
716  }
717  }
718 
719  QWidget::keyPressEvent( event );
720 }
721 
722 
723 void
724 YQDialog::closeEvent( QCloseEvent * event )
725 {
726  // The window manager "close window" button (and WM menu, e.g. Alt-F4) will be
727  // handled just like the user had clicked on the `id`( `cancel ) button in
728  // that dialog. It's up to the YCP application to handle this (if desired).
729 
730  yuiMilestone() << "Caught window manager close event - returning with YCancelEvent" << endl;
731  event->ignore();
732  YQUI::ui()->sendEvent( new YCancelEvent() );
733 }
734 
735 
736 void
737 YQDialog::focusInEvent( QFocusEvent * event )
738 {
739  // The dialog itself doesn't need or want the keyboard focus, but obviously
740  // (since Qt 2.3?) it needs QFocusPolicy::StrongFocus for the default
741  // button mechanism to work. So let's accept the focus and give it to some
742  // child widget.
743 
744  if ( event->reason() == Qt::TabFocusReason )
745  {
746  focusNextPrevChild( true );
747  }
748  else
749  {
750  if ( _defaultButton )
751  _defaultButton->setKeyboardFocus();
752  else
753  focusNextPrevChild( true );
754  }
755 }
756 
757 
758 YEvent *
759 YQDialog::waitForEventInternal( int timeout_millisec )
760 {
762  _eventLoop->wakeUp();
763 
764  YEvent * event = 0;
765 
766  _waitForEventTimer->stop();
767 
768  if ( timeout_millisec > 0 )
769  _waitForEventTimer->start( timeout_millisec ); // single shot
770 
771  if ( qApp->focusWidget() )
772  qApp->focusWidget()->setFocus();
773 
774  YQUI::ui()->normalCursor();
775 
776  if ( ! _eventLoop->isRunning() )
777  {
778 #if VERBOSE_EVENT_LOOP
779  yuiDebug() << "Executing event loop for " << this << endl;
780 #endif
781  _eventLoop->exec();
782 
783 #if VERBOSE_EVENT_LOOP
784  yuiDebug() << "Event loop finished for " << this << endl;
785 #endif
786  }
787  else
788  {
789 #if VERBOSE_EVENT_LOOP
790  yuiDebug() << "Event loop still running for " << this << endl;
791 #endif
792  }
793 
794  _waitForEventTimer->stop();
795  event = YQUI::ui()->consumePendingEvent();
796 
797 
798  // Prepare a busy cursor if the UI cannot respond to user input within the
799  // next 200 milliseconds (if the application doesn't call waitForEvent()
800  // within this time again)
801 
803 
804  return event;
805 }
806 
807 
808 YEvent *
810 {
811  _eventLoop->wakeUp();
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 }
Stylesheet Editor Dialog.
void registerWidget(QWidget *widget)
Registers a widget and applies the style sheet.
Definition: QY2Styler.cc:284
void unregisterWidget(QWidget *widget)
Unregisters a widget.
Definition: QY2Styler.cc:293
void toggleAlternateStyleSheet()
Toggle between default/alternate style sheets.
Definition: QY2Styler.cc:208
bool userResized()
Return 'true' if the user resized this dialog.
Definition: YQDialog.h:116
virtual void setSize(int newWidth, int newHeight)
Set the new size of the widget.
Definition: YQDialog.cc:261
virtual int preferredHeight()
Preferred height of the widget.
Definition: YQDialog.cc:222
YQWizard * findWizard() const
Find the first wizard in that dialog, if there is any.
Definition: YQDialog.cc:425
YQGenericButton * findDefaultButton()
Return this dialog's (first) default button or 0 if none.
Definition: YQDialog.cc:297
void gettingFocus(YQGenericButton *button)
Notification that a button gets the keyboard focus.
Definition: YQDialog.cc:589
void ensureOnlyOneDefaultButton()
Ensure presence of no more than one single default button.
Definition: YQDialog.cc:400
static void center(QWidget *dialog, QWidget *parent=0)
Center a dialog relative to 'parent'.
Definition: YQDialog.cc:845
void waitForEventTimeout()
Timeout during waitForEvent()
Definition: YQDialog.cc:831
virtual YEvent * waitForEventInternal(int timeout_millisec)
Wait for a user event.
Definition: YQDialog.cc:759
virtual YEvent * pollEventInternal()
Check if a user event is pending.
Definition: YQDialog.cc:809
bool activateDefaultButton(bool warn=true)
Activate (i.e.
Definition: YQDialog.cc:534
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:183
virtual int preferredWidth()
Preferred width of the widget.
Definition: YQDialog.cc:191
virtual void openInternal()
Internal open() method, called exactly once during the life time of the dialog in open().
Definition: YQDialog.cc:173
virtual ~YQDialog()
Destructor.
Definition: YQDialog.cc:125
YQGenericButton * wizardDefaultButton(YQWizard *wizard) const
Find a wizard button that would make sense as a default button.
Definition: YQDialog.cc:457
virtual void keyPressEvent(QKeyEvent *event)
Qt event handlers.
Definition: YQDialog.cc:605
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:150
void setDefaultButton(YPushButton *newDefaultButton)
Set the dialog's default button - the button that is activated with [Return] if no other button has t...
Definition: YQDialog.cc:494
void closeEvent(QCloseEvent *ev)
Interited from QDialog: The window was closed via the window manager close button.
Definition: YQDialog.cc:724
virtual void setEnabled(bool enabled)
Set enabled/disabled state.
Definition: YQDialog.cc:253
virtual void highlight(YWidget *child)
Highlight a child widget of this dialog.
Definition: YQDialog.cc:861
void losingFocus(YQGenericButton *button)
Notification that a button loses the keyboard focus.
Definition: YQDialog.cc:573
YQDialog(YDialogType dialogType, YDialogColorMode colorMode=YDialogNormalColor)
Constructor.
Definition: YQDialog.cc:57
Abstract base class for push button and similar widgets - all that can become a YQDialog's "default b...
void showAsDefault(bool show=true)
Show this button as the dialog's default button.
bool isEnabled() const
Returns 'true' if this button is enabled, 'false' otherwise.
virtual bool setKeyboardFocus()
Accept the keyboard focus.
void activate()
Activate (animated) this button.
bool isShownAsDefault() const
Returns 'true' if this button is shown as a default button - which may mean that this really is the d...
static YQMainWinDock * mainWinDock()
Static method to access the singleton for this class.
void remove(YQDialog *dialog=0)
Remove a dialog from the MainWinDock (if it belongs to the MainWinDock).
void add(YQDialog *dialog)
Add a dialog (the widgetRep() of a YQDialog) to the MainWinDock (on top of its widget stack.
bool couldDock()
Return 'true' if the next main dialog could be docked, i.e., if there is either no open dialog at all...
void toggleRecordMacro()
Toggle macro recording (activated by Ctrl-Shift-Alt-M): Stop macro recording if it is in progress,...
static YQUI * ui()
Access the global Qt-UI.
Definition: YQUI.h:83
void askSendWidgetID()
Open a pop-up dialog to ask the user for a widget ID and then send it with sendWidgetID().
Definition: YQUI.cc:613
void askConfigureLogging()
Open dialog to configure logging.
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:578
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:480
int defaultSize(YUIDimension dim) const
Returns size for opt(defaultsize) dialogs (in one dimension).
Definition: YQUI.cc:587
void askSaveLogs()
Open file selection box and let the user save y2logs to that location.
void forceUnblockEvents()
Force unblocking all events, no matter how many times blockEvents() has This returns 0 if there is no...
Definition: YQUI.cc:548
YEvent * consumePendingEvent()
Return the pending event, if there is one, and mark it as "consumed".
Definition: YQUI.h:157
void askPlayMacro()
Open file selection box and ask for a macro file to play (activated by Ctrl-Shift-Alt-P)
void normalCursor()
Show normal mouse cursor not indicating busy status.
Definition: YQUI.cc:568
void makeScreenShot(std::string filename)
Make a screen shot in .png format and save it to 'filename'.
bool isShown() const
Returns 'true' if the associated QPushButton (!) is shown.
virtual YQWizardButton * backButton() const
Return internal widgets.
Definition: YQWizard.h:112
Direction direction() const
Returns the current direction of wizard operations - going forward or going backward.
Definition: YQWizard.h:101