1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
10 ** GNU Lesser General Public License Usage
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
31 **************************************************************************/
33 #include "outputpane.h"
34 #include "outputpanemanager.h"
36 #include "coreconstants.h"
38 #include "ioutputpane.h"
39 #include "modemanager.h"
41 #include <QtGui/QSplitter>
42 #include <QtGui/QVBoxLayout>
46 struct OutputPanePlaceHolderPrivate {
47 explicit OutputPanePlaceHolderPrivate(Core::IMode *mode, QSplitter *parent);
50 QSplitter *m_splitter;
52 static OutputPanePlaceHolder* m_current;
55 OutputPanePlaceHolderPrivate::OutputPanePlaceHolderPrivate(Core::IMode *mode, QSplitter *parent) :
56 m_mode(mode), m_splitter(parent), m_closeable(true)
60 OutputPanePlaceHolder *OutputPanePlaceHolderPrivate::m_current = 0;
62 OutputPanePlaceHolder::OutputPanePlaceHolder(Core::IMode *mode, QSplitter* parent)
63 : QWidget(parent), d(new OutputPanePlaceHolderPrivate(mode, parent))
66 setLayout(new QVBoxLayout);
68 sp.setHorizontalPolicy(QSizePolicy::Preferred);
69 sp.setVerticalPolicy(QSizePolicy::Preferred);
70 sp.setHorizontalStretch(0);
72 layout()->setMargin(0);
73 connect(Core::ModeManager::instance(), SIGNAL(currentModeChanged(Core::IMode *)),
74 this, SLOT(currentModeChanged(Core::IMode *)));
77 OutputPanePlaceHolder::~OutputPanePlaceHolder()
79 if (d->m_current == this) {
80 // FIXME: Prevent exit crash in debug mode.
81 if (Internal::OutputPaneManager *om = Internal::OutputPaneManager::instance()) {
88 void OutputPanePlaceHolder::setCloseable(bool b)
93 bool OutputPanePlaceHolder::closeable()
95 return d->m_closeable;
98 void OutputPanePlaceHolder::currentModeChanged(Core::IMode *mode)
100 if (d->m_current == this) {
102 Internal::OutputPaneManager *om = Internal::OutputPaneManager::instance();
105 om->updateStatusButtons(false);
107 if (d->m_mode == mode) {
109 Internal::OutputPaneManager *om = Internal::OutputPaneManager::instance();
110 layout()->addWidget(om);
112 om->updateStatusButtons(isVisible());
113 om->setCloseable(d->m_closeable);
117 void OutputPanePlaceHolder::maximizeOrMinimize(bool maximize)
121 int idx = d->m_splitter->indexOf(this);
125 QList<int> sizes = d->m_splitter->sizes();
129 foreach(int s, sizes)
131 for (int i = 0; i < sizes.count(); ++i) {
134 sizes[idx] = sum - (sizes.count()-1) * 32;
136 int target = sizeHint().height();
137 int space = sizes[idx] - target;
139 for (int i = 0; i < sizes.count(); ++i) {
140 sizes[i] += space / (sizes.count()-1);
146 d->m_splitter->setSizes(sizes);
150 bool OutputPanePlaceHolder::isMaximized() const
152 return Internal::OutputPaneManager::instance()->isMaximized();
155 void OutputPanePlaceHolder::unmaximize()
157 if (Internal::OutputPaneManager::instance()->isMaximized())
158 Internal::OutputPaneManager::instance()->slotMinMax();
161 OutputPanePlaceHolder *OutputPanePlaceHolder::getCurrent()
163 return OutputPanePlaceHolderPrivate::m_current;
166 bool OutputPanePlaceHolder::canMaximizeOrMinimize() const
168 return d->m_splitter != 0;
171 bool OutputPanePlaceHolder::isCurrentVisible()
173 return OutputPanePlaceHolderPrivate::m_current && OutputPanePlaceHolderPrivate::m_current->isVisible();