KDecoration3

scalehelpers.h
1/*
2 * SPDX-FileCopyrightText: 2024 Xaver Hugl <xaver.hugl@gmail.com>
3 *
4 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5 */
6#pragma once
7
8#include <QPointF>
9#include <QRectF>
10#include <QSizeF>
11
12namespace KDecoration3
13{
14
15/**
16 * @returns the pixel size with the provided scale
17 * @since 6.3
18 */
19inline qreal pixelSize(qreal scale)
20{
21 return 1.0 / scale;
22}
23
24/**
25 * snaps the logical geometry value to a fractional logical geometry value
26 * that aligns to the pixel grid of the provided scale
27 * @since 6.3
28 */
29inline qreal snapToPixelGrid(qreal value, qreal scale)
30{
31 return std::round(value * scale) / scale;
32}
33
34/**
35 * snaps the logical geometry value to a fractional logical geometry value
36 * that aligns to the pixel grid of the provided scale
37 * @since 6.3
38 */
39inline QPointF snapToPixelGrid(const QPointF &value, qreal scale)
40{
41 return QPointF(snapToPixelGrid(value.x(), scale), snapToPixelGrid(value.y(), scale));
42}
43
44/**
45 * snaps the logical geometry value to a fractional logical geometry value
46 * that aligns to the pixel grid of the provided scale
47 * @since 6.3
48 */
49inline QSizeF snapToPixelGrid(const QSizeF &value, qreal scale)
50{
51 return QSizeF(snapToPixelGrid(value.width(), scale), snapToPixelGrid(value.height(), scale));
52}
53
54/**
55 * snaps the logical geometry value to a fractional logical geometry value
56 * that aligns to the pixel grid of the provided scale
57 * @since 6.3
58 */
59inline QRectF snapToPixelGrid(const QRectF &value, qreal scale)
60{
61 return QRectF(snapToPixelGrid(value.topLeft(), scale), snapToPixelGrid(value.bottomRight(), scale));
62}
63
64}
Framework for creating window decorations.
qreal snapToPixelGrid(qreal value, qreal scale)
snaps the logical geometry value to a fractional logical geometry value that aligns to the pixel grid...
qreal pixelSize(qreal scale)
qreal x() const const
qreal y() const const
QPointF bottomRight() const const
QPointF topLeft() 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 16:55:48 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.