diff options
author | Michael Weghorn <m.weghorn@posteo.de> | 2024-10-23 23:21:23 +0200 |
---|---|---|
committer | Michael Weghorn <m.weghorn@posteo.de> | 2024-10-24 09:10:00 +0200 |
commit | 2386540edfb015632ad5771ed048aa4bead315f8 (patch) | |
tree | e1155021e19b6485f7efbee382250cf9f03e784d | |
parent | 0fe7b3cebc1a070b13b825635f4bd387a22e41ab (diff) |
tdf#130857 qt: Move pixmap helper to new include/vcl/qt/QtUtils.hxx
Introduce include/vcl/qt/QtUtils.hxx as a new header
for Qt-specific utility functions that can be used
in multiple modules, e.g. avmedia and the Qt VCL
plugins in vcl.
This is meant to be used only by code that already
links in Qt.
There's already vcl/inc/qt{5,6}/QtTools.hxx for
helpers needed in vcl only.
Initially, add a `loadQPixmapIcon` helper function
that can be used to retrieve a QPixmap for an icon name
and is extracted from QtPlayer::createMediaPlayerWidget
in avmedia.
It will be reused to implement the
QtInstanceButton::set_from_icon_name logic in an upcoming
commit.
Change-Id: I9f25aa5ca8f00da97d06ecdd164a8fae10e492dd
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175524
Tested-by: Jenkins
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
-rw-r--r-- | avmedia/source/qt6/QtPlayer.cxx | 11 | ||||
-rw-r--r-- | include/vcl/qt/QtUtils.hxx | 39 |
2 files changed, 41 insertions, 9 deletions
diff --git a/avmedia/source/qt6/QtPlayer.cxx b/avmedia/source/qt6/QtPlayer.cxx index 5cd19a3c2df5..fe2cf7fc4d76 100644 --- a/avmedia/source/qt6/QtPlayer.cxx +++ b/avmedia/source/qt6/QtPlayer.cxx @@ -21,8 +21,8 @@ #include <rtl/string.hxx> #include <tools/link.hxx> #include <vcl/BitmapTools.hxx> -#include <vcl/filter/PngImageWriter.hxx> #include <vcl/graph.hxx> +#include <vcl/qt/QtUtils.hxx> #include <vcl/svapp.hxx> #include <vcl/syschild.hxx> #include <vcl/sysdata.hxx> @@ -351,14 +351,7 @@ void QtPlayer::createMediaPlayerWidget() } else { - BitmapEx aPlaceholderIcon(u"avmedia/res/avaudiologo.png"_ustr); - SvMemoryStream aMemoryStream; - vcl::PngImageWriter aWriter(aMemoryStream); - aWriter.write(aPlaceholderIcon); - QPixmap aAudioPixmap; - aAudioPixmap.loadFromData(static_cast<const uchar*>(aMemoryStream.GetData()), - aMemoryStream.TellEnd()); - assert(!aAudioPixmap.isNull() && "Failed to load audio logo"); + QPixmap aAudioPixmap = loadQPixmapIcon(u"avmedia/res/avaudiologo.png"_ustr); aAudioPixmap = aAudioPixmap.scaled(QSize(m_aPlayerWidgetRect.Width, m_aPlayerWidgetRect.Height)); diff --git a/include/vcl/qt/QtUtils.hxx b/include/vcl/qt/QtUtils.hxx new file mode 100644 index 000000000000..aa0f4f765cf9 --- /dev/null +++ b/include/vcl/qt/QtUtils.hxx @@ -0,0 +1,39 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#pragma once + +/** + * Utilities/helpers for use in Qt-specific LO code used in multiple modules + * (e.g. avmedia and vcl). + * + * Helpers only needed in a specific module should be defined + * in that module instead, e.g. helper functions only relevant for the Qt-based + * VCL plugins are defined in `vcl/inc/qt5/QtTools.hxx`. + **/ + +#include <rtl/ustring.hxx> +#include <vcl/filter/PngImageWriter.hxx> + +#include <QtGui/QPixmap> + +QPixmap loadQPixmapIcon(const OUString& rIconName) +{ + BitmapEx aIcon(rIconName); + SvMemoryStream aMemoryStream; + vcl::PngImageWriter aWriter(aMemoryStream); + aWriter.write(aIcon); + QPixmap aPixmap; + aPixmap.loadFromData(static_cast<const uchar*>(aMemoryStream.GetData()), + aMemoryStream.TellEnd()); + assert(!aPixmap.isNull() && "Failed to create icon pixmap"); + return aPixmap; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |