]> Some of my projects - aniplayer.git/commitdiff
Add annotation toggle option
authorAPTX <marek321@gmail.com>
Mon, 21 Feb 2022 14:57:15 +0000 (23:57 +0900)
committerAPTX <marek321@gmail.com>
Mon, 21 Feb 2022 14:57:15 +0000 (23:57 +0900)
To be used with shortcut API

featureplugins/feature_annotations/featureannotations.cpp
featureplugins/feature_annotations/featureannotations.h

index 487fad587651da889466e86d9bf54d9f74e07c52..d268b31e0cb60b994ce5d807cd8e86c714d471f5 100644 (file)
@@ -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<FeaturePluginInstance::Action> 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({});
+  }
+}
index cf7948fba9648bfd2d28ea5df724096191bff450..1365ee5275ce23a6d7a15e70be23f08eb0ef1d93 100644 (file)
@@ -32,15 +32,20 @@ class FeatureAnnoationsInstance : public QObject, public FeaturePluginInstance {
 public:
   FeatureAnnoationsInstance(QObject *instance, PlayerFeaturePluginInterface *, QObject *parent = nullptr);
 
+  // FeaturePluginInstance interface
+  QList<Action> 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<PlayerFeaturePluginInterface::AnnotationList> m_watcher;