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
*********************************************************************/
22
#include "clientmodel.h"
24
#include "tabboxconfig.h"
25
#include "tabboxhandler.h"
27
#include <QTextStream>
38
ClientModel::ClientModel(QObject* parent)
39
: QAbstractItemModel(parent)
43
ClientModel::~ClientModel()
47
QVariant ClientModel::data(const QModelIndex& index, int role) const
52
if (m_clientList.isEmpty()) {
53
if (role == EmptyRole)
56
return i18n("*** No Windows ***");
59
int clientIndex = index.row() * columnCount() + index.column();
60
if (clientIndex >= m_clientList.count())
65
return m_clientList[ clientIndex ]->caption();
67
return qVariantFromValue((void*)m_clientList[ clientIndex ]);
68
case DesktopNameRole: {
69
return tabBox->desktopName(m_clientList[ clientIndex ]);
74
return qulonglong(m_clientList[ clientIndex ]->window());
76
return m_clientList[ clientIndex ]->isMinimized();
82
int ClientModel::columnCount(const QModelIndex& parent) const
86
switch(tabBox->config().layout()) {
87
case TabBoxConfig::HorizontalLayout:
88
count = m_clientList.count();
90
case TabBoxConfig::VerticalLayout:
93
case TabBoxConfig::HorizontalVerticalLayout:
94
count = qRound(sqrt(float(m_clientList.count())));
95
if (count * count < m_clientList.count())
99
return qMax(count, 1);
102
int ClientModel::rowCount(const QModelIndex& parent) const
106
switch(tabBox->config().layout()) {
107
case TabBoxConfig::HorizontalLayout:
110
case TabBoxConfig::VerticalLayout:
111
count = m_clientList.count();
113
case TabBoxConfig::HorizontalVerticalLayout:
114
count = qRound(sqrt(float(m_clientList.count())));
117
return qMax(count, 1);
120
QModelIndex ClientModel::parent(const QModelIndex& child) const
123
return QModelIndex();
126
QModelIndex ClientModel::index(int row, int column, const QModelIndex& parent) const
129
int index = row * columnCount() + column;
130
if (index >= m_clientList.count() && !m_clientList.isEmpty())
131
return QModelIndex();
132
return createIndex(row, column);
135
QModelIndex ClientModel::index(TabBoxClient* client) const
137
if (!m_clientList.contains(client))
138
return QModelIndex();
139
int index = m_clientList.indexOf(client);
140
int row = index / columnCount();
141
int column = index % columnCount();
142
return createIndex(row, column);
145
void ClientModel::createClientList(bool partialReset)
147
createClientList(tabBox->currentDesktop(), partialReset);
150
void ClientModel::createClientList(int desktop, bool partialReset)
152
TabBoxClient* start = tabBox->activeClient();
153
// TODO: new clients are not added at correct position
154
if (partialReset && !m_clientList.isEmpty())
155
start = m_clientList.first();
157
m_clientList.clear();
159
switch(tabBox->config().clientSwitchingMode()) {
160
case TabBoxConfig::FocusChainSwitching: {
161
TabBoxClient* c = tabBox->nextClientFocusChain(start);
162
TabBoxClient* stop = c;
164
TabBoxClient* add = tabBox->clientToAddToList(c, desktop,
165
tabBox->config().clientListMode() == TabBoxConfig::AllDesktopsClientList ||
166
tabBox->config().clientListMode() == TabBoxConfig::AllDesktopsApplicationList);
169
m_clientList.removeAll(add);
170
m_clientList.prepend(add);
174
c = tabBox->nextClientFocusChain(c);
181
case TabBoxConfig::StackingOrderSwitching: {
182
// TODO: needs improvement
183
TabBoxClientList stacking = tabBox->stackingOrder();
184
TabBoxClient* c = stacking.first();
185
TabBoxClient* stop = c;
188
TabBoxClient* add = tabBox->clientToAddToList(c, desktop,
189
tabBox->config().clientListMode() == TabBoxConfig::AllDesktopsClientList ||
190
tabBox->config().clientListMode() == TabBoxConfig::AllDesktopsApplicationList);
193
m_clientList.removeAll(add);
194
m_clientList.prepend(add);
198
if (index >= stacking.size() - 1) {
201
c = stacking[++index];
210
if (tabBox->config().isShowDesktop()) {
211
TabBoxClient* desktopClient = tabBox->desktopClient();
213
m_clientList.append(desktopClient);
218
} // namespace Tabbox