[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 VirtualDesktop
From: Luís_Gabriel_Lima <lampih () gmail ! com>
Date: 2012-07-10 22:16:29
Message-ID: 20120710221629.E2A65A60A6 () git ! kde ! org
[Download RAW message or body]
Git commit 10626ce3eb57b86d893028c0ad6014093b9791f8 by Luís Gabriel Lima.
Committed on 08/07/2012 at 23:10.
Pushed by luisgabriellima into branch 'plasma/luisgabriellima/pager-qml'.
Adding VirtualDesktopModel
This model will be used to do the communication between the pager c++
backend and the QML UI.
Signed-off-by: Luís Gabriel Lima <lampih@gmail.com>
M +1 -0 plasma/desktop/applets/pager/CMakeLists.txt
A +79 -0 plasma/desktop/applets/pager/model.cpp [License: GPL (v2+)]
A +50 -0 plasma/desktop/applets/pager/model.h [License: GPL (v2+)]
http://commits.kde.org/kde-workspace/10626ce3eb57b86d893028c0ad6014093b9791f8
diff --git a/plasma/desktop/applets/pager/CMakeLists.txt b/plasma/desktop/applets/pager/CMakeLists.txt
index bc35a99..9b24222 100644
--- a/plasma/desktop/applets/pager/CMakeLists.txt
+++ b/plasma/desktop/applets/pager/CMakeLists.txt
@@ -1,6 +1,7 @@
project(plasma-pager)
set(pager_SRCS
+ model.cpp
pager.cpp)
kde4_add_ui_files(pager_SRCS pagerConfig.ui)
diff --git a/plasma/desktop/applets/pager/model.cpp b/plasma/desktop/applets/pager/model.cpp
new file mode 100644
index 0000000..081c09e
--- /dev/null
+++ b/plasma/desktop/applets/pager/model.cpp
@@ -0,0 +1,79 @@
+/*
+ * Copyright 2012 Luís Gabriel Lima <lampih@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "model.h"
+
+VirtualDesktopModel::VirtualDesktopModel(QObject *parent)
+ : QAbstractListModel(parent)
+{
+ QHash<int, QByteArray> roles;
+ roles[WidthRole] = "width";
+ roles[HeightRole] = "height";
+ roles[XRole] = "x";
+ roles[YRole] = "y";
+ setRoleNames(roles);
+ m_currentIndex = 0;
+}
+
+int VirtualDesktopModel::rowCount(const QModelIndex &parent) const
+{
+ return m_rects.count();
+}
+
+QVariant VirtualDesktopModel::data(const QModelIndex &index, int role) const
+{
+ if (index.row() < 0 || index.row() > m_rects.count())
+ return QVariant();
+
+ const QRectF &rect = m_rects[index.row()];
+ if (role == WidthRole)
+ return rect.width();
+ else if (role == HeightRole)
+ return rect.height();
+ else if (role == XRole)
+ return rect.x();
+ else if (role == YRole)
+ return rect.y();
+
+ return QVariant();
+}
+
+void VirtualDesktopModel::append(const QRectF &rect)
+{
+ beginInsertRows(QModelIndex(), m_rects.count(), m_rects.count());
+ m_rects << rect;
+ endInsertRows();
+}
+
+void VirtualDesktopModel::setList(const QList<QRectF> &list)
+{
+ beginResetModel();
+ m_rects = list;
+ endResetModel();
+}
+
+void VirtualDesktopModel::clear()
+{
+ beginResetModel();
+ return m_rects.clear();
+ endResetModel();
+}
+
+QRectF &VirtualDesktopModel::operator[](int i)
+{
+ return m_rects[i];
+}
diff --git a/plasma/desktop/applets/pager/model.h b/plasma/desktop/applets/pager/model.h
new file mode 100644
index 0000000..862814a
--- /dev/null
+++ b/plasma/desktop/applets/pager/model.h
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2012 Luís Gabriel Lima <lampih@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef MODEL_H
+#define MODEL_H
+
+#include <QAbstractListModel>
+#include <QRectF>
+
+class VirtualDesktopModel : public QAbstractListModel
+{
+ Q_OBJECT
+public:
+ enum RectangleRoles {
+ WidthRole = Qt::UserRole + 1,
+ HeightRole,
+ XRole,
+ YRole,
+ };
+
+ VirtualDesktopModel(QObject *parent = 0);
+
+ int rowCount(const QModelIndex &parent = QModelIndex()) const;
+ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
+
+ void append(const QRectF &rect);
+ void setList(const QList<QRectF>& list);
+ void clear();
+ QRectF &operator[](int i);
+
+private:
+ int m_currentIndex;
+ QList<QRectF> m_rects;
+};
+
+#endif // MODEL_H
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic