2
<one line to give the program's name and a brief idea of what it does.>
3
Copyright (C) 2012 Dan Vratil <dan@progdan.cz>
5
This program is free software: you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation, either version 3 of the License, or
8
(at your option) any later version.
10
This program 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
13
GNU General Public License for more details.
15
You should have received a copy of the GNU General Public License
16
along with this program. If not, see <http://www.gnu.org/licenses/>.
20
#include "modeselectionwidget.h"
23
#include <QGridLayout>
24
#include <kscreen/output.h>
27
#include "qmloutput.h"
28
#include "modesproxymodel.h"
29
#include "resolutionsortmodel.h"
31
ModeSelectionWidget::ModeSelectionWidget(QGraphicsItem *parent, Qt::WindowFlags wFlags):
32
QGraphicsProxyWidget(parent, wFlags),
35
m_resolutionsModel = new ResolutionSortModel(this);
37
m_resolutionsView = new QListView();
38
m_resolutionsView->setModel(m_resolutionsModel);
39
connect(m_resolutionsView, SIGNAL(clicked(QModelIndex)), SLOT(resolutionChanged(QModelIndex)));
41
m_refreshRatesModel = new ModesProxyModel(this);
43
m_refreshRatesView = new QListView();
44
m_refreshRatesView->setModel(m_refreshRatesModel);
45
connect(m_resolutionsView, SIGNAL(clicked(QModelIndex)), SLOT(refreshRateChanged()));
47
QWidget *rootWidget = new QWidget();
49
QGridLayout *mainLayout = new QGridLayout(rootWidget);
50
mainLayout->addWidget(m_resolutionsView, 0, 0);
51
mainLayout->addWidget(m_refreshRatesView, 0, 1);
52
rootWidget->setLayout(mainLayout);
54
setWidget(rootWidget);
57
ModeSelectionWidget::~ModeSelectionWidget()
63
void ModeSelectionWidget::setOutput(QMLOutput *output)
71
m_resolutionsModel->setSourceModel(output->modesModel());
72
m_resolutionsModel->sort(0, Qt::DescendingOrder);
74
m_refreshRatesModel->setSourceModel(m_resolutionsModel);
76
KScreen::Mode *currentMode = m_output->output()->mode(m_output->output()->currentMode());
81
for (int i = 0; i < m_resolutionsModel->rowCount(); i++) {
82
QSize size = m_resolutionsModel->index(i, 0).data(QMLOutput::SizeRole).toSize();
84
if (size == currentMode->size()) {
85
QModelIndex index = m_resolutionsModel->index(i, 0);
86
m_resolutionsView->setCurrentIndex(index);
87
resolutionChanged(index);
93
QMLOutput *ModeSelectionWidget::output() const
98
void ModeSelectionWidget::resolutionChanged(const QModelIndex &index)
100
m_refreshRatesModel->setSourceModelCurrentRow(index.row());
102
if (!m_refreshRatesView->currentIndex().isValid()) {
103
m_refreshRatesView->setCurrentIndex(m_refreshRatesModel->index(0, 0));
105
refreshRateChanged();
109
void ModeSelectionWidget::refreshRateChanged()
115
QModelIndex proxyModelIndex = m_resolutionsModel->index(m_resolutionsView->currentIndex().row(), 0);
116
QModelIndex parentIndex = m_resolutionsModel->mapToSource(proxyModelIndex);
117
QModelIndex modelIndex = m_refreshRatesView->model()->index(m_refreshRatesView->currentIndex().row(), 0, parentIndex);
119
int modeId = m_refreshRatesView->model()->data(modelIndex, QMLOutput::ModeIdRole).toInt();
121
QModelIndex proxyModelIndex = m_resolutionsModel->index(m_resolutionsView->currentIndex().row(), 0);
122
QModelIndex parentIndex = m_resolutionsModel->mapToSource(proxyModelIndex);
123
modeId = m_output->modesModel()->index(0, 0, parentIndex).data(QMLOutput::ModeIdRole).toInt();
130
m_output->output()->setCurrentMode(modeId);
131
m_refreshRatesView->repaint();
134
#include "modeselectionwidget.moc"
b'\\ No newline at end of file'