ZIMA CAD Parts
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
navbar.h
Go to the documentation of this file.
1 #ifndef NAVBAR_H
2 #define NAVBAR_H
3 
4 #include <QStackedWidget>
5 #include <QToolBar>
6 #include <QList>
7 #include <QActionGroup>
8 #include <QMenu>
9 #include <QByteArray>
10 #include "navbarpage.h"
11 #include "navbarheader.h"
12 #include "navbarsplitter.h"
13 #include "navbarpagelistwidget.h"
14 
15 
16 class NavBarToolBar: public QToolBar
17 {
18  Q_OBJECT
19 
20 public:
21  explicit NavBarToolBar(QWidget *parent = 0);
22 };
23 
24 class NavBar : public QFrame
25 {
26  Q_OBJECT
27  Q_PROPERTY(int count READ count)
28  Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentChanged)
29  Q_PROPERTY(int rowHeight READ rowHeight WRITE setRowHeight)
30  Q_PROPERTY(bool collapsed READ isCollapsed WRITE setCollapsed NOTIFY stateChanged)
31  Q_PROPERTY(bool autoPopup READ autoPopup WRITE setAutoPopup)
33  Q_PROPERTY(bool showHeader READ showHeader WRITE setShowHeader)
35  Q_PROPERTY(int visibleRows READ visibleRows WRITE setVisibleRows NOTIFY visibleRowsChanged)
36  Q_PROPERTY(QSize smallIconSize READ smallIconSize WRITE setSmallIconSize)
37  Q_PROPERTY(QSize largeIconSize READ largeIconSize WRITE setLargeIconSize)
38 
39 public:
40  enum { NavBarMarker = 0x4e427232 };
41 
42  explicit NavBar(QWidget *parent = 0, Qt::WindowFlags f = 0);
43  ~NavBar();
44 
45  int addPage(QWidget *page);
46  int addPage(QWidget *page, const QString &text);
47  int addPage(QWidget *page, const QString &text, const QIcon &icon);
48  int insertPage(int index, QWidget *page);
49  int insertPage(int index, QWidget *page, const QString &text);
50  int insertPage(int index, QWidget *page, const QString &text, const QIcon &icon);
51 
52  void removePage(int index);
53 
54  void setPageText(int index, const QString &text);
55  QString pageText(int index) const;
56 
57  void setPageIcon(int index, const QIcon &icon);
58  QIcon pageIcon(int index) const;
59 
60  void setPageEnabled(int index, bool enabled);
61  bool isPageEnabled(int index);
62 
63  void setPageVisible(int index, bool visible);
64  bool isPageVisible(int index);
65 
66  int currentIndex() const;
67  QWidget *currentWidget() const;
68  QWidget *widget(int index) const;
69  int indexOf(QWidget *widget) const;
70  int count() const;
71 
72  void setSmallIconSize(const QSize &size);
73  QSize smallIconSize() const;
74 
75  void setLargeIconSize(const QSize &size);
76  QSize largeIconSize() const;
77 
78  int rowHeight() const;
79  bool isCollapsed() const;
80  bool autoPopup() const;
81  bool showCollapseButton() const;
82  bool showHeader() const;
83  bool showOptionsMenu() const;
84  int visibleRows() const;
85 
86  QByteArray saveState(int version = 0) const;
87  bool restoreState(const QByteArray & state, int version = 0);
88 
89  QSize sizeHint() const;
90 
91  static QString loadStyle(const QString &filename);
92 
93 signals:
94  void currentChanged(int index);
95  void visibleRowsChanged(int rows);
96  void stateChanged(bool collapsed);
97 
98 public slots:
99  void setCurrentIndex(int index);
100  void setCurrentWidget(QWidget *widget);
101  void setRowHeight(int height);
102  void setCollapsed(bool collapse);
103  void setAutoPopup(bool enable);
104  void setShowCollapseButton(bool show);
105  void setShowHeader(bool show);
106  void setShowOptionsMenu(bool show);
107  void setVisibleRows(int rows);
108  int showOptionsDialog();
109 
110 protected:
111  void resizeEvent(QResizeEvent *e);
112  void changeEvent(QEvent *e);
113 
114 private slots:
115  void onClickPageButton(QAction *action);
116  void onButtonVisibilityChanged(int visCount);
117  void changePageVisibility(QAction *action);
118  void showContentsPopup();
119 
120 private:
121  void resizeContent(const QSize &size, int rowheight);
122  void reorderStackedWidget();
123  void recalcPageList(bool reorder);
124  void refillToolBar(int visCount);
125  void refillPagesMenu();
126  void moveContentsToPopup(bool popup);
127  void setHeaderText(const QString &text);
128 
129  QList<NavBarPage> visiblePages();
130 
131  NavBarHeader *header;
132  QStackedWidget *stackedWidget;
133  NavBarSplitter *splitter;
134  NavBarPageListWidget *pageListWidget;
135  NavBarToolBar *pageToolBar;
136  QActionGroup *actionGroup;
137  QMenu *pagesMenu;
138  QFrame *contentsPopup;
139  NavBarTitleButton *pageTitleButton;
140  QAction *actionOptions;
141  QList<NavBarPage> pages;
142  QStringList pageOrder;
143 
144  bool collapsedState;
145  bool autoPopupMode;
146  int expandedWidth;
147  bool optMenuVisible;
148  bool headerVisible;
149  int headerHeight;
150  int collapsedWidth;
151  QSize pageIconSize;
152  int uniquePageCount;
153  bool proceedCollapse;
154 
155  friend class NavBarPageListWidget;
156 };
157 
158 #endif // NAVBAR_H
bool showHeader() const
void setShowCollapseButton(bool show)
Definition: navbar.cpp:351
void changeEvent(QEvent *e)
Definition: navbar.cpp:393
void resizeEvent(QResizeEvent *e)
Definition: navbar.cpp:387
~NavBar()
Definition: navbar.cpp:118
QIcon pageIcon(int index) const
Definition: navbar.cpp:701
Splitter, used inside navigation bar.
Definition: navbarsplitter.h:6
QSize largeIconSize() const
bool isCollapsed() const
Definition: navbar.cpp:225
void setLargeIconSize(const QSize &size)
Definition: navbar.cpp:480
bool autoPopup() const
bool showCollapseButton() const
bool collapsed
Definition: navbar.h:30
bool restoreState(const QByteArray &state, int version=0)
Definition: navbar.cpp:943
void setShowHeader(bool show)
Definition: navbar.cpp:186
void setPageText(int index, const QString &text)
Definition: navbar.cpp:711
void setRowHeight(int height)
Definition: navbar.cpp:254
void setShowOptionsMenu(bool show)
Definition: navbar.cpp:200
static QString loadStyle(const QString &filename)
Definition: navbar.cpp:1061
Definition: navbarheader.h:31
Outlook-like navigation bar.
Definition: navbar.h:24
QWidget * widget(int index) const
Definition: navbar.cpp:731
Definition: navbarpagelistwidget.h:18
void setCurrentIndex(int index)
Definition: navbar.cpp:745
Navigation bar header.
Definition: navbarheader.h:11
void stateChanged(bool collapsed)
QSize smallIconSize() const
Definition: navbar.h:40
void removePage(int index)
Definition: navbar.cpp:609
int currentIndex() const
void setCurrentWidget(QWidget *widget)
Definition: navbar.cpp:760
QWidget * currentWidget() const
Definition: navbar.cpp:147
void setAutoPopup(bool enable)
Definition: navbar.cpp:342
void visibleRowsChanged(int rows)
bool isPageVisible(int index)
Definition: navbar.cpp:681
void setPageEnabled(int index, bool enabled)
Definition: navbar.cpp:691
bool showOptionsMenu() const
int visibleRows() const
Definition: navbar.h:16
NavBar(QWidget *parent=0, Qt::WindowFlags f=0)
Definition: navbar.cpp:57
void setCollapsed(bool collapse)
Definition: navbar.cpp:281
void setSmallIconSize(const QSize &size)
Definition: navbar.cpp:460
void setPageVisible(int index, bool visible)
Definition: navbar.cpp:664
int rowHeight() const
int count() const
void setPageIcon(int index, const QIcon &icon)
Definition: navbar.cpp:721
QByteArray saveState(int version=0) const
Definition: navbar.cpp:915
int indexOf(QWidget *widget) const
Definition: navbar.cpp:157
int showOptionsDialog()
Definition: navbar.cpp:776
int addPage(QWidget *page)
Definition: navbar.cpp:493
void currentChanged(int index)
void setVisibleRows(int rows)
Definition: navbar.cpp:372
bool isPageEnabled(int index)
Definition: navbar.cpp:654
QString pageText(int index) const
Definition: navbar.cpp:644
int insertPage(int index, QWidget *page)
Definition: navbar.cpp:527
NavBarToolBar(QWidget *parent=0)
Definition: navbar.cpp:1075
QSize sizeHint() const
Definition: navbar.cpp:736