From: APTX Date: Mon, 21 Feb 2022 14:57:15 +0000 (+0900) Subject: Add annotation toggle option X-Git-Url: https://gitweb.tyo.aptx.org/?a=commitdiff_plain;h=6b425446e9f9dd7a984ab7d956768fb56e1d27c7;p=aniplayer.git Add annotation toggle option To be used with shortcut API --- diff --git a/featureplugins/feature_annotations/featureannotations.cpp b/featureplugins/feature_annotations/featureannotations.cpp index 487fad5..d268b31 100644 --- a/featureplugins/feature_annotations/featureannotations.cpp +++ b/featureplugins/feature_annotations/featureannotations.cpp @@ -62,9 +62,6 @@ FeatureAnnoationsInstance::FeatureAnnoationsInstance( : FeaturePluginInstance{instance, player} { qCDebug(annotationsCategory) << "Registering with instance" << instance; - connect(instance, SIGNAL(frameChanged(const QImage &)), this, - SLOT(onFrameChanged(const QImage &))); - connect(&m_watcher, SIGNAL(finished()), this, SLOT(onResultReady())); m_fpsTimer.setInterval(1000); @@ -74,6 +71,14 @@ FeatureAnnoationsInstance::FeatureAnnoationsInstance( m_fpsCounter = 0; }); m_fpsTimer.start(); + + ToggleAnnotations(); +} + + +QList FeatureAnnoationsInstance::featurePluginActions() const +{ + return {Action{"Enable annotations", "P", SLOT()}}; } void FeatureAnnoationsInstance::onFrameChanged(const QImage &image) { @@ -139,3 +144,19 @@ void FeatureAnnoationsInstance::onResultReady() { ++m_fpsCounter; m_playerInterface->featureSetAnnotations(m_watcher.result()); } + +void FeatureAnnoationsInstance::onAnnotationToggle() { + enabled = !enabled; + ToggleAnnotations(); +} + +void FeatureAnnoationsInstance::ToggleAnnotations() { + if (enabled) { + connect(m_player, SIGNAL(frameChanged(const QImage &)), this, + SLOT(onFrameChanged(const QImage &))); + } else { + disconnect(m_player, SIGNAL(frameChanged(const QImage &)), this, + SLOT(onFrameChanged(const QImage &))); + m_playerInterface->featureSetAnnotations({}); + } +} diff --git a/featureplugins/feature_annotations/featureannotations.h b/featureplugins/feature_annotations/featureannotations.h index cf7948f..1365ee5 100644 --- a/featureplugins/feature_annotations/featureannotations.h +++ b/featureplugins/feature_annotations/featureannotations.h @@ -32,15 +32,20 @@ class FeatureAnnoationsInstance : public QObject, public FeaturePluginInstance { public: FeatureAnnoationsInstance(QObject *instance, PlayerFeaturePluginInterface *, QObject *parent = nullptr); + // FeaturePluginInstance interface + QList featurePluginActions() const override; + private slots: void onFrameChanged(const QImage &); void onResultReady(); + void onAnnotationToggle(); + private: - int m_fid; - QString m_path; - double m_duration; + void ToggleAnnotations(); + + bool enabled = false; QTimer m_fpsTimer; int m_fpsCounter = 0; QFutureWatcher m_watcher;