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