mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-11-23 19:25:54 +01:00
Added "Open recent" menu
This commit is contained in:
parent
e450e62d8d
commit
8ebd73115f
@ -0,0 +1,4 @@
|
||||
<svg version="1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 22 22">
|
||||
<path fill="#ff9900" d="M 17.417969 5.5 L 10.082031 5.5 L 8.25 3.667969 L 3.667969 3.667969 C 2.660156 3.667969 1.832031 4.492188 1.832031 5.5 L 1.832031 16.5 C 1.832031 17.507812 2.660156 18.332031 3.667969 18.332031 L 17.875 18.332031 C 18.652344 18.332031 19.25 17.738281 19.25 16.957031 L 19.25 7.332031 C 19.25 6.324219 18.425781 5.5 17.417969 5.5 Z M 17.417969 5.5 "/>
|
||||
<path fill="#ffcc00" d="M 19.339844 8.25 L 7.011719 8.25 C 6.140625 8.25 5.363281 8.890625 5.226562 9.761719 L 3.667969 18.332031 L 18.195312 18.332031 C 19.066406 18.332031 19.847656 17.691406 19.984375 16.820312 L 21.128906 10.402344 C 21.359375 9.304688 20.488281 8.25 19.339844 8.25 Z M 19.339844 8.25 "/>
|
||||
</svg>
|
After Width: | Height: | Size: 773 B |
10
icons/GUI/Papirus/actions/22x22/document-open-recent.svg
Normal file
10
icons/GUI/Papirus/actions/22x22/document-open-recent.svg
Normal file
@ -0,0 +1,10 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="22" height="22" version="1.1">
|
||||
<defs>
|
||||
<style id="current-color-scheme" type="text/css">
|
||||
.ColorScheme-Text { color:#444444; } .ColorScheme-Highlight { color:#4285f4; } .ColorScheme-NeutralText { color:#ff9800; } .ColorScheme-PositiveText { color:#4caf50; } .ColorScheme-NegativeText { color:#f44336; }
|
||||
</style>
|
||||
</defs>
|
||||
<g transform="translate(3,3)">
|
||||
<path style="fill:currentColor;fill-rule:evenodd" class="ColorScheme-Text" d="M 7,4 H 9 V 7.5 L 11,9.5 9.5,11 7,8.5 Z M 8,1 A 7,7 0 0 0 1,8 7,7 0 0 0 8,15 7,7 0 0 0 15,8 7,7 0 0 0 8,1 Z M 8,3 A 5,5 0 0 1 13,8 5,5 0 0 1 8,13 5,5 0 0 1 3,8 5,5 0 0 1 8,3 Z"/>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 678 B |
118
src/GUI/gui.cpp
118
src/GUI/gui.cpp
@ -59,12 +59,13 @@
|
||||
#include "gui.h"
|
||||
|
||||
|
||||
#define MAX_RECENT_FILES 10
|
||||
#define TOOLBAR_ICON_SIZE 22
|
||||
|
||||
GUI::GUI()
|
||||
{
|
||||
QString activeMap;
|
||||
QStringList disabledPOIs;
|
||||
QStringList disabledPOIs, recentFiles;
|
||||
|
||||
_poi = new POI(this);
|
||||
_dem = new DEMLoader(ProgramPaths::demDir(true), this);
|
||||
@ -108,10 +109,13 @@ GUI::GUI()
|
||||
_movingTime = 0;
|
||||
_lastTab = 0;
|
||||
|
||||
readSettings(activeMap, disabledPOIs);
|
||||
readSettings(activeMap, disabledPOIs, recentFiles);
|
||||
|
||||
loadInitialMaps(activeMap);
|
||||
loadInitialPOIs(disabledPOIs);
|
||||
#ifndef Q_OS_ANDROID
|
||||
loadRecentFiles(recentFiles);
|
||||
#endif // Q_OS_ANDROID
|
||||
|
||||
updateGraphTabs();
|
||||
updateStatusBarInfo();
|
||||
@ -261,6 +265,15 @@ void GUI::createActions()
|
||||
_statisticsAction->setActionGroup(_fileActionGroup);
|
||||
connect(_statisticsAction, &QAction::triggered, this, &GUI::statistics);
|
||||
addAction(_statisticsAction);
|
||||
#ifndef Q_OS_ANDROID
|
||||
_recentFilesActionGroup = new QActionGroup(this);
|
||||
connect(_recentFilesActionGroup, &QActionGroup::triggered, this,
|
||||
&GUI::recentFileSelected);
|
||||
_clearRecentFilesAction = new QAction(tr("Clear list"), this);
|
||||
_clearRecentFilesAction->setMenuRole(QAction::NoRole);
|
||||
connect(_clearRecentFilesAction, &QAction::triggered, this,
|
||||
&GUI::clearRecentFiles);
|
||||
#endif // Q_OS_ANDROID
|
||||
|
||||
// POI actions
|
||||
_poisActionGroup = new QActionGroup(this);
|
||||
@ -614,6 +627,14 @@ void GUI::createMenus()
|
||||
{
|
||||
QMenu *fileMenu = menuBar()->addMenu(tr("&File"));
|
||||
fileMenu->addAction(_openFileAction);
|
||||
#ifndef Q_OS_ANDROID
|
||||
_recentFilesMenu = fileMenu->addMenu(tr("Open recent"));
|
||||
_recentFilesMenu->setIcon(QIcon::fromTheme(OPEN_RECENT_NAME,
|
||||
QIcon(OPEN_RECENT_ICON)));
|
||||
_recentFilesMenu->setEnabled(false);
|
||||
_recentFilesEnd = _recentFilesMenu->addSeparator();
|
||||
_recentFilesMenu->addAction(_clearRecentFilesAction);
|
||||
#endif // Q_OS_ANDROID
|
||||
fileMenu->addAction(_openDirAction);
|
||||
fileMenu->addSeparator();
|
||||
#ifndef Q_OS_ANDROID
|
||||
@ -1018,6 +1039,9 @@ bool GUI::openFile(const QString &fileName, bool tryUnknown, int &showError)
|
||||
updateNavigationActions();
|
||||
updateStatusBarInfo();
|
||||
updateWindowTitle();
|
||||
#ifndef Q_OS_ANDROID
|
||||
updateRecentFiles(fileName);
|
||||
#endif // Q_OS_ANDROID
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -1992,6 +2016,48 @@ void GUI::updateWindowTitle()
|
||||
setWindowTitle(APP_NAME);
|
||||
}
|
||||
|
||||
#ifndef Q_OS_ANDROID
|
||||
void GUI::updateRecentFiles(const QString &fileName)
|
||||
{
|
||||
QAction *a = 0;
|
||||
|
||||
QList<QAction *> actions(_recentFilesActionGroup->actions());
|
||||
for (int i = 0; i < actions.size(); i++) {
|
||||
if (actions.at(i)->text() == fileName) {
|
||||
a = actions.at(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (a)
|
||||
delete a;
|
||||
else if (actions.size() == MAX_RECENT_FILES)
|
||||
delete actions.last();
|
||||
|
||||
actions = _recentFilesActionGroup->actions();
|
||||
QAction *before = actions.size() ? actions.last() : _recentFilesEnd;
|
||||
_recentFilesMenu->insertAction(before,
|
||||
new QAction(fileName, _recentFilesActionGroup));
|
||||
_recentFilesMenu->setEnabled(true);
|
||||
}
|
||||
|
||||
void GUI::clearRecentFiles()
|
||||
{
|
||||
QList<QAction *> actions(_recentFilesActionGroup->actions());
|
||||
|
||||
for (int i = 0; i < actions.size(); i++)
|
||||
delete actions.at(i);
|
||||
|
||||
_recentFilesMenu->setEnabled(false);
|
||||
}
|
||||
|
||||
void GUI::recentFileSelected(QAction *action)
|
||||
{
|
||||
int showError = 1;
|
||||
openFile(action->text(), true, showError);
|
||||
}
|
||||
#endif // Q_OS_ANDROID
|
||||
|
||||
void GUI::mapChanged(QAction *action)
|
||||
{
|
||||
_map = action->data().value<Map*>();
|
||||
@ -2353,6 +2419,18 @@ void GUI::writeSettings()
|
||||
#endif // Q_OS_ANDROID
|
||||
settings.endGroup();
|
||||
|
||||
/* File */
|
||||
#ifndef Q_OS_ANDROID
|
||||
QList<QAction*> recentActions(_recentFilesActionGroup->actions());
|
||||
QStringList recent;
|
||||
for (int i = 0; i < recentActions.size(); i++)
|
||||
recent.append(recentActions.at(i)->text());
|
||||
|
||||
settings.beginGroup(SETTINGS_FILE);
|
||||
WRITE(recentDataFiles, recent);
|
||||
settings.endGroup();
|
||||
#endif // Q_OS_ANDROID
|
||||
|
||||
/* Map */
|
||||
settings.beginGroup(SETTINGS_MAP);
|
||||
WRITE(activeMap, _map->name());
|
||||
@ -2372,11 +2450,11 @@ void GUI::writeSettings()
|
||||
settings.endGroup();
|
||||
|
||||
/* POI */
|
||||
QList<QAction*> actions(_poisActionGroup->actions());
|
||||
QList<QAction*> disabledActions(_poisActionGroup->actions());
|
||||
QStringList disabled;
|
||||
for (int i = 0; i < actions.size(); i++)
|
||||
if (!actions.at(i)->isChecked())
|
||||
disabled.append(actions.at(i)->data().toString());
|
||||
for (int i = 0; i < disabledActions.size(); i++)
|
||||
if (!disabledActions.at(i)->isChecked())
|
||||
disabled.append(disabledActions.at(i)->data().toString());
|
||||
|
||||
settings.beginGroup(SETTINGS_POI);
|
||||
WRITE(showPoi, _showPOIAction->isChecked());
|
||||
@ -2511,7 +2589,8 @@ void GUI::writeSettings()
|
||||
settings.endGroup();
|
||||
}
|
||||
|
||||
void GUI::readSettings(QString &activeMap, QStringList &disabledPOIs)
|
||||
void GUI::readSettings(QString &activeMap, QStringList &disabledPOIs,
|
||||
QStringList &recentFiles)
|
||||
{
|
||||
#define READ(name) \
|
||||
(Settings::name.read(settings))
|
||||
@ -2560,6 +2639,15 @@ void GUI::readSettings(QString &activeMap, QStringList &disabledPOIs)
|
||||
#endif // Q_OS_ANDROID
|
||||
settings.endGroup();
|
||||
|
||||
/* File */
|
||||
#ifndef Q_OS_ANDROID
|
||||
settings.beginGroup(SETTINGS_FILE);
|
||||
recentFiles = READ(recentDataFiles);
|
||||
settings.endGroup();
|
||||
#else // Q_OS_ANDROID
|
||||
Q_UNUSED(recentFiles);
|
||||
#endif // Q_OS_ANDROID
|
||||
|
||||
/* Map */
|
||||
settings.beginGroup(SETTINGS_MAP);
|
||||
if (READ(showMap).toBool()) {
|
||||
@ -3052,6 +3140,22 @@ void GUI::loadInitialPOIs(const QStringList &disabled)
|
||||
_unselectAllPOIAction->setEnabled(!poiActions.isEmpty());
|
||||
}
|
||||
|
||||
#ifndef Q_OS_ANDROID
|
||||
void GUI::loadRecentFiles(const QStringList &files)
|
||||
{
|
||||
QAction *before = _recentFilesEnd;
|
||||
|
||||
for (int i = 0; i < files.size(); i++) {
|
||||
QAction *a = new QAction(files.at(i), _recentFilesActionGroup);
|
||||
_recentFilesMenu->insertAction(before, a);
|
||||
before = a;
|
||||
}
|
||||
|
||||
if (!files.isEmpty())
|
||||
_recentFilesMenu->setEnabled(true);
|
||||
}
|
||||
#endif // Q_OS_ANDROID
|
||||
|
||||
QAction *GUI::mapAction(const QString &name)
|
||||
{
|
||||
QList<QAction *> maps(_mapsActionGroup->actions());
|
||||
|
@ -92,6 +92,10 @@ private slots:
|
||||
void poiFileChecked(QAction *action);
|
||||
void selectAllPOIs();
|
||||
void unselectAllPOIs();
|
||||
#ifndef Q_OS_ANDROID
|
||||
void recentFileSelected(QAction *action);
|
||||
void clearRecentFiles();
|
||||
#endif // Q_OS_ANDROID
|
||||
|
||||
void next();
|
||||
void prev();
|
||||
@ -161,6 +165,9 @@ private:
|
||||
void updateWindowTitle();
|
||||
bool updateGraphTabs();
|
||||
void updateDEMDownloadAction();
|
||||
#ifndef Q_OS_ANDROID
|
||||
void updateRecentFiles(const QString &fileName);
|
||||
#endif // Q_OS_ANDROID
|
||||
|
||||
TimeType timeType() const;
|
||||
Units units() const;
|
||||
@ -174,10 +181,14 @@ private:
|
||||
qreal movingTime() const;
|
||||
QAction *mapAction(const QString &name);
|
||||
QGeoPositionInfoSource *positionSource(const Options &options);
|
||||
void readSettings(QString &activeMap, QStringList &disabledPOIs);
|
||||
void readSettings(QString &activeMap, QStringList &disabledPOIs,
|
||||
QStringList &recentFiles);
|
||||
|
||||
void loadInitialMaps(const QString &selected);
|
||||
void loadInitialPOIs(const QStringList &disabled);
|
||||
#ifndef Q_OS_ANDROID
|
||||
void loadRecentFiles(const QStringList &files);
|
||||
#endif // Q_OS_ANDROID
|
||||
|
||||
void loadOptions();
|
||||
void updateOptions(const Options &options);
|
||||
@ -198,11 +209,17 @@ private:
|
||||
#endif // Q_OS_ANDROID
|
||||
QMenu *_poiMenu;
|
||||
QMenu *_mapMenu;
|
||||
#ifndef Q_OS_ANDROID
|
||||
QMenu *_recentFilesMenu;
|
||||
#endif // Q_OS_ANDROID
|
||||
|
||||
QActionGroup *_fileActionGroup;
|
||||
QActionGroup *_navigationActionGroup;
|
||||
QActionGroup *_mapsActionGroup;
|
||||
QActionGroup *_poisActionGroup;
|
||||
#ifndef Q_OS_ANDROID
|
||||
QActionGroup *_recentFilesActionGroup;
|
||||
#endif // Q_OS_ANDROID
|
||||
#if !defined(Q_OS_MAC) && !defined(Q_OS_ANDROID)
|
||||
QAction *_exitAction;
|
||||
#endif // Q_OS_MAC + Q_OS_ANDROID
|
||||
@ -276,6 +293,10 @@ private:
|
||||
QAction *_showDEMTilesAction;
|
||||
QAction *_mapsEnd;
|
||||
QAction *_poisEnd;
|
||||
#ifndef Q_OS_ANDROID
|
||||
QAction *_clearRecentFilesAction;
|
||||
QAction *_recentFilesEnd;
|
||||
#endif // Q_OS_ANDROID
|
||||
|
||||
QLabel *_fileNameLabel;
|
||||
QLabel *_distanceLabel;
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
// Toolbar/menu icons
|
||||
#define OPEN_FILE_ICON ":/icons/" APP_NAME "/actions/22x22/document-open.svg"
|
||||
#define OPEN_RECENT_ICON ":/icons/" APP_NAME "/actions/22x22/document-open-recent.svg"
|
||||
#define OPEN_DIR_ICON ":/icons/" APP_NAME "/actions/22x22/document-open-folder.svg"
|
||||
#define EXPORT_FILE_ICON ":/icons/" APP_NAME "/actions/22x22/document-export.svg"
|
||||
#define PRINT_FILE_ICON ":/icons/" APP_NAME "/actions/22x22/document-print.svg"
|
||||
@ -40,6 +41,7 @@
|
||||
|
||||
// Desktop theme names
|
||||
#define OPEN_FILE_NAME "document-open"
|
||||
#define OPEN_RECENT_NAME "document-open-recent"
|
||||
#define OPEN_DIR_NAME "document-open-folder"
|
||||
#define EXPORT_FILE_NAME "document-export"
|
||||
#define PRINT_FILE_NAME "document-print"
|
||||
|
@ -268,3 +268,8 @@ const Settings::SettingMap Settings::positionPluginParameters
|
||||
|
||||
const Settings::SettingList Settings::disabledPoiFiles
|
||||
= Settings::SettingList("disabled", "file");
|
||||
|
||||
#ifndef Q_OS_ANDROID
|
||||
const Settings::SettingList Settings::recentDataFiles
|
||||
= Settings::SettingList("recent", "file");
|
||||
#endif // Q_OS_ANDROID
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
#define SETTINGS_WINDOW "Window"
|
||||
#define SETTINGS_SETTINGS "Settings"
|
||||
#define SETTINGS_FILE "File"
|
||||
#define SETTINGS_MAP "Map"
|
||||
#define SETTINGS_GRAPH "Graph"
|
||||
#define SETTINGS_POI "POI"
|
||||
@ -84,6 +85,11 @@ public:
|
||||
static const Setting showToolbars;
|
||||
#endif // Q_OS_ANDROID
|
||||
|
||||
/* File */
|
||||
#ifndef Q_OS_ANDROID
|
||||
static const SettingList recentDataFiles;
|
||||
#endif // Q_OS_ANDROID
|
||||
|
||||
/* Map */
|
||||
static const Setting activeMap;
|
||||
static const Setting showMap;
|
||||
|
@ -1,6 +1,7 @@
|
||||
<RCC>
|
||||
<qresource prefix="/icons/GPXSee">
|
||||
<file alias="actions/22x22/document-open.svg">icons/GUI/FlatColor/actions/22x22/document-open.svg</file>
|
||||
<file alias="actions/22x22/document-open-recent.svg">icons/GUI/FlatColor/actions/22x22/document-open-recent.svg</file>
|
||||
<file alias="actions/22x22/document-open-folder.svg">icons/GUI/FlatColor/actions/22x22/document-open-folder.svg</file>
|
||||
<file alias="actions/22x22/document-export.svg">icons/GUI/FlatColor/actions/22x22/document-export.svg</file>
|
||||
<file alias="actions/22x22/document-print.svg">icons/GUI/FlatColor/actions/22x22/document-print.svg</file>
|
||||
|
@ -1,6 +1,7 @@
|
||||
<RCC>
|
||||
<qresource prefix="/icons/GPXSee">
|
||||
<file alias="actions/22x22/document-open.svg">icons/GUI/Papirus/actions/22x22/document-open.svg</file>
|
||||
<file alias="actions/22x22/document-open-recent.svg">icons/GUI/Papirus/actions/22x22/document-open-recent.svg</file>
|
||||
<file alias="actions/22x22/document-open-folder.svg">icons/GUI/Papirus/actions/22x22/document-open-folder.svg</file>
|
||||
<file alias="actions/22x22/document-export.svg">icons/GUI/Papirus/actions/22x22/document-export.svg</file>
|
||||
<file alias="actions/22x22/document-print.svg">icons/GUI/Papirus/actions/22x22/document-print.svg</file>
|
||||
|
Loading…
Reference in New Issue
Block a user