1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
15 Author: Stefan Hundhammer <sh@suse.de>
25 #include <qstringlist.h>
26 #include "QY2ListView.h"
27 #include <QGridLayout>
32 #include "YQWizardButton.h"
46 class QTreeWidgetItem;
52 class YQWizard : public QFrame, public YWizard
64 YQWizard( YWidget * parent,
65 const string & backButtonLabel,
66 const string & abortButtonLabel,
67 const string & nextButtonLabel,
68 YWizardMode wizardMode = YWizardMode_Standard );
76 * Returns a descriptive label of this dialog instance for debugging.
78 * Reimplemented from YWidget.
80 virtual string debugLabel();
82 enum Direction { Forward, Backward };
85 * Returns the current direction of wizard operations - going forward or
86 * going backward. This can be used to maintain a consistent direction when
87 * assigning default buttons to a dialog.
89 Direction direction() const { return _direction; }
96 * Return internal widgets.
98 * Implemented from YWizard.
100 virtual YQWizardButton * backButton() const { return _backButton; }
101 virtual YQWizardButton * abortButton() const { return _abortButton; }
102 virtual YQWizardButton * nextButton() const { return _nextButton; }
104 virtual YReplacePoint * contentsReplacePoint() const { return _contentsReplacePoint; }
107 * Set the label of one of the wizard buttons (backButton(), abortButton(),
108 * nextButton() ) if that button is non-null.
110 * Implemented from YWizard.
112 virtual void setButtonLabel( YPushButton * button, const string & newLabel );
117 * Implemented from YWizard.
119 virtual void setHelpText( const string & helpText );
122 * Set the dialog icon. An empty icon name clears the current icon.
124 * Implemented from YWizard.
126 virtual void setDialogIcon( const string & iconName );
129 * Set the dialog heading.
131 * Implemented from YWizard.
133 virtual void setDialogHeading( const string & headingText );
141 * Add a step for the steps panel on the side bar.
142 * This only adds the step to the internal list of steps.
143 * The display is only updated upon calling updateSteps().
145 * Implemented from YWizard.
147 virtual void addStep( const string & text, const string & 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 * Implemented from YWizard.
156 virtual void addStepHeading( const string & text );
159 * Delete all steps and step headings from the internal lists.
160 * The display is only updated upon calling updateSteps().
162 * Implemented from YWizard.
164 virtual void deleteSteps();
167 * Set the current step. This also triggers updateSteps() if necessary.
169 * Implemented from YWizard.
171 virtual void setCurrentStep( const string & id );
174 * Update the steps display: Reflect the internal steps and heading lists
177 * Implemented from YWizard.
179 virtual void updateSteps();
187 * Add a tree item. If "parentID" is an empty string, it will be a root
188 * item. 'text' is the text that will be displayed in the tree, 'id' the ID
189 * with which this newly created item can be referenced - and that will be
190 * returned when the user clicks on a tree item.
192 * Implemented from YWizard.
194 virtual void addTreeItem( const string & parentID,
199 * Select the tree item with the specified ID, if such an item exists.
201 * Implemented from YWizard.
203 virtual void selectTreeItem( const string & id );
206 * Returns the current tree selection or an empty string if nothing is
207 * selected or there is no tree.
209 * Implemented from YWizard.
211 virtual std::string currentTreeSelection();
214 * Delete all tree items.
216 * Implemented from YWizard.
218 virtual void deleteTreeItems();
226 * Add a menu to the menu bar. If the menu bar is not visible yet, it will
227 * be made visible. 'text' is the user-visible text for the menu bar
228 * (including keyboard shortcuts marked with '&'), 'id' is the menu ID for
229 * later addMenuEntry() etc. calls.
231 * Implemented from YWizard.
233 virtual void addMenu( const string & text,
237 * Add a submenu to the menu with ID 'parentMenuID'.
239 * Implemented from YWizard.
241 virtual void addSubMenu( const string & parentMenuID,
246 * Add a menu entry to the menu with ID 'parentMenuID'. 'id' is what will
247 * be returned by UI::UserInput() etc. when a user activates this menu entry.
249 * Implemented from YWizard.
251 virtual void addMenuEntry( const string & parentMenuID,
256 * Add a menu separator to a menu.
258 * Implemented from YWizard.
260 virtual void addMenuSeparator( const string & parentMenuID );
263 * Delete all menus and hide the menu bar.
265 * Implemented from YWizard.
267 virtual void deleteMenus();
275 * Show a "Release Notes" button above the "Help" button in the steps panel
276 * with the specified label that will return the specified id to
277 * UI::UserInput() when clicked.
279 * The button (or the wizard) will assume ownership of the id and delete it
282 * Implemented from YWizard.
284 virtual void showReleaseNotesButton( const string & label,
288 * Hide an existing "Release Notes" button.
290 * Implemented from YWizard.
292 virtual void hideReleaseNotesButton();
295 * Retranslate internal buttons that are not accessible from the outside:
300 * Implemented from YWizard.
302 virtual void retranslateInternalButtons();
307 * Reimplemented from QWidget.
309 virtual bool eventFilter( QObject * obj, QEvent * ev );
312 // Geometry management
316 * Preferred width of the widget.
318 * Reimplemented from YWidget.
320 virtual int preferredWidth();
323 * Preferred height of the widget.
325 * Reimplemented from YWidget.
327 virtual int preferredHeight();
330 * Set the new size of the widget.
332 * Reimplemented from YWidget.
334 virtual void setSize( int newWidth, int newHeight );
340 * Emitted when the "Back" or "Cancel" button is clicked.
345 * Emitted when the "Abort" button is clicked.
350 * Emitted when the "Next" or "OK" button is clicked.
352 * Notice: As long as this signal is connected, the wizard will no longer
353 * send button events to the UI. Rather, the connected QObject has to take
354 * care to propagate those events.
355 * This is used in YQPatternSelector, for example.
363 * Adapt the size of the client area (the ReplacePoint(`id(`contents)) to
364 * fit in its current space.
366 void resizeClientArea();
369 * Show the current help text.
371 * This is useful only if it is obscured by any wizard steps, but it can
372 * safely be called at any time.
377 * Show the current wizard steps, if there are any. If there are none,
383 * Show the current selection tree in the side panel, if there is any. If
384 * there is none, nothing happens.
391 * Internal notification that the "Back" button has been clicked.
393 void slotBackClicked();
396 * Internal notification that the "Abort" button has been clicked.
398 void slotAbortClicked();
401 * Internal notification that the "Next" button has been clicked.
403 void slotNextClicked();
406 * Propagate button clicked event of release notes button to the
409 void releaseNotesClicked();
412 * Internal notification that [Space] or [Return] has been pressed on a
414 * If the item has an ID, that ID will be returned to UI::UserInput().
416 void sendTreeEvent( QTreeWidgetItem * item );
419 * Internal notification that the tree selection has changed.
421 * If the currently selected item has an ID, that ID will be returned to
424 void treeSelectionChanged();
427 * Internal notification that a menu item with numeric ID 'numID' has been
430 void sendMenuEvent( int numID );
437 void layoutTitleBar ( QWidget * parent );
438 QLayout *layoutSideBar ( QWidget * parent );
439 void layoutSideBarButtonBox ( QWidget * parent, QPushButton * button );
440 void layoutStepsPanel();
441 void layoutHelpPanel();
442 void layoutTreePanel();
443 QWidget *layoutWorkArea ( QWidget * parent );
444 void layoutClientArea( QWidget * parent );
445 QLayout *layoutButtonBox( QWidget * parent );
448 * Destroy the button box's buttons
450 void destroyButtons();
453 * Update all step - use appropriate icons and colors
455 void updateStepStates();
458 * Send a wizard event with the specified ID.
460 void sendEvent( const string & id );
463 * Notification that a signal is being connected.
465 * Reimplemented from QObject.
467 void connectNotify ( const char * signal );
470 * Notification that a signal is being disconnected.
472 * Reimplemented from QObject.
474 void disconnectNotify ( const char * signal );
477 * Set a button's label.
479 void setButtonLabel( YQWizardButton * button, const QString & newLabel );
482 * Enable or disable a button.
484 void enableButton( YQWizardButton * button, bool enabled );
487 * Set the keyboard focus to a button.
489 void setButtonFocus( YQWizardButton * button );
492 * Find a step with the specified ID. Returns 0 if there is no such step.
494 YQWizard::Step * findStep( const QString & id );
497 * Find a tree item with the specified ID. Tree items without IDs cannot be
499 * Returns the item or 0 if no such item found.
501 YQWizard::TreeItem * findTreeItem( const string & id );
508 string _backButtonLabel;
509 string _abortButtonLabel;
510 string _nextButtonLabel;
514 bool _protectNextButton;
516 bool _sendButtonEvents;
517 Direction _direction;
519 QString _currentStepID;
523 QStackedWidget * _sideBar;
524 QWidget * _stepsPanel;
525 QPushButton * _releaseNotesButton;
526 string _releaseNotesButtonId;
527 QPushButton * _helpButton;
528 QPushButton * _stepsButton;
529 QPushButton * _treeButton;
533 QWidget * _clientArea;
535 QLabel * _dialogIcon;
536 QLabel * _dialogHeading;
537 YQAlignment * _contents;
538 YQWizardButton * _backButton;
539 YQWizardButton * _abortButton;
540 YQWizardButton * _nextButton;
541 YReplacePoint * _contentsReplacePoint;
543 QList<YQWizard::Step*> _stepsList;
544 QHash<QString,YQWizard::Step*> _stepsIDs;
545 QHash<QString,YQWizard::TreeItem*> _treeIDs;
546 QHash<QString,QMenu*> _menuIDs;
547 vector<string> _menuEntryIDs;
553 * Helper class to represent a wizard step internally
559 Step( const QString & name = "", const QString & id = "" )
569 * Destructor. Intentionally not deleting the widgets.
573 virtual bool isHeading() const { return false; }
575 enum Status { Unset, Todo, Current, Done };
577 QString name() const { return _name; }
578 QLabel * statusLabel() const { return _statusLabel; }
579 QLabel * nameLabel() const { return _nameLabel; }
580 bool isEnabled() const { return _enabled; }
581 const QStringList & id() const { return _idList; }
582 void addID( const QString & id ) { _idList.append( id ); }
583 virtual bool hasID( const QString & id ) { return _idList.indexOf( id ) != -1; }
585 void setStatusLabel( QLabel * label ) { _statusLabel = label; }
586 void setNameLabel ( QLabel * label ) { _nameLabel = label; }
587 void setEnabled( bool enabled ) { _enabled = enabled; }
590 * Set text color and status icon for one wizard step
592 void setStatus( Status s );
597 QLabel * _statusLabel;
604 Q_DISABLE_COPY(Step);
609 * Helper class to represent a wizard step heading internally
611 class StepHeading: public Step
615 StepHeading( const QString & name = "" )
619 virtual ~StepHeading() {}
620 virtual bool isHeading() const { return true; }
621 virtual bool hasID( const QString & id ) { return false; }
624 Q_DISABLE_COPY(StepHeading);
629 * Helper class for wizard tree item
631 class TreeItem: public QY2ListViewItem
634 TreeItem( QY2ListView * parent,
635 const QString & text,
637 : QY2ListViewItem( parent, text )
641 TreeItem( YQWizard::TreeItem * parent,
642 const QString & text,
644 : QY2ListViewItem( parent, text )
648 virtual QString text(int index) const { return QTreeWidgetItem::text(index); }
649 QString text() const { return QTreeWidgetItem::text(0); }
650 QString id() const { return _id; }