mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-04-28 22:53:09 +00:00
homescreens/folio: FavouritesBar: Icon position animation bugfix
This fixes in issue where the favorites bar icons would previously animate based off of position changes. This was causing unwanted animations in situations like screen rotation and login.
This commit is contained in:
parent
f5728e1a21
commit
2a5dec9cf0
4 changed files with 18 additions and 74 deletions
|
|
@ -24,24 +24,6 @@ FavouritesModel::FavouritesModel(HomeScreen *parent)
|
|||
: QAbstractListModel{parent}
|
||||
, m_homeScreen{parent}
|
||||
{
|
||||
connect(m_homeScreen->homeScreenState(), &HomeScreenState::pageWidthChanged, this, [this]() {
|
||||
evaluateDelegatePositions(true);
|
||||
});
|
||||
connect(m_homeScreen->homeScreenState(), &HomeScreenState::pageHeightChanged, this, [this]() {
|
||||
evaluateDelegatePositions(true);
|
||||
});
|
||||
connect(m_homeScreen->homeScreenState(), &HomeScreenState::pageCellWidthChanged, this, [this]() {
|
||||
evaluateDelegatePositions(true);
|
||||
});
|
||||
connect(m_homeScreen->homeScreenState(), &HomeScreenState::pageCellHeightChanged, this, [this]() {
|
||||
evaluateDelegatePositions(true);
|
||||
});
|
||||
connect(m_homeScreen->homeScreenState(), &HomeScreenState::favouritesBarLocationChanged, this, [this]() {
|
||||
evaluateDelegatePositions(true);
|
||||
});
|
||||
connect(m_homeScreen->homeScreenState(), &HomeScreenState::pageOrientationChanged, this, [this]() {
|
||||
evaluateDelegatePositions(true);
|
||||
});
|
||||
}
|
||||
|
||||
int FavouritesModel::rowCount(const QModelIndex &parent) const
|
||||
|
|
@ -59,8 +41,6 @@ QVariant FavouritesModel::data(const QModelIndex &index, int role) const
|
|||
switch (role) {
|
||||
case DelegateRole:
|
||||
return QVariant::fromValue(m_delegates.at(index.row()).delegate);
|
||||
case XPositionRole:
|
||||
return QVariant::fromValue(m_delegates.at(index.row()).xPosition);
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
|
|
@ -68,7 +48,7 @@ QVariant FavouritesModel::data(const QModelIndex &index, int role) const
|
|||
|
||||
QHash<int, QByteArray> FavouritesModel::roleNames() const
|
||||
{
|
||||
return {{DelegateRole, "delegate"}, {XPositionRole, "xPosition"}};
|
||||
return {{DelegateRole, "delegate"}};
|
||||
}
|
||||
|
||||
void FavouritesModel::removeEntry(int row)
|
||||
|
|
@ -83,8 +63,6 @@ void FavouritesModel::removeEntry(int row)
|
|||
m_delegates.removeAt(row);
|
||||
endRemoveRows();
|
||||
|
||||
evaluateDelegatePositions();
|
||||
|
||||
save();
|
||||
}
|
||||
|
||||
|
|
@ -109,8 +87,6 @@ void FavouritesModel::moveEntry(int fromRow, int toRow)
|
|||
}
|
||||
endMoveRows();
|
||||
|
||||
evaluateDelegatePositions();
|
||||
|
||||
save();
|
||||
}
|
||||
|
||||
|
|
@ -136,22 +112,18 @@ bool FavouritesModel::addEntry(int row, FolioDelegate *delegate)
|
|||
if (row == m_delegates.size()) {
|
||||
beginInsertRows(QModelIndex(), row, row);
|
||||
m_delegates.append({delegate, 0});
|
||||
evaluateDelegatePositions(false);
|
||||
endInsertRows();
|
||||
} else if (m_delegates[row].delegate->type() == FolioDelegate::None) {
|
||||
replaceGhostEntry(delegate);
|
||||
} else {
|
||||
beginInsertRows(QModelIndex(), row, row);
|
||||
m_delegates.insert(row, {delegate, 0});
|
||||
evaluateDelegatePositions(false);
|
||||
endInsertRows();
|
||||
}
|
||||
|
||||
// ensure saves are connected when requested by the delegate
|
||||
connectSaveRequests(delegate);
|
||||
|
||||
evaluateDelegatePositions();
|
||||
|
||||
save();
|
||||
|
||||
return true;
|
||||
|
|
@ -291,7 +263,6 @@ void FavouritesModel::loadFromJson(QJsonArray arr)
|
|||
}
|
||||
}
|
||||
|
||||
evaluateDelegatePositions(false);
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
|
|
@ -398,25 +369,6 @@ QPointF FavouritesModel::getDelegateScreenPosition(int position) const
|
|||
return {0, 0};
|
||||
}
|
||||
|
||||
void FavouritesModel::evaluateDelegatePositions(bool emitSignal)
|
||||
{
|
||||
auto homeScreenState = m_homeScreen->homeScreenState();
|
||||
|
||||
bool isLocationBottom = homeScreenState->favouritesBarLocation() == HomeScreenState::Bottom;
|
||||
qreal cellLength = isLocationBottom ? homeScreenState->pageCellWidth() : homeScreenState->pageCellHeight();
|
||||
qreal startPosition = getDelegateRowStartPos();
|
||||
qreal currentPos = startPosition;
|
||||
|
||||
for (int i = 0; i < m_delegates.size(); ++i) {
|
||||
m_delegates[adjustIndex(i)].xPosition = qRound(currentPos);
|
||||
currentPos += cellLength;
|
||||
}
|
||||
|
||||
if (emitSignal) {
|
||||
Q_EMIT dataChanged(createIndex(0, 0), createIndex(m_delegates.size() - 1, 0), {XPositionRole});
|
||||
}
|
||||
}
|
||||
|
||||
qreal FavouritesModel::getDelegateRowStartPos() const
|
||||
{
|
||||
auto homeScreenState = m_homeScreen->homeScreenState();
|
||||
|
|
|
|||
|
|
@ -31,7 +31,6 @@ class FavouritesModel : public QAbstractListModel
|
|||
public:
|
||||
enum Roles {
|
||||
DelegateRole = Qt::UserRole + 1,
|
||||
XPositionRole,
|
||||
};
|
||||
|
||||
FavouritesModel(HomeScreen *parent = nullptr);
|
||||
|
|
@ -73,7 +72,6 @@ public:
|
|||
|
||||
private:
|
||||
void connectSaveRequests(FolioDelegate *delegate);
|
||||
void evaluateDelegatePositions(bool emitSignal = true);
|
||||
|
||||
// get the x (or y) position where delegates start being placed
|
||||
qreal getDelegateRowStartPos() const;
|
||||
|
|
|
|||
|
|
@ -20,45 +20,41 @@ MouseArea {
|
|||
|
||||
property var homeScreen
|
||||
|
||||
// use to account for x-y positioning, because delegate x and y will include the screen margins
|
||||
property real leftMargin
|
||||
property real topMargin
|
||||
|
||||
signal delegateDragRequested(var item)
|
||||
|
||||
onPressAndHold: folio.HomeScreenState.openSettingsView()
|
||||
|
||||
Repeater {
|
||||
id: repeater
|
||||
model: folio.FavouritesModel
|
||||
|
||||
delegate: Item {
|
||||
id: delegate
|
||||
|
||||
property var delegateModel: model.delegate
|
||||
property int index: model.index
|
||||
readonly property var delegateModel: model.delegate
|
||||
readonly property int index: model.index
|
||||
|
||||
property var dragState: folio.HomeScreenState.dragState
|
||||
property bool isDropPositionThis: dragState.candidateDropPosition.location === Folio.DelegateDragPosition.Favourites &&
|
||||
readonly property var dragState: folio.HomeScreenState.dragState
|
||||
readonly property bool isDropPositionThis: dragState.candidateDropPosition.location === Folio.DelegateDragPosition.Favourites &&
|
||||
dragState.candidateDropPosition.favouritesPosition === delegate.index
|
||||
property bool isAppHoveredOver: folio.HomeScreenState.swipeState === Folio.HomeScreenState.DraggingDelegate &&
|
||||
readonly property bool isAppHoveredOver: folio.HomeScreenState.swipeState === Folio.HomeScreenState.DraggingDelegate &&
|
||||
dragState.dropDelegate &&
|
||||
dragState.dropDelegate.type === Folio.FolioDelegate.Application &&
|
||||
isDropPositionThis
|
||||
|
||||
// only one of them will be used, because of the anchors below
|
||||
// this is used due to the ability for the favourites bar to be in multiple locations
|
||||
x: model.xPosition - leftMargin
|
||||
y: model.xPosition - topMargin
|
||||
readonly property bool isLocationBottom: folio.HomeScreenState.favouritesBarLocation === Folio.HomeScreenState.Bottom
|
||||
|
||||
anchors.verticalCenter: folio.HomeScreenState.favouritesBarLocation === Folio.HomeScreenState.Bottom ? parent.verticalCenter : undefined
|
||||
anchors.horizontalCenter: folio.HomeScreenState.favouritesBarLocation === Folio.HomeScreenState.Bottom ? undefined : parent.horizontalCenter
|
||||
// get the normalized index position value from the center so we can animate it
|
||||
property double fromCenterValue: model.index - (repeater.count / 2)
|
||||
Behavior on fromCenterValue {
|
||||
NumberAnimation { duration: 250; easing.type: Easing.InOutQuad; }
|
||||
}
|
||||
|
||||
Behavior on x {
|
||||
NumberAnimation { duration: 250; easing.type: Easing.InOutQuad }
|
||||
}
|
||||
Behavior on y {
|
||||
NumberAnimation { duration: 250; easing.type: Easing.InOutQuad }
|
||||
}
|
||||
// multiply the 'fromCenterValue' by the cell size to get the actual position
|
||||
readonly property int centerPosition: (isLocationBottom ? folio.HomeScreenState.pageCellWidth : folio.HomeScreenState.pageCellHeight) * fromCenterValue
|
||||
|
||||
x: isLocationBottom ? centerPosition + parent.width / 2 : (parent.width - width) / 2
|
||||
y: isLocationBottom ? (parent.height - height) / 2 : parent.height / 2 - centerPosition - folio.HomeScreenState.pageCellHeight
|
||||
|
||||
implicitWidth: folio.HomeScreenState.pageCellWidth
|
||||
implicitHeight: folio.HomeScreenState.pageCellHeight
|
||||
|
|
|
|||
|
|
@ -258,8 +258,6 @@ Item {
|
|||
id: favouritesBar
|
||||
folio: root.folio
|
||||
homeScreen: root
|
||||
leftMargin: root.leftMargin
|
||||
topMargin: root.topMargin
|
||||
|
||||
// don't show in settings mode
|
||||
opacity: 1 - folio.HomeScreenState.settingsOpenProgress
|
||||
|
|
|
|||
Loading…
Reference in a new issue