mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-04-29 15:03:09 +00:00
single role for location
This commit is contained in:
parent
39a4ae5780
commit
8c1b75a777
7 changed files with 58 additions and 64 deletions
|
|
@ -58,8 +58,7 @@ QHash<int, QByteArray> ApplicationListModel::roleNames() const
|
||||||
roleNames[ApplicationStorageIdRole] = "ApplicationStorageIdRole";
|
roleNames[ApplicationStorageIdRole] = "ApplicationStorageIdRole";
|
||||||
roleNames[ApplicationEntryPathRole] = "ApplicationEntryPathRole";
|
roleNames[ApplicationEntryPathRole] = "ApplicationEntryPathRole";
|
||||||
roleNames[ApplicationOriginalRowRole] = "ApplicationOriginalRowRole";
|
roleNames[ApplicationOriginalRowRole] = "ApplicationOriginalRowRole";
|
||||||
roleNames[ApplicationFavoriteRole] = "ApplicationFavoriteRole";
|
roleNames[ApplicationLocationRole] = "ApplicationLocationRole";
|
||||||
roleNames[ApplicationOnDesktopRole] = "ApplicationOnDesktopRole";
|
|
||||||
|
|
||||||
return roleNames;
|
return roleNames;
|
||||||
}
|
}
|
||||||
|
|
@ -146,14 +145,14 @@ void ApplicationListModel::loadApplications()
|
||||||
auto it = m_appPositions.constFind(service->storageId());
|
auto it = m_appPositions.constFind(service->storageId());
|
||||||
if (it != m_appPositions.constEnd()) {
|
if (it != m_appPositions.constEnd()) {
|
||||||
//TODO: proper bookmarks
|
//TODO: proper bookmarks
|
||||||
data.favorite = (*it) < 6;
|
data.location = (*it) < 6 ? Favorites : Grid;
|
||||||
orderedList[*it] = data;
|
orderedList[*it] = data;
|
||||||
} else {
|
} else {
|
||||||
//TODO: proper bookmarks
|
//TODO: proper bookmarks
|
||||||
data.favorite = ++i + m_appPositions.size() < 6;
|
data.location = (++i + m_appPositions.size() < 6) ? Favorites : Grid;
|
||||||
unorderedList << data;
|
unorderedList << data;
|
||||||
}
|
}
|
||||||
if (data.favorite) {
|
if (data.location == Favorites) {
|
||||||
++m_favoriteCount;
|
++m_favoriteCount;
|
||||||
}
|
}
|
||||||
emit favoriteCountChanged();
|
emit favoriteCountChanged();
|
||||||
|
|
@ -194,10 +193,8 @@ QVariant ApplicationListModel::data(const QModelIndex &index, int role) const
|
||||||
return m_applicationList.at(index.row()).entryPath;
|
return m_applicationList.at(index.row()).entryPath;
|
||||||
case ApplicationOriginalRowRole:
|
case ApplicationOriginalRowRole:
|
||||||
return index.row();
|
return index.row();
|
||||||
case ApplicationOnDesktopRole:
|
case ApplicationLocationRole:
|
||||||
return m_applicationList.at(index.row()).desktop;
|
return m_applicationList.at(index.row()).location;
|
||||||
case ApplicationFavoriteRole:
|
|
||||||
return m_applicationList.at(index.row()).favorite;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
@ -225,43 +222,26 @@ void ApplicationListModel::moveRow(const QModelIndex& /* sourceParent */, int so
|
||||||
moveItem(sourceRow, destinationChild);
|
moveItem(sourceRow, destinationChild);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ApplicationListModel::setFavoriteItem(int row, bool favorite)
|
void ApplicationListModel::setLocation(int row, LauncherLocation location)
|
||||||
{
|
{
|
||||||
if (row < 0 || row >= m_applicationList.length()) {
|
if (row < 0 || row >= m_applicationList.length()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ApplicationData &data = m_applicationList[row];
|
ApplicationData &data = m_applicationList[row];
|
||||||
if (data.favorite == favorite) {
|
if (data.location == location) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
setDesktopItem(row, false);
|
if (location == Favorites) {
|
||||||
data.favorite = favorite;
|
|
||||||
|
|
||||||
if (data.favorite) {
|
|
||||||
++m_favoriteCount;
|
++m_favoriteCount;
|
||||||
} else {
|
emit favoriteCountChanged();
|
||||||
|
} else if (data.location == Favorites) {
|
||||||
m_favoriteCount = qMax(0, m_favoriteCount - 1);
|
m_favoriteCount = qMax(0, m_favoriteCount - 1);
|
||||||
}
|
emit favoriteCountChanged();
|
||||||
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];
|
data.location = location;
|
||||||
if (data.desktop == desktop) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setFavoriteItem(row, false);
|
|
||||||
data.desktop = desktop;
|
|
||||||
|
|
||||||
emit dataChanged(index(row, 0), index(row, 0));
|
emit dataChanged(index(row, 0), index(row, 0));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,13 +27,14 @@
|
||||||
|
|
||||||
class QString;
|
class QString;
|
||||||
|
|
||||||
|
class ApplicationListModel;
|
||||||
|
|
||||||
struct ApplicationData {
|
struct ApplicationData {
|
||||||
QString name;
|
QString name;
|
||||||
QString icon;
|
QString icon;
|
||||||
QString storageId;
|
QString storageId;
|
||||||
QString entryPath;
|
QString entryPath;
|
||||||
bool favorite = false;
|
int location = 0; //FIXME
|
||||||
bool desktop = false;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class ApplicationListModel : public QAbstractListModel {
|
class ApplicationListModel : public QAbstractListModel {
|
||||||
|
|
@ -44,6 +45,22 @@ class ApplicationListModel : public QAbstractListModel {
|
||||||
Q_PROPERTY(QStringList appOrder READ appOrder WRITE setAppOrder NOTIFY appOrderChanged)
|
Q_PROPERTY(QStringList appOrder READ appOrder WRITE setAppOrder NOTIFY appOrderChanged)
|
||||||
|
|
||||||
public:
|
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(QObject *parent = nullptr);
|
||||||
~ApplicationListModel() override;
|
~ApplicationListModel() override;
|
||||||
|
|
||||||
|
|
@ -60,21 +77,10 @@ public:
|
||||||
|
|
||||||
QHash<int, QByteArray> roleNames() const Q_DECL_OVERRIDE;
|
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;
|
QStringList appOrder() const;
|
||||||
void setAppOrder(const QStringList &order);
|
void setAppOrder(const QStringList &order);
|
||||||
|
|
||||||
Q_INVOKABLE void setFavoriteItem(int row, bool favorite);
|
Q_INVOKABLE void setLocation(int row, LauncherLocation location);
|
||||||
Q_INVOKABLE void setDesktopItem(int row, bool desktop);
|
|
||||||
|
|
||||||
Q_INVOKABLE void moveItem(int row, int order);
|
Q_INVOKABLE void moveItem(int row, int order);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@
|
||||||
HomeScreen::HomeScreen(QObject *parent, const QVariantList &args)
|
HomeScreen::HomeScreen(QObject *parent, const QVariantList &args)
|
||||||
: Plasma::Containment(parent, 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);
|
m_applicationListModel = new ApplicationListModel(this);
|
||||||
setHasConfigurationInterface(true);
|
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.plasma.private.containmentlayoutmanager 1.0 as ContainmentLayoutManager
|
||||||
|
|
||||||
|
import org.kde.phone.homescreen 1.0
|
||||||
|
|
||||||
ContainmentLayoutManager.ItemContainer {
|
ContainmentLayoutManager.ItemContainer {
|
||||||
id: delegate
|
id: delegate
|
||||||
|
|
||||||
|
|
@ -72,23 +74,22 @@ ContainmentLayoutManager.ItemContainer {
|
||||||
var pos = favoriteStrip.mapFromItem(delegate, 0, 0);
|
var pos = favoriteStrip.mapFromItem(delegate, 0, 0);
|
||||||
newRow = Math.floor((pos.x + dragCenter.x) / delegate.width);
|
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
|
// Put it on desktop
|
||||||
} else if (newContainer == appletsLayout) {
|
} else if (newContainer == appletsLayout) {
|
||||||
var pos = appletsLayout.mapFromItem(delegate, 0, 0);
|
var pos = appletsLayout.mapFromItem(delegate, 0, 0);
|
||||||
plasmoid.nativeInterface.applicationListModel.setDesktopItem(index, true);
|
plasmoid.nativeInterface.applicationListModel.setLocation(index, ApplicationListModel.Desktop);
|
||||||
delegate.x = pos.x
|
print("!!!!!!!!!!!!"+pos.x+" "+pos.y)
|
||||||
delegate.y = pos.y
|
// delegate.x = pos.x
|
||||||
|
// delegate.y = pos.y
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Put it in the general view
|
// Put it in the general view
|
||||||
} else {
|
} 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;
|
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.setLocation(index, ApplicationListModel.Grid);
|
||||||
plasmoid.nativeInterface.applicationListModel.setDesktopItem(index, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
launcherDragManager.showSpacer(delegate, dragCenter.x, dragCenter.y);
|
launcherDragManager.showSpacer(delegate, dragCenter.x, dragCenter.y);
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ QtObject {
|
||||||
|
|
||||||
function changeContainer(item, container) {
|
function changeContainer(item, container) {
|
||||||
var pos;
|
var pos;
|
||||||
|
print("$$$$$$$$"+container)
|
||||||
if (container == appletsLayout) {
|
if (container == appletsLayout) {
|
||||||
pos = container.mapFromItem(item, 0, 0);
|
pos = container.mapFromItem(item, 0, 0);
|
||||||
item.parent = container;
|
item.parent = container;
|
||||||
|
|
@ -75,7 +75,7 @@ QtObject {
|
||||||
|
|
||||||
function putInContainerLayout(item, container) {
|
function putInContainerLayout(item, container) {
|
||||||
var pos = container.contentItem.mapFromItem(item, 0, 0);
|
var pos = container.contentItem.mapFromItem(item, 0, 0);
|
||||||
|
print("££££££££££££££££"+container)
|
||||||
if (container == appletsLayout) {
|
if (container == appletsLayout) {
|
||||||
item.parent = container;
|
item.parent = container;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -125,6 +125,12 @@ QtObject {
|
||||||
var container = containerForItem(item, dragCenterX, dragCenterY);
|
var container = containerForItem(item, dragCenterX, dragCenterY);
|
||||||
|
|
||||||
raiseContainer(container);
|
raiseContainer(container);
|
||||||
|
print("&&&&&&&&&&&"+container)
|
||||||
|
if (container == appletsLayout) {
|
||||||
|
spacer.visible = false;
|
||||||
|
changeContainer(item, container);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var child = nearestChild(item, dragCenterX, dragCenterY, container);
|
var child = nearestChild(item, dragCenterX, dragCenterY, container);
|
||||||
|
|
||||||
|
|
@ -134,11 +140,6 @@ QtObject {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (container == appletsLayout) {
|
|
||||||
changeContainer(item, container);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
spacer.visible = false;
|
spacer.visible = false;
|
||||||
spacer.parent = container.flow
|
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.plasma.private.containmentlayoutmanager 1.0 as ContainmentLayoutManager
|
||||||
|
|
||||||
|
import org.kde.phone.homescreen 1.0
|
||||||
|
|
||||||
LauncherContainer {
|
LauncherContainer {
|
||||||
id: root
|
id: root
|
||||||
|
|
||||||
|
|
@ -46,16 +48,18 @@ LauncherContainer {
|
||||||
height: root.cellHeight
|
height: root.cellHeight
|
||||||
|
|
||||||
parent: {
|
parent: {
|
||||||
if (model.ApplicationOnDesktopRole) {
|
if (model.ApplicationLocationRole == ApplicationListModel.Desktop) {
|
||||||
return appletsLayout;
|
return appletsLayout;
|
||||||
}
|
}
|
||||||
if (model.ApplicationFavoriteRole) {
|
|
||||||
|
if (model.ApplicationLocationRole == ApplicationListModel.Favorites) {
|
||||||
if (editMode) {
|
if (editMode) {
|
||||||
return favoriteStrip.contentItem;
|
return favoriteStrip.contentItem;
|
||||||
} else {
|
} else {
|
||||||
return favoriteStrip.flow;
|
return favoriteStrip.flow;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (editMode) {
|
if (editMode) {
|
||||||
return flowParent;
|
return flowParent;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,8 @@ import "launcher" as Launcher
|
||||||
|
|
||||||
import org.kde.plasma.private.containmentlayoutmanager 1.0 as ContainmentLayoutManager
|
import org.kde.plasma.private.containmentlayoutmanager 1.0 as ContainmentLayoutManager
|
||||||
|
|
||||||
|
import org.kde.phone.homescreen 1.0
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
id: root
|
id: root
|
||||||
width: 640
|
width: 640
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue