2 ******************************************************************************
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
6 * Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
7 * @addtogroup GCSPlugins GCS Plugins
9 * @addtogroup CorePlugin Core Plugin
11 * @brief The Core GCS plugin
12 *****************************************************************************/
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24 * You should have received a copy of the GNU General Public License along
25 * with this program; if not, write to the Free Software Foundation, Inc.,
26 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #include "rightpane.h"
31 #include <coreplugin/modemanager.h>
32 #include <extensionsystem/pluginmanager.h>
34 #include <QtCore/QSettings>
36 #include <QVBoxLayout>
38 #include <QResizeEvent>
43 using namespace Core::Internal
;
45 RightPanePlaceHolder
*RightPanePlaceHolder::m_current
= 0;
47 RightPanePlaceHolder
*RightPanePlaceHolder::current()
52 RightPanePlaceHolder::RightPanePlaceHolder(Core::IMode
*mode
, QWidget
*parent
)
53 : QWidget(parent
), m_mode(mode
)
55 setLayout(new QVBoxLayout
);
56 layout()->setMargin(0);
57 connect(Core::ModeManager::instance(), SIGNAL(currentModeChanged(Core::IMode
*)),
58 this, SLOT(currentModeChanged(Core::IMode
*)));
61 RightPanePlaceHolder::~RightPanePlaceHolder()
63 if (m_current
== this) {
64 RightPaneWidget::instance()->setParent(0);
65 RightPaneWidget::instance()->hide();
69 void RightPanePlaceHolder::applyStoredSize(int width
)
72 QSplitter
*splitter
= qobject_cast
<QSplitter
*>(parentWidget());
74 // A splitter we need to resize the splitter sizes
75 QList
<int> sizes
= splitter
->sizes();
76 int index
= splitter
->indexOf(this);
77 int diff
= width
- sizes
.at(index
);
78 int adjust
= sizes
.count() > 1 ? (diff
/ (sizes
.count() - 1)) : 0;
79 for (int i
= 0; i
< sizes
.count(); ++i
) {
85 splitter
->setSizes(sizes
);
94 // This function does work even though the order in which
95 // the placeHolder get the signal is undefined.
96 // It does ensure that after all PlaceHolders got the signal
97 // m_current points to the current PlaceHolder, or zero if there
98 // is no PlaceHolder in this mode
99 // And that the parent of the RightPaneWidget gets the correct parent
100 void RightPanePlaceHolder::currentModeChanged(Core::IMode
*mode
)
102 if (m_current
== this) {
104 RightPaneWidget::instance()->setParent(0);
105 RightPaneWidget::instance()->hide();
107 if (m_mode
== mode
) {
110 int width
= RightPaneWidget::instance()->storedWidth();
112 layout()->addWidget(RightPaneWidget::instance());
113 RightPaneWidget::instance()->show();
115 applyStoredSize(width
);
116 setVisible(RightPaneWidget::instance()->isShown());
125 RightPaneWidget
*RightPaneWidget::m_instance
= 0;
127 RightPaneWidget::RightPaneWidget()
128 : m_shown(true), m_width(0)
132 QVBoxLayout
*layout
= new QVBoxLayout
;
133 layout
->setMargin(0);
136 ExtensionSystem::PluginManager
*pm
= ExtensionSystem::PluginManager::instance();
138 BaseRightPaneWidget
*rpw
= pm
->getObject
<BaseRightPaneWidget
>();
140 layout
->addWidget(rpw
->widget());
142 connect(pm
, SIGNAL(objectAdded(QObject
*)),
143 this, SLOT(objectAdded(QObject
*)));
144 connect(pm
, SIGNAL(aboutToRemoveObject(QObject
*)),
145 this, SLOT(aboutToRemoveObject(QObject
*)));
148 RightPaneWidget::~RightPaneWidget()
153 void RightPaneWidget::objectAdded(QObject
*obj
)
155 BaseRightPaneWidget
*rpw
= qobject_cast
<BaseRightPaneWidget
*>(obj
);
158 layout()->addWidget(rpw
->widget());
159 setFocusProxy(rpw
->widget());
163 void RightPaneWidget::aboutToRemoveObject(QObject
*obj
)
165 BaseRightPaneWidget
*rpw
= qobject_cast
<BaseRightPaneWidget
*>(obj
);
168 delete rpw
->widget();
172 RightPaneWidget
*RightPaneWidget::instance()
177 int RightPaneWidget::storedWidth()
182 void RightPaneWidget::resizeEvent(QResizeEvent
*re
)
184 if (m_width
&& re
->size().width()) {
185 m_width
= re
->size().width();
187 QWidget::resizeEvent(re
);
190 void RightPaneWidget::saveSettings(QSettings
*settings
)
192 settings
->setValue("RightPane/Visible", isShown());
193 settings
->setValue("RightPane/Width", m_width
);
196 void RightPaneWidget::readSettings(QSettings
*settings
)
198 if (settings
->contains("RightPane/Visible")) {
199 setShown(settings
->value("RightPane/Visible").toBool());
201 setShown(false); // TODO set to false
204 if (settings
->contains("RightPane/Width")) {
205 m_width
= settings
->value("RightPane/Width").toInt();
210 m_width
= 500; // pixel
213 if (RightPanePlaceHolder::m_current
) {
214 RightPanePlaceHolder::m_current
->applyStoredSize(m_width
);
218 void RightPaneWidget::setShown(bool b
)
220 if (RightPanePlaceHolder::m_current
) {
221 RightPanePlaceHolder::m_current
->setVisible(b
);
226 bool RightPaneWidget::isShown()
232 // BaseRightPaneWidget
235 BaseRightPaneWidget::BaseRightPaneWidget(QWidget
*widget
)
240 BaseRightPaneWidget::~BaseRightPaneWidget()
243 QWidget
*BaseRightPaneWidget::widget() const