mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 09:23:03 +00:00
add smart hide
Change-Id: I6bb541da47a3eb19f208af2ec6a25fe8dc216764
This commit is contained in:
parent
3b93eb668d
commit
9ad6126e92
@ -92,6 +92,7 @@ DockSettings::DockSettings(QWidget *parent)
|
||||
connect(m_dockInter, &DBusDock::IconSizeChanged, this, &DockSettings::iconSizeChanged);
|
||||
connect(m_dockInter, &DBusDock::DisplayModeChanged, this, &DockSettings::displayModeChanged);
|
||||
connect(m_dockInter, &DBusDock::HideModeChanged, this, &DockSettings::hideModeChanged);
|
||||
connect(m_dockInter, &DBusDock::HideStateChanged, this, &DockSettings::windowVisibleChanegd);
|
||||
|
||||
connect(m_itemController, &DockItemController::itemInserted, this, &DockSettings::dockItemCountChanged, Qt::QueuedConnection);
|
||||
connect(m_itemController, &DockItemController::itemRemoved, this, &DockSettings::dockItemCountChanged, Qt::QueuedConnection);
|
||||
@ -106,6 +107,11 @@ DisplayMode DockSettings::displayMode() const
|
||||
return m_displayMode;
|
||||
}
|
||||
|
||||
HideMode DockSettings::hideMode() const
|
||||
{
|
||||
return m_hideMode;
|
||||
}
|
||||
|
||||
Position DockSettings::position() const
|
||||
{
|
||||
return m_position;
|
||||
@ -116,6 +122,11 @@ int DockSettings::screenHeight() const
|
||||
return m_displayInter->screenHeight();
|
||||
}
|
||||
|
||||
HideState DockSettings::hideState() const
|
||||
{
|
||||
return HideState(m_dockInter->hideState());
|
||||
}
|
||||
|
||||
const QRect DockSettings::primaryRect() const
|
||||
{
|
||||
return m_primaryRect;
|
||||
@ -217,6 +228,8 @@ void DockSettings::displayModeChanged()
|
||||
void DockSettings::hideModeChanged()
|
||||
{
|
||||
m_hideMode = Dock::HideMode(m_dockInter->hideMode());
|
||||
|
||||
emit windowHideModeChanged();
|
||||
}
|
||||
|
||||
void DockSettings::dockItemCountChanged()
|
||||
|
@ -25,6 +25,8 @@ public:
|
||||
explicit DockSettings(QWidget *parent = 0);
|
||||
|
||||
DisplayMode displayMode() const;
|
||||
HideMode hideMode() const;
|
||||
HideState hideState() const;
|
||||
Position position() const;
|
||||
int screenHeight() const;
|
||||
const QRect primaryRect() const;
|
||||
@ -34,6 +36,8 @@ public:
|
||||
|
||||
signals:
|
||||
void dataChanged() const;
|
||||
void windowVisibleChanegd() const;
|
||||
void windowHideModeChanged() const;
|
||||
void windowGeometryChanged() const;
|
||||
|
||||
public slots:
|
||||
|
@ -10,6 +10,8 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
m_positionUpdateTimer(new QTimer(this)),
|
||||
m_sizeChangeAni(new QPropertyAnimation(this, "size")),
|
||||
m_posChangeAni(new QPropertyAnimation(this, "pos")),
|
||||
m_panelShowAni(new QPropertyAnimation(m_mainPanel, "pos")),
|
||||
m_panelHideAni(new QPropertyAnimation(m_mainPanel, "pos")),
|
||||
m_xcbMisc(XcbMisc::instance())
|
||||
{
|
||||
setWindowFlags(Qt::FramelessWindowHint | Qt::WindowDoesNotAcceptFocus);
|
||||
@ -32,8 +34,6 @@ MainWindow::~MainWindow()
|
||||
void MainWindow::resizeEvent(QResizeEvent *e)
|
||||
{
|
||||
QWidget::resizeEvent(e);
|
||||
|
||||
m_mainPanel->setFixedSize(e->size());
|
||||
}
|
||||
|
||||
void MainWindow::mousePressEvent(QMouseEvent *e)
|
||||
@ -55,6 +55,21 @@ void MainWindow::keyPressEvent(QKeyEvent *e)
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::enterEvent(QEvent *e)
|
||||
{
|
||||
QWidget::enterEvent(e);
|
||||
|
||||
if (m_settings->hideState() != Show)
|
||||
expand();
|
||||
}
|
||||
|
||||
void MainWindow::leaveEvent(QEvent *e)
|
||||
{
|
||||
QWidget::leaveEvent(e);
|
||||
|
||||
updatePanelVisible();
|
||||
}
|
||||
|
||||
void MainWindow::setFixedSize(const QSize &size)
|
||||
{
|
||||
if (m_sizeChangeAni->state() == QPropertyAnimation::Running)
|
||||
@ -92,6 +107,10 @@ void MainWindow::initConnections()
|
||||
{
|
||||
connect(m_settings, &DockSettings::dataChanged, m_positionUpdateTimer, static_cast<void (QTimer::*)()>(&QTimer::start));
|
||||
connect(m_settings, &DockSettings::windowGeometryChanged, this, &MainWindow::updateGeometry);
|
||||
connect(m_settings, &DockSettings::windowHideModeChanged, this, &MainWindow::setStrutPartial);
|
||||
connect(m_settings, &DockSettings::windowVisibleChanegd, this, &MainWindow::updatePanelVisible);
|
||||
|
||||
connect(m_panelHideAni, &QPropertyAnimation::finished, this, &MainWindow::updateGeometry);
|
||||
|
||||
connect(m_positionUpdateTimer, &QTimer::timeout, this, &MainWindow::updatePosition);
|
||||
}
|
||||
@ -108,16 +127,35 @@ void MainWindow::updatePosition()
|
||||
|
||||
void MainWindow::updateGeometry()
|
||||
{
|
||||
const QSize size = m_settings->windowSize();
|
||||
const Position position = m_settings->position();
|
||||
|
||||
setFixedSize(size);
|
||||
m_mainPanel->updateDockPosition(m_settings->position());
|
||||
m_mainPanel->setFixedSize(m_settings->windowSize());
|
||||
m_mainPanel->updateDockPosition(position);
|
||||
m_mainPanel->updateDockDisplayMode(m_settings->displayMode());
|
||||
|
||||
QSize size = m_settings->windowSize();
|
||||
if (m_settings->hideState() == Hide)
|
||||
{
|
||||
m_sizeChangeAni->stop();
|
||||
switch (position)
|
||||
{
|
||||
case Top:
|
||||
case Bottom: size.setHeight(1); break;
|
||||
case Left:
|
||||
case Right: size.setWidth(1); break;
|
||||
}
|
||||
QWidget::setFixedSize(size);
|
||||
}
|
||||
else
|
||||
{
|
||||
setFixedSize(size);
|
||||
}
|
||||
|
||||
const QRect primaryRect = m_settings->primaryRect();
|
||||
const int offsetX = (primaryRect.width() - size.width()) / 2;
|
||||
const int offsetY = (primaryRect.height() - size.height()) / 2;
|
||||
switch (m_settings->position())
|
||||
|
||||
switch (position)
|
||||
{
|
||||
case Top:
|
||||
move(primaryRect.topLeft().x() + offsetX, 0); break;
|
||||
@ -131,7 +169,7 @@ void MainWindow::updateGeometry()
|
||||
Q_ASSERT(false);
|
||||
}
|
||||
|
||||
m_mainPanel->update();
|
||||
update();
|
||||
}
|
||||
|
||||
void MainWindow::clearStrutPartial()
|
||||
@ -144,13 +182,16 @@ void MainWindow::setStrutPartial()
|
||||
// first, clear old strut partial
|
||||
clearStrutPartial();
|
||||
|
||||
if (m_settings->hideMode() != Dock::KeepShowing)
|
||||
return;
|
||||
|
||||
const Position side = m_settings->position();
|
||||
const int maxScreenHeight = m_settings->screenHeight();
|
||||
|
||||
XcbMisc::Orientation orientation;
|
||||
uint strut;
|
||||
uint strutStart;
|
||||
uint strutEnd;
|
||||
XcbMisc::Orientation orientation = XcbMisc::OrientationTop;
|
||||
uint strut = 0;
|
||||
uint strutStart = 0;
|
||||
uint strutEnd = 0;
|
||||
|
||||
const QPoint p = m_posChangeAni->endValue().toPoint();
|
||||
const QRect r = QRect(p, m_settings->windowSize());
|
||||
@ -186,3 +227,86 @@ void MainWindow::setStrutPartial()
|
||||
|
||||
m_xcbMisc->set_strut_partial(winId(), orientation, strut, strutStart, strutEnd);
|
||||
}
|
||||
|
||||
void MainWindow::expand()
|
||||
{
|
||||
if (m_mainPanel->pos() == QPoint(0, 0))
|
||||
return;
|
||||
|
||||
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;
|
||||
|
||||
QWidget::setFixedSize(size);
|
||||
switch (m_settings->position())
|
||||
{
|
||||
case Top:
|
||||
QWidget::move(primaryRect.topLeft().x() + offsetX, 0); break;
|
||||
case Left:
|
||||
QWidget::move(primaryRect.topLeft().x(), offsetY); break;
|
||||
case Right:
|
||||
QWidget::move(primaryRect.right() - size.width() + 1, offsetY); break;
|
||||
case Bottom:
|
||||
QWidget::move(offsetX, primaryRect.bottom() - size.height() + 1); break;
|
||||
default:
|
||||
Q_ASSERT(false);
|
||||
}
|
||||
|
||||
const QPoint finishPos(0, 0);
|
||||
if (m_panelShowAni->state() == QPropertyAnimation::Running)
|
||||
return m_panelShowAni->setEndValue(finishPos);
|
||||
|
||||
QPoint startPos(0, 0);
|
||||
switch (m_settings->position())
|
||||
{
|
||||
case Top: startPos.setY(-size.height()); break;
|
||||
case Bottom: startPos.setY(size.height()); break;
|
||||
case Left: startPos.setX(-size.width()); break;
|
||||
case Right: startPos.setX(size.width()); break;
|
||||
}
|
||||
|
||||
m_panelHideAni->stop();
|
||||
m_panelShowAni->setStartValue(startPos);
|
||||
m_panelShowAni->setEndValue(finishPos);
|
||||
m_panelShowAni->start();
|
||||
}
|
||||
|
||||
void MainWindow::narrow()
|
||||
{
|
||||
const QSize size = m_mainPanel->size();
|
||||
|
||||
QPoint finishPos(0, 0);
|
||||
switch (m_settings->position())
|
||||
{
|
||||
case Top: finishPos.setY(-size.height()); break;
|
||||
case Bottom: finishPos.setY(size.height()); break;
|
||||
case Left: finishPos.setX(-size.width()); break;
|
||||
case Right: finishPos.setX(size.width()); break;
|
||||
}
|
||||
|
||||
if (m_panelHideAni->state() == QPropertyAnimation::Running)
|
||||
return m_panelHideAni->setEndValue(finishPos);
|
||||
|
||||
m_panelShowAni->stop();
|
||||
m_panelHideAni->setStartValue(m_mainPanel->pos());
|
||||
m_panelHideAni->setEndValue(finishPos);
|
||||
m_panelHideAni->start();
|
||||
}
|
||||
|
||||
void MainWindow::updatePanelVisible()
|
||||
{
|
||||
const Dock::HideState state = m_settings->hideState();
|
||||
|
||||
// qDebug() << state;
|
||||
|
||||
if (state == Unknown)
|
||||
return;
|
||||
|
||||
if (state == Show)
|
||||
expand();
|
||||
else
|
||||
narrow();
|
||||
}
|
||||
|
@ -21,6 +21,9 @@ private:
|
||||
void resizeEvent(QResizeEvent *e);
|
||||
void mousePressEvent(QMouseEvent *e);
|
||||
void keyPressEvent(QKeyEvent *e);
|
||||
void enterEvent(QEvent *e);
|
||||
void leaveEvent(QEvent *e);
|
||||
|
||||
void setFixedSize(const QSize &size);
|
||||
void move(int x, int y);
|
||||
void initComponents();
|
||||
@ -32,12 +35,18 @@ private slots:
|
||||
void clearStrutPartial();
|
||||
void setStrutPartial();
|
||||
|
||||
void expand();
|
||||
void narrow();
|
||||
void updatePanelVisible();
|
||||
|
||||
private:
|
||||
MainPanel *m_mainPanel;
|
||||
|
||||
QTimer *m_positionUpdateTimer;
|
||||
QPropertyAnimation *m_sizeChangeAni;
|
||||
QPropertyAnimation *m_posChangeAni;
|
||||
QPropertyAnimation *m_panelShowAni;
|
||||
QPropertyAnimation *m_panelHideAni;
|
||||
|
||||
XcbMisc *m_xcbMisc;
|
||||
DockSettings *m_settings;
|
||||
|
Loading…
x
Reference in New Issue
Block a user