2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** Copyright (C) 2015 The Qt Company Ltd.
|
|
|
|
|
** Contact: http://www.qt.io/licensing
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2015-01-14 18:07:15 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms and
|
|
|
|
|
** conditions see http://www.qt.io/terms-conditions. For further information
|
2014-10-01 13:21:18 +02:00
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2014-10-01 13:21:18 +02:00
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2012-10-02 09:12:39 +02:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** In addition, as a special exception, The Qt Company gives you certain additional
|
|
|
|
|
** rights. These rights are described in The Qt Company LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2008-12-02 15:08:31 +01:00
|
|
|
|
2009-12-09 11:05:18 +01:00
|
|
|
#include "statusbarmanager.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
#include "mainwindow.h"
|
2009-12-08 19:14:39 +01:00
|
|
|
#include "statusbarwidget.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-01-19 12:39:20 +01:00
|
|
|
#include <extensionsystem/pluginmanager.h>
|
2008-12-02 15:08:31 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QHBoxLayout>
|
|
|
|
|
#include <QLabel>
|
2014-02-27 17:26:04 +01:00
|
|
|
#include <QResizeEvent>
|
|
|
|
|
#include <QSplitter>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QStatusBar>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2014-02-27 17:26:04 +01:00
|
|
|
static const char kSettingsGroup[] = "StatusBar";
|
|
|
|
|
static const char kLeftSplitWidthKey[] = "LeftSplitWidth";
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
using namespace Core;
|
|
|
|
|
using namespace Core::Internal;
|
|
|
|
|
|
2013-04-10 10:41:29 +02:00
|
|
|
static QWidget *createWidget(QWidget *parent = 0)
|
2013-03-22 14:11:19 +01:00
|
|
|
{
|
2013-04-10 10:41:29 +02:00
|
|
|
QWidget *w = new QWidget(parent);
|
2013-03-22 14:11:19 +01:00
|
|
|
w->setLayout(new QHBoxLayout);
|
|
|
|
|
w->setVisible(true);
|
|
|
|
|
w->layout()->setMargin(0);
|
|
|
|
|
return w;
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-09 11:05:18 +01:00
|
|
|
StatusBarManager::StatusBarManager(MainWindow *mainWnd)
|
2009-03-09 12:41:34 +01:00
|
|
|
: QObject(mainWnd),
|
2008-12-02 12:01:29 +01:00
|
|
|
m_mainWnd(mainWnd)
|
|
|
|
|
{
|
2013-04-10 10:41:29 +02:00
|
|
|
QStatusBar *bar = m_mainWnd->statusBar();
|
2014-02-27 17:26:04 +01:00
|
|
|
m_splitter = new NonResizingSplitter(bar);
|
|
|
|
|
bar->insertPermanentWidget(0, m_splitter, 10);
|
|
|
|
|
m_splitter->setChildrenCollapsible(false);
|
|
|
|
|
// first
|
|
|
|
|
QWidget *w = createWidget(m_splitter);
|
|
|
|
|
w->layout()->setContentsMargins(0, 0, 3, 0);
|
|
|
|
|
m_splitter->addWidget(w);
|
|
|
|
|
m_statusBarWidgets.append(w);
|
|
|
|
|
|
|
|
|
|
QWidget *w2 = createWidget(m_splitter);
|
|
|
|
|
w2->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed);
|
|
|
|
|
m_splitter->addWidget(w2);
|
|
|
|
|
// second
|
|
|
|
|
w = createWidget(w2);
|
|
|
|
|
w2->layout()->addWidget(w);
|
|
|
|
|
m_statusBarWidgets.append(w);
|
|
|
|
|
// third
|
|
|
|
|
w = createWidget(w2);
|
|
|
|
|
w2->layout()->addWidget(w);
|
|
|
|
|
m_statusBarWidgets.append(w);
|
|
|
|
|
|
|
|
|
|
static_cast<QBoxLayout *>(w2->layout())->addStretch(1);
|
|
|
|
|
|
2013-04-10 10:41:29 +02:00
|
|
|
QWidget *rightCornerWidget = createWidget(bar);
|
2014-02-27 17:26:04 +01:00
|
|
|
bar->insertPermanentWidget(1, rightCornerWidget);
|
2013-03-22 14:11:19 +01:00
|
|
|
m_statusBarWidgets.append(rightCornerWidget);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2009-12-09 11:05:18 +01:00
|
|
|
StatusBarManager::~StatusBarManager()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-09 11:05:18 +01:00
|
|
|
void StatusBarManager::init()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
connect(ExtensionSystem::PluginManager::instance(), SIGNAL(objectAdded(QObject*)),
|
|
|
|
|
this, SLOT(objectAdded(QObject*)));
|
|
|
|
|
connect(ExtensionSystem::PluginManager::instance(), SIGNAL(aboutToRemoveObject(QObject*)),
|
|
|
|
|
this, SLOT(aboutToRemoveObject(QObject*)));
|
2014-02-27 17:26:04 +01:00
|
|
|
connect(ICore::instance(), SIGNAL(saveSettingsRequested()), this, SLOT(saveSettings()));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2009-12-09 11:05:18 +01:00
|
|
|
void StatusBarManager::objectAdded(QObject *obj)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2014-05-06 17:35:12 +02:00
|
|
|
StatusBarWidget *view = qobject_cast<StatusBarWidget *>(obj);
|
2008-12-02 12:01:29 +01:00
|
|
|
if (!view)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
QWidget *viewWidget = 0;
|
|
|
|
|
viewWidget = view->widget();
|
2009-12-08 19:14:39 +01:00
|
|
|
m_statusBarWidgets.at(view->position())->layout()->addWidget(viewWidget);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
m_mainWnd->addContextObject(view);
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-09 11:05:18 +01:00
|
|
|
void StatusBarManager::aboutToRemoveObject(QObject *obj)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2014-05-06 17:35:12 +02:00
|
|
|
StatusBarWidget *view = qobject_cast<StatusBarWidget *>(obj);
|
2008-12-08 12:01:53 +01:00
|
|
|
if (!view)
|
2008-12-02 12:01:29 +01:00
|
|
|
return;
|
|
|
|
|
m_mainWnd->removeContextObject(view);
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-27 17:26:04 +01:00
|
|
|
void StatusBarManager::saveSettings()
|
|
|
|
|
{
|
|
|
|
|
QSettings *s = ICore::settings();
|
|
|
|
|
s->beginGroup(QLatin1String(kSettingsGroup));
|
|
|
|
|
s->setValue(QLatin1String(kLeftSplitWidthKey), m_splitter->sizes().at(0));
|
|
|
|
|
s->endGroup();
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-09 11:05:18 +01:00
|
|
|
void StatusBarManager::extensionsInitalized()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
}
|
2014-02-27 17:26:04 +01:00
|
|
|
|
|
|
|
|
void StatusBarManager::restoreSettings()
|
|
|
|
|
{
|
|
|
|
|
QSettings *s = ICore::settings();
|
|
|
|
|
s->beginGroup(QLatin1String(kSettingsGroup));
|
|
|
|
|
int leftSplitWidth = s->value(QLatin1String(kLeftSplitWidthKey), -1).toInt();
|
|
|
|
|
s->endGroup();
|
|
|
|
|
if (leftSplitWidth < 0) {
|
|
|
|
|
// size first split after its sizeHint + a bit of buffer
|
|
|
|
|
leftSplitWidth = m_splitter->widget(0)->sizeHint().width();
|
|
|
|
|
}
|
|
|
|
|
int sum = 0;
|
|
|
|
|
foreach (int w, m_splitter->sizes())
|
|
|
|
|
sum += w;
|
|
|
|
|
m_splitter->setSizes(QList<int>() << leftSplitWidth << (sum - leftSplitWidth));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NonResizingSplitter::NonResizingSplitter(QWidget *parent)
|
|
|
|
|
: MiniSplitter(parent, Light)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NonResizingSplitter::resizeEvent(QResizeEvent *ev)
|
|
|
|
|
{
|
|
|
|
|
// bypass QSplitter magic
|
|
|
|
|
int leftSplitWidth = qMin(sizes().at(0), ev->size().width());
|
|
|
|
|
int rightSplitWidth = qMax(0, ev->size().width() - leftSplitWidth);
|
|
|
|
|
setSizes(QList<int>() << leftSplitWidth << rightSplitWidth);
|
|
|
|
|
return QWidget::resizeEvent(ev);
|
|
|
|
|
}
|