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 "rightpane.h"
36 #include <coreplugin/modemanager.h>
38 #include <QtCore/QSettings>
40 #include <QtGui/QVBoxLayout>
41 #include <QtGui/QSplitter>
42 #include <QtGui/QResizeEvent>
43 #include <QtGui/QTextEdit>
47 using namespace Core::Internal;
49 RightPanePlaceHolder *RightPanePlaceHolder::m_current = 0;
51 RightPanePlaceHolder* RightPanePlaceHolder::current()
56 RightPanePlaceHolder::RightPanePlaceHolder(Core::IMode *mode, QWidget *parent)
57 :QWidget(parent), m_mode(mode)
59 setLayout(new QVBoxLayout);
60 layout()->setMargin(0);
61 connect(Core::ModeManager::instance(), SIGNAL(currentModeChanged(Core::IMode *)),
62 this, SLOT(currentModeChanged(Core::IMode *)));
65 RightPanePlaceHolder::~RightPanePlaceHolder()
67 if (m_current == this) {
68 RightPaneWidget::instance()->setParent(0);
69 RightPaneWidget::instance()->hide();
73 void RightPanePlaceHolder::applyStoredSize(int width)
76 QSplitter *splitter = qobject_cast<QSplitter *>(parentWidget());
78 // A splitter we need to resize the splitter sizes
79 QList<int> sizes = splitter->sizes();
80 int index = splitter->indexOf(this);
81 int diff = width - sizes.at(index);
82 int adjust = sizes.count() > 1 ? (diff / (sizes.count() - 1)) : 0;
83 for (int i = 0; i < sizes.count(); ++i) {
88 splitter->setSizes(sizes);
97 // This function does work even though the order in which
98 // the placeHolder get the signal is undefined.
99 // It does ensure that after all PlaceHolders got the signal
100 // m_current points to the current PlaceHolder, or zero if there
101 // is no PlaceHolder in this mode
102 // And that the parent of the RightPaneWidget gets the correct parent
103 void RightPanePlaceHolder::currentModeChanged(Core::IMode *mode)
105 if (m_current == this) {
107 RightPaneWidget::instance()->setParent(0);
108 RightPaneWidget::instance()->hide();
110 if (m_mode == mode) {
113 int width = RightPaneWidget::instance()->storedWidth();
115 layout()->addWidget(RightPaneWidget::instance());
116 RightPaneWidget::instance()->show();
118 applyStoredSize(width);
119 setVisible(RightPaneWidget::instance()->isShown());
128 RightPaneWidget *RightPaneWidget::m_instance = 0;
130 RightPaneWidget::RightPaneWidget()
131 : m_shown(true), m_width(0)
135 QVBoxLayout *layout = new QVBoxLayout;
136 layout->setMargin(0);
140 RightPaneWidget::~RightPaneWidget()
146 RightPaneWidget *RightPaneWidget::instance()
151 void RightPaneWidget::setWidget(QWidget *widget)
156 m_widget->setParent(this);
157 layout()->addWidget(m_widget);
158 setFocusProxy(m_widget);
163 int RightPaneWidget::storedWidth()
168 void RightPaneWidget::resizeEvent(QResizeEvent *re)
170 if (m_width && re->size().width())
171 m_width = re->size().width();
172 QWidget::resizeEvent(re);
175 void RightPaneWidget::saveSettings(QSettings *settings)
177 settings->setValue("RightPane/Visible", isShown());
178 settings->setValue("RightPane/Width", m_width);
181 void RightPaneWidget::readSettings(QSettings *settings)
183 if (settings->contains("RightPane/Visible")) {
184 setShown(settings->value("RightPane/Visible").toBool());
186 setShown(false); //TODO set to false
189 if (settings->contains("RightPane/Width")) {
190 m_width = settings->value("RightPane/Width").toInt();
194 m_width = 500; //pixel
197 if (RightPanePlaceHolder::m_current) {
198 RightPanePlaceHolder::m_current->applyStoredSize(m_width);
202 void RightPaneWidget::setShown(bool b)
204 if (RightPanePlaceHolder::m_current)
205 RightPanePlaceHolder::m_current->setVisible(b);
209 bool RightPaneWidget::isShown()
214 void RightPaneWidget::clearWidget()
218 m_widget->setParent(0);