KD Reports API Documentation 2.2
Loading...
Searching...
No Matches
KDReportsHLineTextObject.cpp
Go to the documentation of this file.
1/****************************************************************************
2**
3** This file is part of the KD Reports library.
4**
5** SPDX-FileCopyrightText: 2007 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
6**
7** SPDX-License-Identifier: MIT
8**
9****************************************************************************/
10
12
13#include <QColor>
14#include <QPainter>
15#include <QRectF>
16#include <QTextDocument>
17#include <QTextFormat>
18#include <QTextFrame>
19
20#include <QDebug>
21
22namespace KDReports {
23
24Q_GLOBAL_STATIC(HLineTextObject, globalHLineInterface)
25
26void HLineTextObject::registerHLineObjectHandler(QTextDocument *doc)
27{
28 HLineTextObject *hLineInterface = globalHLineInterface();
29
30 // This assert is here because a bad build environment can cause this to fail. There is a note
31 // in the Qt source that indicates an error should be output, but there is no such output.
32 Q_ASSERT(qobject_cast<QTextObjectInterface *>(hLineInterface));
33
34 doc->documentLayout()->registerHandler(HLineTextObject::HLineTextFormat, hLineInterface);
35}
36
37//@cond PRIVATE
38QSizeF HLineTextObject::intrinsicSize(QTextDocument *doc, int posInDocument, const QTextFormat &format)
39{
40 Q_UNUSED(posInDocument);
41
43 const qreal width = doc->pageSize().width() - (f.leftMargin() + f.rightMargin());
44
45 const double thickness = format.doubleProperty(Thickness);
46 const double margin = format.doubleProperty(Margin);
47 // qDebug() << "intrinsicSize: thickness=" << thickness << "margin=" << margin;
48
49 return QSizeF(width, thickness + 2 * margin);
50}
51
52void HLineTextObject::drawObject(QPainter *painter, const QRectF &r, QTextDocument *doc, int posInDocument, const QTextFormat &format)
53{
54 Q_UNUSED(doc);
55 Q_UNUSED(posInDocument);
56
57 const QColor color = qvariant_cast<QColor>(format.property(Color));
58
59 QPen pen;
61
62 pen.setColor(color);
63 painter->setPen(pen);
64
65 const qreal y = r.top() + (r.height() / 2);
66 QLineF line(r.left(), y, r.right(), y);
67
68 painter->drawLine(line);
69}
70//@endcond
71}
QSizeF intrinsicSize(QTextDocument *doc, int posInDocument, const QTextFormat &format) override
void drawObject(QPainter *painter, const QRectF &rect, QTextDocument *doc, int posInDocument, const QTextFormat &format) override
void drawLine(const QLineF &line)
void setPen(const QColor &color)
void setColor(const QColor &color)
void setWidthF(qreal width)
qreal height() const const
qreal left() const const
qreal right() const const
qreal top() const const
QTextFrame * rootFrame() const const
qreal doubleProperty(int propertyId) const const
QVariant property(int propertyId) const const
QTextFrameFormat frameFormat() const const
qreal leftMargin() const const
qreal rightMargin() const const

© Klarälvdalens Datakonsult AB (KDAB)
"The Qt, C++ and OpenGL Experts"
https://www.kdab.com/
https://www.kdab.com/development-resources/qt-tools/kd-reports/
Generated on Wed Apr 24 2024 04:08:14 for KD Reports API Documentation by doxygen 1.9.8