Skip to content

Commit

Permalink
fix(lock): userwidget pos error when size changed
Browse files Browse the repository at this point in the history
Change-Id: I829089173d86366551d52dcc7a62be3654118ed8
  • Loading branch information
justforlxz committed Nov 15, 2017
1 parent 3128a54 commit 13775f5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lightdm-deepin-greeter/app/loginmanager.cpp
Expand Up @@ -220,9 +220,9 @@ void LoginManager::startSession()

void LoginManager::resizeEvent(QResizeEvent *e)
{
QWidget::resizeEvent(e);
updateWidgetsPosition();

QTimer::singleShot(1, this, &LoginManager::updateWidgetsPosition);
QWidget::resizeEvent(e);
}

void LoginManager::keyPressEvent(QKeyEvent* e) {
Expand Down
17 changes: 11 additions & 6 deletions widgets/userwidget.cpp
Expand Up @@ -96,6 +96,9 @@ void UserWidget::initConnections()
connect(m_dbusAccounts, &DBusAccounts::UserDeleted, this, &UserWidget::onUserRemoved);

connect(m_dbusLogined, &Logined::UserListChanged, this, &UserWidget::onLoginUserListChanged);
connect(this, &UserWidget::userChanged, this, [=] {
updateCurrentUserPos(200);
});
}

void UserWidget::onUserListChanged()
Expand All @@ -114,9 +117,8 @@ void UserWidget::onUserAdded(const QString &path)
m_userDbus.insert(path, user);

UserButton *userBtn = new UserButton(user);
userBtn->hide();
userBtn->setVisible(userBtn->name() == m_currentUser);
userBtn->setParent(this);
userBtn->move(rect().center() - userBtn->rect().center());

connect(userBtn, &UserButton::imageClicked, this, &UserWidget::setCurrentUser);

Expand Down Expand Up @@ -175,6 +177,12 @@ UserButton *UserWidget::getUserByName(const QString &username)
return nullptr;
}

void UserWidget::updateCurrentUserPos(const int duration) const
{
for (UserButton *user : m_userBtns)
user->move(rect().center() - user->rect().center(), duration);
}

void UserWidget::setCurrentUser(const QString &username)
{
qDebug() << username << sender();
Expand All @@ -192,8 +200,6 @@ void UserWidget::setCurrentUser(const QString &username)
user->show();
} else
user->hide(180);

user->move(rect().center() - user->rect().center(), 200);
}

emit userChanged(m_currentUser);
Expand Down Expand Up @@ -269,8 +275,7 @@ void UserWidget::resizeEvent(QResizeEvent *e)
// rearrange the user icons.
expandWidget();
} else {
for (UserButton *user : m_userBtns)
user->move(rect().center() - user->rect().center(), 1);
updateCurrentUserPos();
}
}

Expand Down
1 change: 1 addition & 0 deletions widgets/userwidget.h
Expand Up @@ -91,6 +91,7 @@ private slots:
void onUserRemoved(const QString &name);
void onLoginUserListChanged(const QString &value);
UserButton* getUserByName(const QString &username);
void updateCurrentUserPos(const int duration = 0) const;

private:
int m_currentUserIndex = 0;
Expand Down

0 comments on commit 13775f5

Please sign in to comment.