From ff02b41cdc4c3c7ba03314eb7fd2901d48240b88 Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Sat, 31 Aug 2019 16:55:57 +1000 Subject: [PATCH] added slider widget --- app/node/blend/alphaover/alphaover.cpp | 12 +- app/node/blend/alphaover/alphaover.h | 1 - app/node/color/opacity/opacity.cpp | 1 + app/render/colorservice.cpp | 3 +- app/widget/CMakeLists.txt | 1 + .../nodeparamviewwidgetbridge.cpp | 36 ++- app/widget/slider/CMakeLists.txt | 32 +++ app/widget/slider/floatslider.cpp | 49 ++++ app/widget/slider/floatslider.h | 45 ++++ app/widget/slider/integerslider.cpp | 42 ++++ app/widget/slider/integerslider.h | 43 ++++ app/widget/slider/sliderbase.cpp | 233 ++++++++++++++++++ app/widget/slider/sliderbase.h | 84 +++++++ app/widget/slider/sliderlabel.cpp | 72 ++++++ app/widget/slider/sliderlabel.h | 51 ++++ app/widget/slider/sliderlineedit.cpp | 51 ++++ app/widget/slider/sliderlineedit.h | 45 ++++ app/widget/slider/stringslider.cpp | 42 ++++ app/widget/slider/stringslider.h | 45 ++++ 19 files changed, 868 insertions(+), 20 deletions(-) create mode 100644 app/widget/slider/CMakeLists.txt create mode 100644 app/widget/slider/floatslider.cpp create mode 100644 app/widget/slider/floatslider.h create mode 100644 app/widget/slider/integerslider.cpp create mode 100644 app/widget/slider/integerslider.h create mode 100644 app/widget/slider/sliderbase.cpp create mode 100644 app/widget/slider/sliderbase.h create mode 100644 app/widget/slider/sliderlabel.cpp create mode 100644 app/widget/slider/sliderlabel.h create mode 100644 app/widget/slider/sliderlineedit.cpp create mode 100644 app/widget/slider/sliderlineedit.h create mode 100644 app/widget/slider/stringslider.cpp create mode 100644 app/widget/slider/stringslider.h diff --git a/app/node/blend/alphaover/alphaover.cpp b/app/node/blend/alphaover/alphaover.cpp index 240666734..1ef4aaa4a 100644 --- a/app/node/blend/alphaover/alphaover.cpp +++ b/app/node/blend/alphaover/alphaover.cpp @@ -25,8 +25,7 @@ #include "render/rendertexture.h" #include "render/gl/shadergenerators.h" -AlphaOverBlend::AlphaOverBlend() : - shader_(nullptr) +AlphaOverBlend::AlphaOverBlend() { } @@ -48,7 +47,6 @@ QString AlphaOverBlend::Description() void AlphaOverBlend::Release() { - shader_ = nullptr; } QVariant AlphaOverBlend::Value(NodeOutput *param, const rational &time) @@ -76,14 +74,8 @@ QVariant AlphaOverBlend::Value(NodeOutput *param, const rational &time) // Bind blend blend->Bind(); - // Get default pipeline shader - // FIXME: Come up with a good way to share pipeline shaders since a lot of nodes will just use the default - if (shader_ == nullptr) { - shader_ = olive::ShaderGenerator::DefaultPipeline(); - } - // Draw blend on base - olive::gl::Blit(shader_); + olive::gl::Blit(renderer->default_pipeline()); // Release all blend->Release(); diff --git a/app/node/blend/alphaover/alphaover.h b/app/node/blend/alphaover/alphaover.h index 38a3faf7d..f412b385d 100644 --- a/app/node/blend/alphaover/alphaover.h +++ b/app/node/blend/alphaover/alphaover.h @@ -39,7 +39,6 @@ protected: virtual QVariant Value(NodeOutput* param, const rational& time) override; private: - ShaderPtr shader_; }; #endif // ALPHAOVER_H diff --git a/app/node/color/opacity/opacity.cpp b/app/node/color/opacity/opacity.cpp index a9bc19f0d..8672d889d 100644 --- a/app/node/color/opacity/opacity.cpp +++ b/app/node/color/opacity/opacity.cpp @@ -28,6 +28,7 @@ OpacityNode::OpacityNode() { opacity_input_ = new NodeInput("opacity_in"); opacity_input_->add_data_input(NodeParam::kFloat); + opacity_input_->set_value(100); AddParameter(opacity_input_); texture_input_ = new NodeInput("tex_in"); diff --git a/app/render/colorservice.cpp b/app/render/colorservice.cpp index d2e23b1d3..17d02db2b 100644 --- a/app/render/colorservice.cpp +++ b/app/render/colorservice.cpp @@ -88,8 +88,7 @@ void ColorService::AssociateAlphaInternal(ColorService::AlphaAction action, T *d for (int i=0;i 0) { for (int j=0;j(sender()); + input->set_value(int_slider->GetValue()); break; + } case NodeParam::kFloat: - // FIXME: LabelSlider in FLOAT mode + { + // Widget is a FloatSlider + FloatSlider* float_slider = static_cast(sender()); + input->set_value(float_slider->GetValue()); break; + } case NodeParam::kFile: // FIXME: File selector break; @@ -130,19 +149,22 @@ void NodeParamViewWidgetBridge::WidgetCallback() case NodeParam::kString: { // Sender is a QLineEdit - //QLineEdit* line_edit = static_cast(sender()); + QLineEdit* line_edit = static_cast(sender()); + input->set_value(line_edit->text()); break; } case NodeParam::kBoolean: { // Widget is a QCheckBox - //QCheckBox* check_box = static_cast(sender()); + QCheckBox* check_box = static_cast(sender()); + input->set_value(check_box->isChecked()); break; } case NodeParam::kFont: { // Widget is a QFontComboBox - //QFontComboBox* font_combobox = static_cast(sender()); + QFontComboBox* font_combobox = static_cast(sender()); + input->set_value(font_combobox->currentFont()); break; } case NodeParam::kFootage: diff --git a/app/widget/slider/CMakeLists.txt b/app/widget/slider/CMakeLists.txt new file mode 100644 index 000000000..b58325bb3 --- /dev/null +++ b/app/widget/slider/CMakeLists.txt @@ -0,0 +1,32 @@ +# 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} + widget/slider/floatslider.h + widget/slider/floatslider.cpp + widget/slider/integerslider.h + widget/slider/integerslider.cpp + widget/slider/sliderbase.h + widget/slider/sliderbase.cpp + widget/slider/sliderlabel.h + widget/slider/sliderlabel.cpp + widget/slider/sliderlineedit.h + widget/slider/sliderlineedit.cpp + widget/slider/stringslider.h + widget/slider/stringslider.cpp + PARENT_SCOPE +) diff --git a/app/widget/slider/floatslider.cpp b/app/widget/slider/floatslider.cpp new file mode 100644 index 000000000..09e64ee80 --- /dev/null +++ b/app/widget/slider/floatslider.cpp @@ -0,0 +1,49 @@ +/*** + + 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 "floatslider.h" + +FloatSlider::FloatSlider(QWidget *parent) : + SliderBase(kFloat, parent) +{ + connect(this, SIGNAL(ValueChanged(QVariant)), this, SLOT(ConvertValue(QVariant))); +} + +double FloatSlider::GetValue() +{ + return Value().toDouble(); +} + +void FloatSlider::SetValue(const double &d) +{ + SliderBase::SetValue(d); +} + +void FloatSlider::SetDecimalPlaces(int i) +{ + decimal_places_ = i; + + UpdateLabel(Value()); +} + +void FloatSlider::ConvertValue(QVariant v) +{ + emit ValueChanged(v.toDouble()); +} diff --git a/app/widget/slider/floatslider.h b/app/widget/slider/floatslider.h new file mode 100644 index 000000000..9a4c49bee --- /dev/null +++ b/app/widget/slider/floatslider.h @@ -0,0 +1,45 @@ +/*** + + 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 FLOATSLIDER_H +#define FLOATSLIDER_H + +#include "sliderbase.h" + +class FloatSlider : public SliderBase +{ + Q_OBJECT +public: + FloatSlider(QWidget* parent = nullptr); + + double GetValue(); + + void SetValue(const double& d); + + void SetDecimalPlaces(int i); + +signals: + void ValueChanged(double); + +private slots: + void ConvertValue(QVariant v); +}; + +#endif // FLOATSLIDER_H diff --git a/app/widget/slider/integerslider.cpp b/app/widget/slider/integerslider.cpp new file mode 100644 index 000000000..9d7b4b1ff --- /dev/null +++ b/app/widget/slider/integerslider.cpp @@ -0,0 +1,42 @@ +/*** + + 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 "integerslider.h" + +IntegerSlider::IntegerSlider(QWidget* parent) : + SliderBase(kInteger, parent) +{ + connect(this, SIGNAL(ValueChanged(QVariant)), this, SLOT(ConvertValue(QVariant))); +} + +int IntegerSlider::GetValue() +{ + return Value().toInt(); +} + +void IntegerSlider::SetValue(const int &v) +{ + SliderBase::SetValue(v); +} + +void IntegerSlider::ConvertValue(QVariant v) +{ + emit ValueChanged(v.toInt()); +} diff --git a/app/widget/slider/integerslider.h b/app/widget/slider/integerslider.h new file mode 100644 index 000000000..b5554b7b8 --- /dev/null +++ b/app/widget/slider/integerslider.h @@ -0,0 +1,43 @@ +/*** + + 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 INTEGERSLIDER_H +#define INTEGERSLIDER_H + +#include "sliderbase.h" + +class IntegerSlider : public SliderBase +{ + Q_OBJECT +public: + IntegerSlider(QWidget* parent = nullptr); + + int GetValue(); + + void SetValue(const int& v); + +signals: + void ValueChanged(int); + +private slots: + void ConvertValue(QVariant v); +}; + +#endif // INTEGERSLIDER_H diff --git a/app/widget/slider/sliderbase.cpp b/app/widget/slider/sliderbase.cpp new file mode 100644 index 000000000..9eda9bd6b --- /dev/null +++ b/app/widget/slider/sliderbase.cpp @@ -0,0 +1,233 @@ +/*** + + 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 "sliderbase.h" + +#include +#include +#include + +SliderBase::SliderBase(Mode mode, QWidget *parent) : + QStackedWidget(parent), + decimal_places_(1), + drag_multiplier_(1.0), + mode_(mode), + dragged_(false) +{ + label_ = new SliderLabel(this); + addWidget(label_); + + editor_ = new SliderLineEdit(this); + addWidget(editor_); + + connect(label_, SIGNAL(drag_start()), this, SLOT(LabelPressed())); + connect(label_, SIGNAL(dragged(int)), this, SLOT(LabelDragged(int))); + connect(label_, SIGNAL(drag_stop()), this, SLOT(LabelClicked())); + connect(editor_, SIGNAL(Confirmed()), this, SLOT(LineEditConfirmed())); + connect(editor_, SIGNAL(Cancelled()), this, SLOT(LineEditCancelled())); + + // Set valid cursor based on mode + switch (mode_) { + case kString: + setCursor(Qt::PointingHandCursor); + value_ = ""; + break; + case kInteger: + case kFloat: + setCursor(Qt::SizeHorCursor); + value_ = 0; + break; + } + + UpdateLabel(value_); +} + +void SliderBase::SetDragMultiplier(const double &d) +{ + drag_multiplier_ = d; +} + +const QVariant &SliderBase::Value() +{ + return value_; +} + +void SliderBase::SetValue(const QVariant &v) +{ + value_ = v; + + UpdateLabel(value_); +} + +void SliderBase::changeEvent(QEvent *e) +{ + if (e->type() == QEvent::LanguageChange) { + UpdateLabel(value_); + } + QStackedWidget::changeEvent(e); +} + +void SliderBase::UpdateLabel(const QVariant &v) +{ + switch (mode_) { + case kString: + { + QString vstr = v.toString(); + + if (vstr.isEmpty()) { + label_->setText(tr("(none)")); + } else { + label_->setText(vstr); + } + break; + } + case kInteger: + label_->setText(v.toString()); + break; + case kFloat: + // For floats, we show a limited number of decimal places + label_->setText(QString::number(v.toDouble(), 'f', decimal_places_)); + break; + } +} + +void SliderBase::LabelPressed() +{ + dragged_ = false; + + if (mode_ != kString) { + temp_drag_value_ = value_.toDouble(); + } +} + +void SliderBase::LabelClicked() +{ + if (dragged_) { + // This was a drag + switch (mode_) { + case kString: + // No-op + break; + case kInteger: + value_ = qRound(temp_drag_value_); + break; + case kFloat: + value_ = temp_drag_value_; + break; + } + + UpdateLabel(value_); + } else { + // This was a simple click + + // Load label's text into editor + editor_->setText(label_->text()); + + // Show editor + setCurrentWidget(editor_); + + // Select all text in the editor + editor_->setFocus(); + editor_->selectAll(); + } +} + +void SliderBase::LabelDragged(int i) +{ + switch (mode_) { + case kString: + // No dragging supported for strings + break; + case kInteger: + case kFloat: + { + double real_drag = static_cast(i) * drag_multiplier_; + + temp_drag_value_ += real_drag; + + if (mode_ == kInteger) { + UpdateLabel(qRound(temp_drag_value_)); + } else { + UpdateLabel(temp_drag_value_); + } + break; + } + } + + dragged_ = true; +} + +void SliderBase::LineEditConfirmed() +{ + bool is_valid = true; + QVariant test_val; + + // Check whether the entered value is valid for this mode + switch (mode_) { + case kString: + // Anything goes for a string + test_val = editor_->text(); + break; + case kInteger: + case kFloat: + // Allow both floats and integers for either modes + test_val = editor_->text().toDouble(&is_valid); + + if (is_valid && mode_ == kInteger) { + // But for an integer, we round it + test_val = qRound(test_val.toDouble()); + } + break; + } + + if (is_valid) { + value_ = test_val; + + UpdateLabel(value_); + + emit ValueChanged(value_); + + setCurrentWidget(label_); + } else { + // Ensure the editor focusing out when the messagebox appears does not cause another messagebox + editor_->blockSignals(true); + + QMessageBox::critical(this, + tr("Invalid Value"), + tr("The entered value is not valid for this field."), + QMessageBox::Ok); + + // Refocus editor + editor_->setFocus(); + + editor_->blockSignals(false); + } +} + +void SliderBase::LineEditCancelled() +{ + // Ensure editor doesn't signal that the focus is lost + editor_->blockSignals(true); + + // Set widget back to label + setCurrentWidget(label_); + + editor_->blockSignals(false); +} diff --git a/app/widget/slider/sliderbase.h b/app/widget/slider/sliderbase.h new file mode 100644 index 000000000..1908daf54 --- /dev/null +++ b/app/widget/slider/sliderbase.h @@ -0,0 +1,84 @@ +/*** + + 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 SLIDERBASE_H +#define SLIDERBASE_H + +#include + +#include "sliderlabel.h" +#include "sliderlineedit.h" + +class SliderBase : public QStackedWidget +{ + Q_OBJECT +public: + enum Mode { + kString, + kInteger, + kFloat + }; + + SliderBase(Mode mode, QWidget* parent = nullptr); + + void SetDragMultiplier(const double& d); + +signals: + void ValueChanged(QVariant v); + +protected: + const QVariant& Value(); + + void SetValue(const QVariant& v); + + void UpdateLabel(const QVariant& v); + + virtual void changeEvent(QEvent* e) override; + + int decimal_places_; + + double drag_multiplier_; + +private: + SliderLabel* label_; + + SliderLineEdit* editor_; + + QVariant value_; + + Mode mode_; + + bool dragged_; + + double temp_drag_value_; + +private slots: + void LabelPressed(); + + void LabelClicked(); + + void LabelDragged(int i); + + void LineEditConfirmed(); + + void LineEditCancelled(); +}; + +#endif // SLIDERBASE_H diff --git a/app/widget/slider/sliderlabel.cpp b/app/widget/slider/sliderlabel.cpp new file mode 100644 index 000000000..a72fda395 --- /dev/null +++ b/app/widget/slider/sliderlabel.cpp @@ -0,0 +1,72 @@ +/*** + + 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 "sliderlabel.h" + +#include +#include + +SliderLabel::SliderLabel(QWidget *parent) : + QLabel(parent) +{ + // Use highlight color as font color + setForegroundRole(QPalette::Highlight); + + // Set underlined + QFont f = font(); + f.setUnderline(true); + setFont(f); +} + +void SliderLabel::mousePressEvent(QMouseEvent *ev) +{ + QLabel::mousePressEvent(ev); + + drag_start_ = QCursor::pos(); + + static_cast(QApplication::instance())->setOverrideCursor(Qt::BlankCursor); + + emit drag_start(); +} + +void SliderLabel::mouseMoveEvent(QMouseEvent *ev) +{ + QLabel::mouseMoveEvent(ev); + + QPoint current_pos = QCursor::pos(); + + int x_mvmt = current_pos.x() - drag_start_.x(); + int y_mvmt = drag_start_.y() - current_pos.y(); + + emit dragged(x_mvmt + y_mvmt); + + // Keep cursor in the same position + QCursor::setPos(drag_start_); +} + +void SliderLabel::mouseReleaseEvent(QMouseEvent *ev) +{ + QWidget::mouseReleaseEvent(ev); + + // Emit a clicked signal + emit drag_stop(); + + static_cast(QApplication::instance())->restoreOverrideCursor(); +} diff --git a/app/widget/slider/sliderlabel.h b/app/widget/slider/sliderlabel.h new file mode 100644 index 000000000..f588cdeef --- /dev/null +++ b/app/widget/slider/sliderlabel.h @@ -0,0 +1,51 @@ +/*** + + 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 SLIDERLABEL_H +#define SLIDERLABEL_H + +#include + +class SliderLabel : public QLabel +{ + Q_OBJECT +public: + SliderLabel(QWidget* parent); + +protected: + void mousePressEvent(QMouseEvent *ev) override; + + void mouseMoveEvent(QMouseEvent *ev) override; + + void mouseReleaseEvent(QMouseEvent *ev) override; + +signals: + void dragged(int x); + + void drag_start(); + + void drag_stop(); + +private: + QPoint drag_start_; + +}; + +#endif // SLIDERLABEL_H diff --git a/app/widget/slider/sliderlineedit.cpp b/app/widget/slider/sliderlineedit.cpp new file mode 100644 index 000000000..99ef499da --- /dev/null +++ b/app/widget/slider/sliderlineedit.cpp @@ -0,0 +1,51 @@ +/*** + + 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 "sliderlineedit.h" + +#include + +SliderLineEdit::SliderLineEdit(QWidget *parent) : + QLineEdit(parent) +{ + +} + +void SliderLineEdit::keyPressEvent(QKeyEvent *e) +{ + switch (e->key()) { + case Qt::Key_Return: + case Qt::Key_Enter: + emit Confirmed(); + break; + case Qt::Key_Escape: + emit Cancelled(); + break; + default: + QLineEdit::keyPressEvent(e); + } +} + +void SliderLineEdit::focusOutEvent(QFocusEvent *e) +{ + QLineEdit::focusOutEvent(e); + + emit Confirmed(); +} diff --git a/app/widget/slider/sliderlineedit.h b/app/widget/slider/sliderlineedit.h new file mode 100644 index 000000000..f2c0ed57c --- /dev/null +++ b/app/widget/slider/sliderlineedit.h @@ -0,0 +1,45 @@ +/*** + + 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 SLIDERLINEEDIT_H +#define SLIDERLINEEDIT_H + +#include + +class SliderLineEdit : public QLineEdit +{ + Q_OBJECT +public: + SliderLineEdit(QWidget* parent); + +signals: + void Confirmed(); + + void Cancelled(); + +protected: + void keyPressEvent(QKeyEvent *) override; + + void focusOutEvent(QFocusEvent *) override; + + +}; + +#endif // SLIDERLINEEDIT_H diff --git a/app/widget/slider/stringslider.cpp b/app/widget/slider/stringslider.cpp new file mode 100644 index 000000000..23d01262f --- /dev/null +++ b/app/widget/slider/stringslider.cpp @@ -0,0 +1,42 @@ +/*** + + 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 "stringslider.h" + +StringSlider::StringSlider(QWidget* parent) : + SliderBase(kString, parent) +{ + connect(this, SIGNAL(ValueChanged(QVariant)), this, SLOT(ConvertValue(QVariant))); +} + +QString StringSlider::GetValue() +{ + return Value().toString(); +} + +void StringSlider::SetValue(const QString &v) +{ + SliderBase::SetValue(v); +} + +void StringSlider::ConvertValue(QVariant v) +{ + emit ValueChanged(v.toString()); +} diff --git a/app/widget/slider/stringslider.h b/app/widget/slider/stringslider.h new file mode 100644 index 000000000..020a46f9e --- /dev/null +++ b/app/widget/slider/stringslider.h @@ -0,0 +1,45 @@ +/*** + + 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 STRINGSLIDER_H +#define STRINGSLIDER_H + +#include "sliderbase.h" + +class StringSlider : public SliderBase +{ + Q_OBJECT +public: + StringSlider(QWidget* parent = nullptr); + + void SetDragMultiplier(const double& d) = delete; + + QString GetValue(); + + void SetValue(const QString& v); + +signals: + void ValueChanged(QString); + +private slots: + void ConvertValue(QVariant v); +}; + +#endif // STRINGSLIDER_H