[Libreoffice-commits] core.git: vcl/inc vcl/qt5
Jan-Marek Glogowski (via logerrit)
logerrit at kemper.freedesktop.org
Tue May 7 15:43:13 UTC 2019
vcl/inc/qt5/Qt5Menu.hxx | 2 +
vcl/inc/qt5/Qt5Tools.hxx | 5 +++
vcl/qt5/Qt5Menu.cxx | 74 +++++++++++++++++++++++++++++++++--------------
vcl/qt5/Qt5Tools.cxx | 20 ++++++++++++
4 files changed, 80 insertions(+), 21 deletions(-)
New commits:
commit 8ea988f585db72da88994d29d006f1976007789d
Author: Jan-Marek Glogowski <glogow at fbihome.de>
AuthorDate: Sat May 4 00:03:15 2019 +0000
Commit: Jan-Marek Glogowski <glogow at fbihome.de>
CommitDate: Tue May 7 17:42:32 2019 +0200
tdf#123549 Qt5 implement Qt5Menu::ShowCloseButton
This includes some not-so-nice lifetime handling of the button
"clicked" connection handling. I decided to keep the code in
one place, simply always forcing a disconnect on show, instead
of a more "optimized" code version in SetFrame.
First we try to get the icon from the system theme, but use LO's
own icon theme as a fallback.
Change-Id: Ic0459623ec907b9a54bef4670bf65cf587cd47ea
Reviewed-on: https://gerrit.libreoffice.org/71784
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Jan-Marek Glogowski <glogow at fbihome.de>
diff --git a/vcl/inc/qt5/Qt5Menu.hxx b/vcl/inc/qt5/Qt5Menu.hxx
index f3807abb0bf6..76d865b263ff 100644
--- a/vcl/inc/qt5/Qt5Menu.hxx
+++ b/vcl/inc/qt5/Qt5Menu.hxx
@@ -67,6 +67,7 @@ public:
virtual void SetAccelerator(unsigned nPos, SalMenuItem* pSalMenuItem,
const vcl::KeyCode& rKeyCode, const OUString& rKeyName) override;
virtual void GetSystemMenuData(SystemMenuData* pData) override;
+ virtual void ShowCloseButton(bool bShow) override;
void SetMenu(Menu* pMenu) { mpVCLMenu = pMenu; }
Menu* GetMenu() { return mpVCLMenu; }
@@ -77,6 +78,7 @@ private slots:
static void slotMenuTriggered(Qt5MenuItem* pQItem);
static void slotMenuAboutToShow(Qt5MenuItem* pQItem);
static void slotMenuAboutToHide(Qt5MenuItem* pQItem);
+ void slotCloseDocument();
};
class Qt5MenuItem : public SalMenuItem
diff --git a/vcl/inc/qt5/Qt5Tools.hxx b/vcl/inc/qt5/Qt5Tools.hxx
index 8863e2496687..6b1fb1adcc7e 100644
--- a/vcl/inc/qt5/Qt5Tools.hxx
+++ b/vcl/inc/qt5/Qt5Tools.hxx
@@ -34,6 +34,9 @@
#include <memory>
+class Image;
+class QImage;
+
inline OUString toOUString(const QString& s)
{
// QString stores UTF16, just like OUString
@@ -136,4 +139,6 @@ typedef std::unique_ptr<cairo_surface_t, CairoDeleter> UniqueCairoSurface;
sal_uInt16 GetKeyModCode(Qt::KeyboardModifiers eKeyModifiers);
sal_uInt16 GetMouseModCode(Qt::MouseButtons eButtons);
+QImage toQImage(const Image& rImage);
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/qt5/Qt5Menu.cxx b/vcl/qt5/Qt5Menu.cxx
index d119c71010b9..5bfaefa9b931 100644
--- a/vcl/qt5/Qt5Menu.cxx
+++ b/vcl/qt5/Qt5Menu.cxx
@@ -7,19 +7,21 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
-#include <Qt5Frame.hxx>
-#include <Qt5MainWindow.hxx>
-#include <Qt5Bitmap.hxx>
#include <Qt5Menu.hxx>
#include <Qt5Menu.moc>
+
+#include <Qt5Frame.hxx>
#include <Qt5Instance.hxx>
+#include <Qt5MainWindow.hxx>
-#include <QtWidgets/QtWidgets>
+#include <QtWidgets/QMenuBar>
+#include <QtWidgets/QPushButton>
#include <vcl/svapp.hxx>
#include <sal/log.hxx>
-#include <vcl/pngwrite.hxx>
-#include <tools/stream.hxx>
+
+#include <strings.hrc>
+#include <bitmaps.hlst>
Qt5Menu::Qt5Menu(bool bMenuBar)
: mpVCLMenu(nullptr)
@@ -421,6 +423,7 @@ void Qt5Menu::DoFullMenuUpdate(Menu* pMenuBar)
{
// clear action groups since menu is rebuilt
ResetAllActionGroups();
+ ShowCloseButton(false);
for (sal_Int32 nItem = 0; nItem < static_cast<sal_Int32>(GetItemCount()); nItem++)
{
@@ -507,21 +510,7 @@ void Qt5Menu::SetItemImage(unsigned, SalMenuItem* pItem, const Image& rImage)
if (!pAction)
return;
- QImage aImage;
-
- if (!!rImage)
- {
- SvMemoryStream aMemStm;
- vcl::PNGWriter aWriter(rImage.GetBitmapEx());
- aWriter.Write(aMemStm);
-
- if (!aImage.loadFromData(static_cast<const uchar*>(aMemStm.GetData()), aMemStm.TellEnd()))
- {
- return;
- }
- }
-
- pAction->setIcon(QPixmap::fromImage(aImage));
+ pAction->setIcon(QPixmap::fromImage(toQImage(rImage)));
}
void Qt5Menu::SetAccelerator(unsigned, SalMenuItem* pItem, const vcl::KeyCode&,
@@ -607,6 +596,49 @@ void Qt5Menu::NativeItemText(OUString& rItemText)
rItemText = rItemText.replace('~', '&');
}
+void Qt5Menu::slotCloseDocument()
+{
+ MenuBar* pVclMenuBar = static_cast<MenuBar*>(mpVCLMenu.get());
+ if (pVclMenuBar)
+ Application::PostUserEvent(pVclMenuBar->GetCloseButtonClickHdl());
+}
+
+void Qt5Menu::ShowCloseButton(bool bShow)
+{
+ if (!mpQMenuBar)
+ return;
+
+ QPushButton* pButton = static_cast<QPushButton*>(mpQMenuBar->cornerWidget(Qt::TopRightCorner));
+ if (!pButton)
+ {
+ QIcon aIcon;
+ if (QIcon::hasThemeIcon("window-close-symbolic"))
+ aIcon = QIcon::fromTheme("window-close-symbolic");
+ else
+ aIcon = QIcon(
+ QPixmap::fromImage((toQImage(Image(StockImage::Yes, SV_RESID_BITMAP_CLOSEDOC)))));
+ pButton = new QPushButton(mpQMenuBar);
+ pButton->setIcon(aIcon);
+ pButton->setFlat(true);
+ pButton->setToolTip(toQString(VclResId(SV_HELPTEXT_CLOSEDOCUMENT)));
+ mpQMenuBar->setCornerWidget(pButton, Qt::TopRightCorner);
+ }
+
+ if (bShow)
+ {
+ // The mpQMenuBar is used in multiple Qt5Menu. If one Qt5Menu is deleted, the clicked button
+ // connection is severed. The reconnect could be handled in SetFrame, but ShowCloseButton is
+ // called so seldomly, that I decided to keep the reconnect in this function in one place. As
+ // we don't know the connection state, we unconditionally remove it, so slotCloseDocument
+ // isn't called multiple times on click.
+ pButton->disconnect(SIGNAL(clicked(bool)));
+ connect(pButton, &QPushButton::clicked, this, &Qt5Menu::slotCloseDocument);
+ pButton->show();
+ }
+ else
+ pButton->hide();
+}
+
Qt5MenuItem::Qt5MenuItem(const SalItemParams* pItemData)
: mpParentMenu(nullptr)
, mpSubMenu(nullptr)
diff --git a/vcl/qt5/Qt5Tools.cxx b/vcl/qt5/Qt5Tools.cxx
index 94bb03d1797f..cff661ba8a34 100644
--- a/vcl/qt5/Qt5Tools.cxx
+++ b/vcl/qt5/Qt5Tools.cxx
@@ -21,7 +21,12 @@
#include <cairo.h>
+#include <tools/stream.hxx>
#include <vcl/event.hxx>
+#include <vcl/image.hxx>
+#include <vcl/pngwrite.hxx>
+
+#include <QtGui/QImage>
void CairoDeleter::operator()(cairo_surface_t* pSurface) const { cairo_surface_destroy(pSurface); }
@@ -89,4 +94,19 @@ Qt::DropAction getPreferredDropAction(sal_Int8 dragOperation)
return eAct;
}
+QImage toQImage(const Image& rImage)
+{
+ QImage aImage;
+
+ if (!!rImage)
+ {
+ SvMemoryStream aMemStm;
+ vcl::PNGWriter aWriter(rImage.GetBitmapEx());
+ aWriter.Write(aMemStm);
+ aImage.loadFromData(static_cast<const uchar*>(aMemStm.GetData()), aMemStm.TellEnd());
+ }
+
+ return aImage;
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
More information about the Libreoffice-commits
mailing list