1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
15 Author: Stefan Hundhammer <sh@suse.de>
27 #include <qstringlist.h>
29 #include "QY2ListView.h"
51 class YQWizard : public QVBox, public YWizard
63 YQWizard( YWidget * parent,
64 YWidgetID * backButtonId, const string & backButtonLabel,
65 YWidgetID * abortButtonId, const string & abortButtonLabel,
66 YWidgetID * nextButtonId, const string & nextButtonLabel,
67 YWizardMode wizardMode = YWizardMode_Standard );
75 enum Direction { Forward, Backward };
78 * Returns the current direction of wizard operations - going forward or
79 * going backward. This can be used to maintain a consistent direction when
80 * assigning default buttons to a dialog.
82 Direction direction() const { return _direction; }
85 * Generic direct access to implementation-specific functions.
86 * See YQWizard.cc for details.
88 * Returns 'true' on success, 'false' on failure.
89 * Reimplemented from YWizard.
91 virtual YCPValue command( const YCPTerm & command );
94 * Returns a descriptive label of this dialog instance for debugging.
96 * Reimplemented from YWidget.
98 virtual string debugLabel();
101 * Preferred width of the widget.
103 * Reimplemented from YWidget.
105 virtual int preferredWidth();
108 * Preferred height of the widget.
110 * Reimplemented from YWidget.
112 virtual int preferredHeight();
115 * Set the new size of the widget.
117 * Reimplemented from YWidget.
119 virtual void setSize( int newWidth, int newHeight );
122 * Event filter - inherited from QWidget.
124 virtual bool eventFilter( QObject * obj, QEvent * ev );
127 * Set a dialog icon. 0 is a valid value - it clears the current icon.
129 void setDialogIcon( const char * iconName );
132 * Set a dialog heading. 0 is a valid value - it clears the old text.
134 void setDialogHeading( const QString & headingText );
137 * Returns 'true' if this wizard was created with steps enabled, i.e. the
138 * side bar has a "steps" view.
140 bool stepsEnabled() const { return _stepsEnabled; }
143 * Add a step for the steps panel on the side bar.
144 * This only adds the step to the internal list of steps.
145 * The display is only updated upon calling updateSteps().
147 void addStep( const QString & text, const QString & id );
150 * Add a step heading for the steps panel on the side bar.
151 * This only adds the heading to the internal list of steps.
152 * The display is only updated upon calling updateSteps().
154 void addStepHeading( const QString & text );
157 * Delete all steps and step headings from the internal lists.
158 * The display is only updated upon calling updateSteps().
163 * Set the current step. This also triggers updateSteps() if necessary.
165 void setCurrentStep( const QString & id );
168 * Update the steps display: Reflect the internal steps and heading lists
174 * Returns 'true' if this wizard was created with a selection tree enabled,
175 * i.e. the side bar has a tree selection.
177 bool treeEnabled() const { return _treeEnabled; }
180 * Returns the wizard's "Next" (or "Accept") button.
182 YQWizardButton * nextButton() const { return _nextButton; }
185 * Returns the wizard's "Back" button.
187 YQWizardButton * backButton() const { return _backButton; }
190 * Returns the wizard's "Abort" button.
192 YQWizardButton * abortButton() const { return _abortButton; }
196 * Set wizard command verbosity
198 void setVerboseCommands( bool verbose ) { _verboseCommands = verbose; }
201 * Add a tree item. If "parentID" is an empty string, it will be a root
202 * item. 'text' is the text that will be displayed in the tree, 'id' the ID
203 * with which this newly created item can be referenced - and that will be
204 * returned when the user clicks on a tree item.
206 void addTreeItem( const QString & parentID,
207 const QString & text,
208 const QString & id );
211 * Select the tree item with the specified ID, if such an item exists.
213 void selectTreeItem( const QString & id );
216 * Delete all tree items.
218 void deleteTreeItems();
222 * Add a menu to the menu bar. If the menu bar is not visible yet, it will
223 * be made visible. 'text' is the user-visible text for the menu bar
224 * (including keyboard shortcuts marked with '&'), 'id' is the menu ID for
225 * later addMenuEntry() etc. calls.
227 void addMenu( const QString & text,
228 const QString & id );
231 * Add a submenu to the menu with ID 'parentMenuID'.
233 void addSubMenu( const QString & parentMenuID,
234 const QString & text,
235 const QString & id );
238 * Add a menu entry to the menu with ID 'parentMenuID'. 'id' is what will
239 * be returned by UI::UserInput() etc. when a user activates this menu entry.
241 void addMenuEntry( const QString & parentMenuID,
242 const QString & text,
243 const QString & id );
246 * Add a menu separator to a menu.
248 void addMenuSeparator( const QString & parentMenuID );
251 * Delete all menus and hide the menu bar.
258 * Emitted when the "Back" or "Cancel" button is clicked.
263 * Emitted when the "Abort" button is clicked.
268 * Emitted when the "Next" or "OK" button is clicked.
270 * Notice: As long as this signal is connected, the wizard will no longer
271 * send button events to the UI. Rather, the connected QObject has to take
272 * care to propagate those events.
273 * This is used in YQPatternSelector, for example.
281 * Set the help text. 0 is a valid value - it clears the old text.
283 void setHelpText( QString helpText );
286 * Adapt the size of the client area (the ReplacePoint(`id(`contents)) to
287 * fit in its current space.
289 void resizeClientArea();
292 * Show the current help text.
294 * This is useful only if it is obscured by any wizard steps, but it can
295 * safely be called at any time.
300 * Show the current wizard steps, if there are any. If there are none,
306 * Show the current selection tree in the side panel, if there is any. If
307 * there is none, nothing happens.
312 * Set a widget's background pixmap to a gradient pixmap and set the
313 * widget's height (fixed) to that pixmap's height.
315 static void setGradient( QWidget * widget, const QPixmap & pixmap );
318 * Set a widget's background to the lower portion (the bottom
319 * 'croppedHeight' pixels) of a pixmap and set the widget's height (fixed)
320 * to that 'croppedHeight'.
322 static void setBottomCroppedGradient( QWidget * widget,
323 const QPixmap & pixmap,
327 * Bottom-crop a pixmap: Return a pixmap with the bottom 'croppedHeight'
330 static QPixmap bottomCropPixmap( const QPixmap & pixmap, int croppedHeight );
333 * Return the color of pixel( x, y ) of a pixmap.
334 * If pixmap is null defaultColor is returned.
335 * This is a _very_ expensive operation!
337 static QColor pixelColor( const QPixmap & pixmap, int x, int y, const QColor & defaultColor );
343 * Internal notification that the "Back" button has been clicked.
345 void slotBackClicked();
348 * Internal notification that the "Abort" button has been clicked.
350 void slotAbortClicked();
353 * Internal notification that the "Next" button has been clicked.
355 void slotNextClicked();
358 * Propagate button clicked event of release notes button to the YCP
361 void releaseNotesClicked();
364 * Internal notification that [Space] or [Return] has been pressed on a
366 * If the item has an ID, that ID will be returned to UI::UserInput().
368 void sendTreeEvent( QListViewItem * item );
371 * Internal notification that the tree selection has changed.
373 * If the currently selected item has an ID, that ID will be returned to
376 void treeSelectionChanged();
379 * Internal notification that a menu item with numeric ID 'numID' has been
382 void sendMenuEvent( int numID );
386 * Retranslate internal buttons that are not accessible from the outside:
391 void retranslateInternalButtons();
397 void layoutTitleBar ( QWidget * parent );
398 void layoutSideBar ( QWidget * parent );
399 void layoutSideBarButtonBox ( QWidget * parent, QPushButton * button );
400 void layoutStepsPanel();
401 void layoutHelpPanel();
402 void layoutTreePanel();
403 void layoutWorkArea ( QHBox * parentHBox );
404 void layoutClientArea( QWidget * parent );
405 void layoutButtonBox( QWidget * parent );
409 * Load gradient pixmaps
411 void loadGradientPixmaps();
414 * Load step status icons
416 void loadStepsIcons();
419 * Destroy the button box's buttons
421 void destroyButtons();
424 * Update all step - use appropriate icons and colors
426 void updateStepStates();
429 * Add a (left or right) margin of the specified width to a widget,
430 * consisting of a fixed height top gradient , a flexible center part (in
431 * the gradient center color) and a fixed height bottom gradient.
433 * The bottom gradient widget is returned as a reference for other
434 * background pixmaps.
436 void addGradientColumn( QWidget * parent, int width = 8 );
439 * Send a wizard event with the specified ID.
441 void sendEvent( YCPValue id );
442 void sendEvent( YWidgetID * id );
445 * Returns 'true' if the application is running on a high-color display,
446 * i.e., on an X visual with more than 8 bit depth.
448 bool highColorDisplay() const;
451 * Notification that a signal is being connected.
453 * Reimplemented from QObject.
455 void connectNotify ( const char * signal );
458 * Notification that a signal is being disconnected.
460 * Reimplemented from QObject.
462 void disconnectNotify ( const char * signal );
465 // Wizard command mini-parser
469 * Check if 'term' matches wizard command 'declaration'.
470 * 'declaration' is a function prototype like this:
472 * myFunction ( string, boolean, string )
474 * Void functions are declared without any parameters:
478 * Function names must be unique. They cannot be overloaded.
480 bool isCommand( QString declaration, const YCPTerm & term );
483 * Return argument number 'argNo' from 'term' as QString.
485 QString qStringArg( const YCPTerm & term, int argNo );
488 * Return argument number 'argNo' from 'term' as std::string.
490 std::string stringArg( const YCPTerm & term, int argNo );
493 * Return argument number 'argNo' from 'term' as bool.
495 bool boolArg( const YCPTerm & term, int argNo );
498 * Return argument as type 'any' (plain YCPValue)
500 YCPValue anyArg( const YCPTerm & term, int argNo );
503 * Set a button's label.
505 void setButtonLabel( YQWizardButton * button, const QString & newLabel );
510 void setButtonID( YQWizardButton * button, const YCPValue & id );
513 * Enable or disable a button.
515 void enableButton( YQWizardButton * button, bool enabled );
518 * Set the keyboard focus to a button.
520 void setButtonFocus( YQWizardButton * button );
523 * Set text color and status icon for one wizard step
525 void setStepStatus( YQWizard::Step * step, const QPixmap & icon, const QColor & color );
528 * Find a step with the specified ID. Returns 0 if there is no such step.
530 YQWizard::Step * findStep( const QString & id );
533 * Find a tree item with the specified ID. Tree items without IDs cannot be
535 * Returns the item or 0 if no such item found.
537 YQWizard::TreeItem * findTreeItem( const QString & id );
540 * Returns the current tree selection or an empty string if nothing is
541 * selected or there is no tree.
543 * Reimplemented from YWizard.
545 YCPString currentTreeSelection();
548 * Show a "Release Notes" button above the "Help" button in the steps panel
549 * with the specified label that will return the specified id to
550 * UI::UserInput() when clicked.
552 void showReleaseNotesButton( string label, const YCPValue & id );
555 * Hide an existing "Release Notes" button.
557 void hideReleaseNotesButton();
560 * NOP command just to check if a YQWizard is running
571 bool _verboseCommands;
572 bool _protectNextButton;
574 bool _sendButtonEvents;
575 Direction _direction;
577 QPixmap _titleBarGradientPixmap;
578 QPixmap _topGradientPixmap;
579 QColor _gradientCenterColor;
580 QColor _gradientTopColor;
581 QPixmap _bottomGradientPixmap;
583 QPixmap _stepCurrentIcon;
584 QPixmap _stepToDoIcon;
585 QPixmap _stepDoneIcon;
587 QColor _stepCurrentColor;
588 QColor _stepToDoColor;
589 QColor _stepDoneColor;
591 QString _currentStepID;
594 QWidgetStack * _sideBar;
597 QGridLayout * _stepsGrid;
598 QPushButton * _releaseNotesButton;
599 YCPValue _releaseNotesButtonId;
600 QPushButton * _helpButton;
602 QTextBrowser * _helpBrowser;
603 QPushButton * _stepsButton;
604 QPushButton * _treeButton;
609 QWidget * _menuBarBox;
611 QLabel * _dialogIcon;
612 QLabel * _dialogHeading;
613 YQAlignment * _contents;
614 YQWizardButton * _backButton;
615 QSpacerItem * _backButtonSpacer;
616 YQWizardButton * _abortButton;
617 YQWizardButton * _nextButton;
619 QPtrList<YQWizard::Step> _stepsList;
620 QDict<YQWizard::Step> _stepsIDs;
621 QDict<YQWizard::TreeItem> _treeIDs;
622 QDict<QPopupMenu> _menuIDs;
623 vector<QString> _menuEntryIDs;
629 * Helper class to represent a wizard step internally
635 Step( const QString & name = "", const QString & id = "" )
644 * Destructor. Intentionally not deleting the widgets.
648 virtual bool isHeading() const { return false; }
650 QString name() const { return _name; }
651 QLabel * statusLabel() const { return _statusLabel; }
652 QLabel * nameLabel() const { return _nameLabel; }
653 bool isEnabled() const { return _enabled; }
654 const QStringList & id() const { return _idList; }
655 void addID( const QString & id ) { _idList.append( id ); }
656 virtual bool hasID( const QString & id ) { return _idList.find( id ) != _idList.end(); }
658 void setStatusLabel( QLabel * label ) { _statusLabel = label; }
659 void setNameLabel ( QLabel * label ) { _nameLabel = label; }
660 void setEnabled( bool enabled ) { _enabled = enabled; }
665 QLabel * _statusLabel;
673 * Helper class to represent a wizard step heading internally
675 class StepHeading: public Step
679 StepHeading( const QString & name = "" )
683 virtual ~StepHeading() {}
684 virtual bool isHeading() const { return true; }
685 virtual bool hasID( const QString & id ) { return false; }
690 * Helper class for wizard tree item
692 class TreeItem: public QY2ListViewItem
695 TreeItem( QY2ListView * parent,
696 const QString & text,
698 : QY2ListViewItem( parent, text )
702 TreeItem( YQWizard::TreeItem * parent,
703 const QString & text,
705 : QY2ListViewItem( parent, text )
709 QString text() const { return QListViewItem::text(0); }
710 QString id() const { return _id; }