diff --git a/app/widget/colorlabelmenu/CMakeLists.txt b/app/widget/colorlabelmenu/CMakeLists.txt index 221b11e23..0879cb270 100644 --- a/app/widget/colorlabelmenu/CMakeLists.txt +++ b/app/widget/colorlabelmenu/CMakeLists.txt @@ -20,7 +20,5 @@ set(OLIVE_SOURCES widget/colorlabelmenu/colorcodingcombobox.h widget/colorlabelmenu/colorlabelmenu.cpp widget/colorlabelmenu/colorlabelmenu.h - widget/colorlabelmenu/colorlabelmenuitem.cpp - widget/colorlabelmenu/colorlabelmenuitem.h PARENT_SCOPE ) diff --git a/app/widget/colorlabelmenu/colorlabelmenu.cpp b/app/widget/colorlabelmenu/colorlabelmenu.cpp index 8dfbb0e42..cbd36186b 100644 --- a/app/widget/colorlabelmenu/colorlabelmenu.cpp +++ b/app/widget/colorlabelmenu/colorlabelmenu.cpp @@ -21,6 +21,7 @@ #include "colorlabelmenu.h" #include +#include #include #include "ui/colorcoding.h" @@ -30,17 +31,22 @@ namespace olive { ColorLabelMenu::ColorLabelMenu(QWidget *parent) : Menu(parent) { + // Used for size calculations + int box_size = fontMetrics().height(); + + color_items_.resize(ColorCoding::standard_colors().size()); for (int i=0; iSetColor(ColorCoding::standard_colors().at(i)); - color_items_.append(item); + QPixmap p(box_size, box_size); - QWidgetAction* a = new QWidgetAction(this); - Menu::ConformItem(a, QStringLiteral("colorlabel%1").arg(i), this, &ColorLabelMenu::ActionTriggered); + QPainter painter(&p); + painter.setPen(Qt::black); + painter.setBrush(ColorCoding::standard_colors().at(i).toQColor()); + painter.drawRect(p.rect().adjusted(0, 0, -1, -1)); + + QAction *a = AddItem(QStringLiteral("colorlabel%1").arg(i), this, &ColorLabelMenu::ActionTriggered); + a->setIcon(p); a->setData(i); - a->setDefaultWidget(item); - - this->addAction(a); + color_items_.replace(i, a); } Retranslate(); @@ -60,7 +66,7 @@ void ColorLabelMenu::Retranslate() this->setTitle(tr("Color")); for (int i=0; iSetText(ColorCoding::GetColorName(i)); + color_items_.at(i)->setText(ColorCoding::GetColorName(i)); } } diff --git a/app/widget/colorlabelmenu/colorlabelmenu.h b/app/widget/colorlabelmenu/colorlabelmenu.h index 86c5fe5cd..5a7ee83fb 100644 --- a/app/widget/colorlabelmenu/colorlabelmenu.h +++ b/app/widget/colorlabelmenu/colorlabelmenu.h @@ -21,7 +21,6 @@ #ifndef COLORLABELMENU_H #define COLORLABELMENU_H -#include "colorlabelmenuitem.h" #include "widget/menu/menu.h" namespace olive { @@ -40,7 +39,7 @@ signals: private: void Retranslate(); - QVector color_items_; + QVector color_items_; private slots: void ActionTriggered(); diff --git a/app/widget/colorlabelmenu/colorlabelmenuitem.cpp b/app/widget/colorlabelmenu/colorlabelmenuitem.cpp deleted file mode 100644 index 935427bac..000000000 --- a/app/widget/colorlabelmenu/colorlabelmenuitem.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/*** - - Olive - Non-Linear Video Editor - Copyright (C) 2022 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 "colorlabelmenuitem.h" - -#include - -#include "ui/style/style.h" - -namespace olive { - -ColorLabelMenuItem::ColorLabelMenuItem(QWidget* parent) : - QWidget(parent) -{ - int text_height = fontMetrics().height(); - int padding = text_height/4; - - QHBoxLayout* layout = new QHBoxLayout(this); - layout->setMargin(padding); - layout->setSpacing(padding); - - box_ = new ColorPreviewBox(); - box_->setFixedSize(text_height, text_height); - layout->addWidget(box_); - - label_ = new QLabel(); - layout->addWidget(label_); -} - -void ColorLabelMenuItem::SetText(const QString &text) -{ - label_->setText(text); -} - -void ColorLabelMenuItem::SetColor(const Color &color) -{ - box_->SetColor(color); -} - -} diff --git a/app/widget/colorlabelmenu/colorlabelmenuitem.h b/app/widget/colorlabelmenu/colorlabelmenuitem.h deleted file mode 100644 index 29307d681..000000000 --- a/app/widget/colorlabelmenu/colorlabelmenuitem.h +++ /dev/null @@ -1,48 +0,0 @@ -/*** - - Olive - Non-Linear Video Editor - Copyright (C) 2022 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 COLORLABELMENUITEM_H -#define COLORLABELMENUITEM_H - -#include -#include - -#include "widget/colorwheel/colorpreviewbox.h" - -namespace olive { - -class ColorLabelMenuItem : public QWidget -{ -public: - ColorLabelMenuItem(QWidget* parent = nullptr); - - void SetText(const QString& text); - - void SetColor(const Color& color); - -private: - ColorPreviewBox* box_; - QLabel* label_; - -}; - -} - -#endif // COLORLABELMENUITEM_H