summaryrefslogtreecommitdiff
path: root/ui/qt5/horizonwizardpage.cc
blob: dcd3d8fa0cb41d022de6ae5681e2a465ab00e541 (plain) (blame)
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
/*
 * horizonwizardpage.cc - Implementation of our custom QWizardPage subclass
 * horizon-qt5, the Qt 5 user interface for
 * Project Horizon
 *
 * Copyright (c) 2019 Adélie Linux and contributors.  All rights reserved.
 * This code is licensed under the AGPL 3.0 license, as noted in the
 * LICENSE-code file in the root directory of this repository.
 *
 * SPDX-License-Identifier: AGPL-3.0-only
 */

#include "horizonwizardpage.hh"

using std::string;

QPixmap HorizonWizardPage::loadDPIAwarePixmap(string pixmap, string type) {
    string path = ":/wizard_pixmaps/resources/";
    path += pixmap;
    path += "-";

    if(window()->devicePixelRatioF() <= 1.0) {
        path += "low";
    } else {
        path += "high";
    }

    path += type;
    return QPixmap(path.c_str());
}

void HorizonWizardPage::loadWatermark(string page) {
    QPixmap pixmap = loadDPIAwarePixmap(page);
    qreal pixelRatio = window()->devicePixelRatioF();

    // Handle cases where ratio is not exactly 1.0 or 2.0
    // Wizard machinary automatically uses FastTransformation, which is
    // ugly as sin.
    if(pixelRatio > 1.0) {
        qreal width = 232 * pixelRatio;
        qreal height = 380 * pixelRatio;
        QSize newSize = QSize(width, height);

        pixmap = pixmap.scaled(newSize, Qt::KeepAspectRatio,
                               Qt::SmoothTransformation);
    }
    pixmap.setDevicePixelRatio(pixelRatio);

    setPixmap(QWizard::WatermarkPixmap, pixmap);
}

#ifndef IN_RUNNER
HorizonWizard *HorizonWizardPage::horizonWizard() const {
    return dynamic_cast<HorizonWizard *>(this->wizard());
}
#endif  /* !IN_RUNNER */