[Libreoffice-commits] core.git: vcl/inc vcl/unx

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Wed Feb 20 15:55:46 UTC 2019


 vcl/inc/qt5/Qt5FilePicker.hxx    |    4 
 vcl/unx/kde5/KDE5FilePicker.hxx  |   33 -----
 vcl/unx/kde5/KDE5FilePicker2.cxx |  222 +++++----------------------------------
 3 files changed, 32 insertions(+), 227 deletions(-)

New commits:
commit 0b93a6c3f1c706dd532e71deeefb480c6e0ea02e
Author:     Michael Weghorn <m.weghorn at posteo.de>
AuthorDate: Wed Feb 6 18:11:34 2019 +0100
Commit:     Katarina Behrens <Katarina.Behrens at cib.de>
CommitDate: Wed Feb 20 16:55:18 2019 +0100

    KDE5FilePicker: Reuse custom controls from parent class
    
    Use the custom controls widgets from the parent class
    Qt5FileWidget and drop the own class members that were
    used for this.
    
    Also call the base class's implementations for the methods
    that interact with the custom controls.
    Since the native Plasma/kde5 file picker handles automatic
    file extensions by itself while the non-native qt5 one does
    not, the methods in KDE5FilePicker only forward those
    method calls that are not related to the corresponding
    control ('CHECKBOX_AUTOEXTENSION').
    
    Change-Id: Ia2de3211ffba7814683914a5e629208b19b2ed82
    Reviewed-on: https://gerrit.libreoffice.org/68057
    Tested-by: Jenkins
    Reviewed-by: Katarina Behrens <Katarina.Behrens at cib.de>

diff --git a/vcl/inc/qt5/Qt5FilePicker.hxx b/vcl/inc/qt5/Qt5FilePicker.hxx
index 4a546da46b53..8b8055efab9d 100644
--- a/vcl/inc/qt5/Qt5FilePicker.hxx
+++ b/vcl/inc/qt5/Qt5FilePicker.hxx
@@ -152,6 +152,8 @@ protected:
     static css::uno::Any handleGetListValue(QComboBox* pWidget, sal_Int16 nControlAction);
     static void handleSetListValue(QComboBox* pQComboBox, sal_Int16 nAction,
                                    const css::uno::Any& rValue);
+    void addCustomControl(sal_Int16 controlId);
+    void setCustomControlWidgetLayout(QGridLayout* pLayout) { m_pLayout = pLayout; }
 
 private Q_SLOTS:
     // XExecutableDialog functions
@@ -272,8 +274,6 @@ private:
     Qt5FilePicker(const Qt5FilePicker&) = delete;
     Qt5FilePicker& operator=(const Qt5FilePicker&) = delete;
 
-    void addCustomControl(sal_Int16 controlId);
-
     static QString getResString(const char* pRedId);
 
 private Q_SLOTS:
diff --git a/vcl/unx/kde5/KDE5FilePicker.hxx b/vcl/unx/kde5/KDE5FilePicker.hxx
index 044a921eeb72..dcde5a372fb0 100644
--- a/vcl/unx/kde5/KDE5FilePicker.hxx
+++ b/vcl/unx/kde5/KDE5FilePicker.hxx
@@ -50,10 +50,6 @@ class KDE5FilePicker : public Qt5FilePicker
 {
     Q_OBJECT
 protected:
-    //mapping of SAL control ID's to created custom controls
-    QHash<sal_Int16, QWidget*> _customWidgets;
-    QHash<sal_Int16, QWidget*> _customListboxes;
-
     //layout for extra custom controls
     QGridLayout* _layout;
 
@@ -102,35 +98,6 @@ protected:
 
 Q_SIGNALS:
     sal_Int16 executeSignal();
-    void setValueSignal(sal_Int16 nControlId, sal_Int16 nControlAction,
-                        const css::uno::Any& rValue);
-    css::uno::Any getValueSignal(sal_Int16 nControlId, sal_Int16 nControlAction);
-    void enableControlSignal(sal_Int16 nControlId, bool bEnable);
-    void setLabelSignal(sal_Int16 nControlId, const OUString& rLabel);
-    OUString getLabelSignal(sal_Int16 nControlId);
-
-private Q_SLOTS:
-    void setValueSlot(sal_Int16 nControlId, sal_Int16 nControlAction, const css::uno::Any& rValue)
-    {
-        return setValue(nControlId, nControlAction, rValue);
-    }
-
-    css::uno::Any getValueSlot(sal_Int16 nControlId, sal_Int16 nControlAction)
-    {
-        return getValue(nControlId, nControlAction);
-    }
-
-    void enableControlSlot(sal_Int16 nControlId, bool bEnable)
-    {
-        return enableControl(nControlId, bEnable);
-    }
-
-    void setLabelSlot(sal_Int16 nControId, const OUString& rLabel)
-    {
-        return setLabel(nControId, rLabel);
-    }
-
-    OUString getLabelSlot(sal_Int16 nControlId) { return getLabel(nControlId); }
 };
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/unx/kde5/KDE5FilePicker2.cxx b/vcl/unx/kde5/KDE5FilePicker2.cxx
index cc79f0c99637..3f4f61575185 100644
--- a/vcl/unx/kde5/KDE5FilePicker2.cxx
+++ b/vcl/unx/kde5/KDE5FilePicker2.cxx
@@ -89,6 +89,14 @@ KDE5FilePicker::KDE5FilePicker(QFileDialog::FileMode eMode)
     // use native dialog
     m_pFileDialog->setOption(QFileDialog::DontUseNativeDialog, false);
 
