1 // 2 // Copyright (C) 2001-2013 Graeme Walker <graeme_walker@users.sourceforge.net> 3 // 4 // This program is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // This program is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with this program. If not, see <http://www.gnu.org/licenses/>. 16 // === 17 /// 18 /// \file gdialog.h 19 /// 20 21 #ifndef G_DIALOG_H 22 #define G_DIALOG_H 23 24 #include "gdef.h" 25 #include "qt.h" 26 #include "gpage.h" 27 #include <list> 28 #include <map> 29 class QHBoxLayout; 30 class QPushButton; 31 class QVBoxLayout; 32 class GPage ; 33 34 /// \class GDialog 35 /// The main forward-back dialog box. 36 /// 37 class GDialog : public QDialog 38 {Q_OBJECT 39 public: 40 41 explicit GDialog( bool with_help ) ; 42 ///< Constructor. Use a sequence of add()s to initialise 43 ///< ending with add(void). 44 45 explicit GDialog( QWidget * parent = NULL ) ; 46 ///< Constructor. Use a sequence of add()s to initialise 47 ///< ending with add(void). 48 49 void add( GPage * ) ; 50 ///< Adds a page. 51 52 void add( GPage * , const std::string & conditional_page_name ) ; 53 ///< Adds a page but only if the the page name 54 ///< matches the given conditional name or if the given 55 ///< conditional name is empty. 56 57 void add() ; 58 ///< To be called after other add()s. 59 60 GPage & page( const std::string & ) ; 61 ///< Finds a page by name. 62 63 const GPage & page( const std::string & ) const ; 64 ///< Finds a page by name. 65 66 std::string currentPageName() const ; 67 ///< Returns the current page name. 68 69 GPage & previousPage( unsigned int distance = 1U ) ; 70 ///< Returns the previous page. 71 72 bool historyContains( const std::string & ) const ; 73 ///< Returns true if the history contains the given page. 74 75 bool empty() const ; 76 ///< Returns true if there are no pages add()ed. 77 78 void dumpStateVariables( std::ostream & ) const ; 79 ///< Dump the widget state from all the pages. 80 81 void dumpInstallVariables( std::ostream & ) const ; 82 ///< Dump the install variables from all the pages. 83 84 void wait( bool ) ; 85 ///< Disables all buttons. 86 87 private slots: 88 void helpButtonClicked() ; 89 void backButtonClicked() ; 90 void nextButtonClicked() ; 91 void finishButtonClicked() ; 92 void pageUpdated() ; 93 94 private: 95 void init( bool ) ; 96 void dump( std::ostream & , bool for_install ) const ; 97 void setFirstPage( GPage & page ) ; 98 void switchPage( std::string new_page_name , std::string old_page_name = std::string() , bool back = false ) ; 99 100 private: 101 typedef std::list<std::string> History ; 102 typedef std::map<std::string,GPage*> Map ; 103 Map m_map ; 104 History m_history ; 105 bool m_first ; 106 QPushButton * m_help_button ; 107 QPushButton * m_cancel_button ; 108 QPushButton * m_back_button ; 109 QPushButton * m_next_button ; 110 QPushButton * m_finish_button ; 111 QHBoxLayout * m_button_layout ; 112 QVBoxLayout * m_main_layout ; 113 bool m_waiting ; 114 bool m_back_state ; 115 bool m_next_state ; 116 bool m_finish_state ; 117 }; 118 119 #endif 120