1 #ifndef CSV_WIDGET_SCENETOOL_TOGGLE_H
2 #define CSV_WIDGET_SCENETOOL_TOGGLE_H
3 
4 #include "scenetool.hpp"
5 
6 #include <map>
7 
8 class QHBoxLayout;
9 class QRect;
10 
11 namespace CSVWidget
12 {
13     class SceneToolbar;
14     class PushButton;
15 
16     ///< \brief Multi-Toggle tool
17     class SceneToolToggle : public SceneTool
18     {
19             Q_OBJECT
20 
21             struct ButtonDesc
22             {
23                 unsigned int mMask;
24                 std::string mSmallIcon;
25                 QString mName;
26                 int mIndex;
27             };
28 
29             std::string mEmptyIcon;
30             QWidget *mPanel;
31             QHBoxLayout *mLayout;
32             std::map<PushButton *, ButtonDesc> mButtons; // widget, id
33             int mButtonSize;
34             int mIconSize;
35             QString mToolTip;
36             PushButton *mFirst;
37 
38             void adjustToolTip();
39 
40             void adjustIcon();
41 
42             QRect getIconBox (int index) const;
43 
44         public:
45 
46             SceneToolToggle (SceneToolbar *parent, const QString& toolTip,
47                 const std::string& emptyIcon);
48 
49             void showPanel (const QPoint& position) override;
50 
51             /// \attention After the last button has been added, setSelection must be called at
52             /// least once to finalise the layout.
53             ///
54             /// \note The layout algorithm can not handle more than 9 buttons. To prevent this An
55             /// attempt to add more will result in an exception being thrown.
56             /// The small icons will be sized at (x-4)/3 (where x is the main icon size).
57             void addButton (const std::string& icon, unsigned int mask,
58                 const std::string& smallIcon, const QString& name, const QString& tooltip = "");
59 
60             unsigned int getSelectionMask() const;
61 
62             /// \param or'ed button masks. buttons that do not exist will be ignored.
63             void setSelectionMask (unsigned int selection);
64 
65         signals:
66 
67             void selectionChanged();
68 
69         private slots:
70 
71             void selected();
72     };
73 }
74 
75 #endif
76