mirror of
https://github.com/rwengine/openrw.git
synced 2024-11-07 03:12:36 +01:00
Recent Archives
This commit is contained in:
parent
fe1e94d167
commit
8110358dbf
@ -7,6 +7,8 @@
|
|||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
|
|
||||||
|
static int MaxRecentArchives = 5;
|
||||||
|
|
||||||
ViewerWindow::ViewerWindow(QWidget* parent, Qt::WindowFlags flags): QMainWindow(parent, flags)
|
ViewerWindow::ViewerWindow(QWidget* parent, Qt::WindowFlags flags): QMainWindow(parent, flags)
|
||||||
{
|
{
|
||||||
setMinimumSize(640, 480);
|
setMinimumSize(640, 480);
|
||||||
@ -22,6 +24,12 @@ ViewerWindow::ViewerWindow(QWidget* parent, Qt::WindowFlags flags): QMainWindow(
|
|||||||
QMenu* file = mb->addMenu("&File");
|
QMenu* file = mb->addMenu("&File");
|
||||||
file->addAction("Open &Archive", this, SLOT(openArchive()));
|
file->addAction("Open &Archive", this, SLOT(openArchive()));
|
||||||
file->addSeparator();
|
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);
|
file->addAction("E&xit", QApplication::instance(), SLOT(quit()), QKeySequence::Quit);
|
||||||
|
|
||||||
connect(archivewidget, SIGNAL(selectedFileChanged(QString)), viewer, SLOT(showFile(QString)));
|
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");
|
QSettings settings("OpenRW", "rwviewer");
|
||||||
restoreGeometry(settings.value("geometry").toByteArray());
|
restoreGeometry(settings.value("geometry").toByteArray());
|
||||||
restoreState(settings.value("windowState").toByteArray());
|
restoreState(settings.value("windowState").toByteArray());
|
||||||
|
|
||||||
|
updateRecentArchives();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewerWindow::openArchive(const QString& name)
|
void ViewerWindow::openArchive(const QString& name)
|
||||||
@ -46,6 +56,15 @@ void ViewerWindow::openArchive(const QString& name)
|
|||||||
viewer->world()->gameData.loadIMG(rname.toStdString());
|
viewer->world()->gameData.loadIMG(rname.toStdString());
|
||||||
|
|
||||||
archivewidget->setArchive(ld);
|
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)
|
void ViewerWindow::closeEvent(QCloseEvent* event)
|
||||||
@ -56,7 +75,6 @@ void ViewerWindow::closeEvent(QCloseEvent* event)
|
|||||||
QMainWindow::closeEvent(event);
|
QMainWindow::closeEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ViewerWindow::openArchive()
|
void ViewerWindow::openArchive()
|
||||||
{
|
{
|
||||||
QFileDialog dialog(this, "Open Archive", QDir::homePath(), "IMG Archives (*.img)");
|
QFileDialog dialog(this, "Open Archive", QDir::homePath(), "IMG Archives (*.img)");
|
||||||
@ -70,3 +88,32 @@ void ViewerWindow::updateTitle(const QString& name)
|
|||||||
setWindowTitle(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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -23,6 +23,16 @@ public slots:
|
|||||||
|
|
||||||
void openArchive();
|
void openArchive();
|
||||||
void updateTitle(const QString& name);
|
void updateTitle(const QString& name);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
|
||||||
|
void openRecent();
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
QList<QAction*> recentArchives;
|
||||||
|
QAction* recentSep;
|
||||||
|
void updateRecentArchives();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
Loading…
Reference in New Issue
Block a user