1
/********************************************************************
2
KWin - the KDE window manager
3
This file is part of the KDE project.
5
Copyright (C) 2009 Martin Gräßlin <kde@martin-graesslin.com>
7
This program is free software; you can redistribute it and/or modify
8
it under the terms of the GNU General Public License as published by
9
the Free Software Foundation; either version 2 of the License, or
10
(at your option) any later version.
12
This program is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
GNU General Public License for more details.
17
You should have received a copy of the GNU General Public License
18
along with this program. If not, see <http://www.gnu.org/licenses/>.
19
*********************************************************************/
21
#include "desktopmodel.h"
23
#include "clientmodel.h"
24
#include "tabboxconfig.h"
25
#include "tabboxhandler.h"
34
DesktopModel::DesktopModel(QObject* parent)
35
: QAbstractItemModel(parent)
39
DesktopModel::~DesktopModel()
43
QVariant DesktopModel::data(const QModelIndex& index, int role) const
48
int desktopIndex = index.row() * columnCount() + index.column();
49
if (desktopIndex >= m_desktopList.count())
54
return tabBox->desktopName(m_desktopList[ desktopIndex ]);
56
return m_desktopList[ desktopIndex ];
58
return qVariantFromValue((void*)m_clientModels[ m_desktopList[ desktopIndex ] ]);
64
int DesktopModel::columnCount(const QModelIndex& parent) const
68
switch(tabBox->config().layout()) {
69
case TabBoxConfig::HorizontalLayout:
70
count = m_desktopList.count();
72
case TabBoxConfig::VerticalLayout:
75
case TabBoxConfig::HorizontalVerticalLayout:
76
count = qRound(sqrt(float(m_desktopList.count())));
77
if (count * count < m_desktopList.count())
79
// TODO: pager layout?
82
return qMax(count, 1);
85
int DesktopModel::rowCount(const QModelIndex& parent) const
89
switch(tabBox->config().layout()) {
90
case TabBoxConfig::HorizontalLayout:
93
case TabBoxConfig::VerticalLayout:
94
count = m_desktopList.count();
96
case TabBoxConfig::HorizontalVerticalLayout:
97
count = qRound(sqrt(float(m_desktopList.count())));
98
// TODO: pager layout?
101
return qMax(count, 1);
104
QModelIndex DesktopModel::parent(const QModelIndex& child) const
107
return QModelIndex();
110
QModelIndex DesktopModel::index(int row, int column, const QModelIndex& parent) const
113
int index = row * columnCount() + column;
114
if (index > m_desktopList.count() || m_desktopList.isEmpty())
115
return QModelIndex();
116
return createIndex(row, column);
119
QModelIndex DesktopModel::desktopIndex(int desktop) const
121
if (desktop > m_desktopList.count())
122
return QModelIndex();
123
int index = m_desktopList.indexOf(desktop);
124
int row = index / columnCount();
125
int column = index % columnCount();
126
return createIndex(row, column);
129
void DesktopModel::createDesktopList()
131
m_desktopList.clear();
132
qDeleteAll(m_clientModels);
133
m_clientModels.clear();
135
switch(tabBox->config().desktopSwitchingMode()) {
136
case TabBoxConfig::MostRecentlyUsedDesktopSwitching: {
137
int desktop = tabBox->currentDesktop();
139
m_desktopList.append(desktop);
140
ClientModel* clientModel = new ClientModel(this);
141
clientModel->createClientList(desktop);
142
m_clientModels.insert(desktop, clientModel);
143
desktop = tabBox->nextDesktopFocusChain(desktop);
144
} while (desktop != tabBox->currentDesktop());
147
case TabBoxConfig::StaticDesktopSwitching: {
148
for (int i = 1; i <= tabBox->numberOfDesktops(); i++) {
149
m_desktopList.append(i);
150
ClientModel* clientModel = new ClientModel(this);
151
clientModel->createClientList(i);
152
m_clientModels.insert(i, clientModel);
160
} // namespace Tabbox