Logo    
KDWinUtils
Helper library for MFC to Qt migration
Loading...
Searching...
No Matches
kpainter.h
Go to the documentation of this file.
1/****************************************************************************
2**
3** This file is part of KDWinutils, KDAB's MFC to Qt migration tool.
4**
5** Copyright (C) 2023 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
6** All rights reserved.
7**
8** This file is intended solely for use by the migration tools and services
9** provided by Klarälvdalens Datakonsult AB.
10**
11** Any other use or distribution of this software that is not otherwise agreed
12** upon in writing and signed by an authorized representative of Klarälvdalens
13** Datakonsult AB, KDAB (USA) LLC, KDAB (Deutschland) GmbH & Co. K.G.,
14** KDAB (France) SAS, KDAB (UK), Ltd., or any future subsidiary of Klarälvdalens
15** Datakonsult AB is hereby prohibited.
16**
17** Contact info@kdab.com if any conditions stated above are unclear to you.
18**
19****************************************************************************/
20
21#pragma once
22
24
25#include "../corelib/kpoint.h"
26#include "../corelib/krect.h"
27#include "../corelib/kstring.h"
28#include "kbrush.h"
29#include "kfont.h"
30#include "kpen.h"
31#include "kwidget.h"
32
33#include <QPainter>
34#include <QPoint>
35
36class QWidget;
37class QPainter;
38
40
50class KDWINUTILS_EXPORT KPainter : public QPainter
51{
52public:
53 using QPainter::QPainter;
54
61 template <typename T>
63 {
64 if (auto scrollArea = widget->scrollArea())
65 begin(scrollArea->viewport());
66 else
67 begin(widget);
68 }
69
74 KPen SelectObject(const KPen &pen);
79 KBrush SelectObject(const KBrush &brush);
84 KFont SelectObject(const KFont &font);
85
90 QColor SetTextColor(const QColor &color);
95 QColor SetBkColor(const QColor &color);
96
104 void IntersectClipRect(const KRect &rect);
112 void IntersectClipRect(int x1, int y1, int x2, int y2);
118 void SelectClipRgn(QRegion *region);
119
121 KSize GetTextExtent(const KString &str) const;
122
124 void MoveTo(int x, int y);
126 void LineTo(int x, int y);
127
129 void Rectangle(const KRect &rect);
131 void Rectangle(int x1, int y1, int x2, int y2);
132
134 void Ellipse(const KRect &rect);
136 void Ellipse(int x1, int y1, int x2, int y2);
137
139 void RoundRect(const KRect &rect, int ellipseWidth, int ellipseHeight);
141 void RoundRect(int x1, int y1, int x2, int y2, int ellipseWidth, int ellipseHeight);
142
143 void Chord(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4);
144
146 void Polygon(const KPoint *points, int pointCount);
147
149 void Pie(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4);
150
152 void PolyBezier(const KPoint *points, int pointCount);
153
155 void TextOut(int x, int y, const KString &text, int nCount);
157 void TextOut(int x, int y, const KString &text);
158
160 void FillRect(const KRect &rect, const KBrush &brush);
161
163 void BitBlt(const QRect &rect, const QPixmap &pSrcDC, int xSrc, int ySrc);
165 void BitBlt(int x, int y, int nWidth, int nHeight, const QPixmap &pSrcDC, int xSrc, int ySrc);
166
167private:
168 QPoint m_currentPos;
169};
170
The KBrush class defines a brush to be used during painting.
Definition kbrush.h:38
The KFont class defines a font to be used during painting.
Definition kfont.h:37
The KPainter class is used to paint on a widget.
Definition kpainter.h:51
void BitBlt(const QRect &rect, const QPixmap &pSrcDC, int xSrc, int ySrc)
Draws a bitmap at the specified coordinates.
void Rectangle(int x1, int y1, int x2, int y2)
Draws a rectangle using the current pen and fills it using the current brush.
KBrush SelectObject(const KBrush &brush)
Sets the brush to be used for drawing.
void BitBlt(int x, int y, int nWidth, int nHeight, const QPixmap &pSrcDC, int xSrc, int ySrc)
Draws a bitmap at the specified coordinates.
void Ellipse(const KRect &rect)
Draws an ellipse using the current pen and fills it using the current brush.
void Pie(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4)
Draws a pie-shaped wedge.
void LineTo(int x, int y)
Draws a line from the current position up to, but not including, a point.
void IntersectClipRect(const KRect &rect)
Enables clipping, and sets the clip region to the given rectangle.
void TextOut(int x, int y, const KString &text)
Writes a character string at a specified location using the currently selected font.
void FillRect(const KRect &rect, const KBrush &brush)
Fills a given rectangle by using a specific brush.
void PolyBezier(const KPoint *points, int pointCount)
Draws one or more Bzier splines. The current position isn't used or updated.
void RoundRect(const KRect &rect, int ellipseWidth, int ellipseHeight)
Draws a rounded rectangle using the current pen and fills it using the current brush.
void SelectClipRgn(QRegion *region)
Sets the clipping region to be used for drawing.
void TextOut(int x, int y, const KString &text, int nCount)
Writes a character string at a specified location using the currently selected font.
KPen SelectObject(const KPen &pen)
Sets the pen to be used for drawing.
KFont SelectObject(const KFont &font)
Sets the font to be used for drawing.
void Chord(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4)
KSize GetTextExtent(const KString &str) const
Computes the width and height of a line of text based on the current font.
KPainter(KWidgetBase< T > *widget)
Construct a new KPainter object based on a KWidget or KDialog.
Definition kpainter.h:62
void Rectangle(const KRect &rect)
Draws a rectangle using the current pen and fills it using the current brush.
void IntersectClipRect(int x1, int y1, int x2, int y2)
Enables clipping, and sets the clip region to the given rectangle.
void Polygon(const KPoint *points, int pointCount)
Draws a polygon consisting of two or more points (vertices) connected by lines.
void Ellipse(int x1, int y1, int x2, int y2)
Draws an ellipse using the current pen and fills it using the current brush.
void RoundRect(int x1, int y1, int x2, int y2, int ellipseWidth, int ellipseHeight)
Draws a rounded rectangle using the current pen and fills it using the current brush.
QColor SetBkColor(const QColor &color)
Sets the background color to be used for drawing (ie the brush color)
QColor SetTextColor(const QColor &color)
Sets the text color to be used for drawing (ie the pen color)
void MoveTo(int x, int y)
Moves the current position.
The KPen class defines a font to be used during painting.
Definition kpen.h:42
The KPoint class defines a point in the plane using integer precision.
Definition kpoint.h:43
The KRect class defines a rectangle in the plane using integer precision.
Definition krect.h:40
The KSize class defines the size of a two-dimensional object using integer point precision.
Definition ksize.h:43
The KString class provides a Unicode character string.
Definition kstring.h:45
The KWidgetBase< T > class maps the MFC API of CWnd.
Definition kwidget.h:87
#define KDWINUTILS_EXPORT
Definition kdwinutils_export.h:31
#define KDWINUTILS_BEGIN_NAMESPACE
Definition kdwinutils_global.h:27
#define KDWINUTILS_END_NAMESPACE
Definition kdwinutils_global.h:28