Commit b008e48c authored by Marco Bubke's avatar Marco Bubke

QmlDesigner: Change the size of the root item for preview

parent 74b8d80f
......@@ -40,7 +40,8 @@ SOURCES += formeditoritem.cpp \
toolbox.cpp \
zoomaction.cpp \
formeditorgraphicsview.cpp \
numberseriesaction.cpp
numberseriesaction.cpp \
lineeditaction.cpp
HEADERS += formeditorscene.h \
formeditorwidget.h \
formeditoritem.h \
......@@ -79,5 +80,6 @@ HEADERS += formeditorscene.h \
toolbox.h \
zoomaction.h \
formeditorgraphicsview.h \
numberseriesaction.h
numberseriesaction.h \
lineeditaction.h
RESOURCES += formeditor.qrc
......@@ -48,6 +48,7 @@
#include <formeditorgraphicsview.h>
#include <formeditorscene.h>
#include <formeditorview.h>
#include <lineeditaction.h>
namespace QmlDesigner {
......@@ -133,6 +134,17 @@ FormEditorWidget::FormEditorWidget(FormEditorView *view)
addAction(m_selectOnlyContentItemsAction.data());
upperActions.append(m_selectOnlyContentItemsAction.data());
m_rootWidthAction = new LineEditAction("width", this);
connect(m_rootWidthAction.data(), SIGNAL(textChanged(QString)), this, SLOT(changeRootItemWidth(QString)));
addAction(m_rootWidthAction.data());
upperActions.append(m_rootWidthAction.data());
m_rootHeightAction = new LineEditAction("height", this);
connect(m_rootHeightAction.data(), SIGNAL(textChanged(QString)), this, SLOT(changeRootItemHeight(QString)));
addAction(m_rootHeightAction.data());
upperActions.append(m_rootHeightAction.data());
m_snappingAndAnchoringAction = layoutActionGroup->addAction("Toogle Snapping And Anchoring (Press Key R)");
m_toolBox = new ToolBox(this);
fillLayout->addWidget(m_toolBox.data());
......@@ -169,6 +181,28 @@ void FormEditorWidget::changeTransformTool(bool checked)
m_formEditorView->changeToTransformTools();
}
void FormEditorWidget::changeRootItemWidth(const QString &widthText)
{
bool canConvert;
int width = widthText.toInt(&canConvert);
if (canConvert) {
m_formEditorView->rootModelNode().setAuxiliaryData("width", width);
} else {
m_formEditorView->rootModelNode().setAuxiliaryData("width", QVariant());
}
}
void FormEditorWidget::changeRootItemHeight(const QString &heighText)
{
bool canConvert;
int height = heighText.toInt(&canConvert);
if (canConvert) {
m_formEditorView->rootModelNode().setAuxiliaryData("height", height);
} else {
m_formEditorView->rootModelNode().setAuxiliaryData("height", QVariant());
}
}
void FormEditorWidget::changeAnchorTool(bool checked)
{
if (checked && m_formEditorView->currentState().isBaseState())
......
......@@ -43,6 +43,7 @@ QT_END_NAMESPACE
namespace QmlDesigner {
class ZoomAction;
class LineEditAction;
class FormEditorView;
class FormEditorScene;
class FormEditorGraphicsView;
......@@ -86,6 +87,8 @@ private slots:
void changeTransformTool(bool checked);
void changeAnchorTool(bool checked);
void setZoomLevel(double zoomLevel);
void changeRootItemWidth(const QString &widthText);
void changeRootItemHeight(const QString &heightText);
private:
QWeakPointer<FormEditorView> m_formEditorView;
......@@ -100,6 +103,8 @@ private:
QWeakPointer<QAction> m_noSnappingAction;
QWeakPointer<QAction> m_showBoundingRectAction;
QWeakPointer<QAction> m_selectOnlyContentItemsAction;
QWeakPointer<LineEditAction> m_rootWidthAction;
QWeakPointer<LineEditAction> m_rootHeightAction;
};
......
#include "lineeditaction.h"
#include <QLineEdit>
#include <QIntValidator>
namespace QmlDesigner {
LineEditAction::LineEditAction(const QString &placeHolderText, QObject *parent) :
QWidgetAction(parent),
m_placeHolderText(placeHolderText)
{
}
QWidget *LineEditAction::createWidget(QWidget *parent)
{
QLineEdit *lineEdit = new QLineEdit(parent);
lineEdit->setPlaceholderText(m_placeHolderText);
lineEdit->setFixedWidth(80);
lineEdit->setValidator(new QIntValidator(0, 4096, this));
connect(lineEdit, SIGNAL(textEdited(QString)), this, SIGNAL(textChanged(QString)));
return lineEdit;
}
} // namespace QmlDesigner
#ifndef LINEEDITACTION_H
#define LINEEDITACTION_H
#include <QWidgetAction>
namespace QmlDesigner {
class LineEditAction : public QWidgetAction
{
Q_OBJECT
public:
explicit LineEditAction(const QString &placeHolderText, QObject *parent = 0);
protected:
QWidget *createWidget(QWidget *parent);
signals:
void textChanged(const QString &text);
private:
QString m_placeHolderText;
};
} // namespace QmlDesigner
#endif // LINEEDITACTION_H
......@@ -108,6 +108,7 @@ public:
void instancesRenderImageChanged(const QVector<ModelNode> &nodeList);
void instancesPreviewImageChanged(const QVector<ModelNode> &nodeList);
void instancesChildrenChanged(const QVector<ModelNode> &nodeList);
void auxiliaryDataChanged(const ModelNode &node, const QString &name, const QVariant &data);
void rewriterBeginTransaction();
void rewriterEndTransaction();
......
......@@ -468,6 +468,30 @@ void NodeInstanceView::instancesChildrenChanged(const QVector<ModelNode> &/*node
}
void NodeInstanceView::auxiliaryDataChanged(const ModelNode &node, const QString &name, const QVariant &data)
{
if (node.isRootNode() && (name == "width" || name == "height")) {
if (hasInstanceForNode(node)) {
NodeInstance instance = instanceForNode(node);
QVariant value = data;
if (value.isValid()) {
PropertyValueContainer container(instance.instanceId(), name, value, QString());
ChangeValuesCommand changeValueCommand(QVector<PropertyValueContainer>() << container);
nodeInstanceServer()->changePropertyValues(changeValueCommand);
} else {
if (node.hasVariantProperty(name)) {
PropertyValueContainer container(instance.instanceId(), name, node.variantProperty(name).value(), QString());
ChangeValuesCommand changeValueCommand(QVector<PropertyValueContainer>() << container);
nodeInstanceServer()->changePropertyValues(changeValueCommand);
} else if (node.hasBindingProperty(name)) {
PropertyBindingContainer container(instance.instanceId(), name, node.bindingProperty(name).expression(), QString());
ChangeBindingsCommand changeValueCommand(QVector<PropertyBindingContainer>() << container);
nodeInstanceServer()->changePropertyBindings(changeValueCommand);
}
}
}
}
}
void NodeInstanceView::rewriterBeginTransaction()
{
......
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