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
MainWindow::openDocument() noexcept
{
const QString separator = QStringLiteral(";;");
const QString filename = QFileDialog::getOpenFileName(
this, "Select a document to open", QDir::homePath(),
const QString filename = dialogOpenFileName("Select a document to open", QDir::homePath(),
QStringLiteral("Vivy documents (*.vivy);;"
"Vivy scripts (*.lua *.vvs);;") +
Utils::getAudioFileSuffixFilter() + separator + Utils::getVideoFileSuffixFilter() +
separator + Utils::getAssFileSuffixFilter());
Utils::getAudioFileSuffixFilter() + separator +
Utils::getVideoFileSuffixFilter() + separator +
Utils::getAssFileSuffixFilter());
if (filename.isEmpty()) {
qWarning() << "Found an empty filename, don't open a file";
return;
......@@ -393,3 +393,31 @@ MainWindow::documentViewActionsChanged() noexcept
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:
AbstractDocumentView *getCurrentDocumentView() const;
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
// callable like this: call(DocumentView, Document, QString)
template <typename DV, typename D>
void withOpenFileNameDialog(const QString &title, const QString &filter, auto call) noexcept
{
const QString filename =
QFileDialog::getOpenFileName(this, title, QDir::homePath(), filter);
const QString filename = dialogOpenFileName(title, QDir::homePath(), filter);
if (filename.isEmpty()) {
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