Direct file dialog (no need for QtQuick Controls)
This should simplify the needed packages on Debian, Ubuntu, etc
This commit is contained in:
parent
d92647b364
commit
7339e261e9
4 changed files with 165 additions and 14 deletions
|
@ -242,7 +242,7 @@ void LauncherMainWindow::initQML()
|
|||
|
||||
qmlRegisterUncreatableType<SettingsControl>("FlightGear.Launcher", 1, 0, "Control", "Base class");
|
||||
qmlRegisterUncreatableType<LaunchConfig>("FlightGear.Launcher", 1, 0, "LaunchConfig", "Singleton API");
|
||||
qmlRegisterType<PathUrlHelper>("FlightGear.Launcher", 1, 0, "PathUrlHelper");
|
||||
qmlRegisterType<FileDialogWrapper>("FlightGear.Launcher", 1, 0, "FileDialog");
|
||||
|
||||
qmlRegisterType<FlickableExtentQuery>("FlightGear.Launcher", 1, 0, "FlickableExtentQuery");
|
||||
qmlRegisterType<QmlAircraftInfo>("FlightGear.Launcher", 1, 0, "AircraftInfo");
|
||||
|
|
|
@ -1,16 +1,118 @@
|
|||
#include "PathUrlHelper.hxx"
|
||||
|
||||
PathUrlHelper::PathUrlHelper(QObject *parent) : QObject(parent)
|
||||
#include <QFileDialog>
|
||||
|
||||
FileDialogWrapper::FileDialogWrapper(QObject *parent) : QObject(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QString PathUrlHelper::urlToLocalFilePath(QUrl url) const
|
||||
QString FileDialogWrapper::urlToLocalFilePath(QUrl url) const
|
||||
{
|
||||
return url.toLocalFile();
|
||||
}
|
||||
|
||||
QUrl PathUrlHelper::urlFromLocalFilePath(QString path) const
|
||||
QUrl FileDialogWrapper::urlFromLocalFilePath(QString path) const
|
||||
{
|
||||
return QUrl::fromLocalFile(path);
|
||||
}
|
||||
|
||||
void FileDialogWrapper::open()
|
||||
{
|
||||
QUrl u;
|
||||
if (m_selectFolder) {
|
||||
u = QFileDialog::getExistingDirectoryUrl(nullptr, m_dialogTitle,
|
||||
m_currentFolder);
|
||||
|
||||
} else {
|
||||
u = QFileDialog::getOpenFileUrl(nullptr, m_dialogTitle, m_currentFolder,
|
||||
m_filter);
|
||||
}
|
||||
|
||||
if (u.isValid()) {
|
||||
m_fileUrl = u;
|
||||
accepted();
|
||||
} else {
|
||||
rejected();
|
||||
}
|
||||
}
|
||||
|
||||
QUrl FileDialogWrapper::folder() const
|
||||
{
|
||||
return m_currentFolder;
|
||||
}
|
||||
|
||||
QString FileDialogWrapper::title() const
|
||||
{
|
||||
return m_dialogTitle;
|
||||
}
|
||||
|
||||
bool FileDialogWrapper::selectFolder() const
|
||||
{
|
||||
return m_selectFolder;
|
||||
}
|
||||
|
||||
QUrl FileDialogWrapper::fileUrl() const
|
||||
{
|
||||
return m_fileUrl;
|
||||
}
|
||||
|
||||
QString FileDialogWrapper::filePath() const
|
||||
{
|
||||
return urlToLocalFilePath(fileUrl());
|
||||
}
|
||||
|
||||
QString FileDialogWrapper::filter() const
|
||||
{
|
||||
return m_filter;
|
||||
}
|
||||
|
||||
void FileDialogWrapper::setFolder(QUrl folder)
|
||||
{
|
||||
if (m_currentFolder == folder)
|
||||
return;
|
||||
|
||||
m_currentFolder = folder;
|
||||
emit folderChanged(m_currentFolder);
|
||||
}
|
||||
|
||||
void FileDialogWrapper::setTitle(QString title)
|
||||
{
|
||||
if (m_dialogTitle == title)
|
||||
return;
|
||||
|
||||
m_dialogTitle = title;
|
||||
emit titleChanged(m_dialogTitle);
|
||||
}
|
||||
|
||||
void FileDialogWrapper::setSelectFolder(bool selectFolder)
|
||||
{
|
||||
if (m_selectFolder == selectFolder)
|
||||
return;
|
||||
|
||||
m_selectFolder = selectFolder;
|
||||
emit selectFolderChanged(m_selectFolder);
|
||||
}
|
||||
|
||||
void FileDialogWrapper::setFileUrl(QUrl fileUrl)
|
||||
{
|
||||
if (m_fileUrl == fileUrl)
|
||||
return;
|
||||
|
||||
m_fileUrl = fileUrl;
|
||||
emit fileUrlChanged(m_fileUrl);
|
||||
}
|
||||
|
||||
void FileDialogWrapper::setFilePath(QString filePath)
|
||||
{
|
||||
setFileUrl(urlFromLocalFilePath(filePath));
|
||||
}
|
||||
|
||||
void FileDialogWrapper::setFilter(QString filter)
|
||||
{
|
||||
if (m_filter == filter)
|
||||
return;
|
||||
|
||||
m_filter = filter;
|
||||
emit filterChanged(m_filter);
|
||||
}
|
||||
|
|
|
@ -4,18 +4,72 @@
|
|||
#include <QObject>
|
||||
#include <QUrl>
|
||||
|
||||
class PathUrlHelper : public QObject
|
||||
class FileDialogWrapper : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(QUrl folder READ folder WRITE setFolder NOTIFY folderChanged)
|
||||
Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged)
|
||||
Q_PROPERTY(bool selectFolder READ selectFolder WRITE setSelectFolder NOTIFY selectFolderChanged)
|
||||
Q_PROPERTY(QUrl fileUrl READ fileUrl WRITE setFileUrl NOTIFY fileUrlChanged)
|
||||
Q_PROPERTY(QString filePath READ filePath WRITE setFilePath NOTIFY fileUrlChanged)
|
||||
Q_PROPERTY(QString filter READ filter WRITE setFilter NOTIFY filterChanged)
|
||||
public:
|
||||
explicit PathUrlHelper(QObject *parent = nullptr);
|
||||
explicit FileDialogWrapper(QObject *parent = nullptr);
|
||||
|
||||
Q_INVOKABLE QString urlToLocalFilePath(QUrl url) const;
|
||||
|
||||
Q_INVOKABLE QUrl urlFromLocalFilePath(QString path) const;
|
||||
|
||||
Q_INVOKABLE void open();
|
||||
|
||||
QUrl folder() const;
|
||||
|
||||
QString title() const;
|
||||
|
||||
bool selectFolder() const;
|
||||
|
||||
QUrl fileUrl() const;
|
||||
|
||||
QString filePath() const;
|
||||
|
||||
QString filter() const;
|
||||
|
||||
signals:
|
||||
|
||||
void accepted();
|
||||
void rejected();
|
||||
|
||||
void folderChanged(QUrl folder);
|
||||
|
||||
void titleChanged(QString title);
|
||||
|
||||
void selectFolderChanged(bool selectFolder);
|
||||
|
||||
void fileUrlChanged(QUrl fileUrl);
|
||||
|
||||
void filterChanged(QString filter);
|
||||
|
||||
public slots:
|
||||
|
||||
void setFolder(QUrl folder);
|
||||
|
||||
void setTitle(QString title);
|
||||
|
||||
void setSelectFolder(bool selectFolder);
|
||||
|
||||
void setFileUrl(QUrl fileUrl);
|
||||
|
||||
void setFilePath(QString filePath);
|
||||
|
||||
void setFilter(QString filter);
|
||||
|
||||
private:
|
||||
QUrl m_currentFolder;
|
||||
QUrl m_fileUrl;
|
||||
bool m_selectFolder = false;
|
||||
QString m_dialogTitle;
|
||||
QString m_filter;
|
||||
};
|
||||
|
||||
#endif // PATHURLHELPER_H
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import QtQuick 2.0
|
||||
import QtQuick.Dialogs 1.0 as Dialogs
|
||||
import FlightGear.Launcher 1.0 as FG
|
||||
|
||||
import "."
|
||||
|
@ -20,7 +19,7 @@ SettingControl {
|
|||
|
||||
readonly property bool isDefault: (path.length == 0) || (path == defaultPath)
|
||||
|
||||
readonly property url effectiveUrl: pathHelper.urlFromLocalFilePath(effectivePath());
|
||||
readonly property url effectiveUrl: picker.urlFromLocalFilePath(effectivePath());
|
||||
|
||||
function effectivePath()
|
||||
{
|
||||
|
@ -91,19 +90,15 @@ SettingControl {
|
|||
width: parent.width
|
||||
}
|
||||
|
||||
Dialogs.FileDialog {
|
||||
FG.FileDialog {
|
||||
id: picker
|
||||
|
||||
onAccepted: {
|
||||
path = pathHelper.urlToLocalFilePath(picker.fileUrl);
|
||||
path = filePath
|
||||
}
|
||||
|
||||
onRejected: {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
FG.PathUrlHelper {
|
||||
id: pathHelper
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue