File: screenbrightnessdisplaymodel.h

package info (click to toggle)
powerdevil 4%3A6.5.4-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,680 kB
  • sloc: cpp: 13,284; xml: 1,911; python: 1,204; sh: 19; makefile: 10
file content (59 lines) | stat: -rw-r--r-- 1,802 bytes parent folder | download | duplicates (2)
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
/*
 * SPDX-FileCopyrightText: 2024 Jakob Petsovits <jpetso@petsovits.com>
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

#pragma once

#include "screenbrightnessdisplaymodel.h"

#include <QAbstractListModel>
#include <QMap>

class ScreenBrightnessDisplayModel : public QAbstractListModel
{
    Q_OBJECT

public:
    enum {
        LabelRole = Qt::DisplayRole,
        DisplayNameRole = Qt::UserRole,
        IsInternalRole,
        BrightnessRole,
        MaxBrightnessRole,
    };

    explicit ScreenBrightnessDisplayModel(QObject *parent = nullptr);

    int rowCount(const QModelIndex &parent = QModelIndex()) const override;
    QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
    QHash<int, QByteArray> roleNames() const override;

    QModelIndex displayIndex(const QString &displayName) const;

    // Shown display names (i.e. included in the model, with valid index) are displays included in
    // known display names that also have display data set. Data for any display outside the list of
    // known display names will be removed / not set.
    void setKnownDisplayNames(const QStringList &displayNames);
    void setDisplayData(const QString &displayName, const QString &label, bool isInternal, int brightness, int maxBrightness);
    QStringList knownDisplayNamesWithMissingData() const;

    void onBrightnessChanged(const QString &displayName, int value);
    void onBrightnessRangeChanged(const QString &displayName, int max, int value);

private:
    struct Data {
        QString displayName;
        QString label;
        int brightness;
        int maxBrightness;
        bool isInternal;
    };

    void updateRows();

    QStringList m_knownDisplayNames;
    QStringList m_shownDisplayNames;
    QMap<QString, Data> m_displays;
};