File indexing completed on 2024-12-22 04:13:04
0001 /* 0002 * SPDX-FileCopyrightText: 2021 Felipe Lema <felipelema@mortemale.org> 0003 * SPDX-FileCopyrightText: 2022 Alvin Wong <alvin@alvinhc.com> 0004 * 0005 * SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #ifndef KISRECENTDOCUMENTSMODELWRAPPER_H 0009 #define KISRECENTDOCUMENTSMODELWRAPPER_H 0010 0011 #include <QStandardItemModel> 0012 0013 class QString; 0014 class QIcon; 0015 0016 /** 0017 * This singleton class provides a `QStandardItemModel` representing the 0018 * recent files list and also supports lazy-loading of the file thumbnail 0019 * icons. Each recent file entry is represented as a QStandardItem. When 0020 * `QStandardItem::icon()` is called for the first time, it fetches the icon 0021 * via `KisRecentFileIconCache`, which triggers loading the file icon in 0022 * background if it hasn't already been loaded and cached. 0023 * 0024 * See also `KisRecentFilesManager`. 0025 */ 0026 class KisRecentDocumentsModelWrapper : public QObject 0027 { 0028 Q_OBJECT 0029 public: 0030 static constexpr const int ICON_SIZE_LENGTH = 200; 0031 0032 static KisRecentDocumentsModelWrapper *instance(); 0033 0034 private: 0035 KisRecentDocumentsModelWrapper(); 0036 ~KisRecentDocumentsModelWrapper(); 0037 0038 /** 0039 * Update m_filesAndThumbnailsModel and launch worker thread to fetch icons in background 0040 */ 0041 void setFiles(const QList<QUrl> &urls); 0042 0043 public: 0044 /** 0045 * Get underlying model 0046 * 0047 * No need for any extra setup. This will hold the provided files 0048 */ 0049 QStandardItemModel &model(); 0050 0051 private: 0052 QStandardItemModel m_filesAndThumbnailsModel; 0053 0054 private Q_SLOTS: 0055 void slotFileIconChanged(const QUrl &url, const QIcon &icon); 0056 void fileAdded(const QUrl &url); 0057 void fileRemoved(const QUrl &url); 0058 void listRenewed(); 0059 0060 Q_SIGNALS: 0061 /** 0062 * Report when the model has been updated with the latest recent file list. 0063 */ 0064 void sigModelIsUpToDate(); 0065 }; // class KisRecentDocumentsModelWrapper 0066 0067 #endif // KISRECENTDOCUMENTSMODELWRAPPER_H