Skip to content

Commit

Permalink
Fix play control bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
terrakuh committed Jul 21, 2018
1 parent c32615e commit 50c47be
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 15 deletions.
14 changes: 14 additions & 0 deletions Micasa/folder_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,20 @@ bool folder_view::load_files(const wchar_t * _path)
CComPtr<IWebBrowser2> _browser;

if (SUCCEEDED(CoCreateInstance(CLSID_ShellBrowserWindow, nullptr, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER | CLSCTX_LOCAL_SERVER, IID_PPV_ARGS(&_browser)))) {
struct guard
{
CComPtr<IWebBrowser2> _browser;

guard(CComPtr<IWebBrowser2> & _browser) : _browser(_browser)
{
}
~guard()
{
_browser->Stop();
_browser->Quit();
}
} _guard(_browser);

CComPtr<IServiceProvider> _provider;
CComVariant _empty;
CComVariant _target;
Expand Down
27 changes: 14 additions & 13 deletions Micasa/image_item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ image_item::image_item() : _context_menu(this)
_fullscreen = false;
_play = false;
_reversed = false;
_movie_id = 0;

setFlag(QGraphicsItem::ItemIsMovable);
setCursor(QCursor(Qt::CursorShape::SizeAllCursor));
Expand All @@ -22,7 +23,7 @@ void image_item::play()
_play = true;

QTimer::singleShot(0, [&]() {
show_next_movie_frame(_movie);
show_next_movie_frame(++_movie_id);
});
}
}
Expand Down Expand Up @@ -91,32 +92,32 @@ bool image_item::load_resource(const wchar_t * _path)
QFileInfo _info(QString::fromWCharArray(_path));
auto _recurred = false;

_movie = nullptr;
_movie.reset();

// Is movie
if (QMovie::supportedFormats().contains(_info.suffix().toUtf8())) {
_movie = new QMovie(_info.absoluteFilePath());
_movie.reset(new QMovie(_info.absoluteFilePath()));

if (_movie->isValid()) {
_movie->setCacheMode(QMovie::CacheAll);
//_movie->setCacheMode(QMovie::CacheAll);
_movie->jumpToFrame(0);
_current_size = _movie->currentPixmap().size();
_context_menu.set_active_menu(context_menu::ACTIVE_MENU::MOVIE);

_current_size = _movie->currentPixmap().size();
_play = true;
_reversed = false;

scale_view(_current_size);

QTimer::singleShot(0, [&]() {
center_item();
show_next_movie_frame(_movie);
show_next_movie_frame(++_movie_id);
});

return true;
}

delete _movie;
_movie = nullptr;
_movie.reset();
} // Try image
else {
_original_image = QPixmap(_info.absoluteFilePath());
Expand Down Expand Up @@ -167,13 +168,13 @@ void image_item::mouseDoubleClickEvent(QGraphicsSceneMouseEvent * _event)
// Set image size
if (_movie) {
_current_size = _movie->currentPixmap().size();

if (scale_view(_current_size)) {
//_movie->setScaledSize(_current_size);
}
} else {
_current_size = _original_image.size();

if (scale_view(_current_size)) {
setPixmap(_original_image.scaled(_current_size, Qt::KeepAspectRatio, Qt::SmoothTransformation));
} else {
Expand All @@ -188,9 +189,9 @@ void image_item::mouseDoubleClickEvent(QGraphicsSceneMouseEvent * _event)
}
}

void image_item::show_next_movie_frame(const void * _address)
void image_item::show_next_movie_frame(int _id)
{
if (_movie == _address && _play) {
if (_movie && _movie_id == _id && _play) {
setPixmap(_movie->currentPixmap().scaled(_current_size));

// Jump to next frame
Expand All @@ -208,7 +209,7 @@ void image_item::show_next_movie_frame(const void * _address)

// Schedule show
QTimer::singleShot(_movie->nextFrameDelay(), [=]() {
show_next_movie_frame(_address);
show_next_movie_frame(_id);
});
}
}
Expand Down
6 changes: 4 additions & 2 deletions Micasa/image_item.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <algorithm>
#include <memory>
#include <QtWidgets\QApplication>
#include <QtWidgets\QDesktopWidget>
#include <QtWidgets\QGraphicsItem>
Expand Down Expand Up @@ -47,12 +48,13 @@ class image_item : public QGraphicsPixmapItem, public viewable_item, public edit
bool _fullscreen;
bool _play;
bool _reversed;
int _movie_id;
QSize _current_size;
QSize _scene_size;
QMovie * _movie;
std::unique_ptr<QMovie> _movie;
QPixmap _original_image;
context_menu _context_menu;

void show_next_movie_frame(const void * _address);
void show_next_movie_frame(int _id);
bool scale_view(QSize & _size);
};

0 comments on commit 50c47be

Please sign in to comment.