From 69cc8cd7acf36f1d1f73e6e30d7162bfe59c364e Mon Sep 17 00:00:00 2001 From: Alan Alpert <416365416c@gmail.com> Date: Mon, 19 Nov 2012 19:01:50 -0800 Subject: [PATCH] Unify qmleasing and easingcurveeditor Keeping the name qmleasing, but most of the code from easingcurveeditor. easingcurveeditor had more UI and functionality, as qmleasing could only import AfterEffects curves. That functionality has now been added to easingcurveeditor. Change-Id: Iac1a004f13fe33a18449af1b08bd22138d525322 Reviewed-by: Lars Knoll Reviewed-by: Christopher Adams Reviewed-by: Thomas Hartmann --- tools/easingcurveeditor/easingcurveeditor.pro | 19 -- tools/easingcurveeditor/main.cpp | 55 ------ tools/easingcurveeditor/resources.qrc | 6 - tools/{easingcurveeditor => qmleasing}/Button.qml | 0 tools/qmleasing/TextField.qml | 76 ------- tools/qmleasing/easing.qml | 219 --------------------- tools/qmleasing/import.ui | 139 +++++++++++++ tools/qmleasing/main.cpp | 73 +------ .../mainwindow.cpp | 27 +++ .../{easingcurveeditor => qmleasing}/mainwindow.h | 3 + tools/{easingcurveeditor => qmleasing}/pane.ui | 0 tools/{easingcurveeditor => qmleasing}/preview.qml | 0 .../{easingcurveeditor => qmleasing}/properties.ui | 11 +- tools/qmleasing/qmleasing.pro | 17 +- tools/qmleasing/resources.qrc | 4 +- .../segmentproperties.cpp | 0 .../segmentproperties.h | 0 .../splineeditor.cpp | 0 .../splineeditor.h | 0 tools/tools.pro | 3 +- 20 files changed, 202 insertions(+), 450 deletions(-) delete mode 100644 tools/easingcurveeditor/easingcurveeditor.pro delete mode 100644 tools/easingcurveeditor/main.cpp delete mode 100644 tools/easingcurveeditor/resources.qrc rename tools/{easingcurveeditor => qmleasing}/Button.qml (100%) delete mode 100644 tools/qmleasing/TextField.qml delete mode 100644 tools/qmleasing/easing.qml create mode 100644 tools/qmleasing/import.ui rename tools/{easingcurveeditor => qmleasing}/mainwindow.cpp (80%) rename tools/{easingcurveeditor => qmleasing}/mainwindow.h (96%) rename tools/{easingcurveeditor => qmleasing}/pane.ui (100%) rename tools/{easingcurveeditor => qmleasing}/preview.qml (100%) rename tools/{easingcurveeditor => qmleasing}/properties.ui (92%) rename tools/{easingcurveeditor => qmleasing}/segmentproperties.cpp (100%) rename tools/{easingcurveeditor => qmleasing}/segmentproperties.h (100%) rename tools/{easingcurveeditor => qmleasing}/splineeditor.cpp (100%) rename tools/{easingcurveeditor => qmleasing}/splineeditor.h (100%) diff --git a/tools/easingcurveeditor/easingcurveeditor.pro b/tools/easingcurveeditor/easingcurveeditor.pro deleted file mode 100644 index 91f6516..0000000 --- a/tools/easingcurveeditor/easingcurveeditor.pro +++ /dev/null @@ -1,19 +0,0 @@ -QT += qml quick widgets -CONFIG -= app_bundle - -# Input -SOURCES += main.cpp \ - splineeditor.cpp \ - mainwindow.cpp \ - segmentproperties.cpp - -RESOURCES = $$PWD/resources.qrc - -HEADERS += \ - splineeditor.h \ - mainwindow.h \ - segmentproperties.h - -FORMS += \ - properties.ui \ - pane.ui diff --git a/tools/easingcurveeditor/main.cpp b/tools/easingcurveeditor/main.cpp deleted file mode 100644 index 212b9b1..0000000 --- a/tools/easingcurveeditor/main.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the tools applications of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** 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. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "mainwindow.h" - -#include - -int main(int argc, char ** argv) -{ - QApplication app(argc, argv); - - MainWindow mainWindow; - mainWindow.show(); - mainWindow.showQuickView(); - - return app.exec(); -} diff --git a/tools/easingcurveeditor/resources.qrc b/tools/easingcurveeditor/resources.qrc deleted file mode 100644 index c184af4..0000000 --- a/tools/easingcurveeditor/resources.qrc +++ /dev/null @@ -1,6 +0,0 @@ - - - preview.qml - Button.qml - - diff --git a/tools/easingcurveeditor/Button.qml b/tools/qmleasing/Button.qml similarity index 100% rename from tools/easingcurveeditor/Button.qml rename to tools/qmleasing/Button.qml diff --git a/tools/qmleasing/TextField.qml b/tools/qmleasing/TextField.qml deleted file mode 100644 index 7fedab8..0000000 --- a/tools/qmleasing/TextField.qml +++ /dev/null @@ -1,76 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtQml module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** 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. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.0 - -FocusScope { - width: input.x + input.width - height: border.height - - property alias name: name.text - property alias text: input.text - - Text { - id: name - height: parent.height - } - - TextInput { - id: input - anchors.left: name.right - anchors.leftMargin: 4 - focus: true - width: 50 - horizontalAlignment: "AlignRight" - Rectangle { - id: border - x: -2; y: -2 - width: parent.width + 4 - height: parent.height + 4 - color: "transparent" - border.color: input.activeFocus?"green":"lightgreen" - - border.width: 3 - radius: 5 - } - } -} - diff --git a/tools/qmleasing/easing.qml b/tools/qmleasing/easing.qml deleted file mode 100644 index 8bed5ba..0000000 --- a/tools/qmleasing/easing.qml +++ /dev/null @@ -1,219 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtQml module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** 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. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.0 -import EasingPlot 1.0 - -Rectangle { - width: 775; height: 550 - - function precision(n) - { - var str = n.toPrecision(3); - while (str.length > 1 && (str[str.length - 1] == "0" || str[str.length - 1] == ".")) - str = str.substr(0, str.length - 1); - return str; - } - - function updateEasing() { - var ini = Math.min(100, Math.max(0, Number(in_inf.text))); - var outi = Math.min(100, Math.max(0, Number(out_inf.text))); - - var ins = Number(in_slope.text); - var outs = Number(out_slope.text); - - var p1 = [ (ini / 100), (ini / 100) * ins ]; - var p2 = [ 1 - (outi / 100), 1 - (outi / 100) * outs ]; - - text.text = "[ " + precision(p1[0]) + ", " + precision(p1[1]) + ", " + precision(p2[0]) + ", " + precision(p2[1]) + ", 1, 1 ]"; - } - - Rectangle { - id: border - width: 500; height: 500 - x: 25; y: 25 - border.color: "lightsteelblue" - border.width: 3 - radius: 5 - color: "transparent" - - EasingPlot { - id: plot - - anchors.centerIn: parent - width: parent.width - 10 - height: parent.height - 10 - - easing.type: "Bezier" - easing.bezierCurve: eval(text.text) - } - - } - - Text { - text: "After Effects curve" - anchors.horizontalCenter: text.horizontalCenter - anchors.bottom: column.top - anchors.bottomMargin: 14 - } - - Column { - id: column - - y: 70 - anchors.right: parent.right - anchors.rightMargin: 25 - spacing: 5 - TextField { - id: in_inf - focus: true - name: "Input influence:" - text: "33" - anchors.right: parent.right - KeyNavigation.tab: in_slope - KeyNavigation.backtab: text - onTextChanged: updateEasing(); - } - TextField { - id: in_slope - name: "Input slope:" - text: "0" - anchors.right: parent.right - KeyNavigation.tab: out_inf - KeyNavigation.backtab: in_inf - onTextChanged: updateEasing(); - } - TextField { - id: out_inf - name: "Output influence:" - text: "33" - anchors.right: parent.right - KeyNavigation.tab: out_slope - KeyNavigation.backtab: in_slope - onTextChanged: updateEasing(); - } - TextField { - id: out_slope - name: "Output slope:" - text: "0" - anchors.right: parent.right - KeyNavigation.tab: text - KeyNavigation.backtab: out_info - onTextChanged: updateEasing(); - } - } - - Text { - text: "QML Bezier curve" - anchors.horizontalCenter: text.horizontalCenter - anchors.bottom: text.top - anchors.bottomMargin: 10 - } - - TextEdit { - id: text - x: 200 - width: 200 - height: 200 - - Rectangle { - x: -2; y: -2 - width: parent.width + 4 - height: parent.height + 4 - color: "transparent" - border.color: text.activeFocus?"green":"lightgreen" - - border.width: 3 - radius: 5 - } - - wrapMode: "WordWrap" - - anchors.top: column.bottom - anchors.topMargin: 50 - anchors.right: column.right - KeyNavigation.tab: in_inf - KeyNavigation.backtab: out_slope - } - - - Item { - anchors.left: text.left - anchors.top: text.bottom - anchors.topMargin: 35 - width: text.width - height: rect.height - - Rectangle { - color: "gray" - width: 50; height: 50 - id: rect - - NumberAnimation on x { - id: animation - running: false - easing: plot.easing - duration: 1000 - } - - radius: 5 - } - - MouseArea { - anchors.fill: parent - onClicked: { - if (rect.x < 5) { - animation.to = text.width - rect.width; - } else { - animation.to = 0; - } - animation.start(); - } - } - - Text { - anchors.centerIn: parent - text: "Click to Try" - } - } - - Component.onCompleted: updateEasing(); -} diff --git a/tools/qmleasing/import.ui b/tools/qmleasing/import.ui new file mode 100644 index 0000000..86b80e2 --- /dev/null +++ b/tools/qmleasing/import.ui @@ -0,0 +1,139 @@ + + + ImportDialog + + + + 0 + 0 + 400 + 164 + + + + Import After Effects Curve + + + + + 40 + 130 + 341 + 32 + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + 20 + 10 + 361 + 101 + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + Input Influence: + + + + + + + Output Influence: + + + + + + + Output Slope: + + + + + + + 33 + + + + + + + 0 + + + + + + + 33 + + + + + + + 0 + + + + + + + Input Slope: + + + + + + + + + + buttonBox + accepted() + ImportDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + ImportDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/tools/qmleasing/main.cpp b/tools/qmleasing/main.cpp index 60a6f37..212b9b1 100644 --- a/tools/qmleasing/main.cpp +++ b/tools/qmleasing/main.cpp @@ -39,78 +39,17 @@ ** ****************************************************************************/ -#include -#include -#include -#include -#include +#include "mainwindow.h" -class EasingPlot : public QQuickPaintedItem -{ - Q_OBJECT - Q_PROPERTY(QEasingCurve easing READ easing WRITE setEasing NOTIFY easingChanged); - -public: - EasingPlot(); - - QEasingCurve easing() const; - void setEasing(const QEasingCurve &); - -signals: - void easingChanged(); - -protected: - virtual void paint(QPainter *painter); - -private: - QEasingCurve m_easing; -}; - -EasingPlot::EasingPlot() -{ -} - -QEasingCurve EasingPlot::easing() const -{ - return m_easing; -} - -void EasingPlot::setEasing(const QEasingCurve &e) -{ - if (m_easing == e) - return; - - m_easing = e; - emit easingChanged(); - - update(); -} - -void EasingPlot::paint(QPainter *painter) -{ - QPointF lastPoint(0, 0); - - for (int ii = 1; ii <= 100; ++ii) { - qreal value = m_easing.valueForProgress(qreal(ii) / 100.); - - QPointF currentPoint(width() * qreal(ii) / 100., value * (height() - 1)); - painter->drawLine(lastPoint, currentPoint); - - lastPoint = currentPoint; - } -} +#include int main(int argc, char ** argv) { - QGuiApplication app(argc, argv); - - qmlRegisterType("EasingPlot", 1, 0, "EasingPlot"); + QApplication app(argc, argv); - QQuickView view; - view.setSource(QUrl("qrc:/easing.qml")); - view.show(); + MainWindow mainWindow; + mainWindow.show(); + mainWindow.showQuickView(); return app.exec(); } - -#include "main.moc" diff --git a/tools/easingcurveeditor/mainwindow.cpp b/tools/qmleasing/mainwindow.cpp similarity index 80% rename from tools/easingcurveeditor/mainwindow.cpp rename to tools/qmleasing/mainwindow.cpp index 7f7b2d9..3cf6d22 100644 --- a/tools/easingcurveeditor/mainwindow.cpp +++ b/tools/qmleasing/mainwindow.cpp @@ -47,6 +47,8 @@ #include #include #include +#include +#include MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) @@ -98,6 +100,16 @@ MainWindow::MainWindow(QWidget *parent) : groupBoxLayout->addWidget(splineEditor->pointListWidget()); m_splineEditor = splineEditor; connect(ui_properties.plainTextEdit, SIGNAL(textChanged()), this, SLOT(textEditTextChanged())); + + QDialog* importDialog = new QDialog(this); + ui_import.setupUi(importDialog); + ui_import.inInfluenceEdit->setValidator(new QDoubleValidator(this)); + ui_import.inSlopeEdit->setValidator(new QDoubleValidator(this)); + ui_import.outInfluenceEdit->setValidator(new QDoubleValidator(this)); + ui_import.outSlopeEdit->setValidator(new QDoubleValidator(this)); + connect(ui_properties.importButton, SIGNAL(clicked()), importDialog, SLOT(show())); + connect(importDialog, SIGNAL(finished(int)), this, SLOT(importData(int))); + connect(this, SIGNAL(close()), this, SLOT(doClose())); initQml(); } @@ -140,3 +152,18 @@ void MainWindow::closeEvent(QCloseEvent *) { quickView.close(); } + +void MainWindow::importData(int result) +{ + if (!result) + return; + double ii = ui_import.inInfluenceEdit->text().toDouble(); + double is = ui_import.inSlopeEdit->text().toDouble(); + double oi = ui_import.outInfluenceEdit->text().toDouble(); + double os = ui_import.outSlopeEdit->text().toDouble(); + ii = qBound(0., ii, 100.) / 100.; + oi = qBound(0., oi, 100.) / 100.; + QString generatedString = QString("[%1,%2,%3,%4,1,1]").arg(ii, 0, 'f', 3) + .arg(ii*is,0,'f',3).arg(1-oi, 0, 'f', 3).arg(1-(oi*os), 0, 'f', 3); + ui_properties.plainTextEdit->setPlainText(generatedString); +} diff --git a/tools/easingcurveeditor/mainwindow.h b/tools/qmleasing/mainwindow.h similarity index 96% rename from tools/easingcurveeditor/mainwindow.h rename to tools/qmleasing/mainwindow.h index 9ab58e6..f2fcc61 100644 --- a/tools/easingcurveeditor/mainwindow.h +++ b/tools/qmleasing/mainwindow.h @@ -45,6 +45,7 @@ #include #include #include "ui_properties.h" +#include "ui_import.h" class SplineEditor; @@ -60,6 +61,7 @@ signals: public slots: void textEditTextChanged(); + void importData(int result); protected: virtual void moveEvent(QMoveEvent *event); @@ -71,6 +73,7 @@ private: QQuickView quickView; QWidget *m_placeholder; Ui_Properties ui_properties; + Ui_ImportDialog ui_import; SplineEditor *m_splineEditor; }; diff --git a/tools/easingcurveeditor/pane.ui b/tools/qmleasing/pane.ui similarity index 100% rename from tools/easingcurveeditor/pane.ui rename to tools/qmleasing/pane.ui diff --git a/tools/easingcurveeditor/preview.qml b/tools/qmleasing/preview.qml similarity index 100% rename from tools/easingcurveeditor/preview.qml rename to tools/qmleasing/preview.qml diff --git a/tools/easingcurveeditor/properties.ui b/tools/qmleasing/properties.ui similarity index 92% rename from tools/easingcurveeditor/properties.ui rename to tools/qmleasing/properties.ui index af96e9c..ea28df3 100644 --- a/tools/easingcurveeditor/properties.ui +++ b/tools/qmleasing/properties.ui @@ -86,7 +86,7 @@ - + Qt::Vertical @@ -102,7 +102,7 @@ - + @@ -124,6 +124,13 @@ + + + + Import AfterEffects Curve + + + diff --git a/tools/qmleasing/qmleasing.pro b/tools/qmleasing/qmleasing.pro index b43071c..eadcb30 100644 --- a/tools/qmleasing/qmleasing.pro +++ b/tools/qmleasing/qmleasing.pro @@ -1,6 +1,19 @@ -QT += qml quick +QT += qml quick widgets CONFIG -= app_bundle -SOURCES += main.cpp +SOURCES += main.cpp \ + splineeditor.cpp \ + mainwindow.cpp \ + segmentproperties.cpp RESOURCES = $$PWD/resources.qrc + +HEADERS += \ + splineeditor.h \ + mainwindow.h \ + segmentproperties.h + +FORMS += \ + properties.ui \ + pane.ui \ + import.ui diff --git a/tools/qmleasing/resources.qrc b/tools/qmleasing/resources.qrc index c7a67b8..c184af4 100644 --- a/tools/qmleasing/resources.qrc +++ b/tools/qmleasing/resources.qrc @@ -1,6 +1,6 @@ - easing.qml - TextField.qml + preview.qml + Button.qml diff --git a/tools/easingcurveeditor/segmentproperties.cpp b/tools/qmleasing/segmentproperties.cpp similarity index 100% rename from tools/easingcurveeditor/segmentproperties.cpp rename to tools/qmleasing/segmentproperties.cpp diff --git a/tools/easingcurveeditor/segmentproperties.h b/tools/qmleasing/segmentproperties.h similarity index 100% rename from tools/easingcurveeditor/segmentproperties.h rename to tools/qmleasing/segmentproperties.h diff --git a/tools/easingcurveeditor/splineeditor.cpp b/tools/qmleasing/splineeditor.cpp similarity index 100% rename from tools/easingcurveeditor/splineeditor.cpp rename to tools/qmleasing/splineeditor.cpp diff --git a/tools/easingcurveeditor/splineeditor.h b/tools/qmleasing/splineeditor.h similarity index 100% rename from tools/easingcurveeditor/splineeditor.h rename to tools/qmleasing/splineeditor.h diff --git a/tools/tools.pro b/tools/tools.pro index 3966411..abb246f 100644 --- a/tools/tools.pro +++ b/tools/tools.pro @@ -3,10 +3,9 @@ SUBDIRS += \ qmlscene \ qmlplugindump \ qmlmin \ - qmleasing \ qmlprofiler \ qmlbundle \ qmltestrunner -!contains(QT_CONFIG, no-widgets):SUBDIRS += easingcurveeditor +!contains(QT_CONFIG, no-widgets):SUBDIRS += qmleasing -- 2.7.4