File indexing completed on 2024-05-19 16:34:53
0001 /* 0002 KWin - the KDE window manager 0003 This file is part of the KDE project. 0004 0005 SPDX-FileCopyrightText: 2009 Martin Gräßlin <mgraesslin@kde.org> 0006 0007 SPDX-License-Identifier: GPL-2.0-or-later 0008 */ 0009 0010 #pragma once 0011 #include "tabboxhandler.h" 0012 0013 #include <QModelIndex> 0014 /** 0015 * @file 0016 * This file defines the class ClientModel, the model for TabBoxClients. 0017 * 0018 * @author Martin Gräßlin <mgraesslin@kde.org> 0019 * @since 4.4 0020 */ 0021 0022 namespace KWin 0023 { 0024 namespace TabBox 0025 { 0026 0027 /** 0028 * The model for TabBoxClients used in TabBox. 0029 * 0030 * @author Martin Gräßlin <mgraesslin@kde.org> 0031 * @since 4.4 0032 */ 0033 class ClientModel 0034 : public QAbstractItemModel 0035 { 0036 Q_OBJECT 0037 public: 0038 enum { 0039 ClientRole = Qt::UserRole, ///< The TabBoxClient 0040 CaptionRole = Qt::UserRole + 1, ///< The caption of TabBoxClient 0041 DesktopNameRole = Qt::UserRole + 2, ///< The name of the desktop the TabBoxClient is on 0042 IconRole = Qt::UserRole + 3, // TODO: to be removed 0043 WIdRole = Qt::UserRole + 5, ///< The window ID of TabBoxClient 0044 MinimizedRole = Qt::UserRole + 6, ///< TabBoxClient is minimized 0045 CloseableRole = Qt::UserRole + 7 ///< TabBoxClient can be closed 0046 }; 0047 explicit ClientModel(QObject *parent = nullptr); 0048 ~ClientModel() override; 0049 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; 0050 int columnCount(const QModelIndex &parent = QModelIndex()) const override; 0051 int rowCount(const QModelIndex &parent = QModelIndex()) const override; 0052 QModelIndex parent(const QModelIndex &child) const override; 0053 QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; 0054 QHash<int, QByteArray> roleNames() const override; 0055 Q_INVOKABLE QString longestCaption() const; 0056 0057 /** 0058 * @param client The TabBoxClient whose index should be returned 0059 * @return Returns the ModelIndex of given TabBoxClient or an invalid ModelIndex 0060 * if the model does not contain the given TabBoxClient. 0061 */ 0062 QModelIndex index(QWeakPointer<TabBoxClient> client) const; 0063 0064 /** 0065 * Generates a new list of TabBoxClients based on the current config. 0066 * Calling this method will reset the model. If partialReset is true 0067 * the top of the list is kept as a starting point. If not the 0068 * current active client is used as the starting point to generate the 0069 * list. 0070 * @param desktop The desktop for which the list should be created 0071 * @param partialReset Keep the currently selected client or regenerate everything 0072 */ 0073 void createClientList(int desktop, bool partialReset = false); 0074 /** 0075 * This method is provided as a overload for current desktop 0076 * @see createClientList 0077 */ 0078 void createClientList(bool partialReset = false); 0079 /** 0080 * @return Returns the current list of TabBoxClients. 0081 */ 0082 TabBoxClientList clientList() const 0083 { 0084 return m_mutableClientList; 0085 } 0086 0087 public Q_SLOTS: 0088 void close(int index); 0089 /** 0090 * Activates the client at @p index and closes the TabBox. 0091 * @param index The row index 0092 */ 0093 void activate(int index); 0094 0095 private: 0096 void createFocusChainClientList(int desktop, const QSharedPointer<TabBoxClient> &start, 0097 TabBoxClientList &stickyClients); 0098 void createStackingOrderClientList(int desktop, const QSharedPointer<TabBoxClient> &start, 0099 TabBoxClientList &stickyClients); 0100 0101 TabBoxClientList m_clientList; 0102 TabBoxClientList m_mutableClientList; 0103 }; 0104 0105 } // namespace Tabbox 0106 } // namespace KWin