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  ~MythPainter() override = 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*/) { }
53  virtual void End() { }
54 
55  virtual void SetClipRect(QRect clipRect);
56  virtual void SetClipRegion(const QRegion &clipRegion);
57  virtual void Clear(QPaintDevice *device, const QRegion &region);
58 
59  virtual void DrawImage(QRect dest, MythImage *im, QRect src, int alpha) = 0;
60 
61  void DrawImage(int x, int y, MythImage *im, int alpha);
62  void DrawImage(QPoint topLeft, MythImage *im, int alph);
63 
64  virtual void DrawText(QRect r, const QString &msg, int flags,
65  const MythFontProperties &font, int alpha,
66  QRect boundRect);
67  virtual void DrawTextLayout(QRect canvasRect,
68  const LayoutVector & layouts,
69  const FormatVector & formats,
70  const MythFontProperties &font, int alpha,
71  QRect destRect);
72  virtual void DrawRect(QRect area, const QBrush &fillBrush,
73  const QPen &linePen, int alpha);
74  virtual void DrawRoundRect(QRect area, int cornerRadius,
75  const QBrush &fillBrush, const QPen &linePen,
76  int alpha);
77  virtual void DrawEllipse(QRect area, const QBrush &fillBrush,
78  const QPen &linePen, int alpha);
79 
80  virtual void PushTransformation(const UIEffects &zoom, QPointF center = QPointF());
81  virtual void PopTransformation(void) { }
82 
86  MythImage *GetFormatImage();
87  void DeleteFormatImage(MythImage *im);
88 
89  void SetDebugMode(bool showBorders, bool showNames)
90  {
91  m_showBorders = showBorders;
92  m_showNames = showNames;
93  }
94 
95  bool ShowBorders(void) const { return m_showBorders; }
96  bool ShowTypeNames(void) const { return m_showNames; }
97 
98  void SetMaximumCacheSizes(int hardware, int software);
99 
100  protected:
101  static void DrawTextPriv(MythImage *im, const QString &msg, int flags,
102  QRect r, const MythFontProperties &font);
103  static void DrawRectPriv(MythImage *im, QRect area, int radius, int ellipse,
104  const QBrush &fillBrush, const QPen &linePen);
105 
106  MythImage *GetImageFromString(const QString &msg, int flags, QRect r,
107  const MythFontProperties &font);
108  MythImage *GetImageFromTextLayout(const LayoutVector & layouts,
109  const FormatVector & formats,
110  const MythFontProperties &font,
111  QRect &canvas, QRect &dest);
112  MythImage *GetImageFromRect(QRect area, int radius, int ellipse,
113  const QBrush &fillBrush,
114  const QPen &linePen);
115 
117  virtual MythImage* GetFormatImagePriv(void) = 0;
118  virtual void DeleteFormatImagePriv(MythImage *im) = 0;
119  void ExpireImages(int64_t max = 0);
120 
121  // This needs to be called by classes inheriting from MythPainter
122  // in the destructor.
123  virtual void Teardown(void);
124 
125  void CheckFormatImage(MythImage *im);
126 
127  int m_hardwareCacheSize { 0 };
128  int m_maxHardwareCacheSize { 0 };
129 
130  private:
131  int64_t m_softwareCacheSize {0};
132  int64_t m_maxSoftwareCacheSize {1024 * 1024 * 48};
133 
135  QSet<MythImage*> m_allocatedImages;
136 
137  QMap<QString, MythImage *> m_stringToImageMap;
138  std::list<QString> m_stringExpireList;
139 
140  bool m_showBorders {false};
141  bool m_showNames {false};
142 };
143 
144 #endif
MythPainter::m_allocatedImages
QSet< MythImage * > m_allocatedImages
Definition: mythpainter.h:135
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:134
MythPainter::m_stringExpireList
std::list< QString > m_stringExpireList
Definition: mythpainter.h:138
MythPainter::m_stringToImageMap
QMap< QString, MythImage * > m_stringToImageMap
Definition: mythpainter.h:137
MythFontProperties
Definition: mythfontproperties.h:13
formats
const std::array< const std::string, 8 > formats
Definition: vbilut.cpp:189
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:95
MythPainter::ShowTypeNames
bool ShowTypeNames(void) const
Definition: mythpainter.h:96
MythPainter::SetDebugMode
void SetDebugMode(bool showBorders, bool showNames)
Definition: mythpainter.h:89
Clear
#define Clear(a)
Definition: audiooutputopensles.cpp:47
LayoutVector
QVector< QTextLayout * > LayoutVector
Definition: mythpainter.h:29
MythPainter
Definition: mythpainter.h:32
MythImage
Definition: mythimage.h:36
UIEffects
Definition: mythuianimation.h:12
MythPainter::PopTransformation
virtual void PopTransformation(void)
Definition: mythpainter.h:81
MythPainter::Begin
virtual void Begin(QPaintDevice *)
Definition: mythpainter.h:52
mythuiexp.h