include/vcl/qt/QtUtils.hxx   |   21 ++++++++++++++++++---
 vcl/qt5/QtInstanceImage.cxx  |    4 ++--
 vcl/qt5/QtInstanceWidget.cxx |   10 +++++++++-
 3 files changed, 29 insertions(+), 6 deletions(-)

New commits:
commit e8e0a676b31596ce0d1fee7936ff934dfc9e3c09
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Fri Oct 25 22:19:26 2024 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Sat Oct 26 13:13:22 2024 +0200

    tdf#130857 qt weld: Implement QtInstanceImage::set_image
    
    Extract a helper to convert a BitmapEx to a QPixmap
    from the existing helper function `loadQPixmapIcon`
    and add a new helper that converts a
    css::uno::Reference<css::graphic::XGraphic>& to
    a QPixmap reusing most of the code.
    
    Use that to implement the QtInstanceImage::set_image
    variant with that parameter type.
    
    With this in place, opening the "Help" -> "About LibreOfficeDev"
    dialog in a WIP branch adding "cui/ui/aboutdialog.ui" to the list
    of .ui files in QtInstanceBuilder::IsUIFileSupported now opens
    the dialog with brand image and LibreOffice Community logo present,
    but other aspects in that dialog still need attention before
    enabling this by default.
    
    Change-Id: Ide28c0dc126be511ec8e34e57f4f1df7e70297ca
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175666
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/include/vcl/qt/QtUtils.hxx b/include/vcl/qt/QtUtils.hxx
index a2e5c2eedab6..95f31e97ce63 100644
--- a/include/vcl/qt/QtUtils.hxx
+++ b/include/vcl/qt/QtUtils.hxx
@@ -20,6 +20,7 @@
 
 #include <rtl/ustring.hxx>
 #include <vcl/filter/PngImageWriter.hxx>
+#include <vcl/image.hxx>
 
 #include <QtCore/QString>
 #include <QtGui/QPixmap>
@@ -29,12 +30,11 @@ inline QString toQString(const OUString& rStr)
     return QString::fromUtf16(rStr.getStr(), rStr.getLength());
 }
 
-inline QPixmap loadQPixmapIcon(const OUString& rIconName)
+inline QPixmap toQPixmap(const BitmapEx& rBitmapEx)
 {
-    BitmapEx aIcon(rIconName);
     SvMemoryStream aMemoryStream;
     vcl::PngImageWriter aWriter(aMemoryStream);
-    aWriter.write(aIcon);
+    aWriter.write(rBitmapEx);
     QPixmap aPixmap;
     aPixmap.loadFromData(static_cast<const uchar*>(aMemoryStream.GetData()),
                          aMemoryStream.TellEnd());
@@ -42,4 +42,19 @@ inline QPixmap loadQPixmapIcon(const OUString& rIconName)
     return aPixmap;
 }
 
+inline QPixmap toQPixmap(const css::uno::Reference<css::graphic::XGraphic>& 
rImage)
+{
+    if (!rImage.is())
+        return QPixmap();
+
+    Image aImage(rImage);
+    return toQPixmap(aImage.GetBitmapEx());
+}
+
+inline QPixmap loadQPixmapIcon(const OUString& rIconName)
+{
+    BitmapEx aIcon(rIconName);
+    return toQPixmap(aIcon);
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/qt5/QtInstanceImage.cxx b/vcl/qt5/QtInstanceImage.cxx
index d41fa077e4c2..ce63b3b03e50 100644
--- a/vcl/qt5/QtInstanceImage.cxx
+++ b/vcl/qt5/QtInstanceImage.cxx
@@ -25,9 +25,9 @@ void QtInstanceImage::set_from_icon_name(const OUString&)
 
 void QtInstanceImage::set_image(VirtualDevice*) { assert(false && "Not 
implemented yet"); }
 
-void QtInstanceImage::set_image(const 
css::uno::Reference<css::graphic::XGraphic>&)
+void QtInstanceImage::set_image(const 
css::uno::Reference<css::graphic::XGraphic>& rGraphic)
 {
-    assert(false && "Not implemented yet");
+    m_pLabel->setPixmap(toQPixmap(rGraphic));
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 6a7e1abd100d3aad2d23c96e835e182d191b505d
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Fri Oct 25 21:50:30 2024 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Sat Oct 26 13:12:48 2024 +0200

    tdf#130857 qt weld: Implement QtInstanceWidget::get_preferred_size
    
    Implement QtInstanceWidget::get_preferred_size by returning the
    size of the QWidget::sizeHint property [1]:
    
    > This property holds the recommended size for the widget
    
    With this in place, opening the "Help" -> "About LibreOfficeDev"
    dialog in a WIP branch adding "cui/ui/aboutdialog.ui" to the list
    of .ui files in QtInstanceBuilder::IsUIFileSupported now triggers
    the assert in QtInstanceImage::set_image because that's no implemented
    yet, while this was not reached at all before, because
    
        const tools::Long 
nWidth(m_pCopyrightLabel->get_preferred_size().getWidth());
    
    at the beginning of AboutDialog::AboutDialog would previously
    set a preferred width of 0, and with that, there was no attempt to
    set the images at all.
    
    [1] https://doc.qt.io/qt-6/qwidget.html#sizeHint-prop
    
    Change-Id: I6eaedf07f73ea5e71a36d3e9bc9a0f55e515ffe7
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175665
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>
    Tested-by: Jenkins

diff --git a/vcl/qt5/QtInstanceWidget.cxx b/vcl/qt5/QtInstanceWidget.cxx
index b8145469f7fb..5f3590bd88d9 100644
--- a/vcl/qt5/QtInstanceWidget.cxx
+++ b/vcl/qt5/QtInstanceWidget.cxx
@@ -187,7 +187,15 @@ void QtInstanceWidget::set_size_request(int, int) {}
 
 Size QtInstanceWidget::get_size_request() const { return Size(); }
 
-Size QtInstanceWidget::get_preferred_size() const { return Size(); }
+Size QtInstanceWidget::get_preferred_size() const
+{
+    SolarMutexGuard g;
+
+    Size aPreferredSize;
+    GetQtInstance().RunInMainThread([&] { aPreferredSize = 
toSize(m_pWidget->sizeHint()); });
+
+    return aPreferredSize;
+}
 
 float QtInstanceWidget::get_approximate_digit_width() const { return 1.0; }
 

Reply via email to