MythTV  master
mythpainter.h
Go to the documentation of this file.
1 #ifndef MYTHPAINTER_H_
2 #define MYTHPAINTER_H_
3 
4 #include <QMap>
5 #include <QString>
6 #include <QTextLayout>
7 #include <QWidget>
8 #include <QPaintDevice>
9 #include <QMutex>
10 #include <QSet>
11 
12 class QRect;
13 class QRegion;
14 class QPoint;
15 class QColor;
16 
17 #include "mythuiexp.h"
18 
19 #include <list>
20 
21 #ifdef _MSC_VER
22 # include <cstdint> // int64_t
23 #endif
24 
25 class MythFontProperties;
26 class MythImage;
27 class UIEffects;
28 
29 using LayoutVector = QVector<QTextLayout *>;
30 using FormatVector = QVector<QTextLayout::FormatRange>;
31 
32 class MUI_PUBLIC MythPainter : public QObject
33 {
34  Q_OBJECT
35 
36  public:
37  MythPainter();
45  virtual ~MythPainter() = default;
46 
47  virtual QString GetName(void) = 0;
48  virtual bool SupportsAnimation(void) = 0;
49  virtual bool SupportsAlpha(void) = 0;
50  virtual bool SupportsClipping(void) = 0;
51  virtual void FreeResources(void) { }
52  virtual void Begin(QPaintDevice *parent) { m_parent = parent; }
53  virtual void End() { m_parent = nullptr; }
54 
55  virtual void SetClipRect(const QRect &clipRect);
56  virtual void SetClipRegion(const QRegion &clipRegion);
57  virtual void Clear(QPaintDevice *device, const QRegion &region);
58 
59  QPaintDevice *GetParent(void) { return m_parent; }
60 
61  virtual void DrawImage(const QRect &dest, MythImage *im, const QRect &src,
62  int alpha) = 0;
63 
64  void DrawImage(int x, int y, MythImage *im, int alpha);
65  void DrawImage(const QPoint &topLeft, MythImage *im, int alph);
66 
67  virtual void DrawText(const QRect &r, const QString &msg, int flags,
68  const MythFontProperties &font, int alpha,
69  const QRect &boundRect);
70  virtual void DrawTextLayout(const QRect &canvasRect,
71  const LayoutVector & layouts,
72  const FormatVector & formats,
73  const MythFontProperties &font, int alpha,
74  const QRect &destRect);
75  virtual void DrawRect(const QRect &area, const QBrush &fillBrush,
76  const QPen &linePen, int alpha);
77  virtual void DrawRoundRect(const QRect &area, int cornerRadius,
78  const QBrush &fillBrush, const QPen &linePen,
79  int alpha);
80  virtual void DrawEllipse(const QRect &area, const QBrush &fillBrush,
81  const QPen &linePen, int alpha);
82 
83  virtual void PushTransformation(const UIEffects &zoom, QPointF center = QPointF());
84  virtual void PopTransformation(void) { }
85 
89  MythImage *GetFormatImage();
90  void DeleteFormatImage(MythImage *im);
91 
92  void SetDebugMode(bool showBorders, bool showNames)
93  {
94  m_showBorders = showBorders;
95  m_showNames = showNames;
96  }
97 
98  bool ShowBorders(void) const { return m_showBorders; }
99  bool ShowTypeNames(void) const { return m_showNames; }
100 
101  void SetMaximumCacheSizes(int hardware, int software);
102 
103  protected:
104  static void DrawTextPriv(MythImage *im, const QString &msg, int flags,
105  const QRect &r, const MythFontProperties &font);
106  static void DrawRectPriv(MythImage *im, const QRect &area, int radius, int ellipse,
107  const QBrush &fillBrush, const QPen &linePen);
108 
109  MythImage *GetImageFromString(const QString &msg, int flags, const QRect &r,
110  const MythFontProperties &font);
111  MythImage *GetImageFromTextLayout(const LayoutVector & layouts,
112  const FormatVector & formats,
113  const MythFontProperties &font,
114  QRect &canvas, QRect &dest);
115  MythImage *GetImageFromRect(const QRect &area, int radius, int ellipse,
116  const QBrush &fillBrush,
117  const QPen &linePen);
118 
120  virtual MythImage* GetFormatImagePriv(void) = 0;
121  virtual void DeleteFormatImagePriv(MythImage *im) = 0;
122  void ExpireImages(int64_t max = 0);
123 
124  // This needs to be called by classes inheriting from MythPainter
125  // in the destructor.
126  virtual void Teardown(void);
127 
128  void CheckFormatImage(MythImage *im);
129 
130  QPaintDevice *m_parent {nullptr};
131  int m_hardwareCacheSize {0};
132  int m_maxHardwareCacheSize {0};
133 
134  private:
135  int64_t m_softwareCacheSize {0};
136  int64_t m_maxSoftwareCacheSize {1024 * 1024 * 48};
137 
139  QSet<MythImage*> m_allocatedImages;
140 
141  QMap<QString, MythImage *> m_stringToImageMap;
142  std::list<QString> m_stringExpireList;
143 
144  bool m_showBorders {false};
145  bool m_showNames {false};
146 };
147 
148 #endif
MythPainter::m_allocatedImages
QSet< MythImage * > m_allocatedImages
Definition: mythpainter.h:139
FormatVector
QVector< QTextLayout::FormatRange > FormatVector
Definition: mythpainter.h:30
build_compdb.dest
dest
Definition: build_compdb.py:9
MUI_PUBLIC
#define MUI_PUBLIC
Definition: mythuiexp.h:9
MythPainter::m_allocationLock
QMutex m_allocationLock
Definition: mythpainter.h:138
MythPainter::m_stringExpireList
std::list< QString > m_stringExpireList
Definition: mythpainter.h:142
formats
const char * formats[8]
Definition: vbilut.cpp:188
MythPainter::m_stringToImageMap
QMap< QString, MythImage * > m_stringToImageMap
Definition: mythpainter.h:141
MythPainter::GetParent
QPaintDevice * GetParent(void)
Definition: mythpainter.h:59
MythFontProperties
Definition: mythfontproperties.h:13
MythPainter::FreeResources
virtual void FreeResources(void)
Definition: mythpainter.h:51
MythPainter::End
virtual void End()
Definition: mythpainter.h:53
MythPainter::ShowBorders
bool ShowBorders(void) const
Definition: mythpainter.h:98
MythPainter::ShowTypeNames
bool ShowTypeNames(void) const
Definition: mythpainter.h:99
MythPainter::SetDebugMode
void SetDebugMode(bool showBorders, bool showNames)
Definition: mythpainter.h:92
Clear
#define Clear(a)
Definition: audiooutputopensles.cpp:49
LayoutVector
QVector< QTextLayout * > LayoutVector
Definition: mythpainter.h:29
MythPainter
Definition: mythpainter.h:32
MythImage
Definition: mythimage.h:36
MythPainter::Begin
virtual void Begin(QPaintDevice *parent)
Definition: mythpainter.h:52
UIEffects
Definition: mythuianimation.h:9
MythPainter::PopTransformation
virtual void PopTransformation(void)
Definition: mythpainter.h:84
mythuiexp.h