~ubuntu-branches/ubuntu/wily/libkscreen/wily-proposed

« back to all changes in this revision

Viewing changes to backends/qscreen/qscreenoutput.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2014-10-01 15:47:21 UTC
  • Revision ID: package-import@ubuntu.com-20141001154721-96ng88bgtxpj8sjv
Tags: upstream-5.1.0.1
Import upstream version 5.1.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
19
#include "qscreenoutput.h"
 
20
#include "qscreenbackend.h"
 
21
 
 
22
#include <mode.h>
 
23
#include <edid.h>
 
24
 
 
25
#include <QGuiApplication>
 
26
#include <QScreen>
 
27
 
 
28
using namespace KScreen;
 
29
 
 
30
QScreenOutput::QScreenOutput(const QScreen *qscreen, QObject *parent)
 
31
    : QObject(parent)
 
32
    , m_qscreen(qscreen)
 
33
    , m_edid(0)
 
34
    , m_id(-1)
 
35
{
 
36
}
 
37
 
 
38
QScreenOutput::~QScreenOutput()
 
39
{
 
40
}
 
41
 
 
42
int QScreenOutput::id() const
 
43
{
 
44
    return m_id;
 
45
}
 
46
 
 
47
void QScreenOutput::setId(const int newId)
 
48
{
 
49
    m_id = newId;
 
50
}
 
51
 
 
52
KScreen::Edid *QScreenOutput::edid()
 
53
{
 
54
    if (!m_edid) {
 
55
        m_edid = new KScreen::Edid(0, 0, this);
 
56
    }
 
57
    return m_edid;
 
58
}
 
59
 
 
60
const QScreen *QScreenOutput::qscreen() const
 
61
{
 
62
    return m_qscreen;
 
63
}
 
64
 
 
65
Output *QScreenOutput::toKScreenOutput(Config *parent) const
 
66
{
 
67
    Output *output = new Output(parent);
 
68
    output->setId(m_id);
 
69
    output->setName(m_qscreen->name());
 
70
    updateKScreenOutput(output);
 
71
    return output;
 
72
}
 
73
 
 
74
void QScreenOutput::updateKScreenOutput(Output *output) const
 
75
{
 
76
    // Initialize primary output
 
77
    output->setEnabled(true);
 
78
    output->setConnected(true);
 
79
    output->setPrimary(QGuiApplication::primaryScreen() == m_qscreen);
 
80
 
 
81
    // Rotation - translate QScreen::primaryOrientation() to Output::rotation()
 
82
    if (m_qscreen->primaryOrientation() == Qt::PortraitOrientation) {
 
83
        // 90 degrees
 
84
        output->setRotation(Output::Right);
 
85
    } else if (m_qscreen->primaryOrientation() == Qt::InvertedLandscapeOrientation) {
 
86
        // 180 degrees
 
87
        output->setRotation(Output::Inverted);
 
88
    } else if (m_qscreen->primaryOrientation() == Qt::InvertedPortraitOrientation) {
 
89
        // 270 degrees
 
90
        output->setRotation(Output::Left);
 
91
    }
 
92
 
 
93
    // Physical size, geometry, etc.
 
94
    QSize mm;
 
95
    qreal physicalWidth;
 
96
    physicalWidth = m_qscreen->size().width() / (m_qscreen->physicalDotsPerInchX() / 25.4);
 
97
    mm.setWidth(qRound(physicalWidth));
 
98
    qreal physicalHeight;
 
99
    physicalHeight = m_qscreen->size().height() / (m_qscreen->physicalDotsPerInchY() / 25.4);
 
100
    mm.setHeight(qRound(physicalHeight));
 
101
    output->setSizeMm(mm);
 
102
    output->setPos(m_qscreen->availableGeometry().topLeft());
 
103
 
 
104
    // Modes: we create a single default mode and go with that
 
105
    Mode *mode = new Mode(output);
 
106
    const QString modeid = QStringLiteral("defaultmode");
 
107
    mode->setId(modeid);
 
108
    mode->setRefreshRate(m_qscreen->refreshRate());
 
109
    mode->setSize(m_qscreen->size());
 
110
 
 
111
    const QString modename = QString::number(m_qscreen->size().width()) + QStringLiteral("x") + QString::number(m_qscreen->size().height()) \
 
112
                             + QStringLiteral("@") + QString::number(m_qscreen->refreshRate());
 
113
    mode->setName(modename);
 
114
 
 
115
    ModeList modes;
 
116
    modes[modeid] = mode;
 
117
    output->setModes(modes);
 
118
    output->setCurrentModeId(modeid);
 
119
}
 
120
 
 
121
#include "qscreenoutput.moc"