mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 17:33:05 +00:00
update MainWindow's position when primary-screen's size changed
Change-Id: I48dff4b55722fea10d8e2625449864b5366a513f
This commit is contained in:
parent
e5565772df
commit
e54722b4e4
Notes:
Deepin Code Review
2016-06-14 07:19:47 +00:00
Verified+1: Anonymous Coward #1000004 Code-Review+2: <mr.asianwang@gmail.com> Submitted-by: <mr.asianwang@gmail.com> Submitted-at: Tue, 29 Sep 2015 10:41:09 +0800 Reviewed-on: https://cr.deepin.io/7457 Project: dde/dde-dock Branch: refs/heads/master
@ -4,41 +4,54 @@
|
||||
MainWidget::MainWidget(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
this->setWindowFlags(Qt::Window);
|
||||
this->setAttribute(Qt::WA_TranslucentBackground);
|
||||
|
||||
initHideStateManager();
|
||||
initDockSetting();
|
||||
|
||||
QRect rec = QApplication::desktop()->screenGeometry();
|
||||
this->setFixedSize(rec.width(),m_dmd->getDockHeight());
|
||||
this->move((rec.width() - width()) / 2, rec.height() - this->height());
|
||||
|
||||
m_mainPanel = new Panel(this);
|
||||
connect(m_mainPanel,&Panel::startShow,this,&MainWidget::showDock);
|
||||
connect(m_mainPanel,&Panel::panelHasHidden,this,&MainWidget::hideDock);
|
||||
connect(m_mainPanel, &Panel::sizeChanged, this, &MainWidget::onPanelSizeChanged);
|
||||
|
||||
this->setWindowFlags(Qt::Window);
|
||||
this->setAttribute(Qt::WA_TranslucentBackground);
|
||||
|
||||
connect(m_dmd, &DockModeData::dockModeChanged, this, &MainWidget::changeDockMode);
|
||||
connect(m_dmd, &DockModeData::dockModeChanged, this, &MainWidget::onDockModeChanged);
|
||||
|
||||
//For init
|
||||
changeDockMode(m_dmd->getDockMode(), m_dmd->getDockMode());
|
||||
updatePosition();
|
||||
|
||||
DockUIDbus *dockUIDbus = new DockUIDbus(this);
|
||||
Q_UNUSED(dockUIDbus)
|
||||
|
||||
XcbMisc::instance()->set_window_type(winId(),
|
||||
XcbMisc::Dock);
|
||||
XcbMisc::instance()->set_window_type(winId(), XcbMisc::Dock);
|
||||
|
||||
connect(QApplication::desktop(), &QDesktopWidget::workAreaResized, [=](int screen) {
|
||||
if (screen == QApplication::desktop()->primaryScreen()) {
|
||||
QRect rect = QApplication::desktop()->screenGeometry(screen);
|
||||
qWarning() << QString("PrimaryScreen(index: %0) size changed %1x%2").arg(screen).arg(rect.width()).arg(rect.height());
|
||||
updatePosition();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void MainWidget::changeDockMode(Dock::DockMode, Dock::DockMode)
|
||||
void MainWidget::onDockModeChanged()
|
||||
{
|
||||
if (hasHidden)
|
||||
return;
|
||||
updatePosition();
|
||||
}
|
||||
|
||||
void MainWidget::updatePosition()
|
||||
{
|
||||
QRect rec = QApplication::desktop()->screenGeometry();
|
||||
this->setFixedSize(rec.width(),m_dmd->getDockHeight());
|
||||
this->move((rec.width() - width()) / 2, rec.height() - this->height());
|
||||
if (m_hasHidden) {
|
||||
//set height with 0 mean window is hidden,Windows manager will handle it's showing animation
|
||||
this->setFixedSize(m_mainPanel->width(), 1);
|
||||
this->move((rec.width() - width()) / 2, rec.height() - 1);//1 pixel for grab mouse enter event to show panel
|
||||
}
|
||||
else {
|
||||
|
||||
this->setFixedSize(m_mainPanel->width(), m_dmd->getDockHeight());
|
||||
this->move((rec.width() - width()) / 2, rec.height() - this->height());
|
||||
}
|
||||
|
||||
updateXcbStructPartial();
|
||||
}
|
||||
@ -67,7 +80,7 @@ void MainWidget::initDockSetting()
|
||||
connect(m_dds, &DBusDockSetting::HideModeChanged, this, &MainWidget::updateXcbStructPartial);
|
||||
}
|
||||
|
||||
void MainWidget::enterEvent(QEvent *event)
|
||||
void MainWidget::enterEvent(QEvent *)
|
||||
{
|
||||
if (height() == 1){
|
||||
showDock();
|
||||
@ -83,27 +96,20 @@ void MainWidget::leaveEvent(QEvent *)
|
||||
|
||||
void MainWidget::showDock()
|
||||
{
|
||||
hasHidden = false;
|
||||
QRect rec = QApplication::desktop()->screenGeometry();
|
||||
this->setFixedSize(m_mainPanel->width(), m_dmd->getDockHeight());
|
||||
this->move((rec.width() - width()) / 2, rec.height() - this->height());
|
||||
updateXcbStructPartial();
|
||||
m_hasHidden = false;
|
||||
updatePosition();
|
||||
}
|
||||
|
||||
void MainWidget::hideDock()
|
||||
{
|
||||
hasHidden = true;
|
||||
QRect rec = QApplication::desktop()->screenGeometry();
|
||||
//set height with 0 mean window is hidden,Windows manager will handle it's showing animation
|
||||
this->setFixedSize(m_mainPanel->width(), 1);
|
||||
this->move((rec.width() - width()) / 2, rec.height() - 1);//1 pixel for grab mouse enter event to show panel
|
||||
updateXcbStructPartial();
|
||||
m_hasHidden = true;
|
||||
updatePosition();
|
||||
}
|
||||
|
||||
void MainWidget::onPanelSizeChanged()
|
||||
{
|
||||
this->setFixedSize(m_mainPanel->size());
|
||||
QRect rec = QApplication::desktop()->screenGeometry();
|
||||
this->setFixedSize(m_mainPanel->size());
|
||||
this->move((rec.width() - width()) / 2, y());
|
||||
}
|
||||
|
||||
|
@ -28,21 +28,22 @@ public:
|
||||
void loadResources();
|
||||
|
||||
protected:
|
||||
void enterEvent(QEvent *event);
|
||||
void enterEvent(QEvent *);
|
||||
void leaveEvent(QEvent *);
|
||||
|
||||
private:
|
||||
void showDock();
|
||||
void hideDock();
|
||||
void onPanelSizeChanged();
|
||||
void changeDockMode(Dock::DockMode, Dock::DockMode);
|
||||
void onDockModeChanged();
|
||||
void updatePosition();
|
||||
void updateXcbStructPartial();
|
||||
void initHideStateManager();
|
||||
void initDockSetting();
|
||||
|
||||
private:
|
||||
Panel *m_mainPanel = NULL;
|
||||
bool hasHidden = false;
|
||||
bool m_hasHidden = false;
|
||||
DockModeData * m_dmd = DockModeData::instance();
|
||||
DBusHideStateManager *m_dhsm = NULL;
|
||||
DBusDockSetting *m_dds = NULL;
|
||||
|
Loading…
x
Reference in New Issue
Block a user