colorlabelmenu: improve usability and code quality
This commit is contained in:
@@ -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
|
||||
)
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "colorlabelmenu.h"
|
||||
|
||||
#include <QEvent>
|
||||
#include <QPainter>
|
||||
#include <QWidgetAction>
|
||||
|
||||
#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; i<ColorCoding::standard_colors().size(); i++) {
|
||||
ColorLabelMenuItem* item = new ColorLabelMenuItem();
|
||||
item->SetColor(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; i<color_items_.size(); i++) {
|
||||
color_items_.at(i)->SetText(ColorCoding::GetColorName(i));
|
||||
color_items_.at(i)->setText(ColorCoding::GetColorName(i));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<ColorLabelMenuItem*> color_items_;
|
||||
QVector<QAction*> color_items_;
|
||||
|
||||
private slots:
|
||||
void ActionTriggered();
|
||||
|
||||
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
***/
|
||||
|
||||
#include "colorlabelmenuitem.h"
|
||||
|
||||
#include <QHBoxLayout>
|
||||
|
||||
#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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
***/
|
||||
|
||||
#ifndef COLORLABELMENUITEM_H
|
||||
#define COLORLABELMENUITEM_H
|
||||
|
||||
#include <QLabel>
|
||||
#include <QWidget>
|
||||
|
||||
#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
|
||||
Reference in New Issue
Block a user