From bcc8eaee55fed7ce632e318810d22ea118a1b790 Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Wed, 1 Apr 2020 17:57:19 +1100 Subject: [PATCH] colordialog: began widgets and dialogs for a managed color picker --- app/dialog/CMakeLists.txt | 1 + app/dialog/color/CMakeLists.txt | 22 +++++++++ app/dialog/color/colordialog.cpp | 28 +++++++++++ app/dialog/color/colordialog.h | 19 +++++++ app/widget/CMakeLists.txt | 2 + app/widget/colorbutton/CMakeLists.txt | 22 +++++++++ app/widget/colorbutton/colorbutton.cpp | 15 ++++++ app/widget/colorbutton/colorbutton.h | 20 ++++++++ app/widget/colorwheel/CMakeLists.txt | 22 +++++++++ app/widget/colorwheel/colorwheelwidget.cpp | 49 +++++++++++++++++++ app/widget/colorwheel/colorwheelwidget.h | 16 ++++++ .../nodeparamviewwidgetbridge.cpp | 7 ++- 12 files changed, 222 insertions(+), 1 deletion(-) create mode 100644 app/dialog/color/CMakeLists.txt create mode 100644 app/dialog/color/colordialog.cpp create mode 100644 app/dialog/color/colordialog.h create mode 100644 app/widget/colorbutton/CMakeLists.txt create mode 100644 app/widget/colorbutton/colorbutton.cpp create mode 100644 app/widget/colorbutton/colorbutton.h create mode 100644 app/widget/colorwheel/CMakeLists.txt create mode 100644 app/widget/colorwheel/colorwheelwidget.cpp create mode 100644 app/widget/colorwheel/colorwheelwidget.h diff --git a/app/dialog/CMakeLists.txt b/app/dialog/CMakeLists.txt index 01f013630..140a3ce6e 100644 --- a/app/dialog/CMakeLists.txt +++ b/app/dialog/CMakeLists.txt @@ -16,6 +16,7 @@ add_subdirectory(about) add_subdirectory(actionsearch) +add_subdirectory(color) add_subdirectory(export) add_subdirectory(footageproperties) add_subdirectory(keyframeproperties) diff --git a/app/dialog/color/CMakeLists.txt b/app/dialog/color/CMakeLists.txt new file mode 100644 index 000000000..f36cd6b5d --- /dev/null +++ b/app/dialog/color/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/color/colordialog.h + dialog/color/colordialog.cpp + PARENT_SCOPE +) diff --git a/app/dialog/color/colordialog.cpp b/app/dialog/color/colordialog.cpp new file mode 100644 index 000000000..d96be4b71 --- /dev/null +++ b/app/dialog/color/colordialog.cpp @@ -0,0 +1,28 @@ +#include "colordialog.h" + +#include +#include +#include + +#include "widget/colorwheel/colorwheelwidget.h" + +ColorDialog::ColorDialog(ColorManager* color_manager, QWidget *parent) : + QDialog(parent), + color_manager_(color_manager) +{ + QVBoxLayout* layout = new QVBoxLayout(this); + + QSplitter* splitter = new QSplitter(Qt::Horizontal); + layout->addWidget(splitter); + + ColorWheelWidget* cww1 = new ColorWheelWidget(); + ColorWheelWidget* cww2 = new ColorWheelWidget(); + + splitter->addWidget(cww1); + splitter->addWidget(cww2); + + QDialogButtonBox* buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); + connect(buttons, &QDialogButtonBox::accepted, this, &QDialog::accept); + connect(buttons, &QDialogButtonBox::rejected, this, &QDialog::reject); + layout->addWidget(buttons); +} diff --git a/app/dialog/color/colordialog.h b/app/dialog/color/colordialog.h new file mode 100644 index 000000000..19aa16678 --- /dev/null +++ b/app/dialog/color/colordialog.h @@ -0,0 +1,19 @@ +#ifndef COLORDIALOG_H +#define COLORDIALOG_H + +#include + +#include "render/color.h" +#include "render/colormanager.h" + +class ColorDialog : public QDialog +{ +public: + ColorDialog(ColorManager* color_manager, QWidget* parent = nullptr); + +private: + ColorManager* color_manager_; + +}; + +#endif // COLORDIALOG_H diff --git a/app/widget/CMakeLists.txt b/app/widget/CMakeLists.txt index 1832bae26..1eecf342e 100644 --- a/app/widget/CMakeLists.txt +++ b/app/widget/CMakeLists.txt @@ -16,6 +16,8 @@ add_subdirectory(audiomonitor) add_subdirectory(clickablelabel) +add_subdirectory(colorbutton) +add_subdirectory(colorwheel) add_subdirectory(columnedgridlayout) add_subdirectory(curvewidget) add_subdirectory(flowlayout) diff --git a/app/widget/colorbutton/CMakeLists.txt b/app/widget/colorbutton/CMakeLists.txt new file mode 100644 index 000000000..b7a5da383 --- /dev/null +++ b/app/widget/colorbutton/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} + widget/colorbutton/colorbutton.h + widget/colorbutton/colorbutton.cpp + PARENT_SCOPE +) diff --git a/app/widget/colorbutton/colorbutton.cpp b/app/widget/colorbutton/colorbutton.cpp new file mode 100644 index 000000000..feb95afcb --- /dev/null +++ b/app/widget/colorbutton/colorbutton.cpp @@ -0,0 +1,15 @@ +#include "colorbutton.h" + +#include "dialog/color/colordialog.h" + +ColorButton::ColorButton(QWidget *parent) : + QPushButton(parent) +{ + connect(this, &ColorButton::clicked, this, &ColorButton::ShowColorDialog); +} + +void ColorButton::ShowColorDialog() +{ + ColorDialog cd(nullptr); + cd.exec(); +} diff --git a/app/widget/colorbutton/colorbutton.h b/app/widget/colorbutton/colorbutton.h new file mode 100644 index 000000000..132182b0a --- /dev/null +++ b/app/widget/colorbutton/colorbutton.h @@ -0,0 +1,20 @@ +#ifndef COLORBUTTON_H +#define COLORBUTTON_H + +#include + +class ColorButton : public QPushButton +{ + Q_OBJECT +public: + ColorButton(QWidget* parent = nullptr); + +signals: + void ColorChanged(); + +private slots: + void ShowColorDialog(); + +}; + +#endif // COLORBUTTON_H diff --git a/app/widget/colorwheel/CMakeLists.txt b/app/widget/colorwheel/CMakeLists.txt new file mode 100644 index 000000000..cfbafbbf5 --- /dev/null +++ b/app/widget/colorwheel/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} + widget/colorwheel/colorwheelwidget.h + widget/colorwheel/colorwheelwidget.cpp + PARENT_SCOPE +) diff --git a/app/widget/colorwheel/colorwheelwidget.cpp b/app/widget/colorwheel/colorwheelwidget.cpp new file mode 100644 index 000000000..3ea153325 --- /dev/null +++ b/app/widget/colorwheel/colorwheelwidget.cpp @@ -0,0 +1,49 @@ +#include "colorwheelwidget.h" + +#include +#include + +#define RADIAN_TO_0_1_RANGE 0.15915494309188486110703542313983 + +ColorWheelWidget::ColorWheelWidget(QWidget *parent) : + QWidget(parent) +{ + +} + +void ColorWheelWidget::paintEvent(QPaintEvent *event) +{ + QWidget::paintEvent(event); + + QPainter p(this); + + qreal radius = qMin(width(), height()) / 2; + QPoint center = rect().center(); + + p.setPen(Qt::red); + + int x_start = center.x() - radius; + int x_end= center.x() + radius; + int y_start = center.y() - radius; + int y_end= center.y() + radius; + + for (int i=x_start;i + +class ColorWheelWidget : public QWidget +{ +public: + ColorWheelWidget(QWidget* parent = nullptr); + +protected: + virtual void paintEvent(QPaintEvent* event) override; + +}; + +#endif // COLORWHEELWIDGET_H diff --git a/app/widget/nodeparamview/nodeparamviewwidgetbridge.cpp b/app/widget/nodeparamview/nodeparamviewwidgetbridge.cpp index 9688e0b99..79b152371 100644 --- a/app/widget/nodeparamview/nodeparamviewwidgetbridge.cpp +++ b/app/widget/nodeparamview/nodeparamviewwidgetbridge.cpp @@ -12,6 +12,7 @@ #include "nodeparamviewundo.h" #include "project/item/sequence/sequence.h" #include "undo/undostack.h" +#include "widget/colorbutton/colorbutton.h" #include "widget/footagecombobox/footagecombobox.h" #include "widget/slider/floatslider.h" #include "widget/slider/integerslider.h" @@ -92,8 +93,12 @@ void NodeParamViewWidgetBridge::CreateWidgets() // FIXME: File selector break; case NodeParam::kColor: - // FIXME: Color selector + { + ColorButton* color_button = new ColorButton(); + widgets_.append(color_button); + connect(color_button, &ColorButton::ColorChanged, this, &NodeParamViewWidgetBridge::WidgetCallback); break; + } case NodeParam::kText: { QLineEdit* line_edit = new QLineEdit();