painthelper.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #ifndef PAINTHELPER_H
  2. #define PAINTHELPER_H
  3. #include <QFont>
  4. #include <QPainter>
  5. class PainterEx : public QPainter
  6. {
  7. public:
  8. enum RoundedCorner
  9. {
  10. None = 0x0000,
  11. TopLeft = 0x0001,
  12. TopRight = 0x0002,
  13. BottomLeft = 0x0004,
  14. BottomRight = 0x0008,
  15. Left = TopLeft|BottomLeft,
  16. Right = TopRight|BottomRight,
  17. Top = TopLeft|TopRight,
  18. Bottom = BottomLeft|BottomRight,
  19. All = TopLeft|TopRight|BottomLeft|BottomRight,
  20. };
  21. Q_DECLARE_FLAGS(RoundedCorners, RoundedCorner)
  22. enum RectBorder
  23. {
  24. RectBorderNone = 0x0000,
  25. RectBorderLeft = 0x0001,
  26. RectBorderRight = 0x0002,
  27. RectBorderTop = 0x0004,
  28. RectBorderBottom = 0x0008,
  29. RectBorderAll = TopLeft|TopRight|BottomLeft|BottomRight,
  30. RectBorderExceptLeft = RectBorderAll & (~RectBorderLeft),
  31. RectBorderExceptRight = RectBorderAll & (~RectBorderRight),
  32. RectBorderExceptTop = RectBorderAll & (~RectBorderTop),
  33. RectBorderExceptBottom = RectBorderAll & (~RectBorderBottom),
  34. };
  35. Q_DECLARE_FLAGS(RectBorders, RectBorder)
  36. public:
  37. explicit PainterEx(QPaintDevice *device);
  38. void SetBrushOnly(const QColor &color);
  39. void SetPenOnly(const QColor &color, qreal width = 1, Qt::PenStyle s = Qt::SolidLine);
  40. void DrawCircle(QPointF center, double radius, const QColor &brush = QColor(), const QPen &pen = QPen(Qt::transparent));
  41. void DrawTextTwice(const QRectF &textRect, const QString &text, const QColor &color = QColor(), Qt::Alignment flags = Qt::AlignHCenter|Qt::AlignVCenter);
  42. void DrawText(const QRectF &textRect, const QString &text, const QColor &color, Qt::Alignment flags = Qt::AlignHCenter|Qt::AlignVCenter);
  43. void DrawRoundedRect(const QRectF &rect, int radius, const QColor &color = QColor(), RoundedCorners flags = RoundedCorner::All);
  44. void DrawPixmap(const QRectF &rect, const QPixmap &pixmap);
  45. void DrawPixmap(const QRectF &rect, const QString &srcPath, int alpha = 255);
  46. void DrawBorder(const QRect &rect, const QPen &pen, RectBorders flags = RectBorder::RectBorderAll);
  47. void DrawTriangle(const QRect &rect, bool isUp, const QColor &brush = QColor(), const QPen &pen = QPen(Qt::transparent));
  48. };
  49. Q_DECLARE_OPERATORS_FOR_FLAGS(PainterEx::RoundedCorners)
  50. Q_DECLARE_OPERATORS_FOR_FLAGS(PainterEx::RectBorders)
  51. class FontEx : public QFont
  52. {
  53. public:
  54. enum NotoSansType
  55. {
  56. Unkown,
  57. Normal,
  58. Regular,
  59. Medium,
  60. Light,
  61. Bold
  62. };
  63. public:
  64. explicit FontEx(const QString &family, int pixelSize, bool bold = false);
  65. explicit FontEx(NotoSansType type, int pixelSize);
  66. signals:
  67. public slots:
  68. };
  69. #endif // PAINTHELPER_H