LP-56 - Better txpid option namings, fix tabs-spaces, tooltips. headers, variable...
[librepilot.git] / ground / openpilotgcs / src / plugins / coreplugin / sidebar.h
blob59d7b29ba7fda5a4bffba5f02b7330d2c03d3f90
1 /**
2 ******************************************************************************
4 * @file sidebar.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 SIDEBAR_H
30 #define SIDEBAR_H
32 #include <QtCore/QMap>
33 #include <QtCore/QPointer>
34 #include <QWidget>
35 #include <QComboBox>
37 #include <coreplugin/minisplitter.h>
39 QT_BEGIN_NAMESPACE
40 class QSettings;
41 class QToolBar;
42 class QAction;
43 class QToolButton;
44 QT_END_NAMESPACE
46 namespace Core {
47 class Command;
49 namespace Internal {
50 class SideBarWidget;
51 class ComboBox;
52 } // namespace Internal
55 * An item in the sidebar. Has a widget that is displayed in the sidebar and
56 * optionally a list of tool buttons that are added to the toolbar above it.
57 * The window title of the widget is displayed in the combo box.
59 * The SideBarItem takes ownership over the widget.
61 class CORE_EXPORT SideBarItem {
62 public:
63 SideBarItem(QWidget *widget)
64 : m_widget(widget)
67 virtual ~SideBarItem();
69 QWidget *widget()
71 return m_widget;
74 /* Should always return a new set of tool buttons.
76 * Workaround since there doesn't seem to be a nice way to remove widgets
77 * that have been added to a QToolBar without either not deleting the
78 * associated QAction or causing the QToolButton to be deleted.
80 virtual QList<QToolButton *> createToolBarWidgets()
82 return QList<QToolButton *>();
85 private:
86 QWidget *m_widget;
89 class CORE_EXPORT SideBar : public MiniSplitter {
90 Q_OBJECT
91 public:
93 * The SideBar takes ownership of the SideBarItems.
95 SideBar(QList<SideBarItem *> widgetList,
96 QList<SideBarItem *> defaultVisible);
97 ~SideBar();
99 QStringList availableItems() const;
100 void makeItemAvailable(SideBarItem *item);
101 SideBarItem *item(const QString &title);
103 void saveSettings(QSettings *settings);
104 void readSettings(QSettings *settings);
106 void activateItem(SideBarItem *item);
108 void setShortcutMap(const QMap<QString, Core::Command *> &shortcutMap);
109 QMap<QString, Core::Command *> shortcutMap() const;
111 private slots:
112 void splitSubWidget();
113 void closeSubWidget();
114 void updateWidgets();
116 private:
117 Internal::SideBarWidget *insertSideBarWidget(int position,
118 const QString &title = QString());
119 void removeSideBarWidget(Internal::SideBarWidget *widget);
121 QList<Internal::SideBarWidget *> m_widgets;
123 QMap<QString, SideBarItem *> m_itemMap;
124 QStringList m_availableItems;
125 QStringList m_defaultVisible;
126 QMap<QString, Core::Command *> m_shortcutMap;
129 namespace Internal {
130 class SideBarWidget : public QWidget {
131 Q_OBJECT
132 public:
133 SideBarWidget(SideBar *sideBar, const QString &title);
134 ~SideBarWidget();
136 QString currentItemTitle() const;
137 void setCurrentItem(const QString &title);
139 void updateAvailableItems();
140 void removeCurrentItem();
142 Core::Command *command(const QString &title) const;
144 signals:
145 void splitMe();
146 void closeMe();
147 void currentWidgetChanged();
149 private slots:
150 void setCurrentIndex(int);
152 private:
153 ComboBox *m_comboBox;
154 SideBarItem *m_currentItem;
155 QToolBar *m_toolbar;
156 QAction *m_splitAction;
157 QList<QAction *> m_addedToolBarActions;
158 SideBar *m_sideBar;
159 QToolButton *m_splitButton;
160 QToolButton *m_closeButton;
163 class ComboBox : public QComboBox {
164 Q_OBJECT
166 public:
167 ComboBox(SideBarWidget *sideBarWidget);
169 protected:
170 bool event(QEvent *event);
172 private:
173 SideBarWidget *m_sideBarWidget;
175 } // namespace Internal
176 } // namespace Core
178 #endif // SIDEBAR_H