replaced mediathrobber with mediaiconservice

This commit is contained in:
itsmattkc
2019-02-16 22:22:43 -08:00
parent 5207a0511f
commit f14b0cef7d
17 changed files with 213 additions and 142 deletions
+93
View File
@@ -0,0 +1,93 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 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 "mediaiconservice.h"
const int kThrobberLimit = 20;
const int kThrobberSize = 50;
#include "project/projectmodel.h"
std::unique_ptr<MediaIconService> olive::media_icon_service;
MediaIconService::MediaIconService() {
// set up animation timer
throbber_animator_.setInterval(20);
connect(&throbber_animator_, SIGNAL(timeout()), this, SLOT(AnimationUpdate()));
// set up pixmap
throbber_pixmap_ = QPixmap(":/icons/throbber.png");
}
void MediaIconService::SetMediaIcon(Media *media, int icon_type) {
// if this icon is already part of the throbber animation loop, remove it
if (throbber_items_.contains(media)) {
throbber_items_.removeAll(media);
// if we aren't animating anything, no need to run the timer for now
if (throbber_items_.empty()) {
// ensure timer function is called in its own thread
QMetaObject::invokeMethod(&throbber_animator_, "stop", Qt::QueuedConnection);
}
}
switch (icon_type) {
case ICON_TYPE_VIDEO:
olive::project_model.set_icon(media, QIcon(":/icons/videosource.png"));
break;
case ICON_TYPE_AUDIO:
olive::project_model.set_icon(media, QIcon(":/icons/audiosource.png"));
break;
case ICON_TYPE_IMAGE:
olive::project_model.set_icon(media, QIcon(":/icons/imagesource.png"));
break;
case ICON_TYPE_LOADING:
throbber_items_.append(media);
// if the animation timer isn't running, start it
if (!throbber_animator_.isActive()) {
// set starting frame to 0
throbber_animation_frame_ = 0;
// ensure timer function is called in its own thread
QMetaObject::invokeMethod(&throbber_animator_, "start", Qt::QueuedConnection);
}
break;
case ICON_TYPE_ERROR:
olive::project_model.set_icon(media, QIcon(":/icons/error.png"));
break;
}
emit IconChanged();
}
void MediaIconService::AnimationUpdate() {
if (throbber_animation_frame_ == kThrobberLimit) {
throbber_animation_frame_ = 0;
}
QIcon throbber_ico = QIcon(throbber_pixmap_.copy(kThrobberSize*throbber_animation_frame_, 0, kThrobberSize, kThrobberSize));
for (int i=0;i<throbber_items_.size();i++) {
olive::project_model.set_icon(throbber_items_.at(i), throbber_ico);
}
throbber_animation_frame_++;
}
+58
View File
@@ -0,0 +1,58 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 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 MEDIAICONSERVICE_H
#define MEDIAICONSERVICE_H
#include <QObject>
#include <QTimer>
#include "project/media.h"
enum IconType {
ICON_TYPE_VIDEO,
ICON_TYPE_AUDIO,
ICON_TYPE_IMAGE,
ICON_TYPE_LOADING,
ICON_TYPE_ERROR
};
class MediaIconService : public QObject {
Q_OBJECT
public:
MediaIconService();
public slots:
void SetMediaIcon(Media* media, int icon_type);
signals:
void IconChanged();
private slots:
void AnimationUpdate();
private:
int throbber_animation_frame_;
QVector<Media*> throbber_items_;
QTimer throbber_animator_;
QPixmap throbber_pixmap_;
};
namespace olive {
extern std::unique_ptr<MediaIconService> media_icon_service;
}
#endif // MEDIAICONSERVICE_H
+2 -2
View File
@@ -244,8 +244,8 @@ void TimelineWidget::rename_clip() {
void TimelineWidget::open_sequence_properties() {
QList<Media*> sequence_items;
QList<Media*> all_top_level_items;
for (int i=0;i<project_model.childCount();i++) {
all_top_level_items.append(project_model.child(i));
for (int i=0;i<olive::project_model.childCount();i++) {
all_top_level_items.append(olive::project_model.child(i));
}
panel_project->get_all_media_from_table(all_top_level_items, sequence_items, MEDIA_TYPE_SEQUENCE); // find all sequences in project
for (int i=0;i<sequence_items.size();i++) {