LP-56 - Better txpid option namings, fix tabs-spaces, tooltips. headers, variable...
[librepilot.git] / ground / openpilotgcs / src / plugins / coreplugin / fancytabwidget.h
blobaef20b2c5b7c5655f4504c90f8e5022971b59aa0
1 /**
2 ******************************************************************************
4 * @file fancytabwidget.h
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
6 * Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
7 * @addtogroup GCSPlugins GCS Plugins
8 * @{
9 * @addtogroup CorePlugin Core Plugin
10 * @{
11 * @brief The Core GCS plugin
12 *****************************************************************************/
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 * for more details.
24 * You should have received a copy of the GNU General Public License along
25 * with this program; if not, write to the Free Software Foundation, Inc.,
26 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #ifndef FANCYTABWIDGET_H
30 #define FANCYTABWIDGET_H
32 #include <QIcon>
33 #include <QWidget>
35 #include <QTimer>
36 #include <QPropertyAnimation>
38 QT_BEGIN_NAMESPACE
39 class QPainter;
40 class QStackedLayout;
41 class QStatusBar;
42 QT_END_NAMESPACE
44 namespace Core {
45 namespace Internal {
46 class FancyTab : public QObject {
47 Q_OBJECT Q_PROPERTY(float fader READ fader WRITE setFader)
48 public:
49 FancyTab(QWidget *tabbar) : enabled(false), tabbar(tabbar), m_fader(0)
51 animator.setPropertyName("fader");
52 animator.setTargetObject(this);
54 float fader()
56 return m_fader;
58 void setFader(float value);
60 void fadeIn();
61 void fadeOut();
63 QIcon icon;
64 QString text;
65 QString toolTip;
66 bool enabled;
68 private:
69 QPropertyAnimation animator;
70 QWidget *tabbar;
71 float m_fader;
74 class FancyTabBar : public QWidget {
75 Q_OBJECT
77 public:
78 FancyTabBar(QWidget *parent = 0);
79 ~FancyTabBar();
81 bool event(QEvent *event);
83 void paintEvent(QPaintEvent *event);
84 void paintTab(QPainter *painter, int tabIndex) const;
85 void mousePressEvent(QMouseEvent *);
86 void mouseMoveEvent(QMouseEvent *);
87 void enterEvent(QEvent *);
88 void leaveEvent(QEvent *);
89 bool validIndex(int index) const
91 return index >= 0 && index < m_tabs.count();
94 QSize sizeHint() const;
95 QSize minimumSizeHint() const;
97 void setTabEnabled(int index, bool enable);
98 bool isTabEnabled(int index) const;
100 void insertTab(int index, const QIcon &icon, const QString &label)
102 FancyTab *tab = new FancyTab(this);
104 tab->icon = icon;
105 tab->text = label;
106 m_tabs.insert(index, tab);
107 updateGeometry();
109 void setEnabled(int index, bool enabled);
110 void removeTab(int index)
112 FancyTab *tab = m_tabs.takeAt(index);
114 delete tab;
115 updateGeometry();
117 void setCurrentIndex(int index);
118 int currentIndex() const
120 return m_currentIndex;
123 void setTabToolTip(int index, QString toolTip)
125 m_tabs[index]->toolTip = toolTip;
127 QString tabToolTip(int index) const
129 return m_tabs.at(index)->toolTip;
132 QIcon tabIcon(int index) const
134 return m_tabs.at(index)->icon;
136 QString tabText(int index) const
138 return m_tabs.at(index)->text;
140 int count() const
142 return m_tabs.count();
144 QRect tabRect(int index) const;
146 signals:
147 void currentChanged(int);
149 public slots:
150 void emitCurrentIndex();
152 private:
153 static const int m_rounding;
154 static const int m_textPadding;
155 QRect m_hoverRect;
156 int m_hoverIndex;
157 int m_currentIndex;
158 QList<FancyTab *> m_tabs;
159 QTimer m_triggerTimer;
160 QSize tabSizeHint(bool minimum = false) const;
163 class FancyTabWidget : public QWidget {
164 Q_OBJECT
166 public:
167 FancyTabWidget(QWidget *parent = 0);
169 void insertTab(int index, QWidget *tab, const QIcon &icon, const QString &label);
170 void removeTab(int index);
171 void setBackgroundBrush(const QBrush &brush);
172 void addCornerWidget(QWidget *widget);
173 void insertCornerWidget(int pos, QWidget *widget);
174 int cornerWidgetCount() const;
175 void setTabToolTip(int index, const QString &toolTip);
177 void paintEvent(QPaintEvent *event);
179 int currentIndex() const;
180 QStatusBar *statusBar() const;
182 void setTabEnabled(int index, bool enable);
183 bool isTabEnabled(int index) const;
185 bool isSelectionWidgetVisible() const;
187 signals:
188 void currentAboutToShow(int index);
189 void currentChanged(int index);
191 public slots:
192 void setCurrentIndex(int index);
193 void setSelectionWidgetVisible(bool visible);
195 private slots:
196 void showWidget(int index);
198 private:
199 FancyTabBar *m_tabBar;
200 QWidget *m_cornerWidgetContainer;
201 QStackedLayout *m_modesStack;
202 QWidget *m_selectionWidget;
203 QStatusBar *m_statusBar;
205 } // namespace Internal
206 } // namespace Core
208 #endif // FANCYTABWIDGET_H