JKQtExtras
a library of useful Qt widgets and tools
jkqterecentfilesmenu.h
1 /*
2  Copyright (c) 2013-2020 Jan W. Krieger (<jan@jkrieger.de>)
3 
4  This software is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License (GPL) as published by
6  the Free Software Foundation, either version 3.0 of the License, or
7  (at your option) any later version.
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12  You should have received a copy of the GNU General Public License
13  along with this program. If not, see <http://www.gnu.org/licenses/>.
14 */
15 
16 #ifndef JKQTERECENTFILESMENU_H
17 #define JKQTERECENTFILESMENU_H
18 
19 #include <QMenu>
20 #include <QSettings>
21 #include <QList>
22 #include <QStringList>
23 #include <QMap>
24 #include <QFileInfo>
25 #include <QFileIconProvider>
26 #include "jkqtextras_imexport.h"
27 
28 /*! \brief a special QMenu that allows to manage a list of recently loaded files
29  \ingroup JKQtExtrasWidgetsMenus
30 
31  \image html JKQTERecentFilesMenu.png
32 
33  Usage example:
34 
35  \snippet jkqtextras_test/testmainwindow.cpp Example: JKQTERecentFilesMenu
36  */
38  Q_OBJECT
39  public:
40  explicit JKQTERecentFilesMenu(QWidget *parent = 0);
41 
42  /** \brief set the max. number of files in the list */
43  void setMaxRecentFilesCount(int num);
44  /** \brief returns the max. number of files in the list */
45  int maxRecentFilesCount() const;
46  /** \brief show icons next to the recent files */
47  void setShowIcons(bool enabled);
48  /** \brief show icons next to the recent files */
49  bool doesShowIcons() const;
50 
51  void setAlwaysEnabled(bool enabled);
52 
53  /** \brief register an icon for a given filetype this overrides the display of system icons */
54  void setIconForExtension(const QString& extension, const QIcon& icon);
55  /** \brief set the default icon */
56  void setDefaultIcon(const QIcon& defaultIcon);
57  /** \brief use file icons from system */
58  void setUseSystemFileIcons(bool use);
59 
60  /*! \brief save the list of recent files into a QSettings object.
61 
62  The settings are saved under the key
63  \c [prefix] + "recentfilelist"
64  */
65  void storeSettings(QSettings& settings, QString prefix=QString(""));
66  /*! \brief read the list of recent files from a QSettings object.
67 
68  The settings are saved under the key
69  \c [prefix] + "recentfilelist"
70  */
71  void readSettings(QSettings& settings, QString prefix=QString(""));
72 
73  /** \brief add a new file to the list of recent files */
74  void addRecentFile(const QString& filename);
75  /** \brief clear all recent files */
77 
78  signals:
79  /** \brief emitted when the user clicks one of the recent files in the menu. */
80  void openRecentFile(const QString& filename);
81  public slots:
82  void setMenuEnabled(bool enabled);
83  protected:
85  QList<QAction*> m_actions;
86  QStringList m_files;
87  QMap<QString, QIcon> m_fileIcons;
90  bool m_icons;
92  QFileIconProvider iconProvider;
93  QString strippedName(const QString &fullFileName);
94  QIcon iconForFile(const QFileInfo& fileinfo);
95  protected slots:
96  void updateActions();
98 
99 };
100 
101 #endif // JKQTERECENTFILESMENU_H
JKQTERecentFilesMenu::m_fileIcons
QMap< QString, QIcon > m_fileIcons
Definition: jkqterecentfilesmenu.h:87
JKQTERecentFilesMenu::clearRecentFiles
void clearRecentFiles()
clear all recent files
JKQTERecentFilesMenu::intOpenRecentFile
void intOpenRecentFile()
JKQTERecentFilesMenu::doesShowIcons
bool doesShowIcons() const
show icons next to the recent files
JKQTERecentFilesMenu::readSettings
void readSettings(QSettings &settings, QString prefix=QString(""))
read the list of recent files from a QSettings object.
JKQTERecentFilesMenu::m_defaultIcon
QIcon m_defaultIcon
Definition: jkqterecentfilesmenu.h:88
JKQTERecentFilesMenu::alwaysDisabled
bool alwaysDisabled
Definition: jkqterecentfilesmenu.h:84
JKQTEXTRAS_LIB_EXPORT
#define JKQTEXTRAS_LIB_EXPORT
Definition: jkqtextras_imexport.h:95
JKQTERecentFilesMenu::m_actions
QList< QAction * > m_actions
Definition: jkqterecentfilesmenu.h:85
JKQTERecentFilesMenu::iconForFile
QIcon iconForFile(const QFileInfo &fileinfo)
JKQTERecentFilesMenu::strippedName
QString strippedName(const QString &fullFileName)
JKQTERecentFilesMenu::setIconForExtension
void setIconForExtension(const QString &extension, const QIcon &icon)
register an icon for a given filetype this overrides the display of system icons
JKQTERecentFilesMenu::m_useSystemFileIcons
bool m_useSystemFileIcons
Definition: jkqterecentfilesmenu.h:89
JKQTERecentFilesMenu::openRecentFile
void openRecentFile(const QString &filename)
emitted when the user clicks one of the recent files in the menu.
JKQTERecentFilesMenu::maxRecentFilesCount
int maxRecentFilesCount() const
returns the max. number of files in the list
JKQTERecentFilesMenu::m_icons
bool m_icons
Definition: jkqterecentfilesmenu.h:90
JKQTERecentFilesMenu::storeSettings
void storeSettings(QSettings &settings, QString prefix=QString(""))
save the list of recent files into a QSettings object.
JKQTERecentFilesMenu::setUseSystemFileIcons
void setUseSystemFileIcons(bool use)
use file icons from system
JKQTERecentFilesMenu::m_files
QStringList m_files
Definition: jkqterecentfilesmenu.h:86
JKQTERecentFilesMenu::setMaxRecentFilesCount
void setMaxRecentFilesCount(int num)
set the max. number of files in the list
JKQTERecentFilesMenu::JKQTERecentFilesMenu
JKQTERecentFilesMenu(QWidget *parent=0)
JKQTERecentFilesMenu::setShowIcons
void setShowIcons(bool enabled)
show icons next to the recent files
JKQTERecentFilesMenu::setDefaultIcon
void setDefaultIcon(const QIcon &defaultIcon)
set the default icon
JKQTERecentFilesMenu::m_alwaysEnabled
bool m_alwaysEnabled
Definition: jkqterecentfilesmenu.h:91
JKQTERecentFilesMenu::addRecentFile
void addRecentFile(const QString &filename)
add a new file to the list of recent files
JKQTERecentFilesMenu::setMenuEnabled
void setMenuEnabled(bool enabled)
JKQTERecentFilesMenu
a special QMenu that allows to manage a list of recently loaded files
Definition: jkqterecentfilesmenu.h:37
JKQTERecentFilesMenu::updateActions
void updateActions()
JKQTERecentFilesMenu::iconProvider
QFileIconProvider iconProvider
Definition: jkqterecentfilesmenu.h:92
JKQTERecentFilesMenu::setAlwaysEnabled
void setAlwaysEnabled(bool enabled)