Make clang-format happy, remove vcl/unx/kde5 from blacklist

just between us girls, I hate you clang-format

Change-Id: I4cd041eff7a9fa01eb9192cf357e3f07a26fa6ad
diff --git a/solenv/clang-format/blacklist b/solenv/clang-format/blacklist
index 7dcd631..79c639c 100644
--- a/solenv/clang-format/blacklist
+++ b/solenv/clang-format/blacklist
@@ -18501,24 +18501,6 @@ vcl/unx/kde4/VCLKDEApplication.hxx
vcl/unx/kde4/main.cxx
vcl/unx/kde4/tst_exclude_posted_events.hxx
vcl/unx/kde4/tst_exclude_socket_notifiers.hxx
vcl/unx/kde5/FPServiceInfo.hxx
vcl/unx/kde5/KDE5Data.cxx
vcl/unx/kde5/KDE5Data.hxx
vcl/unx/kde5/KDE5SalDisplay.cxx
vcl/unx/kde5/KDE5SalDisplay.hxx
vcl/unx/kde5/KDE5SalFrame.cxx
vcl/unx/kde5/KDE5SalFrame.hxx
vcl/unx/kde5/KDE5SalGraphics.cxx
vcl/unx/kde5/KDE5SalGraphics.hxx
vcl/unx/kde5/KDE5SalInstance.cxx
vcl/unx/kde5/KDE5SalInstance.hxx
vcl/unx/kde5/KDE5XLib.cxx
vcl/unx/kde5/KDE5XLib.hxx
vcl/unx/kde5/VCLKDE5Application.cxx
vcl/unx/kde5/VCLKDE5Application.hxx
vcl/unx/kde5/main.cxx
vcl/unx/kde5/tst_exclude_posted_events.hxx
vcl/unx/kde5/tst_exclude_socket_notifiers.hxx
vcl/unx/x11/x11sys.cxx
vcl/unx/x11/xlimits.cxx
vcl/win/app/saldata.cxx
diff --git a/vcl/inc/qt5/Qt5FilePicker.hxx b/vcl/inc/qt5/Qt5FilePicker.hxx
index 1aa19b3..9133c43 100644
--- a/vcl/inc/qt5/Qt5FilePicker.hxx
+++ b/vcl/inc/qt5/Qt5FilePicker.hxx
@@ -43,190 +43,218 @@ class QGridLayout;
class QLabel;
class QWidget;

typedef ::cppu::WeakComponentImplHelper
    < css::ui::dialogs::XFilePicker3
    , css::ui::dialogs::XFilePickerControlAccess
    , css::ui::dialogs::XFolderPicker2
    , css::lang::XInitialization
    , css::lang::XServiceInfo
    > Qt5FilePicker_Base;
typedef ::cppu::WeakComponentImplHelper<
    css::ui::dialogs::XFilePicker3, css::ui::dialogs::XFilePickerControlAccess,
    css::ui::dialogs::XFolderPicker2, css::lang::XInitialization, css::lang::XServiceInfo>
    Qt5FilePicker_Base;

class Qt5FilePicker
    : public QObject
    , public Qt5FilePicker_Base
class Qt5FilePicker : public QObject, public Qt5FilePicker_Base
{
    Q_OBJECT

protected:
    css::uno::Reference< css::ui::dialogs::XFilePickerListener > m_xListener;
    css::uno::Reference<css::ui::dialogs::XFilePickerListener> m_xListener;

    QFileDialog* m_pFileDialog;    ///< the non-extendable file picker dialog
    QFileDialog* m_pFileDialog; ///< the non-extendable file picker dialog

    osl::Mutex   m_aHelperMutex;   ///< mutex used by the WeakComponentImplHelper
    osl::Mutex m_aHelperMutex; ///< mutex used by the WeakComponentImplHelper

    QStringList  m_aNamedFilterList;     ///< named filter list for the QFileDialog
    QStringList  m_aFilterTitleList;     ///< the original filter titles
    QString      m_aCurrentFilterTitle;  ///< the current filter title
    QStringList m_aNamedFilterList; ///< named filter list for the QFileDialog
    QStringList m_aFilterTitleList; ///< the original filter titles
    QString m_aCurrentFilterTitle; ///< the current filter title

    QDialog                    *m_pOptionsDialog;    ///< an extra options dialog window
    QLabel                     *m_pFilenameLabel;    ///< label to display the filename
    QLabel                     *m_pFilterLabel;      ///< label to display the filter
    QHash<sal_Int16, QWidget*>  m_aCustomWidgetsMap; ///< map of SAL control ID's to widget
    QDialog* m_pOptionsDialog; ///< an extra options dialog window
    QLabel* m_pFilenameLabel; ///< label to display the filename
    QLabel* m_pFilterLabel; ///< label to display the filter
    QHash<sal_Int16, QWidget*> m_aCustomWidgetsMap; ///< map of SAL control ID's to widget

public:
    explicit Qt5FilePicker( QFileDialog::FileMode );
    explicit Qt5FilePicker(QFileDialog::FileMode);
    virtual ~Qt5FilePicker() override;

    // XFilePickerNotifier
    virtual void SAL_CALL addFilePickerListener( const css::uno::Reference< css::ui::dialogs::XFilePickerListener >& xListener ) override;
    virtual void SAL_CALL removeFilePickerListener( const css::uno::Reference< css::ui::dialogs::XFilePickerListener >& xListener ) override;
    virtual void SAL_CALL addFilePickerListener(
        const css::uno::Reference<css::ui::dialogs::XFilePickerListener>& xListener) override;
    virtual void SAL_CALL removeFilePickerListener(
        const css::uno::Reference<css::ui::dialogs::XFilePickerListener>& xListener) override;

    // XFilterManager functions
    virtual void SAL_CALL appendFilter( const OUString &rTitle, const OUString &rFilter ) override;
    virtual void SAL_CALL setCurrentFilter( const OUString &rTitle ) override;
    virtual void SAL_CALL appendFilter(const OUString& rTitle, const OUString& rFilter) override;
    virtual void SAL_CALL setCurrentFilter(const OUString& rTitle) override;
    virtual OUString SAL_CALL getCurrentFilter() override;

    // XFilterGroupManager functions
    virtual void SAL_CALL appendFilterGroup( const OUString &rGroupTitle, const css::uno::Sequence< css::beans::StringPair > &rFilters ) override;
    virtual void SAL_CALL
    appendFilterGroup(const OUString& rGroupTitle,
                      const css::uno::Sequence<css::beans::StringPair>& rFilters) override;

    // XCancellable
    virtual void SAL_CALL cancel( ) override;
    virtual void SAL_CALL cancel() override;

    // XExecutableDialog functions
    virtual void SAL_CALL setTitle( const OUString &rTitle ) override;
    virtual void SAL_CALL setTitle(const OUString& rTitle) override;
    virtual sal_Int16 SAL_CALL execute() override;

    // XFilePicker functions
    virtual void SAL_CALL setMultiSelectionMode( sal_Bool bMode ) override;
    virtual void SAL_CALL setDefaultName( const OUString &rName ) override;
    virtual void SAL_CALL setDisplayDirectory( const OUString &rDirectory ) override;
    virtual void SAL_CALL setMultiSelectionMode(sal_Bool bMode) override;
    virtual void SAL_CALL setDefaultName(const OUString& rName) override;
    virtual void SAL_CALL setDisplayDirectory(const OUString& rDirectory) override;
    virtual OUString SAL_CALL getDisplayDirectory() override;
    virtual css::uno::Sequence< OUString > SAL_CALL getFiles() override;
    virtual css::uno::Sequence<OUString> SAL_CALL getFiles() override;

    // XFilePickerControlAccess functions
    virtual void SAL_CALL setValue( sal_Int16 nControlId, sal_Int16 nControlAction, const css::uno::Any &rValue ) override;
    virtual css::uno::Any SAL_CALL getValue( sal_Int16 nControlId, sal_Int16 nControlAction ) override;
    virtual void SAL_CALL enableControl( sal_Int16 nControlId, sal_Bool bEnable ) override;
    virtual void SAL_CALL setLabel( sal_Int16 nControlId, const OUString &rLabel ) override;
    virtual OUString SAL_CALL getLabel( sal_Int16 nControlId ) override;
    virtual void SAL_CALL setValue(sal_Int16 nControlId, sal_Int16 nControlAction,
                                   const css::uno::Any& rValue) override;
    virtual css::uno::Any SAL_CALL getValue(sal_Int16 nControlId,
                                            sal_Int16 nControlAction) override;
    virtual void SAL_CALL enableControl(sal_Int16 nControlId, sal_Bool bEnable) override;
    virtual void SAL_CALL setLabel(sal_Int16 nControlId, const OUString& rLabel) override;
    virtual OUString SAL_CALL getLabel(sal_Int16 nControlId) override;

    // XFilePicker2 functions
    virtual css::uno::Sequence< OUString > SAL_CALL getSelectedFiles() override;
    virtual css::uno::Sequence<OUString> SAL_CALL getSelectedFiles() override;

    // XInitialization
    virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any > &rArguments ) override;
    virtual void SAL_CALL initialize(const css::uno::Sequence<css::uno::Any>& rArguments) override;

    // XEventListener
    /// @throws css::uno::RuntimeException
    virtual void SAL_CALL disposing( const css::lang::EventObject &rEvent );
    virtual void SAL_CALL disposing(const css::lang::EventObject& rEvent);
    using cppu::WeakComponentImplHelperBase::disposing;

    // XServiceInfo
    virtual OUString SAL_CALL getImplementationName() override;
    virtual sal_Bool SAL_CALL supportsService( const OUString &rServiceName ) override;
    virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
    virtual sal_Bool SAL_CALL supportsService(const OUString& rServiceName) override;
    virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override;

    // XFolderPicker functions
    virtual OUString SAL_CALL getDirectory() override;
    virtual void SAL_CALL setDescription( const OUString& rDescription ) override;
    virtual void SAL_CALL setDescription(const OUString& rDescription) override;

private Q_SLOTS:
    // XExecutableDialog functions
    /// @throws css::uno::RuntimeException
    void setTitleSlot( const OUString &rTitle ) { return setTitle( rTitle ); }
    void setTitleSlot(const OUString& rTitle) { return setTitle(rTitle); }
    /// @throws css::uno::RuntimeException
    sal_Int16 executeSlot() { return execute(); }

    // XFilePicker functions
    /// @throws css::uno::RuntimeException
    void setMultiSelectionModeSlot( bool bMode ) { return setMultiSelectionMode( bMode ); }
    void setMultiSelectionModeSlot(bool bMode) { return setMultiSelectionMode(bMode); }
    /// @throws css::uno::RuntimeException
    void setDefaultNameSlot( const OUString &rName ) { return setDefaultName( rName ); }
    void setDefaultNameSlot(const OUString& rName) { return setDefaultName(rName); }
    /// @throws css::uno::RuntimeException
    void setDisplayDirectorySlot( const OUString &rDirectory ) { return setDisplayDirectory( rDirectory ); }
    void setDisplayDirectorySlot(const OUString& rDirectory)
    {
        return setDisplayDirectory(rDirectory);
    }
    /// @throws css::uno::RuntimeException
    OUString getDisplayDirectorySlot() { return getDisplayDirectory(); }
    /// @throws css::uno::RuntimeException
    css::uno::Sequence< OUString > getFilesSlot() { return getFiles(); }
    css::uno::Sequence<OUString> getFilesSlot() { return getFiles(); }

    // XFilterManager functions
    /// @throws css::lang::IllegalArgumentException
    /// @throws css::uno::RuntimeException
    void appendFilterSlot( const OUString &rTitle, const OUString &rFilter ) { return appendFilter( rTitle, rFilter ); }
    void appendFilterSlot(const OUString& rTitle, const OUString& rFilter)
    {
        return appendFilter(rTitle, rFilter);
    }
    /// @throws css::lang::IllegalArgumentException
    /// @throws css::uno::RuntimeException
    void setCurrentFilterSlot( const OUString &rTitle ) { return setCurrentFilter( rTitle ); }
    void setCurrentFilterSlot(const OUString& rTitle) { return setCurrentFilter(rTitle); }
    /// @throws css::uno::RuntimeException
    OUString getCurrentFilterSlot() { return getCurrentFilter(); }

    // XFilterGroupManager functions
    /// @throws css::lang::IllegalArgumentException
    /// @throws css::uno::RuntimeException
    void appendFilterGroupSlot( const OUString &rGroupTitle, const css::uno::Sequence< css::beans::StringPair > &rFilters ) { return appendFilterGroup( rGroupTitle, rFilters ); }
    void appendFilterGroupSlot(const OUString& rGroupTitle,
                               const css::uno::Sequence<css::beans::StringPair>& rFilters)
    {
        return appendFilterGroup(rGroupTitle, rFilters);
    }

    // XFilePickerControlAccess functions
    /// @throws css::uno::RuntimeException
    void setValueSlot( sal_Int16 nControlId, sal_Int16 nControlAction, const css::uno::Any &rValue ) { return setValue( nControlId, nControlAction, rValue ); }
    void setValueSlot(sal_Int16 nControlId, sal_Int16 nControlAction, const css::uno::Any& rValue)
    {
        return setValue(nControlId, nControlAction, rValue);
    }
    /// @throws css::uno::RuntimeException
    css::uno::Any getValueSlot( sal_Int16 nControlId, sal_Int16 nControlAction ) { return getValue( nControlId, nControlAction ); }
    css::uno::Any getValueSlot(sal_Int16 nControlId, sal_Int16 nControlAction)
    {
        return getValue(nControlId, nControlAction);
    }
    /// @throws css::uno::RuntimeException
    void enableControlSlot( sal_Int16 nControlId, bool bEnable ) { return enableControl( nControlId, bEnable ); }
    void enableControlSlot(sal_Int16 nControlId, bool bEnable)
    {
        return enableControl(nControlId, bEnable);
    }
    /// @throws css::uno::RuntimeException
    void setLabelSlot( sal_Int16 nControlId, const OUString &rLabel ) { return setLabel( nControlId, rLabel ); }
    void setLabelSlot(sal_Int16 nControlId, const OUString& rLabel)
    {
        return setLabel(nControlId, rLabel);
    }
    /// @throws css::uno::RuntimeException
    OUString getLabelSlot( sal_Int16 nControlId ) { return getLabel( nControlId ); }
    OUString getLabelSlot(sal_Int16 nControlId) { return getLabel(nControlId); }

    // XFilePicker2 functions
    /// @throws css::uno::RuntimeException
    css::uno::Sequence< OUString > getSelectedFilesSlot() { return getSelectedFiles(); }
    css::uno::Sequence<OUString> getSelectedFilesSlot() { return getSelectedFiles(); }

    // XInitialization
    /// @throws css::uno::Exception
    /// @throws css::uno::RuntimeException
    void initializeSlot( const css::uno::Sequence< css::uno::Any > &rArguments ) { return initialize( rArguments ); }
    void initializeSlot(const css::uno::Sequence<css::uno::Any>& rArguments)
    {
        return initialize(rArguments);
    }

Q_SIGNALS:
    // XExecutableDialog functions
    void setTitleSignal( const OUString &rTitle );
    void setTitleSignal(const OUString& rTitle);
    sal_Int16 executeSignal();

    // XFilePicker functions
    void setMultiSelectionModeSignal( bool bMode );
    void setDefaultNameSignal( const OUString &rName );
    void setDisplayDirectorySignal( const OUString &rDirectory );
    void setMultiSelectionModeSignal(bool bMode);
    void setDefaultNameSignal(const OUString& rName);
    void setDisplayDirectorySignal(const OUString& rDirectory);
    OUString getDisplayDirectorySignal();
    css::uno::Sequence< OUString > getFilesSignal();
    css::uno::Sequence<OUString> getFilesSignal();

    // XFilterManager functions
    void appendFilterSignal( const OUString &rTitle, const OUString &rFilter );
    void setCurrentFilterSignal( const OUString &rTitle );
    void appendFilterSignal(const OUString& rTitle, const OUString& rFilter);
    void setCurrentFilterSignal(const OUString& rTitle);
    OUString getCurrentFilterSignal();

    // XFilterGroupManager functions
    void appendFilterGroupSignal( const OUString &rGroupTitle, const css::uno::Sequence< css::beans::StringPair > &rFilters );
    void appendFilterGroupSignal(const OUString& rGroupTitle,
                                 const css::uno::Sequence<css::beans::StringPair>& rFilters);

    // XFilePickerControlAccess functions
    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 );
    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);

    // XFilePicker2 functions
    css::uno::Sequence< OUString > getSelectedFilesSignal() ;
    css::uno::Sequence<OUString> getSelectedFilesSignal();

    // XInitialization
    void initializeSignal( const css::uno::Sequence< css::uno::Any > &rArguments );
    void initializeSignal(const css::uno::Sequence<css::uno::Any>& rArguments);

    // Destructor proxy
    void cleanupProxySignal();

private:
    Qt5FilePicker( const Qt5FilePicker& ) = delete;
    Qt5FilePicker& operator=( const Qt5FilePicker& ) = delete;
    Qt5FilePicker(const Qt5FilePicker&) = delete;
    Qt5FilePicker& operator=(const Qt5FilePicker&) = delete;

    // add a custom control widget to the options dialog
    void addCustomControl(QGridLayout *pLayout, sal_Int16 controlId);
    void addCustomControl(QGridLayout* pLayout, sal_Int16 controlId);

    static QString getResString(const char* pRedId);

@@ -234,9 +262,9 @@ private Q_SLOTS:
    void cleanupProxy();

    // emit XFilePickerListener controlStateChanged event
    void filterSelected(const QString &);
    void filterSelected(const QString&);
    // emit XFilePickerListener fileSelectionChanged event
//    void urlSelected(const QUrl &);
    //    void urlSelected(const QUrl &);

    void selectionChanged();
};
diff --git a/vcl/inc/qt5/Qt5Frame.hxx b/vcl/inc/qt5/Qt5Frame.hxx
index 1f881d7..268441ea 100644
--- a/vcl/inc/qt5/Qt5Frame.hxx
+++ b/vcl/inc/qt5/Qt5Frame.hxx
@@ -87,7 +87,7 @@ public:
    void Damage(sal_Int32 nExtentsX, sal_Int32 nExtentsY, sal_Int32 nExtentsWidth,
                sal_Int32 nExtentsHeight) const;

    virtual void InitSvpSalGraphics( SvpSalGraphics* pSvpSalGraphics );
    virtual void InitSvpSalGraphics(SvpSalGraphics* pSvpSalGraphics);
    virtual SalGraphics* AcquireGraphics() override;
    virtual void ReleaseGraphics(SalGraphics* pGraphics) override;

diff --git a/vcl/inc/qt5/Qt5Instance.hxx b/vcl/inc/qt5/Qt5Instance.hxx
index 24085b2..cd0e911 100644
--- a/vcl/inc/qt5/Qt5Instance.hxx
+++ b/vcl/inc/qt5/Qt5Instance.hxx
@@ -31,7 +31,9 @@ class QApplication;
class SalYieldMutex;
class SalFrame;

class VCLPLUG_QT5_PUBLIC Qt5Instance : public QObject, public SalGenericInstance, public SalUserEventList
class VCLPLUG_QT5_PUBLIC Qt5Instance : public QObject,
                                       public SalGenericInstance,
                                       public SalUserEventList
{
    Q_OBJECT

@@ -79,10 +81,10 @@ public:
    virtual OUString GetDefaultPrinter() override;
    virtual void PostPrintersChanged() override;

    virtual SalMenu*            CreateMenu( bool, Menu* ) override;
    virtual void                DestroyMenu( SalMenu* pMenu ) override;
    virtual SalMenuItem*        CreateMenuItem( const SalItemParams* ) override;
    virtual void                DestroyMenuItem( SalMenuItem* pItem ) override;
    virtual SalMenu* CreateMenu(bool, Menu*) override;
    virtual void DestroyMenu(SalMenu* pMenu) override;
    virtual SalMenuItem* CreateMenuItem(const SalItemParams*) override;
    virtual void DestroyMenuItem(SalMenuItem* pItem) override;

    virtual SalTimer* CreateSalTimer() override;
    virtual SalSystem* CreateSalSystem() override;
@@ -107,11 +109,11 @@ public:
    virtual void TriggerUserEventProcessing() override;
    virtual void ProcessEvent(SalUserEvent aEvent) override;

    virtual css::uno::Reference< css::ui::dialogs::XFilePicker2 > createFilePicker(
        const css::uno::Reference< css::uno::XComponentContext >& ) override;
    virtual css::uno::Reference<css::ui::dialogs::XFilePicker2>
    createFilePicker(const css::uno::Reference<css::uno::XComponentContext>&) override;

    virtual css::uno::Reference< css::ui::dialogs::XFolderPicker2 > createFolderPicker(
        const css::uno::Reference< css::uno::XComponentContext >& ) override;
    virtual css::uno::Reference<css::ui::dialogs::XFolderPicker2>
    createFolderPicker(const css::uno::Reference<css::uno::XComponentContext>&) override;
};

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/inc/qt5/Qt5Menu.hxx b/vcl/inc/qt5/Qt5Menu.hxx
index 3788704..21f33ea 100644
--- a/vcl/inc/qt5/Qt5Menu.hxx
+++ b/vcl/inc/qt5/Qt5Menu.hxx
@@ -21,57 +21,60 @@ class Qt5Menu : public QObject, public SalMenu
{
    Q_OBJECT
private:
    std::vector< Qt5MenuItem* >  maItems;
    VclPtr<Menu>                 mpVCLMenu;
    Qt5Menu*                     mpParentSalMenu;
    Qt5Frame*                    mpFrame;
    bool                         mbMenuBar;
    QMenuBar*                    mpQMenuBar;
    std::vector<Qt5MenuItem*> maItems;
    VclPtr<Menu> mpVCLMenu;
    Qt5Menu* mpParentSalMenu;
    Qt5Frame* mpFrame;
    bool mbMenuBar;
    QMenuBar* mpQMenuBar;

    void DoFullMenuUpdate( Menu* pMenuBar, QMenu* pParentMenu = nullptr );
    void NativeItemText( OUString &rItemText );
    void DoFullMenuUpdate(Menu* pMenuBar, QMenu* pParentMenu = nullptr);
    void NativeItemText(OUString& rItemText);

public:
    Qt5Menu( bool bMenuBar );
    Qt5Menu(bool bMenuBar);
    virtual ~Qt5Menu() override;

    virtual bool                VisibleMenuBar() override;   // must return TRUE to actually DISPLAY native menu bars
    virtual bool VisibleMenuBar() override; // must return TRUE to actually DISPLAY native menu bars

    virtual void                InsertItem( SalMenuItem* pSalMenuItem, unsigned nPos ) override;
    virtual void                RemoveItem( unsigned nPos ) override;
    virtual void                SetSubMenu( SalMenuItem* pSalMenuItem, SalMenu* pSubMenu, unsigned nPos ) override;
    virtual void                SetFrame( const SalFrame* pFrame ) override;
    const Qt5Frame*             GetFrame() const;
    Qt5Menu*                    GetTopLevel();
    virtual void                CheckItem( unsigned nPos, bool bCheck ) override;
    virtual void                EnableItem( unsigned nPos, bool bEnable ) override;
    virtual void                ShowItem( unsigned nPos, bool bShow ) override;
    virtual void                SetItemText( unsigned nPos, SalMenuItem* pSalMenuItem, const OUString& rText ) override;
    virtual void                SetItemImage( unsigned nPos, SalMenuItem* pSalMenuItem, const Image& rImage) override;
    virtual void                SetAccelerator( unsigned nPos, SalMenuItem* pSalMenuItem, const vcl::KeyCode& rKeyCode, const OUString& rKeyName ) override;
    virtual void                GetSystemMenuData( SystemMenuData* pData ) override;
    virtual void InsertItem(SalMenuItem* pSalMenuItem, unsigned nPos) override;
    virtual void RemoveItem(unsigned nPos) override;
    virtual void SetSubMenu(SalMenuItem* pSalMenuItem, SalMenu* pSubMenu, unsigned nPos) override;
    virtual void SetFrame(const SalFrame* pFrame) override;
    const Qt5Frame* GetFrame() const;
    Qt5Menu* GetTopLevel();
    virtual void CheckItem(unsigned nPos, bool bCheck) override;
    virtual void EnableItem(unsigned nPos, bool bEnable) override;
    virtual void ShowItem(unsigned nPos, bool bShow) override;
    virtual void SetItemText(unsigned nPos, SalMenuItem* pSalMenuItem,
                             const OUString& rText) override;
    virtual void SetItemImage(unsigned nPos, SalMenuItem* pSalMenuItem,
                              const Image& rImage) override;
    virtual void SetAccelerator(unsigned nPos, SalMenuItem* pSalMenuItem,
                                const vcl::KeyCode& rKeyCode, const OUString& rKeyName) override;
    virtual void GetSystemMenuData(SystemMenuData* pData) override;

    void                        SetMenu( Menu* pMenu ) { mpVCLMenu = pMenu; }
    Menu*                       GetMenu() { return mpVCLMenu; }
    unsigned                    GetItemCount() { return maItems.size(); }
    Qt5MenuItem*                GetItemAtPos( unsigned nPos ) { return maItems[ nPos ]; }
    void SetMenu(Menu* pMenu) { mpVCLMenu = pMenu; }
    Menu* GetMenu() { return mpVCLMenu; }
    unsigned GetItemCount() { return maItems.size(); }
    Qt5MenuItem* GetItemAtPos(unsigned nPos) { return maItems[nPos]; }

private slots:
    void DispatchCommand( Qt5MenuItem* pQItem );
    void DispatchCommand(Qt5MenuItem* pQItem);
};

