Commit ff2fe85d authored by Marco Martin's avatar Marco Martin

better behavior of favorite strip

parent 3ce063b5
...@@ -105,6 +105,8 @@ void ApplicationListModel::loadApplications() ...@@ -105,6 +105,8 @@ void ApplicationListModel::loadApplications()
int i = 0; // for default bookmarks int i = 0; // for default bookmarks
m_favoriteCount = 0;
// Iterate over all entries in the group // Iterate over all entries in the group
while (!subGroupList.isEmpty()) { while (!subGroupList.isEmpty()) {
KSycocaEntry::Ptr groupEntry = subGroupList.first(); KSycocaEntry::Ptr groupEntry = subGroupList.first();
...@@ -151,6 +153,10 @@ void ApplicationListModel::loadApplications() ...@@ -151,6 +153,10 @@ void ApplicationListModel::loadApplications()
data.favorite = ++i + m_appPositions.size() < 6; data.favorite = ++i + m_appPositions.size() < 6;
unorderedList << data; unorderedList << data;
} }
if (data.favorite) {
++m_favoriteCount;
}
emit favoriteCountChanged();
} }
} }
} }
...@@ -233,6 +239,13 @@ void ApplicationListModel::setFavoriteItem(int row, bool favorite) ...@@ -233,6 +239,13 @@ void ApplicationListModel::setFavoriteItem(int row, bool favorite)
setDesktopItem(row, false); setDesktopItem(row, false);
data.favorite = favorite; data.favorite = favorite;
if (data.favorite) {
++m_favoriteCount;
} else {
m_favoriteCount = qMax(0, m_favoriteCount - 1);
}
emit favoriteCountChanged();
emit dataChanged(index(row, 0), index(row, 0)); emit dataChanged(index(row, 0), index(row, 0));
} }
......
...@@ -40,6 +40,7 @@ class ApplicationListModel : public QAbstractListModel { ...@@ -40,6 +40,7 @@ class ApplicationListModel : public QAbstractListModel {
Q_OBJECT Q_OBJECT
Q_PROPERTY(int count READ count NOTIFY countChanged) Q_PROPERTY(int count READ count NOTIFY countChanged)
Q_PROPERTY(int favoriteCount READ favoriteCount NOTIFY favoriteCountChanged)
Q_PROPERTY(QStringList appOrder READ appOrder WRITE setAppOrder NOTIFY appOrderChanged) Q_PROPERTY(QStringList appOrder READ appOrder WRITE setAppOrder NOTIFY appOrderChanged)
public: public:
...@@ -50,7 +51,8 @@ public: ...@@ -50,7 +51,8 @@ public:
void moveRow(const QModelIndex &sourceParent, int sourceRow, const QModelIndex &destinationParent, int destinationChild); void moveRow(const QModelIndex &sourceParent, int sourceRow, const QModelIndex &destinationParent, int destinationChild);
int count() { return m_applicationList.count(); } int count() const { return m_applicationList.count(); }
int favoriteCount() const { return m_favoriteCount;}
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
...@@ -85,6 +87,7 @@ public Q_SLOTS: ...@@ -85,6 +87,7 @@ public Q_SLOTS:
Q_SIGNALS: Q_SIGNALS:
void countChanged(); void countChanged();
void favoriteCountChanged();
void appOrderChanged(); void appOrderChanged();
private: private:
...@@ -92,6 +95,7 @@ private: ...@@ -92,6 +95,7 @@ private:
QStringList m_appOrder; QStringList m_appOrder;
QHash<QString, int> m_appPositions; QHash<QString, int> m_appPositions;
int m_favoriteCount = 0;
}; };
#endif // APPLICATIONLISTMODEL_H #endif // APPLICATIONLISTMODEL_H
...@@ -40,7 +40,7 @@ ApplicationListModel *HomeScreen::applicationListModel() ...@@ -40,7 +40,7 @@ ApplicationListModel *HomeScreen::applicationListModel()
return m_applicationListModel; return m_applicationListModel;
} }
void HomeScreen::orderItems(QQuickItem *item1, QQuickItem *item2) void HomeScreen::stackBefore(QQuickItem *item1, QQuickItem *item2)
{ {
if (!item1 || !item2 || item1->parentItem() != item2->parentItem()) { if (!item1 || !item2 || item1->parentItem() != item2->parentItem()) {
return; return;
...@@ -49,6 +49,14 @@ void HomeScreen::orderItems(QQuickItem *item1, QQuickItem *item2) ...@@ -49,6 +49,14 @@ void HomeScreen::orderItems(QQuickItem *item1, QQuickItem *item2)
item1->stackBefore(item2); item1->stackBefore(item2);
} }
void HomeScreen::stackAfter(QQuickItem *item1, QQuickItem *item2)
{
if (!item1 || !item2 || item1->parentItem() != item2->parentItem()) {
return;
}
item1->stackAfter(item2);
}
K_EXPORT_PLASMA_APPLET_WITH_JSON(homescreen, HomeScreen, "metadata.json") K_EXPORT_PLASMA_APPLET_WITH_JSON(homescreen, HomeScreen, "metadata.json")
......
...@@ -38,7 +38,8 @@ public: ...@@ -38,7 +38,8 @@ public:
ApplicationListModel *applicationListModel(); ApplicationListModel *applicationListModel();
Q_INVOKABLE void orderItems(QQuickItem *item1, QQuickItem *item2); Q_INVOKABLE void stackBefore(QQuickItem *item1, QQuickItem *item2);
Q_INVOKABLE void stackAfter(QQuickItem *item1, QQuickItem *item2);
private: private:
ApplicationListModel *m_applicationListModel; ApplicationListModel *m_applicationListModel;
......
...@@ -33,7 +33,6 @@ ContainmentLayoutManager.ItemContainer { ...@@ -33,7 +33,6 @@ ContainmentLayoutManager.ItemContainer {
z: dragging ? 1 : 0 z: dragging ? 1 : 0
property var modelData: typeof model !== "undefined" ? model : null property var modelData: typeof model !== "undefined" ? model : null
property Item container
leftPadding: units.smallSpacing * 2 leftPadding: units.smallSpacing * 2
topPadding: units.smallSpacing * 2 topPadding: units.smallSpacing * 2
...@@ -42,24 +41,30 @@ ContainmentLayoutManager.ItemContainer { ...@@ -42,24 +41,30 @@ ContainmentLayoutManager.ItemContainer {
opacity: dragging ? 0.4 : 1 opacity: dragging ? 0.4 : 1
property real dragCenterX
property real dragCenterY
editModeCondition: ContainmentLayoutManager.ItemContainer.AfterPressAndHold//model.ApplicationOnDesktopRole ? ContainmentLayoutManager.ItemContainer.AfterPressAndHold: ContainmentLayoutManager.ItemContainer.Manual editModeCondition: ContainmentLayoutManager.ItemContainer.AfterPressAndHold//model.ApplicationOnDesktopRole ? ContainmentLayoutManager.ItemContainer.AfterPressAndHold: ContainmentLayoutManager.ItemContainer.Manual
onEditModeChanged: {//FIXME: remove onEditModeChanged: {//FIXME: remove
plasmoid.editMode = editMode plasmoid.editMode = editMode
} }
onDragActiveChanged: { onDragActiveChanged: {
if (dragActive) { if (dragActive) {
// Must be 0, 0 as at this point dragCenterX and dragCenterY are on the drag before"
launcherDragManager.showSpacer(delegate, 0, 0); launcherDragManager.showSpacer(delegate, 0, 0);
return; } else {
launcherDragManager.positionItem(delegate, dragCenterX, dragCenterY);
plasmoid.editMode = false;
editMode = false;
} }
plasmoid.editMode = false;
editMode = false;
} }
onUserDrag: { onUserDrag: {
// newPosition // newPosition
var newRow = 0; var newRow = 0;
dragCenterX = dragCenter.x;
dragCenterY = dragCenter.y;
var newContainer = launcherDragManager.containerForItem(delegate, dragCenter.x, dragCenter.y); var newContainer = launcherDragManager.containerForItem(delegate, dragCenter.x, dragCenter.y);
// Put it in the favorites strip // Put it in the favorites strip
......
...@@ -33,7 +33,10 @@ LauncherContainer { ...@@ -33,7 +33,10 @@ LauncherContainer {
flow.flow: Flow.TopToBottom flow.flow: Flow.TopToBottom
visible: plasmoid.nativeInterface.applicationListModel.favoriteCount > 0 || plasmoid.editMode
implicitWidth: launcherGrid.cellWidth * 5 + leftPadding + rightPadding//applicationsFlow.count height: launcherGrid.cellHeight + topPadding + bottomPadding
implicitWidth: launcherGrid.cellWidth * Math.max(1, plasmoid.nativeInterface.applicationListModel.favoriteCount) + leftPadding + rightPadding
} }
...@@ -84,14 +84,49 @@ QtObject { ...@@ -84,14 +84,49 @@ QtObject {
item.y = pos.y; item.y = pos.y;
} }
function nearestChild (item, dragCenterX, dragCenterY, container) {
var distance = Number.POSITIVE_INFINITY;
var child;
// Search Left
for (var i = 0; i < item.width * 2; i += item.width/2) {
var candidate = container.flow.childAt(item.x + dragCenterX + i, item.y + dragCenterY);
if (candidate && i < distance) {
child = candidate;
break;
}
}
// Search Right
for (var i = 0; i < item.width * 2; i += item.width/2) {
var candidate = container.flow.childAt(item.x + dragCenterX - i, item.y + dragCenterY);
if (candidate && i < distance) {
child = candidate;
break;
}
}
if (!child) {
if (item.y < container.flow.height/2) {
child = container.flow.children[0];
} else {
child = container.flow.children[container.flow.children.length - 1];
}
}
return child;
}
function showSpacer(item, dragCenterX, dragCenterY) { function showSpacer(item, dragCenterX, dragCenterY) {
var container = containerForItem(item, dragCenterX, dragCenterY); var container = containerForItem(item, dragCenterX, dragCenterY);
raiseContainer(container); raiseContainer(container);
var child = container.flow.childAt(item.x + dragCenterX, item.y + dragCenterX); var child = nearestChild(item, dragCenterX, dragCenterY, container);
if (!child) { if (!child) {
spacer.visible = false;
spacer.parent = container.flow
return; return;
} }
...@@ -104,15 +139,13 @@ QtObject { ...@@ -104,15 +139,13 @@ QtObject {
spacer.parent = container.flow spacer.parent = container.flow
if (item.x + dragCenterX < child.x + child.width / 2) { if (item.x + dragCenterX < child.x + child.width / 2) {
plasmoid.nativeInterface.orderItems(spacer, child); plasmoid.nativeInterface.stackBefore(spacer, child);
} else { } else {
plasmoid.nativeInterface.orderItems(child, spacer); plasmoid.nativeInterface.stackAfter(spacer, child);
} }
changeContainer(item, container); changeContainer(item, container);
print(spacer.parent+" "+child.parent)
spacer.visible = true; spacer.visible = true;
} }
...@@ -128,16 +161,19 @@ QtObject { ...@@ -128,16 +161,19 @@ QtObject {
spacer.visible = false; spacer.visible = false;
spacer.parent = container.contentItem; spacer.parent = container.contentItem;
var child = container.flow.childAt(item.x + dragCenterX, item.y + dragCenterX); var child = nearestChild(item, dragCenterX, dragCenterY, container);
if (!child) { if (!child) {
putInContainerLayout(item, container);
return; return;
} }
putInContainerLayout(item, container);
if (item.x + dragCenterX < child.x + child.width / 2) { if (item.x + dragCenterX < child.x + child.width / 2) {
plasmoid.nativeInterface.orderItems(item, child); putInContainerLayout(item, container);
plasmoid.nativeInterface.stackBefore(item, child);
} else { } else {
plasmoid.nativeInterface.orderItems(child, item); putInContainerLayout(item, container);
plasmoid.nativeInterface.stackAfter(item, child);
} }
} }
} }
......
...@@ -44,15 +44,7 @@ LauncherContainer { ...@@ -44,15 +44,7 @@ LauncherContainer {
id: delegate id: delegate
width: root.cellWidth width: root.cellWidth
height: root.cellHeight height: root.cellHeight
container: {
if (model.ApplicationOnDesktopRole) {
return null;
}
if (index < favoriteStrip.count) {
return favoriteStrip;
}
return root;
}
parent: { parent: {
if (model.ApplicationOnDesktopRole) { if (model.ApplicationOnDesktopRole) {
return appletsLayout; return appletsLayout;
......
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