mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 17:33:05 +00:00
feat(dock): change mainwindow size drag logic
This commit is contained in:
parent
865cb40b78
commit
afc4e33016
@ -54,6 +54,12 @@ MainPanelControl::MainPanelControl(QWidget *parent)
|
|||||||
updateMainPanelLayout();
|
updateMainPanelLayout();
|
||||||
updateDisplayMode();
|
updateDisplayMode();
|
||||||
setAcceptDrops(true);
|
setAcceptDrops(true);
|
||||||
|
setMouseTracking(true);
|
||||||
|
m_fixedAreaWidget->setMouseTracking(true);
|
||||||
|
m_appAreaWidget->setMouseTracking(true);
|
||||||
|
m_appAreaSonWidget->setMouseTracking(true);
|
||||||
|
m_trayAreaWidget->setMouseTracking(true);
|
||||||
|
m_pluginAreaWidget->setMouseTracking(true);
|
||||||
|
|
||||||
connect(this, SIGNAL(displayModeChanged()), this, SLOT(onDisplayModeChanged()));
|
connect(this, SIGNAL(displayModeChanged()), this, SLOT(onDisplayModeChanged()));
|
||||||
connect(this, SIGNAL(positionChanged()), this, SLOT(onPositionChanged()));
|
connect(this, SIGNAL(positionChanged()), this, SLOT(onPositionChanged()));
|
||||||
@ -89,7 +95,7 @@ void MainPanelControl::init()
|
|||||||
m_pluginLayout->setSpacing(0);
|
m_pluginLayout->setSpacing(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainPanelControl::setDisplayMode(const DisplayMode mode)
|
void MainPanelControl::setDisplayMode(DisplayMode mode)
|
||||||
{
|
{
|
||||||
if (mode == m_dislayMode)
|
if (mode == m_dislayMode)
|
||||||
return;
|
return;
|
||||||
@ -131,22 +137,22 @@ void MainPanelControl::updateMainPanelLayout()
|
|||||||
QTimer::singleShot(0, this, &MainPanelControl::updateAppAreaSonWidgetSize);
|
QTimer::singleShot(0, this, &MainPanelControl::updateAppAreaSonWidgetSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainPanelControl::addFixedAreaItem(const int index, QWidget *wdg)
|
void MainPanelControl::addFixedAreaItem(int index, QWidget *wdg)
|
||||||
{
|
{
|
||||||
m_fixedAreaLayout->insertWidget(index, wdg, 0, Qt::AlignCenter);
|
m_fixedAreaLayout->insertWidget(index, wdg, 0, Qt::AlignCenter);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainPanelControl::addAppAreaItem(const int index, QWidget *wdg)
|
void MainPanelControl::addAppAreaItem(int index, QWidget *wdg)
|
||||||
{
|
{
|
||||||
m_appAreaSonLayout->insertWidget(index, wdg, 0, Qt::AlignCenter);
|
m_appAreaSonLayout->insertWidget(index, wdg, 0, Qt::AlignCenter);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainPanelControl::addTrayAreaItem(const int index, QWidget *wdg)
|
void MainPanelControl::addTrayAreaItem(int index, QWidget *wdg)
|
||||||
{
|
{
|
||||||
m_trayAreaLayout->insertWidget(index, wdg, 0, Qt::AlignCenter);
|
m_trayAreaLayout->insertWidget(index, wdg, 0, Qt::AlignCenter);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainPanelControl::addPluginAreaItem(const int index, QWidget *wdg)
|
void MainPanelControl::addPluginAreaItem(int index, QWidget *wdg)
|
||||||
{
|
{
|
||||||
m_pluginLayout->insertWidget(index, wdg, 0, Qt::AlignCenter);
|
m_pluginLayout->insertWidget(index, wdg, 0, Qt::AlignCenter);
|
||||||
}
|
}
|
||||||
@ -211,7 +217,7 @@ void MainPanelControl::updateAppAreaSonWidgetSize()
|
|||||||
m_appAreaSonWidget->adjustSize();
|
m_appAreaSonWidget->adjustSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainPanelControl::setPositonValue(const Position position)
|
void MainPanelControl::setPositonValue(Position position)
|
||||||
{
|
{
|
||||||
if (m_position == position)
|
if (m_position == position)
|
||||||
return;
|
return;
|
||||||
@ -219,7 +225,7 @@ void MainPanelControl::setPositonValue(const Position position)
|
|||||||
emit positionChanged();
|
emit positionChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainPanelControl::insertItem(const int index, DockItem *item)
|
void MainPanelControl::insertItem(int index, DockItem *item)
|
||||||
{
|
{
|
||||||
item->installEventFilter(this);
|
item->installEventFilter(this);
|
||||||
|
|
||||||
@ -595,12 +601,9 @@ void MainPanelControl::onDisplayModeChanged()
|
|||||||
{
|
{
|
||||||
updateDisplayMode();
|
updateDisplayMode();
|
||||||
}
|
}
|
||||||
void MainPanelControl::updatePosition()
|
|
||||||
{
|
|
||||||
onPositionChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainPanelControl::onPositionChanged()
|
void MainPanelControl::onPositionChanged()
|
||||||
{
|
{
|
||||||
updateMainPanelLayout();
|
updateMainPanelLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,16 +45,16 @@ public:
|
|||||||
MainPanelControl(QWidget *parent = 0);
|
MainPanelControl(QWidget *parent = 0);
|
||||||
~MainPanelControl();
|
~MainPanelControl();
|
||||||
|
|
||||||
void addFixedAreaItem(const int index, QWidget *wdg);
|
void addFixedAreaItem(int index, QWidget *wdg);
|
||||||
void addAppAreaItem(const int index, QWidget *wdg);
|
void addAppAreaItem(int index, QWidget *wdg);
|
||||||
void addTrayAreaItem(const int index, QWidget *wdg);
|
void addTrayAreaItem(int index, QWidget *wdg);
|
||||||
void addPluginAreaItem(const int index, QWidget *wdg);
|
void addPluginAreaItem(int index, QWidget *wdg);
|
||||||
void removeFixedAreaItem(QWidget *wdg);
|
void removeFixedAreaItem(QWidget *wdg);
|
||||||
void removeAppAreaItem(QWidget *wdg);
|
void removeAppAreaItem(QWidget *wdg);
|
||||||
void removeTrayAreaItem(QWidget *wdg);
|
void removeTrayAreaItem(QWidget *wdg);
|
||||||
void removePluginAreaItem(QWidget *wdg);
|
void removePluginAreaItem(QWidget *wdg);
|
||||||
void setPositonValue(const Position position);
|
void setPositonValue(Position position);
|
||||||
void setDisplayMode(const DisplayMode m_displayMode);
|
void setDisplayMode(DisplayMode m_displayMode);
|
||||||
|
|
||||||
MainPanelDelegate *delegate() const;
|
MainPanelDelegate *delegate() const;
|
||||||
void setDelegate(MainPanelDelegate *delegate);
|
void setDelegate(MainPanelDelegate *delegate);
|
||||||
@ -72,7 +72,6 @@ private:
|
|||||||
void updateAppAreaSonWidgetSize();
|
void updateAppAreaSonWidgetSize();
|
||||||
void updateMainPanelLayout();
|
void updateMainPanelLayout();
|
||||||
void updateDisplayMode();
|
void updateDisplayMode();
|
||||||
void updatePosition();
|
|
||||||
|
|
||||||
void dragMoveEvent(QDragMoveEvent *e) override;
|
void dragMoveEvent(QDragMoveEvent *e) override;
|
||||||
void dragEnterEvent(QDragEnterEvent *e) override;
|
void dragEnterEvent(QDragEnterEvent *e) override;
|
||||||
|
@ -42,7 +42,7 @@
|
|||||||
|
|
||||||
#define MAINWINDOW_MAX_SIZE (100)
|
#define MAINWINDOW_MAX_SIZE (100)
|
||||||
#define MAINWINDOW_MIN_SIZE (40)
|
#define MAINWINDOW_MIN_SIZE (40)
|
||||||
#define MAINWINDOW_DRAG_AREA_SIZE (2)
|
#define MAINWINDOW_DRAG_AREA_SIZE (5)
|
||||||
|
|
||||||
using org::kde::StatusNotifierWatcher;
|
using org::kde::StatusNotifierWatcher;
|
||||||
|
|
||||||
@ -89,7 +89,7 @@ MainWindow::MainWindow(QWidget *parent)
|
|||||||
m_xcbMisc(XcbMisc::instance()),
|
m_xcbMisc(XcbMisc::instance()),
|
||||||
m_dbusDaemonInterface(QDBusConnection::sessionBus().interface()),
|
m_dbusDaemonInterface(QDBusConnection::sessionBus().interface()),
|
||||||
m_sniWatcher(new StatusNotifierWatcher(SNI_WATCHER_SERVICE, SNI_WATCHER_PATH, QDBusConnection::sessionBus(), this)),
|
m_sniWatcher(new StatusNotifierWatcher(SNI_WATCHER_SERVICE, SNI_WATCHER_PATH, QDBusConnection::sessionBus(), this)),
|
||||||
m_dragStatus(false)
|
m_dragStatus(NoClick)
|
||||||
{
|
{
|
||||||
setAccessibleName("dock-mainwindow");
|
setAccessibleName("dock-mainwindow");
|
||||||
setAttribute(Qt::WA_TranslucentBackground);
|
setAttribute(Qt::WA_TranslucentBackground);
|
||||||
@ -198,12 +198,15 @@ void MainWindow::showEvent(QShowEvent *e)
|
|||||||
void MainWindow::mousePressEvent(QMouseEvent *e)
|
void MainWindow::mousePressEvent(QMouseEvent *e)
|
||||||
{
|
{
|
||||||
e->ignore();
|
e->ignore();
|
||||||
|
if (e->button() == Qt::RightButton) {
|
||||||
if (e->button() == Qt::RightButton)
|
|
||||||
m_settings->showDockSettingsMenu();
|
m_settings->showDockSettingsMenu();
|
||||||
|
return;
|
||||||
|
}
|
||||||
if ((e->button() == Qt::LeftButton) && (!getNoneResizeRegion().contains(e->pos()))) {
|
if ((e->button() == Qt::LeftButton) && (!getNoneResizeRegion().contains(e->pos()))) {
|
||||||
m_resizePoint = e->globalPos();
|
m_resizePoint = e->globalPos();
|
||||||
m_dragStatus = true;
|
m_dragStatus = ClickInDragArea;
|
||||||
|
} else {
|
||||||
|
m_dragStatus = ClickNotInDragArea;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -231,6 +234,7 @@ void MainWindow::leaveEvent(QEvent *e)
|
|||||||
QWidget::leaveEvent(e);
|
QWidget::leaveEvent(e);
|
||||||
m_expandDelayTimer->stop();
|
m_expandDelayTimer->stop();
|
||||||
m_leaveDelayTimer->start();
|
m_leaveDelayTimer->start();
|
||||||
|
m_dragStatus = NoClick;
|
||||||
setCursor(Qt::ArrowCursor);
|
setCursor(Qt::ArrowCursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -728,9 +732,9 @@ void MainWindow::resetPanelEnvironment(const bool visible, const bool resetPosit
|
|||||||
QPoint finishPos(0, 0);
|
QPoint finishPos(0, 0);
|
||||||
switch (position) {
|
switch (position) {
|
||||||
case Top: finishPos.setY((visible ? 0 : -r.height())); break;
|
case Top: finishPos.setY((visible ? 0 : -r.height())); break;
|
||||||
case Bottom: finishPos.setY(visible ? MAINWINDOW_DRAG_AREA_SIZE * 2 : r.height()); break;
|
case Bottom: finishPos.setY(visible ? 0 : r.height()); break;
|
||||||
case Left: finishPos.setX((visible ? 0 : -r.width())); break;
|
case Left: finishPos.setX((visible ? 0 : -r.width())); break;
|
||||||
case Right: finishPos.setX(visible ? MAINWINDOW_DRAG_AREA_SIZE * 2 : r.width()); break;
|
case Right: finishPos.setX(visible ? 0 : r.width()); break;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_mainPanel->move(finishPos);
|
m_mainPanel->move(finishPos);
|
||||||
@ -841,7 +845,7 @@ void MainWindow::mouseMoveEvent(QMouseEvent *event)
|
|||||||
{
|
{
|
||||||
QPoint mousePoint = event->pos();
|
QPoint mousePoint = event->pos();
|
||||||
QRect r = getNoneResizeRegion();
|
QRect r = getNoneResizeRegion();
|
||||||
if (!r.contains(mousePoint) || (m_dragStatus == true)) {
|
if ((!r.contains(mousePoint) && (NoClick == m_dragStatus)) || (ClickInDragArea == m_dragStatus)) {
|
||||||
if ((Dock::Top == m_settings->position()) || (Dock::Bottom == m_settings->position())) {
|
if ((Dock::Top == m_settings->position()) || (Dock::Bottom == m_settings->position())) {
|
||||||
setCursor(Qt::SizeVerCursor);
|
setCursor(Qt::SizeVerCursor);
|
||||||
} else {
|
} else {
|
||||||
@ -851,7 +855,7 @@ void MainWindow::mouseMoveEvent(QMouseEvent *event)
|
|||||||
setCursor(Qt::ArrowCursor);
|
setCursor(Qt::ArrowCursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_dragStatus) {
|
if (ClickInDragArea == m_dragStatus) {
|
||||||
int xdiff = QCursor::pos().x() - m_resizePoint.x();
|
int xdiff = QCursor::pos().x() - m_resizePoint.x();
|
||||||
int ydiff = QCursor::pos().y() - m_resizePoint.y();
|
int ydiff = QCursor::pos().y() - m_resizePoint.y();
|
||||||
|
|
||||||
@ -875,7 +879,7 @@ void MainWindow::mouseMoveEvent(QMouseEvent *event)
|
|||||||
|
|
||||||
void MainWindow::mouseReleaseEvent(QMouseEvent *event)
|
void MainWindow::mouseReleaseEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
m_dragStatus = false;
|
m_dragStatus = NoClick;
|
||||||
m_size = m_settings->m_mainWindowSize;
|
m_size = m_settings->m_mainWindowSize;
|
||||||
setStrutPartial();
|
setStrutPartial();
|
||||||
setCursor(Qt::ArrowCursor);
|
setCursor(Qt::ArrowCursor);
|
||||||
@ -924,11 +928,11 @@ void MainWindow::resizeMainPanelWindow()
|
|||||||
switch (m_settings->position()) {
|
switch (m_settings->position()) {
|
||||||
case Dock::Top:
|
case Dock::Top:
|
||||||
case Dock::Bottom:
|
case Dock::Bottom:
|
||||||
m_mainPanel->setFixedSize(m_settings->panelSize() - QSize(0, MAINWINDOW_DRAG_AREA_SIZE * 2));
|
m_mainPanel->setFixedSize(m_settings->panelSize());
|
||||||
break;
|
break;
|
||||||
case Dock::Left:
|
case Dock::Left:
|
||||||
case Dock::Right:
|
case Dock::Right:
|
||||||
m_mainPanel->setFixedSize(m_settings->panelSize() - QSize(MAINWINDOW_DRAG_AREA_SIZE * 2, 0));
|
m_mainPanel->setFixedSize(m_settings->panelSize());
|
||||||
break;
|
break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
|
@ -109,6 +109,12 @@ private slots:
|
|||||||
void onDbusNameOwnerChanged(const QString &name, const QString &oldOwner, const QString &newOwner);
|
void onDbusNameOwnerChanged(const QString &name, const QString &oldOwner, const QString &newOwner);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
enum IsClickInDragAreaStatus {
|
||||||
|
NoClick = 0,
|
||||||
|
ClickNotInDragArea,
|
||||||
|
ClickInDragArea
|
||||||
|
};
|
||||||
|
|
||||||
bool m_launched;
|
bool m_launched;
|
||||||
bool m_updatePanelVisible;
|
bool m_updatePanelVisible;
|
||||||
MainPanelControl *m_mainPanel;
|
MainPanelControl *m_mainPanel;
|
||||||
@ -131,7 +137,7 @@ private:
|
|||||||
QDBusConnectionInterface *m_dbusDaemonInterface;
|
QDBusConnectionInterface *m_dbusDaemonInterface;
|
||||||
org::kde::StatusNotifierWatcher *m_sniWatcher;
|
org::kde::StatusNotifierWatcher *m_sniWatcher;
|
||||||
QString m_sniHostService;
|
QString m_sniHostService;
|
||||||
bool m_dragStatus;
|
IsClickInDragAreaStatus m_dragStatus;
|
||||||
QPoint m_resizePoint;
|
QPoint m_resizePoint;
|
||||||
QSize m_size;
|
QSize m_size;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user