outputpane.cpp 4.89 KB
Newer Older
1
/**************************************************************************
con's avatar
con committed
2
3
4
**
** This file is part of Qt Creator
**
hjk's avatar
hjk committed
5
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
con's avatar
con committed
6
**
7
** Contact: Nokia Corporation (qt-info@nokia.com)
con's avatar
con committed
8
**
9
** Commercial Usage
10
**
11
12
13
14
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
15
**
16
** GNU Lesser General Public License Usage
17
**
18
19
20
21
22
23
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24
**
25
** If you are unsure which license is appropriate for your use, please
hjk's avatar
hjk committed
26
** contact the sales department at http://qt.nokia.com/contact.
con's avatar
con committed
27
**
28
**************************************************************************/
hjk's avatar
hjk committed
29

con's avatar
con committed
30
#include "outputpane.h"
31
32
#include "outputpanemanager.h"

con's avatar
con committed
33
#include "coreconstants.h"
34
#include "icore.h"
con's avatar
con committed
35
36
37
#include "ioutputpane.h"
#include "modemanager.h"

38
39
#include <QtGui/QSplitter>
#include <QtGui/QVBoxLayout>
con's avatar
con committed
40

41
namespace Core {
42

43
44
struct OutputPanePlaceHolderPrivate {
    explicit OutputPanePlaceHolderPrivate(Core::IMode *mode, QSplitter *parent);
con's avatar
con committed
45

46
47
48
49
50
    Core::IMode *m_mode;
    QSplitter *m_splitter;
    bool m_closeable;
    static OutputPanePlaceHolder* m_current;
};
51

52
53
54
55
OutputPanePlaceHolderPrivate::OutputPanePlaceHolderPrivate(Core::IMode *mode, QSplitter *parent) :
    m_mode(mode), m_splitter(parent), m_closeable(true)
{
}
con's avatar
con committed
56

57
OutputPanePlaceHolder *OutputPanePlaceHolderPrivate::m_current = 0;
con's avatar
con committed
58

59
OutputPanePlaceHolder::OutputPanePlaceHolder(Core::IMode *mode, QSplitter* parent)
60
   : QWidget(parent), d(new OutputPanePlaceHolderPrivate(mode, parent))
con's avatar
con committed
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
{
    setVisible(false);
    setLayout(new QVBoxLayout);
    QSizePolicy sp;
    sp.setHorizontalPolicy(QSizePolicy::Preferred);
    sp.setVerticalPolicy(QSizePolicy::Preferred);
    sp.setHorizontalStretch(0);
    setSizePolicy(sp);
    layout()->setMargin(0);
    connect(Core::ModeManager::instance(), SIGNAL(currentModeChanged(Core::IMode *)),
            this, SLOT(currentModeChanged(Core::IMode *)));
}

OutputPanePlaceHolder::~OutputPanePlaceHolder()
{
76
    if (d->m_current == this) {
77
78
79
80
81
        // FIXME: Prevent exit crash in debug mode.
        if (Internal::OutputPaneManager *om = Internal::OutputPaneManager::instance()) {
            om->setParent(0);
            om->hide();
        }
con's avatar
con committed
82
83
84
85
86
    }
}

void OutputPanePlaceHolder::setCloseable(bool b)
{
87
    d->m_closeable = b;
con's avatar
con committed
88
89
90
91
}

bool OutputPanePlaceHolder::closeable()
{
92
    return d->m_closeable;
con's avatar
con committed
93
94
95
96
}

void OutputPanePlaceHolder::currentModeChanged(Core::IMode *mode)
{
97
98
99
100
101
102
    if (d->m_current == this) {
        d->m_current = 0;
        Internal::OutputPaneManager *om = Internal::OutputPaneManager::instance();
        om->setParent(0);
        om->hide();
        om->updateStatusButtons(false);
con's avatar
con committed
103
    }
104
105
106
107
108
109
110
    if (d->m_mode == mode) {
        d->m_current = this;
        Internal::OutputPaneManager *om = Internal::OutputPaneManager::instance();
        layout()->addWidget(om);
        om->show();
        om->updateStatusButtons(isVisible());
        om->setCloseable(d->m_closeable);
con's avatar
con committed
111
112
113
    }
}

114
115
void OutputPanePlaceHolder::maximizeOrMinimize(bool maximize)
{
116
    if (!d->m_splitter)
117
        return;
118
    int idx = d->m_splitter->indexOf(this);
119
120
121
    if (idx < 0)
        return;

122
    QList<int> sizes = d->m_splitter->sizes();
123
124

    if (maximize) {
Tobias Hunger's avatar
Tobias Hunger committed
125
        int sum = 0;
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
        foreach(int s, sizes)
            sum += s;
        for (int i = 0; i < sizes.count(); ++i) {
            sizes[i] = 32;
        }
        sizes[idx] = sum - (sizes.count()-1) * 32;
    } else {
        int target = sizeHint().height();
        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;
        }
    }

143
    d->m_splitter->setSizes(sizes);
144
145
146

}

147
148
bool OutputPanePlaceHolder::isMaximized() const
{
149
    return Internal::OutputPaneManager::instance()->isMaximized();
150
151
152
153
}

void OutputPanePlaceHolder::unmaximize()
{
154
155
    if (Internal::OutputPaneManager::instance()->isMaximized())
        Internal::OutputPaneManager::instance()->slotMinMax();
156
157
}

158
OutputPanePlaceHolder *OutputPanePlaceHolder::getCurrent()
con's avatar
con committed
159
{
160
    return OutputPanePlaceHolderPrivate::m_current;
con's avatar
con committed
161
162
}

163
bool OutputPanePlaceHolder::canMaximizeOrMinimize() const
con's avatar
con committed
164
{
165
    return d->m_splitter != 0;
con's avatar
con committed
166
167
}

168
bool OutputPanePlaceHolder::isCurrentVisible()
con's avatar
con committed
169
{
170
    return OutputPanePlaceHolderPrivate::m_current && OutputPanePlaceHolderPrivate::m_current->isVisible();
con's avatar
con committed
171
172
}

173
} // namespace Core
174

con's avatar
con committed
175