Commit e293e467 authored by Marco Bubke's avatar Marco Bubke

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.
parent c876ad1c
......@@ -46,6 +46,7 @@ FormEditorGraphicsView::FormEditorGraphicsView(QWidget *parent) :
{
setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
setResizeAnchor(QGraphicsView::AnchorViewCenter);
setAlignment(Qt::AlignCenter);
setCacheMode(QGraphicsView::CacheNone);
// setCacheMode(QGraphicsView::CacheBackground);
setViewportUpdateMode(QGraphicsView::SmartViewportUpdate);
......
......@@ -36,6 +36,10 @@
#include "formeditorwidget.h"
#include "formeditoritem.h"
#include "movemanipulator.h"
#include "qmldesignerplugin.h"
#include "designersettings.h"
#include <metainfo.h>
#include <QGraphicsSceneDragDropEvent>
......@@ -60,18 +64,13 @@ namespace QmlDesigner {
FormEditorScene::FormEditorScene(FormEditorWidget *view, FormEditorView *editorView)
: QGraphicsScene(),
m_editorView(editorView),
m_formLayerItem(new LayerItem(this)),
m_manipulatorLayerItem(new LayerItem(this)),
m_paintMode(NormalMode),
m_showBoundingRects(true)
{
m_manipulatorLayerItem->setZValue(1.0);
m_formLayerItem->setZValue(0.0);
m_formLayerItem->setFlag(QGraphicsItem::ItemClipsChildrenToShape, false);
setupScene();
view->setScene(this);
setItemIndexMethod(QGraphicsScene::NoIndex);
// setItemIndexMethod(QGraphicsScene::NoIndex);
setSceneRect(-canvasWidth()/2., -canvasHeight()/2., canvasWidth(), canvasHeight());
}
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
{
Q_ASSERT(hasItemForQmlItemNode(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
{
......
......@@ -76,6 +76,12 @@ public:
void updateAllFormEditorItems();
void setupScene();
void resetScene();
double canvasWidth() const;
double canvasHeight() const;
bool hasItemForQmlItemNode(const QmlItemNode &qmlItemNode) const;
void synchronizeTransformation(const QmlItemNode &qmlItemNode);
......
......@@ -147,6 +147,8 @@ void FormEditorView::modelAboutToBeDetached(Model *model)
m_dragTool->clear();
m_scene->clearFormEditorItems();
m_formEditorWidget->updateActions();
m_formEditorWidget->resetView();
scene()->resetScene();
QmlModelView::modelAboutToBeDetached(model);
}
......@@ -451,6 +453,8 @@ void FormEditorView::instancesCompleted(const QVector<ModelNode> &completedNodeL
if (qmlItemNode.isValid() && scene()->hasItemForQmlItemNode(qmlItemNode)) {
scene()->synchronizeParent(qmlItemNode);
itemNodeList.append(scene()->itemForQmlItemNode(qmlItemNode));
if (qmlItemNode.isRootModelNode())
m_formEditorWidget->centerScene();
}
}
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
{
return m_zoomAction.data();
......
......@@ -80,6 +80,10 @@ public:
void updateActions();
void resetView();
void centerScene();
protected:
void enterEvent(QEvent *event);
void wheelEvent(QWheelEvent *event);
......
......@@ -41,7 +41,9 @@ using namespace QmlDesigner;
DesignerSettings::DesignerSettings()
: openDesignMode(QmlDesigner::Constants::QML_OPENDESIGNMODE_DEFAULT),
itemSpacing(0),
snapMargin(0)
snapMargin(0),
canvasWidth(10000),
canvasHeight(10000)
{}
void DesignerSettings::fromSettings(QSettings *settings)
......@@ -55,6 +57,8 @@ void DesignerSettings::fromSettings(QSettings *settings)
QLatin1String(QmlDesigner::Constants::QML_ITEMSPACING_KEY), QVariant(0)).toInt();
snapMargin = settings->value(
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();
}
......@@ -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_ITEMSPACING_KEY), itemSpacing);
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();
}
......@@ -75,5 +80,6 @@ bool DesignerSettings::equals(const DesignerSettings &other) const
{
return openDesignMode == other.openDesignMode
&& snapMargin == other.snapMargin
&& itemSpacing == other.itemSpacing;
&& canvasWidth == other.canvasWidth
&& canvasHeight == other.canvasHeight;
}
......@@ -54,6 +54,8 @@ public:
bool openDesignMode;
int itemSpacing;
int snapMargin;
int canvasWidth;
int canvasHeight;
};
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_ITEMSPACING_KEY = "ItemSpacing";
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_CONTEXTPANEPIN_KEY = "ContextPanePinned";
enum { QML_OPENDESIGNMODE_DEFAULT = 0 }; // 0 for text mode, 1 for design mode
......
......@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>296</width>
<height>132</height>
<width>275</width>
<height>275</height>
</rect>
</property>
<property name="windowTitle">
......@@ -21,7 +21,7 @@
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<layout class="QGridLayout" name="gridLayout">
<layout class="QFormLayout" name="formLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="snapMarginLabel">
<property name="text">
......@@ -64,18 +64,70 @@
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Canvas</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="canvasWidth">
<property name="text">
<string>Width</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="spinBox">
<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>
</layout>
</widget>
......@@ -88,7 +140,7 @@
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>207</height>
<height>40</height>
</size>
</property>
</spacer>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment