OpenWalnut  1.5.0dev
WSettingMenu.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WSETTINGMENU_H
26 #define WSETTINGMENU_H
27 
28 #include <string>
29 
30 #include <QMenu>
31 
32 /**
33  * Similar to WSettingAction, this can handle a multi-option setting as QMenu.
34  */
35 class WSettingMenu: public QMenu
36 {
37  Q_OBJECT
38 public:
39  /**
40  * Constructs a menu with the specified options and automatically handles updates.
41  *
42  * \param parent the parent widget owning this menu
43  * \param settingName the name of the setting tohandle
44  * \param menuName the menu's name
45  * \param tooltip the tooltip for the menu
46  * \param defaultValue a initial default item
47  * \param options a list of exclusive options
48  * \param showRestartInfo if true, show an info dialog that changes get applied on next start.
49  */
50  WSettingMenu( QWidget* parent, std::string settingName, std::string menuName, std::string tooltip, unsigned int defaultValue,
51  const QList< QString >& options, bool showRestartInfo = false );
52 
53  /**
54  * Destructor.
55  */
56  virtual ~WSettingMenu();
57 
58  /**
59  * Returns the current setting.
60  *
61  * \return current setting
62  */
63  unsigned int get() const;
64 
65 signals:
66 
67  /**
68  * Signal getting emitted if the selected option changes.
69  *
70  * \param index the new index.
71  */
72  void change( unsigned int index );
73 
74 protected:
75 private:
76  /**
77  * The name of the setting handled here.
78  */
79  QString m_settingName;
80 
81  /**
82  * If true, a change of the setting causes an restart notification dialog.
83  */
85 
86  /**
87  * Tracks the currently selected option.
88  */
89  unsigned int m_currentItem;
90 
91 private slots:
92 
93  /**
94  * Handles updates in the option.
95  *
96  * \param action the triggered action.
97  */
98  void handleUpdate( QAction* action );
99 };
100 
101 #endif // WSETTINGMENU_H
102 
Similar to WSettingAction, this can handle a multi-option setting as QMenu.
Definition: WSettingMenu.h:36
WSettingMenu(QWidget *parent, std::string settingName, std::string menuName, std::string tooltip, unsigned int defaultValue, const QList< QString > &options, bool showRestartInfo=false)
Constructs a menu with the specified options and automatically handles updates.
unsigned int get() const
Returns the current setting.
unsigned int m_currentItem
Tracks the currently selected option.
Definition: WSettingMenu.h:89
void change(unsigned int index)
Signal getting emitted if the selected option changes.
void handleUpdate(QAction *action)
Handles updates in the option.
virtual ~WSettingMenu()
Destructor.
bool m_showRestartInfo
If true, a change of the setting causes an restart notification dialog.
Definition: WSettingMenu.h:84
QString m_settingName
The name of the setting handled here.
Definition: WSettingMenu.h:79