libyui-qt
YQWizard.h
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: YQWizard.h
20 
21  Author: Stefan Hundhammer <shundhammer@suse.de>
22 
23 /-*/
24 
25 
26 #ifndef YQWizard_h
27 #define YQWizard_h
28 
29 #include <string>
30 #include <vector>
31 
32 #include <qpixmap.h>
33 #include <qstringlist.h>
34 #include "QY2ListView.h"
35 #include <QGridLayout>
36 #include <QSplitter>
37 #include <qlabel.h>
38 #include <QMenu>
39 #include <QAction>
40 #include <qevent.h>
41 #include <yui/YWizard.h>
42 #include "YQWizardButton.h"
43 
44 using std::vector;
45 
46 class QGridLayout;
47 class QFrame;
48 class QSplitter;
49 class QLabel;
50 class QMenuBar;
51 class QPushButton;
52 class QSpacerItem;
53 class QToolButton;
54 class QStackedWidget;
55 class YReplacePoint;
56 class QTreeWidgetItem;
57 class YQAlignment;
58 class YQReplacePoint;
59 class QY2ListView;
60 class QY2HelpDialog;
61 class QY2RelNotesDialog;
62 
63 
64 class YQWizard : public QSplitter, public YWizard
65 {
66  Q_OBJECT
67 
68 protected:
69  class Step;
70  class TreeItem;
71 
72 public:
76  YQWizard( YWidget * parent,
77  const std::string & backButtonLabel,
78  const std::string & abortButtonLabel,
79  const std::string & nextButtonLabel,
80  YWizardMode wizardMode = YWizardMode_Standard );
81 
85  virtual ~YQWizard();
86 
92  virtual std::string debugLabel() const;
93 
94  enum Direction { Forward, Backward };
95 
101  Direction direction() const { return _direction; }
102 
103  //
104  // Wizard basics
105  //
106 
112  virtual YQWizardButton * backButton() const { return _backButton; }
113  virtual YQWizardButton * abortButton() const { return _abortButton; }
114  virtual YQWizardButton * nextButton() const { return _nextButton; }
115 
116  virtual YReplacePoint * contentsReplacePoint() const { return _contentsReplacePoint; }
117 
124  virtual void setButtonLabel( YPushButton * button, const std::string & newLabel );
125 
131  virtual void setHelpText( const std::string & helpText );
132 
138  virtual void setDialogIcon( const std::string & iconName );
139 
146  virtual void setDialogTitle( const std::string & titleText );
147 
153  virtual std::string getDialogTitle();
154 
160  virtual void setDialogHeading( const std::string & headingText );
161 
162 
168  virtual std::string getDialogHeading();
169 
170  //
171  // Steps handling
172  //
173 
181  virtual void addStep( const std::string & text, const std::string & id );
182 
190  virtual void addStepHeading( const std::string & text );
191 
197  QList<YQWizard::Step*> stepsList() { return _stepsList; }
198 
204  void copySteps( YQWizard *wizard);
205 
212  virtual void deleteSteps();
213 
219  virtual void setCurrentStep( const std::string & id );
220 
225  QString currentStep() { return _currentStepID; };
226 
233  virtual void updateSteps();
234 
235 
236  //
237  // Tree handling
238  //
239 
248  virtual void addTreeItem( const std::string & parentID,
249  const std::string & text,
250  const std::string & id );
251 
257  virtual void selectTreeItem( const std::string & id );
258 
265  virtual std::string currentTreeSelection();
266 
272  virtual void deleteTreeItems();
273 
274 
275  //
276  // Menu handling
277  //
278 
287  virtual void addMenu( const std::string & text,
288  const std::string & id );
289 
295  virtual void addSubMenu( const std::string & parentMenuID,
296  const std::string & text,
297  const std::string & id );
298 
305  virtual void addMenuEntry( const std::string & parentMenuID,
306  const std::string & text,
307  const std::string & id );
308 
314  virtual void addMenuSeparator( const std::string & parentMenuID );
315 
321  virtual void deleteMenus();
322 
323 
324  //
325  // Misc
326  //
327 
338  virtual void showReleaseNotesButton( const std::string & label,
339  const std::string & id );
340 
346  virtual void hideReleaseNotesButton();
347 
356  virtual void retranslateInternalButtons();
357 
363  virtual bool eventFilter( QObject * obj, QEvent * ev );
364 
369  QWidget * workArea() const { return _workArea; }
370 
371 
372  //
373  // Geometry management
374  //
375 
381  virtual int preferredWidth();
382 
388  virtual int preferredHeight();
389 
395  virtual void setSize( int newWidth, int newHeight );
396 
400  bool isSecondary() const;
401 
402 signals:
403 
407  void backClicked();
408 
412  void abortClicked();
413 
422  void nextClicked();
423 
424 
425 public slots:
426 
431  void resizeClientArea();
432 
439  void showHelp();
440 
444  void showHotkeys();
445 
450  void showSteps();
451 
456  void showTree();
457 
458 protected slots:
459 
463  void slotBackClicked();
464 
468  void slotAbortClicked();
469 
473  void slotNextClicked();
474 
479  void showReleaseNotes();
480 
486  void sendTreeEvent( QTreeWidgetItem * item );
487 
494  void treeSelectionChanged();
495 
500  void sendMenuEvent( QAction *action );
501 
502 protected:
503 
504  // Layout functions
505 
506  void layoutTitleBar ( QWidget * parent );
507  QLayout *layoutSideBar ( QWidget * parent );
508  void layoutSideBarButtonBox ( QWidget * parent, QPushButton * button );
509  void layoutStepsPanel();
510  void layoutTreePanel();
511  QWidget *layoutWorkArea ( QWidget * parent );
512  void layoutClientArea ( QWidget * parent );
513  QLayout *layoutButtonBox ( QWidget * parent );
514  bool titleIsOnTheLeft();
515 
519  void destroyButtons();
520 
524  void updateStepStates();
525 
529  void sendEvent( const std::string & id );
530 
536  void connectNotify ( const char * signal );
537 
543  void disconnectNotify ( const char * signal );
544 
548  void setButtonLabel( YQWizardButton * button, const QString & newLabel );
549 
553  void enableButton( YQWizardButton * button, bool enabled );
554 
558  void setButtonFocus( YQWizardButton * button );
559 
563  YQWizard::Step * findStep( const QString & id );
564 
570  YQWizard::TreeItem * findTreeItem( const std::string & id );
571 
572 
573  //
574  // Data members
575  //
576 
577  std::string _backButtonLabel;
578  std::string _abortButtonLabel;
579  std::string _nextButtonLabel;
580 
581  bool _stepsEnabled;
582  bool _stepsRegistered;
583  bool _treeEnabled;
584  bool _protectNextButton;
585  bool _stepsDirty;
586  bool _sendButtonEvents;
587  Direction _direction;
588 
589  QString _currentStepID;
590  QString _qHelpText;
591  QString _qHotkeysText;
592 
593  QY2HelpDialog * _helpDlg;
594  QY2HelpDialog * _hotkeysDlg;
595  QY2RelNotesDialog * _relNotesDlg;
596 
597  QStackedWidget * _sideBar;
598  QWidget * _stepsPanel;
599  YQWizardButton * _releaseNotesButton;
600  static std::string _releaseNotesButtonId;
601  static std::string _releaseNotesButtonLabel;
602  YQWizardButton * _helpButton;
603  QAction * _helpAction;
604  QAction * _hotkeysAction;
605  QPushButton * _stepsButton;
606  QPushButton * _treeButton;
607  QFrame * _treePanel;
608  QY2ListView * _tree;
609 
610  QFrame * _workArea;
611  QWidget * _clientArea;
612  QMenuBar * _menuBar;
613  QLabel * _dialogIcon;
614  QLabel * _dialogLogo;
615  QLabel * _dialogBanner;
616  QLabel * _dialogHeading;
617  YQAlignment * _contents;
618  YQWizardButton * _backButton;
619  YQWizardButton * _abortButton;
620  YQWizardButton * _nextButton;
621  YReplacePoint * _contentsReplacePoint;
622 
623  QList<YQWizard::Step*> _stepsList;
624  QHash<QString,YQWizard::Step*> _stepsIDs;
625  QHash<QString,YQWizard::TreeItem*> _treeIDs;
626  QHash<QString,QMenu*> _menuIDs;
627  QHash<QAction*, std::string> _menuEntryIDs;
628 
629  QIcon _previousWindowIcon;
630 
631 private:
632  static YQWizard *main_wizard;
633 
634 protected:
635 
639  class Step
640  {
641  public:
642 
643  Step( const QString & name = "", const QString & id = "" )
644  : _name( name )
645  , _statusLabel( 0 )
646  , _nameLabel(0)
647  , _enabled( true )
648  , _idList( id )
649  , _status( Unset )
650  {}
651 
655  virtual ~Step();
656 
657  virtual bool isHeading() const { return false; }
658 
659  enum Status { Unset, Todo, Current, Done };
660 
661  QString name() const { return _name; }
662  QLabel * statusLabel() const { return _statusLabel; }
663  QLabel * nameLabel() const { return _nameLabel; }
664  bool isEnabled() const { return _enabled; }
665  const QStringList & id() const { return _idList; }
666  void addID( const QString & id ) { _idList.append( id ); }
667  virtual bool hasID( const QString & id ) { return _idList.indexOf( id ) != -1; }
668 
669  void setStatusLabel( QLabel * label ) { _statusLabel = label; }
670  void setNameLabel ( QLabel * label ) { _nameLabel = label; }
671  void setEnabled( bool enabled ) { _enabled = enabled; }
672 
673  void deleteLabels();
674 
678  void setStatus( Status s );
679 
680  protected:
681 
682  QString _name;
683  QLabel * _statusLabel;
684  QLabel * _nameLabel;
685  bool _enabled;
686  QStringList _idList;
687  Status _status;
688 
689  private:
690  Q_DISABLE_COPY(Step);
691  };
692 
693 
697  class StepHeading: public Step
698  {
699  public:
700 
701  StepHeading( const QString & name = "" )
702  : Step( name, "" )
703  {}
704 
705  virtual ~StepHeading() {}
706  virtual bool isHeading() const { return true; }
707  virtual bool hasID( const QString & id ) { return false; }
708 
709  private:
710  Q_DISABLE_COPY(StepHeading);
711  };
712 
713 
717  class TreeItem: public QY2ListViewItem
718  {
719  public:
720  TreeItem( QY2ListView * parent,
721  const QString & text,
722  const QString & id )
723  : QY2ListViewItem( parent, text )
724  , _id( id )
725  {}
726 
727  TreeItem( YQWizard::TreeItem * parent,
728  const QString & text,
729  const QString & id )
730  : QY2ListViewItem( parent, text )
731  , _id( id )
732  {}
733 
734  virtual QString text(int index) const { return QTreeWidgetItem::text(index); }
735  QString text() const { return QTreeWidgetItem::text(0); }
736  QString id() const { return _id; }
737 
738  private:
739  QString _id;
740  };
741 
742 }; // class YQWizard
743 
744 
745 
746 #endif // YQWizard_h
virtual std::string currentTreeSelection()
Definition: YQWizard.cc:670
void showReleaseNotes()
Definition: YQWizard.cc:1184
QY2ListViewItem(QY2ListView *parentListView, const QString &text=QString())
Definition: QY2ListView.cc:368
virtual void setCurrentStep(const std::string &id)
Definition: YQWizard.cc:484
QWidget * workArea() const
Definition: YQWizard.h:369
Definition: YQAlignment.h:35
void setButtonFocus(YQWizardButton *button)
void resizeClientArea()
Definition: YQWizard.cc:1351
virtual ~Step()
Definition: YQWizard.cc:1469
virtual void setDialogIcon(const std::string &iconName)
Definition: YQWizard.cc:1000
Definition: YQWizard.h:64
Direction direction() const
Definition: YQWizard.h:101
void destroyButtons()
Definition: YQWizard.cc:967
virtual void deleteTreeItems()
Definition: YQWizard.cc:615
Definition: QY2RelNotesDialog.h:39
void sendTreeEvent(QTreeWidgetItem *item)
Definition: YQWizard.cc:651
void showSteps()
Definition: YQWizard.cc:1205
Definition: YQWizard.h:697
virtual void setHelpText(const std::string &helpText)
Definition: YQWizard.cc:1085
virtual std::string getDialogTitle()
Definition: YQWizard.cc:1040
virtual void setSize(int newWidth, int newHeight)
Definition: YQWizard.cc:1345
void connectNotify(const char *signal)
Definition: YQWizard.cc:980
virtual YQWizardButton * backButton() const
Definition: YQWizard.h:112
virtual void deleteSteps()
Definition: YQWizard.cc:524
bool isSecondary() const
Definition: YQWizard.cc:207
Definition: YQWizard.h:717
virtual void showReleaseNotesButton(const std::string &label, const std::string &id)
Definition: YQWizard.cc:1392
virtual bool eventFilter(QObject *obj, QEvent *ev)
Definition: YQWizard.cc:1357
void slotAbortClicked()
Definition: YQWizard.cc:1103
virtual void selectTreeItem(const std::string &id)
Definition: YQWizard.cc:634
void enableButton(YQWizardButton *button, bool enabled)
virtual void setButtonLabel(YPushButton *button, const std::string &newLabel)
YQWizard(YWidget *parent, const std::string &backButtonLabel, const std::string &abortButtonLabel, const std::string &nextButtonLabel, YWizardMode wizardMode=YWizardMode_Standard)
Definition: YQWizard.cc:88
Definition: YQReplacePoint.h:35
void copySteps(YQWizard *wizard)
Definition: YQWizard.cc:492
virtual void addStepHeading(const std::string &text)
Definition: YQWizard.cc:327
void treeSelectionChanged()
Definition: YQWizard.cc:663
virtual void setDialogHeading(const std::string &headingText)
Definition: YQWizard.cc:1045
virtual void setDialogTitle(const std::string &titleText)
Definition: YQWizard.cc:1030
virtual ~YQWizard()
Definition: YQWizard.cc:185
virtual void addMenuEntry(const std::string &parentMenuID, const std::string &text, const std::string &id)
Definition: YQWizard.cc:1267
YQWizard::TreeItem * findTreeItem(const std::string &id)
Definition: YQWizard.cc:625
void abortClicked()
Definition: QY2HelpDialog.h:36
void setStatus(Status s)
Definition: YQWizard.cc:1475
virtual void hideReleaseNotesButton()
Definition: YQWizard.cc:1413
void slotBackClicked()
Definition: YQWizard.cc:1092
virtual void retranslateInternalButtons()
Definition: YQWizard.cc:1424
virtual void addMenuSeparator(const std::string &parentMenuID)
Definition: YQWizard.cc:1287
QString currentStep()
Definition: YQWizard.h:225
virtual void addStep(const std::string &text, const std::string &id)
Definition: YQWizard.cc:291
virtual void deleteMenus()
Definition: YQWizard.cc:1302
Enhanced QTreeWidget.
Definition: QY2ListView.h:47
void showHotkeys()
Definition: YQWizard.cc:1139
void showHelp()
Definition: YQWizard.cc:1123
virtual void addSubMenu(const std::string &parentMenuID, const std::string &text, const std::string &id)
Definition: YQWizard.cc:1243
void slotNextClicked()
Definition: YQWizard.cc:1112
YQWizard::Step * findStep(const QString &id)
Definition: YQWizard.cc:539
virtual int preferredHeight()
Definition: YQWizard.cc:1339
void showTree()
Definition: YQWizard.cc:1214
void sendEvent(const std::string &id)
Definition: YQWizard.cc:1327
Definition: YQWizardButton.h:37
Definition: YQWizard.h:639
Definition: QY2ListView.h:233
virtual void addMenu(const std::string &text, const std::string &id)
Definition: YQWizard.cc:1223
QList< YQWizard::Step * > stepsList()
Definition: YQWizard.h:197
virtual void addTreeItem(const std::string &parentID, const std::string &text, const std::string &id)
Definition: YQWizard.cc:580
void nextClicked()
void disconnectNotify(const char *signal)
Definition: YQWizard.cc:990
void updateStepStates()
Definition: YQWizard.cc:441
void sendMenuEvent(QAction *action)
Definition: YQWizard.cc:1314
virtual int preferredWidth()
Definition: YQWizard.cc:1333
virtual std::string getDialogHeading()
Definition: YQWizard.cc:1062
void backClicked()
virtual void updateSteps()
Definition: YQWizard.cc:334
virtual std::string debugLabel() const
Definition: YQWizard.cc:1070