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 // Portions copyright (C) 2001-2003 RibbonSoft
7 // Copyright (C) 2010 Underground Software
8 // See the README and GPLv2 files for licensing and warranty information
10 // JLH = James L. Hammons <jlhamm@acm.org>
13 // --- ---------- -----------------------------------------------------------
14 // JLH 05/11/2010 Added this text. :-)
17 #include "recentfiles.h"
19 #include "applicationwindow.h"
24 * @param number Number of files that can be stored in the list at maximum
26 RecentFiles::RecentFiles(QWidget * parent, QMenu * menu, int num/*= 9*/):
27 QObject(), number(num)
29 // We make a separator that we can control the visibility of...
30 separator = menu->addSeparator();
31 separator->setVisible(false);
33 // We create all the actions up front so we don't have to mess with them
35 for(int i=0; i<number; i++)
37 QAction * action = new QAction(parent);
38 action->setVisible(false);
39 menu->addAction(action);
40 connect(action, SIGNAL(triggered()), parent, SLOT(slotFileOpenRecent()));
41 actionList.append(action);
48 RecentFiles::~RecentFiles()
50 while (!actionList.isEmpty())
51 delete actionList.takeFirst();
55 * Adds a file to the list of recently loaded files if
56 * it's not already in the list.
58 void RecentFiles::add(const QString & filename)
60 DEBUG->print("RecentFiles::add");
62 // Is the file already in the list? Bail out if so...
63 if (files.indexOf(filename) != -1)
66 files.append(filename);
68 // Keep the list under our limit
69 if ((int)files.count() > number)
72 DEBUG->print("RecentFiles::add: OK");
76 * @return complete path and name of the file stored in the
79 QString RecentFiles::get(int i)
81 if (i < (int)files.count())
87 /** @return number of files currently stored in the list */
88 int RecentFiles::count(void)
93 /** @return number of files that can be stored in the list at maximum */
94 int RecentFiles::Maximum(void)
99 void RecentFiles::UpdateGUI(void)
101 int numRecentFiles = count();
103 for(int i=0; i<numRecentFiles; i++)
105 // QString text = tr("&%1 %2").arg(i + 1).arg(strippedName(files[i]));
106 QString text = tr("&%1 %2").arg(i + 1).arg(files[i]);
107 actionList[i]->setText(text);
108 actionList[i]->setData(files[i]);
109 actionList[i]->setVisible(true);
112 for(int j=numRecentFiles; j<Maximum(); j++)
113 actionList[j]->setVisible(false);
115 separator->setVisible(numRecentFiles > 0);