KSvg

framesvg_helpers.h
1/*
2 SPDX-FileCopyrightText: 2014 Aleix Pol Gonzalez <aleixpol@blue-systems.com>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#ifndef KSVG_FRAMESVG_HELPERS_H
8#define KSVG_FRAMESVG_HELPERS_H
9
10#include "framesvg.h"
11
12namespace KSvg
13{
14namespace FrameSvgHelpers
15{
16/**
17 * @returns the element id name for said @p borders
18 */
19QString borderToElementId(FrameSvg::EnabledBorders borders)
20{
21 if (borders == FrameSvg::NoBorder) {
22 return QStringLiteral("center");
23 } else if (borders == FrameSvg::TopBorder) {
24 return QStringLiteral("top");
25 } else if (borders == FrameSvg::BottomBorder) {
26 return QStringLiteral("bottom");
27 } else if (borders == FrameSvg::LeftBorder) {
28 return QStringLiteral("left");
29 } else if (borders == FrameSvg::RightBorder) {
30 return QStringLiteral("right");
31 } else if (borders == (FrameSvg::TopBorder | FrameSvg::LeftBorder)) {
32 return QStringLiteral("topleft");
33 } else if (borders == (FrameSvg::TopBorder | FrameSvg::RightBorder)) {
34 return QStringLiteral("topright");
35 } else if (borders == (FrameSvg::BottomBorder | FrameSvg::LeftBorder)) {
36 return QStringLiteral("bottomleft");
37 } else if (borders == (FrameSvg::BottomBorder | FrameSvg::RightBorder)) {
38 return QStringLiteral("bottomright");
39 } else {
40 qWarning() << "unrecognized border" << borders;
41 }
42 return QString();
43}
44
45/**
46 * @returns the suggested geometry for the @p borders given a @p fullSize frame size and a @p contentRect
47 */
48QRectF sectionRect(KSvg::FrameSvg::EnabledBorders borders, const QRectF &contentRect, const QSizeF &fullSize)
49{
50 // don't use QRect corner methods here, they have semantics that might come as unexpected.
51 // prefer constructing the points explicitly. e.g. from QRect::topRight docs:
52 // Note that for historical reasons this function returns QPoint(left() + width() -1, top()).
53
54 if (borders == FrameSvg::NoBorder) {
55 return contentRect;
56 } else if (borders == FrameSvg::TopBorder) {
57 return QRectF(QPointF(contentRect.left(), 0), QSizeF(contentRect.width(), contentRect.top()));
58 } else if (borders == FrameSvg::BottomBorder) {
59 return QRectF(QPointF(contentRect.left(), contentRect.bottom()), QSizeF(contentRect.width(), fullSize.height() - contentRect.bottom()));
60 } else if (borders == FrameSvg::LeftBorder) {
61 return QRectF(QPointF(0, contentRect.top()), QSizeF(contentRect.left(), contentRect.height()));
62 } else if (borders == FrameSvg::RightBorder) {
63 return QRectF(QPointF(contentRect.right(), contentRect.top()), QSizeF(fullSize.width() - contentRect.right(), contentRect.height()));
64 } else if (borders == (FrameSvg::TopBorder | FrameSvg::LeftBorder)) {
65 return QRectF(QPointF(0, 0), QSizeF(contentRect.left(), contentRect.top()));
66 } else if (borders == (FrameSvg::TopBorder | FrameSvg::RightBorder)) {
67 return QRectF(QPointF(contentRect.right(), 0), QSizeF(fullSize.width() - contentRect.right(), contentRect.top()));
68 } else if (borders == (FrameSvg::BottomBorder | FrameSvg::LeftBorder)) {
69 return QRectF(QPointF(0, contentRect.bottom()), QSizeF(contentRect.left(), fullSize.height() - contentRect.bottom()));
70 } else if (borders == (FrameSvg::BottomBorder | FrameSvg::RightBorder)) {
71 return QRectF(QPointF(contentRect.right(), contentRect.bottom()),
72 QSizeF(fullSize.width() - contentRect.right(), fullSize.height() - contentRect.bottom()));
73 } else {
74 qWarning() << "unrecognized border" << borders;
75 }
76 return QRectF();
77}
78
79}
80
81}
82
83#endif
The KSvg namespace.
qreal bottom() const const
qreal height() const const
qreal left() const const
qreal right() const const
qreal top() const const
qreal width() const const
qreal height() const const
qreal width() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:00:08 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.