Skip to content
Extraits de code Groupes Projets
Vérifiée Valider c069b6f1 rédigé par Kubat's avatar Kubat
Parcourir les fichiers

UI: Now we should use native dialogues with the custom theme + icons (it seems...

UI: Now we should use native dialogues with the custom theme + icons (it seems we can't hinib the qss with QFileDialogs...)
parent 8c726164
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!11Change a bit the UI + Add simple scripts support
...@@ -248,12 +248,12 @@ void ...@@ -248,12 +248,12 @@ void
MainWindow::openDocument() noexcept MainWindow::openDocument() noexcept
{ {
const QString separator = QStringLiteral(";;"); const QString separator = QStringLiteral(";;");
const QString filename = QFileDialog::getOpenFileName( const QString filename = dialogOpenFileName("Select a document to open", QDir::homePath(),
this, "Select a document to open", QDir::homePath(),
QStringLiteral("Vivy documents (*.vivy);;" QStringLiteral("Vivy documents (*.vivy);;"
"Vivy scripts (*.lua *.vvs);;") + "Vivy scripts (*.lua *.vvs);;") +
Utils::getAudioFileSuffixFilter() + separator + Utils::getVideoFileSuffixFilter() + Utils::getAudioFileSuffixFilter() + separator +
separator + Utils::getAssFileSuffixFilter()); Utils::getVideoFileSuffixFilter() + separator +
Utils::getAssFileSuffixFilter());
if (filename.isEmpty()) { if (filename.isEmpty()) {
qWarning() << "Found an empty filename, don't open a file"; qWarning() << "Found an empty filename, don't open a file";
return; return;
...@@ -393,3 +393,31 @@ MainWindow::documentViewActionsChanged() noexcept ...@@ -393,3 +393,31 @@ MainWindow::documentViewActionsChanged() noexcept
qInfo() << "No view to display:" << e.what(); qInfo() << "No view to display:" << e.what();
} }
} }
QString
MainWindow::dialogOpenFileName(const QString &title, const QString &folder,
const QString &filter) noexcept
{
QFileDialog dialog(this, title, folder, filter);
bool dialogAccepted = false;
std::unique_ptr<VivyFileIconProvider> iconProvider(new VivyFileIconProvider());
dialog.setOption(QFileDialog::ReadOnly);
dialog.setIconProvider(iconProvider.get());
dialog.setFileMode(QFileDialog::ExistingFile);
connect(&dialog, &QFileDialog::accepted, this,
[&dialogAccepted]() noexcept -> void { dialogAccepted = true; });
dialog.exec();
if (!dialogAccepted) {
return QStringLiteral("");
}
const QStringList resList = dialog.selectedFiles();
if (resList.size() != 1) {
qCritical() << "You must select only one file";
return QStringLiteral("");
}
return resList.at(0);
}
...@@ -46,14 +46,15 @@ private: ...@@ -46,14 +46,15 @@ private:
AbstractDocumentView *getCurrentDocumentView() const; AbstractDocumentView *getCurrentDocumentView() const;
int findFirstUntouchedDocument() const noexcept; int findFirstUntouchedDocument() const noexcept;
QString dialogOpenFileName(const QString &title, const QString &folder,
const QString &filter) noexcept;
// Do an action with the selected filename. The 'call' variable must be // Do an action with the selected filename. The 'call' variable must be
// callable like this: call(DocumentView, Document, QString) // callable like this: call(DocumentView, Document, QString)
template <typename DV, typename D> template <typename DV, typename D>
void withOpenFileNameDialog(const QString &title, const QString &filter, auto call) noexcept void withOpenFileNameDialog(const QString &title, const QString &filter, auto call) noexcept
{ {
const QString filename = const QString filename = dialogOpenFileName(title, QDir::homePath(), filter);
QFileDialog::getOpenFileName(this, title, QDir::homePath(), filter);
if (filename.isEmpty()) { if (filename.isEmpty()) {
qWarning() << "Found an empty filename, don't open a file"; qWarning() << "Found an empty filename, don't open a file";
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter