Commit 8c1b75a7 authored by Marco Martin's avatar Marco Martin

single role for location

parent 39a4ae57
......@@ -58,8 +58,7 @@ QHash<int, QByteArray> ApplicationListModel::roleNames() const
roleNames[ApplicationStorageIdRole] = "ApplicationStorageIdRole";
roleNames[ApplicationEntryPathRole] = "ApplicationEntryPathRole";
roleNames[ApplicationOriginalRowRole] = "ApplicationOriginalRowRole";
roleNames[ApplicationFavoriteRole] = "ApplicationFavoriteRole";
roleNames[ApplicationOnDesktopRole] = "ApplicationOnDesktopRole";
roleNames[ApplicationLocationRole] = "ApplicationLocationRole";
return roleNames;
}
......@@ -146,14 +145,14 @@ void ApplicationListModel::loadApplications()
auto it = m_appPositions.constFind(service->storageId());
if (it != m_appPositions.constEnd()) {
//TODO: proper bookmarks
data.favorite = (*it) < 6;
data.location = (*it) < 6 ? Favorites : Grid;
orderedList[*it] = data;
} else {
//TODO: proper bookmarks
data.favorite = ++i + m_appPositions.size() < 6;
data.location = (++i + m_appPositions.size() < 6) ? Favorites : Grid;
unorderedList << data;
}
if (data.favorite) {
if (data.location == Favorites) {
++m_favoriteCount;
}
emit favoriteCountChanged();
......@@ -194,10 +193,8 @@ QVariant ApplicationListModel::data(const QModelIndex &index, int role) const
return m_applicationList.at(index.row()).entryPath;
case ApplicationOriginalRowRole:
return index.row();
case ApplicationOnDesktopRole:
return m_applicationList.at(index.row()).desktop;
case ApplicationFavoriteRole:
return m_applicationList.at(index.row()).favorite;
case ApplicationLocationRole:
return m_applicationList.at(index.row()).location;
default:
return QVariant();
......@@ -225,43 +222,26 @@ void ApplicationListModel::moveRow(const QModelIndex& /* sourceParent */, int so
moveItem(sourceRow, destinationChild);
}
void ApplicationListModel::setFavoriteItem(int row, bool favorite)
void ApplicationListModel::setLocation(int row, LauncherLocation location)
{
if (row < 0 || row >= m_applicationList.length()) {
return;
}
ApplicationData &data = m_applicationList[row];
if (data.favorite == favorite) {
if (data.location == location) {
return;
}
setDesktopItem(row, false);
data.favorite = favorite;
if (data.favorite) {
if (location == Favorites) {
++m_favoriteCount;
} else {
emit favoriteCountChanged();
} else if (data.location == Favorites) {
m_favoriteCount = qMax(0, m_favoriteCount - 1);
}
emit favoriteCountChanged();
emit dataChanged(index(row, 0), index(row, 0));
}
void ApplicationListModel::setDesktopItem(int row, bool desktop)
{
if (row < 0 || row >= m_applicationList.length()) {
return;
}
ApplicationData &data = m_applicationList[row];
if (data.desktop == desktop) {
return;
emit favoriteCountChanged();
}
setFavoriteItem(row, false);
data.desktop = desktop;
data.location = location;
emit dataChanged(index(row, 0), index(row, 0));
}
......
......@@ -27,13 +27,14 @@
class QString;
class ApplicationListModel;
struct ApplicationData {
QString name;
QString icon;
QString storageId;
QString entryPath;
bool favorite = false;
bool desktop = false;
int location = 0; //FIXME
};
class ApplicationListModel : public QAbstractListModel {
......@@ -44,6 +45,22 @@ class ApplicationListModel : public QAbstractListModel {
Q_PROPERTY(QStringList appOrder READ appOrder WRITE setAppOrder NOTIFY appOrderChanged)
public:
enum LauncherLocation {
Grid = 0,
Favorites,
Desktop
};
Q_ENUM(LauncherLocation)
enum Roles {
ApplicationNameRole = Qt::UserRole + 1,
ApplicationIconRole,
ApplicationStorageIdRole,
ApplicationEntryPathRole,
ApplicationOriginalRowRole,
ApplicationLocationRole
};
ApplicationListModel(QObject *parent = nullptr);
~ApplicationListModel() override;
......@@ -60,21 +77,10 @@ public:
QHash<int, QByteArray> roleNames() const Q_DECL_OVERRIDE;
enum Roles {
ApplicationNameRole = Qt::UserRole + 1,
ApplicationIconRole,
ApplicationStorageIdRole,
ApplicationEntryPathRole,
ApplicationOriginalRowRole,
ApplicationFavoriteRole, //TODO: a single role for parent
ApplicationOnDesktopRole
};
QStringList appOrder() const;
void setAppOrder(const QStringList &order);
Q_INVOKABLE void setFavoriteItem(int row, bool favorite);
Q_INVOKABLE void setDesktopItem(int row, bool desktop);
Q_INVOKABLE void setLocation(int row, LauncherLocation location);
Q_INVOKABLE void moveItem(int row, int order);
......
......@@ -27,7 +27,7 @@
HomeScreen::HomeScreen(QObject *parent, const QVariantList &args)
: Plasma::Containment(parent, args)
{
qmlRegisterType<ApplicationListModel>();
qmlRegisterUncreatableType<ApplicationListModel>("org.kde.phone.homescreen", 1, 0, "ApplicationListModel", QStringLiteral("Cannot create item of type ApplicationListModel"));
m_applicationListModel = new ApplicationListModel(this);
setHasConfigurationInterface(true);
}
......
......@@ -27,6 +27,8 @@ import org.kde.kquickcontrolsaddons 2.0
import org.kde.plasma.private.containmentlayoutmanager 1.0 as ContainmentLayoutManager
import org.kde.phone.homescreen 1.0
ContainmentLayoutManager.ItemContainer {
id: delegate
......@@ -72,23 +74,22 @@ ContainmentLayoutManager.ItemContainer {
var pos = favoriteStrip.mapFromItem(delegate, 0, 0);
newRow = Math.floor((pos.x + dragCenter.x) / delegate.width);
plasmoid.nativeInterface.applicationListModel.setFavoriteItem(index, true);
plasmoid.nativeInterface.applicationListModel.setLocation(index, ApplicationListModel.Favorites);
// Put it on desktop
} else if (newContainer == appletsLayout) {
var pos = appletsLayout.mapFromItem(delegate, 0, 0);
plasmoid.nativeInterface.applicationListModel.setDesktopItem(index, true);
delegate.x = pos.x
delegate.y = pos.y
plasmoid.nativeInterface.applicationListModel.setLocation(index, ApplicationListModel.Desktop);
print("!!!!!!!!!!!!"+pos.x+" "+pos.y)
// delegate.x = pos.x
// delegate.y = pos.y
return;
// Put it in the general view
} else {
newRow = Math.round(newContainer.flow.width / delegate.width) * Math.floor((delegate.y + dragCenter.y) / delegate.height) + Math.floor((delegate.x + dragCenter.x) / delegate.width) + favoriteStrip.count;
plasmoid.nativeInterface.applicationListModel.setFavoriteItem(index, false);
plasmoid.nativeInterface.applicationListModel.setDesktopItem(index, false);
plasmoid.nativeInterface.applicationListModel.setLocation(index, ApplicationListModel.Grid);
}
launcherDragManager.showSpacer(delegate, dragCenter.x, dragCenter.y);
......
......@@ -60,7 +60,7 @@ QtObject {
function changeContainer(item, container) {
var pos;
print("$$$$$$$$"+container)
if (container == appletsLayout) {
pos = container.mapFromItem(item, 0, 0);
item.parent = container;
......@@ -75,7 +75,7 @@ QtObject {
function putInContainerLayout(item, container) {
var pos = container.contentItem.mapFromItem(item, 0, 0);
print("££££££££££££££££"+container)
if (container == appletsLayout) {
item.parent = container;
} else {
......@@ -125,6 +125,12 @@ QtObject {
var container = containerForItem(item, dragCenterX, dragCenterY);
raiseContainer(container);
print("&&&&&&&&&&&"+container)
if (container == appletsLayout) {
spacer.visible = false;
changeContainer(item, container);
return;
}
var child = nearestChild(item, dragCenterX, dragCenterY, container);
......@@ -134,11 +140,6 @@ QtObject {
return;
}
if (container == appletsLayout) {
changeContainer(item, container);
return;
}
spacer.visible = false;
spacer.parent = container.flow
......
......@@ -27,6 +27,8 @@ import org.kde.kquickcontrolsaddons 2.0
import org.kde.plasma.private.containmentlayoutmanager 1.0 as ContainmentLayoutManager
import org.kde.phone.homescreen 1.0
LauncherContainer {
id: root
......@@ -46,16 +48,18 @@ LauncherContainer {
height: root.cellHeight
parent: {
if (model.ApplicationOnDesktopRole) {
if (model.ApplicationLocationRole == ApplicationListModel.Desktop) {
return appletsLayout;
}
if (model.ApplicationFavoriteRole) {
if (model.ApplicationLocationRole == ApplicationListModel.Favorites) {
if (editMode) {
return favoriteStrip.contentItem;
} else {
return favoriteStrip.flow;
}
}
if (editMode) {
return flowParent;
} else {
......
......@@ -30,6 +30,8 @@ import "launcher" as Launcher
import org.kde.plasma.private.containmentlayoutmanager 1.0 as ContainmentLayoutManager
import org.kde.phone.homescreen 1.0
Item {
id: root
width: 640
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment