mirror of
https://github.com/rwengine/openrw.git
synced 2024-09-15 06:52:34 +02:00
Recent Archives
This commit is contained in:
parent
fe1e94d167
commit
8110358dbf
@ -7,6 +7,8 @@
|
||||
#include <QApplication>
|
||||
#include <QSettings>
|
||||
|
||||
static int MaxRecentArchives = 5;
|
||||
|
||||
ViewerWindow::ViewerWindow(QWidget* parent, Qt::WindowFlags flags): QMainWindow(parent, flags)
|
||||
{
|
||||
setMinimumSize(640, 480);
|
||||
@ -22,6 +24,12 @@ ViewerWindow::ViewerWindow(QWidget* parent, Qt::WindowFlags flags): QMainWindow(
|
||||
QMenu* file = mb->addMenu("&File");
|
||||
file->addAction("Open &Archive", this, SLOT(openArchive()));
|
||||
file->addSeparator();
|
||||
for(int i = 0; i < MaxRecentArchives; ++i) {
|
||||
QAction* r = file->addAction("");
|
||||
recentArchives.append(r);
|
||||
connect(r, SIGNAL(triggered()), SLOT(openRecent()));
|
||||
}
|
||||
recentSep = file->addSeparator();
|
||||
file->addAction("E&xit", QApplication::instance(), SLOT(quit()), QKeySequence::Quit);
|
||||
|
||||
connect(archivewidget, SIGNAL(selectedFileChanged(QString)), viewer, SLOT(showFile(QString)));
|
||||
@ -30,6 +38,8 @@ ViewerWindow::ViewerWindow(QWidget* parent, Qt::WindowFlags flags): QMainWindow(
|
||||
QSettings settings("OpenRW", "rwviewer");
|
||||
restoreGeometry(settings.value("geometry").toByteArray());
|
||||
restoreState(settings.value("windowState").toByteArray());
|
||||
|
||||
updateRecentArchives();
|
||||
}
|
||||
|
||||
void ViewerWindow::openArchive(const QString& name)
|
||||
@ -46,6 +56,15 @@ void ViewerWindow::openArchive(const QString& name)
|
||||
viewer->world()->gameData.loadIMG(rname.toStdString());
|
||||
|
||||
archivewidget->setArchive(ld);
|
||||
|
||||
QSettings settings("OpenRW", "rwviewer");
|
||||
QStringList recent = settings.value("recentArchives").toStringList();
|
||||
recent.removeAll(name);
|
||||
recent.prepend(name);
|
||||
while(recent.size() > MaxRecentArchives) recent.removeLast();
|
||||
settings.setValue("recentArchives", recent);
|
||||
|
||||
updateRecentArchives();
|
||||
}
|
||||
|
||||
void ViewerWindow::closeEvent(QCloseEvent* event)
|
||||
@ -56,7 +75,6 @@ void ViewerWindow::closeEvent(QCloseEvent* event)
|
||||
QMainWindow::closeEvent(event);
|
||||
}
|
||||
|
||||
|
||||
void ViewerWindow::openArchive()
|
||||
{
|
||||
QFileDialog dialog(this, "Open Archive", QDir::homePath(), "IMG Archives (*.img)");
|
||||
@ -70,3 +88,32 @@ void ViewerWindow::updateTitle(const QString& name)
|
||||
setWindowTitle(name);
|
||||
}
|
||||
|
||||
void ViewerWindow::openRecent()
|
||||
{
|
||||
QAction* r = qobject_cast< QAction* >(sender());
|
||||
if(r) {
|
||||
openArchive(r->data().toString());
|
||||
}
|
||||
}
|
||||
|
||||
void ViewerWindow::updateRecentArchives()
|
||||
{
|
||||
QSettings settings("OpenRW", "rwviewer");
|
||||
QStringList recent = settings.value("recentArchives").toStringList();
|
||||
|
||||
for(int i = 0; i < MaxRecentArchives; ++i) {
|
||||
if(i < recent.size()) {
|
||||
QString fnm(QFileInfo(recent[i]).fileName());
|
||||
recentArchives[i]->setText(tr("&%1 - %2").arg(i).arg(fnm));
|
||||
recentArchives[i]->setData(recent[i]);
|
||||
recentArchives[i]->setVisible(true);
|
||||
}
|
||||
else {
|
||||
recentArchives[i]->setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
recentSep->setVisible(recent.size() > 0);
|
||||
}
|
||||
|
||||
|
||||
|
@ -12,7 +12,7 @@ class ViewerWindow : public QMainWindow
|
||||
ViewerWidget* viewer;
|
||||
ArchiveContentsWidget* archivewidget;
|
||||
public:
|
||||
|
||||
|
||||
ViewerWindow(QWidget* parent = 0, Qt::WindowFlags flags = 0);
|
||||
|
||||
void openArchive(const QString& name);
|
||||
@ -23,6 +23,16 @@ public slots:
|
||||
|
||||
void openArchive();
|
||||
void updateTitle(const QString& name);
|
||||
|
||||
private slots:
|
||||
|
||||
void openRecent();
|
||||
|
||||
private:
|
||||
|
||||
QList<QAction*> recentArchives;
|
||||
QAction* recentSep;
|
||||
void updateRecentArchives();
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user