LMMS
Loading...
Searching...
No Matches
embed.h
Go to the documentation of this file.
1/*
2 * embed.h - misc. stuff for using embedded data (resources linked into binary)
3 *
4 * Copyright (c) 2004-2009 Tobias Doerffel <tobydox/at/users.sourceforge.net>
5 *
6 * This file is part of LMMS - https://lmms.io
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program (see COPYING); if not, write to the
20 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301 USA.
22 *
23 */
24
25#ifndef LMMS_EMBED_H
26#define LMMS_EMBED_H
27
28#include <string>
29#include <string_view>
30
31#include <QPixmap>
32#include <QString>
33
34#include "lmms_export.h"
35#ifdef PLUGIN_NAME
36#include "LmmsCommonMacros.h"
37#endif
38
39namespace lmms {
40
41namespace embed {
42
52auto LMMS_EXPORT getIconPixmap(std::string_view name,
53 int width = -1, int height = -1, const char* const* xpm = nullptr) -> QPixmap;
54auto LMMS_EXPORT getText(std::string_view name) -> QString;
55
61inline auto logicalSize(const QPixmap& pixmap) noexcept
62{
63#if QT_VERSION >= QT_VERSION_CHECK(6, 2, 0)
64 return pixmap.deviceIndependentSize().toSize();
65#else
66 return pixmap.isNull() ? QSize(0, 0) : pixmap.size() / pixmap.devicePixelRatio();
67#endif
68}
69
70} // namespace embed
71
73{
74public:
75 PixmapLoader() = default;
76
77 explicit PixmapLoader(std::string name, const char* const* xpm = nullptr) :
78 m_name{std::move(name)},
79 m_xpm{xpm}
80 { }
81
82 virtual ~PixmapLoader() = default;
83
84 auto pixmap(int width = -1, int height = -1) const -> QPixmap
85 {
87 }
88
89 auto pixmapName() const -> const std::string& { return m_name; }
90
91private:
92 std::string m_name;
93 const char* const* m_xpm = nullptr;
94};
95
96#ifdef PLUGIN_NAME
97
98class PluginPixmapLoader : public PixmapLoader
99{
100public:
101 PluginPixmapLoader() = default;
102
103 explicit PluginPixmapLoader(std::string name, const char* const* xpm = nullptr) :
105 { }
106};
107
108namespace PLUGIN_NAME {
109
110inline auto getIconPixmap(std::string_view name,
111 int width = -1, int height = -1, const char* const* xpm = nullptr) -> QPixmap
112{
113 return PluginPixmapLoader{std::string{name}, xpm}.pixmap(width, height);
114}
115
116} // namespace PLUGIN_NAME
117
118#endif // PLUGIN_NAME
119
120} // namespace lmms
121
122#endif // LMMS_EMBED_H
#define LMMS_STRINGIFY(s)
Definition LmmsCommonMacros.h:31
Definition embed.h:73
std::string m_name
Definition embed.h:92
PixmapLoader()=default
virtual ~PixmapLoader()=default
auto pixmap(int width=-1, int height=-1) const -> QPixmap
Definition embed.h:84
PixmapLoader(std::string name, const char *const *xpm=nullptr)
Definition embed.h:77
const char *const * m_xpm
Definition embed.h:93
auto pixmapName() const -> const std::string &
Definition embed.h:89
static const char * name
Definition pugl.h:1582
static int int height
Definition pugl.h:1594
static int width
Definition pugl.h:1593
#define PLUGIN_NAME(name)
Definition lilv_test.c:189
Definition embed.cpp:36
auto getText(std::string_view name) -> QString
Definition embed.cpp:125
auto logicalSize(const QPixmap &pixmap) noexcept
Temporary shim for QPixmap::deviceIndependentSize.
Definition embed.h:61
auto getIconPixmap(std::string_view name, int width, int height, const char *const *xpm) -> QPixmap
Definition embed.cpp:107
Definition AudioAlsa.cpp:35
Definition juce_Uuid.h:141
#define const
Definition zconf.h:137