2010-02-26 11:08:17 +01:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2012-01-26 18:33:46 +01:00
|
|
|
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
2010-02-26 11:08:17 +01:00
|
|
|
**
|
2011-11-02 15:59:12 +01:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2010-02-26 11:08:17 +01:00
|
|
|
**
|
|
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** 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.
|
2010-02-26 11:08:17 +01:00
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-04-13 08:42:33 +02:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Other Usage
|
|
|
|
|
**
|
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
|
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** If you have questions regarding the use of this file, please contact
|
2011-11-02 15:59:12 +01:00
|
|
|
** Nokia at qt-info@nokia.com.
|
2010-02-26 11:08:17 +01:00
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "formeditorstack.h"
|
|
|
|
|
#include "formwindoweditor.h"
|
|
|
|
|
#include "formeditorw.h"
|
|
|
|
|
#include "designerconstants.h"
|
2010-03-09 10:26:20 +01:00
|
|
|
|
2010-03-10 10:21:52 +01:00
|
|
|
#include <widgethost.h>
|
|
|
|
|
|
2010-03-09 15:48:01 +01:00
|
|
|
#include <coreplugin/coreconstants.h>
|
|
|
|
|
#include <coreplugin/modemanager.h>
|
|
|
|
|
#include <coreplugin/imode.h>
|
2010-03-09 10:26:20 +01:00
|
|
|
|
|
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDesignerFormWindowInterface>
|
|
|
|
|
#include <QDesignerFormWindowManagerInterface>
|
|
|
|
|
#include <QDesignerFormEditorInterface>
|
|
|
|
|
#include <QDesignerPropertyEditorInterface>
|
2010-02-26 11:08:17 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDebug>
|
|
|
|
|
#include <QVariant>
|
|
|
|
|
#include <QRect>
|
2010-02-26 11:08:17 +01:00
|
|
|
|
|
|
|
|
namespace Designer {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2010-03-09 10:26:20 +01:00
|
|
|
FormEditorStack::FormEditorStack(QWidget *parent) :
|
|
|
|
|
QStackedWidget(parent),
|
|
|
|
|
m_designerCore(0)
|
2010-02-26 11:08:17 +01:00
|
|
|
{
|
2010-03-09 10:26:20 +01:00
|
|
|
setObjectName(QLatin1String("FormEditorStack"));
|
2010-02-26 11:08:17 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-09 15:48:01 +01:00
|
|
|
void FormEditorStack::add(const EditorData &data)
|
2010-02-26 11:08:17 +01:00
|
|
|
{
|
2010-03-09 10:26:20 +01:00
|
|
|
if (m_designerCore == 0) { // Initialize first time here
|
2010-03-10 10:21:52 +01:00
|
|
|
m_designerCore = data.widgetHost->formWindow()->core();
|
2010-03-09 10:26:20 +01:00
|
|
|
connect(m_designerCore->formWindowManager(), SIGNAL(activeFormWindowChanged(QDesignerFormWindowInterface*)),
|
|
|
|
|
this, SLOT(updateFormWindowSelectionHandles()));
|
2010-03-09 15:48:01 +01:00
|
|
|
connect(Core::ModeManager::instance(), SIGNAL(currentModeAboutToChange(Core::IMode*)),
|
|
|
|
|
this, SLOT(modeAboutToChange(Core::IMode*)));
|
2010-03-09 10:26:20 +01:00
|
|
|
}
|
2010-02-26 11:08:17 +01:00
|
|
|
|
2010-03-09 15:48:01 +01:00
|
|
|
if (Designer::Constants::Internal::debug)
|
2010-03-10 10:21:52 +01:00
|
|
|
qDebug() << "FormEditorStack::add" << data.formWindowEditor << data.widgetHost;
|
2010-03-09 15:48:01 +01:00
|
|
|
|
|
|
|
|
m_formEditors.append(data);
|
2010-03-10 10:21:52 +01:00
|
|
|
addWidget(data.widgetHost);
|
2011-03-30 11:52:15 +02:00
|
|
|
// Editors are normally removed by listening to EditorManager::editorsClosed.
|
|
|
|
|
// However, in the case opening a file fails, EditorManager just deletes the editor, which
|
|
|
|
|
// is caught by the destroyed() signal.
|
|
|
|
|
connect(data.formWindowEditor, SIGNAL(destroyed(QObject*)),
|
|
|
|
|
this, SLOT(removeFormWindowEditor(QObject*)));
|
2010-03-10 10:21:52 +01:00
|
|
|
|
|
|
|
|
connect(data.widgetHost, SIGNAL(formWindowSizeChanged(int,int)),
|
|
|
|
|
this, SLOT(formSizeChanged(int,int)));
|
2010-02-26 11:08:17 +01:00
|
|
|
|
2010-03-09 10:26:20 +01:00
|
|
|
if (Designer::Constants::Internal::debug)
|
2011-03-30 11:52:15 +02:00
|
|
|
qDebug() << "FormEditorStack::add" << data.widgetHost << m_formEditors.size();
|
2010-03-16 16:55:56 +01:00
|
|
|
|
|
|
|
|
// Since we have 1 pixel splitters we enforce no frame
|
|
|
|
|
// on the content widget
|
|
|
|
|
if (QFrame *frame = qobject_cast<QFrame*>(data.widgetHost))
|
|
|
|
|
frame->setFrameStyle(QFrame::NoFrame);
|
2010-03-09 10:26:20 +01:00
|
|
|
}
|
|
|
|
|
|
2011-03-30 11:52:15 +02:00
|
|
|
int FormEditorStack::indexOfFormWindow(const QDesignerFormWindowInterface *fw) const
|
2010-03-09 10:26:20 +01:00
|
|
|
{
|
|
|
|
|
const int count = m_formEditors.size();
|
|
|
|
|
for(int i = 0; i < count; ++i)
|
2010-03-10 10:21:52 +01:00
|
|
|
if (m_formEditors[i].widgetHost->formWindow() == fw)
|
2010-03-09 10:26:20 +01:00
|
|
|
return i;
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2010-02-26 11:08:17 +01:00
|
|
|
|
2011-03-30 11:52:15 +02:00
|
|
|
int FormEditorStack::indexOfFormEditor(const QObject *xmlEditor) const
|
2010-03-09 10:26:20 +01:00
|
|
|
{
|
|
|
|
|
const int count = m_formEditors.size();
|
|
|
|
|
for(int i = 0; i < count; ++i)
|
2010-03-10 10:21:52 +01:00
|
|
|
if (m_formEditors[i].formWindowEditor == xmlEditor)
|
2010-03-09 10:26:20 +01:00
|
|
|
return i;
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-09 17:01:34 +01:00
|
|
|
EditorData FormEditorStack::activeEditor() const
|
2010-03-09 10:26:20 +01:00
|
|
|
{
|
2010-03-09 17:01:34 +01:00
|
|
|
// Should actually be in sync with current index.
|
|
|
|
|
if (QDesignerFormWindowInterface *afw = m_designerCore->formWindowManager()->activeFormWindow()) {
|
2011-03-30 11:52:15 +02:00
|
|
|
const int index = indexOfFormWindow(afw);
|
2010-03-09 17:01:34 +01:00
|
|
|
if (index >= 0)
|
|
|
|
|
return m_formEditors.at(index);
|
|
|
|
|
}
|
|
|
|
|
return EditorData();
|
2010-03-09 10:26:20 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-10 10:21:52 +01:00
|
|
|
SharedTools::WidgetHost *FormEditorStack::formWindowEditorForFormWindow(const QDesignerFormWindowInterface *fw) const
|
2010-03-09 10:26:20 +01:00
|
|
|
{
|
2011-03-30 11:52:15 +02:00
|
|
|
const int i = indexOfFormWindow(fw);
|
2010-03-10 10:21:52 +01:00
|
|
|
return i != -1 ? m_formEditors[i].widgetHost : static_cast<SharedTools::WidgetHost *>(0);
|
2010-02-26 11:08:17 +01:00
|
|
|
}
|
|
|
|
|
|
2011-03-30 11:52:15 +02:00
|
|
|
void FormEditorStack::removeFormWindowEditor(QObject *xmlEditor)
|
2010-02-26 11:08:17 +01:00
|
|
|
{
|
2011-03-30 11:52:15 +02:00
|
|
|
const int i = indexOfFormEditor(xmlEditor);
|
2010-03-09 10:26:20 +01:00
|
|
|
if (Designer::Constants::Internal::debug)
|
2011-03-30 11:52:15 +02:00
|
|
|
qDebug() << "FormEditorStack::removeFormWindowEditor" << xmlEditor << i << " of " << m_formEditors.size() ;
|
|
|
|
|
if (i == -1) // Fail silently as this is invoked for all editors from EditorManager
|
|
|
|
|
return; // and editor deletion signal.
|
|
|
|
|
|
2010-07-05 13:27:13 +02:00
|
|
|
removeWidget(m_formEditors[i].widgetHost);
|
|
|
|
|
m_formEditors[i].widgetHost->deleteLater();
|
2010-03-09 10:26:20 +01:00
|
|
|
m_formEditors.removeAt(i);
|
2010-02-26 11:08:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool FormEditorStack::setVisibleEditor(Core::IEditor *xmlEditor)
|
|
|
|
|
{
|
2010-03-09 10:26:20 +01:00
|
|
|
if (Designer::Constants::Internal::debug)
|
|
|
|
|
qDebug() << "FormEditorStack::setVisibleEditor" << xmlEditor;
|
2011-03-30 11:52:15 +02:00
|
|
|
const int i = indexOfFormEditor(xmlEditor);
|
2010-03-09 10:26:20 +01:00
|
|
|
QTC_ASSERT(i != -1, return false);
|
|
|
|
|
|
|
|
|
|
if (i != currentIndex())
|
|
|
|
|
setCurrentIndex(i);
|
|
|
|
|
return true;
|
2010-02-26 11:08:17 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-09 10:26:20 +01:00
|
|
|
void FormEditorStack::updateFormWindowSelectionHandles()
|
2010-02-26 11:08:17 +01:00
|
|
|
{
|
2010-03-09 10:26:20 +01:00
|
|
|
// Display form selection handles only on active window
|
|
|
|
|
if (Designer::Constants::Internal::debug)
|
|
|
|
|
qDebug() << "updateFormWindowSelectionHandles";
|
|
|
|
|
QDesignerFormWindowInterface *activeFormWindow = m_designerCore->formWindowManager()->activeFormWindow();
|
2010-03-09 15:48:01 +01:00
|
|
|
foreach(const EditorData &fdm, m_formEditors) {
|
2010-03-10 10:21:52 +01:00
|
|
|
const bool active = activeFormWindow == fdm.widgetHost->formWindow();
|
|
|
|
|
fdm.widgetHost->updateFormWindowSelectionHandles(active);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FormEditorStack::formSizeChanged(int w, int h)
|
|
|
|
|
{
|
|
|
|
|
// Handle main container resize.
|
|
|
|
|
if (Designer::Constants::Internal::debug)
|
|
|
|
|
qDebug() << Q_FUNC_INFO << w << h;
|
|
|
|
|
if (const SharedTools::WidgetHost *wh = qobject_cast<const SharedTools::WidgetHost *>(sender())) {
|
|
|
|
|
wh->formWindow()->setDirty(true);
|
|
|
|
|
static const QString geometry = QLatin1String("geometry");
|
|
|
|
|
m_designerCore->propertyEditor()->setPropertyValue(geometry, QRect(0,0,w,h) );
|
2010-02-26 11:08:17 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-10 10:21:52 +01:00
|
|
|
SharedTools::WidgetHost *FormEditorStack::formWindowEditorForXmlEditor(const Core::IEditor *xmlEditor) const
|
2010-03-09 10:26:20 +01:00
|
|
|
{
|
2011-03-30 11:52:15 +02:00
|
|
|
const int i = indexOfFormEditor(xmlEditor);
|
2010-03-10 10:21:52 +01:00
|
|
|
return i != -1 ? m_formEditors.at(i).widgetHost : static_cast<SharedTools::WidgetHost *>(0);
|
2010-03-09 10:26:20 +01:00
|
|
|
}
|
2010-02-26 11:08:17 +01:00
|
|
|
|
2010-03-09 15:48:01 +01:00
|
|
|
void FormEditorStack::modeAboutToChange(Core::IMode *m)
|
2010-02-26 11:08:17 +01:00
|
|
|
{
|
2010-03-09 15:48:01 +01:00
|
|
|
if (Designer::Constants::Internal::debug && m)
|
2012-05-07 18:28:03 +02:00
|
|
|
qDebug() << "FormEditorStack::modeAboutToChange" << m->id().toString();
|
2010-02-26 11:08:17 +01:00
|
|
|
|
2011-03-14 09:42:24 +01:00
|
|
|
// Sync the editor when entering edit mode
|
2012-05-07 18:28:03 +02:00
|
|
|
if (m && m->id() == Core::Constants::MODE_EDIT)
|
2010-03-09 15:48:01 +01:00
|
|
|
foreach(const EditorData &data, m_formEditors)
|
2010-03-10 10:21:52 +01:00
|
|
|
data.formWindowEditor->syncXmlEditor();
|
2010-02-26 11:08:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // Internal
|
|
|
|
|
} // Designer
|