mirror of
https://github.com/JakubMelka/PDF4QT.git
synced 2025-06-05 21:59:17 +02:00
Recent file manager
This commit is contained in:
84
PdfForQtViewer/pdfrecentfilemanager.h
Normal file
84
PdfForQtViewer/pdfrecentfilemanager.h
Normal file
@@ -0,0 +1,84 @@
|
||||
// Copyright (C) 2020 Jakub Melka
|
||||
//
|
||||
// This file is part of PdfForQt.
|
||||
//
|
||||
// PdfForQt is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// PdfForQt 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 Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with PDFForQt. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#ifndef PDFRECENTFILEMANAGER_H
|
||||
#define PDFRECENTFILEMANAGER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QAction>
|
||||
|
||||
#include <array>
|
||||
|
||||
namespace pdfviewer
|
||||
{
|
||||
|
||||
/// Recent file manager, manages list of recent files.
|
||||
class PDFRecentFileManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
using BaseClass = QObject;
|
||||
|
||||
static constexpr const int MAXIMUM_RECENT_FILES = 9;
|
||||
static constexpr const int DEFAULT_RECENT_FILES = 5;
|
||||
|
||||
public:
|
||||
explicit PDFRecentFileManager(QObject* parent);
|
||||
|
||||
/// Adds recent file to recent file list and updates the actions.
|
||||
/// New recent file is added as first file.
|
||||
/// \param fileName New recent file
|
||||
void addRecentFile(QString fileName);
|
||||
|
||||
/// Returns a list of recent files
|
||||
const QStringList& getRecentFiles() const { return m_recentFiles; }
|
||||
|
||||
/// Sets a list of recent files, and udpates manager
|
||||
void setRecentFiles(QStringList recentFiles);
|
||||
|
||||
/// Returns a limit of recent files count
|
||||
int getRecentFilesLimit() const { return m_recentFilesLimit; }
|
||||
|
||||
/// Sets a new limit of recent files count
|
||||
void setRecentFilesLimit(int recentFilesLimit);
|
||||
|
||||
/// Returns list of recent files actions
|
||||
const std::array<QAction*, MAXIMUM_RECENT_FILES>& getActions() const { return m_actions; }
|
||||
|
||||
static constexpr int getMinimumRecentFiles() { return 1; }
|
||||
static constexpr int getDefaultRecentFiles() { return DEFAULT_RECENT_FILES; }
|
||||
static constexpr int getMaximumRecentFiles() { return MAXIMUM_RECENT_FILES; }
|
||||
|
||||
signals:
|
||||
void fileOpenRequest(QString fileName);
|
||||
|
||||
private:
|
||||
/// Updates recent files actions / recent file list
|
||||
void update();
|
||||
|
||||
/// Reaction on recent file action triggered
|
||||
void onRecentFileActionTriggered();
|
||||
|
||||
int m_recentFilesLimit;
|
||||
std::array<QAction*, MAXIMUM_RECENT_FILES> m_actions;
|
||||
QStringList m_recentFiles;
|
||||
};
|
||||
|
||||
} // namespace pdfviewer
|
||||
|
||||
#endif // PDFRECENTFILEMANAGER_H
|
Reference in New Issue
Block a user