From 0d8de4d8262a6f5d0bfb716c7e408ba26e200cb7 Mon Sep 17 00:00:00 2001 From: Brian Matherly Date: Tue, 22 Nov 2011 17:30:49 +0100 Subject: [PATCH] Add GUI for MLT filter dynamic text. This includes the new parameter types 'font' and 'keyword'. The color widget gets alpha channel support. --- data/blacklisted_effects.txt | 1 - effects/CMakeLists.txt | 1 + effects/README | 15 ++++++-- effects/dynamictext.xml | 46 +++++++++++++++++++++++++ src/CMakeLists.txt | 2 ++ src/choosecolorwidget.cpp | 64 +++++++++++++++++++++++++++++++--- src/choosecolorwidget.h | 7 ++-- src/effectstackedit.cpp | 66 +++++++++++++++++++++++++++++++++--- src/widgets/fontval_ui.ui | 34 +++++++++++++++++++ src/widgets/keywordval_ui.ui | 40 ++++++++++++++++++++++ 10 files changed, 261 insertions(+), 15 deletions(-) create mode 100644 effects/dynamictext.xml create mode 100644 src/widgets/fontval_ui.ui create mode 100644 src/widgets/keywordval_ui.ui diff --git a/data/blacklisted_effects.txt b/data/blacklisted_effects.txt index e7510c42..c94871eb 100644 --- a/data/blacklisted_effects.txt +++ b/data/blacklisted_effects.txt @@ -98,7 +98,6 @@ resize resample mono -dynamictext # Effects need extra GUI to create the resulting melt.xml with the corrected content videostab diff --git a/effects/CMakeLists.txt b/effects/CMakeLists.txt index c32a199c..8aa6c04d 100644 --- a/effects/CMakeLists.txt +++ b/effects/CMakeLists.txt @@ -10,6 +10,7 @@ chroma_hold.xml chroma.xml crop.xml dust.xml +dynamictext.xml freeze.xml gamma.xml grain.xml diff --git a/effects/README b/effects/README index 4ee66466..b19bba35 100644 --- a/effects/README +++ b/effects/README @@ -71,15 +71,17 @@ The rest: - multiple choice - represented by a drop-down menu - additional parameter attribute: - - "paramlist": list of possible values separated by comma (no whitespaces!) + - "paramlist": list of possible values separated by semicolon (no whitespaces!) - addtional tag: - - "paramlistdisplay": (optional) list of names to use for the values + - "paramlistdisplay": (optional) list of names to use for the values separated by comma - "position": - time stored as frame number - represented by a slider - "color": - - color value, similar to representation HTML ("#rrggbb" or "0xrrggbb") + - color value, similar to representation HTML ("#rrggbb"/"#aarrggbb" or "0xrrggbbaa") - represented by a button opening the KDE color dialog + a color picker button + - additional attributes: + - "alpha": (default = "0") use to enable alpha support - "keyframe": - keyframable number - keyframes are opt-in (only one keyframe by default -> should be prefered over "constant" whenever possible) @@ -112,6 +114,13 @@ The rest: - cubic Bézier spline editor for the frei0r color curves filter (new version, might be reused for other filters) - "roto-spline": - GUI for the rotoscoping filter (spline on the monitor) + - "keywords": + - Text entry with a selection of possible keywords to be inserted in the text. + - additional tags: + - "keywords": list of possible keyword values separated by semicolon + - "keywordsdisplay": list of names to use for the values separated by semicolon + - "fontfamily": + - Font typeface entry ========== ========== diff --git a/effects/dynamictext.xml b/effects/dynamictext.xml new file mode 100644 index 00000000..dcfbbb1b --- /dev/null +++ b/effects/dynamictext.xml @@ -0,0 +1,46 @@ + + + Dynamic Text + Overlay text with keywords replaced + Brian Matherly + + Geometry + + + Font Family + + + Font Size + + + Font Weight + + + Foreground Color + + + Background Color + + + Outline Color + + + Outline Width + + + Padding + + + Left,Center,Right + Horizontal Alignment + + + Top,Middle,Bottom + Vertical Alignment + + + Text + #timecode#;#frame#;#filedate#;#meta.media.0.stream.frame_rate#;#meta.media.0.codec.name#;#meta.media.0.codec.bit_rate#;#meta.media.width#;#meta.media.height#;#meta.attr.comment.markup# + timecode;frame;file date;source frame rate;source codec;source bit rate;source width;source height;source comment + + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8fdcd8cc..27835494 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -251,6 +251,8 @@ kde4_add_ui_files(kdenlive_UIS widgets/wizardextra_ui.ui widgets/wizardmltcheck_ui.ui widgets/wizardstandard_ui.ui + widgets/keywordval_ui.ui + widgets/fontval_ui.ui ) if(OPENGL_FOUND) diff --git a/src/choosecolorwidget.cpp b/src/choosecolorwidget.cpp index 1b81ca31..aa154b6e 100644 --- a/src/choosecolorwidget.cpp +++ b/src/choosecolorwidget.cpp @@ -27,8 +27,59 @@ #include #include +static QColor stringToColor(QString strColor) +{ + bool ok = false; + QColor color("black"); + int intval = 0; + + if (strColor.startsWith("0x")) { + // Format must be 0xRRGGBBAA + intval = strColor.toUInt(&ok, 16); + color.setRgb( ( intval >> 24 ) & 0xff, // r + ( intval >> 16 ) & 0xff, // g + ( intval >> 8 ) & 0xff, // b + ( intval ) & 0xff ); // a + } else if (strColor.startsWith("#") && strColor.length() == 9) { + // Format must be #AARRGGBB + strColor = strColor.replace('#', "0x"); + intval = strColor.toUInt(&ok, 16); + color.setRgb( ( intval >> 16 ) & 0xff, // r + ( intval >> 8 ) & 0xff, // g + ( intval ) & 0xff, // b + ( intval >> 24 ) & 0xff ); // a + } else if (strColor.startsWith("#") && strColor.length() == 7) { + // Format must be #RRGGBB + strColor = strColor.replace('#', "0x"); + intval = strColor.toUInt(&ok, 16); + color.setRgb( ( intval >> 16 ) & 0xff, // r + ( intval >> 8 ) & 0xff, // g + ( intval ) & 0xff, // b + 0xff ); // a + } + + return color; +} + +static QString colorToString(QColor color, bool alpha) +{ + QString colorStr; + QTextStream stream(&colorStr); + stream << "#"; + stream.setIntegerBase(16); + stream.setFieldWidth(2); + stream.setFieldAlignment(QTextStream::AlignRight); + stream.setPadChar('0'); + if(alpha) + { + stream << color.alpha(); + } + stream << color.red() << color.green() << color.blue(); -ChooseColorWidget::ChooseColorWidget(QString text, QColor color, QWidget *parent) : + return colorStr; +} + +ChooseColorWidget::ChooseColorWidget(QString text, QString color, QWidget *parent) : QWidget(parent) { QHBoxLayout *layout = new QHBoxLayout(this); @@ -36,7 +87,7 @@ ChooseColorWidget::ChooseColorWidget(QString text, QColor color, QWidget *parent layout->setSpacing(0); QLabel *label = new QLabel(text, this); - m_button = new KColorButton(color, this); + m_button = new KColorButton(stringToColor(color), this); m_button->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed); ColorPickerWidget *picker = new ColorPickerWidget(this); @@ -49,9 +100,14 @@ ChooseColorWidget::ChooseColorWidget(QString text, QColor color, QWidget *parent connect(m_button, SIGNAL(changed(QColor)), this, SIGNAL(modified())); } -QColor ChooseColorWidget::getColor() +QString ChooseColorWidget::getColor() +{ + return colorToString(m_button->color(), m_button->isAlphaChannelEnabled()); +} + +void ChooseColorWidget::setAlphaChannelEnabled(bool enabled) { - return m_button->color(); + m_button->setAlphaChannelEnabled(enabled); } void ChooseColorWidget::setColor(QColor color) diff --git a/src/choosecolorwidget.h b/src/choosecolorwidget.h index deac2b81..4c2c2ff2 100644 --- a/src/choosecolorwidget.h +++ b/src/choosecolorwidget.h @@ -39,10 +39,13 @@ public: /** @brief Sets up the widget. * @param text (optional) What the color will be used for * @param color (optional) initial color */ - ChooseColorWidget(QString text = QString(), QColor color = QColor(), QWidget* parent = 0); + ChooseColorWidget(QString text = QString(), QString color = "0xffffffff", QWidget* parent = 0); /** @brief Gets the choosen color. */ - QColor getColor(); + QString getColor(); + /** @brief Enable the use of alpha channel. + * @param enabled (required) whether alpha is enabled or disabled */ + void setAlphaChannelEnabled(bool enabled); private: KColorButton *m_button; diff --git a/src/effectstackedit.cpp b/src/effectstackedit.cpp index 2a956679..7efab0f2 100644 --- a/src/effectstackedit.cpp +++ b/src/effectstackedit.cpp @@ -20,6 +20,8 @@ #include "ui_boolval_ui.h" #include "ui_wipeval_ui.h" #include "ui_urlval_ui.h" +#include "ui_keywordval_ui.h" +#include "ui_fontval_ui.h" #include "complexparameter.h" #include "geometryval.h" #include "positionedit.h" @@ -70,6 +72,14 @@ class Urlval: public QWidget, public Ui::Urlval_UI { }; +class Keywordval: public QWidget, public Ui::Keywordval_UI +{ +}; + +class Fontval: public QWidget, public Ui::Fontval_UI +{ +}; + QMap EffectStackEdit::iconCache; EffectStackEdit::EffectStackEdit(Monitor *monitor, QWidget *parent) : @@ -391,10 +401,8 @@ void EffectStackEdit::transferParamDesc(const QDomElement &d, ItemInfo info, boo m_keyframeEditor->addParameter(pa); } } else if (type == "color") { - if (value.startsWith('#')) - value = value.replace('#', "0x"); - bool ok; - ChooseColorWidget *choosecolor = new ChooseColorWidget(paramName, QColor(value.toUInt(&ok, 16)), this); + ChooseColorWidget *choosecolor = new ChooseColorWidget(paramName, value, this); + choosecolor->setAlphaChannelEnabled(pa.attribute("alpha") == "1"); m_vbox->addWidget(choosecolor); m_valueItems[paramName] = choosecolor; connect(choosecolor, SIGNAL(displayMessage(const QString&, int)), this, SIGNAL(displayMessage(const QString&, int))); @@ -534,6 +542,41 @@ void EffectStackEdit::transferParamDesc(const QDomElement &d, ItemInfo info, boo connect(cval->urlwidget, SIGNAL(returnPressed()) , this, SLOT(collectAllParameters())); connect(cval->urlwidget, SIGNAL(urlSelected(const KUrl&)) , this, SLOT(collectAllParameters())); m_uiItems.append(cval); + } else if (type == "keywords") { + Keywordval* kval = new Keywordval; + kval->setupUi(toFillin); + kval->label->setText(paramName); + kval->lineeditwidget->setText(value); + QDomElement klistelem = pa.firstChildElement("keywords"); + QDomElement kdisplaylistelem = pa.firstChildElement("keywordsdisplay"); + QStringList keywordlist; + QStringList keyworddisplaylist; + if (!klistelem.isNull()) { + keywordlist = klistelem.text().split(';'); + keyworddisplaylist = i18n(kdisplaylistelem.text().toUtf8().data()).split(';'); + } + if (keyworddisplaylist.count() != keywordlist.count()) { + keyworddisplaylist = keywordlist; + } + for (int i = 0; i < keywordlist.count(); i++) { + kval->comboboxwidget->addItem(keyworddisplaylist.at(i), keywordlist.at(i)); + } + // Add disabled user prompt at index 0 + kval->comboboxwidget->insertItem(0, i18n("