diff --git a/app/widget/marker/CMakeLists.txt b/app/widget/marker/CMakeLists.txt new file mode 100644 index 000000000..4ec5cab0d --- /dev/null +++ b/app/widget/marker/CMakeLists.txt @@ -0,0 +1,22 @@ +# Olive - Non-Linear Video Editor +# Copyright (C) 2021 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/marker/marker.h + widget/marker/marker.cpp + PARENT_SCOPE +) \ No newline at end of file diff --git a/app/widget/marker/marker.cpp b/app/widget/marker/marker.cpp new file mode 100644 index 000000000..b6df9e423 --- /dev/null +++ b/app/widget/marker/marker.cpp @@ -0,0 +1,100 @@ +/*** + + Olive - Non-Linear Video Editor + Copyright (C) 2021 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 "marker.h" + +#include + +#include "common/qtutils.h" +#include "ui/colorcoding.h" +#include "widget/menu/menu.h" +#include "widget/menu/menushared.h" + +namespace olive { + +Marker::Marker(QWidget *parent) : + QWidget(parent), + marker_color_(Qt::green) +{ + setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + setMinimumSize(20, 20); + setContextMenuPolicy(Qt::CustomContextMenu); + + connect(this, &Marker::customContextMenuRequested, this, &Marker::ShowContextMenu); + + color_coding_menu_ = new ColorLabelMenu(); + connect(color_coding_menu_, &ColorLabelMenu::ColorSelected, this, &Marker::SetColor); +} + +void Marker::paintEvent(QPaintEvent *event) +{ + QFontMetrics fm = fontMetrics(); + + int text_height = fm.height(); + int marker_width_ = QtUtils::QFontMetricsWidth(fm, "H"); + + int y = text_height; //13 + + int half_width = marker_width_ / 2; + + int x = half_width; //3 + + if (x + half_width < 0 || x - half_width > width()) { + return; + } + + QPainter p(this); + p.setPen(Qt::black); + p.setBrush(marker_color_); + + p.setRenderHint(QPainter::Antialiasing); + + int half_text_height = text_height / 3; + + QPoint points[] = { + QPoint(x, y), + QPoint(x - half_width, y - half_text_height), + QPoint(x - half_width, y - text_height), + QPoint(x + 1 + half_width, y - text_height), + QPoint(x + 1 + half_width, y - half_text_height), + QPoint(x + 1, y), + }; + + p.drawPolygon(points, 6); + + p.setRenderHint(QPainter::Antialiasing, false); +} + +void Marker::ShowContextMenu() { + Menu m(this); + + m.addMenu(color_coding_menu_); + + m.exec(QCursor::pos()); +} + +void Marker::SetColor(int c) +{ + marker_color_ = ColorCoding::GetColor(c).toQColor(); + + update(); +} + +} // namespace olive \ No newline at end of file diff --git a/app/widget/marker/marker.h b/app/widget/marker/marker.h new file mode 100644 index 000000000..ed84f8d45 --- /dev/null +++ b/app/widget/marker/marker.h @@ -0,0 +1,58 @@ +/*** + + Olive - Non-Linear Video Editor + Copyright (C) 2021 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 MARKER_H +#define MARKER_H + +#include +#include + +#include "common/define.h" +#include "widget/colorlabelmenu/colorlabelmenu.h" + +namespace olive { + +class Marker : public QWidget { + Q_OBJECT + public: + Marker(QWidget* parent = nullptr); + + protected: + void paintEvent(QPaintEvent* event) override; + //virtual void mouseReleaseEvent(QMouseEvent* event) override; + //virtual void mouseDoubleClickEvent(QMouseEvent* event) override; + + signals: + //void MouseClicked(); + //void MouseDoubleClicked(); + + private: + ColorLabelMenu* color_coding_menu_; + + QColor marker_color_; + + private slots: + void ShowContextMenu(); + void SetColor(int c); +}; + +} // namespace olive + +#endif // MARKER_H