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 typedef QVector<QTextLayout *> LayoutVector;
30 typedef QVector<QTextLayout::FormatRange> FormatVector;
31 
33 {
34  public:
35  MythPainter();
43  virtual ~MythPainter() = default;
44 
45  virtual QString GetName(void) = 0;
46  virtual bool SupportsAnimation(void) = 0;
47  virtual bool SupportsAlpha(void) = 0;
48  virtual bool SupportsClipping(void) = 0;
49  virtual void FreeResources(void) { }
50  virtual void Begin(QPaintDevice *parent) { m_Parent = parent; }
51  virtual void End() { m_Parent = nullptr; }
52 
53  virtual void SetClipRect(const QRect &clipRect);
54  virtual void SetClipRegion(const QRegion &clipRegion);
55  virtual void Clear(QPaintDevice *device, const QRegion &region);
56 
57  QPaintDevice *GetParent(void) { return m_Parent; }
58 
59  virtual void DrawImage(const QRect &dest, MythImage *im, const QRect &src,
60  int alpha) = 0;
61 
62  void DrawImage(int x, int y, MythImage *im, int alpha);
63  void DrawImage(const QPoint &topLeft, MythImage *im, int alph);
64 
65  virtual void DrawText(const QRect &r, const QString &msg, int flags,
66  const MythFontProperties &font, int alpha,
67  const QRect &boundRect);
68  virtual void DrawTextLayout(const QRect &canvasRect,
69  const LayoutVector & layouts,
70  const FormatVector & formats,
71  const MythFontProperties &font, int alpha,
72  const QRect &destRect);
73  virtual void DrawRect(const QRect &area, const QBrush &fillBrush,
74  const QPen &linePen, int alpha);
75  virtual void DrawRoundRect(const QRect &area, int cornerRadius,
76  const QBrush &fillBrush, const QPen &linePen,
77  int alpha);
78  virtual void DrawEllipse(const QRect &area, const QBrush &fillBrush,
79  const QPen &linePen, int alpha);
80 
81  virtual void PushTransformation(const UIEffects &zoom, QPointF center = QPointF());
82  virtual void PopTransformation(void) { }
83 
87  MythImage *GetFormatImage();
88  void DeleteFormatImage(MythImage *im);
89 
90  void SetDebugMode(bool showBorders, bool showNames)
91  {
92  m_showBorders = showBorders;
93  m_showNames = showNames;
94  }
95 
96  bool ShowBorders(void) { return m_showBorders; }
97  bool ShowTypeNames(void) { return m_showNames; }
98 
99  void SetMaximumCacheSizes(int hardware, int software);
100 
101  protected:
102  void DrawTextPriv(MythImage *im, const QString &msg, int flags,
103  const QRect &r, const MythFontProperties &font);
104  void DrawRectPriv(MythImage *im, const QRect &area, int radius, int ellipse,
105  const QBrush &fillBrush, const QPen &linePen);
106 
107  MythImage *GetImageFromString(const QString &msg, int flags, const QRect &r,
108  const MythFontProperties &font);
109  MythImage *GetImageFromTextLayout(const LayoutVector & layouts,
110  const FormatVector & formats,
111  const MythFontProperties &font,
112  QRect &canvas, QRect &dest);
113  MythImage *GetImageFromRect(const QRect &area, int radius, int ellipse,
114  const QBrush &fillBrush,
115  const QPen &linePen);
116 
118  virtual MythImage* GetFormatImagePriv(void) = 0;
119  virtual void DeleteFormatImagePriv(MythImage *im) = 0;
120  void ExpireImages(int64_t max = 0);
121 
122  // This needs to be called by classes inheriting from MythPainter
123  // in the destructor.
124  virtual void Teardown(void);
125 
126  void CheckFormatImage(MythImage *im);
127 
128  QPaintDevice *m_Parent {nullptr};
129  int m_HardwareCacheSize {0};
131 
132  private:
133  int64_t m_SoftwareCacheSize {0};
135 
137  QSet<MythImage*> m_allocatedImages;
138 
139  QMap<QString, MythImage *> m_StringToImageMap;
140  std::list<QString> m_StringExpireList;
141 
142  bool m_showBorders {false};
143  bool m_showNames {false};
144 };
145 
146 #endif
QMap< QString, MythImage * > m_StringToImageMap
Definition: mythpainter.h:139
QSet< MythImage * > m_allocatedImages
Definition: mythpainter.h:137
QVector< QTextLayout * > LayoutVector
Definition: mythpainter.h:27
const char * formats[8]
Definition: vbilut.cpp:190
QMutex m_allocationLock
Definition: mythpainter.h:136
unsigned char r
Definition: ParseText.cpp:329
bool ShowTypeNames(void)
Definition: mythpainter.h:97
virtual void End()
Definition: mythpainter.h:51
std::list< QString > m_StringExpireList
Definition: mythpainter.h:140
virtual void FreeResources(void)
Definition: mythpainter.h:49
QPaintDevice * GetParent(void)
Definition: mythpainter.h:57
int64_t m_MaxSoftwareCacheSize
Definition: mythpainter.h:134
QVector< QTextLayout::FormatRange > FormatVector
Definition: mythpainter.h:30
bool ShowBorders(void)
Definition: mythpainter.h:96
#define MUI_PUBLIC
Definition: mythuiexp.h:9
virtual void Begin(QPaintDevice *parent)
Definition: mythpainter.h:50
void SetDebugMode(bool showBorders, bool showNames)
Definition: mythpainter.h:90
#define Clear(a)
virtual void PopTransformation(void)
Definition: mythpainter.h:82
int m_MaxHardwareCacheSize
Definition: mythpainter.h:130