MainWindow.hpp 4.6 KB

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