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 */
48QRect sectionRect(KSvg::FrameSvg::EnabledBorders borders, const QRect &contentRect, const QSize &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 QRect(QPoint(contentRect.left(), 0), QSize(contentRect.width(), contentRect.top()));
58 } else if (borders == FrameSvg::BottomBorder) {
59 return QRect(QPoint(contentRect.left(), contentRect.bottom() + 1), QSize(contentRect.width(), fullSize.height() - contentRect.bottom() - 1));
60 } else if (borders == FrameSvg::LeftBorder) {
61 return QRect(QPoint(0, contentRect.top()), QSize(contentRect.left(), contentRect.height()));
62 } else if (borders == FrameSvg::RightBorder) {
63 return QRect(QPoint(contentRect.right() + 1, contentRect.top()), QSize(fullSize.width() - contentRect.right() - 1, contentRect.height()));
64 } else if (borders == (FrameSvg::TopBorder | FrameSvg::LeftBorder)) {
65 return QRect(QPoint(0, 0), QSize(contentRect.left(), contentRect.top()));
66 } else if (borders == (FrameSvg::TopBorder | FrameSvg::RightBorder)) {
67 return QRect(QPoint(contentRect.right() + 1, 0), QSize(fullSize.width() - contentRect.right() - 1, contentRect.top()));
68 } else if (borders == (FrameSvg::BottomBorder | FrameSvg::LeftBorder)) {
69 return QRect(QPoint(0, contentRect.bottom() + 1), QSize(contentRect.left(), fullSize.height() - contentRect.bottom() - 1));
70 } else if (borders == (FrameSvg::BottomBorder | FrameSvg::RightBorder)) {
71 return QRect(QPoint(contentRect.right() + 1, contentRect.bottom() + 1),
72 QSize(fullSize.width() - contentRect.right() - 1, fullSize.height() - contentRect.bottom() - 1));
73 } else {
74 qWarning() << "unrecognized border" << borders;
75 }
76 return QRect();
77}
78
79}
80
81}
82
83#endif
The KSvg namespace.
int bottom() const const
int height() const const
int left() const const
int right() const const
int top() const const
int width() const const
int height() const const
int width() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 10 2024 11:47:10 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.