OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / coreplugin / outputpane.cpp
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
8 **
9 **
10 ** GNU Lesser General Public License Usage
11 **
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.
18 **
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.
22 **
23 ** Other Usage
24 **
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.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **************************************************************************/
32
33 #include "outputpane.h"
34 #include "outputpanemanager.h"
35
36 #include "coreconstants.h"
37 #include "icore.h"
38 #include "ioutputpane.h"
39 #include "modemanager.h"
40
41 #include <QtGui/QSplitter>
42 #include <QtGui/QVBoxLayout>
43
44 namespace Core {
45
46 struct OutputPanePlaceHolderPrivate {
47     explicit OutputPanePlaceHolderPrivate(Core::IMode *mode, QSplitter *parent);
48
49     Core::IMode *m_mode;
50     QSplitter *m_splitter;
51     bool m_closeable;
52     static OutputPanePlaceHolder* m_current;
53 };
54
55 OutputPanePlaceHolderPrivate::OutputPanePlaceHolderPrivate(Core::IMode *mode, QSplitter *parent) :
56     m_mode(mode), m_splitter(parent), m_closeable(true)
57 {
58 }
59
60 OutputPanePlaceHolder *OutputPanePlaceHolderPrivate::m_current = 0;
61
62 OutputPanePlaceHolder::OutputPanePlaceHolder(Core::IMode *mode, QSplitter* parent)
63    : QWidget(parent), d(new OutputPanePlaceHolderPrivate(mode, parent))
64 {
65     setVisible(false);
66     setLayout(new QVBoxLayout);
67     QSizePolicy sp;
68     sp.setHorizontalPolicy(QSizePolicy::Preferred);
69     sp.setVerticalPolicy(QSizePolicy::Preferred);
70     sp.setHorizontalStretch(0);
71     setSizePolicy(sp);
72     layout()->setMargin(0);
73     connect(Core::ModeManager::instance(), SIGNAL(currentModeChanged(Core::IMode *)),
74             this, SLOT(currentModeChanged(Core::IMode *)));
75 }
76
77 OutputPanePlaceHolder::~OutputPanePlaceHolder()
78 {
79     if (d->m_current == this) {
80         // FIXME: Prevent exit crash in debug mode.
81         if (Internal::OutputPaneManager *om = Internal::OutputPaneManager::instance()) {
82             om->setParent(0);
83             om->hide();
84         }
85     }
86 }
87
88 void OutputPanePlaceHolder::setCloseable(bool b)
89 {
90     d->m_closeable = b;
91 }
92
93 bool OutputPanePlaceHolder::closeable()
94 {
95     return d->m_closeable;
96 }
97
98 void OutputPanePlaceHolder::currentModeChanged(Core::IMode *mode)
99 {
100     if (d->m_current == this) {
101         d->m_current = 0;
102         Internal::OutputPaneManager *om = Internal::OutputPaneManager::instance();
103         om->setParent(0);
104         om->hide();
105         om->updateStatusButtons(false);
106     }
107     if (d->m_mode == mode) {
108         d->m_current = this;
109         Internal::OutputPaneManager *om = Internal::OutputPaneManager::instance();
110         layout()->addWidget(om);
111         om->show();
112         om->updateStatusButtons(isVisible());
113         om->setCloseable(d->m_closeable);
114     }
115 }
116
117 void OutputPanePlaceHolder::maximizeOrMinimize(bool maximize)
118 {
119     if (!d->m_splitter)
120         return;
121     int idx = d->m_splitter->indexOf(this);
122     if (idx < 0)
123         return;
124
125     QList<int> sizes = d->m_splitter->sizes();
126
127     if (maximize) {
128         int sum = 0;
129         foreach(int s, sizes)
130             sum += s;
131         for (int i = 0; i < sizes.count(); ++i) {
132             sizes[i] = 32;
133         }
134         sizes[idx] = sum - (sizes.count()-1) * 32;
135     } else {
136         int target = sizeHint().height();
137         int space = sizes[idx] - target;
138         if (space > 0) {
139             for (int i = 0; i < sizes.count(); ++i) {
140                 sizes[i] += space / (sizes.count()-1);
141             }
142             sizes[idx] = target;
143         }
144     }
145
146     d->m_splitter->setSizes(sizes);
147
148 }
149
150 bool OutputPanePlaceHolder::isMaximized() const
151 {
152     return Internal::OutputPaneManager::instance()->isMaximized();
153 }
154
155 void OutputPanePlaceHolder::unmaximize()
156 {
157     if (Internal::OutputPaneManager::instance()->isMaximized())
158         Internal::OutputPaneManager::instance()->slotMinMax();
159 }
160
161 OutputPanePlaceHolder *OutputPanePlaceHolder::getCurrent()
162 {
163     return OutputPanePlaceHolderPrivate::m_current;
164 }
165
166 bool OutputPanePlaceHolder::canMaximizeOrMinimize() const
167 {
168     return d->m_splitter != 0;
169 }
170
171 bool OutputPanePlaceHolder::isCurrentVisible()
172 {
173     return OutputPanePlaceHolderPrivate::m_current && OutputPanePlaceHolderPrivate::m_current->isVisible();
174 }
175
176 } // namespace Core
177
178