File indexing completed on 2024-06-09 04:25:57
0001 /* This file is part of the KDE libraries 0002 SPDX-FileCopyrightText: 1999 Reginald Stadlbauer <reggie@kde.org> 0003 SPDX-FileCopyrightText: 1999 Simon Hausmann <hausmann@kde.org> 0004 SPDX-FileCopyrightText: 2000 Nicolas Hadacek <haadcek@kde.org> 0005 SPDX-FileCopyrightText: 2000 Kurt Granroth <granroth@kde.org> 0006 SPDX-FileCopyrightText: 2000 Michael Koch <koch@kde.org> 0007 SPDX-FileCopyrightText: 2001 Holger Freyther <freyther@kde.org> 0008 SPDX-FileCopyrightText: 2002 Ellis Whitehead <ellis@kde.org> 0009 SPDX-FileCopyrightText: 2003 Andras Mantia <amantia@kde.org> 0010 SPDX-FileCopyrightText: 2005-2006 Hamish Rodda <rodda@kde.org> 0011 SPDX-FileCopyrightText: 2022 Alvin Wong <alvin@alvinhc.com> 0012 0013 SPDX-License-Identifier: LGPL-2.0-only 0014 */ 0015 0016 #ifndef KRECENTFILESACTION_H 0017 #define KRECENTFILESACTION_H 0018 0019 #include <kselectaction.h> 0020 #include <qurl.h> 0021 #include <kritawidgetutils_export.h> 0022 0023 class KConfigGroup; 0024 class KRecentFilesActionPrivate; 0025 0026 class QIcon; 0027 class QStandardItemModel; 0028 class QStandardItem; 0029 0030 /** 0031 * @short Recent files action 0032 * 0033 * This class is an action to handle a recent files submenu. 0034 * The best way to create the action is to use KStandardAction::openRecent. 0035 * Then you simply need to call loadEntries on startup, saveEntries 0036 * on shutdown, addURL when your application loads/saves a file. 0037 * 0038 * @author Michael Koch 0039 */ 0040 class KRITAWIDGETUTILS_EXPORT KRecentFilesAction : public KSelectAction 0041 { 0042 Q_OBJECT 0043 Q_DECLARE_PRIVATE(KRecentFilesAction) 0044 0045 public: 0046 /** 0047 * Constructs an action with the specified parent. 0048 * 0049 * @param parent The parent of this action. 0050 */ 0051 explicit KRecentFilesAction(QObject *parent); 0052 0053 /** 0054 * Constructs an action with text; a shortcut may be specified by 0055 * the ampersand character (e.g. \"&Option\" creates a shortcut with key \e O ) 0056 * 0057 * This is the most common KAction used when you do not have a 0058 * corresponding icon (note that it won't appear in the current version 0059 * of the "Edit ToolBar" dialog, because an action needs an icon to be 0060 * plugged in a toolbar...). 0061 * 0062 * @param text The text that will be displayed. 0063 * @param parent The parent of this action. 0064 */ 0065 KRecentFilesAction(const QString &text, QObject *parent); 0066 0067 /** 0068 * Constructs an action with text and an icon; a shortcut may be specified by 0069 * the ampersand character (e.g. \"&Option\" creates a shortcut with key \e O ) 0070 * 0071 * This is the other common KAction used. Use it when you 0072 * \e do have a corresponding icon. 0073 * 0074 * @param icon The icon to display. 0075 * @param text The text that will be displayed. 0076 * @param parent The parent of this action. 0077 */ 0078 KRecentFilesAction(const QIcon &icon, const QString &text, QObject *parent); 0079 0080 /** 0081 * Destructor. 0082 */ 0083 ~KRecentFilesAction() override; 0084 0085 /** 0086 * Adds \a action to the list of URLs, with \a url and title \a name. 0087 * 0088 * Do not use addAction(QAction*), as no url will be associated, and 0089 * consequently urlSelected() will not be emitted when \a action is selected. 0090 */ 0091 void addAction(QAction *action, const QUrl &url, const QString &name); 0092 0093 /** 0094 * Reimplemented for internal reasons. 0095 */ 0096 QAction *removeAction(QAction *action) override; 0097 0098 private Q_SLOTS: 0099 /** 0100 * Clears the recent files list. 0101 * Note that there is also an action shown to the user for clearing the list. 0102 */ 0103 virtual void clearActionTriggered(); 0104 0105 public: 0106 void setRecentFilesModel(const QStandardItemModel *model); 0107 0108 Q_SIGNALS: 0109 /** 0110 * This signal gets emitted when the user selects a URL. 0111 * 0112 * @param url The URL that the user selected. 0113 */ 0114 void urlSelected(const QUrl &url); 0115 0116 private: 0117 //Internal 0118 void clearEntries(); 0119 // Don't warn about the virtual overload. As the comment of the other 0120 // addAction() says, addAction( QAction* ) should not be used. 0121 using KSelectAction::addAction; 0122 0123 KRecentFilesActionPrivate *d_ptr; 0124 0125 Q_PRIVATE_SLOT(d_func(), void _k_urlSelected(QAction *)) 0126 0127 void rebuildEntries(); 0128 0129 private Q_SLOTS: 0130 void fileAdded(const QUrl &url); 0131 void fileRemoved(const QUrl &url); 0132 void listRenewed(); 0133 0134 void modelItemChanged(QStandardItem *item); 0135 void modelRowsInserted(const QModelIndex &parent, int first, int last); 0136 0137 void menuAboutToShow(); 0138 }; 0139 0140 #endif