navigationwidget.h 3.47 KB
Newer Older
1
/**************************************************************************
con's avatar
con committed
2 3 4
**
** This file is part of Qt Creator
**
con's avatar
con committed
5
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
con's avatar
con committed
6
**
hjk's avatar
hjk committed
7
** Contact: Nokia Corporation (info@qt.nokia.com)
con's avatar
con committed
8
**
9
**
10
** GNU Lesser General Public License Usage
11
**
hjk's avatar
hjk committed
12 13 14 15 16 17
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18
**
con's avatar
con committed
19
** In addition, as a special exception, Nokia gives you certain additional
hjk's avatar
hjk committed
20
** rights. These rights are described in the Nokia Qt LGPL Exception
con's avatar
con committed
21 22
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
23 24 25 26 27
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
con's avatar
con committed
28
** If you have questions regarding the use of this file, please contact
Tobias Hunger's avatar
Tobias Hunger committed
29
** Nokia at info@qt.nokia.com.
con's avatar
con committed
30
**
31
**************************************************************************/
hjk's avatar
hjk committed
32

con's avatar
con committed
33 34 35
#ifndef NAVIGATIONWIDGET_H
#define NAVIGATIONWIDGET_H

36
#include <coreplugin/minisplitter.h>
37
#include <coreplugin/id.h>
38

39
#include <QtCore/QHash>
con's avatar
con committed
40 41 42 43

QT_BEGIN_NAMESPACE
class QSettings;
class QShortcut;
44
class QAbstractItemModel;
45
class QStandardItemModel;
con's avatar
con committed
46 47
QT_END_NAMESPACE

48
namespace Core {
con's avatar
con committed
49 50
class INavigationWidgetFactory;
class IMode;
con's avatar
con committed
51
class Command;
con's avatar
con committed
52
class NavigationWidget;
53 54 55 56
struct NavigationWidgetPrivate;
namespace Internal {
class NavigationSubWidget;
}
con's avatar
con committed
57 58 59 60

class CORE_EXPORT NavigationWidgetPlaceHolder : public QWidget
{
    Q_OBJECT
hjk's avatar
hjk committed
61 62
    friend class Core::NavigationWidget;

con's avatar
con committed
63
public:
64
    explicit NavigationWidgetPlaceHolder(Core::IMode *mode, QWidget *parent = 0);
65
    virtual ~NavigationWidgetPlaceHolder();
con's avatar
con committed
66 67
    static NavigationWidgetPlaceHolder* current();
    void applyStoredSize(int width);
68

con's avatar
con committed
69 70
private slots:
    void currentModeAboutToChange(Core::IMode *);
71

con's avatar
con committed
72 73 74 75 76
private:
    Core::IMode *m_mode;
    static NavigationWidgetPlaceHolder* m_current;
};

77
class CORE_EXPORT NavigationWidget : public MiniSplitter
con's avatar
con committed
78 79
{
    Q_OBJECT
hjk's avatar
hjk committed
80

con's avatar
con committed
81
public:
82 83
    enum FactoryModelRoles {
        FactoryObjectRole = Qt::UserRole,
84 85
        FactoryIdRole,
        FactoryPriorityRole
86 87
    };

88 89
    explicit NavigationWidget(QAction *toggleSideBarAction);
    virtual ~NavigationWidget();
con's avatar
con committed
90

91 92
    void setFactories(const QList<INavigationWidgetFactory*> factories);

con's avatar
con committed
93
    void saveSettings(QSettings *settings);
94
    void restoreSettings(QSettings *settings);
con's avatar
con committed
95

96
    void activateSubWidget(const Id &factoryId);
97 98
    void closeSubWidgets();

con's avatar
con committed
99 100 101 102 103 104 105 106 107 108 109 110 111
    bool isShown() const;
    void setShown(bool b);

    bool isSuppressed() const;
    void setSuppressed(bool b);

    static NavigationWidget* instance();

    int storedWidth();

    // Called from the place holders
    void placeHolderChanged(NavigationWidgetPlaceHolder *holder);

112
    QHash<Id, Core::Command *> commandMap() const;
113
    QAbstractItemModel *factoryModel() const;
con's avatar
con committed
114 115 116

protected:
    void resizeEvent(QResizeEvent *);
117

con's avatar
con committed
118 119
private slots:
    void activateSubWidget();
120 121
    void splitSubWidget();
    void closeSubWidget();
con's avatar
con committed
122 123

private:
124
    void updateToggleText();
125
    Internal::NavigationSubWidget *insertSubItem(int position, int index);
126
    int factoryIndex(const Id &id);
127

hjk's avatar
hjk committed
128
    NavigationWidgetPrivate *d;
con's avatar
con committed
129 130 131 132 133
};

} // namespace Core

#endif // NAVIGATIONWIDGET_H