+    // only columns 0 and 1 are used by controls (s. Qt5FilePicker::addCustomControl);
+    // set stretch for (unused) column 2 in order for the controls to only take the space
+    // they actually need and avoid empty space in between
+    _layout->setColumnStretch(2, 1);
+
+    // set layout so custom widgets show up in our native file dialog
+    setCustomControlWidgetLayout(_layout);
+
     m_pFileDialog->setSupportedSchemes({
         QStringLiteral("file"),
         QStringLiteral("ftp"),
@@ -102,18 +110,6 @@ KDE5FilePicker::KDE5FilePicker(QFileDialog::FileMode eMode)
     connect(this, &KDE5FilePicker::executeSignal, this, &KDE5FilePicker::execute,
             Qt::BlockingQueuedConnection);
 
-    // XFilePickerControlAccess
-    connect(this, &KDE5FilePicker::setValueSignal, this, &KDE5FilePicker::setValueSlot,
-            Qt::BlockingQueuedConnection);
-    connect(this, &KDE5FilePicker::getValueSignal, this, &KDE5FilePicker::getValueSlot,
-            Qt::BlockingQueuedConnection);
-    connect(this, &KDE5FilePicker::setLabelSignal, this, &KDE5FilePicker::setLabelSlot,
-            Qt::BlockingQueuedConnection);
-    connect(this, &KDE5FilePicker::getLabelSignal, this, &KDE5FilePicker::getLabelSlot,
-            Qt::BlockingQueuedConnection);
-    connect(this, &KDE5FilePicker::enableControlSignal, this, &KDE5FilePicker::enableControlSlot,
-            Qt::BlockingQueuedConnection);
-
     // used to set the custom controls
     qApp->installEventFilter(this);
 }
@@ -140,29 +136,11 @@ sal_Int16 SAL_CALL KDE5FilePicker::execute()
 void SAL_CALL KDE5FilePicker::setValue(sal_Int16 controlId, sal_Int16 nControlAction,
                                        const uno::Any& value)
 {
-    if (qApp->thread() != QThread::currentThread())
-    {
-        SolarMutexReleaser aReleaser;
-        return Q_EMIT setValueSignal(controlId, nControlAction, value);
-    }
-
-    if (_customWidgets.contains(controlId))
-    {
-        bool bChecked = false;
-        value >>= bChecked;
+    if (CHECKBOX_AUTOEXTENSION == controlId)
+        // We ignore this one and rely on QFileDialog to provide the functionality
+        return;
 
-        QCheckBox* cb = dynamic_cast<QCheckBox*>(_customWidgets.value(controlId));
-        if (cb)
-            cb->setChecked(bChecked);
-    }
-    else if (_customListboxes.contains(controlId))
-    {
-        QComboBox* cb = dynamic_cast<QComboBox*>(_customListboxes.value(controlId));
-        if (cb)
-            Qt5FilePicker::handleSetListValue(cb, nControlAction, value);
-    }
-    else
-        SAL_WARN("vcl.kde5", "set value on unknown control " << controlId);
+    Qt5FilePicker::setValue(controlId, nControlAction, value);
 }
 
 uno::Any SAL_CALL KDE5FilePicker::getValue(sal_Int16 controlId, sal_Int16 nControlAction)
@@ -181,184 +159,44 @@ uno::Any SAL_CALL KDE5FilePicker::getValue(sal_Int16 controlId, sal_Int16 nContr
         // saves the value of the setting, so LO core is not needed for that either.
         return uno::Any(false);
 
-    bool value = false;
-    if (_customWidgets.contains(controlId))
-    {
-        QCheckBox* cb = dynamic_cast<QCheckBox*>(_customWidgets.value(controlId));
-        if (cb)
-            value = cb->isChecked();
-    }
-    else if (_customListboxes.contains(controlId))
-    {
-        QComboBox* cb = dynamic_cast<QComboBox*>(_customListboxes.value(controlId));
-        if (cb)
-            return Qt5FilePicker::handleGetListValue(cb, nControlAction);
-    }
-    else
-        SAL_WARN("vcl.kde5", "get value on unknown control" << controlId);
-
-    return uno::Any(value);
+    return Qt5FilePicker::getValue(controlId, nControlAction);
 }
 
 void SAL_CALL KDE5FilePicker::enableControl(sal_Int16 controlId, sal_Bool enable)
 {
-    if (qApp->thread() != QThread::currentThread())
-    {
-        SolarMutexReleaser aReleaser;
-        return Q_EMIT enableControlSignal(controlId, enable);
-    }
+    if (CHECKBOX_AUTOEXTENSION == controlId)
+        // We ignore this one and rely on QFileDialog to provide the functionality
+        return;
 
-    if (_customWidgets.contains(controlId))
-        _customWidgets.value(controlId)->setEnabled(enable);
-    else
-        SAL_WARN("vcl.kde5", "enable on unknown control " << controlId);
+    Qt5FilePicker::enableControl(controlId, enable);
 }
 
 void SAL_CALL KDE5FilePicker::setLabel(sal_Int16 controlId, const OUString& label)
 {
-    if (qApp->thread() != QThread::currentThread())
-    {
-        SolarMutexReleaser aReleaser;
-        return Q_EMIT setLabelSignal(controlId, label);
-    }
+    if (CHECKBOX_AUTOEXTENSION == controlId)
+        // We ignore this one and rely on QFileDialog to provide the functionality
+        return;
 
-    if (_customWidgets.contains(controlId))
-    {
-        QCheckBox* cb = dynamic_cast<QCheckBox*>(_customWidgets.value(controlId));
-        if (cb)
-            cb->setText(toQString(label));
-    }
-    else
-        SAL_WARN("vcl.kde5", "set label on unknown control " << controlId);
+    Qt5FilePicker::setLabel(controlId, label);
 }
 
 OUString SAL_CALL KDE5FilePicker::getLabel(sal_Int16 controlId)
 {
-    if (qApp->thread() != QThread::currentThread())
-    {
-        SolarMutexReleaser aReleaser;
-        return Q_EMIT getLabelSignal(controlId);
-    }
-
-    OUString label;
-    if (_customWidgets.contains(controlId))
-    {
-        QCheckBox* cb = dynamic_cast<QCheckBox*>(_customWidgets.value(controlId));
-        if (cb)
-            label = toOUString(cb->text());
-    }
-    else
-        SAL_WARN("vcl.kde5", "get label on unknown control " << controlId);
+    // We ignore this one and rely on QFileDialog to provide the functionality
+    if (CHECKBOX_AUTOEXTENSION == controlId)
+        return "";
 
-    return label;
+    return Qt5FilePicker::getLabel(controlId);
 }
 
 void KDE5FilePicker::addCustomControl(sal_Int16 controlId)
 {
-    const char* resId = nullptr;
+    // native kde5 filepicker has its own autoextension checkbox,
+    // therefore avoid adding yet another one
+    if (controlId == CHECKBOX_AUTOEXTENSION)
+        return;
 
-    switch (controlId)
-    {
-        case CHECKBOX_AUTOEXTENSION:
-            resId = STR_FPICKER_AUTO_EXTENSION;
-            break;
-        case CHECKBOX_PASSWORD:
-            resId = STR_FPICKER_PASSWORD;
-            break;
-        case CHECKBOX_FILTEROPTIONS:
-            resId = STR_FPICKER_FILTER_OPTIONS;
-            break;
-        case CHECKBOX_READONLY:
-            resId = STR_FPICKER_READONLY;
-            break;
-        case CHECKBOX_LINK:
-            resId = STR_FPICKER_INSERT_AS_LINK;
-            break;
-        case CHECKBOX_PREVIEW:
-            resId = STR_FPICKER_SHOW_PREVIEW;
-            break;
-        case CHECKBOX_SELECTION:
-            resId = STR_FPICKER_SELECTION;
-            break;
-        case CHECKBOX_GPGENCRYPTION:
-            resId = STR_FPICKER_GPGENCRYPT;
-            break;
-        case PUSHBUTTON_PLAY:
-            resId = STR_FPICKER_PLAY;
-            break;
-        case LISTBOX_VERSION:
-            resId = STR_FPICKER_VERSION;
-            break;
-        case LISTBOX_TEMPLATE:
-            resId = STR_FPICKER_TEMPLATES;
-            break;
-        case LISTBOX_IMAGE_TEMPLATE:
-            resId = STR_FPICKER_IMAGE_TEMPLATE;
-            break;
-        case LISTBOX_IMAGE_ANCHOR:
-            resId = STR_FPICKER_IMAGE_ANCHOR;
-            break;
-        case LISTBOX_VERSION_LABEL:
-        case LISTBOX_TEMPLATE_LABEL:
-        case LISTBOX_IMAGE_TEMPLATE_LABEL:
-        case LISTBOX_IMAGE_ANCHOR_LABEL:
-        case LISTBOX_FILTER_SELECTOR:
-            break;
-    }
-
-    auto resString = toQString(VclResId(resId));
-    resString.replace('~', '&');
-
-    switch (controlId)
-    {
-        case CHECKBOX_AUTOEXTENSION:
-        case CHECKBOX_PASSWORD:
-        case CHECKBOX_FILTEROPTIONS:
-        case CHECKBOX_READONLY:
-        case CHECKBOX_LINK:
-        case CHECKBOX_PREVIEW:
-        case CHECKBOX_SELECTION:
-        case CHECKBOX_GPGENCRYPTION:
-        {
-            // the checkbox is created even for CHECKBOX_AUTOEXTENSION to simplify
-            // code, but the checkbox is hidden and ignored
-            bool hidden = controlId == CHECKBOX_AUTOEXTENSION;
-
-            auto widget = new QCheckBox(resString, m_pExtraControls);
-            widget->setHidden(hidden);
-            if (!hidden)
-            {
-                _layout->addWidget(widget);
-            }
-            _customWidgets.insert(controlId, widget);
-
-            break;
-        }
-        case PUSHBUTTON_PLAY:
-        case LISTBOX_VERSION_LABEL:
-        case LISTBOX_TEMPLATE_LABEL:
-        case LISTBOX_IMAGE_TEMPLATE_LABEL:
-        case LISTBOX_IMAGE_ANCHOR_LABEL:
-        case LISTBOX_FILTER_SELECTOR:
-            break;
-
-        case LISTBOX_IMAGE_ANCHOR:
-        case LISTBOX_IMAGE_TEMPLATE:
-        case LISTBOX_TEMPLATE:
-        case LISTBOX_VERSION:
-        {
-            auto widget = new QComboBox(m_pExtraControls);
-            QLabel* label = new QLabel(resString);
-            label->setBuddy(widget);
-
-            QHBoxLayout* hBox = new QHBoxLayout;
-            hBox->addWidget(label);
-            hBox->addWidget(widget);
-            _layout->addLayout(hBox, _layout->rowCount(), 0, Qt::AlignLeft);
-            _customListboxes.insert(controlId, widget);
-            break;
-        }
-    }
+    Qt5FilePicker::addCustomControl(controlId);
 }
 
 // XInitialization


More information about the Libreoffice-commits mailing list