mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 17:33:05 +00:00
add animation when position changed
Change-Id: I34f0ce6912893ba3cd686c3a8df05f3ae019cef0
This commit is contained in:
parent
44cc88a53c
commit
e2c87464a2
Notes:
Deepin Code Review
2016-08-12 06:36:42 +00:00
Verified+1: Anonymous Coward #1000004 Code-Review+2: 石博文 <sbw@sbw.so> Submitted-by: 石博文 <sbw@sbw.so> Submitted-at: Fri, 12 Aug 2016 06:36:42 +0000 Reviewed-on: https://cr.deepin.io/15159 Project: dde/dde-dock Branch: refs/heads/master
@ -32,7 +32,6 @@ DockSettings::DockSettings(QWidget *parent)
|
||||
m_dockInter(new DBusDock(this)),
|
||||
m_itemController(DockItemController::instance(this))
|
||||
{
|
||||
resetFrontendGeometry();
|
||||
m_primaryRect = m_displayInter->primaryRect();
|
||||
m_position = Dock::Position(m_dockInter->position());
|
||||
m_displayMode = Dock::DisplayMode(m_dockInter->displayMode());
|
||||
@ -92,7 +91,7 @@ DockSettings::DockSettings(QWidget *parent)
|
||||
m_settingsMenu.addAction(statusSubMenuAct);
|
||||
|
||||
connect(&m_settingsMenu, &DMenu::triggered, this, &DockSettings::menuActionClicked);
|
||||
connect(m_dockInter, &DBusDock::PositionChanged, this, &DockSettings::positionChanged);
|
||||
connect(m_dockInter, &DBusDock::PositionChanged, this, &DockSettings::onPositionChanged);
|
||||
connect(m_dockInter, &DBusDock::IconSizeChanged, this, &DockSettings::iconSizeChanged);
|
||||
connect(m_dockInter, &DBusDock::DisplayModeChanged, this, &DockSettings::displayModeChanged);
|
||||
connect(m_dockInter, &DBusDock::HideModeChanged, this, &DockSettings::hideModeChanged, Qt::QueuedConnection);
|
||||
@ -107,6 +106,7 @@ DockSettings::DockSettings(QWidget *parent)
|
||||
connect(m_displayInter, &DBusDisplay::ScreenWidthChanged, this, &DockSettings::primaryScreenChanged, Qt::QueuedConnection);
|
||||
|
||||
calculateWindowConfig();
|
||||
resetFrontendGeometry();
|
||||
}
|
||||
|
||||
DisplayMode DockSettings::displayMode() const
|
||||
@ -154,6 +154,30 @@ const QSize DockSettings::windowSize() const
|
||||
return m_mainWindowSize;
|
||||
}
|
||||
|
||||
const QRect DockSettings::windowRect(const Position position) const
|
||||
{
|
||||
const QSize size = m_mainWindowSize;
|
||||
const QRect primaryRect = m_primaryRect;
|
||||
const int offsetX = (primaryRect.width() - size.width()) / 2;
|
||||
const int offsetY = (primaryRect.height() - size.height()) / 2;
|
||||
|
||||
QPoint p(0, 0);
|
||||
switch (position)
|
||||
{
|
||||
case Top:
|
||||
p = QPoint(primaryRect.topLeft().x() + offsetX, 0); break;
|
||||
case Left:
|
||||
p = QPoint(primaryRect.topLeft().x(), offsetY); break;
|
||||
case Right:
|
||||
p = QPoint(primaryRect.right() - size.width() + 1, offsetY); break;
|
||||
case Bottom:
|
||||
p = QPoint(offsetX, primaryRect.bottom() - size.height() + 1); break;
|
||||
default:Q_UNREACHABLE();
|
||||
}
|
||||
|
||||
return QRect(p, size);
|
||||
}
|
||||
|
||||
void DockSettings::showDockSettingsMenu()
|
||||
{
|
||||
m_autoHide = false;
|
||||
@ -223,15 +247,21 @@ void DockSettings::menuActionClicked(DAction *action)
|
||||
return m_dockInter->setHideMode(SmartHide);
|
||||
}
|
||||
|
||||
void DockSettings::positionChanged()
|
||||
void DockSettings::onPositionChanged()
|
||||
{
|
||||
m_position = Dock::Position(m_dockInter->position());
|
||||
const Position prevPos = m_position;
|
||||
const Position nextPos = Dock::Position(m_dockInter->position());
|
||||
|
||||
if (prevPos == nextPos)
|
||||
return;
|
||||
|
||||
m_position = nextPos;
|
||||
DockItem::setDockPosition(m_position);
|
||||
qApp->setProperty(PROP_POSITION, QVariant::fromValue(m_position));
|
||||
|
||||
calculateWindowConfig();
|
||||
|
||||
emit dataChanged();
|
||||
emit positionChanged(prevPos);
|
||||
}
|
||||
|
||||
void DockSettings::iconSizeChanged()
|
||||
@ -295,25 +325,9 @@ void DockSettings::primaryScreenChanged()
|
||||
|
||||
void DockSettings::resetFrontendGeometry()
|
||||
{
|
||||
const QSize size = m_mainWindowSize;
|
||||
const QRect primaryRect = m_primaryRect;
|
||||
const int offsetX = (primaryRect.width() - size.width()) / 2;
|
||||
const int offsetY = (primaryRect.height() - size.height()) / 2;
|
||||
const QRect r = windowRect(m_position);
|
||||
|
||||
QPoint p(0, 0);
|
||||
switch (m_position)
|
||||
{
|
||||
case Top:
|
||||
p = QPoint(primaryRect.topLeft().x() + offsetX, 0); break;
|
||||
case Left:
|
||||
p = QPoint(primaryRect.topLeft().x(), offsetY); break;
|
||||
case Right:
|
||||
p = QPoint(primaryRect.right() - size.width() + 1, offsetY); break;
|
||||
case Bottom:
|
||||
p = QPoint(offsetX, primaryRect.bottom() - size.height() + 1); break;
|
||||
}
|
||||
|
||||
m_dockInter->SetFrontendWindowRect(p.x(), p.y(), size.width(), size.height());
|
||||
m_dockInter->SetFrontendWindowRect(r.x(), r.y(), r.width(), r.height());
|
||||
}
|
||||
|
||||
void DockSettings::calculateWindowConfig()
|
||||
|
@ -33,11 +33,13 @@ public:
|
||||
bool autoHide() const;
|
||||
const QRect primaryRect() const;
|
||||
const QSize windowSize() const;
|
||||
const QRect windowRect(const Position position) const;
|
||||
|
||||
void showDockSettingsMenu();
|
||||
|
||||
signals:
|
||||
void dataChanged() const;
|
||||
void positionChanged(const Position prevPosition) const;
|
||||
void autoHideChanged(const bool autoHide) const;
|
||||
void windowVisibleChanegd() const;
|
||||
void windowHideModeChanged() const;
|
||||
@ -49,7 +51,7 @@ public slots:
|
||||
|
||||
private slots:
|
||||
void menuActionClicked(DAction *action);
|
||||
void positionChanged();
|
||||
void onPositionChanged();
|
||||
void iconSizeChanged();
|
||||
void displayModeChanged();
|
||||
void hideModeChanged();
|
||||
|
@ -6,6 +6,9 @@
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
: QWidget(parent),
|
||||
|
||||
m_updatePanelVisible(true),
|
||||
|
||||
m_mainPanel(new MainPanel(this)),
|
||||
m_positionUpdateTimer(new QTimer(this)),
|
||||
m_sizeChangeAni(new QPropertyAnimation(this, "size")),
|
||||
@ -127,9 +130,10 @@ void MainWindow::initComponents()
|
||||
void MainWindow::initConnections()
|
||||
{
|
||||
connect(m_settings, &DockSettings::dataChanged, m_positionUpdateTimer, static_cast<void (QTimer::*)()>(&QTimer::start));
|
||||
connect(m_settings, &DockSettings::positionChanged, this, &MainWindow::positionChanged);
|
||||
connect(m_settings, &DockSettings::windowGeometryChanged, this, &MainWindow::updateGeometry, Qt::DirectConnection);
|
||||
connect(m_settings, &DockSettings::windowHideModeChanged, this, &MainWindow::setStrutPartial, Qt::QueuedConnection);
|
||||
connect(m_settings, &DockSettings::windowHideModeChanged, this, &MainWindow::resetPanelEnvironment);
|
||||
connect(m_settings, &DockSettings::windowHideModeChanged, [this] {resetPanelEnvironment(true);});
|
||||
connect(m_settings, &DockSettings::windowVisibleChanegd, this, &MainWindow::updatePanelVisible, Qt::QueuedConnection);
|
||||
connect(m_settings, &DockSettings::autoHideChanged, this, &MainWindow::updatePanelVisible);
|
||||
|
||||
@ -152,6 +156,28 @@ void MainWindow::initConnections()
|
||||
});
|
||||
}
|
||||
|
||||
void MainWindow::positionChanged(const Position prevPos)
|
||||
{
|
||||
// paly hide animation and disable other animation
|
||||
m_updatePanelVisible = false;
|
||||
clearStrutPartial();
|
||||
narrow(prevPos);
|
||||
|
||||
// reset position & layout and slide out
|
||||
QTimer::singleShot(200, this, [&] {
|
||||
resetPanelEnvironment(false);
|
||||
updateGeometry();
|
||||
expand();
|
||||
});
|
||||
|
||||
// reset to right environment when animation finished
|
||||
QTimer::singleShot(400, this, [&] {
|
||||
m_updatePanelVisible = true;
|
||||
setStrutPartial();
|
||||
updatePanelVisible();
|
||||
});
|
||||
}
|
||||
|
||||
void MainWindow::updatePosition()
|
||||
{
|
||||
// all update operation need pass by timer
|
||||
@ -275,7 +301,7 @@ void MainWindow::expand()
|
||||
if (m_mainPanel->pos() == finishPos && m_mainPanel->size() == this->size())
|
||||
return;
|
||||
|
||||
resetPanelEnvironment();
|
||||
resetPanelEnvironment(true);
|
||||
|
||||
if (m_panelShowAni->state() == QPropertyAnimation::Running)
|
||||
return m_panelShowAni->setEndValue(finishPos);
|
||||
@ -297,13 +323,14 @@ void MainWindow::expand()
|
||||
m_panelShowAni->start();
|
||||
}
|
||||
|
||||
void MainWindow::narrow()
|
||||
void MainWindow::narrow(const Position prevPos)
|
||||
{
|
||||
// qDebug() << "narrow";
|
||||
const QSize size = m_settings->windowSize();
|
||||
// const QSize size = m_settings->windowSize();
|
||||
const QSize size = m_mainPanel->size();
|
||||
|
||||
QPoint finishPos(0, 0);
|
||||
switch (m_settings->position())
|
||||
switch (prevPos)
|
||||
{
|
||||
case Top: finishPos.setY(-size.height()); break;
|
||||
case Bottom: finishPos.setY(size.height()); break;
|
||||
@ -320,41 +347,41 @@ void MainWindow::narrow()
|
||||
m_panelHideAni->start();
|
||||
}
|
||||
|
||||
void MainWindow::resetPanelEnvironment()
|
||||
void MainWindow::resetPanelEnvironment(const bool visible)
|
||||
{
|
||||
// reset environment
|
||||
m_sizeChangeAni->stop();
|
||||
m_posChangeAni->stop();
|
||||
const QSize size = m_settings->windowSize();
|
||||
const QRect primaryRect = m_settings->primaryRect();
|
||||
const int offsetX = (primaryRect.width() - size.width()) / 2;
|
||||
const int offsetY = (primaryRect.height() - size.height()) / 2;
|
||||
|
||||
m_mainPanel->move(0, 0);
|
||||
m_mainPanel->setFixedSize(size);
|
||||
QWidget::setFixedSize(size);
|
||||
m_sizeChangeAni->setEndValue(size);
|
||||
const Position position = m_settings->position();
|
||||
const QRect r(m_settings->windowRect(position));
|
||||
|
||||
QPoint position;
|
||||
switch (m_settings->position())
|
||||
m_sizeChangeAni->setEndValue(r.size());
|
||||
QWidget::setFixedSize(r.size());
|
||||
m_posChangeAni->setEndValue(r.topLeft());
|
||||
QWidget::move(r.topLeft());
|
||||
|
||||
m_mainPanel->setFixedSize(r.size());
|
||||
|
||||
QPoint finishPos(0, 0);
|
||||
if (!visible)
|
||||
{
|
||||
case Top:
|
||||
position = QPoint(primaryRect.topLeft().x() + offsetX, 0); break;
|
||||
case Left:
|
||||
position = QPoint(primaryRect.topLeft().x(), offsetY); break;
|
||||
case Right:
|
||||
position = QPoint(primaryRect.right() - size.width() + 1, offsetY); break;
|
||||
case Bottom:
|
||||
position = QPoint(offsetX, primaryRect.bottom() - size.height() + 1); break;
|
||||
default:
|
||||
Q_ASSERT(false);
|
||||
switch (position)
|
||||
{
|
||||
case Top: finishPos.setY(-r.height()); break;
|
||||
case Bottom: finishPos.setY(r.height()); break;
|
||||
case Left: finishPos.setX(-r.width()); break;
|
||||
case Right: finishPos.setX(r.width()); break;
|
||||
}
|
||||
}
|
||||
QWidget::move(position);
|
||||
m_posChangeAni->setEndValue(position);
|
||||
|
||||
m_mainPanel->move(finishPos);
|
||||
}
|
||||
|
||||
void MainWindow::updatePanelVisible()
|
||||
{
|
||||
if (!m_updatePanelVisible)
|
||||
return;
|
||||
if (m_settings->hideMode() == KeepShowing)
|
||||
return;
|
||||
|
||||
@ -374,7 +401,7 @@ void MainWindow::updatePanelVisible()
|
||||
if (r.contains(QCursor::pos()))
|
||||
break;
|
||||
|
||||
return narrow();
|
||||
return narrow(m_settings->position());
|
||||
|
||||
} while (false);
|
||||
|
||||
|
@ -30,17 +30,19 @@ private:
|
||||
void initConnections();
|
||||
|
||||
private slots:
|
||||
void positionChanged(const Position prevPos);
|
||||
void updatePosition();
|
||||
void updateGeometry();
|
||||
void clearStrutPartial();
|
||||
void setStrutPartial();
|
||||
|
||||
void expand();
|
||||
void narrow();
|
||||
void resetPanelEnvironment();
|
||||
void narrow(const Position prevPos);
|
||||
void resetPanelEnvironment(const bool visible);
|
||||
void updatePanelVisible();
|
||||
|
||||
private:
|
||||
bool m_updatePanelVisible;
|
||||
MainPanel *m_mainPanel;
|
||||
|
||||
QTimer *m_positionUpdateTimer;
|
||||
|
Loading…
x
Reference in New Issue
Block a user