2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://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
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2008-12-02 14:09:21 +01:00
|
|
|
|
2014-11-16 10:52:41 +02:00
|
|
|
#include "imode.h"
|
|
|
|
|
#include "modemanager.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "outputpane.h"
|
2010-09-16 12:26:28 +02:00
|
|
|
#include "outputpanemanager.h"
|
|
|
|
|
|
2016-03-08 14:09:01 +01:00
|
|
|
#include <QResizeEvent>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QSplitter>
|
|
|
|
|
#include <QVBoxLayout>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2020-06-26 13:59:38 +02:00
|
|
|
using namespace Utils;
|
|
|
|
|
|
2010-09-16 12:26:28 +02:00
|
|
|
namespace Core {
|
2009-01-19 12:39:20 +01:00
|
|
|
|
2016-03-08 14:09:01 +01:00
|
|
|
class OutputPanePlaceHolderPrivate {
|
|
|
|
|
public:
|
2016-03-25 20:00:19 +01:00
|
|
|
explicit OutputPanePlaceHolderPrivate(Id mode, QSplitter *parent);
|
2009-07-16 16:30:00 +02:00
|
|
|
|
2016-03-25 20:00:19 +01:00
|
|
|
Id m_mode;
|
2010-09-16 12:26:28 +02:00
|
|
|
QSplitter *m_splitter;
|
2016-03-08 14:09:01 +01:00
|
|
|
int m_nonMaximizedSize = 0;
|
|
|
|
|
bool m_isMaximized = false;
|
|
|
|
|
bool m_initialized = false;
|
2010-09-16 12:26:28 +02:00
|
|
|
static OutputPanePlaceHolder* m_current;
|
|
|
|
|
};
|
2009-04-30 12:50:52 +02:00
|
|
|
|
2016-03-25 20:00:19 +01:00
|
|
|
OutputPanePlaceHolderPrivate::OutputPanePlaceHolderPrivate(Id mode, QSplitter *parent) :
|
2016-03-08 14:09:01 +01:00
|
|
|
m_mode(mode), m_splitter(parent)
|
2010-09-16 12:26:28 +02:00
|
|
|
{
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2018-07-21 21:11:46 +02:00
|
|
|
OutputPanePlaceHolder *OutputPanePlaceHolderPrivate::m_current = nullptr;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2016-03-25 20:00:19 +01:00
|
|
|
OutputPanePlaceHolder::OutputPanePlaceHolder(Id mode, QSplitter *parent)
|
2010-09-16 12:26:28 +02:00
|
|
|
: QWidget(parent), d(new OutputPanePlaceHolderPrivate(mode, parent))
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
setVisible(false);
|
|
|
|
|
setLayout(new QVBoxLayout);
|
|
|
|
|
QSizePolicy sp;
|
|
|
|
|
sp.setHorizontalPolicy(QSizePolicy::Preferred);
|
|
|
|
|
sp.setVerticalPolicy(QSizePolicy::Preferred);
|
|
|
|
|
sp.setHorizontalStretch(0);
|
|
|
|
|
setSizePolicy(sp);
|
2019-08-29 10:36:01 +02:00
|
|
|
layout()->setContentsMargins(0, 0, 0, 0);
|
2014-11-16 10:52:41 +02:00
|
|
|
connect(ModeManager::instance(), &ModeManager::currentModeChanged,
|
|
|
|
|
this, &OutputPanePlaceHolder::currentModeChanged);
|
2016-03-07 15:57:58 +01:00
|
|
|
// if this is part of a lazily created mode widget,
|
|
|
|
|
// we need to check if this is the current placeholder
|
2018-07-10 15:49:50 +02:00
|
|
|
currentModeChanged(ModeManager::currentModeId());
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OutputPanePlaceHolder::~OutputPanePlaceHolder()
|
|
|
|
|
{
|
2010-09-16 12:26:28 +02:00
|
|
|
if (d->m_current == this) {
|
2010-12-06 10:23:51 +01:00
|
|
|
if (Internal::OutputPaneManager *om = Internal::OutputPaneManager::instance()) {
|
2018-07-21 21:11:46 +02:00
|
|
|
om->setParent(nullptr);
|
2010-12-06 10:23:51 +01:00
|
|
|
om->hide();
|
|
|
|
|
}
|
2016-04-04 09:16:44 +02:00
|
|
|
OutputPanePlaceHolderPrivate::m_current = nullptr;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2011-09-16 15:00:41 +02:00
|
|
|
delete d;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2016-03-25 20:00:19 +01:00
|
|
|
void OutputPanePlaceHolder::currentModeChanged(Id mode)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-09-16 12:26:28 +02:00
|
|
|
if (d->m_current == this) {
|
2018-07-21 21:11:46 +02:00
|
|
|
d->m_current = nullptr;
|
2016-03-08 14:09:01 +01:00
|
|
|
if (d->m_initialized)
|
|
|
|
|
Internal::OutputPaneManager::setOutputPaneHeightSetting(d->m_nonMaximizedSize);
|
2010-09-16 12:26:28 +02:00
|
|
|
Internal::OutputPaneManager *om = Internal::OutputPaneManager::instance();
|
|
|
|
|
om->hide();
|
2018-07-21 21:11:46 +02:00
|
|
|
om->setParent(nullptr);
|
2010-09-16 12:26:28 +02:00
|
|
|
om->updateStatusButtons(false);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2010-09-16 12:26:28 +02:00
|
|
|
if (d->m_mode == mode) {
|
2016-03-08 14:09:01 +01:00
|
|
|
if (d->m_current && d->m_current->d->m_initialized)
|
|
|
|
|
Internal::OutputPaneManager::setOutputPaneHeightSetting(d->m_current->d->m_nonMaximizedSize);
|
2010-09-16 12:26:28 +02:00
|
|
|
d->m_current = this;
|
|
|
|
|
Internal::OutputPaneManager *om = Internal::OutputPaneManager::instance();
|
|
|
|
|
layout()->addWidget(om);
|
|
|
|
|
om->show();
|
|
|
|
|
om->updateStatusButtons(isVisible());
|
2016-03-08 14:09:01 +01:00
|
|
|
Internal::OutputPaneManager::updateMaximizeButton(d->m_isMaximized);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-08 14:09:01 +01:00
|
|
|
void OutputPanePlaceHolder::setMaximized(bool maximize)
|
2009-12-14 11:52:23 +01:00
|
|
|
{
|
2016-03-08 14:09:01 +01:00
|
|
|
if (d->m_isMaximized == maximize)
|
|
|
|
|
return;
|
2010-09-16 12:26:28 +02:00
|
|
|
if (!d->m_splitter)
|
2009-12-14 11:52:23 +01:00
|
|
|
return;
|
2010-09-16 12:26:28 +02:00
|
|
|
int idx = d->m_splitter->indexOf(this);
|
2009-12-14 11:52:23 +01:00
|
|
|
if (idx < 0)
|
|
|
|
|
return;
|
|
|
|
|
|
2016-03-08 14:09:01 +01:00
|
|
|
d->m_isMaximized = maximize;
|
|
|
|
|
if (d->m_current == this)
|
|
|
|
|
Internal::OutputPaneManager::updateMaximizeButton(d->m_isMaximized);
|
2010-09-16 12:26:28 +02:00
|
|
|
QList<int> sizes = d->m_splitter->sizes();
|
2009-12-14 11:52:23 +01:00
|
|
|
|
|
|
|
|
if (maximize) {
|
2016-03-08 14:09:01 +01:00
|
|
|
d->m_nonMaximizedSize = sizes[idx];
|
2009-12-15 10:09:27 +01:00
|
|
|
int sum = 0;
|
2012-11-28 20:44:03 +02:00
|
|
|
foreach (int s, sizes)
|
2009-12-14 11:52:23 +01:00
|
|
|
sum += s;
|
|
|
|
|
for (int i = 0; i < sizes.count(); ++i) {
|
|
|
|
|
sizes[i] = 32;
|
|
|
|
|
}
|
|
|
|
|
sizes[idx] = sum - (sizes.count()-1) * 32;
|
|
|
|
|
} else {
|
2016-03-08 14:09:01 +01:00
|
|
|
int target = d->m_nonMaximizedSize > 0 ? d->m_nonMaximizedSize : sizeHint().height();
|
2009-12-14 11:52:23 +01:00
|
|
|
int space = sizes[idx] - target;
|
|
|
|
|
if (space > 0) {
|
|
|
|
|
for (int i = 0; i < sizes.count(); ++i) {
|
|
|
|
|
sizes[i] += space / (sizes.count()-1);
|
|
|
|
|
}
|
|
|
|
|
sizes[idx] = target;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-16 12:26:28 +02:00
|
|
|
d->m_splitter->setSizes(sizes);
|
2009-12-14 11:52:23 +01:00
|
|
|
}
|
|
|
|
|
|
2009-12-15 11:05:17 +01:00
|
|
|
bool OutputPanePlaceHolder::isMaximized() const
|
|
|
|
|
{
|
2016-03-08 14:09:01 +01:00
|
|
|
return d->m_isMaximized;
|
2009-12-15 11:05:17 +01:00
|
|
|
}
|
|
|
|
|
|
2016-03-08 14:09:01 +01:00
|
|
|
void OutputPanePlaceHolder::setHeight(int height)
|
2011-11-24 11:38:35 +01:00
|
|
|
{
|
2013-03-26 10:43:27 +10:00
|
|
|
if (height == 0)
|
|
|
|
|
return;
|
2011-11-24 11:38:35 +01:00
|
|
|
if (!d->m_splitter)
|
|
|
|
|
return;
|
2016-03-08 14:09:01 +01:00
|
|
|
const int idx = d->m_splitter->indexOf(this);
|
2011-11-24 11:38:35 +01:00
|
|
|
if (idx < 0)
|
|
|
|
|
return;
|
|
|
|
|
|
2013-03-26 10:43:16 +10:00
|
|
|
d->m_splitter->refresh();
|
2011-11-24 11:38:35 +01:00
|
|
|
QList<int> sizes = d->m_splitter->sizes();
|
2016-03-08 14:09:01 +01:00
|
|
|
const int difference = height - sizes.at(idx);
|
|
|
|
|
if (difference == 0)
|
2011-11-24 11:38:35 +01:00
|
|
|
return;
|
2016-03-08 14:09:01 +01:00
|
|
|
const int adaption = difference / (sizes.count()-1);
|
2011-11-24 11:38:35 +01:00
|
|
|
for (int i = 0; i < sizes.count(); ++i) {
|
2016-03-08 14:09:01 +01:00
|
|
|
sizes[i] -= adaption;
|
2011-11-24 11:38:35 +01:00
|
|
|
}
|
2013-03-26 10:43:27 +10:00
|
|
|
sizes[idx] = height;
|
2011-11-24 11:38:35 +01:00
|
|
|
d->m_splitter->setSizes(sizes);
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-26 10:43:27 +10:00
|
|
|
void OutputPanePlaceHolder::ensureSizeHintAsMinimum()
|
|
|
|
|
{
|
|
|
|
|
Internal::OutputPaneManager *om = Internal::OutputPaneManager::instance();
|
|
|
|
|
int minimum = (d->m_splitter->orientation() == Qt::Vertical
|
|
|
|
|
? om->sizeHint().height() : om->sizeHint().width());
|
2016-08-25 13:42:55 +02:00
|
|
|
if (nonMaximizedSize() < minimum && !d->m_isMaximized)
|
2016-03-08 14:09:01 +01:00
|
|
|
setHeight(minimum);
|
2013-03-26 10:43:27 +10:00
|
|
|
}
|
|
|
|
|
|
2016-03-08 14:09:01 +01:00
|
|
|
int OutputPanePlaceHolder::nonMaximizedSize() const
|
2009-12-15 11:05:17 +01:00
|
|
|
{
|
2016-09-06 16:57:50 +02:00
|
|
|
if (!d->m_initialized)
|
|
|
|
|
return Internal::OutputPaneManager::outputPaneHeightSetting();
|
2016-03-08 14:09:01 +01:00
|
|
|
return d->m_nonMaximizedSize;
|
2009-04-30 12:50:52 +02:00
|
|
|
}
|
|
|
|
|
|
2016-03-08 14:09:01 +01:00
|
|
|
void OutputPanePlaceHolder::resizeEvent(QResizeEvent *event)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2016-03-08 14:09:01 +01:00
|
|
|
if (d->m_isMaximized || event->size().height() == 0)
|
|
|
|
|
return;
|
|
|
|
|
d->m_nonMaximizedSize = event->size().height();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2016-03-08 14:09:01 +01:00
|
|
|
void OutputPanePlaceHolder::showEvent(QShowEvent *)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2016-03-08 14:09:01 +01:00
|
|
|
if (!d->m_initialized) {
|
|
|
|
|
d->m_initialized = true;
|
|
|
|
|
setHeight(Internal::OutputPaneManager::outputPaneHeightSetting());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OutputPanePlaceHolder *OutputPanePlaceHolder::getCurrent()
|
|
|
|
|
{
|
|
|
|
|
return OutputPanePlaceHolderPrivate::m_current;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-09-16 12:26:28 +02:00
|
|
|
bool OutputPanePlaceHolder::isCurrentVisible()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-09-16 12:26:28 +02:00
|
|
|
return OutputPanePlaceHolderPrivate::m_current && OutputPanePlaceHolderPrivate::m_current->isVisible();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-09-16 12:26:28 +02:00
|
|
|
} // namespace Core
|
2009-04-30 12:50:52 +02:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
|