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 <lars.knoll@digia.com>
Reviewed-by: Christopher Adams <chris.adams@jollamobile.com>
Reviewed-by: Thomas Hartmann <Thomas.Hartmann@digia.com>
This commit is contained in:
Alan Alpert 2012-11-19 19:01:50 -08:00 committed by The Qt Project
parent e03e870b7b
commit 69cc8cd7ac
20 changed files with 202 additions and 450 deletions

View File

@ -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

View File

@ -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 <QApplication>
int main(int argc, char ** argv)
{
QApplication app(argc, argv);
MainWindow mainWindow;
mainWindow.show();
mainWindow.showQuickView();
return app.exec();
}

View File

@ -1,6 +0,0 @@
<RCC>
<qresource prefix="/">
<file>preview.qml</file>
<file>Button.qml</file>
</qresource>
</RCC>

View File

@ -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
}
}
}

View File

@ -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: "<u>After Effects curve</u>"
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: "<u>QML Bezier curve</u>"
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();
}

139
tools/qmleasing/import.ui Normal file
View File

@ -0,0 +1,139 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ImportDialog</class>
<widget class="QDialog" name="ImportDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>164</height>
</rect>
</property>
<property name="windowTitle">
<string>Import After Effects Curve</string>
</property>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="geometry">
<rect>
<x>40</x>
<y>130</y>
<width>341</width>
<height>32</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
<widget class="QWidget" name="formLayoutWidget">
<property name="geometry">
<rect>
<x>20</x>
<y>10</y>
<width>361</width>
<height>101</height>
</rect>
</property>
<layout class="QFormLayout" name="formLayout">
<property name="labelAlignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Input Influence:</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Output Influence:</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Output Slope:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="inInfluenceEdit">
<property name="text">
<string>33</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="inSlopeEdit">
<property name="text">
<string>0</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="outInfluenceEdit">
<property name="text">
<string>33</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="outSlopeEdit">
<property name="text">
<string>0</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Input Slope:</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>ImportDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>ImportDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -39,78 +39,17 @@
**
****************************************************************************/
#include <QPainter>
#include <QtQuick/QQuickView>
#include <QGuiApplication>
#include <QEasingCurve>
#include <QtQuick/QQuickPaintedItem>
#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 <QApplication>
int main(int argc, char ** argv)
{
QGuiApplication app(argc, argv);
QApplication app(argc, argv);
qmlRegisterType<EasingPlot>("EasingPlot", 1, 0, "EasingPlot");
QQuickView view;
view.setSource(QUrl("qrc:/easing.qml"));
view.show();
MainWindow mainWindow;
mainWindow.show();
mainWindow.showQuickView();
return app.exec();
}
#include "main.moc"

View File

@ -47,6 +47,8 @@
#include <QEasingCurve>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QDoubleValidator>
#include <QDialog>
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<double>(0., ii, 100.) / 100.;
oi = qBound<double>(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);
}

View File

@ -45,6 +45,7 @@
#include <QMainWindow>
#include <QtQuick/QQuickView>
#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;
};

View File

@ -86,7 +86,7 @@
</property>
</widget>
</item>
<item row="4" column="1">
<item row="6" column="1">
<spacer name="spacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
@ -102,7 +102,7 @@
</property>
</spacer>
</item>
<item row="5" column="0" colspan="3">
<item row="9" column="0" colspan="3">
<widget class="QGroupBox" name="groupBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
@ -124,6 +124,13 @@
</property>
</widget>
</item>
<item row="4" column="0" colspan="3">
<widget class="QPushButton" name="importButton">
<property name="text">
<string>Import AfterEffects Curve</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>

View File

@ -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

View File

@ -1,6 +1,6 @@
<RCC>
<qresource prefix="/">
<file>easing.qml</file>
<file>TextField.qml</file>
<file>preview.qml</file>
<file>Button.qml</file>
</qresource>
</RCC>

View File

@ -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