From e6bcc1e45af415b8cc7909f89e7c0b88ea179528 Mon Sep 17 00:00:00 2001 From: wangxuwen Date: Mon, 19 Aug 2019 15:17:56 +0800 Subject: [PATCH] feal(mainpanel): add moveitem function and add a new function variable --- frame/panel/mainpanelcontrol.cpp | 36 +++++++++++++++++++------------- frame/panel/mainpanelcontrol.h | 13 ++++++------ frame/window/mainwindow.cpp | 6 +++--- 3 files changed, 32 insertions(+), 23 deletions(-) diff --git a/frame/panel/mainpanelcontrol.cpp b/frame/panel/mainpanelcontrol.cpp index 195b4717c..ca1fdaebe 100644 --- a/frame/panel/mainpanelcontrol.cpp +++ b/frame/panel/mainpanelcontrol.cpp @@ -114,24 +114,24 @@ void MainPanelControl::updateMainPanelLayout() QTimer::singleShot(0, this, &MainPanelControl::updateAppAreaSonWidgetSize); } -void MainPanelControl::addFixedAreaItem(QWidget *wdg) +void MainPanelControl::addFixedAreaItem(const int index, QWidget *wdg) { - m_fixedAreaLayout->addWidget(wdg, 0, Qt::AlignCenter); + m_fixedAreaLayout->insertWidget(index, wdg, 0, Qt::AlignCenter); } -void MainPanelControl::addAppAreaItem(QWidget *wdg) +void MainPanelControl::addAppAreaItem(const int index, QWidget *wdg) { - m_appAreaSonLayout->addWidget(wdg, 0, Qt::AlignCenter); + m_appAreaSonLayout->insertWidget(index, wdg, 0, Qt::AlignCenter); } -void MainPanelControl::addTrayAreaItem(QWidget *wdg) +void MainPanelControl::addTrayAreaItem(const int index, QWidget *wdg) { - m_trayAreaLayout->addWidget(wdg, 0, Qt::AlignCenter); + m_trayAreaLayout->insertWidget(index, wdg, 0, Qt::AlignCenter); } -void MainPanelControl::addPluginAreaItem(QWidget *wdg) +void MainPanelControl::addPluginAreaItem(const int index, QWidget *wdg) { - m_pluginLayout->addWidget(wdg, 0, Qt::AlignCenter); + m_pluginLayout->insertWidget(index, wdg, 0, Qt::AlignCenter); } void MainPanelControl::removeFixedAreaItem(QWidget *wdg) @@ -179,20 +179,20 @@ void MainPanelControl::setPositonValue(const Qt::Edge val) m_position = val; } -void MainPanelControl::itemInserted(const int index, DockItem *item) +void MainPanelControl::insertItem(const int index, DockItem *item) { switch (item->itemType()) { case DockItem::Launcher: - addFixedAreaItem(item); + addFixedAreaItem(index, item); break; case DockItem::App: - addAppAreaItem(item); + addAppAreaItem(index, item); break; case DockItem::TrayPlugin: - addTrayAreaItem(item); + addTrayAreaItem(index, item); break; case DockItem::Plugins: - addPluginAreaItem(item); + addPluginAreaItem(index, item); break; default: break; @@ -201,7 +201,7 @@ void MainPanelControl::itemInserted(const int index, DockItem *item) updateAppAreaSonWidgetSize(); } -void MainPanelControl::itemRemoved(DockItem *item) +void MainPanelControl::removeItem(DockItem *item) { switch (item->itemType()) { case DockItem::Launcher: @@ -223,3 +223,11 @@ void MainPanelControl::itemRemoved(DockItem *item) updateAppAreaSonWidgetSize(); } + void MainPanelControl::movedItem(const int index, DockItem *item) +{ + // remove old item + removeItem(item); + // insert new position + insertItem(index, item); +} + diff --git a/frame/panel/mainpanelcontrol.h b/frame/panel/mainpanelcontrol.h index e4e65da09..88b314d9d 100644 --- a/frame/panel/mainpanelcontrol.h +++ b/frame/panel/mainpanelcontrol.h @@ -33,10 +33,10 @@ public: MainPanelControl(QWidget *parent = 0); ~MainPanelControl(); - void addFixedAreaItem(QWidget *wdg); - void addAppAreaItem(QWidget *wdg); - void addTrayAreaItem(QWidget *wdg); - void addPluginAreaItem(QWidget *wdg); + 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 removeFixedAreaItem(QWidget *wdg); void removeAppAreaItem(QWidget *wdg); void removeTrayAreaItem(QWidget *wdg); @@ -51,8 +51,9 @@ private: void updateMainPanelLayout(); public slots: - void itemInserted(const int index, DockItem *item); - void itemRemoved(DockItem *item); + void insertItem(const int index, DockItem *item); + void removeItem(DockItem *item); + void movedItem(const int index, DockItem *item); private: QBoxLayout *m_mainPanelLayout; diff --git a/frame/window/mainwindow.cpp b/frame/window/mainwindow.cpp index 30cb04e50..37c05c3a2 100644 --- a/frame/window/mainwindow.cpp +++ b/frame/window/mainwindow.cpp @@ -110,7 +110,7 @@ MainWindow::MainWindow(QWidget *parent) m_mainPanel->setFixedSize(m_settings->panelSize()); for (auto item : DockItemManager::instance()->itemList()) - m_mainPanel->itemInserted(-1, item); + m_mainPanel->insertItem(-1, item); } MainWindow::~MainWindow() @@ -403,8 +403,8 @@ void MainWindow::initConnections() connect(m_dbusDaemonInterface, &QDBusConnectionInterface::serviceOwnerChanged, this, &MainWindow::onDbusNameOwnerChanged); - connect(DockItemManager::instance(), &DockItemManager::itemInserted, m_mainPanel, &MainPanelControl::itemInserted, Qt::DirectConnection); - connect(DockItemManager::instance(), &DockItemManager::itemRemoved, m_mainPanel, &MainPanelControl::itemRemoved, Qt::DirectConnection); + connect(DockItemManager::instance(), &DockItemManager::itemInserted, m_mainPanel, &MainPanelControl::insertItem, Qt::DirectConnection); + connect(DockItemManager::instance(), &DockItemManager::itemRemoved, m_mainPanel, &MainPanelControl::removeItem, Qt::DirectConnection); } const QPoint MainWindow::x11GetWindowPos()