class Qt5MenuItem : public SalMenuItem
{
public:
    Qt5MenuItem( const SalItemParams* );
    Qt5MenuItem(const SalItemParams*);
    virtual ~Qt5MenuItem() override;

    sal_uInt16          mnId;               // Item ID
    MenuItemType        mnType;             // Item type
    bool                mbVisible;          // Item visibility.
    Menu*               mpVCLMenu;
    Qt5Menu*            mpParentMenu;       // The menu into which this menu item is inserted
    Qt5Menu*            mpSubMenu;          // Submenu of this item (if defined)
    sal_uInt16 mnId; // Item ID
    MenuItemType mnType; // Item type
    bool mbVisible; // Item visibility.
    Menu* mpVCLMenu;
    Qt5Menu* mpParentMenu; // The menu into which this menu item is inserted
    Qt5Menu* mpSubMenu; // Submenu of this item (if defined)
};

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/inc/qt5/Qt5Tools.hxx b/vcl/inc/qt5/Qt5Tools.hxx
index 06c0257..a714f19 100644
--- a/vcl/inc/qt5/Qt5Tools.hxx
+++ b/vcl/inc/qt5/Qt5Tools.hxx
@@ -58,7 +58,7 @@ inline Size toSize(const QSize& rSize) { return Size(rSize.width(), rSize.height

inline QColor toQColor(const Color& rColor)
{
    return QColor( rColor.GetRed(), rColor.GetGreen(), rColor.GetBlue(), rColor.GetTransparency() );
    return QColor(rColor.GetRed(), rColor.GetGreen(), rColor.GetBlue(), rColor.GetTransparency());
}

static constexpr QImage::Format Qt5_DefaultFormat32 = QImage::Format_ARGB32;
diff --git a/vcl/inc/qt5/Qt5Widget.hxx b/vcl/inc/qt5/Qt5Widget.hxx
index c95bc94..32daa2b 100644
--- a/vcl/inc/qt5/Qt5Widget.hxx
+++ b/vcl/inc/qt5/Qt5Widget.hxx
@@ -21,8 +21,8 @@

#include <QtWidgets/QWidget>

#include  "Qt5Frame.hxx"
#include "Qt5Frame.hxx"

QWidget* createQt5Widget(Qt5Frame &rFrame, QWidget* parent, Qt::WindowFlags f);
QWidget* createQt5Widget(Qt5Frame& rFrame, QWidget* parent, Qt::WindowFlags f);

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/qt5/Qt5FilePicker.cxx b/vcl/qt5/Qt5FilePicker.cxx
index 7dee36d..7bc561a 100644
--- a/vcl/qt5/Qt5FilePicker.cxx
+++ b/vcl/qt5/Qt5FilePicker.cxx
@@ -54,7 +54,6 @@
#include <unx/geninst.h>
#include <strings.hrc>


using namespace ::com::sun::star;
using namespace ::com::sun::star::ui::dialogs;
using namespace ::com::sun::star::ui::dialogs::TemplateDescription;
@@ -66,266 +65,281 @@ using namespace ::com::sun::star::uno;

namespace
{
    uno::Sequence<OUString> SAL_CALL FilePicker_getSupportedServiceNames()
    {
        uno::Sequence<OUString> aRet(3);
        aRet[0] = "com.sun.star.ui.dialogs.FilePicker";
        aRet[1] = "com.sun.star.ui.dialogs.SystemFilePicker";
        aRet[2] = "com.sun.star.ui.dialogs.Qt5FilePicker";
        return aRet;
    }
uno::Sequence<OUString> SAL_CALL FilePicker_getSupportedServiceNames()
{
    uno::Sequence<OUString> aRet(3);
    aRet[0] = "com.sun.star.ui.dialogs.FilePicker";
    aRet[1] = "com.sun.star.ui.dialogs.SystemFilePicker";
    aRet[2] = "com.sun.star.ui.dialogs.Qt5FilePicker";
    return aRet;
}
}

Qt5FilePicker::Qt5FilePicker( QFileDialog::FileMode eMode )
    : Qt5FilePicker_Base( m_aHelperMutex )
Qt5FilePicker::Qt5FilePicker(QFileDialog::FileMode eMode)
    : Qt5FilePicker_Base(m_aHelperMutex)
{
SAL_DEBUG( "Qt5FilePicker::Qt5FilePicker" );
    m_pFileDialog = new QFileDialog();
    m_pOptionsDialog = new QDialog();

    m_pFileDialog->setFileMode( eMode );
//    m_pFileDialog->setWindowModality( Qt::WindowModal );
    m_pFileDialog->setWindowModality( Qt::ApplicationModal );
    m_pOptionsDialog->setWindowModality( Qt::WindowModal );
    m_pFileDialog->setFileMode(eMode);
    //    m_pFileDialog->setWindowModality( Qt::WindowModal );
    m_pFileDialog->setWindowModality(Qt::ApplicationModal);
    m_pOptionsDialog->setWindowModality(Qt::WindowModal);

    setMultiSelectionMode( false );
    setMultiSelectionMode(false);

    // XExecutableDialog functions
    connect( this, SIGNAL( setTitleSignal( const OUString & ) ),
             this, SLOT( setTitleSlot( const OUString & ) ), Qt::BlockingQueuedConnection );
    connect( this, SIGNAL( executeSignal() ),
             this, SLOT( executeSlot() ), Qt::BlockingQueuedConnection );
    connect(this, SIGNAL(setTitleSignal(const OUString&)), this,
            SLOT(setTitleSlot(const OUString&)), Qt::BlockingQueuedConnection);
    connect(this, SIGNAL(executeSignal()), this, SLOT(executeSlot()), Qt::BlockingQueuedConnection);

    // XFilePicker functions
    connect( this, SIGNAL( setMultiSelectionModeSignal( bool ) ),
             this, SLOT( setMultiSelectionModeSlot( bool ) ), Qt::BlockingQueuedConnection );
    connect( this, SIGNAL( setDefaultNameSignal( const OUString & ) ),
             this, SLOT( setDefaultNameSlot( const OUString & ) ), Qt::BlockingQueuedConnection );
    connect( this, SIGNAL( setDisplayDirectorySignal( const OUString & ) ),
             this, SLOT( setDisplayDirectorySlot( const OUString & ) ), Qt::BlockingQueuedConnection );
    connect( this, SIGNAL( getDisplayDirectorySignal() ),
             this, SLOT( getDisplayDirectorySlot() ), Qt::BlockingQueuedConnection );
    connect( this, SIGNAL( getFilesSignal() ),
             this, SLOT( getFilesSlot() ), Qt::BlockingQueuedConnection );
    connect(this, SIGNAL(setMultiSelectionModeSignal(bool)), this,
            SLOT(setMultiSelectionModeSlot(bool)), Qt::BlockingQueuedConnection);
    connect(this, SIGNAL(setDefaultNameSignal(const OUString&)), this,
            SLOT(setDefaultNameSlot(const OUString&)), Qt::BlockingQueuedConnection);
    connect(this, SIGNAL(setDisplayDirectorySignal(const OUString&)), this,
            SLOT(setDisplayDirectorySlot(const OUString&)), Qt::BlockingQueuedConnection);
    connect(this, SIGNAL(getDisplayDirectorySignal()), this, SLOT(getDisplayDirectorySlot()),
            Qt::BlockingQueuedConnection);
    connect(this, SIGNAL(getFilesSignal()), this, SLOT(getFilesSlot()),
            Qt::BlockingQueuedConnection);

    // XFilterManager functions
    connect( this, SIGNAL( appendFilterSignal( const OUString &, const OUString & ) ),
             this, SLOT( appendFilterSlot( const OUString &, const OUString & ) ), Qt::BlockingQueuedConnection );
    connect( this, SIGNAL( setCurrentFilterSignal( const OUString & ) ),
             this, SLOT( setCurrentFilterSlot( const OUString & ) ), Qt::BlockingQueuedConnection );
    connect( this, SIGNAL( getCurrentFilterSignal() ),
             this, SLOT( getCurrentFilterSlot() ), Qt::BlockingQueuedConnection );
    connect(this, SIGNAL(appendFilterSignal(const OUString&, const OUString&)), this,
            SLOT(appendFilterSlot(const OUString&, const OUString&)), Qt::BlockingQueuedConnection);
    connect(this, SIGNAL(setCurrentFilterSignal(const OUString&)), this,
            SLOT(setCurrentFilterSlot(const OUString&)), Qt::BlockingQueuedConnection);
    connect(this, SIGNAL(getCurrentFilterSignal()), this, SLOT(getCurrentFilterSlot()),
            Qt::BlockingQueuedConnection);

    // XFilterGroupManager functions
    connect( this, SIGNAL( appendFilterGroupSignal( const OUString &, const css::uno::Sequence< css::beans::StringPair > & ) ),
             this, SLOT( appendFilterGroupSlot( const OUString &, const css::uno::Sequence< css::beans::StringPair > & ) ), Qt::BlockingQueuedConnection );
    connect(this,
            SIGNAL(appendFilterGroupSignal(const OUString&,
                                           const css::uno::Sequence<css::beans::StringPair>&)),
            this,
            SLOT(appendFilterGroupSlot(const OUString&,
                                       const css::uno::Sequence<css::beans::StringPair>&)),
            Qt::BlockingQueuedConnection);

    // XFilePickerControlAccess functions
    connect( this, SIGNAL( setValueSignal( sal_Int16, sal_Int16, const css::uno::Any & ) ),
             this, SLOT( setValueSlot( sal_Int16, sal_Int16, const css::uno::Any & ) ), Qt::BlockingQueuedConnection );
    connect( this, SIGNAL( getValueSignal( sal_Int16, sal_Int16 ) ),
             this, SLOT( getValueSlot( sal_Int16, sal_Int16 ) ), Qt::BlockingQueuedConnection );
    connect( this, SIGNAL( enableControlSignal( sal_Int16, bool ) ),
             this, SLOT( enableControlSlot( sal_Int16, bool ) ), Qt::BlockingQueuedConnection );
    connect( this, SIGNAL( setLabelSignal( sal_Int16, const OUString & ) ),
             this, SLOT( setLabelSlot( sal_Int16, const OUString & ) ), Qt::BlockingQueuedConnection );
    connect( this, SIGNAL( getLabelSignal( sal_Int16 ) ),
             this, SLOT( getLabelSlot( sal_Int16 ) ), Qt::BlockingQueuedConnection );
    connect(this, SIGNAL(setValueSignal(sal_Int16, sal_Int16, const css::uno::Any&)), this,
            SLOT(setValueSlot(sal_Int16, sal_Int16, const css::uno::Any&)),
            Qt::BlockingQueuedConnection);
    connect(this, SIGNAL(getValueSignal(sal_Int16, sal_Int16)), this,
            SLOT(getValueSlot(sal_Int16, sal_Int16)), Qt::BlockingQueuedConnection);
    connect(this, SIGNAL(enableControlSignal(sal_Int16, bool)), this,
            SLOT(enableControlSlot(sal_Int16, bool)), Qt::BlockingQueuedConnection);
    connect(this, SIGNAL(setLabelSignal(sal_Int16, const OUString&)), this,
            SLOT(setLabelSlot(sal_Int16, const OUString&)), Qt::BlockingQueuedConnection);
    connect(this, SIGNAL(getLabelSignal(sal_Int16)), this, SLOT(getLabelSlot(sal_Int16)),
            Qt::BlockingQueuedConnection);

    // XFilePicker2 functions
    connect( this, SIGNAL( getSelectedFilesSignal() ),
             this, SLOT( getSelectedFilesSlot() ), Qt::BlockingQueuedConnection );
    connect(this, SIGNAL(getSelectedFilesSignal()), this, SLOT(getSelectedFilesSlot()),
            Qt::BlockingQueuedConnection);

    // XInitialization
    connect( this, SIGNAL( initializeSignal( const css::uno::Sequence< css::uno::Any > & ) ),
             this, SLOT( initializeSlot( const css::uno::Sequence< css::uno::Any > & ) ), Qt::BlockingQueuedConnection );
    connect(this, SIGNAL(initializeSignal(const css::uno::Sequence<css::uno::Any>&)), this,
            SLOT(initializeSlot(const css::uno::Sequence<css::uno::Any>&)),
            Qt::BlockingQueuedConnection);

    // Destructor proxy
    connect( this, SIGNAL( cleanupProxySignal() ), this, SLOT( cleanupProxy() ), Qt::BlockingQueuedConnection );
    connect(this, SIGNAL(cleanupProxySignal()), this, SLOT(cleanupProxy()),
            Qt::BlockingQueuedConnection);

    // XFilePickerListener notifications
    connect( m_pFileDialog, SIGNAL( filterSelected(const QString&) ), this, SLOT( filterSelected(const QString&) ));
    connect( m_pFileDialog, SIGNAL( selectionChanged() ), this, SLOT( selectionChanged() ));
    connect(m_pFileDialog, SIGNAL(filterSelected(const QString&)), this,
            SLOT(filterSelected(const QString&)));
    connect(m_pFileDialog, SIGNAL(selectionChanged()), this, SLOT(selectionChanged()));
}

Qt5FilePicker::~Qt5FilePicker()
{
    cleanupProxy();
}
Qt5FilePicker::~Qt5FilePicker() { cleanupProxy(); }

void Qt5FilePicker::cleanupProxy()
{
    if( qApp->thread() != QThread::currentThread() ) {
    if (qApp->thread() != QThread::currentThread())
    {
        SolarMutexReleaser aReleaser;
        return Q_EMIT cleanupProxySignal();
    }
    delete m_pOptionsDialog;
}

void SAL_CALL Qt5FilePicker::addFilePickerListener( const uno::Reference<XFilePickerListener>& xListener )
void SAL_CALL
Qt5FilePicker::addFilePickerListener(const uno::Reference<XFilePickerListener>& xListener)
{
    SolarMutexGuard aGuard;
    m_xListener = xListener;
}

void SAL_CALL Qt5FilePicker::removeFilePickerListener( const uno::Reference<XFilePickerListener>& )
void SAL_CALL Qt5FilePicker::removeFilePickerListener(const uno::Reference<XFilePickerListener>&)
{
    SolarMutexGuard aGuard;
    m_xListener.clear();
}

void SAL_CALL Qt5FilePicker::setTitle( const OUString &title )
void SAL_CALL Qt5FilePicker::setTitle(const OUString& title)
{
    if( qApp->thread() != QThread::currentThread() ) {
    if (qApp->thread() != QThread::currentThread())
    {
        SolarMutexReleaser aReleaser;
        return Q_EMIT setTitleSignal( title );
        return Q_EMIT setTitleSignal(title);
    }

    m_pOptionsDialog->setWindowTitle( toQString(title) );
    m_pOptionsDialog->setWindowTitle(toQString(title));
}

sal_Int16 SAL_CALL Qt5FilePicker::execute()
{
    if( qApp->thread() != QThread::currentThread() ) {
    if (qApp->thread() != QThread::currentThread())
    {
        SolarMutexReleaser aReleaser;
        return Q_EMIT executeSignal();
    }

    vcl::Window *pWindow = ::Application::GetActiveTopWindow();
    assert( pWindow );
    QWidget *pTransientParent = nullptr;
    QWindow *pTransientWindow = nullptr;
    if( pWindow )
    vcl::Window* pWindow = ::Application::GetActiveTopWindow();
    assert(pWindow);
    QWidget* pTransientParent = nullptr;
    QWindow* pTransientWindow = nullptr;
    if (pWindow)
    {
        Qt5Frame *pFrame = dynamic_cast<Qt5Frame *>( pWindow->ImplGetFrame() );
        assert( pFrame );
        if( pFrame )
        Qt5Frame* pFrame = dynamic_cast<Qt5Frame*>(pWindow->ImplGetFrame());
        assert(pFrame);
        if (pFrame)
        {
            pTransientParent = pFrame->GetQWidget();
            pTransientWindow = pTransientParent->window()->windowHandle();
        }
    }

    m_pFileDialog->setNameFilters( m_aNamedFilterList );
    if( !m_aCurrentFilterTitle.isNull() )
    m_pFileDialog->setNameFilters(m_aNamedFilterList);
    if (!m_aCurrentFilterTitle.isNull())
    {
        int i = 0;
        for( ; i < m_aFilterTitleList.size(); ++i )
            if( m_aCurrentFilterTitle == m_aFilterTitleList[ i ] )
        for (; i < m_aFilterTitleList.size(); ++i)
            if (m_aCurrentFilterTitle == m_aFilterTitleList[i])
            {
                m_pFileDialog->selectNameFilter( m_aNamedFilterList[ i ] );
                m_pFileDialog->selectNameFilter(m_aNamedFilterList[i]);
                break;
            }
        assert( i < m_aFilterTitleList.size() );
        assert(i < m_aFilterTitleList.size());
    }

    if( pTransientParent )
    if (pTransientParent)
    {
        m_pFileDialog->show();
        m_pFileDialog->window()->windowHandle()->setTransientParent( pTransientWindow );
        m_pFileDialog->setFocusProxy( pTransientParent );
//        pTransientParent->setMouseTracking( false );
        m_pFileDialog->window()->windowHandle()->setTransientParent(pTransientWindow);
        m_pFileDialog->setFocusProxy(pTransientParent);
        //        pTransientParent->setMouseTracking( false );
    }
    int result = m_pFileDialog->exec();
    if( pTransientParent )
//        pTransientParent->setMouseTracking( true );
    if( QFileDialog::Rejected == result )
        return ExecutableDialogResults::CANCEL;
    if (pTransientParent)
        //        pTransientParent->setMouseTracking( true );
        if (QFileDialog::Rejected == result)
            return ExecutableDialogResults::CANCEL;

    if ( !m_aCustomWidgetsMap.empty() )
    if (!m_aCustomWidgetsMap.empty())
    {
        m_pFilenameLabel->setText( m_pFileDialog->selectedUrls()[ 0 ].url() );
        m_pFilenameLabel->setText(m_pFileDialog->selectedUrls()[0].url());
        QString filter = m_pFileDialog->selectedNameFilter();
        int pos = filter.indexOf(" (");
        if( pos >= 0 )
            filter.truncate( pos );
        m_pFilterLabel->setText( filter );
        if (pos >= 0)
            filter.truncate(pos);
        m_pFilterLabel->setText(filter);

        if( pTransientParent )
        if (pTransientParent)
        {
            m_pOptionsDialog->show();
            m_pOptionsDialog->window()->windowHandle()->setTransientParent( pTransientWindow );
            m_pOptionsDialog->setFocusProxy( pTransientParent );
            m_pOptionsDialog->window()->windowHandle()->setTransientParent(pTransientWindow);
            m_pOptionsDialog->setFocusProxy(pTransientParent);
        }
        result = m_pOptionsDialog->exec();
        if( QFileDialog::Rejected == result )
        if (QFileDialog::Rejected == result)
            return ExecutableDialogResults::CANCEL;
    }

    return ExecutableDialogResults::OK;
}

void SAL_CALL Qt5FilePicker::setMultiSelectionMode( sal_Bool multiSelect )
void SAL_CALL Qt5FilePicker::setMultiSelectionMode(sal_Bool multiSelect)
{
    if( qApp->thread() != QThread::currentThread() ) {
    if (qApp->thread() != QThread::currentThread())
    {
        SolarMutexReleaser aReleaser;
        return Q_EMIT setMultiSelectionModeSignal( multiSelect );
        return Q_EMIT setMultiSelectionModeSignal(multiSelect);
    }

    if( multiSelect )
        m_pFileDialog->setFileMode( QFileDialog::ExistingFiles );
    if (multiSelect)
        m_pFileDialog->setFileMode(QFileDialog::ExistingFiles);
    else
        m_pFileDialog->setFileMode( QFileDialog::ExistingFile );
        m_pFileDialog->setFileMode(QFileDialog::ExistingFile);
}

void SAL_CALL Qt5FilePicker::setDefaultName( const OUString &name )
void SAL_CALL Qt5FilePicker::setDefaultName(const OUString& name)
{
    if( qApp->thread() != QThread::currentThread() ) {
    if (qApp->thread() != QThread::currentThread())
    {
        SolarMutexReleaser aReleaser;
        return Q_EMIT setDefaultNameSignal( name );
        return Q_EMIT setDefaultNameSignal(name);
    }
    m_pFileDialog->selectFile( toQString( name ) );
    m_pFileDialog->selectFile(toQString(name));
}

void SAL_CALL Qt5FilePicker::setDisplayDirectory( const OUString &dir )
void SAL_CALL Qt5FilePicker::setDisplayDirectory(const OUString& dir)
{
    if( qApp->thread() != QThread::currentThread() ) {
    if (qApp->thread() != QThread::currentThread())
    {
        SolarMutexReleaser aReleaser;
        return Q_EMIT setDisplayDirectorySignal( dir );
        return Q_EMIT setDisplayDirectorySignal(dir);
    }
    m_pFileDialog->setDirectory( toQString( dir ) );
    m_pFileDialog->setDirectory(toQString(dir));
}

OUString SAL_CALL Qt5FilePicker::getDisplayDirectory()
{
    if( qApp->thread() != QThread::currentThread() ) {
    if (qApp->thread() != QThread::currentThread())
    {
        SolarMutexReleaser aReleaser;
        return Q_EMIT getDisplayDirectorySignal();
    }
    return toOUString( m_pFileDialog->directoryUrl().toString() );
    return toOUString(m_pFileDialog->directoryUrl().toString());
}

uno::Sequence< OUString > SAL_CALL Qt5FilePicker::getFiles()
uno::Sequence<OUString> SAL_CALL Qt5FilePicker::getFiles()
{
    if( qApp->thread() != QThread::currentThread() ) {
    if (qApp->thread() != QThread::currentThread())
    {
        SolarMutexReleaser aReleaser;
        return Q_EMIT getFilesSignal();
    }
    uno::Sequence< OUString > seq = getSelectedFiles();
    uno::Sequence<OUString> seq = getSelectedFiles();
    if (seq.getLength() > 1)
        seq.realloc(1);
    return seq;
}

uno::Sequence< OUString > SAL_CALL Qt5FilePicker::getSelectedFiles()
uno::Sequence<OUString> SAL_CALL Qt5FilePicker::getSelectedFiles()
{
    if( qApp->thread() != QThread::currentThread() ) {
    if (qApp->thread() != QThread::currentThread())
    {
        SolarMutexReleaser aReleaser;
        return Q_EMIT getSelectedFilesSignal();
    }
    QList<QUrl> urls = m_pFileDialog->selectedUrls();
    uno::Sequence< OUString > seq( urls.size() );
    uno::Sequence<OUString> seq(urls.size());
    int i = 0;
    foreach( const QUrl& url, urls )
        seq[ i++ ]= toOUString( url.toString() );
    foreach (const QUrl& url, urls)
        seq[i++] = toOUString(url.toString());
    return seq;
}

void SAL_CALL Qt5FilePicker::appendFilter( const OUString &title, const OUString &filter )
void SAL_CALL Qt5FilePicker::appendFilter(const OUString& title, const OUString& filter)
{
    if( qApp->thread() != QThread::currentThread() ) {
    if (qApp->thread() != QThread::currentThread())
    {
        SolarMutexReleaser aReleaser;
        return Q_EMIT appendFilterSignal( title, filter );
        return Q_EMIT appendFilterSignal(title, filter);
    }

    QString t = toQString(title);
@@ -336,8 +350,8 @@ void SAL_CALL Qt5FilePicker::appendFilter( const OUString &title, const OUString
    t.replace("/", "\\/");

    int pos = t.indexOf(" (");
    if( pos >= 0 )
        t.truncate( pos );
    if (pos >= 0)
        t.truncate(pos);

    // openoffice gives us filters separated by ';' qt dialogs just want space separated
    f.replace(";", " ");
@@ -345,68 +359,75 @@ void SAL_CALL Qt5FilePicker::appendFilter( const OUString &title, const OUString
    // make sure "*.*" is not used as "all files"
    f.replace("*.*", "*");

    m_aFilterTitleList.append( toQString( title ) );
    m_aNamedFilterList.append( QString("%1 (%2)").arg(t).arg(f) );
    m_aFilterTitleList.append(toQString(title));
    m_aNamedFilterList.append(QString("%1 (%2)").arg(t).arg(f));
}

void SAL_CALL Qt5FilePicker::setCurrentFilter( const OUString &title )
void SAL_CALL Qt5FilePicker::setCurrentFilter(const OUString& title)
{
    if( qApp->thread() != QThread::currentThread() ) {
    if (qApp->thread() != QThread::currentThread())
    {
        SolarMutexReleaser aReleaser;
        return Q_EMIT setCurrentFilterSignal( title );
        return Q_EMIT setCurrentFilterSignal(title);
    }

    m_aCurrentFilterTitle = toQString( title );
    m_aCurrentFilterTitle = toQString(title);
}

OUString SAL_CALL Qt5FilePicker::getCurrentFilter()
{
    if( qApp->thread() != QThread::currentThread() ) {
    if (qApp->thread() != QThread::currentThread())
    {
        SolarMutexReleaser aReleaser;
        return Q_EMIT getCurrentFilterSignal();
    }

    QString filter = m_pFileDialog->selectedNameFilter();
    for( int i = 0; i < m_aNamedFilterList.size(); ++i )
        if( filter == m_aNamedFilterList[ i ] )
            return toOUString( m_aFilterTitleList[ i ] );
    SAL_DEBUG( "vcl.qt5 " << m_aNamedFilterList.size() << " Unknown filter: " << toOUString( filter ) );
    assert( !"Selected filter not in filter list?! " );
    return OUString( "" );
    for (int i = 0; i < m_aNamedFilterList.size(); ++i)
        if (filter == m_aNamedFilterList[i])
            return toOUString(m_aFilterTitleList[i]);
    SAL_WARN("vcl.qt5", m_aNamedFilterList.size() << " Unknown filter: " << toOUString(filter));
    assert(!"Selected filter not in filter list?! ");
    return OUString("");
}

void SAL_CALL Qt5FilePicker::appendFilterGroup( const OUString& rGroupTitle, const uno::Sequence<beans::StringPair>& filters)
void SAL_CALL Qt5FilePicker::appendFilterGroup(const OUString& rGroupTitle,
                                               const uno::Sequence<beans::StringPair>& filters)
{
    if( qApp->thread() != QThread::currentThread() ) {
    if (qApp->thread() != QThread::currentThread())
    {
        SolarMutexReleaser aReleaser;
        return Q_EMIT appendFilterGroupSignal( rGroupTitle, filters );
        return Q_EMIT appendFilterGroupSignal(rGroupTitle, filters);
    }

    const sal_uInt16 length = filters.getLength();
    for (sal_uInt16 i = 0; i < length; ++i)
    {
        beans::StringPair aPair = filters[i];
        appendFilter( aPair.First, aPair.Second );
        appendFilter(aPair.First, aPair.Second);
    }
}

void SAL_CALL Qt5FilePicker::setValue( sal_Int16 controlId, sal_Int16 nControlAction, const uno::Any &value )
void SAL_CALL Qt5FilePicker::setValue(sal_Int16 controlId, sal_Int16 nControlAction,
                                      const uno::Any& value)
{
    if( qApp->thread() != QThread::currentThread() ) {
    if (qApp->thread() != QThread::currentThread())
    {
        SolarMutexReleaser aReleaser;
        return Q_EMIT setValueSignal( controlId, nControlAction, value );
        return Q_EMIT setValueSignal(controlId, nControlAction, value);
    }

    if (m_aCustomWidgetsMap.contains( controlId )) {
        QCheckBox* cb = dynamic_cast<QCheckBox*>( m_aCustomWidgetsMap.value( controlId ));
    if (m_aCustomWidgetsMap.contains(controlId))
    {
        QCheckBox* cb = dynamic_cast<QCheckBox*>(m_aCustomWidgetsMap.value(controlId));
        if (cb)
            cb->setChecked(value.get<bool>());
    }
    else
        SAL_WARN( "vcl", "set label on unknown control " << controlId );
        SAL_WARN("vcl", "set label on unknown control " << controlId);
}

uno::Any SAL_CALL Qt5FilePicker::getValue( sal_Int16 controlId, sal_Int16 nControlAction )
uno::Any SAL_CALL Qt5FilePicker::getValue(sal_Int16 controlId, sal_Int16 nControlAction)
{
    if (CHECKBOX_AUTOEXTENSION == controlId)
        // We ignore this one and rely on QFileDialog to provide the function.
@@ -414,74 +435,81 @@ uno::Any SAL_CALL Qt5FilePicker::getValue( sal_Int16 controlId, sal_Int16 nContr
        // LO core would try to be smart and cut the extension in some places,
        // interfering with QFileDialog's handling of it. QFileDialog also
        // saves the value of the setting, so LO core is not needed for that either.
        return uno::Any( false );
        return uno::Any(false);

    if( qApp->thread() != QThread::currentThread() ) {
    if (qApp->thread() != QThread::currentThread())
    {
        SolarMutexReleaser aReleaser;
        return Q_EMIT getValueSignal( controlId, nControlAction );
        return Q_EMIT getValueSignal(controlId, nControlAction);
    }

    uno::Any res(false);
    if (m_aCustomWidgetsMap.contains( controlId )) {
        QCheckBox* cb = dynamic_cast<QCheckBox*>( m_aCustomWidgetsMap.value( controlId ));
    if (m_aCustomWidgetsMap.contains(controlId))
    {
        QCheckBox* cb = dynamic_cast<QCheckBox*>(m_aCustomWidgetsMap.value(controlId));
        if (cb)
            res <<= cb->isChecked();
    }
    else
        SAL_WARN( "vcl", "get value on unknown control " << controlId );
        SAL_WARN("vcl", "get value on unknown control " << controlId);

    return res;
}

void SAL_CALL Qt5FilePicker::enableControl( sal_Int16 controlId, sal_Bool enable )
void SAL_CALL Qt5FilePicker::enableControl(sal_Int16 controlId, sal_Bool enable)
{
    if( qApp->thread() != QThread::currentThread() ) {
    if (qApp->thread() != QThread::currentThread())
    {
        SolarMutexReleaser aReleaser;
        return Q_EMIT enableControlSignal( controlId, enable );
        return Q_EMIT enableControlSignal(controlId, enable);
    }

    if (m_aCustomWidgetsMap.contains( controlId ))
        m_aCustomWidgetsMap.value( controlId )->setEnabled( enable );
    if (m_aCustomWidgetsMap.contains(controlId))
        m_aCustomWidgetsMap.value(controlId)->setEnabled(enable);
    else
        SAL_WARN( "vcl", "enable unknown control " << controlId );
        SAL_WARN("vcl", "enable unknown control " << controlId);
}

void SAL_CALL Qt5FilePicker::setLabel( sal_Int16 controlId, const OUString &label )
void SAL_CALL Qt5FilePicker::setLabel(sal_Int16 controlId, const OUString& label)
{
    if( qApp->thread() != QThread::currentThread() ) {
    if (qApp->thread() != QThread::currentThread())
    {
        SolarMutexReleaser aReleaser;
        return Q_EMIT setLabelSignal( controlId, label );
        return Q_EMIT setLabelSignal(controlId, label);
    }

    if (m_aCustomWidgetsMap.contains( controlId )) {
        QCheckBox* cb = dynamic_cast<QCheckBox*>( m_aCustomWidgetsMap.value( controlId ));
    if (m_aCustomWidgetsMap.contains(controlId))
    {
        QCheckBox* cb = dynamic_cast<QCheckBox*>(m_aCustomWidgetsMap.value(controlId));
        if (cb)
            cb->setText( toQString(label) );
            cb->setText(toQString(label));
    }
    else
        SAL_WARN( "vcl", "set label on unknown control " << controlId );
        SAL_WARN("vcl", "set label on unknown control " << controlId);
}

OUString SAL_CALL Qt5FilePicker::getLabel(sal_Int16 controlId)
{
    if( qApp->thread() != QThread::currentThread() ) {
    if (qApp->thread() != QThread::currentThread())
    {
        SolarMutexReleaser aReleaser;
        return Q_EMIT getLabelSignal( controlId );
        return Q_EMIT getLabelSignal(controlId);
    }

    QString label;
    if (m_aCustomWidgetsMap.contains( controlId )) {
        QCheckBox* cb = dynamic_cast<QCheckBox*>( m_aCustomWidgetsMap.value( controlId ));
    if (m_aCustomWidgetsMap.contains(controlId))
    {
        QCheckBox* cb = dynamic_cast<QCheckBox*>(m_aCustomWidgetsMap.value(controlId));
        if (cb)
            label = cb->text();
    }
    else
        SAL_WARN( "vcl", "get label on unknown control " << controlId );
        SAL_WARN("vcl", "get label on unknown control " << controlId);

    return toOUString(label);
}

QString Qt5FilePicker::getResString(const char *pResId)
QString Qt5FilePicker::getResString(const char* pResId)
{
    QString aResString;

@@ -493,7 +521,7 @@ QString Qt5FilePicker::getResString(const char *pResId)
    return aResString.replace('~', '&');
}

void Qt5FilePicker::addCustomControl(QGridLayout *pLayout, sal_Int16 controlId)
void Qt5FilePicker::addCustomControl(QGridLayout* pLayout, sal_Int16 controlId)
{
    QWidget* widget = nullptr;
    QWidget* label = nullptr;
@@ -558,8 +586,8 @@ void Qt5FilePicker::addCustomControl(QGridLayout *pLayout, sal_Int16 controlId)
        case LISTBOX_TEMPLATE:
        case LISTBOX_IMAGE_TEMPLATE:
        case LISTBOX_FILTER_SELECTOR:
            label = new QLabel( getResString(resId), m_pOptionsDialog );
            widget = new QComboBox( m_pOptionsDialog );
            label = new QLabel(getResString(resId), m_pOptionsDialog);
            widget = new QComboBox(m_pOptionsDialog);
            break;
        case LISTBOX_VERSION_LABEL:
        case LISTBOX_TEMPLATE_LABEL:
@@ -567,21 +595,22 @@ void Qt5FilePicker::addCustomControl(QGridLayout *pLayout, sal_Int16 controlId)
            break;
    }

    if( widget )
    if (widget)
    {
        const int row = pLayout->rowCount();
        if( label )
            pLayout->addWidget( label, row, 0 );
        pLayout->addWidget( widget, row, 1 );
        m_aCustomWidgetsMap.insert( controlId, widget );
        if (label)
            pLayout->addWidget(label, row, 0);
        pLayout->addWidget(widget, row, 1);
        m_aCustomWidgetsMap.insert(controlId, widget);
    }
}

void SAL_CALL Qt5FilePicker::initialize( const uno::Sequence<uno::Any> &args )
void SAL_CALL Qt5FilePicker::initialize(const uno::Sequence<uno::Any>& args)
{
    if( qApp->thread() != QThread::currentThread() ) {
    if (qApp->thread() != QThread::currentThread())
    {
        SolarMutexReleaser aReleaser;
        return Q_EMIT initializeSignal( args );
        return Q_EMIT initializeSignal(args);
    }

    m_aNamedFilterList.clear();
@@ -592,35 +621,32 @@ void SAL_CALL Qt5FilePicker::initialize( const uno::Sequence<uno::Any> &args )
    uno::Any arg;
    if (args.getLength() == 0)
    {
        throw lang::IllegalArgumentException(
                "no arguments",
                static_cast< XFilePicker2* >( this ), 1 );
        throw lang::IllegalArgumentException("no arguments", static_cast<XFilePicker2*>(this), 1);
    }

    arg = args[0];

    if (( arg.getValueType() != cppu::UnoType<sal_Int16>::get()) &&
        ( arg.getValueType() != cppu::UnoType<sal_Int8>::get()))
    if ((arg.getValueType() != cppu::UnoType<sal_Int16>::get())
        && (arg.getValueType() != cppu::UnoType<sal_Int8>::get()))
    {
        throw lang::IllegalArgumentException(
                "invalid argument type",
                static_cast< XFilePicker2* >( this ), 1 );
        throw lang::IllegalArgumentException("invalid argument type",
                                             static_cast<XFilePicker2*>(this), 1);
    }

    QGridLayout *pLayout = new QGridLayout();
    m_pOptionsDialog->setLayout( pLayout );
    pLayout->addWidget( new QLabel( "Filename:" ), 0, 0 );
    QGridLayout* pLayout = new QGridLayout();
    m_pOptionsDialog->setLayout(pLayout);
    pLayout->addWidget(new QLabel("Filename:"), 0, 0);
    m_pFilenameLabel = new QLabel();
    pLayout->addWidget( m_pFilenameLabel, 0, 1 );
    pLayout->addWidget( new QLabel( "Type:" ), 1, 0 );
    pLayout->addWidget(m_pFilenameLabel, 0, 1);
    pLayout->addWidget(new QLabel("Type:"), 1, 0);
    m_pFilterLabel = new QLabel();
    pLayout->addWidget( m_pFilterLabel, 1, 1 );
    pLayout->addWidget(m_pFilterLabel, 1, 1);

    sal_Int16 templateId = -1;
    arg >>= templateId;

    QFileDialog::AcceptMode acceptMode = QFileDialog::AcceptOpen;
    switch ( templateId )
    switch (templateId)
    {
        case FILEOPEN_SIMPLE:
            break;
@@ -631,157 +657,149 @@ void SAL_CALL Qt5FilePicker::initialize( const uno::Sequence<uno::Any> &args )

        case FILESAVE_AUTOEXTENSION:
            acceptMode = QFileDialog::AcceptSave;
            addCustomControl( pLayout, CHECKBOX_AUTOEXTENSION );
            addCustomControl(pLayout, CHECKBOX_AUTOEXTENSION);
            break;

        case FILESAVE_AUTOEXTENSION_PASSWORD:
            acceptMode = QFileDialog::AcceptSave;
            addCustomControl( pLayout, CHECKBOX_AUTOEXTENSION );
            addCustomControl( pLayout, CHECKBOX_PASSWORD );
            addCustomControl(pLayout, CHECKBOX_AUTOEXTENSION);
            addCustomControl(pLayout, CHECKBOX_PASSWORD);
            break;

        case FILESAVE_AUTOEXTENSION_PASSWORD_FILTEROPTIONS:
            acceptMode = QFileDialog::AcceptSave;
            addCustomControl( pLayout, CHECKBOX_AUTOEXTENSION );
            addCustomControl( pLayout, CHECKBOX_PASSWORD );
            addCustomControl( pLayout, CHECKBOX_FILTEROPTIONS );
            addCustomControl(pLayout, CHECKBOX_AUTOEXTENSION);
            addCustomControl(pLayout, CHECKBOX_PASSWORD);
            addCustomControl(pLayout, CHECKBOX_FILTEROPTIONS);
            break;

        case FILESAVE_AUTOEXTENSION_SELECTION:
            acceptMode = QFileDialog::AcceptSave;
            addCustomControl( pLayout, CHECKBOX_AUTOEXTENSION );
            addCustomControl( pLayout, CHECKBOX_SELECTION );
            addCustomControl(pLayout, CHECKBOX_AUTOEXTENSION);
            addCustomControl(pLayout, CHECKBOX_SELECTION);
            break;

        case FILESAVE_AUTOEXTENSION_TEMPLATE:
            acceptMode = QFileDialog::AcceptSave;
            addCustomControl( pLayout, CHECKBOX_AUTOEXTENSION );
            addCustomControl( pLayout, LISTBOX_TEMPLATE );
            addCustomControl(pLayout, CHECKBOX_AUTOEXTENSION);
            addCustomControl(pLayout, LISTBOX_TEMPLATE);
            break;

        case FILEOPEN_LINK_PREVIEW_IMAGE_TEMPLATE:
            addCustomControl( pLayout, CHECKBOX_LINK );
            addCustomControl( pLayout, CHECKBOX_PREVIEW );
            addCustomControl( pLayout, LISTBOX_IMAGE_TEMPLATE );
            addCustomControl(pLayout, CHECKBOX_LINK);
            addCustomControl(pLayout, CHECKBOX_PREVIEW);
            addCustomControl(pLayout, LISTBOX_IMAGE_TEMPLATE);
            break;

        case FILEOPEN_PLAY:
            addCustomControl( pLayout, PUSHBUTTON_PLAY );
            addCustomControl(pLayout, PUSHBUTTON_PLAY);
            break;

        case FILEOPEN_LINK_PLAY:
            addCustomControl( pLayout, CHECKBOX_LINK );
            addCustomControl( pLayout, PUSHBUTTON_PLAY );
            addCustomControl(pLayout, CHECKBOX_LINK);
            addCustomControl(pLayout, PUSHBUTTON_PLAY);
            break;

        case FILEOPEN_READONLY_VERSION:
            addCustomControl( pLayout, CHECKBOX_READONLY );
            addCustomControl( pLayout, LISTBOX_VERSION );
            addCustomControl(pLayout, CHECKBOX_READONLY);
            addCustomControl(pLayout, LISTBOX_VERSION);
            break;

        case FILEOPEN_LINK_PREVIEW:
            addCustomControl( pLayout, CHECKBOX_LINK );
            addCustomControl( pLayout, CHECKBOX_PREVIEW );
            addCustomControl(pLayout, CHECKBOX_LINK);
            addCustomControl(pLayout, CHECKBOX_PREVIEW);
            break;

        case FILEOPEN_PREVIEW:
            addCustomControl( pLayout, CHECKBOX_PREVIEW );
            addCustomControl(pLayout, CHECKBOX_PREVIEW);
            break;

        default:
            throw lang::IllegalArgumentException(
                    "Unknown template",
                    static_cast< XFilePicker2* >( this ),
                    1 );
            throw lang::IllegalArgumentException("Unknown template",
                                                 static_cast<XFilePicker2*>(this), 1);
    }

    if( !m_aCustomWidgetsMap.empty() )
    if (!m_aCustomWidgetsMap.empty())
    {
        QHBoxLayout *pHBoxLayout = new QHBoxLayout();
        pLayout->addLayout( pHBoxLayout, pLayout->rowCount(), 0, 1, 2 );
        QHBoxLayout* pHBoxLayout = new QHBoxLayout();
        pLayout->addLayout(pHBoxLayout, pLayout->rowCount(), 0, 1, 2);
        pHBoxLayout->addStretch();
        QPushButton *pButton = new QPushButton( "Ok" );
        connect( pButton, SIGNAL(clicked()), m_pOptionsDialog, SLOT(accept()) );
        pHBoxLayout->addWidget( pButton );
        pButton = new QPushButton( "Cancel" );
        connect( pButton, SIGNAL(clicked()), m_pOptionsDialog, SLOT(reject()) );
        pHBoxLayout->addWidget( pButton );
        QPushButton* pButton = new QPushButton("Ok");
        connect(pButton, SIGNAL(clicked()), m_pOptionsDialog, SLOT(accept()));
        pHBoxLayout->addWidget(pButton);
        pButton = new QPushButton("Cancel");
        connect(pButton, SIGNAL(clicked()), m_pOptionsDialog, SLOT(reject()));
        pHBoxLayout->addWidget(pButton);
    }

    const char *resId = nullptr;
    switch ( acceptMode )
    const char* resId = nullptr;
    switch (acceptMode)
    {
    case QFileDialog::AcceptOpen:
        resId = STR_FPICKER_OPEN;
        break;
    case QFileDialog::AcceptSave:
        resId = STR_FPICKER_SAVE;
        m_pFileDialog->setFileMode( QFileDialog::AnyFile );
        break;
        case QFileDialog::AcceptOpen:
            resId = STR_FPICKER_OPEN;
            break;
        case QFileDialog::AcceptSave:
            resId = STR_FPICKER_SAVE;
            m_pFileDialog->setFileMode(QFileDialog::AnyFile);
            break;
    }

    m_pFileDialog->setAcceptMode( acceptMode );
    m_pFileDialog->setWindowTitle( getResString(resId) );
    m_pFileDialog->setAcceptMode(acceptMode);
    m_pFileDialog->setWindowTitle(getResString(resId));
}

void SAL_CALL Qt5FilePicker::cancel()
void SAL_CALL Qt5FilePicker::cancel() {}

void SAL_CALL Qt5FilePicker::disposing(const lang::EventObject& rEvent)
{
    uno::Reference<XFilePickerListener> xFilePickerListener(rEvent.Source, uno::UNO_QUERY);

}

void SAL_CALL Qt5FilePicker::disposing( const lang::EventObject &rEvent )
{
    uno::Reference<XFilePickerListener> xFilePickerListener( rEvent.Source, uno::UNO_QUERY );

    if ( xFilePickerListener.is() )
    if (xFilePickerListener.is())
    {
        removeFilePickerListener( xFilePickerListener );
        removeFilePickerListener(xFilePickerListener);
    }
}

OUString SAL_CALL Qt5FilePicker::getImplementationName()
{
    return OUString( "com.sun.star.ui.dialogs.Qt5FilePicker" );
    return OUString("com.sun.star.ui.dialogs.Qt5FilePicker");
}

sal_Bool SAL_CALL Qt5FilePicker::supportsService( const OUString& ServiceName )
sal_Bool SAL_CALL Qt5FilePicker::supportsService(const OUString& ServiceName)
{
    return cppu::supportsService(this, ServiceName);
}

uno::Sequence< OUString > SAL_CALL Qt5FilePicker::getSupportedServiceNames()
uno::Sequence<OUString> SAL_CALL Qt5FilePicker::getSupportedServiceNames()
{
    return FilePicker_getSupportedServiceNames();
}

void Qt5FilePicker::filterSelected(const QString &)
void Qt5FilePicker::filterSelected(const QString&)
{
    FilePickerEvent aEvent;
    aEvent.ElementId = LISTBOX_FILTER;
    SAL_INFO( "vcl", "filter changed" );
    SAL_INFO("vcl", "filter changed");
    if (m_xListener.is())
        m_xListener->controlStateChanged( aEvent );
        m_xListener->controlStateChanged(aEvent);
}

void Qt5FilePicker::selectionChanged()
{
    FilePickerEvent aEvent;
    SAL_INFO( "vcl", "file selection changed" );
    SAL_INFO("vcl", "file selection changed");
    if (m_xListener.is())
        m_xListener->fileSelectionChanged( aEvent );
        m_xListener->fileSelectionChanged(aEvent);
}

OUString Qt5FilePicker::getDirectory()
{
    uno::Sequence< OUString > seq = getSelectedFiles();
    uno::Sequence<OUString> seq = getSelectedFiles();
    if (seq.getLength() > 1)
        seq.realloc(1);
    return seq[ 0 ];
    return seq[0];
}

void Qt5FilePicker::setDescription( const OUString& )
{

}
void Qt5FilePicker::setDescription(const OUString&) {}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/qt5/Qt5Font.cxx b/vcl/qt5/Qt5Font.cxx
index 46e7b9e..0164c3b1 100644
--- a/vcl/qt5/Qt5Font.cxx
+++ b/vcl/qt5/Qt5Font.cxx
@@ -41,8 +41,7 @@ static hb_blob_t* getFontTable(hb_face_t*, hb_tag_t nTableTag, void* pUserData)

    hb_blob_t* pBlob = nullptr;
    if (nLength > 0)
        pBlob = hb_blob_create(aTable.data(), nLength,
                               HB_MEMORY_MODE_DUPLICATE, nullptr, nullptr);
        pBlob = hb_blob_create(aTable.data(), nLength, HB_MEMORY_MODE_DUPLICATE, nullptr, nullptr);
    return pBlob;
}

diff --git a/vcl/qt5/Qt5Frame.cxx b/vcl/qt5/Qt5Frame.cxx
index 4a36bee..e86e10d 100644
--- a/vcl/qt5/Qt5Frame.cxx
+++ b/vcl/qt5/Qt5Frame.cxx
@@ -141,15 +141,15 @@ void Qt5Frame::TriggerPaintEvent(QRect aRect)
    CallCallback(SalEvent::Paint, &aPaintEvt);
}

void Qt5Frame::InitSvpSalGraphics( SvpSalGraphics* pSvpSalGraphics )
void Qt5Frame::InitSvpSalGraphics(SvpSalGraphics* pSvpSalGraphics)
{
    int width = m_pQWidget->size().width();
    int height = m_pQWidget->size().height();
    m_pSvpGraphics = pSvpSalGraphics;
    m_pSurface.reset(cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height));
    m_pSvpGraphics->setSurface(m_pSurface.get(), basegfx::B2IVector(width, height));
    cairo_surface_set_user_data(m_pSurface.get(), SvpSalGraphics::getDamageKey(),
                                &m_aDamageHandler, nullptr);
    cairo_surface_set_user_data(m_pSurface.get(), SvpSalGraphics::getDamageKey(), &m_aDamageHandler,
                                nullptr);
    TriggerPaintEvent();
}

@@ -164,8 +164,8 @@ SalGraphics* Qt5Frame::AcquireGraphics()
    {
        if (!m_pOurSvpGraphics.get())
        {
            m_pOurSvpGraphics.reset( new SvpSalGraphics() );
            InitSvpSalGraphics( m_pOurSvpGraphics.get() );
            m_pOurSvpGraphics.reset(new SvpSalGraphics());
            InitSvpSalGraphics(m_pOurSvpGraphics.get());
        }
        return m_pOurSvpGraphics.get();
    }
@@ -234,10 +234,7 @@ void Qt5Frame::SetIcon(sal_uInt16 nIcon)
    m_pQWidget->window()->setWindowIcon(aIcon);
}

void Qt5Frame::SetMenu(SalMenu* pMenu)
{
    m_pSalMenu = static_cast<Qt5Menu*>( pMenu );
}
void Qt5Frame::SetMenu(SalMenu* pMenu) { m_pSalMenu = static_cast<Qt5Menu*>(pMenu); }

void Qt5Frame::DrawMenuBar() {}

diff --git a/vcl/qt5/Qt5Graphics_Text.cxx b/vcl/qt5/Qt5Graphics_Text.cxx
index d957959..e5fc79e 100644
--- a/vcl/qt5/Qt5Graphics_Text.cxx
+++ b/vcl/qt5/Qt5Graphics_Text.cxx
@@ -134,14 +134,14 @@ void Qt5Graphics::GetGlyphWidths(const PhysicalFontFace* /*pPFF*/, bool /*bVerti
bool Qt5Graphics::GetGlyphBoundRect(const GlyphItem& rGlyph, tools::Rectangle& rRect)
{
    const int nLevel = rGlyph.mnFallbackLevel;
    if( nLevel >= MAX_FALLBACK )
    if (nLevel >= MAX_FALLBACK)
        return false;

    Qt5Font* pFont = m_pTextStyle[ nLevel ];
    if( !pFont )
    Qt5Font* pFont = m_pTextStyle[nLevel];
    if (!pFont)
        return false;

    QRawFont aRawFont(QRawFont::fromFont( *pFont ));
    QRawFont aRawFont(QRawFont::fromFont(*pFont));
    rRect = toRectangle(aRawFont.boundingRect(rGlyph.maGlyphId).toAlignedRect());
    return true;
}
@@ -155,11 +155,11 @@ std::unique_ptr<SalLayout> Qt5Graphics::GetTextLayout(ImplLayoutArgs&, int nFall
    return std::unique_ptr<SalLayout>();
}

void Qt5Graphics::DrawTextLayout(const GenericSalLayout &rLayout )
void Qt5Graphics::DrawTextLayout(const GenericSalLayout& rLayout)
{
    const Qt5Font* pFont = static_cast<const Qt5Font*>(&rLayout.GetFont());
    assert( pFont );
    QRawFont aRawFont(QRawFont::fromFont( *pFont ));
    assert(pFont);
    QRawFont aRawFont(QRawFont::fromFont(*pFont));

    QVector<quint32> glyphIndexes;
    QVector<QPointF> positions;
@@ -174,14 +174,14 @@ void Qt5Graphics::DrawTextLayout(const GenericSalLayout &rLayout )
    }

    QGlyphRun aGlyphRun;
    aGlyphRun.setPositions( positions );
    aGlyphRun.setGlyphIndexes( glyphIndexes );
    aGlyphRun.setRawFont( aRawFont );
    aGlyphRun.setPositions(positions);
    aGlyphRun.setGlyphIndexes(glyphIndexes);
    aGlyphRun.setRawFont(aRawFont);

    Qt5Painter aPainter(*this);
    QColor aColor = toQColor(m_aTextColor);
    aPainter.setPen(aColor);
    aPainter.drawGlyphRun( QPointF(), aGlyphRun );
    aPainter.drawGlyphRun(QPointF(), aGlyphRun);
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/qt5/Qt5Instance.cxx b/vcl/qt5/Qt5Instance.cxx
index 9bfcd00..6cc083f 100644
--- a/vcl/qt5/Qt5Instance.cxx
+++ b/vcl/qt5/Qt5Instance.cxx
@@ -111,27 +111,21 @@ Qt5Instance::CreateVirtualDevice(SalGraphics* pGraphics, long& nDX, long& nDY, D
    }
}

SalMenu* Qt5Instance::CreateMenu( bool bMenuBar, Menu* pVCLMenu )
SalMenu* Qt5Instance::CreateMenu(bool bMenuBar, Menu* pVCLMenu)
{
    Qt5Menu* pSalMenu = new Qt5Menu( bMenuBar );
    pSalMenu->SetMenu( pVCLMenu );
    Qt5Menu* pSalMenu = new Qt5Menu(bMenuBar);
    pSalMenu->SetMenu(pVCLMenu);
    return pSalMenu;
}

void Qt5Instance::DestroyMenu( SalMenu* pMenu )
void Qt5Instance::DestroyMenu(SalMenu* pMenu) { delete pMenu; }

SalMenuItem* Qt5Instance::CreateMenuItem(const SalItemParams* pItemData)
{
    delete pMenu;
    return new Qt5MenuItem(pItemData);
}

SalMenuItem* Qt5Instance::CreateMenuItem( const SalItemParams* pItemData )
{
    return new Qt5MenuItem( pItemData );
}

void Qt5Instance::DestroyMenuItem( SalMenuItem* pItem )
{
    delete pItem;
}
void Qt5Instance::DestroyMenuItem(SalMenuItem* pItem) { delete pItem; }

SalTimer* Qt5Instance::CreateSalTimer() { return new Qt5Timer(); }

@@ -211,18 +205,18 @@ void Qt5Instance::ProcessEvent(SalUserEvent aEvent)
    aEvent.m_pFrame->CallCallback(aEvent.m_nEvent, aEvent.m_pData);
}

css::uno::Reference< css::ui::dialogs::XFilePicker2 >
Qt5Instance::createFilePicker( const css::uno::Reference< css::uno::XComponentContext > & )
css::uno::Reference<css::ui::dialogs::XFilePicker2>
Qt5Instance::createFilePicker(const css::uno::Reference<css::uno::XComponentContext>&)
{
    return css::uno::Reference< css::ui::dialogs::XFilePicker2 >(
        new Qt5FilePicker( QFileDialog::ExistingFile ) );
    return css::uno::Reference<css::ui::dialogs::XFilePicker2>(
        new Qt5FilePicker(QFileDialog::ExistingFile));
}

css::uno::Reference< css::ui::dialogs::XFolderPicker2 >
Qt5Instance::createFolderPicker( const css::uno::Reference< css::uno::XComponentContext > & )
css::uno::Reference<css::ui::dialogs::XFolderPicker2>
Qt5Instance::createFolderPicker(const css::uno::Reference<css::uno::XComponentContext>&)
{
    return css::uno::Reference< css::ui::dialogs::XFolderPicker2 >(
        new Qt5FilePicker( QFileDialog::Directory ) );
    return css::uno::Reference<css::ui::dialogs::XFolderPicker2>(
        new Qt5FilePicker(QFileDialog::Directory));
}

extern "C" {
diff --git a/vcl/qt5/Qt5Menu.cxx b/vcl/qt5/Qt5Menu.cxx
index e61595a..ce95da1 100644
--- a/vcl/qt5/Qt5Menu.cxx
+++ b/vcl/qt5/Qt5Menu.cxx
@@ -15,174 +15,157 @@

#include <vcl/svapp.hxx>

Qt5Menu::Qt5Menu( bool bMenuBar ) :
    mpVCLMenu( nullptr ),
    mpParentSalMenu( nullptr ),
    mpFrame( nullptr ),
    mbMenuBar( bMenuBar )
Qt5Menu::Qt5Menu(bool bMenuBar)
    : mpVCLMenu(nullptr)
    , mpParentSalMenu(nullptr)
    , mpFrame(nullptr)
    , mbMenuBar(bMenuBar)
{
}

Qt5Menu::~Qt5Menu()
{
    maItems.clear();
}
Qt5Menu::~Qt5Menu() { maItems.clear(); }

bool Qt5Menu::VisibleMenuBar()
{
    return false;
}
bool Qt5Menu::VisibleMenuBar() { return false; }

void Qt5Menu::InsertItem( SalMenuItem* pSalMenuItem, unsigned nPos )
void Qt5Menu::InsertItem(SalMenuItem* pSalMenuItem, unsigned nPos)
{
    SolarMutexGuard aGuard;
    Qt5MenuItem *pItem = static_cast<Qt5MenuItem*>( pSalMenuItem );
    Qt5MenuItem* pItem = static_cast<Qt5MenuItem*>(pSalMenuItem);

    if ( nPos == MENU_APPEND )
        maItems.push_back( pItem );
    if (nPos == MENU_APPEND)
        maItems.push_back(pItem);
    else
        maItems.insert( maItems.begin() + nPos, pItem );
        maItems.insert(maItems.begin() + nPos, pItem);

    pItem->mpParentMenu = this;
}

void Qt5Menu::RemoveItem( unsigned nPos )
void Qt5Menu::RemoveItem(unsigned nPos)
{
    SolarMutexGuard aGuard;
    maItems.erase( maItems.begin() + nPos );
    maItems.erase(maItems.begin() + nPos);
}

void Qt5Menu::SetSubMenu( SalMenuItem* pSalMenuItem, SalMenu* pSubMenu, unsigned nPos )
void Qt5Menu::SetSubMenu(SalMenuItem* pSalMenuItem, SalMenu* pSubMenu, unsigned nPos)
{
    SolarMutexGuard aGuard;
    Qt5MenuItem *pItem = static_cast< Qt5MenuItem* >( pSalMenuItem );
    Qt5Menu *pQSubMenu = static_cast< Qt5Menu* >( pSubMenu );
    Qt5MenuItem* pItem = static_cast<Qt5MenuItem*>(pSalMenuItem);
    Qt5Menu* pQSubMenu = static_cast<Qt5Menu*>(pSubMenu);

    if ( pQSubMenu == nullptr )
    if (pQSubMenu == nullptr)
        return;

    pQSubMenu->mpParentSalMenu = this;
    pItem->mpSubMenu = pQSubMenu;
}

void Qt5Menu::SetFrame( const SalFrame* pFrame )
void Qt5Menu::SetFrame(const SalFrame* pFrame)
{
    SolarMutexGuard aGuard;
    assert(mbMenuBar);
    mpFrame = const_cast<Qt5Frame*>( static_cast<const Qt5Frame*>( pFrame ) );
    mpFrame = const_cast<Qt5Frame*>(static_cast<const Qt5Frame*>(pFrame));

    mpFrame->SetMenu( this );
    mpFrame->SetMenu(this);

    QWidget* pWidget = mpFrame->GetQWidget();
    QMainWindow* pMainWindow = dynamic_cast<QMainWindow*>(pWidget);
    if( pMainWindow )
    if (pMainWindow)
        mpQMenuBar = pMainWindow->menuBar();

    DoFullMenuUpdate( mpVCLMenu );
    DoFullMenuUpdate(mpVCLMenu);
}

void Qt5Menu::DoFullMenuUpdate( Menu* pMenuBar, QMenu* pParentMenu )
void Qt5Menu::DoFullMenuUpdate(Menu* pMenuBar, QMenu* pParentMenu)
{
    Menu* pVCLMenu = mpVCLMenu;

    if ( mbMenuBar && mpQMenuBar )
    if (mbMenuBar && mpQMenuBar)
        mpQMenuBar->clear();
    QActionGroup* pQAG = nullptr;

    for ( sal_Int32 nItem = 0; nItem < static_cast<sal_Int32>(GetItemCount()); nItem++ )
    for (sal_Int32 nItem = 0; nItem < static_cast<sal_Int32>(GetItemCount()); nItem++)
    {
        Qt5MenuItem *pSalMenuItem = GetItemAtPos( nItem );
        Qt5MenuItem* pSalMenuItem = GetItemAtPos(nItem);
        sal_uInt16 nId = pSalMenuItem->mnId;
        OUString aText = pVCLMenu->GetItemText( nId );
        OUString aText = pVCLMenu->GetItemText(nId);
        QMenu* pQMenu = pParentMenu;
        NativeItemText( aText );
        vcl::KeyCode nAccelKey = pVCLMenu->GetAccelKey( nId );
        bool bChecked = pVCLMenu->IsItemChecked( nId );
        MenuItemBits itemBits = pVCLMenu->GetItemBits( nId );
        NativeItemText(aText);
        vcl::KeyCode nAccelKey = pVCLMenu->GetAccelKey(nId);
        bool bChecked = pVCLMenu->IsItemChecked(nId);
        MenuItemBits itemBits = pVCLMenu->GetItemBits(nId);

        if (mbMenuBar && mpQMenuBar)
            // top-level menu
            pQMenu = mpQMenuBar->addMenu( toQString(aText) );
            pQMenu = mpQMenuBar->addMenu(toQString(aText));
        else
        {
            if( pSalMenuItem->mpSubMenu )
            if (pSalMenuItem->mpSubMenu)
            {
                // submenu
                pQMenu = pQMenu->addMenu( toQString(aText) );
                pQAG = new QActionGroup( pQMenu );
                pQMenu = pQMenu->addMenu(toQString(aText));
                pQAG = new QActionGroup(pQMenu);
            }
            else
            {
                if ( pSalMenuItem->mnType == MenuItemType::SEPARATOR )
                if (pSalMenuItem->mnType == MenuItemType::SEPARATOR)
                    pQMenu->addSeparator();
                else
                {
                    // leaf menu
                    QAction *pAction = pQMenu->addAction( toQString(aText) );
                    pAction->setShortcut( toQString( nAccelKey.GetName(GetFrame()->GetWindow()) ) );
                    QAction* pAction = pQMenu->addAction(toQString(aText));
                    pAction->setShortcut(toQString(nAccelKey.GetName(GetFrame()->GetWindow())));

                    if (itemBits & MenuItemBits::CHECKABLE)
                    {
                        pAction->setCheckable( true );
                        pAction->setChecked( bChecked );
                        pAction->setCheckable(true);
                        pAction->setChecked(bChecked);
                    }
                    else if (itemBits & MenuItemBits::RADIOCHECK)
                    {
                        pAction->setCheckable(true);
                        if ( !pQAG )
                        if (!pQAG)
                        {
                            pQAG = new QActionGroup( pQMenu );
                            pQAG = new QActionGroup(pQMenu);
                            pQAG->setExclusive(true);
                        }
                        pQAG->addAction( pAction );
                        pQAG->addAction(pAction);
                    }

                    connect( pAction, &QAction::triggered, this,
                             [this, pSalMenuItem]{ DispatchCommand(pSalMenuItem); } );
                    connect(pAction, &QAction::triggered, this,
                            [this, pSalMenuItem] { DispatchCommand(pSalMenuItem); });
                }
            }
        }

        if ( pSalMenuItem->mpSubMenu != nullptr )
        if (pSalMenuItem->mpSubMenu != nullptr)
        {
            pMenuBar->HandleMenuActivateEvent(pSalMenuItem->mpSubMenu->GetMenu());
            pSalMenuItem->mpSubMenu->DoFullMenuUpdate( pMenuBar, pQMenu );
            pSalMenuItem->mpSubMenu->DoFullMenuUpdate(pMenuBar, pQMenu);
            pMenuBar->HandleMenuDeActivateEvent(pSalMenuItem->mpSubMenu->GetMenu());
        }
    }
}

void Qt5Menu::ShowItem( unsigned nPos, bool bCheck )
void Qt5Menu::ShowItem(unsigned nPos, bool bCheck) {}

void Qt5Menu::CheckItem(unsigned nPos, bool bCheck) {}

void Qt5Menu::EnableItem(unsigned nPos, bool bEnable) {}

void Qt5Menu::SetItemText(unsigned nPos, SalMenuItem* pSalMenuItem, const rtl::OUString& rText) {}

void Qt5Menu::SetItemImage(unsigned nPos, SalMenuItem* pSalMenuItem, const Image& rImage) {}

void Qt5Menu::SetAccelerator(unsigned nPos, SalMenuItem* pSalMenuItem, const vcl::KeyCode& rKeyCode,
                             const OUString& rKeyName)
{
}

void Qt5Menu::CheckItem( unsigned nPos, bool bCheck )
{
}

void Qt5Menu::EnableItem( unsigned nPos, bool bEnable )
{
}

void Qt5Menu::SetItemText( unsigned nPos, SalMenuItem* pSalMenuItem, const rtl::OUString& rText )
{
}

void Qt5Menu::SetItemImage( unsigned nPos, SalMenuItem* pSalMenuItem, const Image& rImage)
{
}

void Qt5Menu::SetAccelerator( unsigned nPos, SalMenuItem* pSalMenuItem, const vcl::KeyCode& rKeyCode, const OUString& rKeyName )
{
}

void Qt5Menu::GetSystemMenuData( SystemMenuData* pData )
{
}
void Qt5Menu::GetSystemMenuData(SystemMenuData* pData) {}

Qt5Menu* Qt5Menu::GetTopLevel()
{
    Qt5Menu *pMenu = this;
    Qt5Menu* pMenu = this;
    while (pMenu->mpParentSalMenu)
        pMenu = pMenu->mpParentSalMenu;
    return pMenu;
@@ -192,38 +175,33 @@ const Qt5Frame* Qt5Menu::GetFrame() const
{
    SolarMutexGuard aGuard;
    const Qt5Menu* pMenu = this;
    while( pMenu && ! pMenu->mpFrame )
    while (pMenu && !pMenu->mpFrame)
        pMenu = pMenu->mpParentSalMenu;
    return pMenu ? pMenu->mpFrame : nullptr;
}

void Qt5Menu::DispatchCommand( Qt5MenuItem *pQItem )
void Qt5Menu::DispatchCommand(Qt5MenuItem* pQItem)
{
    if ( pQItem )
    if (pQItem)
    {
        Qt5Menu* pSalMenu = pQItem->mpParentMenu;
        Qt5Menu* pTopLevel = pSalMenu->GetTopLevel();
        pTopLevel->GetMenu()->HandleMenuCommandEvent(pSalMenu->GetMenu(), pQItem->mnId);
        SAL_WARN("vcl.qt5", "menu triggered " << pQItem->mnId );
        SAL_WARN("vcl.qt5", "menu triggered " << pQItem->mnId);
    }
}

void Qt5Menu::NativeItemText( OUString& rItemText )
{
    rItemText = rItemText.replace( '~', '&' );
}
void Qt5Menu::NativeItemText(OUString& rItemText) { rItemText = rItemText.replace('~', '&'); }

Qt5MenuItem::Qt5MenuItem( const SalItemParams* pItemData ) :
    mnId( pItemData->nId ),
    mnType( pItemData->eType ),
    mpVCLMenu( pItemData->pMenu ),
    mpParentMenu( nullptr ),
    mpSubMenu( nullptr )
Qt5MenuItem::Qt5MenuItem(const SalItemParams* pItemData)
    : mnId(pItemData->nId)
    , mnType(pItemData->eType)
    , mpVCLMenu(pItemData->pMenu)
    , mpParentMenu(nullptr)
    , mpSubMenu(nullptr)
{
}

Qt5MenuItem::~Qt5MenuItem()
{
}
Qt5MenuItem::~Qt5MenuItem() {}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/qt5/Qt5Widget.cxx b/vcl/qt5/Qt5Widget.cxx
index 5331d32..7dc2e17d 100644
--- a/vcl/qt5/Qt5Widget.cxx
+++ b/vcl/qt5/Qt5Widget.cxx
@@ -41,7 +41,7 @@
class VclQtMixinBase
{
public:
    VclQtMixinBase( Qt5Frame *pFrame) { m_pFrame = pFrame; }
    VclQtMixinBase(Qt5Frame* pFrame) { m_pFrame = pFrame; }

    void mixinFocusInEvent(QFocusEvent*);
    void mixinFocusOutEvent(QFocusEvent*);
@@ -61,10 +61,9 @@ private:
    bool mixinHandleKeyEvent(QKeyEvent*, bool);
    void mixinHandleMouseButtonEvent(QMouseEvent*, bool);

    Qt5Frame *m_pFrame;
    Qt5Frame* m_pFrame;
};


void VclQtMixinBase::mixinPaintEvent(QPaintEvent* pEvent, QWidget* widget)
{
    QPainter p(widget);
@@ -74,7 +73,7 @@ void VclQtMixinBase::mixinPaintEvent(QPaintEvent* pEvent, QWidget* widget)
        cairo_surface_flush(pSurface);

        QImage aImage(cairo_image_surface_get_data(pSurface), widget->size().width(),
                      widget->size().height(),Qt5_DefaultFormat32);
                      widget->size().height(), Qt5_DefaultFormat32);
        p.drawImage(pEvent->rect().topLeft(), aImage, pEvent->rect());
    }
    else
@@ -195,7 +194,7 @@ void VclQtMixinBase::mixinMoveEvent(QMoveEvent*)

void VclQtMixinBase::mixinShowEvent(QShowEvent*)
{
    QSize aSize( m_pFrame->GetQWidget()->size() );
    QSize aSize(m_pFrame->GetQWidget()->size());
    SalPaintEvent aPaintEvt(0, 0, aSize.width(), aSize.height(), true);
    m_pFrame->CallCallback(SalEvent::Paint, &aPaintEvt);
}
@@ -380,8 +379,7 @@ void VclQtMixinBase::mixinFocusOutEvent(QFocusEvent*)
    m_pFrame->CallCallback(SalEvent::LoseFocus, nullptr);
}

template<class ParentClassT>
class Qt5Widget : public ParentClassT
template <class ParentClassT> class Qt5Widget : public ParentClassT
{
    //Q_OBJECT

@@ -422,10 +420,7 @@ class Qt5Widget : public ParentClassT
        return maMixin.mixinMouseReleaseEvent(event);
    }

    virtual void moveEvent(QMoveEvent* event) override
    {
        return maMixin.mixinMoveEvent(event);
    }
    virtual void moveEvent(QMoveEvent* event) override { return maMixin.mixinMoveEvent(event); }

    virtual void paintEvent(QPaintEvent* event) override
    {
@@ -437,31 +432,23 @@ class Qt5Widget : public ParentClassT
        return maMixin.mixinResizeEvent(event, ParentClassT::size());
    }

    virtual void showEvent(QShowEvent* event) override
    {
        return maMixin.mixinShowEvent(event);
    }
    virtual void showEvent(QShowEvent* event) override { return maMixin.mixinShowEvent(event); }

    virtual void wheelEvent(QWheelEvent* event) override
    {
        return maMixin.mixinWheelEvent(event);
    }
    virtual void wheelEvent(QWheelEvent* event) override { return maMixin.mixinWheelEvent(event); }

    virtual void closeEvent(QCloseEvent* event) override
    {
        return maMixin.mixinCloseEvent(event);
    }

    virtual void closeEvent(QCloseEvent* event) override { return maMixin.mixinCloseEvent(event); }

private:
    Qt5Widget( Qt5Frame& rFrame, QWidget* parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags() )
        : QWidget(parent, f), maMixin(&rFrame)
    Qt5Widget(Qt5Frame& rFrame, QWidget* parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags())
        : QWidget(parent, f)
        , maMixin(&rFrame)
    {
        Init();
    }

    Qt5Widget( Qt5Frame& rFrame, Qt::WindowFlags f )
        : QMainWindow(Q_NULLPTR, f), maMixin(&rFrame)
    Qt5Widget(Qt5Frame& rFrame, Qt::WindowFlags f)
        : QMainWindow(Q_NULLPTR, f)
        , maMixin(&rFrame)
    {
        Init();
    }
@@ -472,18 +459,19 @@ private:
        ParentClassT::setMouseTracking(true);
        ParentClassT::setFocusPolicy(Qt::StrongFocus);
    }
public:
    virtual ~Qt5Widget() override {};

    friend QWidget* createQt5Widget(Qt5Frame &rFrame, QWidget* parent, Qt::WindowFlags f);
public:
    virtual ~Qt5Widget() override{};

    friend QWidget* createQt5Widget(Qt5Frame& rFrame, QWidget* parent, Qt::WindowFlags f);
};

QWidget* createQt5Widget( Qt5Frame& rFrame, QWidget* parent, Qt::WindowFlags f)
QWidget* createQt5Widget(Qt5Frame& rFrame, QWidget* parent, Qt::WindowFlags f)
{
    if(parent)
       return new Qt5Widget<QWidget>(rFrame, parent, f);
    if (parent)
        return new Qt5Widget<QWidget>(rFrame, parent, f);
    else
       return new Qt5Widget<QMainWindow>(rFrame, f);
        return new Qt5Widget<QMainWindow>(rFrame, f);
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/unx/kde5/FPServiceInfo.hxx b/vcl/unx/kde5/FPServiceInfo.hxx
index fdb2851..ec58684 100644
--- a/vcl/unx/kde5/FPServiceInfo.hxx
+++ b/vcl/unx/kde5/FPServiceInfo.hxx
@@ -23,6 +23,6 @@
#define FILE_PICKER_SERVICE_NAME "com.sun.star.ui.dialogs.KDE4FilePicker"

// the implementation names
#define FILE_PICKER_IMPL_NAME    "com.sun.star.ui.dialogs.KDE4FilePicker"
#define FILE_PICKER_IMPL_NAME "com.sun.star.ui.dialogs.KDE4FilePicker"

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/unx/kde5/KDE5SalData.cxx b/vcl/unx/kde5/KDE5SalData.cxx
index 1b0e207..587bf02 100644
--- a/vcl/unx/kde5/KDE5SalData.cxx
+++ b/vcl/unx/kde5/KDE5SalData.cxx
@@ -24,18 +24,16 @@

#include "KDE5SalData.hxx"

KDE5SalData::KDE5SalData( SalInstance *pInstance )
    : Qt5Data( pInstance )
KDE5SalData::KDE5SalData(SalInstance* pInstance)
    : Qt5Data(pInstance)
{
}

KDE5SalData::~KDE5SalData()
{
}
KDE5SalData::~KDE5SalData() {}

void KDE5SalData::initNWF()
{
    ImplSVData *pSVData = ImplGetSVData();
    ImplSVData* pSVData = ImplGetSVData();

    // draw toolbars on separate lines
    pSVData->maNWFData.mbDockingAreaSeparateTB = true;
@@ -48,13 +46,11 @@ void KDE5SalData::initNWF()
    pSVData->maNWFData.mbNoFocusRectsForFlatButtons = true;

    // Styled menus need additional space
    QStyle *style = QApplication::style();
    pSVData->maNWFData.mnMenuFormatBorderX =
       style->pixelMetric( QStyle::PM_MenuPanelWidth ) +
       style->pixelMetric( QStyle::PM_MenuHMargin );
    pSVData->maNWFData.mnMenuFormatBorderY =
       style->pixelMetric( QStyle::PM_MenuPanelWidth ) +
       style->pixelMetric( QStyle::PM_MenuVMargin );
    QStyle* style = QApplication::style();
    pSVData->maNWFData.mnMenuFormatBorderX = style->pixelMetric(QStyle::PM_MenuPanelWidth)
                                             + style->pixelMetric(QStyle::PM_MenuHMargin);
    pSVData->maNWFData.mnMenuFormatBorderY = style->pixelMetric(QStyle::PM_MenuPanelWidth)
                                             + style->pixelMetric(QStyle::PM_MenuVMargin);
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/unx/kde5/KDE5SalData.hxx b/vcl/unx/kde5/KDE5SalData.hxx
index a721806..32b24da 100644
--- a/vcl/unx/kde5/KDE5SalData.hxx
+++ b/vcl/unx/kde5/KDE5SalData.hxx
@@ -23,11 +23,11 @@

class KDE5SalData : public Qt5Data
{
    public:
        KDE5SalData( SalInstance *pInstance );
        virtual ~KDE5SalData();
public:
    KDE5SalData(SalInstance* pInstance);
    virtual ~KDE5SalData();

        static void initNWF() ;
    static void initNWF();
};

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/unx/kde5/KDE5SalDisplay.cxx b/vcl/unx/kde5/KDE5SalDisplay.cxx
index 4b844c2..e6cec36 100644
--- a/vcl/unx/kde5/KDE5SalDisplay.cxx
+++ b/vcl/unx/kde5/KDE5SalDisplay.cxx
@@ -28,12 +28,12 @@

SalKDE5Display* SalKDE5Display::selfptr = nullptr;

SalKDE5Display::SalKDE5Display( Display* pDisp )
    : SalX11Display( pDisp )
SalKDE5Display::SalKDE5Display(Display* pDisp)
    : SalX11Display(pDisp)
{
    assert( selfptr == nullptr );
    assert(selfptr == nullptr);
    selfptr = this;
    xim_protocol = XInternAtom( pDisp_, "_XIM_PROTOCOL", False );
    xim_protocol = XInternAtom(pDisp_, "_XIM_PROTOCOL", False);
}

SalKDE5Display::~SalKDE5Display()
@@ -48,16 +48,16 @@ SalKDE5Display::~SalKDE5Display()

void SalKDE5Display::Yield()
{
    if( DispatchInternalEvent() )
    if (DispatchInternalEvent())
        return;

    // Prevent blocking from Drag'n'Drop events, which may have already have processed the event
    if (XEventsQueued( pDisp_, QueuedAfterReading ) == 0)
    if (XEventsQueued(pDisp_, QueuedAfterReading) == 0)
        return;

    DBG_ASSERT( GetSalData()->m_pInstance->GetYieldMutex()->IsCurrentThread() ==
                osl::Thread::getCurrentIdentifier(),
                "will crash soon since solar mutex not locked in SalKDE5Display::Yield" );
    DBG_ASSERT(GetSalData()->m_pInstance->GetYieldMutex()->IsCurrentThread()
                   == osl::Thread::getCurrentIdentifier(),
               "will crash soon since solar mutex not locked in SalKDE5Display::Yield");

    /*XEvent event;
    XNextEvent( pDisp_, &event );
@@ -74,22 +74,21 @@ void SalKDE5Display::Yield()
// completely. Skipped events are KeyPress, KeyRelease and also _XIM_PROTOCOL client message
// (seems to be necessary too, hopefully there are not other internal XIM messages that
// would need this handling).
bool SalKDE5Display::checkDirectInputEvent( xcb_generic_event_t* ev )
bool SalKDE5Display::checkDirectInputEvent(xcb_generic_event_t* ev)
{
    switch (ev->response_type & ~0x80)
    {
        case XCB_CLIENT_MESSAGE:
        case XCB_KEY_PRESS:
        case XCB_KEY_RELEASE:
            if( QApplication::activeWindow() == nullptr )
            if (QApplication::activeWindow() == nullptr)
            {
//                Dispatch(ev);
                //                Dispatch(ev);
                return true;
            }
            break;
    }
    return false;

}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/unx/kde5/KDE5SalDisplay.hxx b/vcl/unx/kde5/KDE5SalDisplay.hxx
index 8cd18d4..640efdb 100644
--- a/vcl/unx/kde5/KDE5SalDisplay.hxx
+++ b/vcl/unx/kde5/KDE5SalDisplay.hxx
@@ -28,20 +28,18 @@

class SalKDE5Display : public SalX11Display
{
    public:
        explicit SalKDE5Display( Display* pDisp );
        virtual ~SalKDE5Display() override;
        static SalKDE5Display* self();
        virtual void Yield() override;
        bool checkDirectInputEvent( xcb_generic_event_t* ev );
    private:
        Atom xim_protocol;
        static SalKDE5Display* selfptr;
public:
    explicit SalKDE5Display(Display* pDisp);
    virtual ~SalKDE5Display() override;
    static SalKDE5Display* self();
    virtual void Yield() override;
    bool checkDirectInputEvent(xcb_generic_event_t* ev);

private:
    Atom xim_protocol;
    static SalKDE5Display* selfptr;
};

inline SalKDE5Display* SalKDE5Display::self()
{
    return selfptr;
}
inline SalKDE5Display* SalKDE5Display::self() { return selfptr; }

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/unx/kde5/KDE5SalFrame.cxx b/vcl/unx/kde5/KDE5SalFrame.cxx
index 849f0f3..8caa9b9 100644
--- a/vcl/unx/kde5/KDE5SalFrame.cxx
+++ b/vcl/unx/kde5/KDE5SalFrame.cxx
@@ -45,109 +45,108 @@

#include <boost/optional.hpp>


KDE5SalFrame::KDE5SalFrame( KDE5SalFrame* pParent, SalFrameStyleFlags nState, bool bUseCairo )
    :Qt5Frame( pParent, nState, bUseCairo )
    ,m_bGraphicsInUse(false)
KDE5SalFrame::KDE5SalFrame(KDE5SalFrame* pParent, SalFrameStyleFlags nState, bool bUseCairo)
    : Qt5Frame(pParent, nState, bUseCairo)
    , m_bGraphicsInUse(false)
{
}

/** Helper function to convert colors.
*/
static Color toColor( const QColor &rColor )
static Color toColor(const QColor& rColor)
{
    return Color( rColor.red(), rColor.green(), rColor.blue() );
    return Color(rColor.red(), rColor.green(), rColor.blue());
}


/** Helper function to add information to Font from QFont.

    Mostly grabbed from the Gtk+ vclplug (salnativewidgets-gtk.cxx).
*/
static vcl::Font toFont( const QFont &rQFont, const css::lang::Locale& rLocale )
static vcl::Font toFont(const QFont& rQFont, const css::lang::Locale& rLocale)
{
    psp::FastPrintFontInfo aInfo;
    QFontInfo qFontInfo( rQFont );
    QFontInfo qFontInfo(rQFont);

    // set family name
    aInfo.m_aFamilyName = OUString( static_cast<const char *>(rQFont.family().toUtf8()), strlen( static_cast<const char *>(rQFont.family().toUtf8()) ), RTL_TEXTENCODING_UTF8 );
    aInfo.m_aFamilyName = OUString(static_cast<const char*>(rQFont.family().toUtf8()),
                                   strlen(static_cast<const char*>(rQFont.family().toUtf8())),
                                   RTL_TEXTENCODING_UTF8);

    // set italic
    aInfo.m_eItalic = ( qFontInfo.italic()? ITALIC_NORMAL: ITALIC_NONE );
    aInfo.m_eItalic = (qFontInfo.italic() ? ITALIC_NORMAL : ITALIC_NONE);

    // set weight
    int nWeight = qFontInfo.weight();
    if ( nWeight <= QFont::Light )
    if (nWeight <= QFont::Light)
        aInfo.m_eWeight = WEIGHT_LIGHT;
    else if ( nWeight <= QFont::Normal )
    else if (nWeight <= QFont::Normal)
        aInfo.m_eWeight = WEIGHT_NORMAL;
    else if ( nWeight <= QFont::DemiBold )
    else if (nWeight <= QFont::DemiBold)
        aInfo.m_eWeight = WEIGHT_SEMIBOLD;
    else if ( nWeight <= QFont::Bold )
    else if (nWeight <= QFont::Bold)
        aInfo.m_eWeight = WEIGHT_BOLD;
    else
        aInfo.m_eWeight = WEIGHT_ULTRABOLD;

    // set width
    int nStretch = rQFont.stretch();
    if ( nStretch <= QFont::UltraCondensed )
    if (nStretch <= QFont::UltraCondensed)
        aInfo.m_eWidth = WIDTH_ULTRA_CONDENSED;
    else if ( nStretch <= QFont::ExtraCondensed )
    else if (nStretch <= QFont::ExtraCondensed)
        aInfo.m_eWidth = WIDTH_EXTRA_CONDENSED;
    else if ( nStretch <= QFont::Condensed )
    else if (nStretch <= QFont::Condensed)
        aInfo.m_eWidth = WIDTH_CONDENSED;
    else if ( nStretch <= QFont::SemiCondensed )
    else if (nStretch <= QFont::SemiCondensed)
        aInfo.m_eWidth = WIDTH_SEMI_CONDENSED;
    else if ( nStretch <= QFont::Unstretched )
    else if (nStretch <= QFont::Unstretched)
        aInfo.m_eWidth = WIDTH_NORMAL;
    else if ( nStretch <= QFont::SemiExpanded )
    else if (nStretch <= QFont::SemiExpanded)
        aInfo.m_eWidth = WIDTH_SEMI_EXPANDED;
    else if ( nStretch <= QFont::Expanded )
    else if (nStretch <= QFont::Expanded)
        aInfo.m_eWidth = WIDTH_EXPANDED;
    else if ( nStretch <= QFont::ExtraExpanded )
    else if (nStretch <= QFont::ExtraExpanded)
        aInfo.m_eWidth = WIDTH_EXTRA_EXPANDED;
    else
        aInfo.m_eWidth = WIDTH_ULTRA_EXPANDED;

    SAL_INFO( "vcl.kde5", "font name BEFORE system match: \"" << aInfo.m_aFamilyName << "\"" );
    SAL_INFO("vcl.kde5", "font name BEFORE system match: \"" << aInfo.m_aFamilyName << "\"");

    // match font to e.g. resolve "Sans"
    psp::PrintFontManager::get().matchFont( aInfo, rLocale );
    psp::PrintFontManager::get().matchFont(aInfo, rLocale);

    SAL_INFO( "vcl.kde5", "font match " <<
              (aInfo.m_nID != 0 ? "succeeded" : "failed") <<
              ", name AFTER: \"" << aInfo.m_aFamilyName << "\"" );
    SAL_INFO("vcl.kde5", "font match " << (aInfo.m_nID != 0 ? "succeeded" : "failed")
                                       << ", name AFTER: \"" << aInfo.m_aFamilyName << "\"");

    // font height
    int nPointHeight = qFontInfo.pointSize();
    if ( nPointHeight <= 0 )
    if (nPointHeight <= 0)
        nPointHeight = rQFont.pointSize();

    // Create the font
    vcl::Font aFont( aInfo.m_aFamilyName, Size( 0, nPointHeight ) );
    if( aInfo.m_eWeight != WEIGHT_DONTKNOW )
        aFont.SetWeight( aInfo.m_eWeight );
    if( aInfo.m_eWidth != WIDTH_DONTKNOW )
        aFont.SetWidthType( aInfo.m_eWidth );
    if( aInfo.m_eItalic != ITALIC_DONTKNOW )
        aFont.SetItalic( aInfo.m_eItalic );
    if( aInfo.m_ePitch != PITCH_DONTKNOW )
        aFont.SetPitch( aInfo.m_ePitch );
    vcl::Font aFont(aInfo.m_aFamilyName, Size(0, nPointHeight));
    if (aInfo.m_eWeight != WEIGHT_DONTKNOW)
        aFont.SetWeight(aInfo.m_eWeight);
    if (aInfo.m_eWidth != WIDTH_DONTKNOW)
        aFont.SetWidthType(aInfo.m_eWidth);
    if (aInfo.m_eItalic != ITALIC_DONTKNOW)
        aFont.SetItalic(aInfo.m_eItalic);
    if (aInfo.m_ePitch != PITCH_DONTKNOW)
        aFont.SetPitch(aInfo.m_ePitch);

    return aFont;
}

/** Implementation of KDE integration's main method.
*/
void KDE5SalFrame::UpdateSettings( AllSettings& rSettings )
void KDE5SalFrame::UpdateSettings(AllSettings& rSettings)
{
    StyleSettings style( rSettings.GetStyleSettings() );
    StyleSettings style(rSettings.GetStyleSettings());
    bool bSetTitleFont = false;

    // General settings
    QPalette pal = QApplication::palette();

    style.SetToolbarIconSize( ToolbarIconSize::Large );
    style.SetToolbarIconSize(ToolbarIconSize::Large);

    style.SetActiveColor(toColor(pal.color(QPalette::Active, QPalette::Window)));
    style.SetDeactiveColor(toColor(pal.color(QPalette::Inactive, QPalette::Window)));
@@ -190,125 +189,127 @@ void KDE5SalFrame::UpdateSettings( AllSettings& rSettings )
        }
    }*/

    Color aFore = toColor( pal.color( QPalette::Active, QPalette::WindowText ) );
    Color aBack = toColor( pal.color( QPalette::Active, QPalette::Window ) );
    Color aText = toColor( pal.color( QPalette::Active, QPalette::Text ) );
    Color aBase = toColor( pal.color( QPalette::Active, QPalette::Base ) );
    Color aButn = toColor( pal.color( QPalette::Active, QPalette::ButtonText ) );
    Color aMid = toColor( pal.color( QPalette::Active, QPalette::Mid ) );
    Color aHigh = toColor( pal.color( QPalette::Active, QPalette::Highlight ) );
    Color aHighText = toColor( pal.color( QPalette::Active, QPalette::HighlightedText ) );
    Color aFore = toColor(pal.color(QPalette::Active, QPalette::WindowText));
    Color aBack = toColor(pal.color(QPalette::Active, QPalette::Window));
    Color aText = toColor(pal.color(QPalette::Active, QPalette::Text));
    Color aBase = toColor(pal.color(QPalette::Active, QPalette::Base));
    Color aButn = toColor(pal.color(QPalette::Active, QPalette::ButtonText));
    Color aMid = toColor(pal.color(QPalette::Active, QPalette::Mid));
    Color aHigh = toColor(pal.color(QPalette::Active, QPalette::Highlight));
    Color aHighText = toColor(pal.color(QPalette::Active, QPalette::HighlightedText));

    style.SetSkipDisabledInMenus( true );
    style.SetSkipDisabledInMenus(true);

    // Foreground
    style.SetRadioCheckTextColor( aFore );
    style.SetLabelTextColor( aFore );
    style.SetDialogTextColor( aFore );
    style.SetGroupTextColor( aFore );
    style.SetRadioCheckTextColor(aFore);
    style.SetLabelTextColor(aFore);
    style.SetDialogTextColor(aFore);
    style.SetGroupTextColor(aFore);

    // Text
    style.SetFieldTextColor( aText );
    style.SetFieldRolloverTextColor( aText );
    style.SetWindowTextColor( aText );
    style.SetToolTextColor( aText );
    style.SetFieldTextColor(aText);
    style.SetFieldRolloverTextColor(aText);
    style.SetWindowTextColor(aText);
    style.SetToolTextColor(aText);

    // Base
    style.SetFieldColor( aBase );
    style.SetWindowColor( aBase );
    style.SetActiveTabColor( aBase );
    style.SetFieldColor(aBase);
    style.SetWindowColor(aBase);
    style.SetActiveTabColor(aBase);

    // Buttons
    style.SetButtonTextColor( aButn );
    style.SetButtonRolloverTextColor( aButn );
    style.SetButtonPressedRolloverTextColor( aButn );
    style.SetButtonTextColor(aButn);
    style.SetButtonRolloverTextColor(aButn);
    style.SetButtonPressedRolloverTextColor(aButn);

    // Tabs
    style.SetTabTextColor( aButn );
    style.SetTabRolloverTextColor( aButn );
    style.SetTabHighlightTextColor( aButn );
    style.SetTabTextColor(aButn);
    style.SetTabRolloverTextColor(aButn);
    style.SetTabHighlightTextColor(aButn);

    // Disable color
    style.SetDisableColor( toColor( pal.color( QPalette::Disabled, QPalette::WindowText ) ) );
    style.SetDisableColor(toColor(pal.color(QPalette::Disabled, QPalette::WindowText)));

    // Background
    style.BatchSetBackgrounds( aBack );
    style.SetInactiveTabColor( aBack );
    style.BatchSetBackgrounds(aBack);
    style.SetInactiveTabColor(aBack);

    // Workspace
    style.SetWorkspaceColor( aMid );
    style.SetWorkspaceColor(aMid);

    // Selection
    style.SetHighlightColor( aHigh );
    style.SetHighlightTextColor( aHighText );
    style.SetHighlightColor(aHigh);
    style.SetHighlightTextColor(aHighText);

    // Tooltip
    style.SetHelpColor( toColor( QToolTip::palette().color( QPalette::Active, QPalette::ToolTipBase )));
    style.SetHelpTextColor( toColor( QToolTip::palette().color( QPalette::Active, QPalette::ToolTipText )));
    style.SetHelpColor(toColor(QToolTip::palette().color(QPalette::Active, QPalette::ToolTipBase)));
    style.SetHelpTextColor(
        toColor(QToolTip::palette().color(QPalette::Active, QPalette::ToolTipText)));

    // Font
    vcl::Font aFont = toFont( QApplication::font(), rSettings.GetUILanguageTag().getLocale() );
    vcl::Font aFont = toFont(QApplication::font(), rSettings.GetUILanguageTag().getLocale());

    style.BatchSetFonts( aFont, aFont );
    style.BatchSetFonts(aFont, aFont);

    aFont.SetWeight( WEIGHT_BOLD );
    if( !bSetTitleFont )
    aFont.SetWeight(WEIGHT_BOLD);
    if (!bSetTitleFont)
    {
        style.SetTitleFont( aFont );
        style.SetTitleFont(aFont);
    }
    style.SetFloatTitleFont( aFont );
    style.SetHelpFont( toFont( QToolTip::font(), rSettings.GetUILanguageTag().getLocale()));
    style.SetFloatTitleFont(aFont);
    style.SetHelpFont(toFont(QToolTip::font(), rSettings.GetUILanguageTag().getLocale()));

    int flash_time = QApplication::cursorFlashTime();
    style.SetCursorBlinkTime( flash_time != 0 ? flash_time/2 : STYLE_CURSOR_NOBLINKTIME );
    style.SetCursorBlinkTime(flash_time != 0 ? flash_time / 2 : STYLE_CURSOR_NOBLINKTIME);

    // Menu
    std::unique_ptr<QMenuBar> pMenuBar = std::unique_ptr<QMenuBar>( new QMenuBar() );
    std::unique_ptr<QMenuBar> pMenuBar = std::unique_ptr<QMenuBar>(new QMenuBar());
    QPalette qMenuCG = pMenuBar->palette();

    // Menu text and background color, theme specific
    Color aMenuFore = toColor( qMenuCG.color( QPalette::WindowText ) );
    Color aMenuBack = toColor( qMenuCG.color( QPalette::Window ) );
    Color aMenuFore = toColor(qMenuCG.color(QPalette::WindowText));
    Color aMenuBack = toColor(qMenuCG.color(QPalette::Window));

    style.SetMenuTextColor( aMenuFore );
    style.SetMenuBarTextColor( style.GetPersonaMenuBarTextColor().get_value_or( aMenuFore ) );
    style.SetMenuColor( aMenuBack );
    style.SetMenuBarColor( aMenuBack );
    style.SetMenuHighlightColor( toColor ( qMenuCG.color( QPalette::Highlight ) ) );
    style.SetMenuHighlightTextColor( toColor ( qMenuCG.color( QPalette::HighlightedText ) ) );
    style.SetMenuTextColor(aMenuFore);
    style.SetMenuBarTextColor(style.GetPersonaMenuBarTextColor().get_value_or(aMenuFore));
    style.SetMenuColor(aMenuBack);
    style.SetMenuBarColor(aMenuBack);
    style.SetMenuHighlightColor(toColor(qMenuCG.color(QPalette::Highlight)));
    style.SetMenuHighlightTextColor(toColor(qMenuCG.color(QPalette::HighlightedText)));

    // set special menubar highlight text color
    if ( QApplication::style()->inherits( "HighContrastStyle" ) )
        ImplGetSVData()->maNWFData.maMenuBarHighlightTextColor = toColor( qMenuCG.color( QPalette::HighlightedText ) );
    if (QApplication::style()->inherits("HighContrastStyle"))
        ImplGetSVData()->maNWFData.maMenuBarHighlightTextColor
            = toColor(qMenuCG.color(QPalette::HighlightedText));
    else
        ImplGetSVData()->maNWFData.maMenuBarHighlightTextColor = aMenuFore;

    // set menubar rollover color
    if ( pMenuBar->style()->styleHint( QStyle::SH_MenuBar_MouseTracking ) )
    if (pMenuBar->style()->styleHint(QStyle::SH_MenuBar_MouseTracking))
    {
        style.SetMenuBarRolloverColor( toColor ( qMenuCG.color( QPalette::Highlight ) ) );
        style.SetMenuBarRolloverTextColor( ImplGetSVData()->maNWFData.maMenuBarHighlightTextColor );
        style.SetMenuBarRolloverColor(toColor(qMenuCG.color(QPalette::Highlight)));
        style.SetMenuBarRolloverTextColor(ImplGetSVData()->maNWFData.maMenuBarHighlightTextColor);
    }
    else
    {
        style.SetMenuBarRolloverColor( aMenuBack );
        style.SetMenuBarRolloverTextColor( aMenuFore );
        style.SetMenuBarRolloverColor(aMenuBack);
        style.SetMenuBarRolloverTextColor(aMenuFore);
    }
    style.SetMenuBarHighlightTextColor(style.GetMenuHighlightTextColor());

    // Font
    aFont = toFont( pMenuBar->font(), rSettings.GetUILanguageTag().getLocale() );
    style.SetMenuFont( aFont );
    aFont = toFont(pMenuBar->font(), rSettings.GetUILanguageTag().getLocale());
    style.SetMenuFont(aFont);

    // Scroll bar size
    style.SetScrollBarSize( QApplication::style()->pixelMetric( QStyle::PM_ScrollBarExtent ) );
    style.SetMinThumbSize( QApplication::style()->pixelMetric( QStyle::PM_ScrollBarSliderMin ));
    style.SetScrollBarSize(QApplication::style()->pixelMetric(QStyle::PM_ScrollBarExtent));
    style.SetMinThumbSize(QApplication::style()->pixelMetric(QStyle::PM_ScrollBarSliderMin));

    // These colors are used for the ruler text and marks
    style.SetShadowColor(toColor(pal.color(QPalette::Disabled, QPalette::WindowText)));
    style.SetDarkShadowColor(toColor(pal.color(QPalette::Inactive, QPalette::WindowText)));

    rSettings.SetStyleSettings( style );
    rSettings.SetStyleSettings(style);
}

SalGraphics* KDE5SalFrame::AcquireGraphics()
@@ -318,19 +319,19 @@ SalGraphics* KDE5SalFrame::AcquireGraphics()

    m_bGraphicsInUse = true;

    if ( !m_pKDE5Graphics.get() )
    if (!m_pKDE5Graphics.get())
    {
        m_pKDE5Graphics.reset( new KDE5SalGraphics());
        Qt5Frame::InitSvpSalGraphics( m_pKDE5Graphics.get() );
        m_pKDE5Graphics.reset(new KDE5SalGraphics());
        Qt5Frame::InitSvpSalGraphics(m_pKDE5Graphics.get());
    }

    return m_pKDE5Graphics.get();
}

void KDE5SalFrame::ReleaseGraphics( SalGraphics* pSalGraph )
void KDE5SalFrame::ReleaseGraphics(SalGraphics* pSalGraph)
{
    (void)pSalGraph;
    assert( pSalGraph == m_pKDE5Graphics.get() );
    assert(pSalGraph == m_pKDE5Graphics.get());
    m_bGraphicsInUse = false;
}

diff --git a/vcl/unx/kde5/KDE5SalFrame.hxx b/vcl/unx/kde5/KDE5SalFrame.hxx
index 64f4386..11a55b0 100644
--- a/vcl/unx/kde5/KDE5SalFrame.hxx
+++ b/vcl/unx/kde5/KDE5SalFrame.hxx
@@ -34,26 +34,26 @@ class KDE5SalGraphics;

class KDE5SalFrame : public Qt5Frame
{
    private:
        std::unique_ptr<KDE5SalGraphics> m_pKDE5Graphics;
        bool m_bGraphicsInUse;
private:
    std::unique_ptr<KDE5SalGraphics> m_pKDE5Graphics;
    bool m_bGraphicsInUse;

    public:
        KDE5SalFrame( KDE5SalFrame* pParent, SalFrameStyleFlags nStyle, bool bUseCairo );
public:
    KDE5SalFrame(KDE5SalFrame* pParent, SalFrameStyleFlags nStyle, bool bUseCairo);

        virtual SalGraphics* AcquireGraphics() override;
        virtual void ReleaseGraphics( SalGraphics *pGraphics ) override;
        virtual void UpdateSettings( AllSettings& rSettings ) override;
    virtual SalGraphics* AcquireGraphics() override;
    virtual void ReleaseGraphics(SalGraphics* pGraphics) override;
    virtual void UpdateSettings(AllSettings& rSettings) override;

        virtual void DrawMenuBar() override { return; }
    virtual void DrawMenuBar() override { return; }

        virtual LanguageType GetInputLanguage() override { return LANGUAGE_SYSTEM; }
        virtual void Beep() override { return; }
        virtual const SystemEnvData* GetSystemData() const override { return nullptr; }
        virtual SalPointerState GetPointerState() override { return SalPointerState(); }
        virtual KeyIndicatorState GetIndicatorState() override { return KeyIndicatorState(); }
    virtual LanguageType GetInputLanguage() override { return LANGUAGE_SYSTEM; }
    virtual void Beep() override { return; }
    virtual const SystemEnvData* GetSystemData() const override { return nullptr; }
    virtual SalPointerState GetPointerState() override { return SalPointerState(); }
    virtual KeyIndicatorState GetIndicatorState() override { return KeyIndicatorState(); }

        virtual void SetScreenNumber( unsigned int ) override { return; }
    virtual void SetScreenNumber(unsigned int) override { return; }
};

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/unx/kde5/KDE5SalGraphics.cxx b/vcl/unx/kde5/KDE5SalGraphics.cxx
index 070a18c..1ef53d0 100644
--- a/vcl/unx/kde5/KDE5SalGraphics.cxx
+++ b/vcl/unx/kde5/KDE5SalGraphics.cxx
@@ -41,42 +41,49 @@
  @param nControlState State of the widget (default, focused, ...) in Native Widget Framework.
  @param aValue Value held by the widget (on, off, ...)
*/
QStyle::State vclStateValue2StateFlag( ControlState nControlState,
    const ImplControlValue& aValue )
QStyle::State vclStateValue2StateFlag(ControlState nControlState, const ImplControlValue& aValue)
{
    QStyle::State nState =
        ( (nControlState & ControlState::ENABLED)?  QStyle::State_Enabled:   QStyle::State_None ) |
        ( (nControlState & ControlState::FOCUSED)?  QStyle::State_HasFocus:  QStyle::State_None ) |
        ( (nControlState & ControlState::PRESSED)?  QStyle::State_Sunken:    QStyle::State_None ) |
        ( (nControlState & ControlState::SELECTED)? QStyle::State_Selected : QStyle::State_None ) |
        ( (nControlState & ControlState::ROLLOVER)? QStyle::State_MouseOver: QStyle::State_None );
    QStyle::State nState
        = ((nControlState & ControlState::ENABLED) ? QStyle::State_Enabled : QStyle::State_None)
          | ((nControlState & ControlState::FOCUSED) ? QStyle::State_HasFocus : QStyle::State_None)
          | ((nControlState & ControlState::PRESSED) ? QStyle::State_Sunken : QStyle::State_None)
          | ((nControlState & ControlState::SELECTED) ? QStyle::State_Selected : QStyle::State_None)
          | ((nControlState & ControlState::ROLLOVER) ? QStyle::State_MouseOver
                                                      : QStyle::State_None);

    switch ( aValue.getTristateVal() )
    switch (aValue.getTristateVal())
    {
        case ButtonValue::On:    nState |= QStyle::State_On;       break;
        case ButtonValue::Off:   nState |= QStyle::State_Off;      break;
        case ButtonValue::Mixed: nState |= QStyle::State_NoChange; break;
        default: break;
        case ButtonValue::On:
            nState |= QStyle::State_On;
            break;
        case ButtonValue::Off:
            nState |= QStyle::State_Off;
            break;
        case ButtonValue::Mixed:
            nState |= QStyle::State_NoChange;
            break;
        default:
            break;
    }

    return nState;
}

void QImage2BitmapBuffer( QImage* pImg, BitmapBuffer* pBuf )
void QImage2BitmapBuffer(QImage* pImg, BitmapBuffer* pBuf)
{
    pBuf->mnWidth = pImg->width();
    pBuf->mnHeight = pImg->height();
    pBuf->mnBitCount = getFormatBits( pImg->format() );
    pBuf->mnBitCount = getFormatBits(pImg->format());
    pBuf->mpBits = pImg->bits();
    pBuf->mnScanlineSize = pImg->bytesPerLine();
}

KDE5SalGraphics::KDE5SalGraphics()
   : SvpSalGraphics()
    : SvpSalGraphics()
{
}

bool KDE5SalGraphics::IsNativeControlSupported( ControlType type, ControlPart part )
bool KDE5SalGraphics::IsNativeControlSupported(ControlType type, ControlPart part)
{
    switch (type)
    {
@@ -124,56 +131,61 @@ bool KDE5SalGraphics::IsNativeControlSupported( ControlType type, ControlPart pa
/// helper drawing methods
namespace
{
    void draw( QStyle::ControlElement element, QStyleOption* option, QImage* image, QStyle::State const & state, QRect rect = QRect())
    {
        option->state |= state;
        option->rect = !rect.isNull() ? rect : image->rect();
void draw(QStyle::ControlElement element, QStyleOption* option, QImage* image,
          QStyle::State const& state, QRect rect = QRect())
{
    option->state |= state;
    option->rect = !rect.isNull() ? rect : image->rect();

        QPainter painter(image);
        QApplication::style()->drawControl(element, option, &painter);
    }

    void draw( QStyle::PrimitiveElement element, QStyleOption* option, QImage* image, QStyle::State const & state, QRect rect = QRect())
    {
        option->state |= state;
        option->rect = !rect.isNull() ? rect : image->rect();

        QPainter painter(image);
        QApplication::style()->drawPrimitive(element, option, &painter);
    }

    void draw( QStyle::ComplexControl element, QStyleOptionComplex* option, QImage* image, QStyle::State const & state )
    {
        option->state |= state;
        option->rect = image->rect();

        QPainter painter(image);
        QApplication::style()->drawComplexControl(element, option, &painter);
    }

    void lcl_drawFrame( QStyle::PrimitiveElement element, QImage* image, QStyle::State const & state,
                        QStyle::PixelMetric eLineMetric = QStyle::PM_DefaultFrameWidth )
    {
        QStyleOptionFrame option;
        option.frameShape = QFrame::StyledPanel;
        option.state = QStyle::State_Sunken;
        option.lineWidth = QApplication::style()->pixelMetric( eLineMetric );
        draw(element, &option, image, state);
    }
    QPainter painter(image);
    QApplication::style()->drawControl(element, option, &painter);
}

bool KDE5SalGraphics::drawNativeControl( ControlType type, ControlPart part,
                                        const tools::Rectangle& rControlRegion, ControlState nControlState,
                                        const ImplControlValue& value,
                                        const OUString& )
void draw(QStyle::PrimitiveElement element, QStyleOption* option, QImage* image,
          QStyle::State const& state, QRect rect = QRect())
{
    bool nativeSupport = IsNativeControlSupported( type, part );
    if( ! nativeSupport ) {
        assert( ! nativeSupport && "drawNativeControl called without native support!" );
    option->state |= state;
    option->rect = !rect.isNull() ? rect : image->rect();

    QPainter painter(image);
    QApplication::style()->drawPrimitive(element, option, &painter);
}

void draw(QStyle::ComplexControl element, QStyleOptionComplex* option, QImage* image,
          QStyle::State const& state)
{
    option->state |= state;
    option->rect = image->rect();

    QPainter painter(image);
    QApplication::style()->drawComplexControl(element, option, &painter);
}

void lcl_drawFrame(QStyle::PrimitiveElement element, QImage* image, QStyle::State const& state,
                   QStyle::PixelMetric eLineMetric = QStyle::PM_DefaultFrameWidth)
{
    QStyleOptionFrame option;
    option.frameShape = QFrame::StyledPanel;
    option.state = QStyle::State_Sunken;
    option.lineWidth = QApplication::style()->pixelMetric(eLineMetric);
    draw(element, &option, image, state);
}
}

bool KDE5SalGraphics::drawNativeControl(ControlType type, ControlPart part,
                                        const tools::Rectangle& rControlRegion,
                                        ControlState nControlState, const ImplControlValue& value,
                                        const OUString&)
{
    bool nativeSupport = IsNativeControlSupported(type, part);
    if (!nativeSupport)
    {
        assert(!nativeSupport && "drawNativeControl called without native support!");
        return false;
    }

    if( lastPopupRect.isValid() && ( type != ControlType::MenuPopup || part != ControlPart::MenuItem ))
    if (lastPopupRect.isValid()
        && (type != ControlType::MenuPopup || part != ControlPart::MenuItem))
        lastPopupRect = QRect();

    bool returnVal = true;
@@ -183,30 +195,31 @@ bool KDE5SalGraphics::drawNativeControl( ControlType type, ControlPart part,
    //if no image, or resized, make a new image
    if (!m_image || m_image->size() != widgetRect.size())
    {
        m_image.reset(new QImage( widgetRect.width(), widgetRect.height(), QImage::Format_ARGB32_Premultiplied ) );
        m_image.reset(new QImage(widgetRect.width(), widgetRect.height(),
                                 QImage::Format_ARGB32_Premultiplied));
    }

    // Default image color - just once
    switch (type)
    {
        case ControlType::MenuPopup:
            if( part == ControlPart::MenuItemCheckMark || part == ControlPart::MenuItemRadioMark )
            if (part == ControlPart::MenuItemCheckMark || part == ControlPart::MenuItemRadioMark)
            {
                // it is necessary to fill the background transparently first, as this
                // is painted after menuitem highlight, otherwise there would be a grey area
                m_image->fill( Qt::transparent );
                m_image->fill(Qt::transparent);
                break;
            }
            SAL_FALLTHROUGH; // QPalette::Window
        case ControlType::Menubar:
        case ControlType::WindowBackground:
            m_image->fill( QApplication::palette().color(QPalette::Window).rgb() );
            m_image->fill(QApplication::palette().color(QPalette::Window).rgb());
            break;
        case ControlType::Tooltip:
            m_image->fill(QApplication::palette().color(QPalette::ToolTipBase).rgb());
            break;
        case ControlType::Pushbutton:
            if ( nControlState & ControlState::FOCUSED )
            if (nControlState & ControlState::FOCUSED)
                m_image->fill(QApplication::palette().color(QPalette::Highlight).rgb());
            else
                m_image->fill(QApplication::palette().color(QPalette::Button).rgb());
@@ -215,12 +228,12 @@ bool KDE5SalGraphics::drawNativeControl( ControlType type, ControlPart part,
            if ((part == ControlPart::DrawBackgroundVert)
                || (part == ControlPart::DrawBackgroundHorz))
            {
                m_image->fill( QApplication::palette().color(QPalette::Window).rgb() );
                m_image->fill(QApplication::palette().color(QPalette::Window).rgb());
                break;
            }
            SAL_FALLTHROUGH; // Qt::transparent
        default:
            m_image->fill( Qt::transparent );
            m_image->fill(Qt::transparent);
            break;
    }

@@ -229,29 +242,30 @@ bool KDE5SalGraphics::drawNativeControl( ControlType type, ControlPart part,
    if (type == ControlType::Pushbutton)
    {
        QStyleOptionButton option;
        draw( QStyle::CE_PushButton, &option, m_image.get(),
              vclStateValue2StateFlag(nControlState, value) );
        draw(QStyle::CE_PushButton, &option, m_image.get(),
             vclStateValue2StateFlag(nControlState, value));
    }
    else if (type == ControlType::Menubar)
    {
        if (part == ControlPart::MenuItem)
        {
            QStyleOptionMenuItem option;
            if ( ( nControlState & ControlState::ROLLOVER )
                && QApplication::style()->styleHint( QStyle::SH_MenuBar_MouseTracking ) )
            if ((nControlState & ControlState::ROLLOVER)
                && QApplication::style()->styleHint(QStyle::SH_MenuBar_MouseTracking))
                option.state |= QStyle::State_Selected;

            if ( nControlState & ControlState::SELECTED ) // Passing State_Sunken is currently not documented.
                option.state |= QStyle::State_Sunken;  // But some kinds of QStyle interpret it.
            if (nControlState
                & ControlState::SELECTED) // Passing State_Sunken is currently not documented.
                option.state |= QStyle::State_Sunken; // But some kinds of QStyle interpret it.

            draw( QStyle::CE_MenuBarItem, &option, m_image.get(),
                  vclStateValue2StateFlag(nControlState, value) );
            draw(QStyle::CE_MenuBarItem, &option, m_image.get(),
                 vclStateValue2StateFlag(nControlState, value));
        }
        else if (part == ControlPart::Entire)
        {
            QStyleOptionMenuItem option;
            draw( QStyle::CE_MenuBarEmptyArea, &option, m_image.get(),
                  vclStateValue2StateFlag(nControlState, value) );
            draw(QStyle::CE_MenuBarEmptyArea, &option, m_image.get(),
                 vclStateValue2StateFlag(nControlState, value));
        }
        else
        {
@@ -260,23 +274,25 @@ bool KDE5SalGraphics::drawNativeControl( ControlType type, ControlPart part,
    }
    else if (type == ControlType::MenuPopup)
    {
        OSL_ASSERT( part == ControlPart::MenuItem ? lastPopupRect.isValid() : !lastPopupRect.isValid());
        if( part == ControlPart::MenuItem )
        OSL_ASSERT(part == ControlPart::MenuItem ? lastPopupRect.isValid()
                                                 : !lastPopupRect.isValid());
        if (part == ControlPart::MenuItem)
        {
            QStyleOptionMenuItem option;
            draw( QStyle::CE_MenuItem, &option, m_image.get(),
                  vclStateValue2StateFlag(nControlState, value) );
            draw(QStyle::CE_MenuItem, &option, m_image.get(),
                 vclStateValue2StateFlag(nControlState, value));
            // HACK: LO core first paints the entire popup and only then it paints menu items,
            // but QMenu::paintEvent() paints popup frame after all items. That means highlighted
            // items here would paint the highlight over the frame border. Since calls to ControlPart::MenuItem
            // are always preceded by calls to ControlPart::Entire, just remember the size for the whole
            // popup (otherwise not possible to get here) and draw the border afterwards.
            QRect framerect( lastPopupRect.topLeft() - widgetRect.topLeft(),
                widgetRect.size().expandedTo( lastPopupRect.size()));
            QRect framerect(lastPopupRect.topLeft() - widgetRect.topLeft(),
                            widgetRect.size().expandedTo(lastPopupRect.size()));
            QStyleOptionFrame frame;
            draw( QStyle::PE_FrameMenu, &frame, m_image.get(), vclStateValue2StateFlag( nControlState, value ), framerect );
            draw(QStyle::PE_FrameMenu, &frame, m_image.get(),
                 vclStateValue2StateFlag(nControlState, value), framerect);
        }
        else if( part == ControlPart::Separator )
        else if (part == ControlPart::Separator)
        {
            QStyleOptionMenuItem option;
            option.menuItemType = QStyleOptionMenuItem::Separator;
@@ -284,130 +300,139 @@ bool KDE5SalGraphics::drawNativeControl( ControlType type, ControlPart part,
            // with at least Plastique style, so clip only to the separator itself
            // (QSize( 2, 2 ) is hardcoded in Qt)
            option.rect = m_image->rect();
            QSize size = QApplication::style()->sizeFromContents( QStyle::CT_MenuItem, &option, QSize( 2, 2 ));
            QSize size = QApplication::style()->sizeFromContents(QStyle::CT_MenuItem, &option,
                                                                 QSize(2, 2));
            QRect rect = m_image->rect();
            QPoint center = rect.center();
            rect.setHeight( size.height());
            rect.moveCenter( center );
            rect.setHeight(size.height());
            rect.moveCenter(center);
            // don't paint over popup frame border (like the hack above, but here it can be simpler)
            int fw = QApplication::style()->pixelMetric( QStyle::PM_MenuPanelWidth );
            localClipRegion = new QRegion(rect.translated(widgetRect.topLeft()).adjusted(fw, 0, -fw, 0));
            draw( QStyle::CE_MenuItem, &option, m_image.get(),
                  vclStateValue2StateFlag(nControlState, value), rect );
            int fw = QApplication::style()->pixelMetric(QStyle::PM_MenuPanelWidth);
            localClipRegion
                = new QRegion(rect.translated(widgetRect.topLeft()).adjusted(fw, 0, -fw, 0));
            draw(QStyle::CE_MenuItem, &option, m_image.get(),
                 vclStateValue2StateFlag(nControlState, value), rect);
        }
        else if( part == ControlPart::MenuItemCheckMark || part == ControlPart::MenuItemRadioMark )
        else if (part == ControlPart::MenuItemCheckMark || part == ControlPart::MenuItemRadioMark)
        {
            QStyleOptionMenuItem option;
            option.checkType = ( part == ControlPart::MenuItemCheckMark )
                ? QStyleOptionMenuItem::NonExclusive : QStyleOptionMenuItem::Exclusive;
            option.checked = bool( nControlState & ControlState::PRESSED );
            option.checkType = (part == ControlPart::MenuItemCheckMark)
                                   ? QStyleOptionMenuItem::NonExclusive
                                   : QStyleOptionMenuItem::Exclusive;
            option.checked = bool(nControlState & ControlState::PRESSED);
            // widgetRect is now the rectangle for the checkbox/radiobutton itself, but Qt
            // paints the whole menu item, so translate position (and it'll be clipped);
            // it is also necessary to fill the background transparently first, as this
            // is painted after menuitem highlight, otherwise there would be a grey area
            assert( value.getType() == ControlType::MenuPopup );
            assert(value.getType() == ControlType::MenuPopup);
            const MenupopupValue* menuVal = static_cast<const MenupopupValue*>(&value);
            QRect menuItemRect( toQRect( menuVal->maItemRect ));
            QRect rect( menuItemRect.topLeft() - widgetRect.topLeft(),
                widgetRect.size().expandedTo( menuItemRect.size()));
            QRect menuItemRect(toQRect(menuVal->maItemRect));
            QRect rect(menuItemRect.topLeft() - widgetRect.topLeft(),
                       widgetRect.size().expandedTo(menuItemRect.size()));
            // checkboxes are always displayed next to images in menus, so are never centered
            const int focus_size = QApplication::style()->pixelMetric( QStyle::PM_FocusFrameHMargin );
            rect.moveTo( -focus_size, rect.y() );
            draw( QStyle::CE_MenuItem, &option, m_image.get(),
                  vclStateValue2StateFlag(nControlState & ~ControlState::PRESSED, value), rect );
            const int focus_size = QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin);
            rect.moveTo(-focus_size, rect.y());
            draw(QStyle::CE_MenuItem, &option, m_image.get(),
                 vclStateValue2StateFlag(nControlState & ~ControlState::PRESSED, value), rect);
        }
        else if( part == ControlPart::Entire )
        else if (part == ControlPart::Entire)
        {
            QStyleOptionMenuItem option;
            draw( QStyle::PE_PanelMenu, &option, m_image.get(), vclStateValue2StateFlag( nControlState, value ));
            draw(QStyle::PE_PanelMenu, &option, m_image.get(),
                 vclStateValue2StateFlag(nControlState, value));
            // Try hard to get any frame!
            QStyleOptionFrame frame;
            draw( QStyle::PE_FrameMenu, &frame, m_image.get(), vclStateValue2StateFlag( nControlState, value ));
            draw( QStyle::PE_FrameWindow, &frame, m_image.get(), vclStateValue2StateFlag( nControlState, value ));
            draw(QStyle::PE_FrameMenu, &frame, m_image.get(),
                 vclStateValue2StateFlag(nControlState, value));
            draw(QStyle::PE_FrameWindow, &frame, m_image.get(),
                 vclStateValue2StateFlag(nControlState, value));
            lastPopupRect = widgetRect;
        }
        else
            returnVal = false;
    }
    else if ( (type == ControlType::Toolbar) && (part == ControlPart::Button) )
    else if ((type == ControlType::Toolbar) && (part == ControlPart::Button))
    {
        QStyleOptionToolButton option;

        option.arrowType = Qt::NoArrow;
        option.subControls = QStyle::SC_ToolButton;

        option.state = vclStateValue2StateFlag( nControlState, value );
        option.state = vclStateValue2StateFlag(nControlState, value);
        option.state |= QStyle::State_Raised | QStyle::State_Enabled | QStyle::State_AutoRaise;

        draw( QStyle::CC_ToolButton, &option, m_image.get(),
              vclStateValue2StateFlag(nControlState, value) );
        draw(QStyle::CC_ToolButton, &option, m_image.get(),
             vclStateValue2StateFlag(nControlState, value));
    }
    else if ( (type == ControlType::Toolbar) && (part == ControlPart::Entire) )
    else if ((type == ControlType::Toolbar) && (part == ControlPart::Entire))
    {
        QStyleOptionToolBar option;

        option.rect = QRect(0, 0, widgetRect.width(), widgetRect.height());
        option.state = vclStateValue2StateFlag( nControlState, value );
        option.state = vclStateValue2StateFlag(nControlState, value);

        draw( QStyle::CE_ToolBar, &option, m_image.get(),
              vclStateValue2StateFlag(nControlState, value) );
        draw(QStyle::CE_ToolBar, &option, m_image.get(),
             vclStateValue2StateFlag(nControlState, value));
    }
    else if ( (type == ControlType::Toolbar)
            && (part == ControlPart::ThumbVert || part == ControlPart::ThumbHorz) )
    {   // reduce paint area only to the handle area
    else if ((type == ControlType::Toolbar)
             && (part == ControlPart::ThumbVert || part == ControlPart::ThumbHorz))
    { // reduce paint area only to the handle area
        const int handleExtend = QApplication::style()->pixelMetric(QStyle::PM_ToolBarHandleExtent);
        QRect rect;
        QStyleOption option;

        if (part == ControlPart::ThumbVert)
        {
            rect = QRect( 0, 0, handleExtend, widgetRect.height());
            localClipRegion = new QRegion(widgetRect.x(), widgetRect.y(), handleExtend, widgetRect.height());
            rect = QRect(0, 0, handleExtend, widgetRect.height());
            localClipRegion
                = new QRegion(widgetRect.x(), widgetRect.y(), handleExtend, widgetRect.height());
            option.state = QStyle::State_Horizontal;
        }
        else
        {
            rect = QRect( 0, 0, widgetRect.width(), handleExtend);
            localClipRegion = new QRegion(widgetRect.x(), widgetRect.y(), widgetRect.width(), handleExtend);
            rect = QRect(0, 0, widgetRect.width(), handleExtend);
            localClipRegion
                = new QRegion(widgetRect.x(), widgetRect.y(), widgetRect.width(), handleExtend);
        }

        draw( QStyle::PE_IndicatorToolBarHandle, &option, m_image.get(),
              vclStateValue2StateFlag(nControlState, value), rect );
        draw(QStyle::PE_IndicatorToolBarHandle, &option, m_image.get(),
             vclStateValue2StateFlag(nControlState, value), rect);
    }
    else if (type == ControlType::Editbox || type == ControlType::MultilineEditbox)
    {
        lcl_drawFrame( QStyle::PE_FrameLineEdit, m_image.get(),
                       vclStateValue2StateFlag(nControlState, value));
        lcl_drawFrame(QStyle::PE_FrameLineEdit, m_image.get(),
                      vclStateValue2StateFlag(nControlState, value));
    }
    else if (type == ControlType::Combobox)
    {
        QStyleOptionComboBox option;
        option.editable = true;
        draw( QStyle::CC_ComboBox, &option, m_image.get(),
              vclStateValue2StateFlag(nControlState, value) );
        draw(QStyle::CC_ComboBox, &option, m_image.get(),
             vclStateValue2StateFlag(nControlState, value));
    }
    else if (type == ControlType::Listbox)
    {
        QStyleOptionComboBox option;
        option.editable = false;
        switch (part) {
        switch (part)
        {
            case ControlPart::ListboxWindow:
                lcl_drawFrame( QStyle::PE_Frame, m_image.get(),
                               vclStateValue2StateFlag(nControlState, value),
                               QStyle::PM_ComboBoxFrameWidth );
                lcl_drawFrame(QStyle::PE_Frame, m_image.get(),
                              vclStateValue2StateFlag(nControlState, value),
                              QStyle::PM_ComboBoxFrameWidth);
                break;
            case ControlPart::SubEdit:
                draw( QStyle::CE_ComboBoxLabel, &option, m_image.get(),
                      vclStateValue2StateFlag(nControlState, value) );
                draw(QStyle::CE_ComboBoxLabel, &option, m_image.get(),
                     vclStateValue2StateFlag(nControlState, value));
                break;
            case ControlPart::Entire:
                draw( QStyle::CC_ComboBox, &option, m_image.get(),
                      vclStateValue2StateFlag(nControlState, value) );
                draw(QStyle::CC_ComboBox, &option, m_image.get(),
                     vclStateValue2StateFlag(nControlState, value));
                break;
            case ControlPart::ButtonDown:
                option.subControls = QStyle::SC_ComboBoxArrow;
                draw( QStyle::CC_ComboBox, &option, m_image.get(),
                      vclStateValue2StateFlag(nControlState, value) );
                draw(QStyle::CC_ComboBox, &option, m_image.get(),
                     vclStateValue2StateFlag(nControlState, value));
                break;
            default:
                returnVal = false;
@@ -422,28 +447,28 @@ bool KDE5SalGraphics::drawNativeControl( ControlType type, ControlPart part,
        if (value.getTristateVal() == ButtonValue::On)
            option.state |= QStyle::State_Open;

        draw( QStyle::PE_IndicatorBranch, &option, m_image.get(),
              vclStateValue2StateFlag(nControlState, value) );
        draw(QStyle::PE_IndicatorBranch, &option, m_image.get(),
             vclStateValue2StateFlag(nControlState, value));
    }
    else if (type == ControlType::ListHeader)
    {
        QStyleOptionHeader option;
        draw(QStyle::CE_HeaderSection, &option, m_image.get(),
              vclStateValue2StateFlag(nControlState, value) );
             vclStateValue2StateFlag(nControlState, value));
    }
    else if (type == ControlType::Checkbox)
    {
        if (part == ControlPart::Entire)
        {
            QStyleOptionButton option;
            draw( QStyle::CE_CheckBox, &option, m_image.get(),
               vclStateValue2StateFlag(nControlState, value) );
            draw(QStyle::CE_CheckBox, &option, m_image.get(),
                 vclStateValue2StateFlag(nControlState, value));
        }
        else if (part == ControlPart::Focus)
        {
            QStyleOptionFocusRect option;
            draw( QStyle::PE_FrameFocusRect, &option, m_image.get(),
                  vclStateValue2StateFlag(nControlState, value) );
            draw(QStyle::PE_FrameFocusRect, &option, m_image.get(),
                 vclStateValue2StateFlag(nControlState, value));
        }
    }
    else if (type == ControlType::Scrollbar)
@@ -451,22 +476,22 @@ bool KDE5SalGraphics::drawNativeControl( ControlType type, ControlPart part,
        if ((part == ControlPart::DrawBackgroundVert) || (part == ControlPart::DrawBackgroundHorz))
        {
            QStyleOptionSlider option;
            OSL_ASSERT( value.getType() == ControlType::Scrollbar );
            const ScrollbarValue* sbVal = static_cast<const ScrollbarValue *>(&value);
            OSL_ASSERT(value.getType() == ControlType::Scrollbar);
            const ScrollbarValue* sbVal = static_cast<const ScrollbarValue*>(&value);

            //if the scroll bar is active (aka not degenrate...allow for hover events
            if (sbVal->mnVisibleSize < sbVal->mnMax)
                option.state = QStyle::State_MouseOver;

            bool horizontal = ( part == ControlPart::DrawBackgroundHorz ); //horizontal or vertical
            bool horizontal = (part == ControlPart::DrawBackgroundHorz); //horizontal or vertical
            option.orientation = horizontal ? Qt::Horizontal : Qt::Vertical;
            if( horizontal )
            if (horizontal)
                option.state |= QStyle::State_Horizontal;

            //setup parameters from the OO values
            option.minimum = sbVal->mnMin;
            option.maximum = sbVal->mnMax - sbVal->mnVisibleSize;
            option.maximum = qMax( option.maximum, option.minimum ); // bnc#619772
            option.maximum = qMax(option.maximum, option.minimum); // bnc#619772
            option.sliderValue = sbVal->mnCur;
            option.sliderPosition = sbVal->mnCur;
            option.pageStep = sbVal->mnVisibleSize;
@@ -477,8 +502,8 @@ bool KDE5SalGraphics::drawNativeControl( ControlType type, ControlPart part,
            if (sbVal->mnThumbState & ControlState::ROLLOVER)
                option.activeSubControls = QStyle::SC_ScrollBarSlider;

            draw( QStyle::CC_ScrollBar, &option, m_image.get(),
                  vclStateValue2StateFlag(nControlState, value) );
            draw(QStyle::CC_ScrollBar, &option, m_image.get(),
                 vclStateValue2StateFlag(nControlState, value));
        }
        else
        {
@@ -491,54 +516,55 @@ bool KDE5SalGraphics::drawNativeControl( ControlType type, ControlPart part,
        option.frame = true;

        // determine active control
        if( value.getType() == ControlType::SpinButtons )
        if (value.getType() == ControlType::SpinButtons)
        {
            const SpinbuttonValue* pSpinVal = static_cast<const SpinbuttonValue *>(&value);
            if( (pSpinVal->mnUpperState & ControlState::PRESSED) )
            const SpinbuttonValue* pSpinVal = static_cast<const SpinbuttonValue*>(&value);
            if ((pSpinVal->mnUpperState & ControlState::PRESSED))
                option.activeSubControls |= QStyle::SC_SpinBoxUp;
            if( (pSpinVal->mnLowerState & ControlState::PRESSED) )
            if ((pSpinVal->mnLowerState & ControlState::PRESSED))
                option.activeSubControls |= QStyle::SC_SpinBoxDown;
            if( (pSpinVal->mnUpperState & ControlState::ENABLED) )
            if ((pSpinVal->mnUpperState & ControlState::ENABLED))
                option.stepEnabled |= QAbstractSpinBox::StepUpEnabled;
            if( (pSpinVal->mnLowerState & ControlState::ENABLED) )
            if ((pSpinVal->mnLowerState & ControlState::ENABLED))
                option.stepEnabled |= QAbstractSpinBox::StepDownEnabled;
            if( (pSpinVal->mnUpperState & ControlState::ROLLOVER) )
            if ((pSpinVal->mnUpperState & ControlState::ROLLOVER))
                option.state = QStyle::State_MouseOver;
            if( (pSpinVal->mnLowerState & ControlState::ROLLOVER) )
            if ((pSpinVal->mnLowerState & ControlState::ROLLOVER))
                option.state = QStyle::State_MouseOver;
        }

        draw( QStyle::CC_SpinBox, &option, m_image.get(),
              vclStateValue2StateFlag(nControlState, value) );
        draw(QStyle::CC_SpinBox, &option, m_image.get(),
             vclStateValue2StateFlag(nControlState, value));
    }
    else if (type == ControlType::Radiobutton)
    {
        if (part == ControlPart::Entire)
        {
            QStyleOptionButton option;
            draw( QStyle::CE_RadioButton, &option, m_image.get(),
                  vclStateValue2StateFlag(nControlState, value) );
            draw(QStyle::CE_RadioButton, &option, m_image.get(),
                 vclStateValue2StateFlag(nControlState, value));
        }
        else if (part == ControlPart::Focus)
        {
            QStyleOptionFocusRect option;
            draw( QStyle::PE_FrameFocusRect, &option, m_image.get(),
                  vclStateValue2StateFlag(nControlState, value) );
            draw(QStyle::PE_FrameFocusRect, &option, m_image.get(),
                 vclStateValue2StateFlag(nControlState, value));
        }
    }
    else if (type == ControlType::Tooltip)
    {
        QStyleOption option;
        draw( QStyle::PE_PanelTipLabel, &option, m_image.get(),
              vclStateValue2StateFlag(nControlState, value) );
        draw(QStyle::PE_PanelTipLabel, &option, m_image.get(),
             vclStateValue2StateFlag(nControlState, value));
    }
    else if (type == ControlType::Frame)
    {
        lcl_drawFrame( QStyle::PE_Frame, m_image.get(),
                       vclStateValue2StateFlag(nControlState, value) );
        lcl_drawFrame(QStyle::PE_Frame, m_image.get(),
                      vclStateValue2StateFlag(nControlState, value));
        // draw just the border, see http://qa.openoffice.org/issues/show_bug.cgi?id=107945
        int fw = QApplication::style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
        localClipRegion = new QRegion(QRegion(widgetRect).subtracted(widgetRect.adjusted(fw, fw, -fw, -fw)));
        localClipRegion
            = new QRegion(QRegion(widgetRect).subtracted(widgetRect.adjusted(fw, fw, -fw, -fw)));
    }
    else if (type == ControlType::WindowBackground)
    {
@@ -550,68 +576,70 @@ bool KDE5SalGraphics::drawNativeControl( ControlType type, ControlPart part,
        option.menuItemType = QStyleOptionMenuItem::Separator;
        option.state |= QStyle::State_Item;

        draw( QStyle::CE_MenuItem, &option, m_image.get(),
              vclStateValue2StateFlag(nControlState, value) );
        draw(QStyle::CE_MenuItem, &option, m_image.get(),
             vclStateValue2StateFlag(nControlState, value));
    }
    else if (type == ControlType::Slider && (part == ControlPart::TrackHorzArea || part == ControlPart::TrackVertArea))
    else if (type == ControlType::Slider
             && (part == ControlPart::TrackHorzArea || part == ControlPart::TrackVertArea))
    {
        OSL_ASSERT( value.getType() == ControlType::Slider );
        const SliderValue* slVal = static_cast<const SliderValue *>(&value);
        OSL_ASSERT(value.getType() == ControlType::Slider);
        const SliderValue* slVal = static_cast<const SliderValue*>(&value);
        QStyleOptionSlider option;

        option.rect = QRect(0, 0, widgetRect.width(), widgetRect.height());
        option.state = vclStateValue2StateFlag( nControlState, value );
        option.maximum     = slVal->mnMax;
        option.minimum     = slVal->mnMin;
        option.state = vclStateValue2StateFlag(nControlState, value);
        option.maximum = slVal->mnMax;
        option.minimum = slVal->mnMin;
        option.sliderPosition = option.sliderValue = slVal->mnCur;
        bool horizontal = ( part == ControlPart::TrackHorzArea ); //horizontal or vertical
        bool horizontal = (part == ControlPart::TrackHorzArea); //horizontal or vertical
        option.orientation = horizontal ? Qt::Horizontal : Qt::Vertical;
        if( horizontal )
        if (horizontal)
            option.state |= QStyle::State_Horizontal;

        draw( QStyle::CC_Slider, &option, m_image.get(), vclStateValue2StateFlag(nControlState, value) );
        draw(QStyle::CC_Slider, &option, m_image.get(),
             vclStateValue2StateFlag(nControlState, value));
    }
    else if( type == ControlType::Progress && part == ControlPart::Entire )
    else if (type == ControlType::Progress && part == ControlPart::Entire)
    {
        QStyleOptionProgressBarV2 option;
        option.minimum = 0;
        option.maximum = widgetRect.width();
        option.progress = value.getNumericVal();
        option.rect = QRect(0, 0, widgetRect.width(), widgetRect.height());
        option.state = vclStateValue2StateFlag( nControlState, value );
        option.state = vclStateValue2StateFlag(nControlState, value);

        draw( QStyle::CE_ProgressBar, &option, m_image.get(),
              vclStateValue2StateFlag(nControlState, value) );
        draw(QStyle::CE_ProgressBar, &option, m_image.get(),
             vclStateValue2StateFlag(nControlState, value));
    }
    else
    {
        returnVal = false;
    }

    BitmapBuffer *pBuffer = new BitmapBuffer;
    QImage2BitmapBuffer( m_image.get(), pBuffer );
    SalTwoRect aTR( 0, 0, m_image.get()->width(), m_image.get()->height(),
                    rControlRegion.getX(), rControlRegion.getY(),
                    rControlRegion.GetWidth(), rControlRegion.GetHeight() );
    drawBitmap( aTR, pBuffer );
    BitmapBuffer* pBuffer = new BitmapBuffer;
    QImage2BitmapBuffer(m_image.get(), pBuffer);
    SalTwoRect aTR(0, 0, m_image.get()->width(), m_image.get()->height(), rControlRegion.getX(),
                   rControlRegion.getY(), rControlRegion.GetWidth(), rControlRegion.GetHeight());
    drawBitmap(aTR, pBuffer);

    delete localClipRegion;
    return returnVal;
}

bool KDE5SalGraphics::getNativeControlRegion( ControlType type, ControlPart part,
                                             const tools::Rectangle& controlRegion, ControlState controlState,
                                             const ImplControlValue& val,
bool KDE5SalGraphics::getNativeControlRegion(ControlType type, ControlPart part,
                                             const tools::Rectangle& controlRegion,
                                             ControlState controlState, const ImplControlValue& val,
                                             const OUString&,
                                             tools::Rectangle &nativeBoundingRegion, tools::Rectangle &nativeContentRegion )
                                             tools::Rectangle& nativeBoundingRegion,
                                             tools::Rectangle& nativeContentRegion)
{
    bool retVal = false;

    QRect boundingRect = toQRect( controlRegion );
    QRect boundingRect = toQRect(controlRegion);
    QRect contentRect = boundingRect;
    QStyleOptionComplex styleOption;

    switch ( type )
    switch (type)
    {
        // Metrics of the push button
        case ControlType::Pushbutton:
@@ -619,11 +647,11 @@ bool KDE5SalGraphics::getNativeControlRegion( ControlType type, ControlPart part
            {
                styleOption.state = vclStateValue2StateFlag(controlState, val);

                if ( controlState & ControlState::DEFAULT )
                if (controlState & ControlState::DEFAULT)
                {
                    int size = QApplication::style()->pixelMetric(
                        QStyle::PM_ButtonDefaultIndicator, &styleOption );
                    boundingRect.adjust( -size, -size, size, size );
                    int size = QApplication::style()->pixelMetric(QStyle::PM_ButtonDefaultIndicator,
                                                                  &styleOption);
                    boundingRect.adjust(-size, -size, size, size);
                    retVal = true;
                }
            }
@@ -635,19 +663,19 @@ bool KDE5SalGraphics::getNativeControlRegion( ControlType type, ControlPart part
            fo.frameShape = QFrame::StyledPanel;
            fo.state = QStyle::State_Sunken;
            fo.lineWidth = QApplication::style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
            QSize aMinSize = QApplication::style()->
                sizeFromContents( QStyle::CT_LineEdit, &fo, contentRect.size() );
            if( aMinSize.height() > boundingRect.height() )
            QSize aMinSize = QApplication::style()->sizeFromContents(QStyle::CT_LineEdit, &fo,
                                                                     contentRect.size());
            if (aMinSize.height() > boundingRect.height())
            {
                int nHeight = (aMinSize.height() - boundingRect.height()) / 2;
                assert( 0 == (aMinSize.height() - boundingRect.height()) % 2 );
                boundingRect.adjust( 0, -nHeight, 0, nHeight );
                assert(0 == (aMinSize.height() - boundingRect.height()) % 2);
                boundingRect.adjust(0, -nHeight, 0, nHeight);
            }
            if( aMinSize.width() > boundingRect.width() )
            if (aMinSize.width() > boundingRect.width())
            {
                int nWidth = (aMinSize.width() - boundingRect.width()) / 2;
                assert( 0 == (aMinSize.width() - boundingRect.width()) % 2 );
                boundingRect.adjust( -nWidth, 0, nWidth, 0 );
                assert(0 == (aMinSize.width() - boundingRect.width()) % 2);
                boundingRect.adjust(-nWidth, 0, nWidth, 0);
            }
            retVal = true;
            break;
@@ -657,17 +685,18 @@ bool KDE5SalGraphics::getNativeControlRegion( ControlType type, ControlPart part
            {
                styleOption.state = vclStateValue2StateFlag(controlState, val);

                contentRect.setWidth(QApplication::style()->pixelMetric(
                    QStyle::PM_IndicatorWidth, &styleOption));
                contentRect.setHeight(QApplication::style()->pixelMetric(
                    QStyle::PM_IndicatorHeight, &styleOption));
                contentRect.setWidth(
                    QApplication::style()->pixelMetric(QStyle::PM_IndicatorWidth, &styleOption));
                contentRect.setHeight(
                    QApplication::style()->pixelMetric(QStyle::PM_IndicatorHeight, &styleOption));

                contentRect.adjust(0, 0,
                    2 * QApplication::style()->pixelMetric(
                        QStyle::PM_FocusFrameHMargin, &styleOption),
                    2 * QApplication::style()->pixelMetric(
                        QStyle::PM_FocusFrameVMargin, &styleOption)
                    );
                                   2
                                       * QApplication::style()->pixelMetric(
                                             QStyle::PM_FocusFrameHMargin, &styleOption),
                                   2
                                       * QApplication::style()->pixelMetric(
                                             QStyle::PM_FocusFrameVMargin, &styleOption));

                boundingRect = contentRect;

@@ -682,33 +711,33 @@ bool KDE5SalGraphics::getNativeControlRegion( ControlType type, ControlPart part
            cbo.rect = QRect(0, 0, contentRect.width(), contentRect.height());
            cbo.state = vclStateValue2StateFlag(controlState, val);

            switch ( part )
            switch (part)
            {
                case ControlPart::Entire:
                {
                    // find out the minimum size that should be used
                    // assume contents is a text line
                    int nHeight = QApplication::fontMetrics().height();
                    QSize aContentSize( contentRect.width(), nHeight );
                    QSize aMinSize = QApplication::style()->
                        sizeFromContents( QStyle::CT_ComboBox, &cbo, aContentSize );
                    if( aMinSize.height() > contentRect.height() )
                        contentRect.adjust( 0, 0, 0, aMinSize.height() - contentRect.height() );
                    QSize aContentSize(contentRect.width(), nHeight);
                    QSize aMinSize = QApplication::style()->sizeFromContents(QStyle::CT_ComboBox,
                                                                             &cbo, aContentSize);
                    if (aMinSize.height() > contentRect.height())
                        contentRect.adjust(0, 0, 0, aMinSize.height() - contentRect.height());
                    boundingRect = contentRect;
                    retVal = true;
                    break;
                }
                case ControlPart::ButtonDown:
                    contentRect = QApplication::style()->subControlRect(
                        QStyle::CC_ComboBox, &cbo, QStyle::SC_ComboBoxArrow );
                    contentRect.translate( boundingRect.left(), boundingRect.top() );
                    contentRect = QApplication::style()->subControlRect(QStyle::CC_ComboBox, &cbo,
                                                                        QStyle::SC_ComboBoxArrow);
                    contentRect.translate(boundingRect.left(), boundingRect.top());
                    retVal = true;
                    break;
                case ControlPart::SubEdit:
                {
                    contentRect = QApplication::style()->subControlRect(
                        QStyle::CC_ComboBox, &cbo, QStyle::SC_ComboBoxEditField );
                    contentRect.translate( boundingRect.left(), boundingRect.top() );
                        QStyle::CC_ComboBox, &cbo, QStyle::SC_ComboBoxEditField);
                    contentRect.translate(boundingRect.left(), boundingRect.top());
                    retVal = true;
                    break;
                }
@@ -725,41 +754,41 @@ bool KDE5SalGraphics::getNativeControlRegion( ControlType type, ControlPart part
            sbo.rect = QRect(0, 0, contentRect.width(), contentRect.height());
            sbo.state = vclStateValue2StateFlag(controlState, val);

            switch ( part )
            switch (part)
            {
                case ControlPart::Entire:
                {
                    int nHeight = QApplication::fontMetrics().height();
                    QSize aContentSize( contentRect.width(), nHeight );
                    QSize aMinSize = QApplication::style()->
                        sizeFromContents( QStyle::CT_SpinBox, &sbo, aContentSize );
                    if( aMinSize.height() > contentRect.height() )
                        contentRect.adjust( 0, 0, 0, aMinSize.height() - contentRect.height() );
                    QSize aContentSize(contentRect.width(), nHeight);
                    QSize aMinSize = QApplication::style()->sizeFromContents(QStyle::CT_SpinBox,
                                                                             &sbo, aContentSize);
                    if (aMinSize.height() > contentRect.height())
                        contentRect.adjust(0, 0, 0, aMinSize.height() - contentRect.height());
                    boundingRect = contentRect;
                    retVal = true;
                    break;
                }
                case ControlPart::ButtonUp:
                    contentRect = QApplication::style()->subControlRect(
                        QStyle::CC_SpinBox, &sbo, QStyle::SC_SpinBoxUp );
                    contentRect.translate( boundingRect.left(), boundingRect.top() );
                    contentRect = QApplication::style()->subControlRect(QStyle::CC_SpinBox, &sbo,
                                                                        QStyle::SC_SpinBoxUp);
                    contentRect.translate(boundingRect.left(), boundingRect.top());
                    retVal = true;
                    boundingRect = QRect();
                    break;

                case ControlPart::ButtonDown:
                    contentRect = QApplication::style()->subControlRect(
                        QStyle::CC_SpinBox, &sbo, QStyle::SC_SpinBoxDown );
                    contentRect = QApplication::style()->subControlRect(QStyle::CC_SpinBox, &sbo,
                                                                        QStyle::SC_SpinBoxDown);
                    retVal = true;
                    contentRect.translate( boundingRect.left(), boundingRect.top() );
                    contentRect.translate(boundingRect.left(), boundingRect.top());
                    boundingRect = QRect();
                    break;

                case ControlPart::SubEdit:
                    contentRect = QApplication::style()->subControlRect(
                        QStyle::CC_SpinBox, &sbo, QStyle::SC_SpinBoxEditField );
                        QStyle::CC_SpinBox, &sbo, QStyle::SC_SpinBoxEditField);
                    retVal = true;
                    contentRect.translate( boundingRect.left(), boundingRect.top() );
                    contentRect.translate(boundingRect.left(), boundingRect.top());
                    break;
                default:
                    break;
@@ -769,21 +798,23 @@ bool KDE5SalGraphics::getNativeControlRegion( ControlType type, ControlPart part
        case ControlType::MenuPopup:
        {
            int h, w;
            switch ( part ) {
            case ControlPart::MenuItemCheckMark:
                h = QApplication::style()->pixelMetric(QStyle::PM_IndicatorHeight);
                w = QApplication::style()->pixelMetric(QStyle::PM_IndicatorWidth);
                retVal = true;
                break;
            case ControlPart::MenuItemRadioMark:
                h = QApplication::style()->pixelMetric(QStyle::PM_ExclusiveIndicatorHeight);
                w = QApplication::style()->pixelMetric(QStyle::PM_ExclusiveIndicatorWidth);
                retVal = true;
                break;
            default:
                break;
            switch (part)
            {
                case ControlPart::MenuItemCheckMark:
                    h = QApplication::style()->pixelMetric(QStyle::PM_IndicatorHeight);
                    w = QApplication::style()->pixelMetric(QStyle::PM_IndicatorWidth);
                    retVal = true;
                    break;
                case ControlPart::MenuItemRadioMark:
                    h = QApplication::style()->pixelMetric(QStyle::PM_ExclusiveIndicatorHeight);
                    w = QApplication::style()->pixelMetric(QStyle::PM_ExclusiveIndicatorWidth);
                    retVal = true;
                    break;
                default:
                    break;
            }
            if (retVal) {
            if (retVal)
            {
                contentRect = QRect(0, 0, w, h);
                boundingRect = contentRect;
            }
@@ -791,13 +822,13 @@ bool KDE5SalGraphics::getNativeControlRegion( ControlType type, ControlPart part
        }
        case ControlType::Frame:
        {
            if( part == ControlPart::Border )
            if (part == ControlPart::Border)
            {
                auto nStyle = static_cast<DrawFrameFlags>(
                    val.getNumericVal() & 0xFFF0);
                if( nStyle & DrawFrameFlags::NoDraw )
                auto nStyle = static_cast<DrawFrameFlags>(val.getNumericVal() & 0xFFF0);
                if (nStyle & DrawFrameFlags::NoDraw)
                {
                    int nFrameWidth = QApplication::style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
                    int nFrameWidth
                        = QApplication::style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
                    contentRect.adjust(nFrameWidth, nFrameWidth, -nFrameWidth, -nFrameWidth);
                }
                retVal = true;
@@ -810,12 +841,10 @@ bool KDE5SalGraphics::getNativeControlRegion( ControlType type, ControlPart part
            const int w = QApplication::style()->pixelMetric(QStyle::PM_ExclusiveIndicatorWidth);

            contentRect = QRect(boundingRect.left(), boundingRect.top(), w, h);
            contentRect.adjust(0, 0,
                2 * QApplication::style()->pixelMetric(
                    QStyle::PM_FocusFrameHMargin, &styleOption),
                2 * QApplication::style()->pixelMetric(
                    QStyle::PM_FocusFrameVMargin, &styleOption)
                );
            contentRect.adjust(
                0, 0,
                2 * QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin, &styleOption),
                2 * QApplication::style()->pixelMetric(QStyle::PM_FocusFrameVMargin, &styleOption));
            boundingRect = contentRect;

            retVal = true;
@@ -824,15 +853,17 @@ bool KDE5SalGraphics::getNativeControlRegion( ControlType type, ControlPart part
        case ControlType::Slider:
        {
            const int w = QApplication::style()->pixelMetric(QStyle::PM_SliderLength);
            if( part == ControlPart::ThumbHorz )
            if (part == ControlPart::ThumbHorz)
            {
                contentRect = QRect(boundingRect.left(), boundingRect.top(), w, boundingRect.height());
                contentRect
                    = QRect(boundingRect.left(), boundingRect.top(), w, boundingRect.height());
                boundingRect = contentRect;
                retVal = true;
            }
            else if( part == ControlPart::ThumbVert )
            else if (part == ControlPart::ThumbVert)
            {
                contentRect = QRect(boundingRect.left(), boundingRect.top(), boundingRect.width(), w);
                contentRect
                    = QRect(boundingRect.left(), boundingRect.top(), boundingRect.width(), w);
                boundingRect = contentRect;
                retVal = true;
            }
@@ -841,15 +872,17 @@ bool KDE5SalGraphics::getNativeControlRegion( ControlType type, ControlPart part
        case ControlType::Toolbar:
        {
            const int nWorH = QApplication::style()->pixelMetric(QStyle::PM_ToolBarHandleExtent);
            if( part == ControlPart::ThumbHorz )
            if (part == ControlPart::ThumbHorz)
            {
                contentRect = QRect(boundingRect.left(), boundingRect.top(), boundingRect.width(), nWorH );
                contentRect
                    = QRect(boundingRect.left(), boundingRect.top(), boundingRect.width(), nWorH);
                boundingRect = contentRect;
                retVal = true;
            }
            else if( part == ControlPart::ThumbVert )
            else if (part == ControlPart::ThumbVert)
            {
                contentRect = QRect(boundingRect.left(), boundingRect.top(), nWorH, boundingRect.height() );
                contentRect
                    = QRect(boundingRect.left(), boundingRect.top(), nWorH, boundingRect.height());
                boundingRect = contentRect;
                retVal = true;
            }
@@ -859,12 +892,12 @@ bool KDE5SalGraphics::getNativeControlRegion( ControlType type, ControlPart part
        {
            // core can't handle 3-button scrollbars well, so we fix that in hitTestNativeControl(),
            // for the rest also provide the track area (i.e. area not taken by buttons)
            if( part == ControlPart::TrackVertArea || part == ControlPart::TrackHorzArea )
            if (part == ControlPart::TrackVertArea || part == ControlPart::TrackHorzArea)
            {
                QStyleOptionSlider option;
                bool horizontal = ( part == ControlPart::TrackHorzArea ); //horizontal or vertical
                bool horizontal = (part == ControlPart::TrackHorzArea); //horizontal or vertical
                option.orientation = horizontal ? Qt::Horizontal : Qt::Vertical;
                if( horizontal )
                if (horizontal)
                    option.state |= QStyle::State_Horizontal;
                // getNativeControlRegion usually gets ImplControlValue as 'val' (i.e. not the proper
                // subclass), so use random sensible values (doesn't matter anyway, as the wanted
@@ -878,11 +911,11 @@ bool KDE5SalGraphics::getNativeControlRegion( ControlType type, ControlPart part
                // coordinates but at least QPlastiqueStyle::subControlRect() is buggy
                // and sometimes uses widget coordinates.
                QRect rect = contentRect;
                rect.moveTo( 0, 0 );
                rect.moveTo(0, 0);
                option.rect = rect;
                rect = QApplication::style()->subControlRect( QStyle::CC_ScrollBar, &option,
                    QStyle::SC_ScrollBarGroove );
                rect.translate( contentRect.topLeft()); // reverse the workaround above
                rect = QApplication::style()->subControlRect(QStyle::CC_ScrollBar, &option,
                                                             QStyle::SC_ScrollBarGroove);
                rect.translate(contentRect.topLeft()); // reverse the workaround above
                contentRect = boundingRect = rect;
                retVal = true;
            }
@@ -894,14 +927,14 @@ bool KDE5SalGraphics::getNativeControlRegion( ControlType type, ControlPart part
    if (retVal)
    {
        // Bounding region
        Point aBPoint( boundingRect.x(), boundingRect.y() );
        Size aBSize( boundingRect.width(), boundingRect.height() );
        nativeBoundingRegion = tools::Rectangle( aBPoint, aBSize );
        Point aBPoint(boundingRect.x(), boundingRect.y());
        Size aBSize(boundingRect.width(), boundingRect.height());
        nativeBoundingRegion = tools::Rectangle(aBPoint, aBSize);

        // vcl::Region of the content
        Point aPoint( contentRect.x(), contentRect.y() );
        Size  aSize( contentRect.width(), contentRect.height() );
        nativeContentRegion = tools::Rectangle( aPoint, aSize );
        Point aPoint(contentRect.x(), contentRect.y());
        Size aSize(contentRect.width(), contentRect.height());
        nativeContentRegion = tools::Rectangle(aPoint, aSize);
    }

    return retVal;
@@ -912,31 +945,31 @@ bool KDE5SalGraphics::getNativeControlRegion( ControlType type, ControlPart part
    aPos was or was not inside the native widget specified by the
    nType/nPart combination.
*/
bool KDE5SalGraphics::hitTestNativeControl( ControlType nType, ControlPart nPart,
                                           const tools::Rectangle& rControlRegion, const Point& rPos,
                                           bool& rIsInside )
bool KDE5SalGraphics::hitTestNativeControl(ControlType nType, ControlPart nPart,
                                           const tools::Rectangle& rControlRegion,
                                           const Point& rPos, bool& rIsInside)
{
    if ( nType == ControlType::Scrollbar )
    if (nType == ControlType::Scrollbar)
    {
        if( nPart != ControlPart::ButtonUp && nPart != ControlPart::ButtonDown
            && nPart != ControlPart::ButtonLeft && nPart != ControlPart::ButtonRight )
        if (nPart != ControlPart::ButtonUp && nPart != ControlPart::ButtonDown
            && nPart != ControlPart::ButtonLeft && nPart != ControlPart::ButtonRight)
        { // we adjust only for buttons (because some scrollbars have 3 buttons,
          // and LO core doesn't handle such scrollbars well)
            // and LO core doesn't handle such scrollbars well)
            return false;
        }
        rIsInside = false;
        bool bHorizontal = ( nPart == ControlPart::ButtonLeft || nPart == ControlPart::ButtonRight );
        QRect rect = toQRect( rControlRegion );
        QPoint pos( rPos.X(), rPos.Y());
        bool bHorizontal = (nPart == ControlPart::ButtonLeft || nPart == ControlPart::ButtonRight);
        QRect rect = toQRect(rControlRegion);
        QPoint pos(rPos.X(), rPos.Y());
        // Adjust coordinates to make the widget appear to be at (0,0), i.e. make
        // widget and screen coordinates the same. QStyle functions should use screen
        // coordinates but at least QPlastiqueStyle::subControlRect() is buggy
        // and sometimes uses widget coordinates.
        pos -= rect.topLeft();
        rect.moveTo( 0, 0 );
        rect.moveTo(0, 0);
        QStyleOptionSlider options;
        options.orientation = bHorizontal ? Qt::Horizontal : Qt::Vertical;
        if( bHorizontal )
        if (bHorizontal)
            options.state |= QStyle::State_Horizontal;
        options.rect = rect;
        // some random sensible values, since we call this code only for scrollbar buttons,
@@ -945,11 +978,12 @@ bool KDE5SalGraphics::hitTestNativeControl( ControlType nType, ControlPart nPart
        options.minimum = 0;
        options.sliderPosition = options.sliderValue = 4;
        options.pageStep = 2;
        QStyle::SubControl control = QApplication::style()->hitTestComplexControl( QStyle::CC_ScrollBar, &options, pos );
        if( nPart == ControlPart::ButtonUp || nPart == ControlPart::ButtonLeft )
            rIsInside = ( control == QStyle::SC_ScrollBarSubLine );
        QStyle::SubControl control
            = QApplication::style()->hitTestComplexControl(QStyle::CC_ScrollBar, &options, pos);
        if (nPart == ControlPart::ButtonUp || nPart == ControlPart::ButtonLeft)
            rIsInside = (control == QStyle::SC_ScrollBarSubLine);
        else // DOWN, RIGHT
            rIsInside = ( control == QStyle::SC_ScrollBarAddLine );
            rIsInside = (control == QStyle::SC_ScrollBarAddLine);
        return true;
    }
    return false;
diff --git a/vcl/unx/kde5/KDE5SalGraphics.hxx b/vcl/unx/kde5/KDE5SalGraphics.hxx
index 94000a8..60870dd 100644
--- a/vcl/unx/kde5/KDE5SalGraphics.hxx
+++ b/vcl/unx/kde5/KDE5SalGraphics.hxx
@@ -37,17 +37,17 @@ class KDE5SalGraphics : public SvpSalGraphics
{
public:
    KDE5SalGraphics();
    virtual bool IsNativeControlSupported( ControlType, ControlPart ) override;
    virtual bool IsNativeControlSupported(ControlType, ControlPart) override;

    virtual bool hitTestNativeControl( ControlType, ControlPart,
                                       const tools::Rectangle&, const Point&, bool& ) override;
    virtual bool hitTestNativeControl(ControlType, ControlPart, const tools::Rectangle&,
                                      const Point&, bool&) override;

    virtual bool drawNativeControl( ControlType, ControlPart, const tools::Rectangle&,
                                    ControlState, const ImplControlValue&, const OUString& ) override;
    virtual bool drawNativeControl(ControlType, ControlPart, const tools::Rectangle&, ControlState,
                                   const ImplControlValue&, const OUString&) override;

    virtual bool getNativeControlRegion( ControlType, ControlPart, const tools::Rectangle&,
                                         ControlState, const ImplControlValue&,
                                         const OUString&, tools::Rectangle&, tools::Rectangle& ) override;
    virtual bool getNativeControlRegion(ControlType, ControlPart, const tools::Rectangle&,
                                        ControlState, const ImplControlValue&, const OUString&,
                                        tools::Rectangle&, tools::Rectangle&) override;

    std::unique_ptr<QImage> m_image;
    QRect lastPopupRect;
diff --git a/vcl/unx/kde5/KDE5SalInstance.cxx b/vcl/unx/kde5/KDE5SalInstance.cxx
index 8198893..120bf40 100644
--- a/vcl/unx/kde5/KDE5SalInstance.cxx
+++ b/vcl/unx/kde5/KDE5SalInstance.cxx
@@ -34,7 +34,7 @@
using namespace com::sun::star;

KDE5SalInstance::KDE5SalInstance(SalYieldMutex* pMutex)
    :Qt5Instance( pMutex, true )
    : Qt5Instance(pMutex, true)
{
    ImplSVData* pSVData = ImplGetSVData();
    delete pSVData->maAppData.mpToolkitName;
@@ -43,21 +43,18 @@ KDE5SalInstance::KDE5SalInstance(SalYieldMutex* pMutex)
    KDE5SalData::initNWF();
}

SalFrame* KDE5SalInstance::CreateFrame( SalFrame *pParent, SalFrameStyleFlags nState )
SalFrame* KDE5SalInstance::CreateFrame(SalFrame* pParent, SalFrameStyleFlags nState)
{
    return new KDE5SalFrame( static_cast<KDE5SalFrame*>(pParent), nState, true );
    return new KDE5SalFrame(static_cast<KDE5SalFrame*>(pParent), nState, true);
}

uno::Reference< ui::dialogs::XFilePicker2 > KDE5SalInstance::createFilePicker(
    const uno::Reference< uno::XComponentContext >& xMSF )
uno::Reference<ui::dialogs::XFilePicker2>
KDE5SalInstance::createFilePicker(const uno::Reference<uno::XComponentContext>& xMSF)
{
    return SalInstance::createFilePicker( xMSF );
    return SalInstance::createFilePicker(xMSF);
}

bool KDE5SalInstance::IsMainThread() const
{
    return qApp->thread() == QThread::currentThread();
}
bool KDE5SalInstance::IsMainThread() const { return qApp->thread() == QThread::currentThread(); }

extern "C" {
VCLPLUG_KDE5_PUBLIC SalInstance* create_SalInstance()
diff --git a/vcl/unx/kde5/KDE5SalInstance.hxx b/vcl/unx/kde5/KDE5SalInstance.hxx
index e22426d..9afe49c 100644
--- a/vcl/unx/kde5/KDE5SalInstance.hxx
+++ b/vcl/unx/kde5/KDE5SalInstance.hxx
@@ -29,13 +29,12 @@ class KDE5SalInstance : public Qt5Instance
{
public:
    explicit KDE5SalInstance(SalYieldMutex* pMutex);
    virtual SalFrame* CreateFrame( SalFrame* pParent, SalFrameStyleFlags nStyle );
    virtual SalFrame* CreateFrame(SalFrame* pParent, SalFrameStyleFlags nStyle);

    virtual bool hasNativeFileSelection() const override { return true; }

    virtual css::uno::Reference< css::ui::dialogs::XFilePicker2 >
        createFilePicker( const css::uno::Reference<
                              css::uno::XComponentContext >& ) override;
    virtual css::uno::Reference<css::ui::dialogs::XFilePicker2>
    createFilePicker(const css::uno::Reference<css::uno::XComponentContext>&) override;

    virtual bool IsMainThread() const override;
};
diff --git a/vcl/unx/kde5/VCLKDE5Application.cxx b/vcl/unx/kde5/VCLKDE5Application.cxx
index 981a98a5..7ae9b5a 100644
--- a/vcl/unx/kde5/VCLKDE5Application.cxx
+++ b/vcl/unx/kde5/VCLKDE5Application.cxx
@@ -24,8 +24,8 @@

#include "KDE5SalDisplay.hxx"

VCLKDE5Application::VCLKDE5Application( int argc, char** argv) :
    QApplication( argc, argv)
VCLKDE5Application::VCLKDE5Application(int argc, char** argv)
    : QApplication(argc, argv)
{
}

@@ -43,7 +43,7 @@ void VCLKDE5Application::preDialogSetup()
    // (see the KDE VCL plug), then this won't happen.
    // We cannot simply release SolarMutex here, because the event loop started
    // by the file dialog would also call back to LO code.
    assert( QApplication::clipboard()->property( "useEventLoopWhenWaiting" ).toBool() );
    assert(QApplication::clipboard()->property("useEventLoopWhenWaiting").toBool());
}

// various hacks to be performed after a Qt dialog has been closed
@@ -67,9 +67,9 @@ void VCLKDE5Application::postDialogCleanup()
    // (it's a mystery why LO's clipboard handling has its own thread when whole LO can
    // get blocked by both trying to send and receive clipboard contents anyway).
    QClipboard* clipboard = QApplication::clipboard();
    if( clipboard->ownsSelection())
        clipboard->clear( QClipboard::Selection );
    if( clipboard->ownsClipboard())
    if (clipboard->ownsSelection())
        clipboard->clear(QClipboard::Selection);
    if (clipboard->ownsClipboard())
        clipboard->clear();
}

diff --git a/vcl/unx/kde5/VCLKDE5Application.hxx b/vcl/unx/kde5/VCLKDE5Application.hxx
index 1e4d1bc..6c6fb42 100644
--- a/vcl/unx/kde5/VCLKDE5Application.hxx
+++ b/vcl/unx/kde5/VCLKDE5Application.hxx
@@ -26,15 +26,14 @@
#include <QtCore/QAbstractNativeEventFilter>
#include <KConfigCore/kconfig.h>


#undef Region

class VCLKDE5Application : public QApplication, public QAbstractNativeEventFilter
{
    public:
        VCLKDE5Application( int argc, char** argv);
        static void preDialogSetup();
        static void postDialogCleanup();
public:
    VCLKDE5Application(int argc, char** argv);
    static void preDialogSetup();
    static void postDialogCleanup();
};

#endif
diff --git a/vcl/unx/kde5/tst_exclude_posted_events.hxx b/vcl/unx/kde5/tst_exclude_posted_events.hxx
index c07ca89..79c9887 100644
--- a/vcl/unx/kde5/tst_exclude_posted_events.hxx
+++ b/vcl/unx/kde5/tst_exclude_posted_events.hxx
@@ -26,42 +26,42 @@

const QEvent::Type eventType = QEvent::User;

class TestExcludePostedEvents
    : public QObject
class TestExcludePostedEvents : public QObject
{
    Q_OBJECT
    public:
        TestExcludePostedEvents();
        virtual bool event( QEvent* e ) override;
        bool processed;
public:
    TestExcludePostedEvents();
    virtual bool event(QEvent* e) override;
    bool processed;
};

TestExcludePostedEvents::TestExcludePostedEvents()
    : processed( false )
    : processed(false)
{
}

bool TestExcludePostedEvents::event( QEvent* e )
bool TestExcludePostedEvents::event(QEvent* e)
{
    if( e->type() == eventType )
    if (e->type() == eventType)
        processed = true;
    return QObject::event( e );
    return QObject::event(e);
}

#define QVERIFY(a) \
    if (!a) return 1;
#define QVERIFY(a)                                                                                 \
    if (!a)                                                                                        \
        return 1;

static int tst_excludePostedEvents()
{
    TestExcludePostedEvents test;
    QCoreApplication::postEvent( &test, new QEvent( eventType ));
    QCoreApplication::postEvent(&test, new QEvent(eventType));
    QEventLoop loop;
    loop.processEvents(QEventLoop::ExcludeUserInputEvents
        | QEventLoop::ExcludeSocketNotifiers
//        | QEventLoop::WaitForMoreEvents
        | QEventLoop::X11ExcludeTimers);
    QVERIFY( !test.processed );
                       | QEventLoop::ExcludeSocketNotifiers
                       //        | QEventLoop::WaitForMoreEvents
                       | QEventLoop::X11ExcludeTimers);
    QVERIFY(!test.processed);
    loop.processEvents();
    QVERIFY( test.processed );
    QVERIFY(test.processed);
    return 0;
}
diff --git a/vcl/unx/kde5/tst_exclude_socket_notifiers.hxx b/vcl/unx/kde5/tst_exclude_socket_notifiers.hxx
index d0acafe..7f4d2e3 100644
--- a/vcl/unx/kde5/tst_exclude_socket_notifiers.hxx
+++ b/vcl/unx/kde5/tst_exclude_socket_notifiers.hxx
@@ -26,55 +26,53 @@
#include <QtCore/QSocketNotifier>
#include <unistd.h>

class TestExcludeSocketNotifiers
    : public QObject
class TestExcludeSocketNotifiers : public QObject
{
    Q_OBJECT
    public:
        TestExcludeSocketNotifiers( const int* pipes );
        virtual ~TestExcludeSocketNotifiers() override;
        bool received;
    public slots:
        void slotReceived();
    private:
        const int* pipes;
public:
    TestExcludeSocketNotifiers(const int* pipes);
    virtual ~TestExcludeSocketNotifiers() override;
    bool received;
public slots:
    void slotReceived();

private:
    const int* pipes;
};

TestExcludeSocketNotifiers::TestExcludeSocketNotifiers( const int* thePipes )
    : received( false )
    , pipes( thePipes )
TestExcludeSocketNotifiers::TestExcludeSocketNotifiers(const int* thePipes)
    : received(false)
    , pipes(thePipes)
{
}

TestExcludeSocketNotifiers::~TestExcludeSocketNotifiers()
{
    close( pipes[ 0 ] );
    close( pipes[ 1 ] );
    close(pipes[0]);
    close(pipes[1]);
}

void TestExcludeSocketNotifiers::slotReceived()
{
    received = true;
}
void TestExcludeSocketNotifiers::slotReceived() { received = true; }

#define QVERIFY(a) \
    if (!a) return 1;
#define QVERIFY(a)                                                                                 \
    if (!a)                                                                                        \
        return 1;

static int tst_processEventsExcludeSocket()
{
    int pipes[ 2 ];
    if( pipe( pipes ) < 0 )
    int pipes[2];
    if (pipe(pipes) < 0)
        return 1;
    TestExcludeSocketNotifiers test( pipes );
    QSocketNotifier notifier( pipes[ 0 ], QSocketNotifier::Read );
    QObject::connect( &notifier, SIGNAL( activated( int )), &test, SLOT( slotReceived()));
    TestExcludeSocketNotifiers test(pipes);
    QSocketNotifier notifier(pipes[0], QSocketNotifier::Read);
    QObject::connect(&notifier, SIGNAL(activated(int)), &test, SLOT(slotReceived()));
    char dummy = 'a';
    if( 1 != write( pipes[ 1 ], &dummy, 1 ) )
    if (1 != write(pipes[1], &dummy, 1))
        return 1;
    QEventLoop loop;
    loop.processEvents( QEventLoop::ExcludeSocketNotifiers );
    QVERIFY( !test.received );
    loop.processEvents(QEventLoop::ExcludeSocketNotifiers);
    QVERIFY(!test.received);
    loop.processEvents();
    QVERIFY( test.received );
    QVERIFY(test.received);
    return 0;
}