stash SVGs that are continuously reused

This commit is contained in:
itsmattkc
2019-03-10 17:31:00 +11:00
parent 9fc1bc3e1d
commit d768871c2d
13 changed files with 248 additions and 184 deletions
+66 -68
View File
@@ -20,8 +20,6 @@
#include "collapsiblewidget.h"
#include "ui/checkboxex.h"
#include <QDebug>
#include <QLabel>
#include <QLayout>
@@ -32,113 +30,113 @@
#include <QWidget>
#include <QPainter>
#include "ui/checkboxex.h"
#include "ui/icons.h"
#include "debug.h"
CollapsibleWidget::CollapsibleWidget(QWidget* parent) : QWidget(parent) {
selected = false;
selected = false;
layout = new QVBoxLayout(this);
layout->setMargin(0);
layout->setSpacing(0);
layout = new QVBoxLayout(this);
layout->setMargin(0);
layout->setSpacing(0);
title_bar = new CollapsibleWidgetHeader(this);
title_bar->setFocusPolicy(Qt::ClickFocus);
title_bar->setAutoFillBackground(true);
title_bar_layout = new QHBoxLayout(title_bar);
title_bar_layout->setMargin(5);
enabled_check = new CheckboxEx(title_bar);
enabled_check->setChecked(true);
header = new QLabel(title_bar);
collapse_button = new QPushButton(title_bar);
collapse_button->setIconSize(collapse_button->iconSize()*0.5);
collapse_button->setStyleSheet("QPushButton { border: none; }");
setText(tr("<untitled>"));
title_bar_layout->addWidget(collapse_button);
title_bar_layout->addWidget(enabled_check);
title_bar_layout->addWidget(header);
title_bar_layout->addStretch();
layout->addWidget(title_bar);
title_bar = new CollapsibleWidgetHeader(this);
title_bar->setFocusPolicy(Qt::ClickFocus);
title_bar->setAutoFillBackground(true);
title_bar_layout = new QHBoxLayout(title_bar);
title_bar_layout->setMargin(5);
enabled_check = new CheckboxEx(title_bar);
enabled_check->setChecked(true);
header = new QLabel(title_bar);
collapse_button = new QPushButton(title_bar);
collapse_button->setIconSize(collapse_button->iconSize()*0.5);
collapse_button->setStyleSheet("QPushButton { border: none; }");
setText(tr("<untitled>"));
title_bar_layout->addWidget(collapse_button);
title_bar_layout->addWidget(enabled_check);
title_bar_layout->addWidget(header);
title_bar_layout->addStretch();
layout->addWidget(title_bar);
tri_down_ = QIcon(":/icons/tri-down.svg");
tri_right_ = QIcon(":/icons/tri-right.svg");
connect(title_bar, SIGNAL(select(bool, bool)), this, SLOT(header_click(bool, bool)));
connect(title_bar, SIGNAL(select(bool, bool)), this, SLOT(header_click(bool, bool)));
set_button_icon(true);
set_button_icon(true);
contents = nullptr;
contents = nullptr;
}
void CollapsibleWidget::header_click(bool s, bool deselect) {
selected = s;
title_bar->selected = s;
if (s) {
QPalette p = title_bar->palette();
p.setColor(QPalette::Background, QColor(255, 255, 255, 64));
title_bar->setPalette(p);
} else {
title_bar->setPalette(palette());
}
if (deselect) emit deselect_others(this);
selected = s;
title_bar->selected = s;
if (s) {
QPalette p = title_bar->palette();
p.setColor(QPalette::Background, QColor(255, 255, 255, 64));
title_bar->setPalette(p);
} else {
title_bar->setPalette(palette());
}
if (deselect) emit deselect_others(this);
}
bool CollapsibleWidget::is_focused() {
if (hasFocus()) return true;
return title_bar->hasFocus();
if (hasFocus()) return true;
return title_bar->hasFocus();
}
bool CollapsibleWidget::is_expanded() {
return contents->isVisible();
return contents->isVisible();
}
void CollapsibleWidget::set_button_icon(bool open) {
collapse_button->setIcon(open ? tri_down_ : tri_right_);
collapse_button->setIcon(open ? olive::icon::DownArrow : olive::icon::RightArrow);
}
void CollapsibleWidget::setContents(QWidget* c) {
bool existing = (contents != nullptr);
contents = c;
if (!existing) {
layout->addWidget(contents);
connect(enabled_check, SIGNAL(toggled(bool)), this, SLOT(on_enabled_change(bool)));
connect(collapse_button, SIGNAL(clicked()), this, SLOT(on_visible_change()));
}
bool existing = (contents != nullptr);
contents = c;
if (!existing) {
layout->addWidget(contents);
connect(enabled_check, SIGNAL(toggled(bool)), this, SLOT(on_enabled_change(bool)));
connect(collapse_button, SIGNAL(clicked()), this, SLOT(on_visible_change()));
}
}
void CollapsibleWidget::setText(const QString &s) {
header->setText(s);
header->setText(s);
}
void CollapsibleWidget::on_enabled_change(bool b) {
contents->setEnabled(b);
contents->setEnabled(b);
}
void CollapsibleWidget::on_visible_change() {
contents->setVisible(!contents->isVisible());
set_button_icon(contents->isVisible());
emit visibleChanged();
contents->setVisible(!contents->isVisible());
set_button_icon(contents->isVisible());
emit visibleChanged();
}
CollapsibleWidgetHeader::CollapsibleWidgetHeader(QWidget* parent) : QWidget(parent), selected(false) {
setContextMenuPolicy(Qt::CustomContextMenu);
setContextMenuPolicy(Qt::CustomContextMenu);
}
void CollapsibleWidgetHeader::mousePressEvent(QMouseEvent* event) {
if (selected) {
if ((event->modifiers() & Qt::ShiftModifier)) {
selected = false;
emit select(selected, false);
}
} else {
selected = true;
emit select(selected, !(event->modifiers() & Qt::ShiftModifier));
}
if (selected) {
if ((event->modifiers() & Qt::ShiftModifier)) {
selected = false;
emit select(selected, false);
}
} else {
selected = true;
emit select(selected, !(event->modifiers() & Qt::ShiftModifier));
}
}
void CollapsibleWidgetHeader::paintEvent(QPaintEvent *event) {
QWidget::paintEvent(event);
QPainter p(this);
QWidget::paintEvent(event);
QPainter p(this);
p.setPen(Qt::white);
int line_y = height() - 1;
int line_y = height() - 1;
p.drawLine(0, line_y, width(), line_y);
}
-3
View File
@@ -66,9 +66,6 @@ private:
QHBoxLayout* title_bar_layout;
void set_button_icon(bool open);
QIcon tri_right_;
QIcon tri_down_;
signals:
void deselect_others(QWidget*);
void visibleChanged();
+66
View File
@@ -1,3 +1,69 @@
#include "icons.h"
#include "oliveglobal.h"
QIcon olive::icon::LeftArrow;
QIcon olive::icon::RightArrow;
QIcon olive::icon::UpArrow;
QIcon olive::icon::DownArrow;
QIcon olive::icon::Diamond;
QIcon olive::icon::Clock;
QIcon olive::icon::MediaVideo;
QIcon olive::icon::MediaAudio;
QIcon olive::icon::MediaImage;
QIcon olive::icon::MediaError;
QIcon olive::icon::MediaSequence;
QIcon olive::icon::MediaFolder;
QIcon olive::icon::ViewerGoToStart;
QIcon olive::icon::ViewerPrevFrame;
QIcon olive::icon::ViewerPlay;
QIcon olive::icon::ViewerPause;
QIcon olive::icon::ViewerNextFrame;
QIcon olive::icon::ViewerGoToEnd;
QIcon olive::icon::CreateIconFromSVG(const QString &path)
{
QIcon icon;
QPixmap normal(path);
icon.addPixmap(normal, QIcon::Normal, QIcon::On);
QPixmap disabled(normal.size());
disabled.fill(Qt::transparent);
// draw semi-transparent version of icon for the disabled variant
QPainter p(&disabled);
p.setOpacity(0.5);
p.drawPixmap(0, 0, normal);
p.end();
icon.addPixmap(disabled, QIcon::Disabled, QIcon::On);
return icon;
}
void olive::icon::Initialize()
{
LeftArrow = QIcon(":/icons/tri-left.svg");
RightArrow = QIcon(":/icons/tri-right.svg");
UpArrow = QIcon(":/icons/tri-up.svg");
DownArrow = QIcon(":/icons/tri-down.svg");
Diamond = QIcon(":/icons/diamond.svg");
Clock = QIcon(":/icons/clock.svg");
MediaVideo = QIcon(":/icons/videosource.svg");
MediaAudio = QIcon(":/icons/audiosource.svg");
MediaImage = QIcon(":/icons/imagesource.svg");
MediaError = QIcon(":/icons/error.svg");
MediaSequence = QIcon(":/icons/sequence.svg");
MediaFolder = QIcon(":/icons/folder.svg");
ViewerGoToStart = CreateIconFromSVG(QStringLiteral(":/icons/prev.svg"));
ViewerPrevFrame = CreateIconFromSVG(QStringLiteral(":/icons/rew.svg"));
ViewerPlay = CreateIconFromSVG(QStringLiteral(":/icons/play.svg"));
ViewerPause = QPixmap(":/icons/pause.svg");
ViewerNextFrame = CreateIconFromSVG(QStringLiteral(":/icons/ff.svg"));
ViewerGoToEnd = CreateIconFromSVG(QStringLiteral(":/icons/next.svg"));
}
+31 -3
View File
@@ -5,9 +5,37 @@
namespace olive {
namespace icon {
extern QIcon KeyframeLeft;
extern QIcon KeyframeSet;
extern QIcon KeyframeRight;
extern QIcon LeftArrow;
extern QIcon RightArrow;
extern QIcon UpArrow;
extern QIcon DownArrow;
extern QIcon Diamond;
extern QIcon Clock;
extern QIcon MediaVideo;
extern QIcon MediaAudio;
extern QIcon MediaImage;
extern QIcon MediaError;
extern QIcon MediaSequence;
extern QIcon MediaFolder;
extern QIcon ViewerGoToStart;
extern QIcon ViewerPrevFrame;
extern QIcon ViewerPlay;
extern QIcon ViewerPause;
extern QIcon ViewerNextFrame;
extern QIcon ViewerGoToEnd;
void Initialize();
/**
* @brief Converts an SVG into a QIcon with a semi-transparent for the QIcon::Disabled property
*
* @param path
*
* Path to SVG file
*/
QIcon CreateIconFromSVG(const QString &path);
}
}
+43 -41
View File
@@ -25,62 +25,64 @@
#include <QApplication>
#include <QDesktopWidget>
#include "ui/icons.h"
KeyframeNavigator::KeyframeNavigator(QWidget *parent, bool addLeftPad) : QWidget(parent) {
key_controls = new QHBoxLayout(this);
key_controls->setSpacing(0);
key_controls->setMargin(0);
key_controls = new QHBoxLayout(this);
key_controls->setSpacing(0);
key_controls->setMargin(0);
if (addLeftPad) {
key_controls->addStretch();
}
if (addLeftPad) {
key_controls->addStretch();
}
left_key_nav = new QPushButton(this);
left_key_nav->setIcon(QIcon(":/icons/tri-left.svg"));
left_key_nav->setIconSize(left_key_nav->iconSize()*0.5);
left_key_nav->setVisible(false);
key_controls->addWidget(left_key_nav);
connect(left_key_nav, SIGNAL(clicked(bool)), this, SIGNAL(goto_previous_key()));
connect(left_key_nav, SIGNAL(clicked(bool)), this, SIGNAL(clicked()));
left_key_nav = new QPushButton(this);
left_key_nav->setIcon(olive::icon::LeftArrow);
left_key_nav->setIconSize(left_key_nav->iconSize()*0.5);
left_key_nav->setVisible(false);
key_controls->addWidget(left_key_nav);
connect(left_key_nav, SIGNAL(clicked(bool)), this, SIGNAL(goto_previous_key()));
connect(left_key_nav, SIGNAL(clicked(bool)), this, SIGNAL(clicked()));
key_addremove = new QPushButton(this);
key_addremove->setIcon(QIcon(":/icons/diamond.svg"));
key_addremove->setIconSize(key_addremove->iconSize()*0.5);
key_addremove->setVisible(false);
key_controls->addWidget(key_addremove);
connect(key_addremove, SIGNAL(clicked(bool)), this, SIGNAL(toggle_key()));
connect(key_addremove, SIGNAL(clicked(bool)), this, SIGNAL(clicked()));
key_addremove = new QPushButton(this);
key_addremove->setIcon(olive::icon::Diamond);
key_addremove->setIconSize(key_addremove->iconSize()*0.5);
key_addremove->setVisible(false);
key_controls->addWidget(key_addremove);
connect(key_addremove, SIGNAL(clicked(bool)), this, SIGNAL(toggle_key()));
connect(key_addremove, SIGNAL(clicked(bool)), this, SIGNAL(clicked()));
right_key_nav = new QPushButton(this);
right_key_nav->setIcon(QIcon(":/icons/tri-right.svg"));
right_key_nav->setIconSize(right_key_nav->iconSize()*0.5);
right_key_nav->setVisible(false);
key_controls->addWidget(right_key_nav);
connect(right_key_nav, SIGNAL(clicked(bool)), this, SIGNAL(goto_next_key()));
connect(right_key_nav, SIGNAL(clicked(bool)), this, SIGNAL(clicked()));
right_key_nav = new QPushButton(this);
right_key_nav->setIcon(olive::icon::RightArrow);
right_key_nav->setIconSize(right_key_nav->iconSize()*0.5);
right_key_nav->setVisible(false);
key_controls->addWidget(right_key_nav);
connect(right_key_nav, SIGNAL(clicked(bool)), this, SIGNAL(goto_next_key()));
connect(right_key_nav, SIGNAL(clicked(bool)), this, SIGNAL(clicked()));
keyframe_enable = new QPushButton(QIcon(":/icons/clock.svg"), "", this);
keyframe_enable->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed);
keyframe_enable->setIconSize(keyframe_enable->iconSize()*0.75);
keyframe_enable->setCheckable(true);
keyframe_enable->setToolTip(tr("Enable Keyframes"));
connect(keyframe_enable, SIGNAL(clicked(bool)), this, SIGNAL(keyframe_enabled_changed(bool)));
connect(keyframe_enable, SIGNAL(toggled(bool)), this, SLOT(keyframe_ui_enabled(bool)));
connect(keyframe_enable, SIGNAL(clicked(bool)), this, SIGNAL(clicked()));
key_controls->addWidget(keyframe_enable);
keyframe_enable = new QPushButton(olive::icon::Clock, "", this);
keyframe_enable->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed);
keyframe_enable->setIconSize(keyframe_enable->iconSize()*0.75);
keyframe_enable->setCheckable(true);
keyframe_enable->setToolTip(tr("Enable Keyframes"));
connect(keyframe_enable, SIGNAL(clicked(bool)), this, SIGNAL(keyframe_enabled_changed(bool)));
connect(keyframe_enable, SIGNAL(toggled(bool)), this, SLOT(keyframe_ui_enabled(bool)));
connect(keyframe_enable, SIGNAL(clicked(bool)), this, SIGNAL(clicked()));
key_controls->addWidget(keyframe_enable);
}
KeyframeNavigator::~KeyframeNavigator() {}
void KeyframeNavigator::enable_keyframes(bool b) {
keyframe_enable->setChecked(b);
keyframe_enable->setChecked(b);
}
void KeyframeNavigator::enable_keyframe_toggle(bool b) {
keyframe_enable->setVisible(b);
keyframe_enable->setVisible(b);
}
void KeyframeNavigator::keyframe_ui_enabled(bool enabled) {
left_key_nav->setVisible(enabled);
key_addremove->setVisible(enabled);
right_key_nav->setVisible(enabled);
left_key_nav->setVisible(enabled);
key_addremove->setVisible(enabled);
right_key_nav->setVisible(enabled);
}
+5 -4
View File
@@ -24,6 +24,7 @@ const int kThrobberLimit = 20;
const int kThrobberSize = 50;
#include "project/projectmodel.h"
#include "ui/icons.h"
std::unique_ptr<MediaIconService> olive::media_icon_service;
@@ -54,13 +55,13 @@ void MediaIconService::SetMediaIcon(Media *media, int icon_type) {
switch (icon_type) {
case ICON_TYPE_VIDEO:
olive::project_model.set_icon(media, QIcon(":/icons/videosource.svg"));
olive::project_model.set_icon(media, olive::icon::MediaVideo);
break;
case ICON_TYPE_AUDIO:
olive::project_model.set_icon(media, QIcon(":/icons/audiosource.svg"));
olive::project_model.set_icon(media, olive::icon::MediaAudio);
break;
case ICON_TYPE_IMAGE:
olive::project_model.set_icon(media, QIcon(":/icons/imagesource.svg"));
olive::project_model.set_icon(media, olive::icon::MediaImage);
break;
case ICON_TYPE_LOADING:
throbber_items_.append(media);
@@ -75,7 +76,7 @@ void MediaIconService::SetMediaIcon(Media *media, int icon_type) {
}
break;
case ICON_TYPE_ERROR:
olive::project_model.set_icon(media, QIcon(":/icons/error.svg"));
olive::project_model.set_icon(media, olive::icon::MediaError);
break;
}