Skip to content

Commit

Permalink
smooth drop down animation
Browse files Browse the repository at this point in the history
  • Loading branch information
Liu Wei committed Sep 13, 2020
1 parent 0a3c7eb commit 7730aca
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
33 changes: 23 additions & 10 deletions wuake_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
#include "wuake_tab_page.h"

WuakeWindow::WuakeWindow(QWidget *parent) :
QDialog(parent, Qt::ToolTip | Qt::FramelessWindowHint)
QDialog(parent, Qt::ToolTip | Qt::FramelessWindowHint),
mIsShowing(false)
//QDialog(parent)
{
//resize(819, 475);
Expand Down Expand Up @@ -51,7 +52,7 @@ WuakeWindow::~WuakeWindow()

void WuakeWindow::show()
{
if (!isHidden()) return;
if (mIsShowing) return;

QDialog::show();

Expand All @@ -60,29 +61,42 @@ void WuakeWindow::show()

void WuakeWindow::hide()
{
if (isHidden()) return;
if (!mIsShowing) return;
if (mShowAnim.state() == QAbstractAnimation::Running ||
mHideAnim.state() == QAbstractAnimation::Running) {
return;
}
mHideAnim.start();
}

void WuakeWindow::onShow()
{
activateWindow();
mIsShowing = true;
}

void WuakeWindow::onHide()
{
mIsShowing = false;
}

void WuakeWindow::initAnim()
{
updateAnimRect();

mShowAnim.setTargetObject(this);
mShowAnim.setPropertyName("pos");
mShowAnim.setDuration(170);
mShowAnim.setEasingCurve(QEasingCurve::OutQuint);
mShowAnim.setEasingCurve(QEasingCurve::Linear);

connect(&mShowAnim, &QPropertyAnimation::finished, this, &WuakeWindow::onShow);

mHideAnim.setTargetObject(this);
mHideAnim.setPropertyName("pos");
mHideAnim.setDuration(170);
mHideAnim.setEasingCurve(QEasingCurve::InQuint);
mHideAnim.setEasingCurve(QEasingCurve::Linear);

connect(&mHideAnim, &QPropertyAnimation::finished, this, &QDialog::hide);
connect(&mHideAnim, &QPropertyAnimation::finished, this, &WuakeWindow::onHide);
}

void WuakeWindow::updateAnimRect()
Expand Down Expand Up @@ -138,11 +152,10 @@ void WuakeWindow::onHotkey()
HotKeyCode keyCode = mHotkeys.key(hotkeyStr, HOTKEY_NONE);

if (HOTKEY_SHOW_HIDE == keyCode) {
if (isHidden()) {
show();
activateWindow();
} else {
if (mIsShowing) {
hide();
} else {
show();
}
return;
}
Expand Down
4 changes: 4 additions & 0 deletions wuake_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class WuakeWindow : public QDialog
public slots:
void show();
void hide();
void onShow();
void onHide();

protected:
void resizeEvent(QResizeEvent* event);
Expand All @@ -53,4 +55,6 @@ protected slots:

QPropertyAnimation mShowAnim;
QPropertyAnimation mHideAnim;

bool mIsShowing;
};

0 comments on commit 7730aca

Please sign in to comment.