diff --git a/app/dialog/CMakeLists.txt b/app/dialog/CMakeLists.txt index 140a3ce6e..1eed0ae0a 100644 --- a/app/dialog/CMakeLists.txt +++ b/app/dialog/CMakeLists.txt @@ -24,6 +24,7 @@ add_subdirectory(preferences) add_subdirectory(progress) add_subdirectory(projectproperties) add_subdirectory(rendercancel) +add_subdirectory(richtext) add_subdirectory(sequence) add_subdirectory(speedduration) add_subdirectory(task) diff --git a/app/dialog/richtext/CMakeLists.txt b/app/dialog/richtext/CMakeLists.txt new file mode 100644 index 000000000..c434be383 --- /dev/null +++ b/app/dialog/richtext/CMakeLists.txt @@ -0,0 +1,22 @@ +# Olive - Non-Linear Video Editor +# Copyright (C) 2019 Olive Team +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +set(OLIVE_SOURCES + ${OLIVE_SOURCES} + dialog/richtext/richtext.h + dialog/richtext/richtext.cpp + PARENT_SCOPE +) diff --git a/app/dialog/richtext/richtext.cpp b/app/dialog/richtext/richtext.cpp new file mode 100644 index 000000000..ebd58ff2c --- /dev/null +++ b/app/dialog/richtext/richtext.cpp @@ -0,0 +1,109 @@ +/*** + + Olive - Non-Linear Video Editor + Copyright (C) 2019 Olive Team + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +***/ + +#include "richtext.h" + +#include +#include +#include +#include +#include + +#include "ui/icons/icons.h" + +OLIVE_NAMESPACE_ENTER + +RichTextDialog::RichTextDialog(const QString &start, QWidget* parent) : + QDialog(parent) +{ + QVBoxLayout* layout = new QVBoxLayout(this); + + // Create toolbar + QHBoxLayout* toolbar_layout = new QHBoxLayout(); + + bold_btn_ = new QPushButton(QStringLiteral("B")); + bold_btn_->setCheckable(true); + toolbar_layout->addWidget(bold_btn_); + italic_btn_ = new QPushButton(QStringLiteral("I")); + italic_btn_->setCheckable(true); + toolbar_layout->addWidget(italic_btn_); + underline_btn_ = new QPushButton(QStringLiteral("U")); + underline_btn_->setCheckable(true); + toolbar_layout->addWidget(underline_btn_); + font_combo_ = new QFontComboBox(); + toolbar_layout->addWidget(font_combo_); + size_slider_ = new FloatSlider(); + size_slider_->SetMinimum(0.1); + toolbar_layout->addWidget(size_slider_); + + toolbar_layout->addStretch(); + + layout->addLayout(toolbar_layout); + + // Create text edit widget + text_edit_ = new QTextEdit(); + connect(text_edit_, &QTextEdit::cursorPositionChanged, this, &RichTextDialog::UpdateButtons); + text_edit_->document()->setHtml(start); + layout->addWidget(text_edit_); + + // Create buttons + QDialogButtonBox* buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); + layout->addWidget(buttons); + connect(buttons, &QDialogButtonBox::accepted, this, &RichTextDialog::accept); + connect(buttons, &QDialogButtonBox::rejected, this, &RichTextDialog::reject); + + // Connect font buttons + connect(bold_btn_, &QPushButton::clicked, this, [this](bool e){ + text_edit_->setFontWeight(e ? QFont::Bold : QFont::Normal); + }); + connect(italic_btn_, &QPushButton::clicked, text_edit_, &QTextEdit::setFontItalic); + connect(underline_btn_, &QPushButton::clicked, text_edit_, &QTextEdit::setFontUnderline); + connect(size_slider_, &FloatSlider::ValueChanged, text_edit_, &QTextEdit::setFontPointSize); + + connect(font_combo_, &QFontComboBox::currentTextChanged, this, [this](const QString& s){ + QTextCharFormat fmt; + fmt.setFontFamily(s); + + QTextCursor cursor = text_edit_->textCursor(); + if (!cursor.hasSelection()) + cursor.select(QTextCursor::WordUnderCursor); + cursor.mergeCharFormat(fmt); + text_edit_->mergeCurrentCharFormat(fmt); + }); +} + +void RichTextDialog::UpdateButtons() +{ + bold_btn_->setChecked(text_edit_->fontWeight() > QFont::Normal); + italic_btn_->setChecked(text_edit_->fontItalic()); + underline_btn_->setChecked(text_edit_->fontUnderline()); + + font_combo_->blockSignals(true); + QString font_family = text_edit_->fontFamily(); + if (font_family.isEmpty()) { + font_family = QFont().family(); + } + font_combo_->setCurrentFont(font_family); + font_combo_->blockSignals(false); + + size_slider_->SetValue(text_edit_->fontPointSize()); +} + +OLIVE_NAMESPACE_EXIT diff --git a/app/dialog/richtext/richtext.h b/app/dialog/richtext/richtext.h new file mode 100644 index 000000000..746dbaf0a --- /dev/null +++ b/app/dialog/richtext/richtext.h @@ -0,0 +1,60 @@ +/*** + + Olive - Non-Linear Video Editor + Copyright (C) 2019 Olive Team + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +***/ + +#ifndef RICHTEXTDIALOG_H +#define RICHTEXTDIALOG_H + +#include +#include +#include + +#include "common/define.h" +#include "widget/slider/floatslider.h" + +OLIVE_NAMESPACE_ENTER + +class RichTextDialog : public QDialog +{ + Q_OBJECT +public: + RichTextDialog(const QString& start, QWidget* parent = nullptr); + + QString text() const + { + return text_edit_->document()->toHtml("utf-8"); + } + +private: + QTextEdit* text_edit_; + + QPushButton* bold_btn_; + QPushButton* italic_btn_; + QPushButton* underline_btn_; + QFontComboBox* font_combo_; + FloatSlider* size_slider_; + +private slots: + void UpdateButtons(); + +}; + +OLIVE_NAMESPACE_EXIT + +#endif // RICHTEXTDIALOG_H diff --git a/app/widget/nodeparamview/CMakeLists.txt b/app/widget/nodeparamview/CMakeLists.txt index 58f5320e4..9bac86e5a 100644 --- a/app/widget/nodeparamview/CMakeLists.txt +++ b/app/widget/nodeparamview/CMakeLists.txt @@ -26,6 +26,8 @@ set(OLIVE_SOURCES widget/nodeparamview/nodeparamviewitem.cpp widget/nodeparamview/nodeparamviewkeyframecontrol.h widget/nodeparamview/nodeparamviewkeyframecontrol.cpp + widget/nodeparamview/nodeparamviewrichtext.h + widget/nodeparamview/nodeparamviewrichtext.cpp widget/nodeparamview/nodeparamviewundo.h widget/nodeparamview/nodeparamviewundo.cpp widget/nodeparamview/nodeparamviewwidgetbridge.h diff --git a/app/widget/nodeparamview/nodeparamviewrichtext.cpp b/app/widget/nodeparamview/nodeparamviewrichtext.cpp new file mode 100644 index 000000000..de382f0c9 --- /dev/null +++ b/app/widget/nodeparamview/nodeparamviewrichtext.cpp @@ -0,0 +1,56 @@ +/*** + + Olive - Non-Linear Video Editor + Copyright (C) 2019 Olive Team + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +***/ + +#include "nodeparamviewrichtext.h" + +#include +#include + +#include "dialog/richtext/richtext.h" +#include "ui/icons/icons.h" + +OLIVE_NAMESPACE_ENTER + +NodeParamViewRichText::NodeParamViewRichText(QWidget *parent) : + QWidget(parent) +{ + QHBoxLayout* layout = new QHBoxLayout(this); + layout->setMargin(0); + + line_edit_ = new QLineEdit(); + connect(line_edit_, &QLineEdit::textEdited, this, &NodeParamViewRichText::textEdited); + layout->addWidget(line_edit_); + + QPushButton* edit_btn = new QPushButton(); + edit_btn->setIcon(icon::ToolEdit); + layout->addWidget(edit_btn); + connect(edit_btn, &QPushButton::clicked, this, &NodeParamViewRichText::ShowRichTextDialog); +} + +void NodeParamViewRichText::ShowRichTextDialog() +{ + RichTextDialog d(line_edit_->text(), this); + if (d.exec() == QDialog::Accepted) { + line_edit_->setText(d.text()); + emit textEdited(d.text()); + } +} + +OLIVE_NAMESPACE_EXIT diff --git a/app/widget/nodeparamview/nodeparamviewrichtext.h b/app/widget/nodeparamview/nodeparamviewrichtext.h new file mode 100644 index 000000000..88a2befef --- /dev/null +++ b/app/widget/nodeparamview/nodeparamviewrichtext.h @@ -0,0 +1,61 @@ +/*** + + Olive - Non-Linear Video Editor + Copyright (C) 2019 Olive Team + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +***/ + +#ifndef NODEPARAMVIEWRICHTEXT_H +#define NODEPARAMVIEWRICHTEXT_H + +#include +#include + +#include "common/define.h" + +OLIVE_NAMESPACE_ENTER + +class NodeParamViewRichText : public QWidget +{ + Q_OBJECT +public: + NodeParamViewRichText(QWidget* parent = nullptr); + + QString text() const + { + return line_edit_->text(); + } + +public slots: + void setText(const QString &s) + { + line_edit_->setText(s); + } + +signals: + void textEdited(const QString &); + +private: + QLineEdit* line_edit_; + +private slots: + void ShowRichTextDialog(); + +}; + +OLIVE_NAMESPACE_EXIT + +#endif // NODEPARAMVIEWRICHTEXT_H diff --git a/app/widget/nodeparamview/nodeparamviewwidgetbridge.cpp b/app/widget/nodeparamview/nodeparamviewwidgetbridge.cpp index b59c633a8..34fd5f1f7 100644 --- a/app/widget/nodeparamview/nodeparamviewwidgetbridge.cpp +++ b/app/widget/nodeparamview/nodeparamviewwidgetbridge.cpp @@ -22,7 +22,6 @@ #include #include -#include #include #include #include @@ -30,6 +29,7 @@ #include "core.h" #include "node/node.h" #include "nodeparamviewarraywidget.h" +#include "nodeparamviewrichtext.h" #include "nodeparamviewundo.h" #include "project/item/sequence/sequence.h" #include "undo/undostack.h" @@ -146,9 +146,9 @@ void NodeParamViewWidgetBridge::CreateWidgets() } case NodeParam::kText: { - QLineEdit* line_edit = new QLineEdit(); + NodeParamViewRichText* line_edit = new NodeParamViewRichText(); widgets_.append(line_edit); - connect(line_edit, &QLineEdit::textEdited, this, &NodeParamViewWidgetBridge::WidgetCallback); + connect(line_edit, &NodeParamViewRichText::textEdited, this, &NodeParamViewWidgetBridge::WidgetCallback); break; } case NodeParam::kBoolean: @@ -336,8 +336,8 @@ void NodeParamViewWidgetBridge::WidgetCallback() } case NodeParam::kText: { - // Sender is a QLineEdit - SetInputValue(static_cast(sender())->text(), 0); + // Sender is a NodeParamViewRichText + SetInputValue(static_cast(sender())->text(), 0); break; } case NodeParam::kBoolean: @@ -456,10 +456,8 @@ void NodeParamViewWidgetBridge::UpdateWidgetValues() } case NodeParam::kText: { - QLineEdit* e = static_cast(widgets_.first()); - int pos = e->cursorPosition(); + NodeParamViewRichText* e = static_cast(widgets_.first()); e->setText(input_->get_value_at_time(node_time).toString()); - e->setCursorPosition(pos); break; } case NodeParam::kBoolean: