1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
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.
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights. These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
34 #include "outputpane.h"
35 #include "outputpanemanager.h"
37 #include "coreconstants.h"
39 #include "ioutputpane.h"
40 #include "modemanager.h"
42 #include <QtGui/QSplitter>
43 #include <QtGui/QVBoxLayout>
47 struct OutputPanePlaceHolderPrivate {
48 explicit OutputPanePlaceHolderPrivate(Core::IMode *mode, QSplitter *parent);
51 QSplitter *m_splitter;
53 static OutputPanePlaceHolder* m_current;
56 OutputPanePlaceHolderPrivate::OutputPanePlaceHolderPrivate(Core::IMode *mode, QSplitter *parent) :
57 m_mode(mode), m_splitter(parent), m_closeable(true)
61 OutputPanePlaceHolder *OutputPanePlaceHolderPrivate::m_current = 0;
63 OutputPanePlaceHolder::OutputPanePlaceHolder(Core::IMode *mode, QSplitter* parent)
64 : QWidget(parent), d(new OutputPanePlaceHolderPrivate(mode, parent))
67 setLayout(new QVBoxLayout);
69 sp.setHorizontalPolicy(QSizePolicy::Preferred);
70 sp.setVerticalPolicy(QSizePolicy::Preferred);
71 sp.setHorizontalStretch(0);
73 layout()->setMargin(0);
74 connect(Core::ModeManager::instance(), SIGNAL(currentModeChanged(Core::IMode *)),
75 this, SLOT(currentModeChanged(Core::IMode *)));
78 OutputPanePlaceHolder::~OutputPanePlaceHolder()
80 if (d->m_current == this) {
81 // FIXME: Prevent exit crash in debug mode.
82 if (Internal::OutputPaneManager *om = Internal::OutputPaneManager::instance()) {
89 void OutputPanePlaceHolder::setCloseable(bool b)
94 bool OutputPanePlaceHolder::closeable()
96 return d->m_closeable;
99 void OutputPanePlaceHolder::currentModeChanged(Core::IMode *mode)
101 if (d->m_current == this) {
103 Internal::OutputPaneManager *om = Internal::OutputPaneManager::instance();
106 om->updateStatusButtons(false);
108 if (d->m_mode == mode) {
110 Internal::OutputPaneManager *om = Internal::OutputPaneManager::instance();
111 layout()->addWidget(om);
113 om->updateStatusButtons(isVisible());
114 om->setCloseable(d->m_closeable);
118 void OutputPanePlaceHolder::maximizeOrMinimize(bool maximize)
122 int idx = d->m_splitter->indexOf(this);
126 QList<int> sizes = d->m_splitter->sizes();
130 foreach(int s, sizes)
132 for (int i = 0; i < sizes.count(); ++i) {
135 sizes[idx] = sum - (sizes.count()-1) * 32;
137 int target = sizeHint().height();
138 int space = sizes[idx] - target;
140 for (int i = 0; i < sizes.count(); ++i) {
141 sizes[i] += space / (sizes.count()-1);
147 d->m_splitter->setSizes(sizes);
151 bool OutputPanePlaceHolder::isMaximized() const
153 return Internal::OutputPaneManager::instance()->isMaximized();
156 void OutputPanePlaceHolder::unmaximize()
158 if (Internal::OutputPaneManager::instance()->isMaximized())
159 Internal::OutputPaneManager::instance()->slotMinMax();
162 OutputPanePlaceHolder *OutputPanePlaceHolder::getCurrent()
164 return OutputPanePlaceHolderPrivate::m_current;
167 bool OutputPanePlaceHolder::canMaximizeOrMinimize() const
169 return d->m_splitter != 0;
172 bool OutputPanePlaceHolder::isCurrentVisible()
174 return OutputPanePlaceHolderPrivate::m_current && OutputPanePlaceHolderPrivate::m_current->isVisible();