3 // Part of the Architektonas Project
4 // Originally part of QCad Community Edition by Andrew Mustun
5 // Extensively rewritten and refactored by James L. Hammons
6 // (C) 2010 Underground Software
8 // JLH = James L. Hammons <jlhamm@acm.org>
11 // --- ---------- -----------------------------------------------------------
12 // JLH 05/11/2010 Added this text. :-)
15 #include "recentfiles.h"
17 #include "applicationwindow.h"
22 * @param number Number of files that can be stored in the list at maximum
24 RecentFiles::RecentFiles(QWidget * parent, QMenu * menu, int num/*= 9*/):
25 QObject(), number(num)
27 // We make a separator that we can control the visibility of...
28 separator = menu->addSeparator();
29 separator->setVisible(false);
31 // We create all the actions up front so we don't have to mess with them
33 for(int i=0; i<number; i++)
35 QAction * action = new QAction(parent);
36 action->setVisible(false);
37 menu->addAction(action);
38 connect(action, SIGNAL(triggered()), parent, SLOT(slotFileOpenRecent()));
39 actionList.append(action);
46 RecentFiles::~RecentFiles()
48 while (!actionList.isEmpty())
49 delete actionList.takeFirst();
53 * Adds a file to the list of recently loaded files if
54 * it's not already in the list.
56 void RecentFiles::add(const QString & filename)
58 RS_DEBUG->print("RecentFiles::add");
60 // Is the file already in the list? Bail out if so...
61 if (files.indexOf(filename) != -1)
64 files.append(filename);
66 // Keep the list under our limit
67 if ((int)files.count() > number)
70 RS_DEBUG->print("RecentFiles::add: OK");
74 * @return complete path and name of the file stored in the
77 QString RecentFiles::get(int i)
79 if (i < (int)files.count())
85 /** @return number of files currently stored in the list */
86 int RecentFiles::count(void)
91 /** @return number of files that can be stored in the list at maximum */
92 int RecentFiles::Maximum(void)
97 void RecentFiles::UpdateGUI(void)
99 int numRecentFiles = count();
101 for(int i=0; i<numRecentFiles; i++)
103 // QString text = tr("&%1 %2").arg(i + 1).arg(strippedName(files[i]));
104 QString text = tr("&%1 %2").arg(i + 1).arg(files[i]);
105 actionList[i]->setText(text);
106 actionList[i]->setData(files[i]);
107 actionList[i]->setVisible(true);
110 for(int j=numRecentFiles; j<Maximum(); j++)
111 actionList[j]->setVisible(false);
113 separator->setVisible(numRecentFiles > 0);