forked from qt-creator/qt-creator
QmlDesigner: Larger canvas size
Many qml documents have items outside of the root item area. The scene rectangle is now much bigger so you can scroll the items around.
This commit is contained in:
@@ -46,6 +46,7 @@ FormEditorGraphicsView::FormEditorGraphicsView(QWidget *parent) :
|
|||||||
{
|
{
|
||||||
setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
|
setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
|
||||||
setResizeAnchor(QGraphicsView::AnchorViewCenter);
|
setResizeAnchor(QGraphicsView::AnchorViewCenter);
|
||||||
|
setAlignment(Qt::AlignCenter);
|
||||||
setCacheMode(QGraphicsView::CacheNone);
|
setCacheMode(QGraphicsView::CacheNone);
|
||||||
// setCacheMode(QGraphicsView::CacheBackground);
|
// setCacheMode(QGraphicsView::CacheBackground);
|
||||||
setViewportUpdateMode(QGraphicsView::SmartViewportUpdate);
|
setViewportUpdateMode(QGraphicsView::SmartViewportUpdate);
|
||||||
|
@@ -36,6 +36,10 @@
|
|||||||
#include "formeditorwidget.h"
|
#include "formeditorwidget.h"
|
||||||
#include "formeditoritem.h"
|
#include "formeditoritem.h"
|
||||||
#include "movemanipulator.h"
|
#include "movemanipulator.h"
|
||||||
|
#include "qmldesignerplugin.h"
|
||||||
|
#include "designersettings.h"
|
||||||
|
|
||||||
|
|
||||||
#include <metainfo.h>
|
#include <metainfo.h>
|
||||||
#include <QGraphicsSceneDragDropEvent>
|
#include <QGraphicsSceneDragDropEvent>
|
||||||
|
|
||||||
@@ -60,18 +64,13 @@ namespace QmlDesigner {
|
|||||||
FormEditorScene::FormEditorScene(FormEditorWidget *view, FormEditorView *editorView)
|
FormEditorScene::FormEditorScene(FormEditorWidget *view, FormEditorView *editorView)
|
||||||
: QGraphicsScene(),
|
: QGraphicsScene(),
|
||||||
m_editorView(editorView),
|
m_editorView(editorView),
|
||||||
m_formLayerItem(new LayerItem(this)),
|
|
||||||
m_manipulatorLayerItem(new LayerItem(this)),
|
|
||||||
m_paintMode(NormalMode),
|
m_paintMode(NormalMode),
|
||||||
m_showBoundingRects(true)
|
m_showBoundingRects(true)
|
||||||
{
|
{
|
||||||
m_manipulatorLayerItem->setZValue(1.0);
|
setupScene();
|
||||||
m_formLayerItem->setZValue(0.0);
|
|
||||||
m_formLayerItem->setFlag(QGraphicsItem::ItemClipsChildrenToShape, false);
|
|
||||||
view->setScene(this);
|
view->setScene(this);
|
||||||
setItemIndexMethod(QGraphicsScene::NoIndex);
|
setItemIndexMethod(QGraphicsScene::NoIndex);
|
||||||
|
setSceneRect(-canvasWidth()/2., -canvasHeight()/2., canvasWidth(), canvasHeight());
|
||||||
// setItemIndexMethod(QGraphicsScene::NoIndex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FormEditorScene::~FormEditorScene()
|
FormEditorScene::~FormEditorScene()
|
||||||
@@ -81,12 +80,40 @@ FormEditorScene::~FormEditorScene()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void FormEditorScene::setupScene()
|
||||||
|
{
|
||||||
|
m_formLayerItem = new LayerItem(this);
|
||||||
|
qDebug() << "formLayerItem" << m_formLayerItem.data();
|
||||||
|
m_manipulatorLayerItem = new LayerItem(this);
|
||||||
|
qDebug() << "manipulatorLayerItem" << m_manipulatorLayerItem.data();
|
||||||
|
m_manipulatorLayerItem->setZValue(1.0);
|
||||||
|
m_formLayerItem->setZValue(0.0);
|
||||||
|
m_formLayerItem->setFlag(QGraphicsItem::ItemClipsChildrenToShape, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void FormEditorScene::resetScene()
|
||||||
|
{
|
||||||
|
foreach(QGraphicsItem *item, m_manipulatorLayerItem->childItems())
|
||||||
|
removeItem(item);
|
||||||
|
}
|
||||||
|
|
||||||
FormEditorItem* FormEditorScene::itemForQmlItemNode(const QmlItemNode &qmlItemNode) const
|
FormEditorItem* FormEditorScene::itemForQmlItemNode(const QmlItemNode &qmlItemNode) const
|
||||||
{
|
{
|
||||||
Q_ASSERT(hasItemForQmlItemNode(qmlItemNode));
|
Q_ASSERT(hasItemForQmlItemNode(qmlItemNode));
|
||||||
return m_qmlItemNodeItemHash.value(qmlItemNode);
|
return m_qmlItemNodeItemHash.value(qmlItemNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double FormEditorScene::canvasWidth() const
|
||||||
|
{
|
||||||
|
DesignerSettings settings = Internal::BauhausPlugin::pluginInstance()->settings();
|
||||||
|
return settings.canvasWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
double FormEditorScene::canvasHeight() const
|
||||||
|
{
|
||||||
|
DesignerSettings settings = Internal::BauhausPlugin::pluginInstance()->settings();
|
||||||
|
return settings.canvasHeight;
|
||||||
|
}
|
||||||
|
|
||||||
QList<FormEditorItem*> FormEditorScene::itemsForQmlItemNodes(const QList<QmlItemNode> &nodeList) const
|
QList<FormEditorItem*> FormEditorScene::itemsForQmlItemNodes(const QList<QmlItemNode> &nodeList) const
|
||||||
{
|
{
|
||||||
|
@@ -76,6 +76,12 @@ public:
|
|||||||
|
|
||||||
void updateAllFormEditorItems();
|
void updateAllFormEditorItems();
|
||||||
|
|
||||||
|
void setupScene();
|
||||||
|
void resetScene();
|
||||||
|
|
||||||
|
double canvasWidth() const;
|
||||||
|
double canvasHeight() const;
|
||||||
|
|
||||||
bool hasItemForQmlItemNode(const QmlItemNode &qmlItemNode) const;
|
bool hasItemForQmlItemNode(const QmlItemNode &qmlItemNode) const;
|
||||||
|
|
||||||
void synchronizeTransformation(const QmlItemNode &qmlItemNode);
|
void synchronizeTransformation(const QmlItemNode &qmlItemNode);
|
||||||
|
@@ -147,6 +147,8 @@ void FormEditorView::modelAboutToBeDetached(Model *model)
|
|||||||
m_dragTool->clear();
|
m_dragTool->clear();
|
||||||
m_scene->clearFormEditorItems();
|
m_scene->clearFormEditorItems();
|
||||||
m_formEditorWidget->updateActions();
|
m_formEditorWidget->updateActions();
|
||||||
|
m_formEditorWidget->resetView();
|
||||||
|
scene()->resetScene();
|
||||||
|
|
||||||
QmlModelView::modelAboutToBeDetached(model);
|
QmlModelView::modelAboutToBeDetached(model);
|
||||||
}
|
}
|
||||||
@@ -451,6 +453,8 @@ void FormEditorView::instancesCompleted(const QVector<ModelNode> &completedNodeL
|
|||||||
if (qmlItemNode.isValid() && scene()->hasItemForQmlItemNode(qmlItemNode)) {
|
if (qmlItemNode.isValid() && scene()->hasItemForQmlItemNode(qmlItemNode)) {
|
||||||
scene()->synchronizeParent(qmlItemNode);
|
scene()->synchronizeParent(qmlItemNode);
|
||||||
itemNodeList.append(scene()->itemForQmlItemNode(qmlItemNode));
|
itemNodeList.append(scene()->itemForQmlItemNode(qmlItemNode));
|
||||||
|
if (qmlItemNode.isRootModelNode())
|
||||||
|
m_formEditorWidget->centerScene();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
currentTool()->instancesCompleted(itemNodeList);
|
currentTool()->instancesCompleted(itemNodeList);
|
||||||
|
@@ -244,6 +244,17 @@ void FormEditorWidget::updateActions()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void FormEditorWidget::resetView()
|
||||||
|
{
|
||||||
|
setRootItemRect(QRectF());
|
||||||
|
}
|
||||||
|
|
||||||
|
void FormEditorWidget::centerScene()
|
||||||
|
{
|
||||||
|
m_graphicsView->centerOn(rootItemRect().center());
|
||||||
|
}
|
||||||
|
|
||||||
ZoomAction *FormEditorWidget::zoomAction() const
|
ZoomAction *FormEditorWidget::zoomAction() const
|
||||||
{
|
{
|
||||||
return m_zoomAction.data();
|
return m_zoomAction.data();
|
||||||
|
@@ -80,6 +80,10 @@ public:
|
|||||||
|
|
||||||
void updateActions();
|
void updateActions();
|
||||||
|
|
||||||
|
void resetView();
|
||||||
|
void centerScene();
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void enterEvent(QEvent *event);
|
void enterEvent(QEvent *event);
|
||||||
void wheelEvent(QWheelEvent *event);
|
void wheelEvent(QWheelEvent *event);
|
||||||
|
@@ -41,7 +41,9 @@ using namespace QmlDesigner;
|
|||||||
DesignerSettings::DesignerSettings()
|
DesignerSettings::DesignerSettings()
|
||||||
: openDesignMode(QmlDesigner::Constants::QML_OPENDESIGNMODE_DEFAULT),
|
: openDesignMode(QmlDesigner::Constants::QML_OPENDESIGNMODE_DEFAULT),
|
||||||
itemSpacing(0),
|
itemSpacing(0),
|
||||||
snapMargin(0)
|
snapMargin(0),
|
||||||
|
canvasWidth(10000),
|
||||||
|
canvasHeight(10000)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void DesignerSettings::fromSettings(QSettings *settings)
|
void DesignerSettings::fromSettings(QSettings *settings)
|
||||||
@@ -55,6 +57,8 @@ void DesignerSettings::fromSettings(QSettings *settings)
|
|||||||
QLatin1String(QmlDesigner::Constants::QML_ITEMSPACING_KEY), QVariant(0)).toInt();
|
QLatin1String(QmlDesigner::Constants::QML_ITEMSPACING_KEY), QVariant(0)).toInt();
|
||||||
snapMargin = settings->value(
|
snapMargin = settings->value(
|
||||||
QLatin1String(QmlDesigner::Constants::QML_SNAPMARGIN_KEY), QVariant(0)).toInt();
|
QLatin1String(QmlDesigner::Constants::QML_SNAPMARGIN_KEY), QVariant(0)).toInt();
|
||||||
|
canvasWidth = settings->value(QLatin1String(QmlDesigner::Constants::QML_CANVASWIDTH_KEY), QVariant(10000)).toInt();
|
||||||
|
canvasHeight = settings->value(QLatin1String(QmlDesigner::Constants::QML_CANVASHEIGHT_KEY), QVariant(10000)).toInt();
|
||||||
settings->endGroup();
|
settings->endGroup();
|
||||||
settings->endGroup();
|
settings->endGroup();
|
||||||
}
|
}
|
||||||
@@ -66,7 +70,8 @@ void DesignerSettings::toSettings(QSettings *settings) const
|
|||||||
settings->setValue(QLatin1String(QmlDesigner::Constants::QML_OPENDESIGNMODE_SETTINGS_KEY), openDesignMode);
|
settings->setValue(QLatin1String(QmlDesigner::Constants::QML_OPENDESIGNMODE_SETTINGS_KEY), openDesignMode);
|
||||||
settings->setValue(QLatin1String(QmlDesigner::Constants::QML_ITEMSPACING_KEY), itemSpacing);
|
settings->setValue(QLatin1String(QmlDesigner::Constants::QML_ITEMSPACING_KEY), itemSpacing);
|
||||||
settings->setValue(QLatin1String(QmlDesigner::Constants::QML_SNAPMARGIN_KEY), snapMargin);
|
settings->setValue(QLatin1String(QmlDesigner::Constants::QML_SNAPMARGIN_KEY), snapMargin);
|
||||||
|
settings->setValue(QLatin1String(QmlDesigner::Constants::QML_CANVASWIDTH_KEY), canvasWidth);
|
||||||
|
settings->setValue(QLatin1String(QmlDesigner::Constants::QML_CANVASHEIGHT_KEY), canvasHeight);
|
||||||
settings->endGroup();
|
settings->endGroup();
|
||||||
settings->endGroup();
|
settings->endGroup();
|
||||||
}
|
}
|
||||||
@@ -75,5 +80,6 @@ bool DesignerSettings::equals(const DesignerSettings &other) const
|
|||||||
{
|
{
|
||||||
return openDesignMode == other.openDesignMode
|
return openDesignMode == other.openDesignMode
|
||||||
&& snapMargin == other.snapMargin
|
&& snapMargin == other.snapMargin
|
||||||
&& itemSpacing == other.itemSpacing;
|
&& canvasWidth == other.canvasWidth
|
||||||
|
&& canvasHeight == other.canvasHeight;
|
||||||
}
|
}
|
||||||
|
@@ -54,6 +54,8 @@ public:
|
|||||||
bool openDesignMode;
|
bool openDesignMode;
|
||||||
int itemSpacing;
|
int itemSpacing;
|
||||||
int snapMargin;
|
int snapMargin;
|
||||||
|
int canvasWidth;
|
||||||
|
int canvasHeight;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline bool operator==(const DesignerSettings &s1, const DesignerSettings &s2)
|
inline bool operator==(const DesignerSettings &s1, const DesignerSettings &s2)
|
||||||
|
@@ -66,6 +66,8 @@ const char * const QML_DESIGNER_SETTINGS_GROUP = "Designer";
|
|||||||
const char * const QML_OPENDESIGNMODE_SETTINGS_KEY = "OpenDesignMode";
|
const char * const QML_OPENDESIGNMODE_SETTINGS_KEY = "OpenDesignMode";
|
||||||
const char * const QML_ITEMSPACING_KEY = "ItemSpacing";
|
const char * const QML_ITEMSPACING_KEY = "ItemSpacing";
|
||||||
const char * const QML_SNAPMARGIN_KEY = "SnapMargin";
|
const char * const QML_SNAPMARGIN_KEY = "SnapMargin";
|
||||||
|
const char * const QML_CANVASWIDTH_KEY = "CanvasWidth";
|
||||||
|
const char * const QML_CANVASHEIGHT_KEY = "CanvasHeight";
|
||||||
const char * const QML_CONTEXTPANE_KEY = "ContextPaneEnabled";
|
const char * const QML_CONTEXTPANE_KEY = "ContextPaneEnabled";
|
||||||
const char * const QML_CONTEXTPANEPIN_KEY = "ContextPanePinned";
|
const char * const QML_CONTEXTPANEPIN_KEY = "ContextPanePinned";
|
||||||
enum { QML_OPENDESIGNMODE_DEFAULT = 0 }; // 0 for text mode, 1 for design mode
|
enum { QML_OPENDESIGNMODE_DEFAULT = 0 }; // 0 for text mode, 1 for design mode
|
||||||
|
@@ -6,8 +6,8 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>296</width>
|
<width>275</width>
|
||||||
<height>132</height>
|
<height>275</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
@@ -21,7 +21,7 @@
|
|||||||
</property>
|
</property>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
<item>
|
<item>
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
<layout class="QFormLayout" name="formLayout_2">
|
||||||
<item row="0" column="0">
|
<item row="0" column="0">
|
||||||
<widget class="QLabel" name="snapMarginLabel">
|
<widget class="QLabel" name="snapMarginLabel">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@@ -64,18 +64,70 @@
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QGroupBox" name="groupBox">
|
||||||
|
<property name="title">
|
||||||
|
<string>Canvas</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
<item>
|
<item>
|
||||||
<spacer name="horizontalSpacer">
|
<layout class="QFormLayout" name="formLayout">
|
||||||
<property name="orientation">
|
<item row="0" column="0">
|
||||||
<enum>Qt::Horizontal</enum>
|
<widget class="QLabel" name="canvasWidth">
|
||||||
</property>
|
<property name="text">
|
||||||
<property name="sizeHint" stdset="0">
|
<string>Width</string>
|
||||||
<size>
|
</property>
|
||||||
<width>40</width>
|
</widget>
|
||||||
<height>20</height>
|
</item>
|
||||||
</size>
|
<item row="0" column="1">
|
||||||
</property>
|
<widget class="QSpinBox" name="spinBox">
|
||||||
</spacer>
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="maximum">
|
||||||
|
<number>100000</number>
|
||||||
|
</property>
|
||||||
|
<property name="singleStep">
|
||||||
|
<number>100</number>
|
||||||
|
</property>
|
||||||
|
<property name="value">
|
||||||
|
<number>10000</number>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0">
|
||||||
|
<widget class="QLabel" name="canvasHeight">
|
||||||
|
<property name="text">
|
||||||
|
<string>Height</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="1">
|
||||||
|
<widget class="QSpinBox" name="spinBox_2">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="maximum">
|
||||||
|
<number>100000</number>
|
||||||
|
</property>
|
||||||
|
<property name="singleStep">
|
||||||
|
<number>100</number>
|
||||||
|
</property>
|
||||||
|
<property name="value">
|
||||||
|
<number>10000</number>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
@@ -88,7 +140,7 @@
|
|||||||
<property name="sizeHint" stdset="0">
|
<property name="sizeHint" stdset="0">
|
||||||
<size>
|
<size>
|
||||||
<width>20</width>
|
<width>20</width>
|
||||||
<height>207</height>
|
<height>40</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
|
Reference in New Issue
Block a user