GCC Code Coverage Report


Directory: ./
File: backends/qscreen/qscreenoutput.cpp
Date: 2023-04-20 22:59:23
Exec Total Coverage
Lines: 56 63 88.9%
Branches: 6 12 50.0%

Line Branch Exec Source
1 /*************************************************************************************
2 * Copyright 2014 Sebastian K├╝gler <sebas@kde.org> *
3 * *
4 * This library is free software; you can redistribute it and/or *
5 * modify it under the terms of the GNU Lesser General Public *
6 * License as published by the Free Software Foundation; either *
7 * version 2.1 of the License, or (at your option) any later version. *
8 * *
9 * This library is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
12 * Lesser General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU Lesser General Public *
15 * License along with this library; if not, write to the Free Software *
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
17 *************************************************************************************/
18 #include "qscreenoutput.h"
19 #include "qscreenbackend.h"
20
21 #include "mode.h"
22 #include "output.h"
23
24 #include <QGuiApplication>
25 #include <QScreen>
26
27 using namespace Disman;
28
29 2 QScreenOutput::QScreenOutput(const QScreen* qscreen, QObject* parent)
30 : QObject(parent)
31 2 , m_qscreen(qscreen)
32 2 , m_id(-1)
33 {
34 2 }
35
36 QScreenOutput::~QScreenOutput()
37 {
38 }
39
40 18 int QScreenOutput::id() const
41 {
42 18 return m_id;
43 }
44
45 2 void QScreenOutput::set_id(const int newId)
46 {
47 2 m_id = newId;
48 2 }
49
50 16 const QScreen* QScreenOutput::qscreen() const
51 {
52 16 return m_qscreen;
53 }
54
55 8 std::string QScreenOutput::description() const
56 {
57 8 std::string ret;
58
59
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 8 times.
8 if (auto vendor = m_qscreen->manufacturer().toStdString(); vendor.size()) {
60 ret += vendor + " ";
61 8 }
62
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 8 times.
8 if (auto model = m_qscreen->model().toStdString(); model.size()) {
63 ret += model + " ";
64 8 }
65
66
1/2
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
8 if (!ret.size()) {
67 8 return m_qscreen->name().toStdString();
68 }
69 return ret + "(" + m_qscreen->name().toStdString() + ")";
70 8 }
71
72 8 OutputPtr QScreenOutput::toDismanOutput() const
73 {
74 8 OutputPtr output(new Output);
75 8 output->set_id(m_id);
76 8 output->set_name(m_qscreen->name().toStdString());
77
78 8 auto const descr = description();
79 8 output->set_description(descr);
80 8 output->set_hash(descr);
81
82 8 updateDismanOutput(output);
83 8 return output;
84 8 }
85
86 24 void QScreenOutput::updateDismanOutput(OutputPtr& output) const
87 {
88 24 output->set_enabled(true);
89
90 // Rotation - translate QScreen::primaryOrientation() to Output::rotation()
91
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
24 if (m_qscreen->primaryOrientation() == Qt::PortraitOrientation) {
92 // 90 degrees
93 output->set_rotation(Output::Right);
94
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
24 } else if (m_qscreen->primaryOrientation() == Qt::InvertedLandscapeOrientation) {
95 // 180 degrees
96 output->set_rotation(Output::Inverted);
97
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
24 } else if (m_qscreen->primaryOrientation() == Qt::InvertedPortraitOrientation) {
98 // 270 degrees
99 output->set_rotation(Output::Left);
100 }
101
102 // Physical size, geometry, etc.
103 24 QSize mm;
104 qreal physicalWidth;
105 24 physicalWidth = m_qscreen->size().width() / (m_qscreen->physicalDotsPerInchX() / 25.4);
106 24 mm.setWidth(qRound(physicalWidth));
107 qreal physicalHeight;
108 24 physicalHeight = m_qscreen->size().height() / (m_qscreen->physicalDotsPerInchY() / 25.4);
109 24 mm.setHeight(qRound(physicalHeight));
110 24 output->set_physical_size(mm);
111 24 output->set_position(m_qscreen->availableGeometry().topLeft());
112
113 // Modes: we create a single default mode and go with that
114 24 ModePtr mode(new Mode);
115 24 std::string const modeid = "defaultmode";
116 24 mode->set_id(modeid);
117 24 mode->set_refresh(m_qscreen->refreshRate() * 1000);
118 24 mode->set_size(m_qscreen->size());
119
120 48 const QString modename = QString::number(m_qscreen->size().width()) + QLatin1String("x")
121 96 + QString::number(m_qscreen->size().height()) + QLatin1String("@")
122 72 + QString::number(m_qscreen->refreshRate());
123 24 mode->set_name(modename.toStdString());
124
125 24 ModeMap modes;
126 24 modes[modeid] = mode;
127 24 output->set_modes(modes);
128 24 output->set_mode(mode);
129 24 }
130