123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- #ifndef PAINTHELPER_H
- #define PAINTHELPER_H
- #include <QFont>
- #include <QPainter>
- class PainterEx : public QPainter
- {
- public:
- enum RoundedCorner
- {
- None = 0x0000,
- TopLeft = 0x0001,
- TopRight = 0x0002,
- BottomLeft = 0x0004,
- BottomRight = 0x0008,
- Left = TopLeft|BottomLeft,
- Right = TopRight|BottomRight,
- Top = TopLeft|TopRight,
- Bottom = BottomLeft|BottomRight,
- All = TopLeft|TopRight|BottomLeft|BottomRight,
- };
- Q_DECLARE_FLAGS(RoundedCorners, RoundedCorner)
- enum RectBorder
- {
- RectBorderNone = 0x0000,
- RectBorderLeft = 0x0001,
- RectBorderRight = 0x0002,
- RectBorderTop = 0x0004,
- RectBorderBottom = 0x0008,
- RectBorderAll = TopLeft|TopRight|BottomLeft|BottomRight,
- RectBorderExceptLeft = RectBorderAll & (~RectBorderLeft),
- RectBorderExceptRight = RectBorderAll & (~RectBorderRight),
- RectBorderExceptTop = RectBorderAll & (~RectBorderTop),
- RectBorderExceptBottom = RectBorderAll & (~RectBorderBottom),
- };
- Q_DECLARE_FLAGS(RectBorders, RectBorder)
- public:
- explicit PainterEx(QPaintDevice *device);
- void SetBrushOnly(const QColor &color);
- void SetPenOnly(const QColor &color, qreal width = 1, Qt::PenStyle s = Qt::SolidLine);
- void DrawCircle(QPointF center, double radius, const QColor &brush = QColor(), const QPen &pen = QPen(Qt::transparent));
- void DrawTextTwice(const QRectF &textRect, const QString &text, const QColor &color = QColor(), Qt::Alignment flags = Qt::AlignHCenter|Qt::AlignVCenter);
- void DrawText(const QRectF &textRect, const QString &text, const QColor &color, Qt::Alignment flags = Qt::AlignHCenter|Qt::AlignVCenter);
- void DrawRoundedRect(const QRectF &rect, int radius, const QColor &color = QColor(), RoundedCorners flags = RoundedCorner::All);
- void DrawPixmap(const QRectF &rect, const QPixmap &pixmap);
- void DrawPixmap(const QRectF &rect, const QString &srcPath, int alpha = 255);
- void DrawBorder(const QRect &rect, const QPen &pen, RectBorders flags = RectBorder::RectBorderAll);
- void DrawTriangle(const QRect &rect, bool isUp, const QColor &brush = QColor(), const QPen &pen = QPen(Qt::transparent));
- };
- Q_DECLARE_OPERATORS_FOR_FLAGS(PainterEx::RoundedCorners)
- Q_DECLARE_OPERATORS_FOR_FLAGS(PainterEx::RectBorders)
- class FontEx : public QFont
- {
- public:
- enum NotoSansType
- {
- Unkown,
- Normal,
- Regular,
- Medium,
- Light,
- Bold
- };
- public:
- explicit FontEx(const QString &family, int pixelSize, bool bold = false);
- explicit FontEx(NotoSansType type, int pixelSize);
-
- signals:
-
- public slots:
- };
- #endif // PAINTHELPER_H
|