mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-03 00:15:21 +00:00
feat:add DockItemManager data to MainPanelControl
This commit is contained in:
parent
1f7d63dae4
commit
b92759d379
@ -32,7 +32,7 @@ DockPluginsController::DockPluginsController(QObject *parent)
|
||||
setObjectName("DockPlugin");
|
||||
}
|
||||
|
||||
void DockPluginsController::itemAdded(PluginsItemInterface * const itemInter, const QString &itemKey)
|
||||
void DockPluginsController::itemAdded(PluginsItemInterface *const itemInter, const QString &itemKey)
|
||||
{
|
||||
QMap<PluginsItemInterface *, QMap<QString, QObject *>> &mPluginsMap = pluginsMap();
|
||||
|
||||
@ -53,14 +53,12 @@ void DockPluginsController::itemAdded(PluginsItemInterface * const itemInter, co
|
||||
item = new PluginsItem(itemInter, itemKey);
|
||||
}
|
||||
|
||||
item->setVisible(false);
|
||||
|
||||
mPluginsMap[itemInter][itemKey] = item;
|
||||
|
||||
emit pluginItemInserted(item);
|
||||
}
|
||||
|
||||
void DockPluginsController::itemUpdate(PluginsItemInterface * const itemInter, const QString &itemKey)
|
||||
void DockPluginsController::itemUpdate(PluginsItemInterface *const itemInter, const QString &itemKey)
|
||||
{
|
||||
PluginsItem *item = static_cast<PluginsItem *>(pluginItemAt(itemInter, itemKey));
|
||||
if (!item)
|
||||
@ -71,7 +69,7 @@ void DockPluginsController::itemUpdate(PluginsItemInterface * const itemInter, c
|
||||
emit pluginItemUpdated(item);
|
||||
}
|
||||
|
||||
void DockPluginsController::itemRemoved(PluginsItemInterface * const itemInter, const QString &itemKey)
|
||||
void DockPluginsController::itemRemoved(PluginsItemInterface *const itemInter, const QString &itemKey)
|
||||
{
|
||||
PluginsItem *item = static_cast<PluginsItem *>(pluginItemAt(itemInter, itemKey));
|
||||
if (!item)
|
||||
@ -91,7 +89,7 @@ void DockPluginsController::itemRemoved(PluginsItemInterface * const itemInter,
|
||||
item->deleteLater();
|
||||
}
|
||||
|
||||
void DockPluginsController::requestWindowAutoHide(PluginsItemInterface * const itemInter, const QString &itemKey, const bool autoHide)
|
||||
void DockPluginsController::requestWindowAutoHide(PluginsItemInterface *const itemInter, const QString &itemKey, const bool autoHide)
|
||||
{
|
||||
PluginsItem *item = static_cast<PluginsItem *>(pluginItemAt(itemInter, itemKey));
|
||||
if (!item)
|
||||
@ -100,7 +98,7 @@ void DockPluginsController::requestWindowAutoHide(PluginsItemInterface * const i
|
||||
Q_EMIT item->requestWindowAutoHide(autoHide);
|
||||
}
|
||||
|
||||
void DockPluginsController::requestRefreshWindowVisible(PluginsItemInterface * const itemInter, const QString &itemKey)
|
||||
void DockPluginsController::requestRefreshWindowVisible(PluginsItemInterface *const itemInter, const QString &itemKey)
|
||||
{
|
||||
PluginsItem *item = static_cast<PluginsItem *>(pluginItemAt(itemInter, itemKey));
|
||||
if (!item)
|
||||
@ -109,7 +107,7 @@ void DockPluginsController::requestRefreshWindowVisible(PluginsItemInterface * c
|
||||
Q_EMIT item->requestRefreshWindowVisible();
|
||||
}
|
||||
|
||||
void DockPluginsController::requestSetAppletVisible(PluginsItemInterface * const itemInter, const QString &itemKey, const bool visible)
|
||||
void DockPluginsController::requestSetAppletVisible(PluginsItemInterface *const itemInter, const QString &itemKey, const bool visible)
|
||||
{
|
||||
PluginsItem *item = static_cast<PluginsItem *>(pluginItemAt(itemInter, itemKey));
|
||||
if (!item)
|
||||
@ -128,7 +126,8 @@ void DockPluginsController::startLoader()
|
||||
loadSystemPlugins();
|
||||
}
|
||||
|
||||
void DockPluginsController::loadLocalPlugins() {
|
||||
void DockPluginsController::loadLocalPlugins()
|
||||
{
|
||||
QString pluginsDir(QString("%1/.local/lib/dde-dock/plugins/").arg(QDir::homePath()));
|
||||
|
||||
if (!QDir(pluginsDir).exists()) {
|
||||
@ -140,7 +139,8 @@ void DockPluginsController::loadLocalPlugins() {
|
||||
AbstractPluginsController::startLoader(new PluginLoader(pluginsDir, this));
|
||||
}
|
||||
|
||||
void DockPluginsController::loadSystemPlugins() {
|
||||
void DockPluginsController::loadSystemPlugins()
|
||||
{
|
||||
QString pluginsDir(qApp->applicationDirPath() + "/../plugins");
|
||||
if (!QDir(pluginsDir).exists()) {
|
||||
pluginsDir = "/usr/lib/dde-dock/plugins";
|
||||
|
@ -45,8 +45,7 @@ DockItem::DockItem(QWidget *parent)
|
||||
|
||||
m_menuManagerInter(new DBusMenuManager(this))
|
||||
{
|
||||
if (PopupWindow.isNull())
|
||||
{
|
||||
if (PopupWindow.isNull()) {
|
||||
DockPopupWindow *arrowRectangle = new DockPopupWindow(nullptr);
|
||||
arrowRectangle->setShadowBlurRadius(20);
|
||||
arrowRectangle->setRadius(6);
|
||||
@ -69,6 +68,13 @@ DockItem::DockItem(QWidget *parent)
|
||||
connect(m_popupAdjustDelayTimer, &QTimer::timeout, this, &DockItem::updatePopupPosition, Qt::QueuedConnection);
|
||||
|
||||
grabGesture(Qt::TapAndHoldGesture);
|
||||
|
||||
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
}
|
||||
|
||||
QSize DockItem::sizeHint() const
|
||||
{
|
||||
return QSize(50, 50);
|
||||
}
|
||||
|
||||
DockItem::~DockItem()
|
||||
@ -104,10 +110,8 @@ void DockItem::gestureEvent(QGestureEvent *event)
|
||||
|
||||
bool DockItem::event(QEvent *event)
|
||||
{
|
||||
if (m_popupShown)
|
||||
{
|
||||
switch (event->type())
|
||||
{
|
||||
if (m_popupShown) {
|
||||
switch (event->type()) {
|
||||
case QEvent::Paint:
|
||||
if (!m_popupAdjustDelayTimer->isActive())
|
||||
m_popupAdjustDelayTimer->start();
|
||||
@ -117,7 +121,7 @@ bool DockItem::event(QEvent *event)
|
||||
}
|
||||
|
||||
if (event->type() == QEvent::Gesture)
|
||||
gestureEvent(static_cast<QGestureEvent*>(event));
|
||||
gestureEvent(static_cast<QGestureEvent *>(event));
|
||||
|
||||
return QWidget::event(event);
|
||||
}
|
||||
@ -213,8 +217,7 @@ void DockItem::showContextMenu()
|
||||
QDBusPendingReply<QDBusObjectPath> result = m_menuManagerInter->RegisterMenu();
|
||||
|
||||
result.waitForFinished();
|
||||
if (result.isError())
|
||||
{
|
||||
if (result.isError()) {
|
||||
qWarning() << result.error();
|
||||
return;
|
||||
}
|
||||
@ -227,8 +230,7 @@ void DockItem::showContextMenu()
|
||||
menuObject.insert("isDockMenu", QJsonValue(true));
|
||||
menuObject.insert("menuJsonContent", QJsonValue(menuJson));
|
||||
|
||||
switch (DockPosition)
|
||||
{
|
||||
switch (DockPosition) {
|
||||
case Top: menuObject.insert("direction", "top"); break;
|
||||
case Bottom: menuObject.insert("direction", "bottom"); break;
|
||||
case Left: menuObject.insert("direction", "left"); break;
|
||||
@ -265,14 +267,14 @@ void DockItem::showHoverTips()
|
||||
if (!r.contains(QCursor::pos()))
|
||||
return;
|
||||
|
||||
QWidget * const content = popupTips();
|
||||
QWidget *const content = popupTips();
|
||||
if (!content)
|
||||
return;
|
||||
|
||||
showPopupWindow(content);
|
||||
}
|
||||
|
||||
void DockItem::showPopupWindow(QWidget * const content, const bool model)
|
||||
void DockItem::showPopupWindow(QWidget *const content, const bool model)
|
||||
{
|
||||
m_popupShown = true;
|
||||
m_lastPopupWidget = content;
|
||||
@ -285,10 +287,9 @@ void DockItem::showPopupWindow(QWidget * const content, const bool model)
|
||||
if (lastContent)
|
||||
lastContent->setVisible(false);
|
||||
|
||||
switch (DockPosition)
|
||||
{
|
||||
switch (DockPosition) {
|
||||
case Top: popup->setArrowDirection(DockPopupWindow::ArrowTop); break;
|
||||
case Bottom:popup->setArrowDirection(DockPopupWindow::ArrowBottom); break;
|
||||
case Bottom: popup->setArrowDirection(DockPopupWindow::ArrowBottom); break;
|
||||
case Left: popup->setArrowDirection(DockPopupWindow::ArrowLeft); break;
|
||||
case Right: popup->setArrowDirection(DockPopupWindow::ArrowRight); break;
|
||||
}
|
||||
@ -314,7 +315,7 @@ void DockItem::popupWindowAccept()
|
||||
hidePopup();
|
||||
}
|
||||
|
||||
void DockItem::showPopupApplet(QWidget * const applet)
|
||||
void DockItem::showPopupApplet(QWidget *const applet)
|
||||
{
|
||||
// another model popup window already exists
|
||||
if (PopupWindow->model())
|
||||
@ -357,8 +358,7 @@ const QPoint DockItem::popupMarkPoint() const
|
||||
|
||||
const QRect r = rect();
|
||||
const int offset = 2;
|
||||
switch (DockPosition)
|
||||
{
|
||||
switch (DockPosition) {
|
||||
case Top: p += QPoint(r.width() / 2, r.height() + offset); break;
|
||||
case Bottom: p += QPoint(r.width() / 2, 0 - offset); break;
|
||||
case Left: p += QPoint(r.width() + offset, r.height() / 2); break;
|
||||
|
@ -59,10 +59,12 @@ public:
|
||||
|
||||
inline virtual ItemType itemType() const {Q_UNREACHABLE(); return App;}
|
||||
|
||||
QSize sizeHint() const override;
|
||||
|
||||
public slots:
|
||||
virtual void refershIcon() {}
|
||||
|
||||
void showPopupApplet(QWidget * const applet);
|
||||
void showPopupApplet(QWidget *const applet);
|
||||
void hidePopup();
|
||||
|
||||
signals:
|
||||
@ -84,7 +86,7 @@ protected:
|
||||
|
||||
void hideNonModel();
|
||||
void popupWindowAccept();
|
||||
virtual void showPopupWindow(QWidget * const content, const bool model = false);
|
||||
virtual void showPopupWindow(QWidget *const content, const bool model = false);
|
||||
virtual void showHoverTips();
|
||||
virtual void invokedMenuItem(const QString &itemId, const bool checked);
|
||||
virtual const QString contextMenu() const;
|
||||
|
@ -45,15 +45,14 @@ void RegisterDdeSession()
|
||||
QByteArray cookie = qgetenv(envName.toUtf8().data());
|
||||
qunsetenv(envName.toUtf8().data());
|
||||
|
||||
if (!cookie.isEmpty())
|
||||
{
|
||||
if (!cookie.isEmpty()) {
|
||||
QDBusPendingReply<bool> r = DDBusSender()
|
||||
.interface("com.deepin.SessionManager")
|
||||
.path("/com/deepin/SessionManager")
|
||||
.service("com.deepin.SessionManager")
|
||||
.method("Register")
|
||||
.arg(QString(cookie))
|
||||
.call();
|
||||
.interface("com.deepin.SessionManager")
|
||||
.path("/com/deepin/SessionManager")
|
||||
.service("com.deepin.SessionManager")
|
||||
.method("Register")
|
||||
.arg(QString(cookie))
|
||||
.call();
|
||||
|
||||
qDebug() << Q_FUNC_INFO << r.value();
|
||||
}
|
||||
@ -109,7 +108,7 @@ int main(int argc, char *argv[])
|
||||
QTimer::singleShot(1, &mw, &MainWindow::launch);
|
||||
|
||||
if (!parser.isSet(disablePlugOption)) {
|
||||
DockItemController::instance()->startLoadPlugins();
|
||||
DockItemManager::instance()->startLoadPlugins();
|
||||
}
|
||||
|
||||
return app.exec();
|
||||
|
@ -50,7 +50,7 @@ private:
|
||||
void updateAppAreaSonWidgetSize();
|
||||
void updateMainPanelLayout();
|
||||
|
||||
private slots:
|
||||
public slots:
|
||||
void itemInserted(const int index, DockItem *item);
|
||||
void itemRemoved(DockItem *item);
|
||||
|
||||
|
@ -21,6 +21,7 @@
|
||||
|
||||
#include "mainwindow.h"
|
||||
#include "panel/mainpanelcontrol.h"
|
||||
#include "controller/dockitemmanager.h"
|
||||
#include "util/utils.h"
|
||||
|
||||
#include <QDebug>
|
||||
@ -43,22 +44,22 @@ using org::kde::StatusNotifierWatcher;
|
||||
|
||||
const QPoint rawXPosition(const QPoint &scaledPos)
|
||||
{
|
||||
QScreen const * screen = Utils::screenAtByScaled(scaledPos);
|
||||
QScreen const *screen = Utils::screenAtByScaled(scaledPos);
|
||||
|
||||
return screen ? screen->geometry().topLeft() +
|
||||
(scaledPos - screen->geometry().topLeft()) *
|
||||
screen->devicePixelRatio()
|
||||
: scaledPos;
|
||||
(scaledPos - screen->geometry().topLeft()) *
|
||||
screen->devicePixelRatio()
|
||||
: scaledPos;
|
||||
}
|
||||
|
||||
const QPoint scaledPos(const QPoint &rawXPos)
|
||||
{
|
||||
QScreen const * screen = Utils::screenAt(rawXPos);
|
||||
QScreen const *screen = Utils::screenAt(rawXPos);
|
||||
|
||||
return screen
|
||||
? screen->geometry().topLeft() +
|
||||
(rawXPos - screen->geometry().topLeft()) / screen->devicePixelRatio()
|
||||
: rawXPos;
|
||||
? screen->geometry().topLeft() +
|
||||
(rawXPos - screen->geometry().topLeft()) / screen->devicePixelRatio()
|
||||
: rawXPos;
|
||||
}
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
@ -107,6 +108,9 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
initConnections();
|
||||
|
||||
m_mainPanel->setFixedSize(m_settings->panelSize());
|
||||
|
||||
for (auto item : DockItemManager::instance()->itemList())
|
||||
m_mainPanel->itemInserted(-1, item);
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
@ -146,8 +150,7 @@ void MainWindow::launch()
|
||||
|
||||
bool MainWindow::event(QEvent *e)
|
||||
{
|
||||
switch (e->type())
|
||||
{
|
||||
switch (e->type()) {
|
||||
case QEvent::Move:
|
||||
if (!e->spontaneous())
|
||||
QTimer::singleShot(1, this, &MainWindow::positionCheck);
|
||||
@ -167,7 +170,7 @@ void MainWindow::showEvent(QShowEvent *e)
|
||||
m_platformWindowHandle.setShadowRadius(0);
|
||||
|
||||
connect(qGuiApp, &QGuiApplication::primaryScreenChanged,
|
||||
windowHandle(), [this] (QScreen *new_screen) {
|
||||
windowHandle(), [this](QScreen * new_screen) {
|
||||
QScreen *old_screen = windowHandle()->screen();
|
||||
windowHandle()->setScreen(new_screen);
|
||||
// 屏幕变化后可能导致控件缩放比变化,此时应该重设控件位置大小
|
||||
@ -196,8 +199,7 @@ void MainWindow::mousePressEvent(QMouseEvent *e)
|
||||
|
||||
void MainWindow::keyPressEvent(QKeyEvent *e)
|
||||
{
|
||||
switch (e->key())
|
||||
{
|
||||
switch (e->key()) {
|
||||
#ifdef QT_DEBUG
|
||||
case Qt::Key_Escape: qApp->quit(); break;
|
||||
#endif
|
||||
@ -328,8 +330,8 @@ void MainWindow::internalMove(const QPoint &p)
|
||||
{
|
||||
const bool isHide = m_settings->hideState() == HideState::Hide && !testAttribute(Qt::WA_UnderMouse);
|
||||
const bool pos_adjust = m_settings->hideMode() != HideMode::KeepShowing &&
|
||||
isHide &&
|
||||
m_posChangeAni->state() == QVariantAnimation::Stopped;
|
||||
isHide &&
|
||||
m_posChangeAni->state() == QVariantAnimation::Stopped;
|
||||
if (!pos_adjust)
|
||||
return QWidget::move(p);
|
||||
|
||||
@ -337,8 +339,7 @@ void MainWindow::internalMove(const QPoint &p)
|
||||
const auto ratio = devicePixelRatioF();
|
||||
|
||||
const QRect &r = m_settings->primaryRawRect();
|
||||
switch (m_settings->position())
|
||||
{
|
||||
switch (m_settings->position()) {
|
||||
case Left: rp.setX(r.x()); break;
|
||||
case Top: rp.setY(r.y()); break;
|
||||
case Right: rp.setX(r.right() - 1); break;
|
||||
@ -347,12 +348,10 @@ void MainWindow::internalMove(const QPoint &p)
|
||||
|
||||
int hx = height() * ratio, wx = width() * ratio;
|
||||
if (m_settings->hideMode() != HideMode::KeepShowing &&
|
||||
isHide &&
|
||||
m_panelHideAni->state() == QVariantAnimation::Stopped &&
|
||||
m_panelShowAni->state() == QVariantAnimation::Stopped)
|
||||
{
|
||||
switch (m_settings->position())
|
||||
{
|
||||
isHide &&
|
||||
m_panelHideAni->state() == QVariantAnimation::Stopped &&
|
||||
m_panelShowAni->state() == QVariantAnimation::Stopped) {
|
||||
switch (m_settings->position()) {
|
||||
case Top:
|
||||
case Bottom:
|
||||
hx = 2;
|
||||
@ -395,7 +394,7 @@ void MainWindow::initConnections()
|
||||
connect(m_posChangeAni, &QVariantAnimation::finished, this, static_cast<void (MainWindow::*)()>(&MainWindow::internalMove), Qt::QueuedConnection);
|
||||
|
||||
// to fix qt animation bug, sometimes window size not change
|
||||
connect(m_sizeChangeAni, &QVariantAnimation::valueChanged, [=](const QVariant &value) {
|
||||
connect(m_sizeChangeAni, &QVariantAnimation::valueChanged, [ = ](const QVariant & value) {
|
||||
QWidget::setFixedSize(value.toSize());
|
||||
});
|
||||
|
||||
@ -403,6 +402,9 @@ void MainWindow::initConnections()
|
||||
connect(&m_platformWindowHandle, &DPlatformWindowHandle::frameMarginsChanged, m_shadowMaskOptimizeTimer, static_cast<void (QTimer::*)()>(&QTimer::start));
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
const QPoint MainWindow::x11GetWindowPos()
|
||||
@ -549,8 +551,7 @@ void MainWindow::setStrutPartial()
|
||||
uint strutEnd = 0;
|
||||
|
||||
QRect strutArea(0, 0, maxScreenWidth, maxScreenHeight);
|
||||
switch (side)
|
||||
{
|
||||
switch (side) {
|
||||
case Position::Top:
|
||||
orientation = XcbMisc::OrientationTop;
|
||||
strut = p.y() + s.height() * ratio;
|
||||
@ -596,8 +597,7 @@ void MainWindow::setStrutPartial()
|
||||
// pass if strut area is intersect with other screen
|
||||
int count = 0;
|
||||
const QRect pr = m_settings->primaryRect();
|
||||
for (auto *screen : qApp->screens())
|
||||
{
|
||||
for (auto *screen : qApp->screens()) {
|
||||
const QRect sr = screen->geometry();
|
||||
if (sr == pr)
|
||||
continue;
|
||||
@ -605,8 +605,7 @@ void MainWindow::setStrutPartial()
|
||||
if (sr.intersects(strutArea))
|
||||
++count;
|
||||
}
|
||||
if (count > 0)
|
||||
{
|
||||
if (count > 0) {
|
||||
qWarning() << "strutArea is intersects with another screen.";
|
||||
qWarning() << maxScreenHeight << maxScreenWidth << side << p << s;
|
||||
return;
|
||||
@ -626,12 +625,10 @@ void MainWindow::expand()
|
||||
|
||||
resetPanelEnvironment(true, false);
|
||||
|
||||
if (showAniState != QPropertyAnimation::Running && m_mainPanel->pos() != m_panelShowAni->currentValue())
|
||||
{
|
||||
if (showAniState != QPropertyAnimation::Running && m_mainPanel->pos() != m_panelShowAni->currentValue()) {
|
||||
QPoint startPos(0, 0);
|
||||
const QSize &size = m_settings->windowSize();
|
||||
switch (m_settings->position())
|
||||
{
|
||||
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;
|
||||
@ -651,8 +648,7 @@ void MainWindow::narrow(const Position prevPos)
|
||||
const QSize size = m_settings->panelSize();
|
||||
|
||||
QPoint finishPos(0, 0);
|
||||
switch (prevPos)
|
||||
{
|
||||
switch (prevPos) {
|
||||
case Top: finishPos.setY(-size.height()); break;
|
||||
case Bottom: finishPos.setY(size.height()); break;
|
||||
case Left: finishPos.setX(-size.width()); break;
|
||||
@ -687,8 +683,7 @@ void MainWindow::resetPanelEnvironment(const bool visible, const bool resetPosit
|
||||
if (!resetPosition)
|
||||
return;
|
||||
QPoint finishPos(0, 0);
|
||||
switch (position)
|
||||
{
|
||||
switch (position) {
|
||||
case Top: finishPos.setY((visible ? 0 : -r.height())); break;
|
||||
case Bottom: finishPos.setY(visible ? 0 : r.height()); break;
|
||||
case Left: finishPos.setX((visible ? 0 : -r.width())); break;
|
||||
@ -708,8 +703,7 @@ void MainWindow::updatePanelVisible()
|
||||
|
||||
const Dock::HideState state = m_settings->hideState();
|
||||
|
||||
do
|
||||
{
|
||||
do {
|
||||
if (state != Hide)
|
||||
break;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user