~neon/project-neon/kscreen

« back to all changes in this revision

Viewing changes to kcm/src/qmloutput.cpp

  • Committer: Dan Vrátil
  • Date: 2012-11-13 11:22:10 UTC
  • mfrom: (0.1.48)
  • Revision ID: git-v1:14fdbb224dc8a85b623b394662458a62675e977c
Merge branch 'kcm_import'

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    <one line to give the library's name and an idea of what it does.>
 
3
    Copyright (C) 2012  Dan Vratil <dvratil@redhat.com>
 
4
 
 
5
    This library is free software; you can redistribute it and/or
 
6
    modify it under the terms of the GNU Lesser General Public
 
7
    License as published by the Free Software Foundation; either
 
8
    version 2.1 of the License, or (at your option) any later version.
 
9
 
 
10
    This library is distributed in the hope that it will be useful,
 
11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
13
    Lesser General Public License for more details.
 
14
 
 
15
    You should have received a copy of the GNU Lesser General Public
 
16
    License along with this library; if not, write to the Free Software
 
17
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
18
*/
 
19
 
 
20
 
 
21
#include "qmloutput.h"
 
22
#include <kscreen/output.h>
 
23
#include <KDebug>
 
24
 
 
25
#include <QStandardItem>
 
26
#include <QStandardItemModel>
 
27
#include <QStringBuilder>
 
28
 
 
29
Q_DECLARE_METATYPE(KScreen::Mode*);
 
30
 
 
31
QMLOutput::QMLOutput():
 
32
    QDeclarativeItem(),
 
33
    m_output(0),
 
34
    m_cloneOf(0),
 
35
    m_modesModel(new QStandardItemModel(this))
 
36
{
 
37
 
 
38
}
 
39
 
 
40
QMLOutput::~QMLOutput()
 
41
{
 
42
 
 
43
}
 
44
 
 
45
void QMLOutput::setOutput(KScreen::Output* output)
 
46
{
 
47
    m_output = output;
 
48
 
 
49
    QList<KScreen::Mode*> modes = m_output->modes().values();
 
50
    Q_FOREACH (KScreen::Mode *mode, modes) {
 
51
        QList<QStandardItem*> items = m_modesModel->findItems(mode->name(), Qt::MatchExactly, 0);
 
52
        if (items.isEmpty()) {
 
53
          QStandardItem *item = new QStandardItem(mode->name());
 
54
          item->setData(mode->size(), QMLOutput::SizeRole);
 
55
 
 
56
          m_modesModel->appendRow(item);
 
57
          items << item;
 
58
        }
 
59
 
 
60
        QStandardItem *modeItem = new QStandardItem(QString::number(mode->refreshRate(), 'f', 1) % QLatin1String("Hz"));
 
61
        modeItem->setData(mode->refreshRate(), QMLOutput::RefreshRateRole);
 
62
        modeItem->setData(mode->id(), QMLOutput::ModeIdRole);
 
63
        modeItem->setData(QVariant::fromValue(mode), QMLOutput::ModeRole);
 
64
 
 
65
        QStandardItem *item = items.first();
 
66
        item->appendRow(modeItem);
 
67
    }
 
68
 
 
69
    connect(output, SIGNAL(clonesChanged()), SIGNAL(changed()));
 
70
    connect(output, SIGNAL(currentModeChanged()), SIGNAL(changed()));
 
71
    connect(output, SIGNAL(isEnabledChanged()), SIGNAL(changed()));
 
72
    connect(output, SIGNAL(isPrimaryChanged()), SIGNAL(changed()));
 
73
    connect(output, SIGNAL(outputChanged()), SIGNAL(changed()));
 
74
    connect(output, SIGNAL(posChanged()), SIGNAL(changed()));
 
75
    connect(output, SIGNAL(rotationChanged()), SIGNAL(changed()));
 
76
 
 
77
    Q_EMIT outputChanged();
 
78
}
 
79
 
 
80
KScreen::Output* QMLOutput::output() const
 
81
{
 
82
    return m_output;
 
83
}
 
84
 
 
85
void QMLOutput::setCloneOf(QMLOutput* other)
 
86
{
 
87
    m_cloneOf = other;
 
88
 
 
89
    Q_EMIT cloneOfChanged();
 
90
}
 
91
 
 
92
QMLOutput* QMLOutput::cloneOf() const
 
93
{
 
94
    return m_cloneOf;
 
95
}
 
96
 
 
97
QAbstractItemModel* QMLOutput::modesModel()
 
98
{
 
99
    return m_modesModel;
 
100
}