File: utils.cpp

package info (click to toggle)
kscreen 4%3A6.5.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,444 kB
  • sloc: cpp: 6,786; xml: 19; makefile: 7; sh: 5
file content (77 lines) | stat: -rw-r--r-- 2,229 bytes parent folder | download
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
67
68
69
70
71
72
73
74
75
76
77
/*
    SPDX-FileCopyrightText: 2013 Daniel Vrátil <dvratil@redhat.com>

    SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/

#include "utils.h"

#include <kscreen/edid.h>
#include <kscreen/mode.h>

#include <KLocalizedString>

QString Utils::outputName(const KScreen::OutputPtr &output, bool shouldShowSerialNumber, bool shouldShowConnector)
{
    return outputName(output.data(), shouldShowSerialNumber, shouldShowConnector);
}

QString Utils::outputName(const KScreen::Output *output, bool shouldShowSerialNumber, bool shouldShowConnector)
{
    if (output->type() == KScreen::Output::Panel) {
        return i18nd("kscreen_common", "Built-in Screen");
    }

        // The name will be "VendorName ModelName (ConnectorName)",
        // but some components may be empty.
    QString name;
    if (!(output->vendor().isEmpty())) {
        name = output->vendor() + QLatin1Char(' ');
    }
    if (!output->model().isEmpty()) {
        name += output->model() + QLatin1Char(' ');
    }
    if (output->edid()) {
        if (!output->edid()->serial().isEmpty() && shouldShowSerialNumber) {
            name += output->edid()->serial() + QLatin1Char(' ');
        }
    }
    if (shouldShowConnector) {
        name += output->name();
    }
    if (!name.trimmed().isEmpty()) {
        return name;
    }
    return output->name();
}

QString Utils::sizeToString(const QSize &size)
{
    return QStringLiteral("%1x%2").arg(size.width()).arg(size.height());
}

KScreen::ModePtr Utils::biggestMode(const KScreen::ModeList &modes)
{
    Q_ASSERT(!modes.isEmpty());

    int modeArea, biggestArea = 0;
    KScreen::ModePtr biggestMode;
    for (const KScreen::ModePtr &mode : modes) {
        modeArea = mode->size().width() * mode->size().height();
        if (modeArea < biggestArea) {
            continue;
        }
        if (modeArea == biggestArea && mode->refreshRate() < biggestMode->refreshRate()) {
            continue;
        }
        if (modeArea == biggestArea && mode->refreshRate() > biggestMode->refreshRate()) {
            biggestMode = mode;
            continue;
        }

        biggestArea = modeArea;
        biggestMode = mode;
    }

    return biggestMode;
}