MainWindow.hpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #pragma once
  2. #include "DatabaseManager.hpp"
  3. #include "ResultFilterProxyModel.hpp"
  4. #include "ResultItemDelegate.hpp"
  5. #include "ResultListModel.hpp"
  6. #include <QCheckBox>
  7. #include <QCloseEvent>
  8. #include <QDropEvent>
  9. #include <QEvent>
  10. #include <QFutureWatcher>
  11. #include <QLabel>
  12. #include <QLineEdit>
  13. #include <QListView>
  14. #include <QListWidget>
  15. #include <QMainWindow>
  16. #include <QNetworkAccessManager>
  17. #include <QNetworkReply>
  18. #include <QObject>
  19. #include <QProgressBar>
  20. #include <QPushButton>
  21. #include <QSlider>
  22. #include <QTimer>
  23. #include <memory>
  24. #include <unordered_set>
  25. #include <vector>
  26. // アプリケーションのメインウィンドウ(GUI)を管理するクラス
  27. class MainWindow : public QMainWindow {
  28. Q_OBJECT
  29. public:
  30. MainWindow(QWidget *parent = nullptr);
  31. ~MainWindow();
  32. private slots:
  33. // イベントに応答するスロット関数群
  34. void onAddDirectory(); // 検索対象ディレクトリ追加ボタン押下
  35. void onRemoveDirectory(); // リストからディレクトリ除外ボタン押下
  36. void onStartScan(); // 重複検索スキャン開始ボタン押下
  37. void onDeleteSelected(); // チェックされた重複画像を削除するボタン押下
  38. void onThresholdChanged(int value); // 類似度しきい値スライダー変更時
  39. void onStrictChanged(int state); // Strictモードチェックボックス変更時
  40. void onScanFinished(); // ディレクトリの一括スキャン完了時
  41. void performAsyncSearch(); // 非同期での類似画像群の抽出実行
  42. void onSearchFinished(); // 類似画像の検索完了時
  43. void onClearResults(); // 結果表示のクリア
  44. void removeGroupFromView(int groupId); // 指定したグループをリストから除外
  45. void onContextMenuRequested(const std::string &path, int groupId,
  46. const QPoint &globalPos);
  47. void onFileDoubleClicked(const std::string &path);
  48. void onSearchTextChanged(const QString &text);
  49. void onUrlDownloadFinished(QNetworkReply *reply);
  50. private:
  51. // 内部処理・初期化メソッド
  52. void setupUi(); // UIのレイアウトと初期化
  53. void loadSettings(); // INIファイルからの設定値復元
  54. void saveSettings(); // INIファイルへの設定値保存
  55. void updateResultGrid(
  56. const std::vector<DuplicateGroup> &groups,
  57. bool preserveState = false); // 結果グリッドへサムネイルを並べる
  58. std::vector<ImageData>
  59. getFilteredImages(); // 現在リストにあるディレクトリの画像のみ抽出
  60. bool
  61. eventFilter(QObject *obj,
  62. QEvent *event) override; // 右クリックメニュー等のイベントフィルタ
  63. void
  64. closeEvent(QCloseEvent *event) override; // ウィンドウ終了時の保存処理など
  65. void dropEvent(QDropEvent *e) override; // ドロップを受け付ける
  66. void dragEnterEvent(QDragEnterEvent *event) override; // ドロップを受け付ける
  67. // データベースマネージャーのインスタンス
  68. std::unique_ptr<DatabaseManager> m_dbManager;
  69. // UI要素
  70. QListWidget *m_dirList; // 追加済みディレクトリのリスト
  71. QPushButton *m_addDirBtn;
  72. QPushButton *m_removeDirBtn;
  73. QPushButton *m_startScanBtn;
  74. QPushButton *m_deselectBtn; // チェック状態を全クリアするボタン
  75. QProgressBar *m_progressBar; // スキャン・検索時のプログレスバー
  76. QListView *m_resultView; // 検索結果表示用リストビュー
  77. QPushButton *m_deleteBtn;
  78. QPushButton *m_clearBtn;
  79. // 類似判定コントロール要素
  80. QSlider *m_thresholdSlider; // ハミング距離しきい値の設定スライダー
  81. QLabel *m_thresholdLabel; // しきい値の現在数値ラベル
  82. QCheckBox *m_strictCheckBox; // pHash, dHash両方を厳密チェックするか
  83. int m_currentThreshold = 5;
  84. bool m_strictMode = false;
  85. ResultListModel *m_model;
  86. ResultItemDelegate *m_delegate;
  87. ResultFilterProxyModel *m_proxyModel;
  88. QLineEdit *m_searchBox;
  89. // 非同期(バックグラウンド)処理用オブジェクト
  90. QFutureWatcher<void> *m_scanWatcher; // 画像スキャンの進捗監視
  91. QFutureWatcher<std::vector<DuplicateGroup>>
  92. *m_searchWatcher; // 類似検索の進捗監視
  93. QTimer
  94. *m_searchTimer; // 頻繁なスライダ操作をまとめる(デバウンス)ためのタイマ
  95. // キャッシュ
  96. std::vector<ImageData>
  97. m_lastScannedImages; // 各ディレクトリから抽出した画像キャッシュ
  98. QStringList m_loadedDirs; // 起動時にロードされたディレクトリ群
  99. std::vector<DuplicateGroup> m_currentGroups; // 現在表示中のグループ一覧
  100. std::unordered_set<std::string>
  101. m_ignoredPaths; // セッション中に除外した画像のパス
  102. QNetworkAccessManager *m_networkManager;
  103. };