/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
void KDE5FilePicker::enableFolderMode()
{
_dialog->setOption(QFileDialog::ShowDirsOnly, true); // Workaround for https://bugs.kde.org/show_bug.cgi?id=406464 : // Don't set file mode to QFileDialog::Directory when native KDE Plasma 5 // file dialog is used, since clicking on directory "bar" inside directory "foo" // and then confirming would return "foo" rather than "foo/bar"; // on the other hand, non-native file dialog needs 'QFileDialog::Directory' // and doesn't allow folder selection otherwise if (Application::GetDesktopEnvironment() != "PLASMA5")
{
_dialog->setFileMode(QFileDialog::Directory);
}
}
bool KDE5FilePicker::execute()
{ if (!_filters.isEmpty())
_dialog->setNameFilters(_filters); if (!_currentFilter.isEmpty())
_dialog->selectNameFilter(_currentFilter);
_dialog->show(); //block and wait for user input return _dialog->exec() == QFileDialog::Accepted;
}
void KDE5FilePicker::setMultiSelectionMode(bool multiSelect)
{ if (_dialog->acceptMode() == QFileDialog::AcceptSave) return;
void KDE5FilePicker::appendFilter(const QString& title, const QString& filter)
{
QString t = title;
QString f = filter; // '/' need to be escaped else they are assumed to be mime types by kfiledialog //see the docs
t.replace("/", "\\/");
// openoffice gives us filters separated by ';' qt dialogs just want space separated
f.replace(";", " ");
// make sure "*.*" is not used as "all files"
f.replace("*.*", "*");
auto widget = new QCheckBox(resString, _extraControls);
widget->setHidden(hidden); if (!hidden)
{
_layout->addWidget(widget);
}
_customWidgets.insert(controlId, widget);
}
void KDE5FilePicker::setupCustomWidgets()
{ // When using the platform-native Plasma/KDE5 file picker, we currently rely on KFileWidget // being present to add the custom controls visible (s. 'eventFilter' method). // Since this doesn't work for other desktop environments, use a non-native // dialog there in order not to lose the custom controls and insert the custom // widget in the layout returned by QFileDialog::layout() // (which returns nullptr for native file dialogs) if (Application::GetDesktopEnvironment() == "PLASMA5")
{
qApp->installEventFilter(this);
} else
{
_dialog->setOption(QFileDialog::DontUseNativeDialog);
QGridLayout* pLayout = static_cast<QGridLayout*>(_dialog->layout());
assert(pLayout); constint row = pLayout->rowCount();
pLayout->addWidget(_extraControls, row, 1);
}
}
bool KDE5FilePicker::eventFilter(QObject* o, QEvent* e)
{ if (e->type() == QEvent::Show && o->isWidgetType())
{ auto* w = static_cast<QWidget*>(o); if (!w->parentWidget() && w->isModal())
{ /* To replace when baseline will include kwindowsystem >= 5.62 with: w->setAttribute(Qt::WA_NativeWindow, true); KWindowSystem::setMainWindow(w->windowHandle(), _winId);
*/
SAL_WNODEPRECATED_DECLARATIONS_PUSH
KWindowSystem::setMainWindow(w, _winId);
SAL_WNODEPRECATED_DECLARATIONS_POP if (auto* fileWidget = w->findChild<KFileWidget*>({}, Qt::FindDirectChildrenOnly))
{
fileWidget->setCustomWidget(_extraControls); // remove event filter again; the only purpose was to set the custom widget here
qApp->removeEventFilter(this);
}
}
} return QObject::eventFilter(o, e);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.