[Libreoffice-commits] core.git: Branch 'private/michaelweghorn/qt5_kde5_fpicker_deduplication' - 3 commits - vcl/inc vcl/qt5 vcl/unx

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Thu Feb 7 10:49:02 UTC 2019


 vcl/inc/qt5/Qt5FilePicker.hxx    |    4 
 vcl/qt5/Qt5FilePicker.cxx        |    6 +
 vcl/unx/kde5/KDE5FilePicker.hxx  |   38 ------
 vcl/unx/kde5/KDE5FilePicker2.cxx |  229 +++++----------------------------------
 4 files changed, 41 insertions(+), 236 deletions(-)

New commits:
commit e756031edbda566ff971ce6dfee2c4ca83e5af10
Author:     Michael Weghorn <m.weghorn at posteo.de>
AuthorDate: Wed Feb 6 18:11:34 2019 +0100
Commit:     Michael Weghorn <m.weghorn at posteo.de>
CommitDate: Thu Feb 7 11:41:25 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

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 da64c3a51936..fe3d74133944 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;
 
@@ -103,35 +99,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
commit 5a579b7891bfda0ef954984592f6749a491117a1
Author:     Michael Weghorn <m.weghorn at posteo.de>
AuthorDate: Wed Feb 6 17:45:56 2019 +0100
Commit:     Michael Weghorn <m.weghorn at posteo.de>
CommitDate: Wed Feb 6 17:47:20 2019 +0100

    Qt5FilePicker::addCustomControl: Add missing from kde5
    
    Take over functionality from 'KDE5FilePicker::addCustomControl'
    that has not been implemented in qt5 one yet.
    
    Change-Id: I9690e163b3b739bfec6813d9a4e1e0170b730187

diff --git a/vcl/qt5/Qt5FilePicker.cxx b/vcl/qt5/Qt5FilePicker.cxx
index 9a0d6e820783..0d2025cec55b 100644
--- a/vcl/qt5/Qt5FilePicker.cxx
+++ b/vcl/qt5/Qt5FilePicker.cxx
@@ -624,9 +624,13 @@ void Qt5FilePicker::addCustomControl(sal_Int16 controlId)
         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;
     }
@@ -653,6 +657,7 @@ void Qt5FilePicker::addCustomControl(sal_Int16 controlId)
             break;
         case LISTBOX_VERSION:
         case LISTBOX_TEMPLATE:
+        case LISTBOX_IMAGE_ANCHOR:
         case LISTBOX_IMAGE_TEMPLATE:
         case LISTBOX_FILTER_SELECTOR:
             label = new QLabel(getResString(resId), m_pExtraControls);
@@ -662,6 +667,7 @@ void Qt5FilePicker::addCustomControl(sal_Int16 controlId)
         case LISTBOX_VERSION_LABEL:
         case LISTBOX_TEMPLATE_LABEL:
         case LISTBOX_IMAGE_TEMPLATE_LABEL:
+        case LISTBOX_IMAGE_ANCHOR_LABEL:
             break;
     }
 
commit 4452d6e8b11307c2726676c5c42548ba351c5a1c
Author:     Michael Weghorn <m.weghorn at posteo.de>
AuthorDate: Wed Feb 6 17:12:32 2019 +0100
Commit:     Michael Weghorn <m.weghorn at posteo.de>
CommitDate: Wed Feb 6 17:24:20 2019 +0100

    kde5 fpicker: Reuse parent class member to store custom widgets
    
    Directly access member 'm_pExtraControls' from parent class
    Qt5FilePicker for managing custom widgets, rather than maintaining
    an own one.
    
    This is meant as an intermediate step, further refactoring will
    follow.
    
    Change-Id: I0568d3db68dc24042e198d36f4b5e49608f93a0e

diff --git a/vcl/unx/kde5/KDE5FilePicker.hxx b/vcl/unx/kde5/KDE5FilePicker.hxx
index 3d3a428cd5a0..da64c3a51936 100644
--- a/vcl/unx/kde5/KDE5FilePicker.hxx
+++ b/vcl/unx/kde5/KDE5FilePicker.hxx
@@ -54,9 +54,6 @@ protected:
     QHash<sal_Int16, QWidget*> _customWidgets;
     QHash<sal_Int16, QWidget*> _customListboxes;
 
-    //widget to contain extra custom controls
-    QWidget* _extraControls;
-
     //layout for extra custom controls
     QGridLayout* _layout;
 
@@ -64,7 +61,7 @@ protected:
 
 public:
     explicit KDE5FilePicker(QFileDialog::FileMode);
-    virtual ~KDE5FilePicker() override;
+    virtual ~KDE5FilePicker() override = default;
 
     // XExecutableDialog functions
     virtual sal_Int16 SAL_CALL execute() override;
diff --git a/vcl/unx/kde5/KDE5FilePicker2.cxx b/vcl/unx/kde5/KDE5FilePicker2.cxx
index 582bff27e494..cc79f0c99637 100644
--- a/vcl/unx/kde5/KDE5FilePicker2.cxx
+++ b/vcl/unx/kde5/KDE5FilePicker2.cxx
@@ -83,8 +83,7 @@ uno::Sequence<OUString> FilePicker_getSupportedServiceNames()
 KDE5FilePicker::KDE5FilePicker(QFileDialog::FileMode eMode)
     // Native kde5 filepicker does not add file extension automatically
     : Qt5FilePicker(eMode, true)
-    , _extraControls(new QWidget)
-    , _layout(new QGridLayout(_extraControls))
+    , _layout(new QGridLayout(m_pExtraControls))
     , allowRemoteUrls(false)
 {
     // use native dialog
@@ -119,8 +118,6 @@ KDE5FilePicker::KDE5FilePicker(QFileDialog::FileMode eMode)
     qApp->installEventFilter(this);
 }
 
-KDE5FilePicker::~KDE5FilePicker() { delete _extraControls; }
-
 sal_Int16 SAL_CALL KDE5FilePicker::execute()
 {
     if (qApp->thread() != QThread::currentThread())
@@ -327,7 +324,7 @@ void KDE5FilePicker::addCustomControl(sal_Int16 controlId)
             // code, but the checkbox is hidden and ignored
             bool hidden = controlId == CHECKBOX_AUTOEXTENSION;
 
-            auto widget = new QCheckBox(resString, _extraControls);
+            auto widget = new QCheckBox(resString, m_pExtraControls);
             widget->setHidden(hidden);
             if (!hidden)
             {
@@ -350,7 +347,7 @@ void KDE5FilePicker::addCustomControl(sal_Int16 controlId)
         case LISTBOX_TEMPLATE:
         case LISTBOX_VERSION:
         {
-            auto widget = new QComboBox(_extraControls);
+            auto widget = new QComboBox(m_pExtraControls);
             QLabel* label = new QLabel(resString);
             label->setBuddy(widget);
 
@@ -509,7 +506,7 @@ bool KDE5FilePicker::eventFilter(QObject* o, QEvent* e)
         {
             if (auto* fileWidget = w->findChild<KFileWidget*>({}, Qt::FindDirectChildrenOnly))
             {
-                fileWidget->setCustomWidget(_extraControls);
+                fileWidget->setCustomWidget(m_pExtraControls);
                 // remove event filter again; the only purpose was to set the custom widget here
                 qApp->removeEventFilter(this);
             }


More information about the Libreoffice-commits mailing list