2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
2008-12-02 15:08:31 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "formeditorw.h"
|
|
|
|
|
#include "formwindoweditor.h"
|
2014-09-03 12:38:51 +02:00
|
|
|
#include "formwindowfile.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "settingsmanager.h"
|
|
|
|
|
#include "settingspage.h"
|
|
|
|
|
#include "editorwidget.h"
|
2010-03-09 15:48:01 +01:00
|
|
|
#include "editordata.h"
|
2009-05-08 16:11:49 +02:00
|
|
|
#include "qtcreatorintegration.h"
|
2010-02-26 11:08:17 +01:00
|
|
|
#include "designercontext.h"
|
2010-03-10 10:21:52 +01:00
|
|
|
#include <widgethost.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2020-06-17 12:23:44 +02:00
|
|
|
#include <coreplugin/actionmanager/actioncontainer.h>
|
|
|
|
|
#include <coreplugin/actionmanager/actionmanager.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <coreplugin/coreconstants.h>
|
2020-06-17 12:23:44 +02:00
|
|
|
#include <coreplugin/designmode.h>
|
2015-03-04 15:04:03 +01:00
|
|
|
#include <coreplugin/dialogs/ioptionspage.h>
|
2015-02-26 13:22:35 +01:00
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
2020-06-17 12:23:44 +02:00
|
|
|
#include <coreplugin/editortoolbar.h>
|
|
|
|
|
#include <coreplugin/helpmanager.h>
|
|
|
|
|
#include <coreplugin/icore.h>
|
2010-06-28 11:20:07 +02:00
|
|
|
#include <coreplugin/minisplitter.h>
|
2020-06-17 12:23:44 +02:00
|
|
|
#include <coreplugin/modemanager.h>
|
2010-06-28 11:20:07 +02:00
|
|
|
#include <coreplugin/outputpane.h>
|
2020-06-17 12:23:44 +02:00
|
|
|
#include <utils/infobar.h>
|
2008-12-09 15:25:01 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDesignerFormEditorPluginInterface>
|
|
|
|
|
#include <QDesignerFormEditorInterface>
|
|
|
|
|
#include <QDesignerComponents>
|
2014-08-20 16:09:26 +02:00
|
|
|
#include <QDesignerFormWindowManagerInterface>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDesignerWidgetBoxInterface>
|
|
|
|
|
#include <abstractobjectinspector.h>
|
|
|
|
|
#include <QDesignerPropertyEditorInterface>
|
|
|
|
|
#include <QDesignerActionEditorInterface>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QAction>
|
|
|
|
|
#include <QActionGroup>
|
|
|
|
|
#include <QApplication>
|
|
|
|
|
#include <QCursor>
|
|
|
|
|
#include <QDockWidget>
|
2015-02-26 13:38:54 +01:00
|
|
|
#include <QMenu>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QMessageBox>
|
|
|
|
|
#include <QKeySequence>
|
|
|
|
|
#include <QPrintDialog>
|
|
|
|
|
#include <QPrinter>
|
|
|
|
|
#include <QPainter>
|
|
|
|
|
#include <QStyle>
|
|
|
|
|
#include <QToolBar>
|
|
|
|
|
#include <QVBoxLayout>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDebug>
|
|
|
|
|
#include <QSettings>
|
|
|
|
|
#include <QPluginLoader>
|
|
|
|
|
#include <QTime>
|
2019-07-05 13:43:54 +02:00
|
|
|
#include <QElapsedTimer>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2016-08-03 23:29:58 +03:00
|
|
|
#include <algorithm>
|
|
|
|
|
|
2012-01-20 15:18:58 +01:00
|
|
|
static const char settingsGroupC[] = "Designer";
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-03-11 14:37:24 +01:00
|
|
|
/* Actions of the designer plugin:
|
|
|
|
|
* Designer provides a toolbar which is subject to a context change (to
|
2010-01-11 10:22:55 +01:00
|
|
|
* "edit mode" context) when it is focused.
|
2009-03-11 14:37:24 +01:00
|
|
|
* In order to prevent its actions from being disabled/hidden by that context
|
|
|
|
|
* change, the actions are registered on the global context. In currentEditorChanged(),
|
|
|
|
|
* the ones that are present in the global edit menu are set visible/invisible manually.
|
|
|
|
|
* The designer context is currently used for Cut/Copy/Paste, etc. */
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
static inline QIcon designerIcon(const QString &iconName)
|
|
|
|
|
{
|
2011-05-19 11:30:38 +02:00
|
|
|
const QIcon icon = QDesignerFormEditorInterface::createIcon(iconName);
|
2008-12-02 12:01:29 +01:00
|
|
|
if (icon.isNull())
|
|
|
|
|
qWarning() << "Unable to locate " << iconName;
|
|
|
|
|
return icon;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-30 16:38:57 +02:00
|
|
|
using namespace Core;
|
2008-12-02 12:01:29 +01:00
|
|
|
using namespace Designer::Constants;
|
2020-06-26 13:59:38 +02:00
|
|
|
using namespace Utils;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-03-09 10:26:20 +01:00
|
|
|
namespace Designer {
|
|
|
|
|
namespace Internal {
|
2009-08-11 15:32:53 +02:00
|
|
|
|
2014-09-03 12:38:51 +02:00
|
|
|
/* A stub-like, read-only text editor which displays UI files as text. Could be used as a
|
|
|
|
|
* read/write editor too, but due to lack of XML editor, highlighting and other such
|
|
|
|
|
* functionality, editing is disabled.
|
|
|
|
|
* Provides an informational title bar containing a button triggering a
|
|
|
|
|
* switch to design mode.
|
|
|
|
|
* Internally manages a FormWindowEditor and uses the plain text
|
|
|
|
|
* editable embedded in it. */
|
2014-09-26 11:37:54 +02:00
|
|
|
class DesignerXmlEditorWidget : public TextEditor::TextEditorWidget
|
2014-09-03 12:38:51 +02:00
|
|
|
{
|
|
|
|
|
public:
|
2019-11-25 14:23:33 +01:00
|
|
|
using TextEditorWidget::TextEditorWidget;
|
2014-09-03 12:38:51 +02:00
|
|
|
|
2015-06-01 17:55:31 +02:00
|
|
|
void finalizeInitialization() override
|
2014-09-03 12:38:51 +02:00
|
|
|
{
|
|
|
|
|
setReadOnly(true);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2014-09-26 11:37:54 +02:00
|
|
|
class FormWindowEditorFactory : public TextEditor::TextEditorFactory
|
2014-09-03 12:38:51 +02:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
FormWindowEditorFactory()
|
|
|
|
|
{
|
2015-02-03 23:55:24 +02:00
|
|
|
setId(K_DESIGNER_XML_EDITOR_ID);
|
2014-09-03 12:38:51 +02:00
|
|
|
setEditorCreator([]() { return new FormWindowEditor; });
|
|
|
|
|
setEditorWidgetCreator([]() { return new Internal::DesignerXmlEditorWidget; });
|
2015-02-03 09:18:57 +01:00
|
|
|
setUseGenericHighlighter(true);
|
2014-09-03 12:38:51 +02:00
|
|
|
setDuplicatedSupported(false);
|
2018-06-11 14:07:20 +02:00
|
|
|
setMarksVisible(false);
|
2014-09-03 12:38:51 +02:00
|
|
|
}
|
|
|
|
|
|
2014-09-03 16:03:35 +02:00
|
|
|
FormWindowEditor *create(QDesignerFormWindowInterface *form)
|
|
|
|
|
{
|
|
|
|
|
setDocumentCreator([form]() { return new FormWindowFile(form); });
|
|
|
|
|
return qobject_cast<FormWindowEditor *>(createEditor());
|
|
|
|
|
}
|
2014-09-03 12:38:51 +02:00
|
|
|
};
|
|
|
|
|
|
2009-08-11 15:32:53 +02:00
|
|
|
// --------- FormEditorW
|
|
|
|
|
|
2014-09-03 16:03:35 +02:00
|
|
|
class FormEditorData
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
Q_DECLARE_TR_FUNCTIONS(FormEditorW)
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
FormEditorData();
|
|
|
|
|
~FormEditorData();
|
|
|
|
|
|
|
|
|
|
void activateEditMode(int id);
|
|
|
|
|
void toolChanged(int);
|
|
|
|
|
void print();
|
|
|
|
|
void setPreviewMenuEnabled(bool e);
|
2016-07-19 22:53:08 +03:00
|
|
|
void updateShortcut(Command *command);
|
2014-09-03 16:03:35 +02:00
|
|
|
|
|
|
|
|
void fullInit();
|
|
|
|
|
|
|
|
|
|
void saveSettings(QSettings *s);
|
|
|
|
|
|
|
|
|
|
void initDesignerSubWindows();
|
|
|
|
|
|
|
|
|
|
void setupActions();
|
|
|
|
|
void setupViewActions();
|
2015-02-03 23:55:24 +02:00
|
|
|
void addDockViewAction(ActionContainer *viewMenu,
|
2014-09-03 16:03:35 +02:00
|
|
|
int index,
|
2015-02-03 23:55:24 +02:00
|
|
|
const Context &context,
|
|
|
|
|
const QString &title, Id id);
|
2014-09-03 16:03:35 +02:00
|
|
|
|
2015-02-03 23:55:24 +02:00
|
|
|
ActionContainer *createPreviewStyleMenu(QActionGroup *actionGroup);
|
2014-09-03 16:03:35 +02:00
|
|
|
|
|
|
|
|
void critical(const QString &errorMessage);
|
2015-02-03 23:55:24 +02:00
|
|
|
void bindShortcut(Command *command, QAction *action);
|
2014-09-03 16:03:35 +02:00
|
|
|
QAction *createEditModeAction(QActionGroup *ag,
|
2015-02-03 23:55:24 +02:00
|
|
|
const Context &context,
|
|
|
|
|
ActionContainer *medit,
|
2014-09-03 16:03:35 +02:00
|
|
|
const QString &actionName,
|
2015-02-03 23:55:24 +02:00
|
|
|
Id id,
|
2014-09-03 16:03:35 +02:00
|
|
|
int toolNumber,
|
|
|
|
|
const QString &iconName = QString(),
|
|
|
|
|
const QString &keySequence = QString());
|
2015-02-03 23:55:24 +02:00
|
|
|
Command *addToolAction(QAction *a,
|
|
|
|
|
const Context &context, Id id,
|
|
|
|
|
ActionContainer *c1, const QString &keySequence = QString(),
|
|
|
|
|
Id groupId = Id());
|
2014-09-03 16:03:35 +02:00
|
|
|
QToolBar *createEditorToolBar() const;
|
2015-02-03 23:55:24 +02:00
|
|
|
IEditor *createEditor();
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2014-09-03 16:03:35 +02:00
|
|
|
public:
|
2017-10-16 20:47:05 +02:00
|
|
|
QDesignerFormEditorInterface *m_formeditor = nullptr;
|
|
|
|
|
QtCreatorIntegration *m_integration = nullptr;
|
|
|
|
|
QDesignerFormWindowManagerInterface *m_fwm = nullptr;
|
2019-11-25 14:23:33 +01:00
|
|
|
FormEditorW::InitializationStage m_initStage = FormEditorW::RegisterPlugins;
|
2014-09-03 16:03:35 +02:00
|
|
|
|
2015-02-03 23:55:24 +02:00
|
|
|
QWidget *m_designerSubWindows[DesignerSubWindowCount];
|
2014-09-03 16:03:35 +02:00
|
|
|
|
2017-10-16 20:47:05 +02:00
|
|
|
QAction *m_lockAction = nullptr;
|
|
|
|
|
QAction *m_resetLayoutAction = nullptr;
|
2014-09-03 16:03:35 +02:00
|
|
|
|
2015-02-03 23:55:24 +02:00
|
|
|
QList<IOptionsPage *> m_settingsPages;
|
2017-10-16 20:47:05 +02:00
|
|
|
QActionGroup *m_actionGroupEditMode = nullptr;
|
|
|
|
|
QAction *m_actionPrint = nullptr;
|
|
|
|
|
QAction *m_actionPreview = nullptr;
|
|
|
|
|
QActionGroup *m_actionGroupPreviewInStyle = nullptr;
|
|
|
|
|
QMenu *m_previewInStyleMenu = nullptr;
|
|
|
|
|
QAction *m_actionAboutPlugins = nullptr;
|
|
|
|
|
|
2015-02-03 23:55:24 +02:00
|
|
|
Context m_contexts;
|
2014-09-03 16:03:35 +02:00
|
|
|
|
2015-02-03 23:55:24 +02:00
|
|
|
QList<Id> m_toolActionIds;
|
2017-10-16 20:47:05 +02:00
|
|
|
QWidget *m_modeWidget = nullptr;
|
|
|
|
|
EditorWidget *m_editorWidget = nullptr;
|
2014-09-03 16:03:35 +02:00
|
|
|
|
2017-10-16 20:47:05 +02:00
|
|
|
QWidget *m_editorToolBar = nullptr;
|
|
|
|
|
EditorToolBar *m_toolBar = nullptr;
|
2014-09-03 16:03:35 +02:00
|
|
|
|
2015-02-03 23:55:24 +02:00
|
|
|
QMap<Command *, QAction *> m_commandToDesignerAction;
|
2017-10-16 20:47:05 +02:00
|
|
|
FormWindowEditorFactory *m_xmlEditorFactory = nullptr;
|
2014-09-03 16:03:35 +02:00
|
|
|
};
|
|
|
|
|
|
2017-10-16 20:47:05 +02:00
|
|
|
static FormEditorData *d = nullptr;
|
|
|
|
|
static FormEditorW *m_instance = nullptr;
|
2014-09-03 16:03:35 +02:00
|
|
|
|
|
|
|
|
FormEditorData::FormEditorData() :
|
2019-11-25 14:23:33 +01:00
|
|
|
m_formeditor(QDesignerComponents::createFormEditor(nullptr))
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-01-21 12:07:19 +01:00
|
|
|
if (Designer::Constants::Internal::debug)
|
2008-12-02 12:01:29 +01:00
|
|
|
qDebug() << Q_FUNC_INFO;
|
2014-09-03 16:03:35 +02:00
|
|
|
QTC_ASSERT(!d, return);
|
|
|
|
|
d = this;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2016-08-03 23:29:58 +03:00
|
|
|
std::fill(m_designerSubWindows, m_designerSubWindows + DesignerSubWindowCount,
|
2019-07-31 17:21:41 +02:00
|
|
|
static_cast<QWidget *>(nullptr));
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2013-08-30 16:38:57 +02:00
|
|
|
m_formeditor->setTopLevel(ICore::mainWindow());
|
2008-12-02 12:01:29 +01:00
|
|
|
m_formeditor->setSettingsManager(new SettingsManager());
|
|
|
|
|
|
2011-05-19 11:30:38 +02:00
|
|
|
m_fwm = m_formeditor->formWindowManager();
|
2008-12-09 15:25:01 +01:00
|
|
|
QTC_ASSERT(m_fwm, return);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2015-02-03 23:55:24 +02:00
|
|
|
m_contexts.add(C_FORMEDITOR);
|
2010-03-09 10:26:20 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
setupActions();
|
|
|
|
|
|
2017-10-16 20:47:05 +02:00
|
|
|
const auto optionPages = m_formeditor->optionsPages();
|
|
|
|
|
for (QDesignerOptionsPageInterface *designerPage : optionPages) {
|
2008-12-02 12:01:29 +01:00
|
|
|
SettingsPage *settingsPage = new SettingsPage(designerPage);
|
|
|
|
|
m_settingsPages.append(settingsPage);
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-03 16:03:35 +02:00
|
|
|
QObject::connect(EditorManager::instance(), &EditorManager::currentEditorChanged, [this](IEditor *editor) {
|
|
|
|
|
if (Designer::Constants::Internal::debug)
|
|
|
|
|
qDebug() << Q_FUNC_INFO << editor << " of " << m_fwm->formWindowCount();
|
|
|
|
|
|
|
|
|
|
if (editor && editor->document()->id() == Constants::K_DESIGNER_XML_EDITOR_ID) {
|
|
|
|
|
FormWindowEditor *xmlEditor = qobject_cast<FormWindowEditor *>(editor);
|
|
|
|
|
QTC_ASSERT(xmlEditor, return);
|
|
|
|
|
FormEditorW::ensureInitStage(FormEditorW::FullyInitialized);
|
|
|
|
|
SharedTools::WidgetHost *fw = m_editorWidget->formWindowEditorForXmlEditor(xmlEditor);
|
|
|
|
|
QTC_ASSERT(fw, return);
|
|
|
|
|
m_editorWidget->setVisibleEditor(xmlEditor);
|
|
|
|
|
m_fwm->setActiveFormWindow(fw->formWindow());
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2014-09-03 12:38:51 +02:00
|
|
|
m_xmlEditorFactory = new FormWindowEditorFactory;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2014-09-03 16:03:35 +02:00
|
|
|
FormEditorData::~FormEditorData()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2014-09-03 16:03:35 +02:00
|
|
|
if (m_initStage == FormEditorW::FullyInitialized) {
|
2013-08-30 16:38:57 +02:00
|
|
|
QSettings *s = ICore::settings();
|
2017-10-16 20:47:05 +02:00
|
|
|
s->beginGroup(settingsGroupC);
|
2012-08-09 12:58:51 +03:00
|
|
|
m_editorWidget->saveSettings(s);
|
|
|
|
|
s->endGroup();
|
2010-02-26 11:08:17 +01:00
|
|
|
|
2018-01-23 09:09:46 +01:00
|
|
|
DesignMode::unregisterDesignWidget(m_modeWidget);
|
2010-03-09 10:26:20 +01:00
|
|
|
delete m_modeWidget;
|
2017-10-16 20:47:05 +02:00
|
|
|
m_modeWidget = nullptr;
|
2010-03-09 10:26:20 +01:00
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
delete m_formeditor;
|
2010-12-02 18:28:16 +01:00
|
|
|
qDeleteAll(m_settingsPages);
|
|
|
|
|
m_settingsPages.clear();
|
2010-02-26 11:08:17 +01:00
|
|
|
delete m_integration;
|
|
|
|
|
|
2014-09-03 12:38:51 +02:00
|
|
|
delete m_xmlEditorFactory ;
|
2017-10-16 20:47:05 +02:00
|
|
|
d = nullptr;
|
2010-03-09 10:26:20 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-09 15:48:01 +01:00
|
|
|
// Add an actioon to toggle the view state of a dock window
|
2014-09-03 16:03:35 +02:00
|
|
|
void FormEditorData::addDockViewAction(ActionContainer *viewMenu,
|
2013-08-30 16:38:57 +02:00
|
|
|
int index, const Context &context,
|
2014-07-01 11:08:26 +02:00
|
|
|
const QString &title, Id id)
|
2010-03-09 10:26:20 +01:00
|
|
|
{
|
|
|
|
|
if (const QDockWidget *dw = m_editorWidget->designerDockWidgets()[index]) {
|
|
|
|
|
QAction *action = dw->toggleViewAction();
|
|
|
|
|
action->setText(title);
|
2013-08-30 16:38:57 +02:00
|
|
|
Command *cmd = addToolAction(action, context, id, viewMenu, QString());
|
|
|
|
|
cmd->setAttribute(Command::CA_Hide);
|
2010-03-09 10:26:20 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-03 16:03:35 +02:00
|
|
|
void FormEditorData::setupViewActions()
|
2010-03-09 10:26:20 +01:00
|
|
|
{
|
|
|
|
|
// Populate "View" menu of form editor menu
|
2020-03-04 10:44:07 +01:00
|
|
|
ActionContainer *viewMenu = ActionManager::actionContainer(Core::Constants::M_VIEW_VIEWS);
|
2012-04-17 08:01:25 +02:00
|
|
|
QTC_ASSERT(viewMenu, return);
|
2010-03-09 10:26:20 +01:00
|
|
|
|
2012-05-24 13:49:06 +02:00
|
|
|
addDockViewAction(viewMenu, WidgetBoxSubWindow, m_contexts,
|
2013-08-30 16:38:57 +02:00
|
|
|
tr("Widget box"), "FormEditor.WidgetBox");
|
2010-02-26 11:08:17 +01:00
|
|
|
|
2012-05-24 13:49:06 +02:00
|
|
|
addDockViewAction(viewMenu, ObjectInspectorSubWindow, m_contexts,
|
2013-08-30 16:38:57 +02:00
|
|
|
tr("Object Inspector"), "FormEditor.ObjectInspector");
|
2010-02-26 11:08:17 +01:00
|
|
|
|
2012-05-24 13:49:06 +02:00
|
|
|
addDockViewAction(viewMenu, PropertyEditorSubWindow, m_contexts,
|
2013-08-30 16:38:57 +02:00
|
|
|
tr("Property Editor"), "FormEditor.PropertyEditor");
|
2010-03-09 10:26:20 +01:00
|
|
|
|
2012-05-24 13:49:06 +02:00
|
|
|
addDockViewAction(viewMenu, SignalSlotEditorSubWindow, m_contexts,
|
2013-08-30 16:38:57 +02:00
|
|
|
tr("Signals && Slots Editor"), "FormEditor.SignalsAndSlotsEditor");
|
2010-03-09 10:26:20 +01:00
|
|
|
|
2012-05-24 13:49:06 +02:00
|
|
|
addDockViewAction(viewMenu, ActionEditorSubWindow, m_contexts,
|
2013-08-30 16:38:57 +02:00
|
|
|
tr("Action Editor"), "FormEditor.ActionEditor");
|
2014-09-29 17:03:25 +02:00
|
|
|
// Lock/Reset
|
|
|
|
|
Command *cmd = addToolAction(m_editorWidget->menuSeparator1(), m_contexts, "FormEditor.SeparatorLock", viewMenu);
|
|
|
|
|
cmd->setAttribute(Command::CA_Hide);
|
|
|
|
|
|
|
|
|
|
cmd = addToolAction(m_editorWidget->autoHideTitleBarsAction(), m_contexts, "FormEditor.Locked", viewMenu);
|
|
|
|
|
cmd->setAttribute(Command::CA_Hide);
|
|
|
|
|
|
|
|
|
|
cmd = addToolAction(m_editorWidget->menuSeparator2(), m_contexts, "FormEditor.SeparatorReset", viewMenu);
|
2013-08-30 16:38:57 +02:00
|
|
|
cmd->setAttribute(Command::CA_Hide);
|
2010-03-09 10:26:20 +01:00
|
|
|
|
2013-08-30 16:38:57 +02:00
|
|
|
cmd = addToolAction(m_editorWidget->resetLayoutAction(), m_contexts, "FormEditor.ResetToDefaultLayout", viewMenu);
|
2014-09-03 16:03:35 +02:00
|
|
|
|
|
|
|
|
QObject::connect(m_editorWidget, &EditorWidget::resetLayout,
|
|
|
|
|
m_editorWidget, &EditorWidget::resetToDefaultLayout);
|
|
|
|
|
|
2013-08-30 16:38:57 +02:00
|
|
|
cmd->setAttribute(Command::CA_Hide);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2014-09-03 16:03:35 +02:00
|
|
|
void FormEditorData::fullInit()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2014-09-03 16:03:35 +02:00
|
|
|
QTC_ASSERT(m_initStage == FormEditorW::RegisterPlugins, return);
|
2019-07-31 17:21:41 +02:00
|
|
|
QElapsedTimer *initTime = nullptr;
|
2009-01-21 12:07:19 +01:00
|
|
|
if (Designer::Constants::Internal::debug) {
|
2019-07-05 13:43:54 +02:00
|
|
|
initTime = new QElapsedTimer;
|
2008-12-02 12:01:29 +01:00
|
|
|
initTime->start();
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-03 16:03:35 +02:00
|
|
|
QDesignerComponents::createTaskMenu(m_formeditor, m_instance);
|
|
|
|
|
QDesignerComponents::initializePlugins(m_formeditor);
|
2008-12-02 12:01:29 +01:00
|
|
|
QDesignerComponents::initializeResources();
|
|
|
|
|
initDesignerSubWindows();
|
2014-09-03 16:03:35 +02:00
|
|
|
m_integration = new QtCreatorIntegration(m_formeditor, m_instance);
|
2008-12-02 12:01:29 +01:00
|
|
|
m_formeditor->setIntegration(m_integration);
|
2010-05-28 15:58:55 +02:00
|
|
|
// Connect Qt Designer help request to HelpManager.
|
2015-06-02 09:14:40 +02:00
|
|
|
QObject::connect(m_integration, &QtCreatorIntegration::creatorHelpRequested,
|
2018-08-31 16:00:32 +02:00
|
|
|
HelpManager::Signals::instance(),
|
2019-01-24 10:42:24 +01:00
|
|
|
[](const QUrl &url) { HelpManager::showHelpUrl(url, HelpManager::HelpModeAlways); });
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This will initialize our TabOrder, Signals and slots and Buddy editors.
|
|
|
|
|
*/
|
2017-10-16 20:47:05 +02:00
|
|
|
const QList<QObject *> plugins = QPluginLoader::staticInstances() + m_formeditor->pluginInstances();
|
|
|
|
|
for (QObject *plugin : plugins) {
|
2008-12-02 12:01:29 +01:00
|
|
|
if (QDesignerFormEditorPluginInterface *formEditorPlugin = qobject_cast<QDesignerFormEditorPluginInterface*>(plugin)) {
|
|
|
|
|
if (!formEditorPlugin->isInitialized())
|
|
|
|
|
formEditorPlugin->initialize(m_formeditor);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-11 15:44:58 +01:00
|
|
|
if (m_actionAboutPlugins)
|
|
|
|
|
m_actionAboutPlugins->setEnabled(true);
|
|
|
|
|
|
2009-01-21 12:07:19 +01:00
|
|
|
if (Designer::Constants::Internal::debug) {
|
2008-12-02 12:01:29 +01:00
|
|
|
qDebug() << Q_FUNC_INFO << initTime->elapsed() << "ms";
|
|
|
|
|
delete initTime;
|
|
|
|
|
}
|
2009-03-11 15:44:58 +01:00
|
|
|
|
2017-10-16 20:47:05 +02:00
|
|
|
QObject::connect(EditorManager::instance(), &EditorManager::editorsClosed,
|
|
|
|
|
[this] (const QList<IEditor *> editors) {
|
|
|
|
|
for (IEditor *editor : editors)
|
2014-09-03 16:03:35 +02:00
|
|
|
m_editorWidget->removeFormWindowEditor(editor);
|
|
|
|
|
});
|
|
|
|
|
|
2010-03-09 10:26:20 +01:00
|
|
|
// Nest toolbar and editor widget
|
2014-09-24 08:10:27 +03:00
|
|
|
m_editorWidget = new EditorWidget;
|
2013-08-30 16:38:57 +02:00
|
|
|
QSettings *settings = ICore::settings();
|
2017-10-16 20:47:05 +02:00
|
|
|
settings->beginGroup(settingsGroupC);
|
2010-03-09 10:26:20 +01:00
|
|
|
m_editorWidget->restoreSettings(settings);
|
|
|
|
|
settings->endGroup();
|
2010-02-26 11:08:17 +01:00
|
|
|
|
2010-03-10 10:50:11 +01:00
|
|
|
m_editorToolBar = createEditorToolBar();
|
2014-07-18 15:58:26 +02:00
|
|
|
m_toolBar = new EditorToolBar;
|
2013-08-30 16:38:57 +02:00
|
|
|
m_toolBar->setToolbarCreationFlags(EditorToolBar::FlagsStandalone);
|
2010-03-10 10:50:11 +01:00
|
|
|
m_toolBar->setNavigationVisible(false);
|
|
|
|
|
m_toolBar->addCenterToolBar(m_editorToolBar);
|
|
|
|
|
|
2010-03-09 10:26:20 +01:00
|
|
|
m_modeWidget = new QWidget;
|
2017-10-16 20:47:05 +02:00
|
|
|
m_modeWidget->setObjectName("DesignerModeWidget");
|
2019-11-25 14:23:33 +01:00
|
|
|
auto layout = new QVBoxLayout(m_modeWidget);
|
2019-08-29 10:36:01 +02:00
|
|
|
layout->setContentsMargins(0, 0, 0, 0);
|
2010-03-09 10:26:20 +01:00
|
|
|
layout->setSpacing(0);
|
2010-03-10 10:50:11 +01:00
|
|
|
layout->addWidget(m_toolBar);
|
2010-06-28 11:20:07 +02:00
|
|
|
// Avoid mode switch to 'Edit' mode when the application started by
|
|
|
|
|
// 'Run' in 'Design' mode emits output.
|
2019-11-25 14:23:33 +01:00
|
|
|
auto splitter = new MiniSplitter(Qt::Vertical);
|
2010-06-28 11:20:07 +02:00
|
|
|
splitter->addWidget(m_editorWidget);
|
2018-01-23 09:09:46 +01:00
|
|
|
QWidget *outputPane = new OutputPanePlaceHolder(Core::Constants::MODE_DESIGN, splitter);
|
2017-10-16 20:47:05 +02:00
|
|
|
outputPane->setObjectName("DesignerOutputPanePlaceHolder");
|
2010-12-03 17:30:09 +01:00
|
|
|
splitter->addWidget(outputPane);
|
2010-06-28 11:20:07 +02:00
|
|
|
layout->addWidget(splitter);
|
2010-03-09 10:26:20 +01:00
|
|
|
|
2013-08-30 16:38:57 +02:00
|
|
|
Context designerContexts = m_contexts;
|
2010-06-25 17:37:59 +02:00
|
|
|
designerContexts.add(Core::Constants::C_EDITORMANAGER);
|
2020-05-26 14:48:38 +02:00
|
|
|
ICore::addContextObject(new DesignerContext(designerContexts, m_modeWidget, m_instance));
|
2010-03-09 10:26:20 +01:00
|
|
|
|
2018-01-23 09:09:46 +01:00
|
|
|
DesignMode::registerDesignWidget(m_modeWidget, QStringList(FORM_MIMETYPE), m_contexts);
|
2010-03-09 10:26:20 +01:00
|
|
|
|
|
|
|
|
setupViewActions();
|
2010-02-26 11:08:17 +01:00
|
|
|
|
2014-09-03 16:03:35 +02:00
|
|
|
m_initStage = FormEditorW::FullyInitialized;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2014-09-03 16:03:35 +02:00
|
|
|
void FormEditorData::initDesignerSubWindows()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2019-07-31 17:21:41 +02:00
|
|
|
std::fill(m_designerSubWindows, m_designerSubWindows + DesignerSubWindowCount, static_cast<QWidget*>(nullptr));
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2019-07-31 17:21:41 +02:00
|
|
|
QDesignerWidgetBoxInterface *wb = QDesignerComponents::createWidgetBox(m_formeditor, nullptr);
|
2009-08-11 15:32:53 +02:00
|
|
|
wb->setWindowTitle(tr("Widget Box"));
|
2017-10-16 20:47:05 +02:00
|
|
|
wb->setObjectName("WidgetBox");
|
2008-12-02 12:01:29 +01:00
|
|
|
m_formeditor->setWidgetBox(wb);
|
|
|
|
|
m_designerSubWindows[WidgetBoxSubWindow] = wb;
|
|
|
|
|
|
2019-07-31 17:21:41 +02:00
|
|
|
QDesignerObjectInspectorInterface *oi = QDesignerComponents::createObjectInspector(m_formeditor, nullptr);
|
2009-08-11 15:32:53 +02:00
|
|
|
oi->setWindowTitle(tr("Object Inspector"));
|
2017-10-16 20:47:05 +02:00
|
|
|
oi->setObjectName("ObjectInspector");
|
2008-12-02 12:01:29 +01:00
|
|
|
m_formeditor->setObjectInspector(oi);
|
|
|
|
|
m_designerSubWindows[ObjectInspectorSubWindow] = oi;
|
|
|
|
|
|
2019-07-31 17:21:41 +02:00
|
|
|
QDesignerPropertyEditorInterface *pe = QDesignerComponents::createPropertyEditor(m_formeditor, nullptr);
|
2009-08-11 15:32:53 +02:00
|
|
|
pe->setWindowTitle(tr("Property Editor"));
|
2017-10-16 20:47:05 +02:00
|
|
|
pe->setObjectName("PropertyEditor");
|
2008-12-02 12:01:29 +01:00
|
|
|
m_formeditor->setPropertyEditor(pe);
|
|
|
|
|
m_designerSubWindows[PropertyEditorSubWindow] = pe;
|
|
|
|
|
|
2019-07-31 17:21:41 +02:00
|
|
|
QWidget *se = QDesignerComponents::createSignalSlotEditor(m_formeditor, nullptr);
|
2020-11-09 08:03:34 +01:00
|
|
|
se->setWindowTitle(tr("Signals and Slots Editor"));
|
2017-10-16 20:47:05 +02:00
|
|
|
se->setObjectName("SignalsAndSlotsEditor");
|
2008-12-02 12:01:29 +01:00
|
|
|
m_designerSubWindows[SignalSlotEditorSubWindow] = se;
|
|
|
|
|
|
2019-07-31 17:21:41 +02:00
|
|
|
QDesignerActionEditorInterface *ae = QDesignerComponents::createActionEditor(m_formeditor, nullptr);
|
2009-08-11 15:32:53 +02:00
|
|
|
ae->setWindowTitle(tr("Action Editor"));
|
2017-10-16 20:47:05 +02:00
|
|
|
ae->setObjectName("ActionEditor");
|
2008-12-02 12:01:29 +01:00
|
|
|
m_formeditor->setActionEditor(ae);
|
|
|
|
|
m_designerSubWindows[ActionEditorSubWindow] = ae;
|
2014-09-03 16:03:35 +02:00
|
|
|
m_initStage = FormEditorW::SubwindowsInitialized;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2015-02-03 23:55:24 +02:00
|
|
|
QList<IOptionsPage *> FormEditorW::optionsPages()
|
2010-12-02 18:28:16 +01:00
|
|
|
{
|
2014-09-03 16:03:35 +02:00
|
|
|
return d->m_settingsPages;
|
2010-12-02 18:28:16 +01:00
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void FormEditorW::ensureInitStage(InitializationStage s)
|
|
|
|
|
{
|
2009-01-21 12:07:19 +01:00
|
|
|
if (Designer::Constants::Internal::debug)
|
2008-12-02 12:01:29 +01:00
|
|
|
qDebug() << Q_FUNC_INFO << s;
|
2014-09-03 16:03:35 +02:00
|
|
|
if (!d) {
|
|
|
|
|
m_instance = new FormEditorW;
|
|
|
|
|
d = new FormEditorData;
|
|
|
|
|
}
|
|
|
|
|
if (d->m_initStage >= s)
|
2008-12-02 12:01:29 +01:00
|
|
|
return;
|
|
|
|
|
QApplication::setOverrideCursor(Qt::WaitCursor);
|
2014-09-03 16:03:35 +02:00
|
|
|
d->fullInit();
|
2008-12-02 12:01:29 +01:00
|
|
|
QApplication::restoreOverrideCursor();
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-03 16:03:35 +02:00
|
|
|
void FormEditorW::deleteInstance()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2014-09-03 16:03:35 +02:00
|
|
|
delete d;
|
2017-10-16 20:47:05 +02:00
|
|
|
d = nullptr;
|
2014-09-03 16:03:35 +02:00
|
|
|
delete m_instance;
|
2017-10-16 20:47:05 +02:00
|
|
|
m_instance = nullptr;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2014-09-03 16:03:35 +02:00
|
|
|
IEditor *FormEditorW::createEditor()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2014-09-03 16:03:35 +02:00
|
|
|
ensureInitStage(FullyInitialized);
|
|
|
|
|
return d->createEditor();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2014-09-03 16:03:35 +02:00
|
|
|
void FormEditorData::setupActions()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
//menus
|
2013-08-30 16:38:57 +02:00
|
|
|
ActionContainer *medit = ActionManager::actionContainer(Core::Constants::M_EDIT);
|
2014-03-06 17:50:28 +01:00
|
|
|
ActionContainer *mformtools = ActionManager::actionContainer(M_FORMEDITOR);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
//overridden actions
|
2013-08-30 16:38:57 +02:00
|
|
|
bindShortcut(ActionManager::registerAction(m_fwm->actionUndo(), Core::Constants::UNDO, m_contexts), m_fwm->actionUndo());
|
|
|
|
|
bindShortcut(ActionManager::registerAction(m_fwm->actionRedo(), Core::Constants::REDO, m_contexts), m_fwm->actionRedo());
|
|
|
|
|
bindShortcut(ActionManager::registerAction(m_fwm->actionCut(), Core::Constants::CUT, m_contexts), m_fwm->actionCut());
|
|
|
|
|
bindShortcut(ActionManager::registerAction(m_fwm->actionCopy(), Core::Constants::COPY, m_contexts), m_fwm->actionCopy());
|
|
|
|
|
bindShortcut(ActionManager::registerAction(m_fwm->actionPaste(), Core::Constants::PASTE, m_contexts), m_fwm->actionPaste());
|
|
|
|
|
bindShortcut(ActionManager::registerAction(m_fwm->actionSelectAll(), Core::Constants::SELECTALL, m_contexts), m_fwm->actionSelectAll());
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2014-09-03 16:03:35 +02:00
|
|
|
m_actionPrint = new QAction(m_instance);
|
2013-08-30 16:38:57 +02:00
|
|
|
bindShortcut(ActionManager::registerAction(m_actionPrint, Core::Constants::PRINT, m_contexts), m_actionPrint);
|
2014-09-03 16:03:35 +02:00
|
|
|
QObject::connect(m_actionPrint, &QAction::triggered, [this]() { print(); });
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-04-20 10:13:17 +02:00
|
|
|
//'delete' action. Do not set a shortcut as Designer handles
|
|
|
|
|
// the 'Delete' key by event filter. Setting a shortcut triggers
|
|
|
|
|
// buggy behaviour on Mac (Pressing Delete in QLineEdit removing the widget).
|
2013-08-30 16:38:57 +02:00
|
|
|
Command *command;
|
2013-09-03 11:42:35 +02:00
|
|
|
command = ActionManager::registerAction(m_fwm->actionDelete(), "FormEditor.Edit.Delete", m_contexts);
|
2010-01-08 13:10:04 +01:00
|
|
|
bindShortcut(command, m_fwm->actionDelete());
|
2013-08-30 16:38:57 +02:00
|
|
|
command->setAttribute(Command::CA_Hide);
|
2008-12-02 12:01:29 +01:00
|
|
|
medit->addAction(command, Core::Constants::G_EDIT_COPYPASTE);
|
|
|
|
|
|
2014-09-03 16:03:35 +02:00
|
|
|
m_actionGroupEditMode = new QActionGroup(m_instance);
|
2008-12-02 12:01:29 +01:00
|
|
|
m_actionGroupEditMode->setExclusive(true);
|
2014-09-03 16:03:35 +02:00
|
|
|
QObject::connect(m_actionGroupEditMode, &QActionGroup::triggered,
|
|
|
|
|
[this](QAction *a) { activateEditMode(a->data().toInt()); });
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-06-05 14:22:20 +02:00
|
|
|
medit->addSeparator(m_contexts, Core::Constants::G_EDIT_OTHER);
|
2009-07-09 18:27:56 +02:00
|
|
|
|
2013-09-03 11:42:35 +02:00
|
|
|
m_toolActionIds.push_back("FormEditor.WidgetEditor");
|
2012-05-24 13:49:06 +02:00
|
|
|
createEditModeAction(m_actionGroupEditMode, m_contexts, medit,
|
2010-05-14 15:45:43 +02:00
|
|
|
tr("Edit Widgets"), m_toolActionIds.back(),
|
2017-10-16 20:47:05 +02:00
|
|
|
EditModeWidgetEditor, "widgettool.png", tr("F3"));
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2013-09-03 11:42:35 +02:00
|
|
|
m_toolActionIds.push_back("FormEditor.SignalsSlotsEditor");
|
2012-05-24 13:49:06 +02:00
|
|
|
createEditModeAction(m_actionGroupEditMode, m_contexts, medit,
|
2010-05-14 15:45:43 +02:00
|
|
|
tr("Edit Signals/Slots"), m_toolActionIds.back(),
|
2017-10-16 20:47:05 +02:00
|
|
|
EditModeSignalsSlotEditor, "signalslottool.png", tr("F4"));
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2013-09-03 11:42:35 +02:00
|
|
|
m_toolActionIds.push_back("FormEditor.BuddyEditor");
|
2012-05-24 13:49:06 +02:00
|
|
|
createEditModeAction(m_actionGroupEditMode, m_contexts, medit,
|
2010-05-14 15:45:43 +02:00
|
|
|
tr("Edit Buddies"), m_toolActionIds.back(),
|
2017-10-16 20:47:05 +02:00
|
|
|
EditModeBuddyEditor, "buddytool.png");
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2013-09-03 11:42:35 +02:00
|
|
|
m_toolActionIds.push_back("FormEditor.TabOrderEditor");
|
2012-05-24 13:49:06 +02:00
|
|
|
createEditModeAction(m_actionGroupEditMode, m_contexts, medit,
|
2010-05-14 15:45:43 +02:00
|
|
|
tr("Edit Tab Order"), m_toolActionIds.back(),
|
2017-10-16 20:47:05 +02:00
|
|
|
EditModeTabOrderEditor, "tabordertool.png");
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
//tool actions
|
2013-09-03 11:42:35 +02:00
|
|
|
m_toolActionIds.push_back("FormEditor.LayoutHorizontally");
|
2018-02-02 13:39:18 +01:00
|
|
|
const QString horizLayoutShortcut = useMacShortcuts ? tr("Meta+Shift+H") : tr("Ctrl+H");
|
2012-05-24 13:49:06 +02:00
|
|
|
addToolAction(m_fwm->actionHorizontalLayout(), m_contexts,
|
2009-03-11 14:37:24 +01:00
|
|
|
m_toolActionIds.back(), mformtools, horizLayoutShortcut);
|
|
|
|
|
|
2013-09-03 11:42:35 +02:00
|
|
|
m_toolActionIds.push_back("FormEditor.LayoutVertically");
|
2018-02-02 13:39:18 +01:00
|
|
|
const QString vertLayoutShortcut = useMacShortcuts ? tr("Meta+L") : tr("Ctrl+L");
|
2012-05-24 13:49:06 +02:00
|
|
|
addToolAction(m_fwm->actionVerticalLayout(), m_contexts,
|
2009-03-11 14:37:24 +01:00
|
|
|
m_toolActionIds.back(), mformtools, vertLayoutShortcut);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2013-09-03 11:42:35 +02:00
|
|
|
m_toolActionIds.push_back("FormEditor.SplitHorizontal");
|
2012-05-24 13:49:06 +02:00
|
|
|
addToolAction(m_fwm->actionSplitHorizontal(), m_contexts,
|
2008-12-02 12:01:29 +01:00
|
|
|
m_toolActionIds.back(), mformtools);
|
|
|
|
|
|
2013-09-03 11:42:35 +02:00
|
|
|
m_toolActionIds.push_back("FormEditor.SplitVertical");
|
2012-05-24 13:49:06 +02:00
|
|
|
addToolAction(m_fwm->actionSplitVertical(), m_contexts,
|
2008-12-02 12:01:29 +01:00
|
|
|
m_toolActionIds.back(), mformtools);
|
|
|
|
|
|
2013-09-03 11:42:35 +02:00
|
|
|
m_toolActionIds.push_back("FormEditor.LayoutForm");
|
2012-05-24 13:49:06 +02:00
|
|
|
addToolAction(m_fwm->actionFormLayout(), m_contexts,
|
2008-12-02 12:01:29 +01:00
|
|
|
m_toolActionIds.back(), mformtools);
|
|
|
|
|
|
2013-09-03 11:42:35 +02:00
|
|
|
m_toolActionIds.push_back("FormEditor.LayoutGrid");
|
2018-02-02 13:39:18 +01:00
|
|
|
const QString gridShortcut = useMacShortcuts ? tr("Meta+Shift+G") : tr("Ctrl+G");
|
2012-05-24 13:49:06 +02:00
|
|
|
addToolAction(m_fwm->actionGridLayout(), m_contexts,
|
2009-03-11 14:37:24 +01:00
|
|
|
m_toolActionIds.back(), mformtools, gridShortcut);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2013-09-03 11:42:35 +02:00
|
|
|
m_toolActionIds.push_back("FormEditor.LayoutBreak");
|
2012-05-24 13:49:06 +02:00
|
|
|
addToolAction(m_fwm->actionBreakLayout(), m_contexts,
|
2008-12-02 12:01:29 +01:00
|
|
|
m_toolActionIds.back(), mformtools);
|
|
|
|
|
|
2013-09-03 11:42:35 +02:00
|
|
|
m_toolActionIds.push_back("FormEditor.LayoutAdjustSize");
|
2018-02-02 13:39:18 +01:00
|
|
|
const QString adjustShortcut = useMacShortcuts ? tr("Meta+J") : tr("Ctrl+J");
|
2012-05-24 13:49:06 +02:00
|
|
|
addToolAction(m_fwm->actionAdjustSize(), m_contexts,
|
2009-03-11 14:37:24 +01:00
|
|
|
m_toolActionIds.back(), mformtools, adjustShortcut);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2013-09-03 11:42:35 +02:00
|
|
|
m_toolActionIds.push_back("FormEditor.SimplifyLayout");
|
2012-05-24 13:49:06 +02:00
|
|
|
addToolAction(m_fwm->actionSimplifyLayout(), m_contexts,
|
2008-12-02 12:01:29 +01:00
|
|
|
m_toolActionIds.back(), mformtools);
|
|
|
|
|
|
2012-06-05 14:22:20 +02:00
|
|
|
mformtools->addSeparator(m_contexts);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2013-09-03 11:42:35 +02:00
|
|
|
addToolAction(m_fwm->actionLower(), m_contexts, "FormEditor.Lower", mformtools);
|
|
|
|
|
addToolAction(m_fwm->actionRaise(), m_contexts, "FormEditor.Raise", mformtools);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
// Commands that do not go into the editor toolbar
|
2012-06-05 14:22:20 +02:00
|
|
|
mformtools->addSeparator(m_contexts);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2011-05-19 11:30:38 +02:00
|
|
|
m_actionPreview = m_fwm->action(QDesignerFormWindowManagerInterface::DefaultPreviewAction);
|
2008-12-09 15:25:01 +01:00
|
|
|
QTC_ASSERT(m_actionPreview, return);
|
2013-09-03 11:42:35 +02:00
|
|
|
addToolAction(m_actionPreview, m_contexts, "FormEditor.Preview", mformtools, tr("Alt+Shift+R"));
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
// Preview in style...
|
2011-05-19 11:30:38 +02:00
|
|
|
m_actionGroupPreviewInStyle = m_fwm->actionGroup(QDesignerFormWindowManagerInterface::StyledPreviewActionGroup);
|
|
|
|
|
|
2013-08-30 16:38:57 +02:00
|
|
|
ActionContainer *previewAC = createPreviewStyleMenu(m_actionGroupPreviewInStyle);
|
2010-06-29 09:29:18 +02:00
|
|
|
m_previewInStyleMenu = previewAC->menu();
|
|
|
|
|
mformtools->addMenu(previewAC);
|
|
|
|
|
setPreviewMenuEnabled(false);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
// Form settings
|
2012-06-05 14:22:20 +02:00
|
|
|
medit->addSeparator(m_contexts, Core::Constants::G_EDIT_OTHER);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-06-05 14:22:20 +02:00
|
|
|
mformtools->addSeparator(m_contexts);
|
2010-08-10 16:07:06 +02:00
|
|
|
|
2014-03-06 17:50:28 +01:00
|
|
|
mformtools->addSeparator(m_contexts, Core::Constants::G_DEFAULT_THREE);
|
2011-05-19 11:30:38 +02:00
|
|
|
QAction *actionFormSettings = m_fwm->action(QDesignerFormWindowManagerInterface::FormWindowSettingsDialogAction);
|
2014-03-06 17:50:28 +01:00
|
|
|
addToolAction(actionFormSettings, m_contexts, "FormEditor.FormSettings", mformtools,
|
|
|
|
|
QString(), Core::Constants::G_DEFAULT_THREE);
|
2009-03-11 14:37:24 +01:00
|
|
|
|
2014-03-06 17:50:28 +01:00
|
|
|
mformtools->addSeparator(m_contexts, Core::Constants::G_DEFAULT_THREE);
|
2014-09-03 16:03:35 +02:00
|
|
|
m_actionAboutPlugins = new QAction(tr("About Qt Designer Plugins..."), m_instance);
|
2014-03-06 17:50:28 +01:00
|
|
|
addToolAction(m_actionAboutPlugins, m_contexts, "FormEditor.AboutPlugins", mformtools,
|
|
|
|
|
QString(), Core::Constants::G_DEFAULT_THREE);
|
2014-09-03 16:03:35 +02:00
|
|
|
QObject::connect(m_actionAboutPlugins, &QAction::triggered,
|
|
|
|
|
m_fwm, &QDesignerFormWindowManagerInterface::showPluginDialog);
|
2009-03-11 15:44:58 +01:00
|
|
|
m_actionAboutPlugins->setEnabled(false);
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
// FWM
|
2014-09-03 16:03:35 +02:00
|
|
|
QObject::connect(m_fwm, &QDesignerFormWindowManagerInterface::activeFormWindowChanged,
|
|
|
|
|
[this] (QDesignerFormWindowInterface *afw) {
|
|
|
|
|
m_fwm->closeAllPreviews();
|
2019-07-31 17:21:41 +02:00
|
|
|
setPreviewMenuEnabled(afw != nullptr);
|
2014-09-03 16:03:35 +02:00
|
|
|
});
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2014-09-03 16:03:35 +02:00
|
|
|
QToolBar *FormEditorData::createEditorToolBar() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-03-09 10:26:20 +01:00
|
|
|
QToolBar *editorToolBar = new QToolBar;
|
2019-11-25 14:23:33 +01:00
|
|
|
for (const auto &id : m_toolActionIds) {
|
|
|
|
|
Command *cmd = ActionManager::command(id);
|
2008-12-09 15:25:01 +01:00
|
|
|
QTC_ASSERT(cmd, continue);
|
2008-12-02 12:01:29 +01:00
|
|
|
QAction *action = cmd->action();
|
|
|
|
|
if (!action->icon().isNull()) // Simplify grid has no action yet
|
2010-03-09 10:26:20 +01:00
|
|
|
editorToolBar->addAction(action);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2010-03-09 10:26:20 +01:00
|
|
|
const int size = editorToolBar->style()->pixelMetric(QStyle::PM_SmallIconSize);
|
|
|
|
|
editorToolBar->setIconSize(QSize(size, size));
|
|
|
|
|
editorToolBar->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
|
|
|
|
|
return editorToolBar;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2014-09-03 16:03:35 +02:00
|
|
|
ActionContainer *FormEditorData::createPreviewStyleMenu(QActionGroup *actionGroup)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2017-10-16 20:47:05 +02:00
|
|
|
const QString menuId = M_FORMEDITOR_PREVIEW;
|
2013-08-30 16:38:57 +02:00
|
|
|
ActionContainer *menuPreviewStyle = ActionManager::createMenu(M_FORMEDITOR_PREVIEW);
|
2008-12-02 12:01:29 +01:00
|
|
|
menuPreviewStyle->menu()->setTitle(tr("Preview in"));
|
|
|
|
|
|
|
|
|
|
// The preview menu is a list of invisible actions for the embedded design
|
|
|
|
|
// device profiles (integer data) followed by a separator and the styles
|
|
|
|
|
// (string data). Make device profiles update their text and hide them
|
|
|
|
|
// in the configuration dialog.
|
|
|
|
|
const QList<QAction*> actions = actionGroup->actions();
|
|
|
|
|
|
2017-10-16 20:47:05 +02:00
|
|
|
const QString deviceProfilePrefix = "DeviceProfile";
|
|
|
|
|
const QChar dot = '.';
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2017-10-16 20:47:05 +02:00
|
|
|
for (QAction *a : actions) {
|
2008-12-02 12:01:29 +01:00
|
|
|
QString name = menuId;
|
|
|
|
|
name += dot;
|
|
|
|
|
const QVariant data = a->data();
|
|
|
|
|
const bool isDeviceProfile = data.type() == QVariant::Int;
|
|
|
|
|
if (isDeviceProfile) {
|
|
|
|
|
name += deviceProfilePrefix;
|
|
|
|
|
name += dot;
|
|
|
|
|
}
|
|
|
|
|
name += data.toString();
|
2013-08-30 16:38:57 +02:00
|
|
|
Command *command = ActionManager::registerAction(a, Id::fromString(name), m_contexts);
|
2010-01-08 13:10:04 +01:00
|
|
|
bindShortcut(command, a);
|
2008-12-02 12:01:29 +01:00
|
|
|
if (isDeviceProfile) {
|
2013-08-30 16:38:57 +02:00
|
|
|
command->setAttribute(Command::CA_UpdateText);
|
|
|
|
|
command->setAttribute(Command::CA_NonConfigurable);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
menuPreviewStyle->addAction(command);
|
|
|
|
|
}
|
|
|
|
|
return menuPreviewStyle;
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-03 16:03:35 +02:00
|
|
|
void FormEditorData::setPreviewMenuEnabled(bool e)
|
2010-06-29 09:29:18 +02:00
|
|
|
{
|
|
|
|
|
m_actionPreview->setEnabled(e);
|
|
|
|
|
m_previewInStyleMenu->setEnabled(e);
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-03 16:03:35 +02:00
|
|
|
void FormEditorData::saveSettings(QSettings *s)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2017-10-16 20:47:05 +02:00
|
|
|
s->beginGroup(settingsGroupC);
|
2010-03-09 10:26:20 +01:00
|
|
|
m_editorWidget->saveSettings(s);
|
2009-08-10 16:24:29 +02:00
|
|
|
s->endGroup();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2014-09-03 16:03:35 +02:00
|
|
|
void FormEditorData::critical(const QString &errorMessage)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2020-06-02 09:10:40 +02:00
|
|
|
QMessageBox::critical(ICore::dialogParent(), tr("Designer"), errorMessage);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-01-08 13:10:04 +01:00
|
|
|
// Apply the command shortcut to the action and connects to the command's keySequenceChanged signal
|
2014-09-03 16:03:35 +02:00
|
|
|
void FormEditorData::bindShortcut(Command *command, QAction *action)
|
2010-01-08 13:10:04 +01:00
|
|
|
{
|
|
|
|
|
m_commandToDesignerAction.insert(command, action);
|
2015-06-02 09:14:40 +02:00
|
|
|
QObject::connect(command, &Command::keySequenceChanged,
|
2016-07-19 22:53:08 +03:00
|
|
|
command, [this, command] { updateShortcut(command); });
|
2010-01-08 13:10:04 +01:00
|
|
|
updateShortcut(command);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create an action to activate a designer tool
|
2014-09-03 16:03:35 +02:00
|
|
|
QAction *FormEditorData::createEditModeAction(QActionGroup *ag,
|
2013-08-30 16:38:57 +02:00
|
|
|
const Context &context,
|
|
|
|
|
ActionContainer *medit,
|
2010-01-08 13:10:04 +01:00
|
|
|
const QString &actionName,
|
2014-07-01 11:08:26 +02:00
|
|
|
Id id,
|
2010-01-08 13:10:04 +01:00
|
|
|
int toolNumber,
|
|
|
|
|
const QString &iconName,
|
|
|
|
|
const QString &keySequence)
|
|
|
|
|
{
|
2019-11-25 14:23:33 +01:00
|
|
|
auto rc = new QAction(actionName, ag);
|
2010-01-08 13:10:04 +01:00
|
|
|
rc->setCheckable(true);
|
|
|
|
|
if (!iconName.isEmpty())
|
|
|
|
|
rc->setIcon(designerIcon(iconName));
|
2013-08-30 16:38:57 +02:00
|
|
|
Command *command = ActionManager::registerAction(rc, id, context);
|
2015-02-03 23:55:24 +02:00
|
|
|
command->setAttribute(Command::CA_Hide);
|
2010-01-08 13:10:04 +01:00
|
|
|
if (!keySequence.isEmpty())
|
|
|
|
|
command->setDefaultKeySequence(QKeySequence(keySequence));
|
|
|
|
|
bindShortcut(command, rc);
|
|
|
|
|
medit->addAction(command, Core::Constants::G_EDIT_OTHER);
|
|
|
|
|
rc->setData(toolNumber);
|
|
|
|
|
ag->addAction(rc);
|
|
|
|
|
return rc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create a tool action
|
2014-09-03 16:03:35 +02:00
|
|
|
Command *FormEditorData::addToolAction(QAction *a, const Context &context, Id id,
|
|
|
|
|
ActionContainer *c1, const QString &keySequence,
|
2015-02-03 23:55:24 +02:00
|
|
|
Id groupId)
|
2010-01-08 13:10:04 +01:00
|
|
|
{
|
2013-08-30 16:38:57 +02:00
|
|
|
Command *command = ActionManager::registerAction(a, id, context);
|
2010-01-08 13:10:04 +01:00
|
|
|
if (!keySequence.isEmpty())
|
|
|
|
|
command->setDefaultKeySequence(QKeySequence(keySequence));
|
2010-04-20 16:46:35 +02:00
|
|
|
if (!a->isSeparator())
|
|
|
|
|
bindShortcut(command, a);
|
2014-03-06 17:50:28 +01:00
|
|
|
c1->addAction(command, groupId);
|
2010-04-20 16:46:35 +02:00
|
|
|
return command;
|
2010-01-08 13:10:04 +01:00
|
|
|
}
|
|
|
|
|
|
2015-02-03 23:55:24 +02:00
|
|
|
IEditor *FormEditorData::createEditor()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-03-09 15:48:01 +01:00
|
|
|
if (Designer::Constants::Internal::debug)
|
|
|
|
|
qDebug() << "FormEditorW::createEditor";
|
|
|
|
|
// Create and associate form and text editor.
|
2008-12-02 12:01:29 +01:00
|
|
|
m_fwm->closeAllPreviews();
|
2019-07-31 17:21:41 +02:00
|
|
|
QDesignerFormWindowInterface *form = m_fwm->createFormWindow(nullptr);
|
|
|
|
|
QTC_ASSERT(form, return nullptr);
|
2020-08-14 11:29:34 +02:00
|
|
|
form->setPalette(Theme::initialPalette());
|
2014-09-03 16:03:35 +02:00
|
|
|
QObject::connect(form, &QDesignerFormWindowInterface::toolChanged, [this] (int i) { toolChanged(i); });
|
2014-09-03 12:38:51 +02:00
|
|
|
|
2019-11-25 14:23:33 +01:00
|
|
|
auto widgetHost = new SharedTools::WidgetHost( /* parent */ nullptr, form);
|
2014-09-03 16:03:35 +02:00
|
|
|
FormWindowEditor *formWindowEditor = m_xmlEditorFactory->create(form);
|
2010-03-10 10:50:11 +01:00
|
|
|
|
2014-09-03 16:03:35 +02:00
|
|
|
m_editorWidget->add(widgetHost, formWindowEditor);
|
|
|
|
|
m_toolBar->addEditor(formWindowEditor);
|
2010-03-10 10:50:11 +01:00
|
|
|
|
2014-09-03 16:03:35 +02:00
|
|
|
if (formWindowEditor) {
|
2020-06-17 12:23:44 +02:00
|
|
|
Utils::InfoBarEntry info(Id(Constants::INFO_READ_ONLY),
|
|
|
|
|
tr("This file can only be edited in <b>Design</b> mode."));
|
2022-01-17 16:47:31 +01:00
|
|
|
info.addCustomButton(tr("Switch Mode"), []() { ModeManager::activateMode(Core::Constants::MODE_DESIGN); });
|
2014-09-03 16:03:35 +02:00
|
|
|
formWindowEditor->document()->infoBar()->addInfo(info);
|
|
|
|
|
}
|
|
|
|
|
return formWindowEditor;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2014-09-03 16:03:35 +02:00
|
|
|
QDesignerFormEditorInterface *FormEditorW::designerEditor()
|
2010-01-08 13:10:04 +01:00
|
|
|
{
|
2014-09-03 16:03:35 +02:00
|
|
|
ensureInitStage(FullyInitialized);
|
|
|
|
|
return d->m_formeditor;
|
2010-01-08 13:10:04 +01:00
|
|
|
}
|
|
|
|
|
|
2014-09-03 16:03:35 +02:00
|
|
|
QWidget * const *FormEditorW::designerSubWindows()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2014-09-03 16:03:35 +02:00
|
|
|
ensureInitStage(SubwindowsInitialized);
|
|
|
|
|
return d->m_designerSubWindows;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2014-09-03 16:03:35 +02:00
|
|
|
SharedTools::WidgetHost *FormEditorW::activeWidgetHost()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2014-09-03 16:03:35 +02:00
|
|
|
ensureInitStage(FullyInitialized);
|
|
|
|
|
if (d->m_editorWidget)
|
|
|
|
|
return d->m_editorWidget->activeEditor().widgetHost;
|
2019-07-31 17:21:41 +02:00
|
|
|
return nullptr;
|
2014-09-03 16:03:35 +02:00
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2014-09-03 16:03:35 +02:00
|
|
|
FormWindowEditor *FormEditorW::activeEditor()
|
|
|
|
|
{
|
|
|
|
|
ensureInitStage(FullyInitialized);
|
|
|
|
|
if (d->m_editorWidget)
|
|
|
|
|
return d->m_editorWidget->activeEditor().formWindowEditor;
|
2019-07-31 17:21:41 +02:00
|
|
|
return nullptr;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2016-07-19 22:53:08 +03:00
|
|
|
void FormEditorData::updateShortcut(Command *command)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2016-07-19 22:53:08 +03:00
|
|
|
if (!command)
|
2014-09-03 16:03:35 +02:00
|
|
|
return;
|
2016-07-19 22:53:08 +03:00
|
|
|
if (QAction *a = m_commandToDesignerAction.value(command))
|
|
|
|
|
a->setShortcut(command->action()->shortcut());
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2014-09-03 16:03:35 +02:00
|
|
|
void FormEditorData::activateEditMode(int id)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
if (const int count = m_fwm->formWindowCount())
|
|
|
|
|
for (int i = 0; i < count; i++)
|
|
|
|
|
m_fwm->formWindow(i)->setCurrentTool(id);
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-03 16:03:35 +02:00
|
|
|
void FormEditorData::toolChanged(int t)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
typedef QList<QAction *> ActionList;
|
|
|
|
|
if (const QAction *currentAction = m_actionGroupEditMode->checkedAction())
|
|
|
|
|
if (currentAction->data().toInt() == t)
|
|
|
|
|
return;
|
|
|
|
|
const ActionList actions = m_actionGroupEditMode->actions();
|
|
|
|
|
const ActionList::const_iterator cend = actions.constEnd();
|
|
|
|
|
for (ActionList::const_iterator it = actions.constBegin(); it != cend; ++it)
|
|
|
|
|
if ( (*it)->data().toInt() == t) {
|
|
|
|
|
(*it)->setChecked(true);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-03 16:03:35 +02:00
|
|
|
void FormEditorData::print()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
// Printing code courtesy of designer_actions.cpp
|
|
|
|
|
QDesignerFormWindowInterface *fw = m_fwm->activeFormWindow();
|
|
|
|
|
if (!fw)
|
|
|
|
|
return;
|
|
|
|
|
|
2013-08-30 16:38:57 +02:00
|
|
|
QPrinter *printer = ICore::printer();
|
2012-01-24 15:36:40 +01:00
|
|
|
const bool oldFullPage = printer->fullPage();
|
2020-09-28 17:28:05 +02:00
|
|
|
const QPageLayout::Orientation oldOrientation = printer->pageLayout().orientation();
|
2012-01-24 15:36:40 +01:00
|
|
|
printer->setFullPage(false);
|
2008-12-02 12:01:29 +01:00
|
|
|
do {
|
|
|
|
|
// Grab the image to be able to a suggest suitable orientation
|
|
|
|
|
QString errorMessage;
|
2011-05-19 11:30:38 +02:00
|
|
|
const QPixmap pixmap = m_fwm->createPreviewPixmap();
|
2008-12-02 12:01:29 +01:00
|
|
|
if (pixmap.isNull()) {
|
2009-05-11 17:57:52 +02:00
|
|
|
critical(tr("The image could not be created: %1").arg(errorMessage));
|
2008-12-02 12:01:29 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QSizeF pixmapSize = pixmap.size();
|
2020-09-28 17:28:05 +02:00
|
|
|
printer->setPageOrientation(pixmapSize.width() > pixmapSize.height() ? QPageLayout::Landscape
|
|
|
|
|
: QPageLayout::Portrait);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
// Printer parameters
|
2012-01-24 15:36:40 +01:00
|
|
|
QPrintDialog dialog(printer, fw);
|
2008-12-02 12:01:29 +01:00
|
|
|
if (!dialog.exec())
|
|
|
|
|
break;
|
|
|
|
|
|
2013-08-30 16:38:57 +02:00
|
|
|
QWidget *mainWindow = ICore::mainWindow();
|
2012-01-24 15:36:40 +01:00
|
|
|
const QCursor oldCursor = mainWindow->cursor();
|
|
|
|
|
mainWindow->setCursor(Qt::WaitCursor);
|
2008-12-02 12:01:29 +01:00
|
|
|
// Estimate of required scaling to make form look the same on screen and printer.
|
2012-01-24 15:36:40 +01:00
|
|
|
const double suggestedScaling = static_cast<double>(printer->physicalDpiX()) / static_cast<double>(fw->physicalDpiX());
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-01-24 15:36:40 +01:00
|
|
|
QPainter painter(printer);
|
2008-12-02 12:01:29 +01:00
|
|
|
painter.setRenderHint(QPainter::SmoothPixmapTransform);
|
|
|
|
|
|
|
|
|
|
// Clamp to page
|
|
|
|
|
const QRectF page = painter.viewport();
|
|
|
|
|
const double maxScaling = qMin(page.size().width() / pixmapSize.width(), page.size().height() / pixmapSize.height());
|
|
|
|
|
const double scaling = qMin(suggestedScaling, maxScaling);
|
|
|
|
|
|
2011-11-09 09:39:58 +01:00
|
|
|
const double xOffset = page.left() + qMax(0.0, (page.size().width() - scaling * pixmapSize.width()) / 2.0);
|
|
|
|
|
const double yOffset = page.top() + qMax(0.0, (page.size().height() - scaling * pixmapSize.height()) / 2.0);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
// Draw.
|
|
|
|
|
painter.translate(xOffset, yOffset);
|
|
|
|
|
painter.scale(scaling, scaling);
|
|
|
|
|
painter.drawPixmap(0, 0, pixmap);
|
2012-01-24 15:36:40 +01:00
|
|
|
mainWindow->setCursor(oldCursor);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
} while (false);
|
2012-01-24 15:36:40 +01:00
|
|
|
printer->setFullPage(oldFullPage);
|
2020-09-28 17:28:05 +02:00
|
|
|
printer->setPageOrientation(oldOrientation);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2010-02-26 11:08:17 +01:00
|
|
|
|
2010-03-09 10:26:20 +01:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Designer
|