OSDN Git Service

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