From 3ce29f909302a27703d97dc99a68264b5bfabfeb Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Fri, 22 Jan 2021 17:07:42 +1100 Subject: [PATCH] apparently these weren't committed before, whoops --- app/ui/colorcoding.cpp | 99 +++++++++++++++++++ app/ui/colorcoding.h | 50 ++++++++++ .../colorlabelmenu/colorcodingcombobox.cpp | 53 ++++++++++ .../colorlabelmenu/colorcodingcombobox.h | 52 ++++++++++ 4 files changed, 254 insertions(+) create mode 100644 app/ui/colorcoding.cpp create mode 100644 app/ui/colorcoding.h create mode 100644 app/widget/colorlabelmenu/colorcodingcombobox.cpp create mode 100644 app/widget/colorlabelmenu/colorcodingcombobox.h diff --git a/app/ui/colorcoding.cpp b/app/ui/colorcoding.cpp new file mode 100644 index 000000000..ff6df5d00 --- /dev/null +++ b/app/ui/colorcoding.cpp @@ -0,0 +1,99 @@ +/*** + + Olive - Non-Linear Video Editor + Copyright (C) 2020 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 "colorcoding.h" + +namespace olive { + +QVector ColorCoding::colors_ = { + Color(1.0, 0.0, 0.0), + Color(0.5, 0.0, 0.0), + Color(1.0, 0.5, 0.0), + Color(0.5, 0.25, 0.0), + Color(1.0, 1.0, 0.0), + Color(0.5, 0.5, 0.0), + Color(0.0, 1.0, 0.0), + Color(0.0, 0.5, 0.0), + Color(0.0, 1.0, 1.0), + Color(0.0, 0.5, 0.5), + Color(0.0, 0.0, 1.0), + Color(0.0, 0.0, 0.5), + Color(1.0, 0.0, 1.0), + Color(0.5, 0.0, 1.0), + Color(0.8, 0.8, 0.8), + Color(0.5, 0.5, 0.5) +}; + +QString ColorCoding::GetColorName(int c) +{ + // FIXME: I'm sure we could come up with more creative names for these colors + switch (c) { + case 0: + return tr("Red"); + case 1: + return tr("Maroon"); + case 2: + return tr("Orange"); + case 3: + return tr("Brown"); + case 4: + return tr("Yellow"); + case 5: + return tr("Olive"); + case 6: + return tr("Lime"); + case 7: + return tr("Green"); + case 8: + return tr("Cyan"); + case 9: + return tr("Teal"); + case 10: + return tr("Blue"); + case 11: + return tr("Navy"); + case 12: + return tr("Pink"); + case 13: + return tr("Purple"); + case 14: + return tr("Silver"); + case 15: + return tr("Gray"); + } + + return QString(); +} + +Color ColorCoding::GetColor(int c) +{ + return colors_.at(c); +} + +Qt::GlobalColor ColorCoding::GetUISelectorColor(const Color &c) +{ + if (c.GetRoughLuminance() > 0.66) { + return Qt::black; + } else { + return Qt::white; + } +} + +} diff --git a/app/ui/colorcoding.h b/app/ui/colorcoding.h new file mode 100644 index 000000000..b21e07922 --- /dev/null +++ b/app/ui/colorcoding.h @@ -0,0 +1,50 @@ +/*** + + Olive - Non-Linear Video Editor + Copyright (C) 2020 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 COLORCODING_H +#define COLORCODING_H + +#include "render/color.h" + +namespace olive { + +class ColorCoding : public QObject +{ + Q_OBJECT +public: + static QString GetColorName(int c); + + static Color GetColor(int c); + + static Qt::GlobalColor GetUISelectorColor(const Color& c); + + static const QVector& standard_colors() + { + return colors_; + } + +private: + static QVector colors_; + +}; + +} + +#endif // COLORCODING_H diff --git a/app/widget/colorlabelmenu/colorcodingcombobox.cpp b/app/widget/colorlabelmenu/colorcodingcombobox.cpp new file mode 100644 index 000000000..1bd63f574 --- /dev/null +++ b/app/widget/colorlabelmenu/colorcodingcombobox.cpp @@ -0,0 +1,53 @@ +/*** + + Olive - Non-Linear Video Editor + Copyright (C) 2020 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 "colorcodingcombobox.h" + +#include "ui/colorcoding.h" + +namespace olive { + +ColorCodingComboBox::ColorCodingComboBox(QWidget *parent) : + QComboBox(parent) +{ + SetColor(0); +} + +void ColorCodingComboBox::showPopup() +{ + ColorLabelMenu menu(this); + + menu.setMinimumWidth(width()); + + QAction* a = menu.exec(parentWidget()->mapToGlobal(pos())); + + if (a) { + SetColor(a->data().toInt()); + } +} + +void ColorCodingComboBox::SetColor(int index) +{ + clear(); + addItem(ColorCoding::GetColorName(index)); + index_ = index; +} + +} diff --git a/app/widget/colorlabelmenu/colorcodingcombobox.h b/app/widget/colorlabelmenu/colorcodingcombobox.h new file mode 100644 index 000000000..0edeb2470 --- /dev/null +++ b/app/widget/colorlabelmenu/colorcodingcombobox.h @@ -0,0 +1,52 @@ +/*** + + Olive - Non-Linear Video Editor + Copyright (C) 2020 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 COLORCODINGCOMBOBOX_H +#define COLORCODINGCOMBOBOX_H + +#include + +#include "widget/colorlabelmenu/colorlabelmenu.h" + +namespace olive { + +class ColorCodingComboBox : public QComboBox +{ + Q_OBJECT +public: + ColorCodingComboBox(QWidget* parent = nullptr); + + virtual void showPopup() override; + + void SetColor(int index); + + int GetSelectedColor() const + { + return index_; + } + +private: + int index_; + +}; + +} + +#endif // COLORCODINGCOMBOBOX_H