~bzoltan/ubuntu-ui-toolkit/click-uitk

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
 * Copyright 2015 Canonical Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; version 3.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#ifndef UCFONTUTILS_H
#define UCFONTUTILS_H

#include <QtCore/QObject>

class UCUnits;
class UCFontUtils : public QObject
{
    Q_OBJECT

public:
    static constexpr float fontUnits = 14.0f;
    static constexpr float xxSmallScale = 0.606f;
    static constexpr float xSmallScale = 0.707f;
    static constexpr float smallScale = 0.857f;
    static constexpr float mediumScale = 1.0f;
    static constexpr float largeScale = 1.414f;
    static constexpr float xLargeScale = 1.905f;

    static UCFontUtils *instance(QObject *parent = Q_NULLPTR)
    {
        if (!m_instance) {
            if (!parent) {
                qFatal("Creating FontUtils singleton requires a parent object!");
            }
            m_instance = new UCFontUtils(parent);
        }
        return m_instance;
    }

    explicit UCFontUtils(QObject *parent = 0) : QObject(parent) {}
    ~UCFontUtils() { m_instance = Q_NULLPTR; }

    Q_INVOKABLE qreal sizeToPixels(const QString &size);
    Q_INVOKABLE qreal modularScale(const QString &size);

private:
    static UCFontUtils *m_instance;
};

#define SCALE_CODE(size)    reinterpret_cast<int*>(size.toLatin1().data())[0]
#define SCALE_MEDIUM        0x6964656d // "medi"
#define SCALE_LARGE         0x6772616c // "larg"
#define SCALE_SMALL         0x6c616d73 // "smal"
#define SCALE_XLARGE        0x616c2d78 // "x-la"
#define SCALE_XSMALL        0x6d732d78 // "x-sm"
#define SCALE_XXSMALL       0x732d7878 // "xx-s"

#endif // UCFONTUTILS_H