[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [kde-workspace/plasma/luisgabriellima/pager-qml] plasma/desktop/applets/pager: Adding a separate mod
From: Luís_Gabriel_Lima <lampih () gmail ! com>
Date: 2012-07-17 18:27:13
Message-ID: 20120717182713.C3113A6094 () git ! kde ! org
[Download RAW message or body]
Git commit cb5f986525897ecf89b92aa2e7ed027114be265d by Luís Gabriel Lima.
Committed on 17/07/2012 at 20:16.
Pushed by luisgabriellima into branch 'plasma/luisgabriellima/pager-qml'.
Adding a separate model to the windows
Signed-off-by: Luís Gabriel Lima <lampih@gmail.com>
M +53 -11 plasma/desktop/applets/pager/model.cpp
M +24 -2 plasma/desktop/applets/pager/model.h
M +2 -2 plasma/desktop/applets/pager/pager.cpp
http://commits.kde.org/kde-workspace/cb5f986525897ecf89b92aa2e7ed027114be265d
diff --git a/plasma/desktop/applets/pager/model.cpp \
b/plasma/desktop/applets/pager/model.cpp index 679a1d3..d6f38c8 100644
--- a/plasma/desktop/applets/pager/model.cpp
+++ b/plasma/desktop/applets/pager/model.cpp
@@ -35,16 +35,12 @@ QHash<int, QByteArray> RectangleModel::roles() const
void RectangleModel::clear()
{
- beginResetModel();
m_rects.clear();
- endResetModel();
}
void RectangleModel::append(const QRectF &rect)
{
- beginInsertRows(QModelIndex(), rowCount(), rowCount());
m_rects.append(rect);
- endInsertRows();
}
QRectF &RectangleModel::rectAt(int index)
@@ -77,15 +73,62 @@ QVariant RectangleModel::data(const QModelIndex &index, int role) \
const }
+WindowModel::WindowModel(QObject *parent)
+ : RectangleModel(parent)
+{
+ setRoleNames(roles());
+}
+
+QHash<int, QByteArray> WindowModel::roles() const
+{
+ QHash<int, QByteArray> rectRoles = RectangleModel::roles();
+ rectRoles[IdRole] = "windowId";
+ return rectRoles;
+}
+
+void WindowModel::clear()
+{
+ beginResetModel();
+ RectangleModel::clear();
+ m_ids.clear();
+ endResetModel();
+}
+
+void WindowModel::append(WId windowId, const QRectF &rect)
+{
+ beginInsertRows(QModelIndex(), rowCount(), rowCount());
+ m_ids.append(windowId);
+ RectangleModel::append(rect);
+ endInsertRows();
+}
+
+WId WindowModel::idAt(int index) const
+{
+ return m_ids[index];
+}
+QVariant WindowModel::data(const QModelIndex &index, int role) const
+{
+ if (index.row() < 0 || index.row() >= rowCount())
+ return QVariant();
+
+ if (role >= RectangleModel::WidthRole && role < IdRole)
+ return RectangleModel::data(index, role);
+ else if (role == IdRole)
+ return int(m_ids[index.row()]);
+
+ return QVariant();
+}
+
+
VirtualDesktopModel::VirtualDesktopModel(QObject *parent)
: QAbstractListModel(parent)
{
setRoleNames(roles());
}
-RectangleModel *VirtualDesktopModel::windowsAt(int index) const
+WindowModel *VirtualDesktopModel::windowsAt(int index) const
{
- return qobject_cast<RectangleModel *>(m_windows[index]);
+ return qobject_cast<WindowModel *>(m_windows[index]);
}
QHash<int, QByteArray> VirtualDesktopModel::roles() const
@@ -126,13 +169,12 @@ void VirtualDesktopModel::clearWindowRects()
// append more windows model if the number of desktop has increased
for (int i = m_windows.count(); i < rowCount(); i++)
- m_windows.append(new RectangleModel(this));
+ m_windows.append(new WindowModel(this));
}
-void VirtualDesktopModel::appendWindowRect(int desktopId, WId window, const QRectF \
&rect) +void VirtualDesktopModel::appendWindowRect(int desktopId, WId windowId, const \
QRectF &rect) {
- Q_UNUSED(window); // XXX: add this role in the windows model
- windowsAt(desktopId)->append(rect);
+ windowsAt(desktopId)->append(windowId, rect);
QModelIndex i = index(desktopId);
emit dataChanged(i, i);
@@ -145,7 +187,7 @@ QVariant VirtualDesktopModel::data(const QModelIndex &index, int \
role) const if (role >= RectangleModel::WidthRole && role < WindowsRole) {
return m_desktops.data(index, role);
} else if (role == WindowsRole) {
- if (index.row() >= 0 && index.row() < m_windows.count())
+ if (index.row() >= 0 && index.row() < m_windows.count())
return QVariant::fromValue(m_windows[index.row()]);
else
return QVariant();
diff --git a/plasma/desktop/applets/pager/model.h \
b/plasma/desktop/applets/pager/model.h index c20da7e..92a64d8 100644
--- a/plasma/desktop/applets/pager/model.h
+++ b/plasma/desktop/applets/pager/model.h
@@ -37,7 +37,7 @@ public:
virtual QHash<int, QByteArray> roles() const;
virtual void clear();
- virtual void append(const QRectF &rect);
+ void append(const QRectF &rect);
QRectF &rectAt(int index);
int rowCount(const QModelIndex &parent = QModelIndex()) const;
@@ -48,6 +48,28 @@ private:
};
+class WindowModel : public RectangleModel
+{
+ Q_OBJECT
+public:
+ enum WindowRole {
+ IdRole = RectangleModel::YRole + 1,
+ };
+
+ WindowModel(QObject *parent = 0);
+
+ QHash<int, QByteArray> roles() const;
+ void clear();
+ void append(WId windowId, const QRectF &rect);
+ WId idAt(int index) const;
+
+ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
+
+private:
+ QList<WId> m_ids;
+};
+
+
class VirtualDesktopModel : public QAbstractListModel
{
Q_OBJECT
@@ -66,7 +88,7 @@ public:
void clearWindowRects();
void appendWindowRect(int desktopId, WId window, const QRectF &rect);
- RectangleModel *windowsAt(int index) const;
+ WindowModel *windowsAt(int index) const;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
int rowCount(const QModelIndex &parent = QModelIndex()) const;
diff --git a/plasma/desktop/applets/pager/pager.cpp \
b/plasma/desktop/applets/pager/pager.cpp index 9cb1a60..68d8ead 100644
--- a/plasma/desktop/applets/pager/pager.cpp
+++ b/plasma/desktop/applets/pager/pager.cpp
@@ -857,11 +857,11 @@ void Pager::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
} else if (m_dragStartDesktop != -1 &&
(event->pos() - m_dragOriginalPos).toPoint().manhattanLength() > \
KGlobalSettings::dndEventDelay()) {
m_dragId = 0; // prevent us from going through this more than once
- RectangleModel *windows= m_pagerModel->windowsAt(m_dragStartDesktop);
+ WindowModel *windows= m_pagerModel->windowsAt(m_dragStartDesktop);
for (int k = windows->rowCount() - 1; k >= 0 ; k--) {
if (windows->rectAt(k).contains(m_dragOriginalPos.toPoint())) {
m_dragOriginal = windows->rectAt(k);
- //m_dragId = windows->widAt(k);
+ m_dragId = windows->idAt(k);
event->accept();
break;
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic