summaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
authorThomas Hartmann <Thomas.Hartmann@nokia.com>2010-04-13 12:01:53 +0200
committerThomas Hartmann <Thomas.Hartmann@nokia.com>2010-04-13 12:13:11 +0200
commit41b3a9a952b7fa28f01d498658788b74ce2ca791 (patch)
treeb763ae833b8ad295a19b44a6731b1e0ea5545b45 /src/plugins
parentd633ec2094c78e2b0782290c62add03f68bbd105 (diff)
downloadqt-creator-41b3a9a952b7fa28f01d498658788b74ce2ca791.tar.gz
QmlDesigner.propertyEditor: adding widget for transformOrigin
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/qmldesigner/components/propertyeditor/originwidget.cpp140
-rw-r--r--src/plugins/qmldesigner/components/propertyeditor/originwidget.h78
-rw-r--r--src/plugins/qmldesigner/components/propertyeditor/propertyeditor.pri2
3 files changed, 220 insertions, 0 deletions
diff --git a/src/plugins/qmldesigner/components/propertyeditor/originwidget.cpp b/src/plugins/qmldesigner/components/propertyeditor/originwidget.cpp
new file mode 100644
index 0000000000..d6994232e1
--- /dev/null
+++ b/src/plugins/qmldesigner/components/propertyeditor/originwidget.cpp
@@ -0,0 +1,140 @@
+/**************************************************************************
+**
+** 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 "originwidget.h"
+#include <QList>
+#include <QPainter>
+#include <QMouseEvent>
+#include <qdeclarative.h>
+
+static QList<QPoint> positions;
+static QStringList originsStringList;
+
+namespace QmlDesigner {
+
+OriginWidget::OriginWidget(QWidget *parent) : QWidget(parent), m_pressed(false), m_marked(false)
+{
+ if (positions.isEmpty())
+ positions << QPoint(0, 0) << QPoint(18, 0) << QPoint(36, 0)
+ << QPoint(0, 18) << QPoint(18, 18) << QPoint(36, 18)
+ << QPoint(0, 36) << QPoint(18, 36) << QPoint(36, 36);
+
+ if (originsStringList.isEmpty())
+ originsStringList << "TopLeft" << "Top"
+ << "TopRight" << "Left" << "Center" << "Right"
+ << "BottomLeft" << "Bottom" << "BottomRight";
+
+ m_originString = "Center";
+ resize(50, 50);
+ setMinimumHeight(50);
+ setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
+}
+
+void OriginWidget::setOrigin(const QString& newOrigin)
+{
+ if (!originsStringList.contains(newOrigin))
+ return;
+ if (newOrigin == m_originString)
+ return;
+
+ m_originString = newOrigin;
+ update();
+ emit originChanged();
+}
+
+void OriginWidget::registerDeclarativeType()
+{
+ qmlRegisterType<QmlDesigner::OriginWidget>("Bauhaus",1,0,"OriginWidget");
+
+}
+
+void OriginWidget::paintEvent(QPaintEvent *event)
+{
+ QWidget::paintEvent(event);
+
+ QPainter p(this);
+
+ foreach (const QPoint& position, positions)
+ p.fillRect(position.x(), position.y(), 14, 14, Qt::black);
+
+ int origin = originsStringList.indexOf(m_originString);
+
+ if (m_pressed)
+ p.fillRect(positions.at(m_index).x() + 4, positions.at(m_index).y() + 4, 6, 6, "#868686");
+
+ if (m_marked)
+ p.fillRect(positions.at(origin).x(), positions.at(origin).y(), 14, 14, "#9999ff");
+ else
+ p.fillRect(positions.at(origin).x(), positions.at(origin).y(), 14, 14, "#e6e6e6");
+ p.fillRect(positions.at(origin).x() + 2, positions.at(origin).y() + 2, 10, 10, "#666666");
+}
+
+void OriginWidget::mouseReleaseEvent(QMouseEvent *event)
+{
+ if (event->button() == Qt::LeftButton) {
+ m_pressed = false;
+ for (int i = 0; i < positions.size(); i++)
+ if (QRect(positions.at(i), QSize(14, 14)).contains(event->pos()))
+ setOrigin(originsStringList.at(i));
+ }
+ QWidget::mouseReleaseEvent(event);
+}
+
+void OriginWidget::mousePressEvent(QMouseEvent * event)
+{
+ if (event->button() == Qt::LeftButton) {
+ m_pressed = true;
+ for (int i = 0; i < positions.size(); i++)
+ if (QRect(positions.at(i), QSize(14, 14)).contains(event->pos())) {
+ m_index = i;
+ update();
+ }
+ }
+ QWidget::mousePressEvent(event);
+}
+
+static inline QString getToolTip(const QPoint &pos)
+{
+ for (int i = 0; i < positions.size(); i++)
+ if (QRect(positions.at(i), QSize(14, 14)).contains(pos))
+ return originsStringList.at(i);
+
+ return QString();
+}
+
+bool OriginWidget::event(QEvent *event)
+{
+ if (event->type() == QEvent::ToolTip)
+ setToolTip(getToolTip(static_cast<QHelpEvent*>(event)->pos()));
+
+ return QWidget::event(event);
+}
+
+} //QmlDesigner
+
diff --git a/src/plugins/qmldesigner/components/propertyeditor/originwidget.h b/src/plugins/qmldesigner/components/propertyeditor/originwidget.h
new file mode 100644
index 0000000000..14a9175f02
--- /dev/null
+++ b/src/plugins/qmldesigner/components/propertyeditor/originwidget.h
@@ -0,0 +1,78 @@
+/**************************************************************************
+**
+** 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 ORIGINWIDGET_H
+#define ORIGINWIDGET_H
+
+#include <QtGui/QWidget>
+
+namespace QmlDesigner {
+
+class OriginWidget: public QWidget {
+
+Q_OBJECT
+
+Q_PROPERTY(QString origin READ origin WRITE setOrigin NOTIFY originChanged)
+Q_PROPERTY(bool marked READ marked WRITE setMarked)
+
+public:
+ OriginWidget(QWidget *parent = 0);
+
+ QString origin() const
+ { return m_originString; }
+
+ void setOrigin(const QString& newOrigin);
+
+ bool marked() const
+ { return m_marked; }
+
+ void setMarked(bool newMarked)
+ { m_marked = newMarked; }
+
+ static void registerDeclarativeType();
+
+signals:
+ void originChanged();
+
+protected:
+ void paintEvent(QPaintEvent *event);
+ void mouseReleaseEvent(QMouseEvent * event);
+ void mousePressEvent(QMouseEvent * event);
+ bool event(QEvent *event);
+private:
+ QString m_originString;
+ bool m_pressed;
+ int m_index;
+ bool m_marked;
+};
+
+} // QmlDesigner
+
+
+#endif //ORIGINWIDGET_H
diff --git a/src/plugins/qmldesigner/components/propertyeditor/propertyeditor.pri b/src/plugins/qmldesigner/components/propertyeditor/propertyeditor.pri
index 32449a9759..3c4c9a9bf4 100644
--- a/src/plugins/qmldesigner/components/propertyeditor/propertyeditor.pri
+++ b/src/plugins/qmldesigner/components/propertyeditor/propertyeditor.pri
@@ -15,6 +15,7 @@ SOURCES += propertyeditor.cpp \
filewidget.cpp \
propertyeditorvalue.cpp \
fontwidget.cpp \
+ originwidget.cpp \
siblingcombobox.cpp \
propertyeditortransaction.cpp
HEADERS += propertyeditor.h \
@@ -31,6 +32,7 @@ HEADERS += propertyeditor.h \
filewidget.h \
propertyeditorvalue.h \
fontwidget.h \
+ originwidget.h \
siblingcombobox.h \
propertyeditortransaction.h
QT += declarative