OSDN Git Service

It's 2011 now.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / coreplugin / sidebar.h
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** No Commercial Usage
10 **
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 **
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file.  Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights.  These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33
34 #ifndef SIDEBAR_H
35 #define SIDEBAR_H
36
37 #include "core_global.h"
38 #include "minisplitter.h"
39
40 #include <QtCore/QMap>
41 #include <QtCore/QList>
42 #include <QtCore/QScopedPointer>
43
44 QT_BEGIN_NAMESPACE
45 class QSettings;
46 class QToolButton;
47 QT_END_NAMESPACE
48
49 namespace Core {
50
51 class Command;
52 struct SideBarPrivate;
53
54 namespace Internal {
55 class SideBarWidget;
56 } // namespace Internal
57
58 /*
59  * An item in the sidebar. Has a widget that is displayed in the sidebar and
60  * optionally a list of tool buttons that are added to the toolbar above it.
61  * The window title of the widget is displayed in the combo box.
62  *
63  * The SideBarItem takes ownership over the widget.
64  */
65 class CORE_EXPORT SideBarItem : public QObject
66 {
67     Q_OBJECT
68 public:
69     // id is non-localized string of the item that's used to store the settings.
70     explicit SideBarItem(QWidget *widget, const QString &id);
71     virtual ~SideBarItem();
72
73     QWidget *widget() const;
74     QString id() const;
75     QString title() const;
76
77     /* Should always return a new set of tool buttons.
78      *
79      * Workaround since there doesn't seem to be a nice way to remove widgets
80      * that have been added to a QToolBar without either not deleting the
81      * associated QAction or causing the QToolButton to be deleted.
82      */
83     virtual QList<QToolButton *> createToolBarWidgets();
84
85 private:
86     const QString m_id;
87
88     QWidget *m_widget;    
89 };
90
91 class CORE_EXPORT SideBar : public MiniSplitter
92 {
93     Q_OBJECT
94 public:
95     /*
96      * The SideBar takes explicit ownership of the SideBarItems
97      * if you have one SideBar, or shared ownership in case
98      * of multiple SideBars.
99      */
100     explicit SideBar(QList< SideBarItem*> widgetList,
101             QList< SideBarItem*> defaultVisible);
102     virtual ~SideBar();
103
104     QStringList availableItemIds() const;
105     QStringList availableItemTitles() const;
106     QStringList unavailableItemIds() const;
107     void makeItemAvailable(SideBarItem *item);
108     void setUnavailableItemIds(const QStringList &itemTitles);
109     QString idForTitle(const QString &itemId) const;
110
111     SideBarItem *item(const QString &title);
112
113     bool closeWhenEmpty() const;
114     void setCloseWhenEmpty(bool value);
115
116     void saveSettings(QSettings *settings, const QString &name);
117     void readSettings(QSettings *settings, const QString &name);
118     void closeAllWidgets();
119     void activateItem(SideBarItem *item);
120
121     void setShortcutMap(const QMap<QString, Core::Command*> &shortcutMap);
122     QMap<QString, Core::Command*> shortcutMap() const;
123
124 signals:
125     void availableItemsChanged();
126
127 private slots:
128     void splitSubWidget();
129     void closeSubWidget();
130     void updateWidgets();
131
132 private:
133     Internal::SideBarWidget *insertSideBarWidget(int position,
134                                                  const QString &title = QString());
135     void removeSideBarWidget(Internal::SideBarWidget *widget);
136
137     QScopedPointer<SideBarPrivate> d;
138 };
139
140 } // namespace Core
141
142 #endif // SIDEBAR_H