1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
15 Author: Stefan Hundhammer <sh@suse.de>
26 #include <q3ptrlist.h>
27 #include <qstringlist.h>
29 #include "QY2ListView.h"
31 #include <q3gridlayout.h>
33 #include <q3popupmenu.h>
56 class YQWizard : public QFrame, public YWizard
68 YQWizard( YWidget * parent,
69 YWidgetID * backButtonId, const string & backButtonLabel,
70 YWidgetID * abortButtonId, const string & abortButtonLabel,
71 YWidgetID * nextButtonId, const string & nextButtonLabel,
72 YWizardMode wizardMode = YWizardMode_Standard );
80 enum Direction { Forward, Backward };
83 * Returns the current direction of wizard operations - going forward or
84 * going backward. This can be used to maintain a consistent direction when
85 * assigning default buttons to a dialog.
87 Direction direction() const { return _direction; }
90 * Generic direct access to implementation-specific functions.
91 * See YQWizard.cc for details.
93 * Returns 'true' on success, 'false' on failure.
94 * Reimplemented from YWizard.
96 virtual YCPValue command( const YCPTerm & command );
99 * Returns a descriptive label of this dialog instance for debugging.
101 * Reimplemented from YWidget.
103 virtual string debugLabel();
106 * Preferred width of the widget.
108 * Reimplemented from YWidget.
110 virtual int preferredWidth();
113 * Preferred height of the widget.
115 * Reimplemented from YWidget.
117 virtual int preferredHeight();
120 * Set the new size of the widget.
122 * Reimplemented from YWidget.
124 virtual void setSize( int newWidth, int newHeight );
127 * Event filter - inherited from QWidget.
129 virtual bool eventFilter( QObject * obj, QEvent * ev );
132 * Set a dialog icon. 0 is a valid value - it clears the current icon.
134 void setDialogIcon( const char * iconName );
137 * Set a dialog heading. 0 is a valid value - it clears the old text.
139 void setDialogHeading( const QString & headingText );
142 * Returns 'true' if this wizard was created with steps enabled, i.e. the
143 * side bar has a "steps" view.
145 bool stepsEnabled() const { return _stepsEnabled; }
148 * Add a step for the steps panel on the side bar.
149 * This only adds the step to the internal list of steps.
150 * The display is only updated upon calling updateSteps().
152 void addStep( const QString & text, const QString & id );
155 * Add a step heading for the steps panel on the side bar.
156 * This only adds the heading to the internal list of steps.
157 * The display is only updated upon calling updateSteps().
159 void addStepHeading( const QString & text );
162 * Delete all steps and step headings from the internal lists.
163 * The display is only updated upon calling updateSteps().
168 * Set the current step. This also triggers updateSteps() if necessary.
170 void setCurrentStep( const QString & id );
173 * Update the steps display: Reflect the internal steps and heading lists
179 * Returns 'true' if this wizard was created with a selection tree enabled,
180 * i.e. the side bar has a tree selection.
182 bool treeEnabled() const { return _treeEnabled; }
185 * Returns the wizard's "Next" (or "Accept") button.
187 YQWizardButton * nextButton() const { return _nextButton; }
190 * Returns the wizard's "Back" button.
192 YQWizardButton * backButton() const { return _backButton; }
195 * Returns the wizard's "Abort" button.
197 YQWizardButton * abortButton() const { return _abortButton; }
201 * Set wizard command verbosity
203 void setVerboseCommands( bool verbose ) { _verboseCommands = verbose; }
206 * Add a tree item. If "parentID" is an empty string, it will be a root
207 * item. 'text' is the text that will be displayed in the tree, 'id' the ID
208 * with which this newly created item can be referenced - and that will be
209 * returned when the user clicks on a tree item.
211 void addTreeItem( const QString & parentID,
212 const QString & text,
213 const QString & id );
216 * Select the tree item with the specified ID, if such an item exists.
218 void selectTreeItem( const QString & id );
221 * Delete all tree items.
223 void deleteTreeItems();
227 * Add a menu to the menu bar. If the menu bar is not visible yet, it will
228 * be made visible. 'text' is the user-visible text for the menu bar
229 * (including keyboard shortcuts marked with '&'), 'id' is the menu ID for
230 * later addMenuEntry() etc. calls.
232 void addMenu( const QString & text,
233 const QString & id );
236 * Add a submenu to the menu with ID 'parentMenuID'.
238 void addSubMenu( const QString & parentMenuID,
239 const QString & text,
240 const QString & id );
243 * Add a menu entry to the menu with ID 'parentMenuID'. 'id' is what will
244 * be returned by UI::UserInput() etc. when a user activates this menu entry.
246 void addMenuEntry( const QString & parentMenuID,
247 const QString & text,
248 const QString & id );
251 * Add a menu separator to a menu.
253 void addMenuSeparator( const QString & parentMenuID );
256 * Delete all menus and hide the menu bar.
263 * Emitted when the "Back" or "Cancel" button is clicked.
268 * Emitted when the "Abort" button is clicked.
273 * Emitted when the "Next" or "OK" button is clicked.
275 * Notice: As long as this signal is connected, the wizard will no longer
276 * send button events to the UI. Rather, the connected QObject has to take
277 * care to propagate those events.
278 * This is used in YQPatternSelector, for example.
286 * Set the help text. 0 is a valid value - it clears the old text.
288 void setHelpText( QString helpText );
291 * Adapt the size of the client area (the ReplacePoint(`id(`contents)) to
292 * fit in its current space.
294 void resizeClientArea();
297 * Show the current help text.
299 * This is useful only if it is obscured by any wizard steps, but it can
300 * safely be called at any time.
305 * Show the current wizard steps, if there are any. If there are none,
311 * Show the current selection tree in the side panel, if there is any. If
312 * there is none, nothing happens.
317 * Set a widget's background pixmap to a gradient pixmap and set the
318 * widget's height (fixed) to that pixmap's height.
320 static void setGradient( QWidget * widget, const QPixmap & pixmap );
323 * Set a widget's background to the lower portion (the bottom
324 * 'croppedHeight' pixels) of a pixmap and set the widget's height (fixed)
325 * to that 'croppedHeight'.
327 static void setBottomCroppedGradient( QWidget * widget,
328 const QPixmap & pixmap,
332 * Bottom-crop a pixmap: Return a pixmap with the bottom 'croppedHeight'
335 static QPixmap bottomCropPixmap( const QPixmap & pixmap, int croppedHeight );
338 * Return the color of pixel( x, y ) of a pixmap.
339 * If pixmap is null defaultColor is returned.
340 * This is a _very_ expensive operation!
342 static QColor pixelColor( const QPixmap & pixmap, int x, int y, const QColor & defaultColor );
348 * Internal notification that the "Back" button has been clicked.
350 void slotBackClicked();
353 * Internal notification that the "Abort" button has been clicked.
355 void slotAbortClicked();
358 * Internal notification that the "Next" button has been clicked.
360 void slotNextClicked();
363 * Propagate button clicked event of release notes button to the YCP
366 void releaseNotesClicked();
369 * Internal notification that [Space] or [Return] has been pressed on a
371 * If the item has an ID, that ID will be returned to UI::UserInput().
373 void sendTreeEvent( Q3ListViewItem * item );
376 * Internal notification that the tree selection has changed.
378 * If the currently selected item has an ID, that ID will be returned to
381 void treeSelectionChanged();
384 * Internal notification that a menu item with numeric ID 'numID' has been
387 void sendMenuEvent( int numID );
391 * Retranslate internal buttons that are not accessible from the outside:
396 void retranslateInternalButtons();
402 void layoutTitleBar ( QWidget * parent );
403 void layoutSideBar ( QWidget * parent );
404 void layoutSideBarButtonBox ( QWidget * parent, QPushButton * button );
405 void layoutStepsPanel();
406 void layoutHelpPanel();
407 void layoutTreePanel();
408 void layoutWorkArea ( QFrame * parentHBox );
409 void layoutClientArea( QWidget * parent );
410 void layoutButtonBox( QWidget * parent );
414 * Load gradient pixmaps
416 void loadGradientPixmaps();
419 * Load step status icons
421 void loadStepsIcons();
424 * Destroy the button box's buttons
426 void destroyButtons();
429 * Update all step - use appropriate icons and colors
431 void updateStepStates();
434 * Add a (left or right) margin of the specified width to a widget,
435 * consisting of a fixed height top gradient , a flexible center part (in
436 * the gradient center color) and a fixed height bottom gradient.
438 * The bottom gradient widget is returned as a reference for other
439 * background pixmaps.
441 void addGradientColumn( QWidget * parent, int width = 8 );
444 * Send a wizard event with the specified ID.
446 void sendEvent( YCPValue id );
447 void sendEvent( YWidgetID * id );
450 * Returns 'true' if the application is running on a high-color display,
451 * i.e., on an X visual with more than 8 bit depth.
453 bool highColorDisplay() const;
456 * Notification that a signal is being connected.
458 * Reimplemented from QObject.
460 void connectNotify ( const char * signal );
463 * Notification that a signal is being disconnected.
465 * Reimplemented from QObject.
467 void disconnectNotify ( const char * signal );
470 // Wizard command mini-parser
474 * Check if 'term' matches wizard command 'declaration'.
475 * 'declaration' is a function prototype like this:
477 * myFunction ( string, boolean, string )
479 * Void functions are declared without any parameters:
483 * Function names must be unique. They cannot be overloaded.
485 bool isCommand( QString declaration, const YCPTerm & term );
488 * Return argument number 'argNo' from 'term' as QString.
490 QString qStringArg( const YCPTerm & term, int argNo );
493 * Return argument number 'argNo' from 'term' as std::string.
495 std::string stringArg( const YCPTerm & term, int argNo );
498 * Return argument number 'argNo' from 'term' as bool.
500 bool boolArg( const YCPTerm & term, int argNo );
503 * Return argument as type 'any' (plain YCPValue)
505 YCPValue anyArg( const YCPTerm & term, int argNo );
508 * Set a button's label.
510 void setButtonLabel( YQWizardButton * button, const QString & newLabel );
515 void setButtonID( YQWizardButton * button, const YCPValue & id );
518 * Enable or disable a button.
520 void enableButton( YQWizardButton * button, bool enabled );
523 * Set the keyboard focus to a button.
525 void setButtonFocus( YQWizardButton * button );
528 * Set text color and status icon for one wizard step
530 void setStepStatus( YQWizard::Step * step, const QPixmap & icon, const QColor & color );
533 * Find a step with the specified ID. Returns 0 if there is no such step.
535 YQWizard::Step * findStep( const QString & id );
538 * Find a tree item with the specified ID. Tree items without IDs cannot be
540 * Returns the item or 0 if no such item found.
542 YQWizard::TreeItem * findTreeItem( const QString & id );
545 * Returns the current tree selection or an empty string if nothing is
546 * selected or there is no tree.
548 * Reimplemented from YWizard.
550 YCPString currentTreeSelection();
553 * Show a "Release Notes" button above the "Help" button in the steps panel
554 * with the specified label that will return the specified id to
555 * UI::UserInput() when clicked.
557 void showReleaseNotesButton( string label, const YCPValue & id );
560 * Hide an existing "Release Notes" button.
562 void hideReleaseNotesButton();
565 * NOP command just to check if a YQWizard is running
576 bool _verboseCommands;
577 bool _protectNextButton;
579 bool _sendButtonEvents;
580 Direction _direction;
582 QPixmap _titleBarGradientPixmap;
583 QPixmap _topGradientPixmap;
584 QColor _gradientCenterColor;
585 QColor _gradientTopColor;
586 QPixmap _bottomGradientPixmap;
588 QPixmap _stepCurrentIcon;
589 QPixmap _stepToDoIcon;
590 QPixmap _stepDoneIcon;
592 QColor _stepCurrentColor;
593 QColor _stepToDoColor;
594 QColor _stepDoneColor;
596 QString _currentStepID;
599 Q3WidgetStack * _sideBar;
600 Q3VBox * _stepsPanel;
602 Q3GridLayout * _stepsGrid;
603 QPushButton * _releaseNotesButton;
604 YCPValue _releaseNotesButtonId;
605 QPushButton * _helpButton;
607 Q3TextBrowser * _helpBrowser;
608 QPushButton * _stepsButton;
609 QPushButton * _treeButton;
613 Q3VBox * _clientArea;
614 QWidget * _menuBarBox;
616 QLabel * _dialogIcon;
617 QLabel * _dialogHeading;
618 YQAlignment * _contents;
619 YQWizardButton * _backButton;
620 QSpacerItem * _backButtonSpacer;
621 YQWizardButton * _abortButton;
622 YQWizardButton * _nextButton;
624 Q3PtrList<YQWizard::Step> _stepsList;
625 Q3Dict<YQWizard::Step> _stepsIDs;
626 Q3Dict<YQWizard::TreeItem> _treeIDs;
627 Q3Dict<Q3PopupMenu> _menuIDs;
628 vector<QString> _menuEntryIDs;
634 * Helper class to represent a wizard step internally
640 Step( const QString & name = "", const QString & id = "" )
649 * Destructor. Intentionally not deleting the widgets.
653 virtual bool isHeading() const { return false; }
655 QString name() const { return _name; }
656 QLabel * statusLabel() const { return _statusLabel; }
657 QLabel * nameLabel() const { return _nameLabel; }
658 bool isEnabled() const { return _enabled; }
659 const QStringList & id() const { return _idList; }
660 void addID( const QString & id ) { _idList.append( id ); }
661 virtual bool hasID( const QString & id ) { return _idList.find( id ) != _idList.end(); }
663 void setStatusLabel( QLabel * label ) { _statusLabel = label; }
664 void setNameLabel ( QLabel * label ) { _nameLabel = label; }
665 void setEnabled( bool enabled ) { _enabled = enabled; }
670 QLabel * _statusLabel;
678 * Helper class to represent a wizard step heading internally
680 class StepHeading: public Step
684 StepHeading( const QString & name = "" )
688 virtual ~StepHeading() {}
689 virtual bool isHeading() const { return true; }
690 virtual bool hasID( const QString & id ) { return false; }
695 * Helper class for wizard tree item
697 class TreeItem: public QY2ListViewItem
700 TreeItem( QY2ListView * parent,
701 const QString & text,
703 : QY2ListViewItem( parent, text )
707 TreeItem( YQWizard::TreeItem * parent,
708 const QString & text,
710 : QY2ListViewItem( parent, text )
714 virtual QString text(int index) const { return Q3ListViewItem::text(index); }
715 QString text() const { return Q3ListViewItem::text(0); }
716 QString id() const { return _id; }