OSDN Git Service

Merge branch 'master' of scm.dev.nokia.troll.no:creator/mainline
[qt-creator-jp/qt-creator-jp.git] / src / plugins / coreplugin / statusbarmanager.cpp
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** Commercial Usage
10 **
11 ** Licensees holding valid Qt Commercial licenses may use this file in
12 ** accordance with the Qt Commercial License Agreement provided with the
13 ** Software or, alternatively, in accordance with the terms contained in
14 ** a written agreement between you and Nokia.
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 ** If you are unsure which license is appropriate for your use, please
26 ** contact the sales department at http://qt.nokia.com/contact.
27 **
28 **************************************************************************/
29
30 #include "statusbarmanager.h"
31
32 #include "coreconstants.h"
33 #include "mainwindow.h"
34 #include "statusbarwidget.h"
35
36 #include <coreplugin/actionmanager/actionmanager.h>
37 #include <coreplugin/actionmanager/command.h>
38 #include <aggregation/aggregate.h>
39 #include <extensionsystem/pluginmanager.h>
40
41 #include <QtCore/QSettings>
42 #include <QtGui/QHBoxLayout>
43 #include <QtGui/QLabel>
44 #include <QtGui/QStatusBar>
45
46 using namespace Core;
47 using namespace Core::Internal;
48
49 StatusBarManager::StatusBarManager(MainWindow *mainWnd)
50   : QObject(mainWnd),
51     m_mainWnd(mainWnd)
52 {
53     for (int i = 0; i <= StatusBarWidget::Last; ++i) {
54         QWidget *w = new QWidget();
55         m_mainWnd->statusBar()->insertPermanentWidget(i, w);
56         w->setLayout(new QHBoxLayout);
57         w->setVisible(true);
58         w->layout()->setMargin(0);
59         m_statusBarWidgets.append(w);
60     }
61     m_mainWnd->statusBar()->insertPermanentWidget(StatusBarWidget::Last+1,
62                                                   new QLabel(), 1);
63 }
64
65 StatusBarManager::~StatusBarManager()
66 {
67 }
68
69 void StatusBarManager::init()
70 {
71     connect(ExtensionSystem::PluginManager::instance(), SIGNAL(objectAdded(QObject*)),
72             this, SLOT(objectAdded(QObject*)));
73     connect(ExtensionSystem::PluginManager::instance(), SIGNAL(aboutToRemoveObject(QObject*)),
74             this, SLOT(aboutToRemoveObject(QObject*)));
75 }
76
77 void StatusBarManager::objectAdded(QObject *obj)
78 {
79     StatusBarWidget *view = Aggregation::query<StatusBarWidget>(obj);
80     if (!view)
81         return;
82
83     QWidget *viewWidget = 0;
84     viewWidget = view->widget();
85     m_statusBarWidgets.at(view->position())->layout()->addWidget(viewWidget);
86
87     m_mainWnd->addContextObject(view);
88 }
89
90 void StatusBarManager::aboutToRemoveObject(QObject *obj)
91 {
92     StatusBarWidget *view = Aggregation::query<StatusBarWidget>(obj);
93     if (!view)
94         return;
95     m_mainWnd->removeContextObject(view);
96 }
97
98 void StatusBarManager::extensionsInitalized()
99 {
100 }