Commit ff2fe85d authored by Marco Martin's avatar Marco Martin

better behavior of favorite strip

parent 3ce063b5
......@@ -105,6 +105,8 @@ void ApplicationListModel::loadApplications()
int i = 0; // for default bookmarks
m_favoriteCount = 0;
// Iterate over all entries in the group
while (!subGroupList.isEmpty()) {
KSycocaEntry::Ptr groupEntry = subGroupList.first();
......@@ -151,6 +153,10 @@ void ApplicationListModel::loadApplications()
data.favorite = ++i + m_appPositions.size() < 6;
unorderedList << data;
}
if (data.favorite) {
++m_favoriteCount;
}
emit favoriteCountChanged();
}
}
}
......@@ -233,6 +239,13 @@ void ApplicationListModel::setFavoriteItem(int row, bool favorite)
setDesktopItem(row, false);
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));
}
......
......@@ -40,6 +40,7 @@ class ApplicationListModel : public QAbstractListModel {
Q_OBJECT
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)
public:
......@@ -50,7 +51,8 @@ public:
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;
......@@ -85,6 +87,7 @@ public Q_SLOTS:
Q_SIGNALS:
void countChanged();
void favoriteCountChanged();
void appOrderChanged();
private:
......@@ -92,6 +95,7 @@ private:
QStringList m_appOrder;
QHash<QString, int> m_appPositions;
int m_favoriteCount = 0;
};
#endif // APPLICATIONLISTMODEL_H
......@@ -40,7 +40,7 @@ ApplicationListModel *HomeScreen::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()) {
return;
......@@ -49,6 +49,14 @@ void HomeScreen::orderItems(QQuickItem *item1, QQuickItem *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")
......
......@@ -38,7 +38,8 @@ public:
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:
ApplicationListModel *m_applicationListModel;
......
......@@ -33,7 +33,6 @@ ContainmentLayoutManager.ItemContainer {
z: dragging ? 1 : 0
property var modelData: typeof model !== "undefined" ? model : null
property Item container
leftPadding: units.smallSpacing * 2
topPadding: units.smallSpacing * 2
......@@ -42,24 +41,30 @@ ContainmentLayoutManager.ItemContainer {
opacity: dragging ? 0.4 : 1
property real dragCenterX
property real dragCenterY
editModeCondition: ContainmentLayoutManager.ItemContainer.AfterPressAndHold//model.ApplicationOnDesktopRole ? ContainmentLayoutManager.ItemContainer.AfterPressAndHold: ContainmentLayoutManager.ItemContainer.Manual
onEditModeChanged: {//FIXME: remove
plasmoid.editMode = editMode
}
onDragActiveChanged: {
if (dragActive) {
// Must be 0, 0 as at this point dragCenterX and dragCenterY are on the drag before"
launcherDragManager.showSpacer(delegate, 0, 0);
return;
} else {
launcherDragManager.positionItem(delegate, dragCenterX, dragCenterY);
plasmoid.editMode = false;
editMode = false;
}
plasmoid.editMode = false;
editMode = false;
}
onUserDrag: {
// newPosition
var newRow = 0;
dragCenterX = dragCenter.x;
dragCenterY = dragCenter.y;
var newContainer = launcherDragManager.containerForItem(delegate, dragCenter.x, dragCenter.y);
// Put it in the favorites strip
......
......@@ -33,7 +33,10 @@ LauncherContainer {
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 {
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) {
var container = containerForItem(item, dragCenterX, dragCenterY);
raiseContainer(container);
var child = container.flow.childAt(item.x + dragCenterX, item.y + dragCenterX);
var child = nearestChild(item, dragCenterX, dragCenterY, container);
if (!child) {
spacer.visible = false;
spacer.parent = container.flow
return;
}
......@@ -104,15 +139,13 @@ QtObject {
spacer.parent = container.flow
if (item.x + dragCenterX < child.x + child.width / 2) {
plasmoid.nativeInterface.orderItems(spacer, child);
plasmoid.nativeInterface.stackBefore(spacer, child);
} else {
plasmoid.nativeInterface.orderItems(child, spacer);
plasmoid.nativeInterface.stackAfter(spacer, child);
}
changeContainer(item, container);
print(spacer.parent+" "+child.parent)
spacer.visible = true;
}
......@@ -128,16 +161,19 @@ QtObject {
spacer.visible = false;
spacer.parent = container.contentItem;
var child = container.flow.childAt(item.x + dragCenterX, item.y + dragCenterX);
var child = nearestChild(item, dragCenterX, dragCenterY, container);
if (!child) {
putInContainerLayout(item, container);
return;
}
putInContainerLayout(item, container);
if (item.x + dragCenterX < child.x + child.width / 2) {
plasmoid.nativeInterface.orderItems(item, child);
putInContainerLayout(item, container);
plasmoid.nativeInterface.stackBefore(item, child);
} else {
plasmoid.nativeInterface.orderItems(child, item);
putInContainerLayout(item, container);
plasmoid.nativeInterface.stackAfter(item, child);
}
}
}
......
......@@ -44,15 +44,7 @@ LauncherContainer {
id: delegate
width: root.cellWidth
height: root.cellHeight
container: {
if (model.ApplicationOnDesktopRole) {
return null;
}
if (index < favoriteStrip.count) {
return favoriteStrip;
}
return root;
}
parent: {
if (model.ApplicationOnDesktopRole) {
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