From 1cdba285be9bebd9b793fc6ae0369d201a0e713b Mon Sep 17 00:00:00 2001 From: saturneric Date: Mon, 1 Jan 2024 17:15:25 +0800 Subject: feat: improve file browser's functions and tidy up codes --- src/ui/widgets/FileTreeView.h | 236 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 236 insertions(+) create mode 100644 src/ui/widgets/FileTreeView.h (limited to 'src/ui/widgets/FileTreeView.h') diff --git a/src/ui/widgets/FileTreeView.h b/src/ui/widgets/FileTreeView.h new file mode 100644 index 00000000..3627a564 --- /dev/null +++ b/src/ui/widgets/FileTreeView.h @@ -0,0 +1,236 @@ +/** + * Copyright (C) 2021 Saturneric + * + * This file is part of GpgFrontend. + * + * GpgFrontend is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GpgFrontend is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GpgFrontend. If not, see . + * + * The initial version of the source code is inherited from + * the gpg4usb project, which is under GPL-3.0-or-later. + * + * All the source code of GpgFrontend was modified and released by + * Saturneric starting on May 12, 2021. + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ + +#pragma once + +namespace GpgFrontend::UI { + +class FileTreeView : public QTreeView { + Q_OBJECT + public: + explicit FileTreeView(QWidget* parent); + + /** + * @brief Get the Current Path object + * + * @return std::filesystem::path + */ + auto GetCurrentPath() -> std::filesystem::path; + + /** + * @brief Get the Selected Path object + * + * @return std::filesystem::path + */ + auto GetSelectedPath() -> std::filesystem::path; + + /** + * @brief Get the Path By Click Point object + * + * @param point + * @return std::filesystem::path + */ + auto GetPathByClickPoint(const QPoint& point) -> std::filesystem::path; + + /** + * @brief Get the Mouse Point Global object + * + * @param point + * @return QPoint + */ + auto GetMousePointGlobal(const QPoint& point) -> QPoint; + + protected: + /** + * @brief + * + * @param selected + * @param deselected + */ + void selectionChanged(const QItemSelection& selected, + const QItemSelection& deselected) override; + + /** + * @brief + * + * @param event + */ + void keyPressEvent(QKeyEvent* event) override; + + /** + * @brief + * + */ + void paintEvent(QPaintEvent* event) override; + + signals: + + /** + * @brief + * + * @param path + */ + void SignalPathChanged(const QString&); + + /** + * @brief + * + */ + void SignalSelectedChanged(const QString&); + + /** + * @brief + * + */ + void SignalOpenFile(const QString&); + + public slots: + + /** + * @brief + * + */ + void SlotGoPath(const std::filesystem::path&); + + /** + * @brief + * + */ + void SlotUpLevel(); + + /** + * @brief + * + */ + void SlotShowSystemFile(bool); + + /** + * @brief + * + * @param on + */ + void SlotShowHiddenFile(bool); + + /** + * @brief + * + */ + auto SlotDeleteSelectedItem() -> void; + + /** + * @brief + * + */ + void SlotMkdir(); + + /** + * @brief + * + */ + void SlotMkdirBelowAtSelectedItem(); + + /** + * @brief + * + */ + void SlotTouch(); + + /** + * @brief + * + */ + void SlotTouchBelowAtSelectedItem(); + + /** + * @brief + * + */ + void SlotRenameSelectedItem(); + + /** + * @brief + * + */ + void SlotOpenSelectedItemBySystemApplication(); + + private slots: + + /** + * @brief + * + * @param index + */ + void slot_file_tree_view_item_selected(const QModelIndex& index); + + /** + * @brief + * + * @param index + */ + void slot_file_tree_view_item_double_clicked(const QModelIndex& index); + + /** + * @brief + * + */ + void slot_calculate_hash(); + + /** + * @brief compress directory into gpg-zip + * + */ + void slot_compress_files(); + + /** + * @brief + * + * @param point + */ + void slot_show_custom_context_menu(const QPoint& point); + + /** + * @brief Create a popup menu object + * + */ + void slot_create_popup_menu(); + + private: + QFileSystemModel* dir_model_; ///< + std::filesystem::path current_path_; ///< + std::filesystem::path selected_path_; ///< + + QMenu* popup_menu_; + QAction* action_open_file_; + QAction* action_rename_file_; + QAction* action_delete_file_; + QAction* action_calculate_hash_; + QAction* action_create_empty_file_; + QAction* action_make_directory_; + QAction* action_compress_files_; +}; +} // namespace GpgFrontend::UI \ No newline at end of file -- cgit v1.2.3 From dcdd494d7f6654a5e2d608d37f69e16cb15fa845 Mon Sep 17 00:00:00 2001 From: saturneric Date: Mon, 1 Jan 2024 17:50:54 +0800 Subject: fix: find and solve some issues --- src/ui/widgets/FileTreeView.h | 7 ------- 1 file changed, 7 deletions(-) (limited to 'src/ui/widgets/FileTreeView.h') diff --git a/src/ui/widgets/FileTreeView.h b/src/ui/widgets/FileTreeView.h index 3627a564..94fdb3de 100644 --- a/src/ui/widgets/FileTreeView.h +++ b/src/ui/widgets/FileTreeView.h @@ -180,13 +180,6 @@ class FileTreeView : public QTreeView { private slots: - /** - * @brief - * - * @param index - */ - void slot_file_tree_view_item_selected(const QModelIndex& index); - /** * @brief * -- cgit v1.2.3 From ba7dd4ef022b19e307557561e2c8d788768c5026 Mon Sep 17 00:00:00 2001 From: saturneric Date: Mon, 8 Jan 2024 15:22:03 +0800 Subject: feat: select a directory before entering into the File Browser --- src/ui/widgets/FileTreeView.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/ui/widgets/FileTreeView.h') diff --git a/src/ui/widgets/FileTreeView.h b/src/ui/widgets/FileTreeView.h index 94fdb3de..5d013ae4 100644 --- a/src/ui/widgets/FileTreeView.h +++ b/src/ui/widgets/FileTreeView.h @@ -33,7 +33,7 @@ namespace GpgFrontend::UI { class FileTreeView : public QTreeView { Q_OBJECT public: - explicit FileTreeView(QWidget* parent); + explicit FileTreeView(QWidget* parent, const QString& target_path); /** * @brief Get the Current Path object -- cgit v1.2.3 From f22ceca734868a4cb946c232f661aad72da01ded Mon Sep 17 00:00:00 2001 From: saturneric Date: Fri, 19 Jan 2024 20:10:17 +0800 Subject: fix: slove discovered faults and bugs --- src/ui/widgets/FileTreeView.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/ui/widgets/FileTreeView.h') diff --git a/src/ui/widgets/FileTreeView.h b/src/ui/widgets/FileTreeView.h index 5d013ae4..9e9b03dd 100644 --- a/src/ui/widgets/FileTreeView.h +++ b/src/ui/widgets/FileTreeView.h @@ -40,14 +40,14 @@ class FileTreeView : public QTreeView { * * @return std::filesystem::path */ - auto GetCurrentPath() -> std::filesystem::path; + auto GetCurrentPath() -> QString; /** * @brief Get the Selected Path object * * @return std::filesystem::path */ - auto GetSelectedPath() -> std::filesystem::path; + auto GetSelectedPath() -> QString; /** * @brief Get the Path By Click Point object @@ -55,7 +55,7 @@ class FileTreeView : public QTreeView { * @param point * @return std::filesystem::path */ - auto GetPathByClickPoint(const QPoint& point) -> std::filesystem::path; + auto GetPathByClickPoint(const QPoint& point) -> QString; /** * @brief Get the Mouse Point Global object @@ -115,7 +115,7 @@ class FileTreeView : public QTreeView { * @brief * */ - void SlotGoPath(const std::filesystem::path&); + void SlotGoPath(const QString&); /** * @brief @@ -213,9 +213,9 @@ class FileTreeView : public QTreeView { void slot_create_popup_menu(); private: - QFileSystemModel* dir_model_; ///< - std::filesystem::path current_path_; ///< - std::filesystem::path selected_path_; ///< + QFileSystemModel* dir_model_; ///< + QString current_path_; ///< + QString selected_path_; ///< QMenu* popup_menu_; QAction* action_open_file_; -- cgit v1.2.3