statusbarmanager.cpp 3.11 KB
Newer Older
1
/**************************************************************************
con's avatar
con committed
2
3
4
**
** This file is part of Qt Creator
**
hjk's avatar
hjk committed
5
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
con's avatar
con committed
6
**
7
** Contact: Nokia Corporation (qt-info@nokia.com)
con's avatar
con committed
8
**
9
** Commercial Usage
10
**
11
12
13
14
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
15
**
16
** GNU Lesser General Public License Usage
17
**
18
19
20
21
22
23
** Alternatively, 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.
24
**
25
** If you are unsure which license is appropriate for your use, please
hjk's avatar
hjk committed
26
** contact the sales department at http://qt.nokia.com/contact.
con's avatar
con committed
27
**
28
**************************************************************************/
hjk's avatar
hjk committed
29

con's avatar
con committed
30
#include "statusbarmanager.h"
con's avatar
con committed
31
32
33

#include "coreconstants.h"
#include "mainwindow.h"
34
#include "statusbarwidget.h"
con's avatar
con committed
35

36
#include <coreplugin/actionmanager/actionmanager.h>
con's avatar
con committed
37
#include <coreplugin/actionmanager/command.h>
hjk's avatar
hjk committed
38
#include <aggregation/aggregate.h>
39
#include <extensionsystem/pluginmanager.h>
hjk's avatar
hjk committed
40

con's avatar
con committed
41
#include <QtCore/QSettings>
hjk's avatar
hjk committed
42
#include <QtGui/QHBoxLayout>
con's avatar
con committed
43
#include <QtGui/QLabel>
hjk's avatar
hjk committed
44
#include <QtGui/QStatusBar>
con's avatar
con committed
45
46
47
48

using namespace Core;
using namespace Core::Internal;

con's avatar
con committed
49
StatusBarManager::StatusBarManager(MainWindow *mainWnd)
hjk's avatar
hjk committed
50
  : QObject(mainWnd),
con's avatar
con committed
51
52
    m_mainWnd(mainWnd)
{
53
    for (int i = 0; i <= StatusBarWidget::Last; ++i) {
con's avatar
con committed
54
55
56
57
58
59
60
        QWidget *w = new QWidget();
        m_mainWnd->statusBar()->insertPermanentWidget(i, w);
        w->setLayout(new QHBoxLayout);
        w->setVisible(true);
        w->layout()->setMargin(0);
        m_statusBarWidgets.append(w);
    }
61
62
    m_mainWnd->statusBar()->insertPermanentWidget(StatusBarWidget::Last+1,
                                                  new QLabel(), 1);
con's avatar
con committed
63
64
}

con's avatar
con committed
65
StatusBarManager::~StatusBarManager()
con's avatar
con committed
66
67
68
{
}

con's avatar
con committed
69
void StatusBarManager::init()
con's avatar
con committed
70
71
72
73
74
75
76
{
    connect(ExtensionSystem::PluginManager::instance(), SIGNAL(objectAdded(QObject*)),
            this, SLOT(objectAdded(QObject*)));
    connect(ExtensionSystem::PluginManager::instance(), SIGNAL(aboutToRemoveObject(QObject*)),
            this, SLOT(aboutToRemoveObject(QObject*)));
}

con's avatar
con committed
77
void StatusBarManager::objectAdded(QObject *obj)
con's avatar
con committed
78
{
79
    StatusBarWidget *view = Aggregation::query<StatusBarWidget>(obj);
con's avatar
con committed
80
81
82
83
84
    if (!view)
        return;

    QWidget *viewWidget = 0;
    viewWidget = view->widget();
85
    m_statusBarWidgets.at(view->position())->layout()->addWidget(viewWidget);
con's avatar
con committed
86
87
88
89

    m_mainWnd->addContextObject(view);
}

con's avatar
con committed
90
void StatusBarManager::aboutToRemoveObject(QObject *obj)
con's avatar
con committed
91
{
92
    StatusBarWidget *view = Aggregation::query<StatusBarWidget>(obj);
hjk's avatar
hjk committed
93
    if (!view)
con's avatar
con committed
94
95
96
97
        return;
    m_mainWnd->removeContextObject(view);
}

con's avatar
con committed
98
void StatusBarManager::extensionsInitalized()
con's avatar
con committed
99
100
{
}