Choreonoid  1.8
ToolBar.h
Go to the documentation of this file.
1 
5 #ifndef CNOID_BASE_TOOL_BAR_H
6 #define CNOID_BASE_TOOL_BAR_H
7 
8 #include "Buttons.h"
9 #include "Action.h"
10 #include <QLabel>
11 #include <QWidget>
12 #include <QBoxLayout>
13 #include "exportdecl.h"
14 
15 namespace cnoid {
16 
17 class Archive;
18 class ExtensionManager;
19 class ToolBarArea;
20 class MainWindow;
21 
22 class CNOID_EXPORT ToolBar : public QWidget
23 {
24  Q_OBJECT
25 public:
26 
27  ToolBar(const QString& name);
28  virtual ~ToolBar();
29 
30  ToolButton* addButton(const QString& text, const QString& tooltip = QString());
31  ToolButton* addButton(const QIcon& icon, const QString& tooltip = QString());
32  ToolButton* addButton(const char* const* xpm, const QString& tooltip = QString());
33 
34  ToolButton* addToggleButton(const QString& text, const QString& tooltip = QString());
35  ToolButton* addToggleButton(const QIcon& icon, const QString& tooltip = QString());
36  ToolButton* addToggleButton(const char* const* xpm, const QString& tooltip = QString());
37 
38  void requestNewRadioGroup();
39  QButtonGroup* currentRadioGroup();
40 
41  ToolButton* addRadioButton(const QString& text, const QString& tooltip = QString());
42  ToolButton* addRadioButton(const QIcon& icon, const QString& tooltip = QString());
43  ToolButton* addRadioButton(const char* const* xpm, const QString& tooltip = QString());
44 
45  void addAction(QAction* action);
46  void addWidget(QWidget* widget);
47  QLabel* addLabel(const QString& text);
48  QLabel* addImage(const QString& filename);
49  QWidget* addSeparator();
50  void addSpacing(int spacing = -1);
51 
52  ToolBar& setInsertionPosition(int index);
53 
54  void setVisibleByDefault(bool on = true) { isVisibleByDefault_ = on; }
55  bool isVisibleByDefault() const { return isVisibleByDefault_; }
56  void placeOnNewRowByDefault(bool on = true) { isPlacedOnNewRowByDefault_ = on; }
57  bool isPlacedOnNewRowByDefault() const { return isPlacedOnNewRowByDefault_; }
58  void setStretchable(bool on) { isStretchable_ = on; }
59  bool isStretchable() const { return isStretchable_; }
60  virtual int stretchableDefaultWidth() const;
61  void setAutoRaiseByDefault(bool on = true) { isAutoRaiseByDefault_ = on; }
62  bool isAutoRaiseByDefault() const { return isAutoRaiseByDefault_; }
63 
64  ToolBarArea* toolBarArea() { return toolBarArea_; }
65 
67  public:
68  bool operator() (ToolBar* bar1, ToolBar* bar2) {
69  return (bar1->layoutPriority < bar2->layoutPriority);
70  }
71  };
72 
73  virtual bool storeState(Archive& archive);
74  virtual bool restoreState(const Archive& archive);
75 
76 public Q_SLOTS:
77  void setEnabled(bool on);
78  void changeIconSize(const QSize& iconSize);
79 
80 private:
81  QHBoxLayout* hbox;
82  int insertionPosition;
83  QWidget* handle;
84  QButtonGroup* radioGroup;
85  bool isNewRadioGroupRequested;
86  MainWindow* mainWindow;
87  ToolBarArea* toolBarArea_;
88  bool isVisibleByDefault_;
89  bool isPlacedOnNewRowByDefault_;
90  bool isAutoRaiseByDefault_;
91 
92  // used for layouting tool bars on a ToolBarArea
93  bool isStretchable_;
94  int desiredX;
95  int layoutPriority;
96 
97  void setRadioButton(ToolButton* button);
98  void changeIconSizeSub(QLayout* layout, const QSize& iconSize);
99 
100  friend class ToolBarArea;
101 };
102 
103 }
104 
105 #endif
cnoid::ToolBar::LayoutPriorityCmp
Definition: ToolBar.h:66
cnoid::ToolBar::setAutoRaiseByDefault
void setAutoRaiseByDefault(bool on=true)
Definition: ToolBar.h:61
cnoid::ToolBar
Definition: ToolBar.h:22
cnoid::ToolBar::isStretchable
bool isStretchable() const
Definition: ToolBar.h:59
cnoid::ToolBarArea
Definition: ToolBarArea.h:18
Buttons.h
cnoid::Archive
Definition: Archive.h:22
cnoid::ToolBar::isAutoRaiseByDefault
bool isAutoRaiseByDefault() const
Definition: ToolBar.h:62
Action.h
cnoid::MainWindow
Definition: MainWindow.h:19
cnoid::ToolBar::isPlacedOnNewRowByDefault
bool isPlacedOnNewRowByDefault() const
Definition: ToolBar.h:57
cnoid::ToolBar::placeOnNewRowByDefault
void placeOnNewRowByDefault(bool on=true)
Definition: ToolBar.h:56
cnoid
Definition: AbstractSceneLoader.h:11
cnoid::ToolBar::setStretchable
void setStretchable(bool on)
Definition: ToolBar.h:58
cnoid::ToolBar::setVisibleByDefault
void setVisibleByDefault(bool on=true)
Definition: ToolBar.h:54
cnoid::ToolButton
Definition: Buttons.h:74
cnoid::ToolBar::isVisibleByDefault
bool isVisibleByDefault() const
Definition: ToolBar.h:55
cnoid::ToolBar::toolBarArea
ToolBarArea * toolBarArea()
Definition: ToolBar.h:64