diff --git a/src/plugins/designer/designer.pro b/src/plugins/designer/designer.pro index 48d9e3db1802848a17941f3b5ca81dc0d5504d38..d60541416476ba8d3f575b9837c07bb043f54bca 100644 --- a/src/plugins/designer/designer.pro +++ b/src/plugins/designer/designer.pro @@ -25,7 +25,6 @@ HEADERS += formeditorplugin.h \ formeditorfactory.h \ formwindoweditor.h \ formwindowfile.h \ - formwindowhost.h \ formwizard.h \ qtcreatorintegration.h \ designerconstants.h \ @@ -46,7 +45,6 @@ SOURCES += formeditorplugin.cpp \ formeditorfactory.cpp \ formwindoweditor.cpp \ formwindowfile.cpp \ - formwindowhost.cpp \ formwizard.cpp \ qtcreatorintegration.cpp \ settingspage.cpp \ diff --git a/src/plugins/designer/designercontext.cpp b/src/plugins/designer/designercontext.cpp index 69f0678d8e49f433a0afb73d631ebfc4f29d0438..5a5a7b6bee0eee3c283fdb44a4e0472c23561e84 100644 --- a/src/plugins/designer/designercontext.cpp +++ b/src/plugins/designer/designercontext.cpp @@ -29,27 +29,26 @@ #include "designercontext.h" #include "designerconstants.h" -#include <coreplugin/uniqueidmanager.h> -#include <coreplugin/coreconstants.h> +#include "formeditorw.h" -#include <QWidget> +#include <QtDesigner/QDesignerFormEditorInterface> +#include "qt_private/qdesigner_integration_p.h" + +#include <QtGui/QWidget> +#include <QtCore/QDebug> + +enum { debug = 0 }; namespace Designer { namespace Internal { -DesignerContext::DesignerContext(QWidget *widget) : Core::IContext(widget), +DesignerContext::DesignerContext(const QList<int> contexts, + QWidget *widget, + QObject *parent) : + Core::IContext(parent), + m_context(contexts), m_widget(widget) { - Core::UniqueIDManager *idMan = Core::UniqueIDManager::instance(); - m_context << idMan->uniqueIdentifier(Designer::Constants::C_FORMEDITOR) - << idMan->uniqueIdentifier(Core::Constants::C_EDITORMANAGER) - << idMan->uniqueIdentifier(Core::Constants::C_DESIGN_MODE); - -} - -DesignerContext::~DesignerContext() -{ - } QList<int> DesignerContext::context() const @@ -62,11 +61,19 @@ QWidget *DesignerContext::widget() return m_widget; } -void DesignerContext::setWidget(QWidget *widget) +QString DesignerContext::contextHelpId() const { - m_widget = widget; -} - -} + QString helpId; + const QDesignerFormEditorInterface *core = FormEditorW::instance()->designerEditor(); + // Present from Qt 4.5.1 onwards. This will show the class documentation + // scrolled to the current property. + if (const qdesigner_internal::QDesignerIntegration *integration = + qobject_cast<const qdesigner_internal::QDesignerIntegration*>(core->integration())) + helpId = integration->contextHelpId(); + if (debug) + qDebug() << "DesignerContext::contextHelpId" << m_widget << helpId; + return helpId; } +} // namespace Internal +} // namespace Designer diff --git a/src/plugins/designer/designercontext.h b/src/plugins/designer/designercontext.h index 00d798387a58553aafdaceef4ddf531aba9f6181..4b0a0827c3ee8f2f60d243bbd0243a3d62e27e63 100644 --- a/src/plugins/designer/designercontext.h +++ b/src/plugins/designer/designercontext.h @@ -42,19 +42,22 @@ namespace Internal { class DesignerContext : public Core::IContext { + Q_DISABLE_COPY(DesignerContext) public: - DesignerContext(QWidget *widget = 0); - ~DesignerContext(); - QList<int> context() const; - QWidget *widget(); - void setWidget(QWidget *widget); + explicit DesignerContext(const QList<int> contexts, + QWidget *widget, + QObject *parent = 0); + + virtual QList<int> context() const; + virtual QWidget *widget(); + virtual QString contextHelpId() const; + private: - QList<int> m_context; + const QList<int> m_context; QWidget *m_widget; }; -} -} - +} // namespace Internal +} // namespace Designer #endif // DESIGNERCONTEXT_H diff --git a/src/plugins/designer/designerxmleditor.cpp b/src/plugins/designer/designerxmleditor.cpp index eabb9910726055bb3f976596142b985fb9a2d9de..96e52f1bcaba5433f23a9985ddec0e5a7b593ea6 100644 --- a/src/plugins/designer/designerxmleditor.cpp +++ b/src/plugins/designer/designerxmleditor.cpp @@ -99,4 +99,12 @@ Core::IEditor *DesignerXmlEditorEditable::duplicate(QWidget *parent) Q_UNUSED(parent); return 0; } + +namespace Internal { +TextEditor::BaseTextEditorEditable *DesignerXmlEditor::createEditableInterface() +{ + return new DesignerXmlEditorEditable(this); +} +} } // namespace Designer + diff --git a/src/plugins/designer/designerxmleditor.h b/src/plugins/designer/designerxmleditor.h index 09714214ce5db96f2267bf76cf325a5fd179d545..ce0b2abb897416022fd73c93791b8288f0b5f396 100644 --- a/src/plugins/designer/designerxmleditor.h +++ b/src/plugins/designer/designerxmleditor.h @@ -80,7 +80,7 @@ private slots: void updateEditorInfoBar(Core::IEditor *editor); protected: - virtual TextEditor::BaseTextEditorEditable *createEditableInterface() { return new DesignerXmlEditorEditable(this); } + virtual TextEditor::BaseTextEditorEditable *createEditableInterface(); private: }; diff --git a/src/plugins/designer/editorwidget.cpp b/src/plugins/designer/editorwidget.cpp index 88d08138c4c4be390d5a7921bc021dbe35b23272..4459b263078a8ba140ec52a5bc4c3c67127e42d0 100644 --- a/src/plugins/designer/editorwidget.cpp +++ b/src/plugins/designer/editorwidget.cpp @@ -29,168 +29,97 @@ #include "editorwidget.h" #include "formeditorw.h" +#include "formeditorstack.h" -#include <coreplugin/minisplitter.h> #include <utils/qtcassert.h> -#include <QtCore/QEvent> #include <QtGui/QVBoxLayout> -#include <QtGui/QTabWidget> - -static const char *editorWidgetStateKeyC = "editorWidgetState"; +#include <QtGui/QDockWidget> using namespace Designer::Constants; namespace Designer { namespace Internal { -SharedSubWindow::SharedSubWindow(QWidget *shared, QWidget *parent) : - QWidget(parent), - m_shared(shared), - m_layout(new QVBoxLayout) -{ - QTC_ASSERT(m_shared, /**/); - m_layout->setContentsMargins(0, 0, 0, 0); - setLayout(m_layout); -} - -void SharedSubWindow::activate() -{ - // Take the widget off the other parent - QTC_ASSERT(m_shared, return); - QWidget *currentParent = m_shared->parentWidget(); - if (currentParent == this) - return; - - m_layout->addWidget(m_shared); - m_shared->show(); -} - -SharedSubWindow::~SharedSubWindow() -{ - // Do not destroy the shared sub window if we currently own it - if (m_shared->parent() == this) { - m_shared->hide(); - m_shared->setParent(0); - } -} - // ---------- EditorWidget -QHash<QString, QVariant> EditorWidget::m_globalState = QHash<QString, QVariant>(); - -EditorWidget::EditorWidget(QWidget *formWindow) - : m_mainWindow(new Utils::FancyMainWindow), - m_initialized(false) +EditorWidget::EditorWidget(FormEditorW *few, QWidget *parent) : + Utils::FancyMainWindow(parent), + m_stack(new FormEditorStack) { - QVBoxLayout *layout = new QVBoxLayout; - layout->setMargin(0); - layout->setSpacing(0); - setLayout(layout); - layout->addWidget(m_mainWindow); - m_mainWindow->setCentralWidget(formWindow); - m_mainWindow->setDocumentMode(true); - m_mainWindow->setTabPosition(Qt::AllDockWidgetAreas, QTabWidget::South); - m_mainWindow->setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea); - m_mainWindow->setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea); - - // Get shared sub windows from Form Editor - FormEditorW *few = FormEditorW::instance(); - QWidget * const*subs = few->designerSubWindows(); + setObjectName(QLatin1String("EditorWidget")); + setCentralWidget(m_stack); + setDocumentMode(true); + setTabPosition(Qt::AllDockWidgetAreas, QTabWidget::South); + setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea); + setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea); - // Create shared sub windows - for (int i=0; i < DesignerSubWindowCount; i++) { - m_designerSubWindows[i] = new SharedSubWindow(subs[i]); - m_designerSubWindows[i]->setWindowTitle(subs[i]->windowTitle()); - m_designerDockWidgets[i] = m_mainWindow->addDockForWidget(m_designerSubWindows[i]); + QWidget * const*subs = few->designerSubWindows(); + for (int i = 0; i < DesignerSubWindowCount; i++) { + QWidget *subWindow = subs[i]; + subWindow->setWindowTitle(subs[i]->windowTitle()); + m_designerDockWidgets[i] = addDockForWidget(subWindow); } + resetToDefaultLayout(); } void EditorWidget::resetToDefaultLayout() { - m_mainWindow->setTrackingEnabled(false); - QList<QDockWidget *> dockWidgets = m_mainWindow->dockWidgets(); - foreach (QDockWidget *dockWidget, dockWidgets) { + setTrackingEnabled(false); + QList<QDockWidget *> dockWidgetList = dockWidgets(); + foreach (QDockWidget *dockWidget, dockWidgetList) { dockWidget->setFloating(false); - m_mainWindow->removeDockWidget(dockWidget); + removeDockWidget(dockWidget); } - m_mainWindow->addDockWidget(Qt::LeftDockWidgetArea, m_designerDockWidgets[WidgetBoxSubWindow]); - m_mainWindow->addDockWidget(Qt::RightDockWidgetArea, m_designerDockWidgets[ObjectInspectorSubWindow]); - m_mainWindow->addDockWidget(Qt::RightDockWidgetArea, m_designerDockWidgets[PropertyEditorSubWindow]); - m_mainWindow->addDockWidget(Qt::BottomDockWidgetArea, m_designerDockWidgets[ActionEditorSubWindow]); - m_mainWindow->addDockWidget(Qt::BottomDockWidgetArea, m_designerDockWidgets[SignalSlotEditorSubWindow]); + addDockWidget(Qt::LeftDockWidgetArea, m_designerDockWidgets[WidgetBoxSubWindow]); + addDockWidget(Qt::RightDockWidgetArea, m_designerDockWidgets[ObjectInspectorSubWindow]); + addDockWidget(Qt::RightDockWidgetArea, m_designerDockWidgets[PropertyEditorSubWindow]); + addDockWidget(Qt::BottomDockWidgetArea, m_designerDockWidgets[ActionEditorSubWindow]); + addDockWidget(Qt::BottomDockWidgetArea, m_designerDockWidgets[SignalSlotEditorSubWindow]); - m_mainWindow->tabifyDockWidget(m_designerDockWidgets[ActionEditorSubWindow], - m_designerDockWidgets[SignalSlotEditorSubWindow]); + tabifyDockWidget(m_designerDockWidgets[ActionEditorSubWindow], + m_designerDockWidgets[SignalSlotEditorSubWindow]); - foreach (QDockWidget *dockWidget, dockWidgets) { + foreach (QDockWidget *dockWidget, dockWidgetList) dockWidget->show(); - } - m_mainWindow->setTrackingEnabled(true); + setTrackingEnabled(true); } -void EditorWidget::activate() +QDockWidget* const* EditorWidget::designerDockWidgets() const { - /* - - - now, settings are only changed when form is hidden. - - they should be not restored when a new form is activated - the same settings should be kept. - - only on initial load, settings should be loaded. - - */ - for (int i=0; i < DesignerSubWindowCount; i++) - m_designerSubWindows[i]->activate(); - - if (!m_initialized) { - // set a default layout, so if something goes wrong with - // restoring the settings below, there is a fallback - // (otherwise we end up with a broken mainwindow layout) - // we can't do it in the constructor, because the sub windows - // don't have their widgets yet there - resetToDefaultLayout(); - m_initialized = true; - if (!m_globalState.isEmpty()) - m_mainWindow->restoreSettings(m_globalState); - } + return m_designerDockWidgets; +} - if (m_globalState.isEmpty()) - m_globalState = m_mainWindow->saveSettings(); +Designer::FormWindowEditor *EditorWidget::createFormWindowEditor(DesignerXmlEditorEditable *xmlEditor) +{ + return m_stack->createFormWindowEditor(xmlEditor); } -void EditorWidget::hideEvent(QHideEvent *) +bool EditorWidget::removeFormWindowEditor(Core::IEditor *xmlEditor) { - m_globalState = m_mainWindow->saveSettings(); + return m_stack->removeFormWindowEditor(xmlEditor); } -void EditorWidget::saveState(QSettings *settings) +bool EditorWidget::setVisibleEditor(Core::IEditor *xmlEditor) { - settings->beginGroup(editorWidgetStateKeyC); - QHashIterator<QString, QVariant> it(m_globalState); - while (it.hasNext()) { - it.next(); - settings->setValue(it.key(), it.value()); - } - settings->endGroup(); + return m_stack->setVisibleEditor(xmlEditor); } -void EditorWidget::restoreState(QSettings *settings) +Designer::FormWindowEditor *EditorWidget::formWindowEditorForXmlEditor(const Core::IEditor *xmlEditor) const { - m_globalState.clear(); - settings->beginGroup(editorWidgetStateKeyC); - foreach (const QString &key, settings->childKeys()) { - m_globalState.insert(key, settings->value(key)); - } - settings->endGroup(); + return m_stack->formWindowEditorForXmlEditor(xmlEditor); +} + +FormWindowEditor *EditorWidget::activeFormWindow() const +{ + return m_stack->activeFormWindow(); } -void EditorWidget::toolChanged(int i) +Designer::FormWindowEditor *EditorWidget::formWindowEditorForFormWindow(const QDesignerFormWindowInterface *fw) const { - Q_UNUSED(i) -// TODO: How to activate the right dock window? -// if (m_bottomTab) -// m_bottomTab->setCurrentIndex(i == EditModeSignalsSlotEditor ? SignalSlotEditorTab : ActionEditorTab); + return m_stack->formWindowEditorForFormWindow(fw); } } // namespace Internal diff --git a/src/plugins/designer/editorwidget.h b/src/plugins/designer/editorwidget.h index 589a611fa8bf5cf366940380d5e5240084718a57..42c8e52a3ebcc6c2acbb0c4c910b733c9a992658 100644 --- a/src/plugins/designer/editorwidget.h +++ b/src/plugins/designer/editorwidget.h @@ -34,72 +34,48 @@ #include <utils/fancymainwindow.h> -#include <QtCore/QPointer> -#include <QtCore/QList> #include <QtCore/QHash> #include <QtCore/QVariant> -#include <QtCore/QSettings> -#include <QtGui/QWidget> -#include <QtGui/QVBoxLayout> -#include <QtGui/QDockWidget> -#include <QtGui/QHideEvent> -namespace Designer { -namespace Internal { - -/* A widget that shares its embedded sub window with others. For example, - * the designer editors need to share the widget box, etc. */ -class SharedSubWindow : public QWidget -{ - Q_OBJECT - Q_DISABLE_COPY(SharedSubWindow) - -public: - SharedSubWindow(QWidget *shared, QWidget *parent = 0); - virtual ~SharedSubWindow(); - -public slots: - // Takes the shared widget off the current parent and adds it to its - // layout - void activate(); +QT_BEGIN_NAMESPACE +class QDesignerFormWindowInterface; +QT_END_NAMESPACE -private: - QPointer <QWidget> m_shared; - QVBoxLayout *m_layout; -}; +namespace Core { + class IEditor; +} +namespace Designer { +class FormWindowEditor; +class DesignerXmlEditorEditable; +namespace Internal { +class FormEditorStack; +class FormEditorW; /* Form editor splitter used as editor window. Contains the shared designer * windows. */ -class EditorWidget : public QWidget +class EditorWidget : public Utils::FancyMainWindow { Q_OBJECT Q_DISABLE_COPY(EditorWidget) public: - explicit EditorWidget(QWidget *formWindow); + explicit EditorWidget(FormEditorW *fe, QWidget *parent = 0); + QDockWidget* const* designerDockWidgets() const; - void resetToDefaultLayout(); - QDockWidget* const* dockWidgets() const { return m_designerDockWidgets; } - bool isLocked() const { return m_mainWindow->isLocked(); } - void setLocked(bool locked) { m_mainWindow->setLocked(locked); } - - static void saveState(QSettings *settings); - static void restoreState(QSettings *settings); + // Form editor stack API + Designer::FormWindowEditor *createFormWindowEditor(DesignerXmlEditorEditable *xmlEditor); + bool removeFormWindowEditor(Core::IEditor *xmlEditor); + bool setVisibleEditor(Core::IEditor *xmlEditor); + Designer::FormWindowEditor *formWindowEditorForXmlEditor(const Core::IEditor *xmlEditor) const; + Designer::FormWindowEditor *formWindowEditorForFormWindow(const QDesignerFormWindowInterface *fw) const; + FormWindowEditor *activeFormWindow() const; public slots: - void activate(); - void toolChanged(int); - -protected: - void hideEvent(QHideEvent * e); + void resetToDefaultLayout(); private: - SharedSubWindow* m_designerSubWindows[Designer::Constants::DesignerSubWindowCount]; + FormEditorStack *m_stack; QDockWidget *m_designerDockWidgets[Designer::Constants::DesignerSubWindowCount]; - Utils::FancyMainWindow *m_mainWindow; - bool m_initialized; - - static QHash<QString, QVariant> m_globalState; }; } // namespace Internal diff --git a/src/plugins/designer/faketoolbar.cpp b/src/plugins/designer/faketoolbar.cpp index 3f3e5e6d59e0a3f525783da76e1e1892d0435d76..96abeb369921b345d52866c9dee3a2cf95f72fee 100644 --- a/src/plugins/designer/faketoolbar.cpp +++ b/src/plugins/designer/faketoolbar.cpp @@ -33,7 +33,6 @@ #include <coreplugin/coreconstants.h> #include <coreplugin/editormanager/ieditor.h> #include <coreplugin/icore.h> -#include <coreplugin/minisplitter.h> #include <coreplugin/sidebar.h> #include <coreplugin/editormanager/editormanager.h> #include <coreplugin/editormanager/openeditorsmodel.h> @@ -59,7 +58,7 @@ #include <QtGui/QLabel> #include <QtGui/QToolBar> -using Core::MiniSplitter; + using Core::IEditor; using Core::EditorManager; @@ -69,24 +68,28 @@ enum { debug = false }; +static inline bool isDesignerXmlEditor(const Core::IEditor *editor) +{ + return editor->id() == QLatin1String(Designer::Constants::K_DESIGNER_XML_EDITOR_ID); +} + namespace Designer { namespace Internal { /*! Mimic the look of the text editor toolbar as defined in e.g. EditorView::EditorView */ -FakeToolBar::FakeToolBar(Core::IEditor *editor, QWidget *toolbar, QWidget *parent) : +FakeToolBar::FakeToolBar(QWidget *toolbar, QWidget *parent) : QWidget(parent), m_editorList(new QComboBox), m_closeButton(new QToolButton), m_lockButton(new QToolButton), m_goBackAction(new QAction(QIcon(QLatin1String(":/help/images/previous.png")), EditorManager::tr("Go Back"), parent)), - m_goForwardAction(new QAction(QIcon(QLatin1String(":/help/images/next.png")), EditorManager::tr("Go Forward"), parent)), - m_editor(editor) + m_goForwardAction(new QAction(QIcon(QLatin1String(":/help/images/next.png")), EditorManager::tr("Go Forward"), parent)) { Core::ICore *core = Core::ICore::instance(); - //setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); + setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed); m_editorsListModel = core->editorManager()->openedEditorsModel(); // copied from EditorView::EditorView @@ -95,7 +98,6 @@ FakeToolBar::FakeToolBar(Core::IEditor *editor, QWidget *toolbar, QWidget *paren m_editorList->setModel(m_editorsListModel); m_editorList->setMaxVisibleItems(40); m_editorList->setContextMenuPolicy(Qt::CustomContextMenu); - m_editorList->setCurrentIndex(m_editorsListModel->indexOf(m_editor).row()); QToolBar *editorListToolBar = new QToolBar; editorListToolBar->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Ignored); @@ -141,7 +143,6 @@ FakeToolBar::FakeToolBar(Core::IEditor *editor, QWidget *toolbar, QWidget *paren toplayout->setMargin(0); toplayout->setContentsMargins(0,0,0,0); -// toplayout->addWidget(backFwToolBar); toplayout->addWidget(editorListToolBar); toplayout->addWidget(toolbar); toplayout->addWidget(rightToolBar); @@ -151,16 +152,26 @@ FakeToolBar::FakeToolBar(Core::IEditor *editor, QWidget *toolbar, QWidget *paren connect(m_lockButton, SIGNAL(clicked()), this, SLOT(makeEditorWritable())); connect(m_closeButton, SIGNAL(clicked()), this, SLOT(close())); - connect(m_editor, SIGNAL(changed()), this, SLOT(updateEditorStatus())); - connect(core->editorManager(), SIGNAL(currentEditorChanged(Core::IEditor*)), SLOT(updateEditorListSelection(Core::IEditor*))); + connect(core->editorManager(), SIGNAL(currentEditorChanged(Core::IEditor*)), SLOT(editorChanged(Core::IEditor*))); updateEditorStatus(); + if (Core::IEditor *editor = core->editorManager()->currentEditor()) + editorChanged(editor); } -void FakeToolBar::updateEditorListSelection(Core::IEditor *newSelection) +void FakeToolBar::editorChanged(Core::IEditor *newSelection) { + if (newSelection == m_editor) + return; + if (m_editor && isDesignerXmlEditor(m_editor)) + disconnect(m_editor, SIGNAL(changed()), this, SLOT(updateEditorStatus())); + if (newSelection) { + m_editor = newSelection; m_editorList->setCurrentIndex(m_editorsListModel->indexOf(newSelection).row()); + if (isDesignerXmlEditor(m_editor)) + connect(m_editor, SIGNAL(changed()), this, SLOT(updateEditorStatus())); + updateEditorStatus(); } } @@ -170,11 +181,9 @@ void FakeToolBar::close() // close the xml file instead. Core::ICore *core = Core::ICore::instance(); - Core::IEditor *editor = core->editorManager()->currentEditor(); - if (editor && editor->id() == Designer::Constants::K_DESIGNER_XML_EDITOR_ID - && editor->file() == m_editor->file()) - { - core->editorManager()->closeEditors(QList<Core::IEditor*>() << editor); + if (Core::IEditor *editor = core->editorManager()->currentEditor()) { + if (isDesignerXmlEditor(editor) && editor->file() == m_editor->file()) + core->editorManager()->closeEditors(QList<Core::IEditor*>() << editor); } core->modeManager()->activateMode(Core::Constants::MODE_EDIT); } @@ -182,10 +191,9 @@ void FakeToolBar::close() void FakeToolBar::listSelectionActivated(int row) { Core::EditorManager *em = Core::ICore::instance()->editorManager(); - QAbstractItemModel *model = m_editorList->model(); - + const QAbstractItemModel *model = m_editorList->model(); const QModelIndex modelIndex = model->index(row, 0); - IEditor *editor = model->data(modelIndex, Qt::UserRole).value<IEditor*>(); + Core::IEditor *editor = model->data(modelIndex, Qt::UserRole).value<Core::IEditor*>(); if (editor) { if (editor != em->currentEditor()) em->activateEditor(editor, EditorManager::NoModeSwitch); @@ -219,7 +227,7 @@ void FakeToolBar::makeEditorWritable() void FakeToolBar::updateEditorStatus() { - if (!m_editor->file()) + if (!m_editor || !m_editor->file()) return; if (m_editor->file()->isReadOnly()) { diff --git a/src/plugins/designer/faketoolbar.h b/src/plugins/designer/faketoolbar.h index 82993b25506782e75c6930107bb99f9fc977fade..3da123caac78c2cd5e593771116dcf389088bb1f 100644 --- a/src/plugins/designer/faketoolbar.h +++ b/src/plugins/designer/faketoolbar.h @@ -56,12 +56,12 @@ class FakeToolBar : public QWidget Q_OBJECT Q_DISABLE_COPY(FakeToolBar) public: - explicit FakeToolBar(Core::IEditor *editor, QWidget *toolbar, QWidget *parent = 0); + explicit FakeToolBar(QWidget *toolbar, QWidget *parent = 0); void updateActions(); private slots: - void updateEditorListSelection(Core::IEditor *newSelection); + void editorChanged(Core::IEditor *newSelection); void close(); void listSelectionActivated(int row); void listContextMenu(QPoint); diff --git a/src/plugins/designer/formeditorstack.cpp b/src/plugins/designer/formeditorstack.cpp index c9e52273c5ab7926dfae9a795e4e4a7b0bdc9eca..6d7198445b1e5a5480205259d10922de56cd5046 100644 --- a/src/plugins/designer/formeditorstack.cpp +++ b/src/plugins/designer/formeditorstack.cpp @@ -29,93 +29,152 @@ #include "formeditorstack.h" #include "designerxmleditor.h" -#include <QDesignerFormWindowInterface> -#include <texteditor/basetextdocument.h> -#include <coreplugin/editormanager/editormanager.h> -#include <coreplugin/editormanager/ieditor.h> -#include <coreplugin/icore.h> #include "formwindoweditor.h" #include "formeditorw.h" #include "designerconstants.h" + +#include <texteditor/basetextdocument.h> + +#include <coreplugin/editormanager/editormanager.h> +#include <coreplugin/icore.h> + +#include <utils/qtcassert.h> + +#include <QDesignerFormWindowInterface> +#include <QDesignerFormWindowManagerInterface> +#include <QDesignerFormEditorInterface> #include "qt_private/formwindowbase_p.h" -#include <QtCore/QStringList> +#include <QtCore/QDebug> namespace Designer { namespace Internal { -FormEditorStack::FormEditorStack() : activeEditor(0) +FormEditorStack::FormXmlData::FormXmlData() : + xmlEditor(0), formEditor(0) { - } -FormEditorStack::~FormEditorStack() +FormEditorStack::FormEditorStack(QWidget *parent) : + QStackedWidget(parent), + m_designerCore(0) { - qDeleteAll(m_formEditors); + setObjectName(QLatin1String("FormEditorStack")); } Designer::FormWindowEditor *FormEditorStack::createFormWindowEditor(DesignerXmlEditorEditable *xmlEditor) { - FormXmlData *data = new FormXmlData; - data->formEditor = FormEditorW::instance()->createFormWindowEditor(this); - data->formEditor->setFile(xmlEditor->file()); - data->xmlEditor = xmlEditor; - data->widgetIndex = addWidget(data->formEditor->widget()); + FormEditorW *few = FormEditorW::instance(); + if (m_designerCore == 0) { // Initialize first time here + m_designerCore = few->designerEditor(); + connect(m_designerCore->formWindowManager(), SIGNAL(activeFormWindowChanged(QDesignerFormWindowInterface*)), + this, SLOT(updateFormWindowSelectionHandles())); + } + FormXmlData data; + data.formEditor = few->createFormWindowEditor(this); + data.formEditor->setFile(xmlEditor->file()); + data.xmlEditor = xmlEditor; + addWidget(data.formEditor); m_formEditors.append(data); - setFormEditorData(data->formEditor, xmlEditor->contents()); + setFormEditorData(data.formEditor, xmlEditor->contents()); TextEditor::BaseTextDocument *document = qobject_cast<TextEditor::BaseTextDocument*>(xmlEditor->file()); connect(document, SIGNAL(reloaded()), SLOT(reloadDocument())); + if (Designer::Constants::Internal::debug) + qDebug() << "FormEditorStack::createFormWindowEditor" << data.formEditor; + return data.formEditor; +} + +int FormEditorStack::indexOf(const QDesignerFormWindowInterface *fw) const +{ + const int count = m_formEditors.size(); + for(int i = 0; i < count; ++i) + if (m_formEditors[i].formEditor->formWindow() == fw) + return i; + return -1; +} - return data->formEditor; +int FormEditorStack::indexOf(const Core::IEditor *xmlEditor) const +{ + const int count = m_formEditors.size(); + for(int i = 0; i < count; ++i) + if (m_formEditors[i].xmlEditor == xmlEditor) + return i; + return -1; +} + +FormWindowEditor *FormEditorStack::activeFormWindow() const +{ + if (QDesignerFormWindowInterface *afw = m_designerCore->formWindowManager()->activeFormWindow()) + if (FormWindowEditor *fwe = formWindowEditorForFormWindow(afw)) + return fwe; + return 0; +} + +Designer::FormWindowEditor *FormEditorStack::formWindowEditorForFormWindow(const QDesignerFormWindowInterface *fw) const +{ + const int i = indexOf(fw); + return i != -1 ? m_formEditors[i].formEditor : static_cast<Designer::FormWindowEditor *>(0); } bool FormEditorStack::removeFormWindowEditor(Core::IEditor *xmlEditor) { - for(int i = 0; i < m_formEditors.length(); ++i) { - if (m_formEditors[i]->xmlEditor == xmlEditor) { - disconnect(m_formEditors[i]->formEditor->formWindow(), SIGNAL(changed()), this, SLOT(formChanged())); - removeWidget(m_formEditors[i]->formEditor->widget()); - delete m_formEditors[i]->formEditor; - m_formEditors.removeAt(i); - return true; - } - } - return false; + if (Designer::Constants::Internal::debug) + qDebug() << "FormEditorStack::removeFormWindowEditor" << xmlEditor; + const int i = indexOf(xmlEditor); + if (i == -1) // Fail silently as this is invoked for all editors. + return false; + disconnect(m_formEditors[i].formEditor->formWindow(), SIGNAL(changed()), this, SLOT(formChanged())); + removeWidget(m_formEditors[i].formEditor->widget()); + delete m_formEditors[i].formEditor; + m_formEditors.removeAt(i); + return true; } bool FormEditorStack::setVisibleEditor(Core::IEditor *xmlEditor) { - for(int i = 0; i < m_formEditors.length(); ++i) { - if (m_formEditors[i]->xmlEditor == xmlEditor) { - setCurrentIndex(m_formEditors[i]->widgetIndex); - activeEditor = m_formEditors[i]; - return true; - } - } - return false; + if (Designer::Constants::Internal::debug) + qDebug() << "FormEditorStack::setVisibleEditor" << xmlEditor; + const int i = indexOf(xmlEditor); + QTC_ASSERT(i != -1, return false); + + if (i != currentIndex()) + setCurrentIndex(i); + return true; } -Designer::FormWindowEditor *FormEditorStack::formWindowEditorForXmlEditor(Core::IEditor *xmlEditor) +void FormEditorStack::updateFormWindowSelectionHandles() { - foreach(FormXmlData *data, m_formEditors) { - if (data->xmlEditor == xmlEditor) - return data->formEditor; + // Display form selection handles only on active window + if (Designer::Constants::Internal::debug) + qDebug() << "updateFormWindowSelectionHandles"; + QDesignerFormWindowInterface *activeFormWindow = m_designerCore->formWindowManager()->activeFormWindow(); + foreach(const FormXmlData &fdm, m_formEditors) { + const bool active = activeFormWindow == fdm.formEditor->formWindow(); + fdm.formEditor->updateFormWindowSelectionHandles(active); } - return 0; } +Designer::FormWindowEditor *FormEditorStack::formWindowEditorForXmlEditor(const Core::IEditor *xmlEditor) const +{ + const int i = indexOf(xmlEditor); + return i != -1 ? m_formEditors.at(i).formEditor : static_cast<Designer::FormWindowEditor *>(0); +} void FormEditorStack::reloadDocument() { - if (activeEditor) { - setFormEditorData(activeEditor->formEditor, activeEditor->xmlEditor->contents()); - } + if (Designer::Constants::Internal::debug) + qDebug() << "FormEditorStack::reloadDocument()"; + const int index = currentIndex(); + if (index >= 0) + setFormEditorData(m_formEditors[index].formEditor, m_formEditors[index].xmlEditor->contents()); } void FormEditorStack::setFormEditorData(Designer::FormWindowEditor *formEditor, const QString &contents) { + if (Designer::Constants::Internal::debug) + qDebug() << "FormEditorStack::setFormEditorData()"; disconnect(formEditor->formWindow(), SIGNAL(changed()), this, SLOT(formChanged())); formEditor->createNew(contents); connect(formEditor->formWindow(), SIGNAL(changed()), SLOT(formChanged())); @@ -123,17 +182,17 @@ void FormEditorStack::setFormEditorData(Designer::FormWindowEditor *formEditor, void FormEditorStack::formChanged() { - Core::ICore *core = Core::ICore::instance(); - - if (core->editorManager()->currentEditor() && activeEditor - && core->editorManager()->currentEditor() == activeEditor->xmlEditor) - { - TextEditor::BaseTextDocument *doc = qobject_cast<TextEditor::BaseTextDocument*>(activeEditor->xmlEditor->file()); - Q_ASSERT(doc); - if (doc) { - // Save quietly (without spacer's warning). - if (const qdesigner_internal::FormWindowBase *fwb = qobject_cast<const qdesigner_internal::FormWindowBase *>(activeEditor->formEditor->formWindow())) - doc->document()->setPlainText(fwb->fileContents()); + const int index = currentIndex(); + if (index < 0) + return; + if (Core::IEditor *currentEditor = Core::EditorManager::instance()->currentEditor()) { + if (m_formEditors[index].xmlEditor == currentEditor) { + FormXmlData &xmlData = m_formEditors[index]; + TextEditor::BaseTextDocument *doc = qobject_cast<TextEditor::BaseTextDocument*>(xmlData.xmlEditor->file()); + QTC_ASSERT(doc, return); + if (doc) // Save quietly (without spacer's warning). + if (const qdesigner_internal::FormWindowBase *fwb = qobject_cast<const qdesigner_internal::FormWindowBase *>(xmlData.formEditor->formWindow())) + doc->document()->setPlainText(fwb->fileContents()); } } } diff --git a/src/plugins/designer/formeditorstack.h b/src/plugins/designer/formeditorstack.h index 8d035cac59bf2e6d557514d72e2b1ad69a635e4f..994a892c6c0894f84c0cc5e818caa3df1528158c 100644 --- a/src/plugins/designer/formeditorstack.h +++ b/src/plugins/designer/formeditorstack.h @@ -34,6 +34,11 @@ #include <QtCore/QList> #include <QtCore/QString> +QT_BEGIN_NAMESPACE +class QDesignerFormWindowInterface; +class QDesignerFormEditorInterface; +QT_END_NAMESPACE + namespace Core { class IEditor; } @@ -54,34 +59,35 @@ class FormEditorStack : public QStackedWidget Q_OBJECT Q_DISABLE_COPY(FormEditorStack); public: - FormEditorStack(); - ~FormEditorStack(); + explicit FormEditorStack(QWidget *parent = 0); + Designer::FormWindowEditor *createFormWindowEditor(DesignerXmlEditorEditable *xmlEditor); bool removeFormWindowEditor(Core::IEditor *xmlEditor); bool setVisibleEditor(Core::IEditor *xmlEditor); - Designer::FormWindowEditor *formWindowEditorForXmlEditor(Core::IEditor *xmlEditor); + Designer::FormWindowEditor *formWindowEditorForXmlEditor(const Core::IEditor *xmlEditor) const; + Designer::FormWindowEditor *formWindowEditorForFormWindow(const QDesignerFormWindowInterface *fw) const; + FormWindowEditor *activeFormWindow() const; private slots: void formChanged(); void reloadDocument(); + void updateFormWindowSelectionHandles(); private: - void setFormEditorData(Designer::FormWindowEditor *formEditor, const QString &contents); - - struct FormXmlData; - QList<FormXmlData*> m_formEditors; - - FormXmlData *activeEditor; + inline int indexOf(const QDesignerFormWindowInterface *) const; + inline int indexOf(const Core::IEditor *xmlEditor) const; + void setFormEditorData(Designer::FormWindowEditor *formEditor, const QString &contents); struct FormXmlData { + FormXmlData(); DesignerXmlEditorEditable *xmlEditor; Designer::FormWindowEditor *formEditor; - int widgetIndex; }; - + QList<FormXmlData> m_formEditors; + QDesignerFormEditorInterface *m_designerCore; }; -} -} +} // namespace Internal +} // namespace Designer #endif // FORMEDITORSTACK_H diff --git a/src/plugins/designer/formeditorw.cpp b/src/plugins/designer/formeditorw.cpp index 8e9f2dd4cac948a71fdb677d4ea849ed0b0b8a25..98c2ea295bbc438356e261a9a7e9a280705cbf65 100644 --- a/src/plugins/designer/formeditorw.cpp +++ b/src/plugins/designer/formeditorw.cpp @@ -30,13 +30,14 @@ #include "formeditorw.h" #include "formwindoweditor.h" #include "designerconstants.h" +#include "faketoolbar.h" #include "settingsmanager.h" #include "settingspage.h" #include "editorwidget.h" #include "qtcreatorintegration.h" #include "designerxmleditor.h" #include "designercontext.h" -#include "formeditorstack.h" +#include "editorwidget.h" #include <texteditor/basetextdocument.h> #include <coreplugin/modemanager.h> @@ -62,11 +63,8 @@ #include <QtDesigner/abstractobjectinspector.h> #include <QtDesigner/QDesignerPropertyEditorInterface> #include <QtDesigner/QDesignerActionEditorInterface> +#include <QtDesigner/QDesignerFormEditorInterface> -#include <QtCore/QPluginLoader> -#include <QtCore/QTemporaryFile> -#include <QtCore/QDir> -#include <QtCore/QTime> #include <QtGui/QAction> #include <QtGui/QActionGroup> #include <QtGui/QApplication> @@ -79,14 +77,17 @@ #include <QtGui/QPrintDialog> #include <QtGui/QPrinter> #include <QtGui/QPainter> -#include <QtGui/QStatusBar> #include <QtGui/QStyle> #include <QtGui/QToolBar> +#include <QtGui/QVBoxLayout> #include <QtCore/QDebug> #include <QtCore/QSettings> +#include <QtCore/QSignalMapper> +#include <QtCore/QPluginLoader> +#include <QtCore/QTime> -static const char *settingsGroup = "Designer"; +static const char settingsGroup[] = "Designer"; #ifdef Q_OS_MAC enum { osMac = 1 }; @@ -125,69 +126,10 @@ static inline QAction *createSeparator(QObject *parent, return actSeparator; } -using namespace Designer; -using namespace Designer::Internal; using namespace Designer::Constants; -// --------- Proxy Action - -ProxyAction::ProxyAction(const QString &defaultText, QObject *parent) - : QAction(defaultText, parent), - m_defaultText(defaultText), - m_action(0) -{ - setEnabled(false); -} - -void ProxyAction::setAction(QAction *action) -{ - if (m_action) { - disconnect(m_action, SIGNAL(changed()), this, SLOT(update())); - disconnect(this, SIGNAL(triggered(bool)), m_action, SIGNAL(triggered(bool))); - disconnect(this, SIGNAL(toggled(bool)), m_action, SLOT(setChecked(bool))); - } - m_action = action; - if (!m_action) { - setEnabled(false); -// if (hasAttribute(CA_Hide)) -// m_action->setVisible(false); -// if (hasAttribute(CA_UpdateText)) { - setText(m_defaultText); -// } - } else { - setCheckable(m_action->isCheckable()); - setSeparator(m_action->isSeparator()); - connect(m_action, SIGNAL(changed()), this, SLOT(update())); - // we want to avoid the toggling semantic on slot trigger(), so we just connect the signals - connect(this, SIGNAL(triggered(bool)), m_action, SIGNAL(triggered(bool))); - // we need to update the checked state, so we connect to setChecked slot, which also fires a toggled signal - connect(this, SIGNAL(toggled(bool)), m_action, SLOT(setChecked(bool))); - update(); - } -} - -void ProxyAction::update() -{ - QTC_ASSERT(m_action, return) - bool block = blockSignals(true); -// if (hasAttribute(CA_UpdateIcon)) { - setIcon(m_action->icon()); - setIconText(m_action->iconText()); -// } -// if (hasAttribute(CA_UpdateText)) { - setText(m_action->text()); - setToolTip(m_action->toolTip()); - setStatusTip(m_action->statusTip()); - setWhatsThis(m_action->whatsThis()); -// } - - setChecked(m_action->isChecked()); - - setEnabled(m_action->isEnabled()); - setVisible(m_action->isVisible()); - blockSignals(block); - emit changed(); -} +namespace Designer { +namespace Internal { // --------- FormEditorW @@ -199,6 +141,7 @@ FormEditorW::FormEditorW() : m_fwm(0), m_core(Core::ICore::instance()), m_initStage(RegisterPlugins), + m_viewMenu(0), m_actionGroupEditMode(0), m_actionPrint(0), m_actionPreview(0), @@ -206,7 +149,8 @@ FormEditorW::FormEditorW() : m_actionAboutPlugins(0), m_shortcutMapper(new QSignalMapper(this)), m_context(0), - m_stack(new FormEditorStack), + m_modeWidget(0), + m_editorWidget(0), m_designMode(0) { if (Designer::Constants::Internal::debug) @@ -217,8 +161,6 @@ FormEditorW::FormEditorW() : qFill(m_designerSubWindows, m_designerSubWindows + Designer::Constants::DesignerSubWindowCount, static_cast<QWidget *>(0)); - qFill(m_designerSubWindowActions, m_designerSubWindowActions + Designer::Constants::DesignerSubWindowCount, - static_cast<ProxyAction *>(0)); m_formeditor->setTopLevel(qobject_cast<QWidget *>(m_core->editorManager())); m_formeditor->setSettingsManager(new SettingsManager()); @@ -226,7 +168,11 @@ FormEditorW::FormEditorW() : m_fwm = qobject_cast<qdesigner_internal::QDesignerFormWindowManager*>(m_formeditor->formWindowManager()); QTC_ASSERT(m_fwm, return); - m_context = new DesignerContext(); + Core::UniqueIDManager *idMan = Core::UniqueIDManager::instance(); + m_contexts << idMan->uniqueIdentifier(QLatin1String(Designer::Constants::C_FORMEDITOR)) + << idMan->uniqueIdentifier(QLatin1String(Core::Constants::C_EDITORMANAGER)) + << idMan->uniqueIdentifier(QLatin1String(Core::Constants::C_DESIGN_MODE)); + setupActions(); foreach (QDesignerOptionsPageInterface *designerPage, m_formeditor->optionsPages()) { @@ -234,7 +180,6 @@ FormEditorW::FormEditorW() : ExtensionSystem::PluginManager::instance()->addObject(settingsPage); m_settingsPages.append(settingsPage); } - restoreSettings(m_core->settings()); connect(m_core->editorManager(), SIGNAL(currentEditorChanged(Core::IEditor *)), this, SLOT(currentEditorChanged(Core::IEditor *))); @@ -244,16 +189,19 @@ FormEditorW::FormEditorW() : FormEditorW::~FormEditorW() { - saveSettings(m_core->settings()); - + if (m_context) + m_core->removeContextObject(m_context); if (m_initStage == FullyInitialized) { - m_designMode->unregisterDesignWidget(m_stack); - delete m_stack; - m_stack = 0; - } + if (QSettings *s = m_core->settings()) { + m_core->settings()->beginGroup(settingsGroup); + m_editorWidget->saveSettings(s); + s->endGroup(); + } - for (int i = 0; i < Designer::Constants::DesignerSubWindowCount; ++i) - delete m_designerSubWindows[i]; + m_designMode->unregisterDesignWidget(m_modeWidget); + delete m_modeWidget; + m_modeWidget = 0; + } delete m_formeditor; foreach (SettingsPage *settingsPage, m_settingsPages) { @@ -262,9 +210,56 @@ FormEditorW::~FormEditorW() } delete m_integration; + m_self = 0; +} + +// Add an action to toggle the view state of a dock window +void FormEditorW::addDockViewAction(Core::ActionManager *am, + int index, const QList<int> &context, + const QString &title, const QString &id) +{ + if (const QDockWidget *dw = m_editorWidget->designerDockWidgets()[index]) { + QAction *action = dw->toggleViewAction(); + action->setText(title); + addToolAction(action, am, context, id, m_viewMenu, QString()); + } +} + +void FormEditorW::setupViewActions() +{ + // Populate "View" menu of form editor menu + Core::ActionManager *am = m_core->actionManager(); + QList<int> globalcontext; + globalcontext << m_core->uniqueIDManager()->uniqueIdentifier(Core::Constants::C_GLOBAL); + + addDockViewAction(am, WidgetBoxSubWindow, globalcontext, + tr("Widget box"), QLatin1String("FormEditor.WidgetBox")); + addDockViewAction(am, ObjectInspectorSubWindow, globalcontext, + tr("Object Inspector"), QLatin1String("FormEditor.ObjectInspector")); - m_self = 0; + addDockViewAction(am, PropertyEditorSubWindow, globalcontext, + tr("Property Editor"), QLatin1String("FormEditor.PropertyEditor")); + + addDockViewAction(am, SignalSlotEditorSubWindow, globalcontext, + tr("Signals && Slots Editor"), QLatin1String("FormEditor.SignalsAndSlotsEditor")); + + addDockViewAction(am, ActionEditorSubWindow, globalcontext, + tr("Action Editor"), QLatin1String("FormEditor.ActionEditor")); + + createSeparator(this, am, globalcontext, m_viewMenu, QLatin1String("FormEditor.Menu.Tools.Views.SeparatorLock")); + + m_lockAction = new QAction(tr("Locked"), this); + m_lockAction->setCheckable(true); + addToolAction(m_lockAction, am, globalcontext, QLatin1String("FormEditor.Locked"), m_viewMenu, QString()); + connect(m_lockAction, SIGNAL(toggled(bool)), m_editorWidget, SLOT(setLocked(bool))); + + createSeparator(this, am, globalcontext, m_viewMenu, QLatin1String("FormEditor.Menu.Tools.Views.SeparatorReset")); + + m_resetLayoutAction = new QAction(tr("Reset to Default Layout"), this); + m_lockAction->setChecked(m_editorWidget->isLocked()); + connect(m_resetLayoutAction, SIGNAL(triggered()), m_editorWidget, SLOT(resetToDefaultLayout())); + addToolAction(m_resetLayoutAction, am, globalcontext, QLatin1String("FormEditor.ResetToDefaultLayout"), m_viewMenu, QString()); } void FormEditorW::fullInit() @@ -303,17 +298,32 @@ void FormEditorW::fullInit() delete initTime; } - connect(m_core->editorManager()->instance(), SIGNAL(currentEditorChanged(Core::IEditor*)), - SLOT(checkToActivateEditor(Core::IEditor*))); - connect(m_core->modeManager(), SIGNAL(currentModeChanged(Core::IMode*)), - SLOT(syncOnModeChange(Core::IMode*))); connect(m_core->editorManager()->instance(), SIGNAL(editorsClosed(QList<Core::IEditor*>)), SLOT(closeFormEditorsForXmlEditors(QList<Core::IEditor*>))); + // Nest toolbar and editor widget + m_editorWidget = new EditorWidget(this); + QSettings *settings = m_core->settings(); + settings->beginGroup(settingsGroup); + m_editorWidget->restoreSettings(settings); + settings->endGroup(); m_designMode = ExtensionSystem::PluginManager::instance()->getObject<Core::DesignMode>(); - QStringList mimeTypes; - mimeTypes << FORM_MIMETYPE; - m_designMode->registerDesignWidget(m_stack, mimeTypes); + m_modeWidget = new QWidget; + m_modeWidget->setObjectName(QLatin1String("DesignerModeWidget")); + QVBoxLayout *layout = new QVBoxLayout; + layout->setMargin(0); + layout->setSpacing(0); + + layout->addWidget(new FakeToolBar(createEditorToolBar())); + layout->addWidget(m_editorWidget); + m_modeWidget->setLayout(layout); + + m_context = new DesignerContext(m_contexts, m_modeWidget, this); + m_core->addContextObject(m_context); + + m_designMode->registerDesignWidget(m_modeWidget, QStringList(QLatin1String(FORM_MIMETYPE))); + + setupViewActions(); m_initStage = FullyInitialized; } @@ -371,24 +381,6 @@ void FormEditorW::deleteInstance() delete m_self; } -void FormEditorW::checkToActivateEditor(Core::IEditor *editor) -{ - Core::ModeManager *mm = Core::ICore::instance()->modeManager(); - if (editor && editor->id() == Constants::K_DESIGNER_XML_EDITOR_ID) { - mm->activateMode(Core::Constants::MODE_DESIGN); - } -} - -void FormEditorW::syncOnModeChange(Core::IMode *mode) -{ - Core::ICore *core = Core::ICore::instance(); - if (mode->id() == Core::Constants::MODE_DESIGN - && core->editorManager()->currentEditor()->id() == Designer::Constants::K_DESIGNER_XML_EDITOR_ID ) - { - m_stack->setVisibleEditor(core->editorManager()->currentEditor()); - } -} - void FormEditorW::setupActions() { Core::ActionManager *am = m_core->actionManager(); @@ -406,19 +398,19 @@ void FormEditorW::setupActions() mtools->addMenu(mformtools); //overridden actions - bindShortcut(am->registerAction(m_fwm->actionUndo(), Core::Constants::UNDO, m_context->context()), m_fwm->actionUndo()); - bindShortcut(am->registerAction(m_fwm->actionRedo(), Core::Constants::REDO, m_context->context()), m_fwm->actionRedo()); - bindShortcut(am->registerAction(m_fwm->actionCut(), Core::Constants::CUT, m_context->context()), m_fwm->actionCut()); - bindShortcut(am->registerAction(m_fwm->actionCopy(), Core::Constants::COPY, m_context->context()), m_fwm->actionCopy()); - bindShortcut(am->registerAction(m_fwm->actionPaste(), Core::Constants::PASTE, m_context->context()), m_fwm->actionPaste()); - bindShortcut(am->registerAction(m_fwm->actionSelectAll(), Core::Constants::SELECTALL, m_context->context()), m_fwm->actionSelectAll()); + bindShortcut(am->registerAction(m_fwm->actionUndo(), Core::Constants::UNDO, m_contexts), m_fwm->actionUndo()); + bindShortcut(am->registerAction(m_fwm->actionRedo(), Core::Constants::REDO, m_contexts), m_fwm->actionRedo()); + bindShortcut(am->registerAction(m_fwm->actionCut(), Core::Constants::CUT, m_contexts), m_fwm->actionCut()); + bindShortcut(am->registerAction(m_fwm->actionCopy(), Core::Constants::COPY, m_contexts), m_fwm->actionCopy()); + bindShortcut(am->registerAction(m_fwm->actionPaste(), Core::Constants::PASTE, m_contexts), m_fwm->actionPaste()); + bindShortcut(am->registerAction(m_fwm->actionSelectAll(), Core::Constants::SELECTALL, m_contexts), m_fwm->actionSelectAll()); m_actionPrint = new QAction(this); - bindShortcut(am->registerAction(m_actionPrint, Core::Constants::PRINT, m_context->context()), m_actionPrint); + bindShortcut(am->registerAction(m_actionPrint, Core::Constants::PRINT, m_contexts), m_actionPrint); connect(m_actionPrint, SIGNAL(triggered()), this, SLOT(print())); //'delete' action - command = am->registerAction(m_fwm->actionDelete(), QLatin1String("FormEditor.Edit.Delete"), m_context->context()); + command = am->registerAction(m_fwm->actionDelete(), QLatin1String("FormEditor.Edit.Delete"), m_contexts); command->setDefaultKeySequence(QKeySequence::Delete); bindShortcut(command, m_fwm->actionDelete()); command->setAttribute(Core::Command::CA_Hide); @@ -497,7 +489,7 @@ void FormEditorW::setupActions() addToolAction(m_fwm->actionSimplifyLayout(), am, globalcontext, m_toolActionIds.back(), mformtools); - createSeparator(this, am, m_context->context(), mformtools, QLatin1String("FormEditor.Menu.Tools.Separator1")); + createSeparator(this, am, m_contexts, mformtools, QLatin1String("FormEditor.Menu.Tools.Separator1")); addToolAction(m_fwm->actionLower(), am, globalcontext, QLatin1String("FormEditor.Lower"), mformtools); @@ -505,46 +497,6 @@ void FormEditorW::setupActions() addToolAction(m_fwm->actionRaise(), am, globalcontext, QLatin1String("FormEditor.Raise"), mformtools); - // Views - createSeparator(this, am, globalcontext, mformtools, QLatin1String("FormEditor.Menu.Tools.SeparatorViews")); - - Core::ActionContainer *mviews = am->createMenu(M_FORMEDITOR_VIEWS); - mviews->menu()->setTitle(tr("Views")); - mformtools->addMenu(mviews); - - m_designerSubWindowActions[WidgetBoxSubWindow] = new ProxyAction(tr("Widget Box"), this); - addToolAction(m_designerSubWindowActions[WidgetBoxSubWindow], am, globalcontext, - QLatin1String("FormEditor.WidgetBox"), mviews, ""); - - m_designerSubWindowActions[ObjectInspectorSubWindow] = new ProxyAction(tr("Object Inspector"), this); - addToolAction(m_designerSubWindowActions[ObjectInspectorSubWindow], am, globalcontext, - QLatin1String("FormEditor.ObjectInspector"), mviews, ""); - - m_designerSubWindowActions[PropertyEditorSubWindow] = new ProxyAction(tr("Property Editor"), this); - addToolAction(m_designerSubWindowActions[PropertyEditorSubWindow], am, globalcontext, - QLatin1String("FormEditor.PropertyEditor"), mviews, ""); - - m_designerSubWindowActions[SignalSlotEditorSubWindow] = new ProxyAction(tr("Signals && Slots Editor"), this); - addToolAction(m_designerSubWindowActions[SignalSlotEditorSubWindow], am, globalcontext, - QLatin1String("FormEditor.SignalsAndSlotsEditor"), mviews, ""); - - m_designerSubWindowActions[ActionEditorSubWindow] = new ProxyAction(tr("Action Editor"), this); - addToolAction(m_designerSubWindowActions[ActionEditorSubWindow], am, globalcontext, - QLatin1String("FormEditor.ActionEditor"), mviews, ""); - - createSeparator(this, am, globalcontext, mviews, QLatin1String("FormEditor.Menu.Tools.Views.SeparatorLock")); - - m_lockAction = new QAction(tr("Locked"), this); - m_lockAction->setCheckable(true); - addToolAction(m_lockAction, am, globalcontext, QLatin1String("FormEditor.Locked"), mviews, ""); - connect(m_lockAction, SIGNAL(toggled(bool)), this, SLOT(setFormWindowLayoutLocked(bool))); - - createSeparator(this, am, globalcontext, mviews, QLatin1String("FormEditor.Menu.Tools.Views.SeparatorReset")); - - m_resetLayoutAction = new QAction(tr("Reset to Default Layout"), this); - addToolAction(m_resetLayoutAction, am, globalcontext, QLatin1String("FormEditor.ResetToDefaultLayout"), mviews, ""); - connect(m_resetLayoutAction, SIGNAL(triggered()), this, SLOT(resetToDefaultLayout())); - // Commands that do not go into the editor toolbar createSeparator(this, am, globalcontext, mformtools, QLatin1String("FormEditor.Menu.Tools.Separator2")); @@ -558,7 +510,7 @@ void FormEditorW::setupActions() mformtools->addMenu(createPreviewStyleMenu(am, m_actionGroupPreviewInStyle)); // Form settings - createSeparator(this, am, m_context->context(), medit, QLatin1String("FormEditor.Edit.Separator2"), Core::Constants::G_EDIT_OTHER); + createSeparator(this, am, m_contexts, medit, QLatin1String("FormEditor.Edit.Separator2"), Core::Constants::G_EDIT_OTHER); createSeparator(this, am, globalcontext, mformtools, QLatin1String("FormEditor.Menu.Tools.Separator3")); QAction *actionFormSettings = m_fwm->actionShowFormWindowSettingsDialog(); @@ -571,14 +523,20 @@ void FormEditorW::setupActions() connect(m_actionAboutPlugins, SIGNAL(triggered()), m_fwm, SLOT(aboutPlugins())); m_actionAboutPlugins->setEnabled(false); + // Views. Populated later on. + createSeparator(this, am, globalcontext, mformtools, QLatin1String("FormEditor.Menu.Tools.SeparatorViews")); + + m_viewMenu = am->createMenu(QLatin1String(M_FORMEDITOR_VIEWS)); + m_viewMenu->menu()->setTitle(tr("Views")); + mformtools->addMenu(m_viewMenu); + // FWM connect(m_fwm, SIGNAL(activeFormWindowChanged(QDesignerFormWindowInterface *)), this, SLOT(activeFormWindowChanged(QDesignerFormWindowInterface *))); } - QToolBar *FormEditorW::createEditorToolBar() const { - QToolBar *toolBar = new QToolBar; + QToolBar *editorToolBar = new QToolBar; Core::ActionManager *am = m_core->actionManager(); const QStringList::const_iterator cend = m_toolActionIds.constEnd(); for (QStringList::const_iterator it = m_toolActionIds.constBegin(); it != cend; ++it) { @@ -586,12 +544,12 @@ QToolBar *FormEditorW::createEditorToolBar() const QTC_ASSERT(cmd, continue); QAction *action = cmd->action(); if (!action->icon().isNull()) // Simplify grid has no action yet - toolBar->addAction(action); + editorToolBar->addAction(action); } - int size = toolBar->style()->pixelMetric(QStyle::PM_SmallIconSize); - toolBar->setIconSize(QSize(size, size)); - toolBar->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); - return toolBar; + const int size = editorToolBar->style()->pixelMetric(QStyle::PM_SmallIconSize); + editorToolBar->setIconSize(QSize(size, size)); + editorToolBar->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); + return editorToolBar; } Core::ActionContainer *FormEditorW::createPreviewStyleMenu(Core::ActionManager *am, @@ -620,7 +578,7 @@ Core::ActionContainer *FormEditorW::createPreviewStyleMenu(Core::ActionManager * name += dot; } name += data.toString(); - Core::Command *command = am->registerAction(a, name, m_context->context()); + Core::Command *command = am->registerAction(a, name, m_contexts); bindShortcut(command, a); if (isDeviceProfile) { command->setAttribute(Core::Command::CA_UpdateText); @@ -634,18 +592,10 @@ Core::ActionContainer *FormEditorW::createPreviewStyleMenu(Core::ActionManager * void FormEditorW::saveSettings(QSettings *s) { s->beginGroup(settingsGroup); - EditorWidget::saveState(s); - s->endGroup(); -} - -void FormEditorW::restoreSettings(QSettings *s) -{ - s->beginGroup(settingsGroup); - EditorWidget::restoreState(s); + m_editorWidget->saveSettings(s); s->endGroup(); } - void FormEditorW::critical(const QString &errorMessage) { QMessageBox::critical(m_core->mainWindow(), tr("Designer"), errorMessage); @@ -705,36 +655,9 @@ FormWindowEditor *FormEditorW::createFormWindowEditor(QWidget* parentWidget) { m_fwm->closeAllPreviews(); QDesignerFormWindowInterface *form = m_fwm->createFormWindow(0); - connect(form, SIGNAL(toolChanged(int)), this, SLOT(toolChanged(int))); qdesigner_internal::FormWindowBase::setupDefaultAction(form); - - FormWindowEditor *fww = new FormWindowEditor(form, parentWidget); - // Store a pointer to all form windows so we can unselect - // all other formwindows except the active one. - m_formWindows.append(fww); - - fww->setContext(m_context->context()); - - connect(fww, SIGNAL(destroyed()), this, SLOT(editorDestroyed())); - return fww; -} - -void FormEditorW::editorDestroyed() -{ - QObject *source = sender(); - - if (Designer::Constants::Internal::debug) - qDebug() << Q_FUNC_INFO << source; - - for (EditorList::iterator it = m_formWindows.begin(); it != m_formWindows.end(); ) { - if (*it == source) { - it = m_formWindows.erase(it); - break; - } else { - ++it; - } - } + return new FormWindowEditor(form, parentWidget); } void FormEditorW::updateShortcut(QObject *command) @@ -753,78 +676,42 @@ void FormEditorW::currentEditorChanged(Core::IEditor *editor) if (Designer::Constants::Internal::debug) qDebug() << Q_FUNC_INFO << editor << " of " << m_fwm->formWindowCount(); - // Deactivate Designer if a non-form is being edited if (editor && editor->id() == QLatin1String(Constants::K_DESIGNER_XML_EDITOR_ID)) { DesignerXmlEditorEditable *xmlEditor = qobject_cast<DesignerXmlEditorEditable *>(editor); - FormWindowEditor *fw = m_stack->formWindowEditorForXmlEditor(xmlEditor); QTC_ASSERT(xmlEditor, return); - if (!fw) - fw = m_stack->createFormWindowEditor(xmlEditor); - - // change context when activating another editor - m_core->removeContextObject(m_context); - m_context->setWidget(fw->widget()); - m_core->addContextObject(m_context); - - fw->activate(); - + ensureInitStage(FullyInitialized); + FormWindowEditor *fw = m_editorWidget->formWindowEditorForXmlEditor(xmlEditor); + if (fw) { + m_editorWidget->setVisibleEditor(xmlEditor); + } else { + fw = m_editorWidget->createFormWindowEditor(xmlEditor); + } m_fwm->setActiveFormWindow(fw->formWindow()); m_actionGroupEditMode->setVisible(true); m_modeActionSeparator->setVisible(true); - QDockWidget * const*dockWidgets = fw->dockWidgets(); - for (int i = 0; i < Designer::Constants::DesignerSubWindowCount; ++i) { - if (m_designerSubWindowActions[i] != 0 && dockWidgets[i] != 0) - m_designerSubWindowActions[i]->setAction(dockWidgets[i]->toggleViewAction()); - } - m_lockAction->setEnabled(true); - m_lockAction->setChecked(fw->isLocked()); - m_resetLayoutAction->setEnabled(true); + // Now switch to design mode. + m_core->modeManager()->activateMode(QLatin1String(Core::Constants::MODE_DESIGN)); } else { + // Deactivate Designer if a non-form is being edited m_actionGroupEditMode->setVisible(false); m_modeActionSeparator->setVisible(false); - m_fwm->setActiveFormWindow(0); - for (int i = 0; i < Designer::Constants::DesignerSubWindowCount; ++i) { - if (m_designerSubWindowActions[i] != 0) - m_designerSubWindowActions[i]->setAction(0); - } - m_lockAction->setEnabled(false); - m_resetLayoutAction->setEnabled(false); } } void FormEditorW::activeFormWindowChanged(QDesignerFormWindowInterface *afw) { if (Designer::Constants::Internal::debug) - qDebug() << Q_FUNC_INFO << afw << " of " << m_fwm->formWindowCount() << m_formWindows; + qDebug() << Q_FUNC_INFO << afw << " of " << m_fwm->formWindowCount(); m_fwm->closeAllPreviews(); - - bool foundFormWindow = false; - // Display form selection handles only on active window - EditorList::const_iterator cend = m_formWindows.constEnd(); - for (EditorList::const_iterator it = m_formWindows.constBegin(); it != cend ; ++it) { - FormWindowEditor *fwe = *it; - const bool active = fwe->formWindow() == afw; - if (active) - foundFormWindow = true; - fwe->updateFormWindowSelectionHandles(active); - } - - m_actionPreview->setEnabled(foundFormWindow); - m_actionGroupPreviewInStyle->setEnabled(foundFormWindow); + m_actionPreview->setEnabled(afw != 0); + m_actionGroupPreviewInStyle->setEnabled(afw != 0); } -FormWindowEditor *FormEditorW::activeFormWindow() +FormWindowEditor *FormEditorW::activeFormWindow() const { - QDesignerFormWindowInterface *afw = m_fwm->activeFormWindow(); - for (int i = 0; i < m_formWindows.count(); ++i) { - if (FormWindowEditor *fw = m_formWindows[i]) { - QDesignerFormWindowInterface *fwd = fw->formWindow(); - if (fwd == afw) { - return fw; - } - } - } + if (m_editorWidget) + return m_editorWidget->activeFormWindow(); return 0; } @@ -855,24 +742,10 @@ void FormEditorW::toolChanged(int t) } } -void FormEditorW::setFormWindowLayoutLocked(bool locked) -{ - FormWindowEditor *fwe = activeFormWindow(); - if (fwe) - fwe->setLocked(locked); -} - -void FormEditorW::resetToDefaultLayout() -{ - FormWindowEditor *fwe = activeFormWindow(); - if (fwe) - fwe->resetToDefaultLayout(); -} - void FormEditorW::closeFormEditorsForXmlEditors(QList<Core::IEditor*> editors) { foreach(Core::IEditor *editor, editors) { - m_stack->removeFormWindowEditor(editor); + m_editorWidget->removeFormWindowEditor(editor); } } @@ -931,3 +804,5 @@ void FormEditorW::print() m_core->printer()->setOrientation(oldOrientation); } +} // namespace Internal +} // namespace Designer diff --git a/src/plugins/designer/formeditorw.h b/src/plugins/designer/formeditorw.h index a458224a6b9760e790ad1474b41c13bbf1e74af0..51893429e5be0a4a6af8a6c15ea9428e46096cb3 100644 --- a/src/plugins/designer/formeditorw.h +++ b/src/plugins/designer/formeditorw.h @@ -30,14 +30,10 @@ #ifndef FORMEDITORW_H #define FORMEDITORW_H -#include <QtDesigner/QDesignerFormEditorInterface> - -#include <QtCore/QList> #include <QtCore/QObject> #include <QtCore/QPointer> #include <QtCore/QStringList> -#include <QtCore/QSignalMapper> -#include <QtGui/QAction> +#include <QtCore/QMap> #include "designerconstants.h" @@ -47,6 +43,7 @@ class QDesignerIntegrationInterface; class QDesignerFormEditorInterface; class QDesignerFormWindowInterface; +class QAction; class QActionGroup; class QFocusEvent; @@ -76,25 +73,10 @@ class FormWindowEditor; namespace Internal { -class FormEditorStack; +class EditorWidget; class SettingsPage; class DesignerContext; -class ProxyAction : public QAction -{ - Q_OBJECT -public: - ProxyAction(const QString &defaultText, QObject *parent = 0); - void setAction(QAction *action); - -private slots: - void update(); - -private: - QString m_defaultText; - QPointer<QAction> m_action; -}; - /** FormEditorW is a singleton that stores the Designer CoreInterface and * performs centralized operations. The instance() method will return an * instance. However, it must be manually deleted when unloading the @@ -107,7 +89,10 @@ private: * This is based on the assumption that the Designer settings work with * no plugins loaded. If that does not work, full initialization can be * triggered by connection to the ICore::optionsDialogRequested() signal. - */ + * + * The form editor shows a read-only XML editor in edit mode and Qt Designer + * in Design mode. It connects to void EditorManager::currentEditorChanged() + * and switches modes if a designer XML editor is activated. */ class FormEditorW : public QObject { Q_OBJECT @@ -130,11 +115,10 @@ public: inline QDesignerFormEditorInterface *designerEditor() const { return m_formeditor; } inline QWidget * const*designerSubWindows() const { return m_designerSubWindows; } - QToolBar *createEditorToolBar() const; FormWindowEditor *createFormWindowEditor(QWidget* parentWidget); - FormWindowEditor *activeFormWindow(); + FormWindowEditor *activeFormWindow() const; private slots: void activateEditMode(int id); @@ -143,13 +127,8 @@ private slots: void currentEditorChanged(Core::IEditor *editor); void toolChanged(int); void print(); - void setFormWindowLayoutLocked(bool locked); - void resetToDefaultLayout(); - void editorDestroyed(); void updateShortcut(QObject *command); - void syncOnModeChange(Core::IMode *mode); - void checkToActivateEditor(Core::IEditor *editor); void closeFormEditorsForXmlEditors(QList<Core::IEditor*> editors); private: @@ -157,13 +136,15 @@ private: void fullInit(); void saveSettings(QSettings *s); - void restoreSettings(QSettings *s); void initDesignerSubWindows(); - typedef QList<FormWindowEditor *> EditorList; - void setupActions(); + void setupViewActions(); + inline void addDockViewAction(Core::ActionManager *am, int index, + const QList<int> &context, + const QString &title, const QString &id); + Core::ActionContainer *createPreviewStyleMenu(Core::ActionManager *am, QActionGroup *actionGroup); @@ -184,7 +165,7 @@ private: const QString &name, Core::ActionContainer *c1, const QString &keySequence = QString()); - + QToolBar *createEditorToolBar() const; static FormEditorW *m_self; @@ -195,7 +176,8 @@ private: InitializationStage m_initStage; QWidget *m_designerSubWindows[Designer::Constants::DesignerSubWindowCount]; - ProxyAction *m_designerSubWindowActions[Designer::Constants::DesignerSubWindowCount]; + Core::ActionContainer *m_viewMenu; + QAction *m_lockAction; QAction *m_resetLayoutAction; @@ -209,10 +191,11 @@ private: QSignalMapper *m_shortcutMapper; DesignerContext *m_context; - EditorList m_formWindows; + QList<int> m_contexts; QStringList m_toolActionIds; - QPointer<FormEditorStack> m_stack; + QWidget *m_modeWidget; + EditorWidget *m_editorWidget; Core::DesignMode *m_designMode; QMap<Core::Command *, QAction *> m_commandToDesignerAction; diff --git a/src/plugins/designer/formwindoweditor.cpp b/src/plugins/designer/formwindoweditor.cpp index d7a61bf79d42d01fdd7c500eab4e7a45668b1030..bc43089985bf70296775dfeea39c512d64ae956e 100644 --- a/src/plugins/designer/formwindoweditor.cpp +++ b/src/plugins/designer/formwindoweditor.cpp @@ -27,13 +27,11 @@ ** **************************************************************************/ +#include "formwindoweditor.h" #include "designerconstants.h" -#include "editorwidget.h" #include "formeditorw.h" -#include "formwindoweditor.h" -#include "formwindowfile.h" -#include "formwindowhost.h" -#include "faketoolbar.h" + +#include <coreplugin/ifile.h> #include <projectexplorer/projectexplorer.h> #include <projectexplorer/projectnodes.h> @@ -42,26 +40,15 @@ #include <projectexplorer/session.h> #include <utils/qtcassert.h> -#include <coreplugin/icore.h> -#include <coreplugin/editormanager/editormanager.h> #include <QtDesigner/QDesignerFormWindowInterface> #include <QtDesigner/QDesignerFormEditorInterface> #include <QtDesigner/QDesignerFormWindowManagerInterface> #include <QtDesigner/QDesignerPropertyEditorInterface> -#include <QtDesigner/QDesignerWidgetDataBaseInterface> #include "qt_private/formwindowbase_p.h" #include "qt_private/qtresourcemodel_p.h" -#include "qt_private/qdesigner_integration_p.h" -#include <QtCore/QFile> -#include <QtCore/QDir> -#include <QtCore/QByteArray> -#include <QtCore/QFileInfo> -#include <QtCore/QTemporaryFile> #include <QtCore/QDebug> -#include <QtGui/QToolBar> -#include <QtGui/QDockWidget> using namespace Designer; using namespace Designer::Internal; @@ -103,37 +90,16 @@ void QrcFilesVisitor::visitFolderNode(FolderNode *folderNode) FormWindowEditor::FormWindowEditor(QDesignerFormWindowInterface *form, - QObject *parent) - : Core::IEditor(parent), - m_formWindow(form), + QWidget *parent) : + SharedTools::WidgetHost(parent, form), m_file(0), - m_host(new FormWindowHost(form)), - m_editorWidget(new EditorWidget(m_host)), - m_toolBar(0), m_sessionNode(0), - m_sessionWatcher(0), - m_fakeToolBar(new FakeToolBar(this, toolBar())) + m_sessionWatcher(0) { - m_containerWidget = new QWidget; - QVBoxLayout *layout = new QVBoxLayout(m_containerWidget); - m_containerWidget->setLayout(layout); - - layout->addWidget(m_fakeToolBar); - layout->addWidget(m_editorWidget); - layout->setStretch(0,0); - layout->setStretch(1,1); - layout->setSpacing(0); - layout->setMargin(0); - layout->setContentsMargins(0,0,0,0); - - if (Designer::Constants::Internal::debug) - qDebug() << Q_FUNC_INFO << form << parent; - - connect(m_host, SIGNAL(changed()), this, SIGNAL(changed())); + connect(formWindow(), SIGNAL(selectionChanged()), this, SIGNAL(changed())); + connect(this, SIGNAL(formWindowSizeChanged(int,int)), this, SLOT(slotFormSizeChanged(int,int))); + connect(formWindow(), SIGNAL(changed()), this, SIGNAL(changed())); - connect(form, SIGNAL(toolChanged(int)), m_editorWidget, SLOT(toolChanged(int))); - - m_editorWidget->activate(); } void FormWindowEditor::setFile(Core::IFile *file) @@ -144,7 +110,7 @@ void FormWindowEditor::setFile(Core::IFile *file) } m_file = file; - m_formWindow->setFileName(file->fileName()); + formWindow()->setFileName(file->fileName()); if (m_file) { connect(m_file, SIGNAL(changed()), this, SIGNAL(changed())); @@ -155,36 +121,25 @@ void FormWindowEditor::setFile(Core::IFile *file) FormWindowEditor::~FormWindowEditor() { // Close: Delete the Designer form window via embedding widget - delete m_toolBar; - delete m_fakeToolBar; - delete m_host; - delete m_editorWidget; - if (Designer::Constants::Internal::debug) - qDebug() << Q_FUNC_INFO << m_displayName; if (m_sessionNode && m_sessionWatcher) { m_sessionNode->unregisterWatcher(m_sessionWatcher); delete m_sessionWatcher; } } -void FormWindowEditor::setContext(QList<int> context) -{ - m_context = context; -} - bool FormWindowEditor::createNew(const QString &contents) { if (Designer::Constants::Internal::debug) qDebug() << Q_FUNC_INFO << contents.size() << "chars"; - if (!m_formWindow) + if (!formWindow()) return false; - m_formWindow->setContents(contents); - if (!m_formWindow->mainContainer()) + formWindow()->setContents(contents); + if (!formWindow()->mainContainer()) return false; - if (qdesigner_internal::FormWindowBase *fw = qobject_cast<qdesigner_internal::FormWindowBase *>(m_formWindow)) + if (qdesigner_internal::FormWindowBase *fw = qobject_cast<qdesigner_internal::FormWindowBase *>(formWindow())) fw->setDesignerGrid(qdesigner_internal::FormWindowBase::defaultDesignerGrid()); initializeResources(); @@ -192,43 +147,7 @@ bool FormWindowEditor::createNew(const QString &contents) return true; } -bool FormWindowEditor::open(const QString &fileName /*= QString()*/) -{ - if (Designer::Constants::Internal::debug) - qDebug() << Q_FUNC_INFO << fileName; - - if (fileName.isEmpty()) { - setDisplayName(tr("untitled")); - } else { - const QFileInfo fi(fileName); - const QString fileName = fi.absoluteFilePath(); - - QFile file(fileName); - if (!file.exists()) - return false; - - if (!fi.isReadable()) - return false; - - if (!file.open(QIODevice::ReadOnly|QIODevice::Text)) - return false; - - m_formWindow->setFileName(fileName); - m_formWindow->setContents(&file); - file.close(); - if (!m_formWindow->mainContainer()) - return false; - m_formWindow->setDirty(false); - - initializeResources(fileName); - - setDisplayName(fi.fileName()); - - } - - return true; -} -void FormWindowEditor::initializeResources(const QString &fileName /*= QString()*/) +void FormWindowEditor::initializeResources(const QString & /* fileName */) { ProjectExplorer::ProjectExplorerPlugin *pe = ProjectExplorer::ProjectExplorerPlugin::instance(); ProjectExplorer::SessionManager *session = pe->session(); @@ -242,25 +161,22 @@ void FormWindowEditor::initializeResources(const QString &fileName /*= QString() connect(m_sessionWatcher, SIGNAL(foldersRemoved()), this, SLOT(updateResources())); m_sessionNode->registerWatcher(m_sessionWatcher); - if (qdesigner_internal::FormWindowBase *fw = qobject_cast<qdesigner_internal::FormWindowBase *>(m_formWindow)) { + if (qdesigner_internal::FormWindowBase *fw = qobject_cast<qdesigner_internal::FormWindowBase *>(formWindow())) { QtResourceSet *rs = fw->resourceSet(); m_originalUiQrcPaths = rs->activeQrcPaths(); } - if (!fileName.isEmpty()) - emit opened(fileName); - updateResources(); QDesignerFormWindowManagerInterface *fwm = FormEditorW::instance()->designerEditor()->formWindowManager(); - fwm->setActiveFormWindow(m_formWindow); + fwm->setActiveFormWindow(formWindow()); emit changed(); } void FormWindowEditor::updateResources() { - if (qdesigner_internal::FormWindowBase *fw = qobject_cast<qdesigner_internal::FormWindowBase *>(m_formWindow)) { + if (qdesigner_internal::FormWindowBase *fw = qobject_cast<qdesigner_internal::FormWindowBase *>(formWindow())) { ProjectExplorer::ProjectExplorerPlugin *pe = ProjectExplorer::ProjectExplorerPlugin::instance(); // filename could change in the meantime. ProjectExplorer::Project *project = pe->session()->projectForFile(m_file->fileName()); @@ -281,143 +197,25 @@ void FormWindowEditor::updateResources() } } -void FormWindowEditor::slotOpen(const QString &fileName) -{ - open(fileName); -} - -void FormWindowEditor::slotSetDisplayName(const QString &title) -{ - if (Designer::Constants::Internal::debug) - qDebug() << Q_FUNC_INFO << title; - setDisplayName(title); -} - -bool FormWindowEditor::duplicateSupported() const -{ - return false; -} - -Core::IEditor *FormWindowEditor::duplicate(QWidget *) -{ - return 0; -} - -Core::IFile *FormWindowEditor::file() +Core::IFile *FormWindowEditor::file() const { return m_file; } -QString FormWindowEditor::id() const -{ - return QLatin1String(FORMEDITOR_ID); -} - -QString FormWindowEditor::displayName() const -{ - return m_displayName; -} - -void FormWindowEditor::setDisplayName(const QString &title) -{ - m_displayName = title; -} - -QWidget *FormWindowEditor::toolBar() -{ - if (!m_toolBar) - m_toolBar = FormEditorW::instance()->createEditorToolBar(); - return m_toolBar; -} - -QByteArray FormWindowEditor::saveState() const -{ - return QByteArray(); -} - -bool FormWindowEditor::restoreState(const QByteArray &/*state*/) -{ - return true; -} - -QList<int> FormWindowEditor::context() const -{ - return m_context; -} - -QWidget *FormWindowEditor::widget() -{ - return m_containerWidget; -} - - -QDesignerFormWindowInterface *FormWindowEditor::formWindow() const -{ - return m_formWindow; -} - -QWidget *FormWindowEditor::integrationContainer() -{ - return m_host->integrationContainer(); -} - -void FormWindowEditor::updateFormWindowSelectionHandles(bool state) -{ - m_host->updateFormWindowSelectionHandles(state); -} - -void FormWindowEditor::activate() -{ - m_editorWidget->activate(); -} - -void FormWindowEditor::resetToDefaultLayout() -{ - m_editorWidget->resetToDefaultLayout(); -} - -QString FormWindowEditor::contextHelpId() const -{ - const QDesignerFormEditorInterface *core = FormEditorW::instance()->designerEditor(); - // Present from Qt 4.5.1 onwards. This will show the class documentation - // scrolled to the current property. - const qdesigner_internal::QDesignerIntegration *integration = - qobject_cast<const qdesigner_internal::QDesignerIntegration*>(core->integration()); - if (integration) - return integration->contextHelpId(); - return QString(); -} - QString FormWindowEditor::contents() const { - if (!m_formWindow) + if (!formWindow()) return QString(); -// Activate once all Qt branches around have integrated 4.5.2 -// (Kinetic) -/* -#if QT_VERSION > 0x040501 - // Quiet save as of Qt 4.5.2 - qdesigner_internal::FormWindowBase *fwb = qobject_cast<qdesigner_internal::FormWindowBase *>(m_formWindow); - QTC_ASSERT(fwb, return QString::null); - return fwb->fileContents(); -#else - return m_formWindow->contents(); -#endif -*/ - return m_formWindow->contents(); + return formWindow()->contents(); } -QDockWidget* const* FormWindowEditor::dockWidgets() const +void FormWindowEditor::slotFormSizeChanged(int w, int h) { - return m_editorWidget->dockWidgets(); -} - -bool FormWindowEditor::isLocked() const -{ - return m_editorWidget->isLocked(); -} + if (Designer::Constants::Internal::debug) + qDebug() << Q_FUNC_INFO << w << h; -void FormWindowEditor::setLocked(bool locked) -{ - m_editorWidget->setLocked(locked); + formWindow()->setDirty(true); + static const QString geometry = QLatin1String("geometry"); + FormEditorW::instance()->designerEditor()->propertyEditor()->setPropertyValue(geometry, QRect(0,0,w,h) ); + emit changed(); } diff --git a/src/plugins/designer/formwindoweditor.h b/src/plugins/designer/formwindoweditor.h index d02df943ced9de0e172a05a5c3799af6509829b3..aeb59ef594fe7e803fee29b2e5bb7ba7fb465279 100644 --- a/src/plugins/designer/formwindoweditor.h +++ b/src/plugins/designer/formwindoweditor.h @@ -31,102 +31,55 @@ #define FORMWINDOWEDITOR_H #include "designer_export.h" - -#include <coreplugin/editormanager/ieditor.h> +#include "widgethost.h" #include <QtCore/QStringList> #include <QtCore/QPointer> -QT_BEGIN_NAMESPACE -class QDesignerFormWindowInterface; -class QDesignerFormWindowManagerInterface; -class QFile; -class QToolBar; -class QDockWidget; -QT_END_NAMESPACE - namespace ProjectExplorer { class SessionNode; class NodesWatcher; } -namespace Designer { -namespace Internal { -class FormWindowFile; -class FormWindowHost; -class EditorWidget; -class FakeToolBar; +namespace Core { + class IFile; } +namespace Designer { + // Master class maintaining a form window editor, // containing file and widget host -class DESIGNER_EXPORT FormWindowEditor : public Core::IEditor +class FormWindowEditor : public SharedTools::WidgetHost { Q_OBJECT public: - FormWindowEditor(QDesignerFormWindowInterface *form, - QObject *parent = 0); + explicit FormWindowEditor(QDesignerFormWindowInterface *form, + QWidget *parent = 0); ~FormWindowEditor(); // IEditor bool createNew(const QString &contents); - bool open(const QString &fileName = QString()); - bool duplicateSupported() const; - Core::IEditor *duplicate(QWidget *); - Core::IFile *file(); - QString id() const; - QString displayName() const; - void setDisplayName(const QString &title); - QWidget *toolBar(); - QByteArray saveState() const; - bool restoreState(const QByteArray &state); - virtual bool isTemporary() const { return false; } - - void setContext(QList<int> ctx); - // ContextInterface - virtual QList<int> context() const; - virtual QWidget *widget(); - virtual QString contextHelpId() const; - - QDesignerFormWindowInterface *formWindow() const; - QWidget *integrationContainer(); - void updateFormWindowSelectionHandles(bool state); - QDockWidget* const* dockWidgets() const; - bool isLocked() const; - void setLocked(bool locked); - - QString contents() const;\ void setFile(Core::IFile *file); + QString contents() const; + Core::IFile *file() const; signals: - // Internal - void opened(const QString &fileName); - -public slots: - void activate(); - void resetToDefaultLayout(); + void changed(); private slots: - void slotOpen(const QString &fileName); - void slotSetDisplayName(const QString &title); void updateResources(); + void slotFormSizeChanged(int w, int h); private: void initializeResources(const QString &fileName = QString()); QWidget *m_containerWidget; QString m_displayName; - QList<int> m_context; - QDesignerFormWindowInterface *m_formWindow; QPointer<Core::IFile> m_file; - Internal::FormWindowHost *m_host; - Internal::EditorWidget *m_editorWidget; - QToolBar *m_toolBar; QStringList m_originalUiQrcPaths; ProjectExplorer::SessionNode *m_sessionNode; ProjectExplorer::NodesWatcher *m_sessionWatcher; - Internal::FakeToolBar *m_fakeToolBar; }; } // namespace Designer diff --git a/src/plugins/designer/formwindowfile.cpp b/src/plugins/designer/formwindowfile.cpp index 73e6a6a22f53af2bcc6ddfdce48bc3e6193a9b66..15bac0bbd09b7882534435a13d4c964c10e5a7c7 100644 --- a/src/plugins/designer/formwindowfile.cpp +++ b/src/plugins/designer/formwindowfile.cpp @@ -94,6 +94,8 @@ QString FormWindowFile::fileName() const bool FormWindowFile::isModified() const { + if (Designer::Constants::Internal::debug) + qDebug() << Q_FUNC_INFO << m_formWindow->isDirty(); return m_formWindow->isDirty(); } diff --git a/src/plugins/designer/formwindowhost.cpp b/src/plugins/designer/formwindowhost.cpp deleted file mode 100644 index 182c9f9e1327e01b8e4392ef61a9f4149d981e8a..0000000000000000000000000000000000000000 --- a/src/plugins/designer/formwindowhost.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/************************************************************************** -** -** This file is part of Qt Creator -** -** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** Commercial Usage -** -** 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. -** -** GNU Lesser General Public License Usage -** -** 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. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://qt.nokia.com/contact. -** -**************************************************************************/ - -#include "formwindowhost.h" -#include "formeditorw.h" - -#include <QtDesigner/QDesignerFormWindowInterface> -#include <QtDesigner/QDesignerFormEditorInterface> -#include <QtDesigner/QDesignerPropertyEditorInterface> - -#include <QtCore/QDebug> -#include <QtCore/QVariant> - -using namespace Designer::Internal; -using namespace SharedTools; - -FormWindowHost::FormWindowHost(QDesignerFormWindowInterface *form, - QWidget *parent) : - WidgetHost(parent, form) -{ - connect(formWindow(), SIGNAL(selectionChanged()), this, SIGNAL(changed())); - connect(this, SIGNAL(formWindowSizeChanged(int,int)), this, SLOT(formSizeChanged(int,int))); - connect(formWindow(), SIGNAL(changed()), this, SIGNAL(changed())); -} - -FormWindowHost::~FormWindowHost() -{ - if (Designer::Constants::Internal::debug) - qDebug() << Q_FUNC_INFO; -} - -void FormWindowHost::formSizeChanged(int w, int h) -{ - if (Designer::Constants::Internal::debug) - qDebug() << Q_FUNC_INFO << w << h; - - formWindow()->setDirty(true); - static const QString geometry = QLatin1String("geometry"); - FormEditorW::instance()->designerEditor()->propertyEditor()->setPropertyValue(geometry, QRect(0,0,w,h) ); - emit changed(); -} diff --git a/src/plugins/designer/formwindowhost.h b/src/plugins/designer/formwindowhost.h deleted file mode 100644 index 7a66e8fda64ad352600694fb886fb18aa3c906d6..0000000000000000000000000000000000000000 --- a/src/plugins/designer/formwindowhost.h +++ /dev/null @@ -1,57 +0,0 @@ -/************************************************************************** -** -** This file is part of Qt Creator -** -** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** Commercial Usage -** -** 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. -** -** GNU Lesser General Public License Usage -** -** 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. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://qt.nokia.com/contact. -** -**************************************************************************/ - -#ifndef FORMWINDOWHOST_H -#define FORMWINDOWHOST_H - -#include "widgethost.h" - -class QDesignerFormWindowInterface; - -namespace Designer { -namespace Internal { - -class FormWindowHost : public SharedTools::WidgetHost -{ - Q_OBJECT -public: - FormWindowHost(QDesignerFormWindowInterface *form, QWidget *parent = 0); - ~FormWindowHost(); - -signals: - void changed(); - -private slots: - void formSizeChanged(int w, int h); -}; - -} // namespace Internal -} // namespace Designer - -#endif // FORMWINDOWHOST_H diff --git a/src/plugins/designer/qtcreatorintegration.cpp b/src/plugins/designer/qtcreatorintegration.cpp index cd286fd7d794e8ad3c6c10b82f0479bdbb84db5d..54ace337dad71250e9182d456baa634ab59637f6 100644 --- a/src/plugins/designer/qtcreatorintegration.cpp +++ b/src/plugins/designer/qtcreatorintegration.cpp @@ -52,6 +52,7 @@ #include <projectexplorer/session.h> #include <QtDesigner/QDesignerFormWindowInterface> +#include <QtDesigner/QDesignerFormEditorInterface> #include <QtGui/QMessageBox>