TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musicsinglemanager.h
Go to the documentation of this file.
1 #ifndef MUSICSINGLEMANAGER_H
2 #define MUSICSINGLEMANAGER_H
3 
4 /***************************************************************************
5  * This file is part of the TTK Music Player project
6  * Copyright (C) 2015 - 2024 Greedysky Studio
7 
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (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
16  * GNU General Public License for more details.
17 
18  * You should have received a copy of the GNU General Public License along
19  * with this program; If not, see <http://www.gnu.org/licenses/>.
20  ***************************************************************************/
21 
22 #include <QMap>
23 #include "ttksingleton.h"
24 #include "musicwidgetutils.h"
25 
26 #define __SingleWidget__1(name) \
27  __SingleWidget__2(name, MusicApplication::instance())
28 
29 #define __SingleWidget__2(name, widget) \
30  [](QWidget *parent) \
31  { \
32  MusicSingleManager *manager = G_SINGLE_MANAGER_PTR; \
33  if(!manager->contains(#name)) \
34  { \
35  manager->appendObject(#name, new name(parent)); \
36  } \
37  name *w = TTKObjectCast(name*, manager->object(#name)); \
38  TTK::Widget::adjustWidgetPosition(w); \
39  w->raise(); \
40  w->show(); \
41  return w; \
42  }(widget)
43 
44 // marco generate single widget
45 #ifndef Q_CC_MSVC
46 # define TTKGenerateSingleWidget(...) TTK_PP_OVERLOAD(__SingleWidget__, __VA_ARGS__)(__VA_ARGS__)
47 #else
48 # define TTKGenerateSingleWidget(...) TTK_PP_CAT(TTK_PP_OVERLOAD(__SingleWidget__, __VA_ARGS__)(__VA_ARGS__), TTK_PP_EMPTY())
49 #endif
50 
51 #define TTKRemoveSingleWidget(name) G_SINGLE_MANAGER_PTR->removeObject(name);
52 
53 
58 {
60 public:
64  void appendObject(const QString &name, QObject *object);
68  void removeObject(const QString &name);
72  QObject *object(const QString &name);
76  bool contains(const QString &name) const;
77 
78 private:
82  MusicSingleManager() = default;
83 
84  QMap<QString, QObject*> m_parameter;
85 
87 
88 };
89 
90 #define G_SINGLE_MANAGER_PTR makeMusicSingleManager()
92 
93 #endif // MUSICSINGLEMANAGER_H
#define TTK_MODULE_EXPORT
QMap< QString, QObject * > m_parameter
The class of the single object manager.
TTK_MODULE_EXPORT MusicSingleManager * makeMusicSingleManager()
const char * name
Definition: http_parser.c:458
#define TTK_DECLARE_SINGLETON_CLASS(Class)
// Singleton Macro // //
Definition: ttksingleton.h:86
#define TTK_DECLARE_MODULE(Class)
Definition: ttkqtglobal.h:152