From b9e4c3262cee6d438b6104d4d85df367b46703a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9F=B3=E5=8D=9A=E6=96=87?= Date: Tue, 14 Jun 2016 16:49:29 +0800 Subject: [PATCH] add launcher item Change-Id: I2ac8bde9bb84eac7bf14b1781d9bd1d4b0d5465b --- controller/dockitemcontroller.cpp | 2 ++ dde-dock.pro | 6 +++-- item/launcheritem.cpp | 41 +++++++++++++++++++++++++++++++ item/launcheritem.h | 22 +++++++++++++++++ panel/mainpanel.cpp | 1 + 5 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 item/launcheritem.cpp create mode 100644 item/launcheritem.h diff --git a/controller/dockitemcontroller.cpp b/controller/dockitemcontroller.cpp index c337502b6..9d5712d50 100644 --- a/controller/dockitemcontroller.cpp +++ b/controller/dockitemcontroller.cpp @@ -2,6 +2,7 @@ #include "dbus/dbusdockentry.h" #include "item/appitem.h" #include "item/placeholderitem.h" +#include "item/launcheritem.h" #include @@ -29,6 +30,7 @@ DockItemController::DockItemController(QObject *parent) : QObject(parent), m_dockInter(new DBusDock(this)) { + m_itemList.append(new LauncherItem); for (auto entry : m_dockInter->entries()) m_itemList.append(new AppItem(entry)); m_itemList.append(new PlaceholderItem); diff --git a/dde-dock.pro b/dde-dock.pro index 1a8e31288..e88f9d816 100644 --- a/dde-dock.pro +++ b/dde-dock.pro @@ -20,7 +20,8 @@ SOURCES += main.cpp \ dbus/dbusclientmanager.cpp \ dbus/dbusdock.cpp \ dbus/dbusmenu.cpp \ - util/themeappicon.cpp + util/themeappicon.cpp \ + item/launcheritem.cpp HEADERS += \ window/mainwindow.h \ @@ -36,4 +37,5 @@ HEADERS += \ dbus/dbusclientmanager.h \ dbus/dbusdock.h \ dbus/dbusmenu.h \ - util/themeappicon.h + util/themeappicon.h \ + item/launcheritem.h diff --git a/item/launcheritem.cpp b/item/launcheritem.cpp new file mode 100644 index 000000000..08a1188d6 --- /dev/null +++ b/item/launcheritem.cpp @@ -0,0 +1,41 @@ +#include "launcheritem.h" +#include "util/themeappicon.h" + +#include +#include + +LauncherItem::LauncherItem(QWidget *parent) + : DockItem(DockItem::Launcher, parent) +{ +} + +void LauncherItem::paintEvent(QPaintEvent *e) +{ + DockItem::paintEvent(e); + + QPainter painter(this); + painter.drawPixmap(rect().center() - m_icon.rect().center(), m_icon); +} + +void LauncherItem::resizeEvent(QResizeEvent *e) +{ + DockItem::resizeEvent(e); + + m_icon = ThemeAppIcon::getIcon("deepin-launcher", 48); +} + +void LauncherItem::mousePressEvent(QMouseEvent *e) +{ + DockItem::mousePressEvent(e); + + QProcess *proc = new QProcess; + + connect(proc, static_cast(&QProcess::finished), proc, &QProcess::deleteLater); + + QStringList args = QStringList() << "--print-reply" + << "--dest=com.deepin.dde.Launcher" + << "/com/deepin/dde/Launcher" + << "com.deepin.dde.Launcher.Toggle"; + + proc->start("dbus-send", args); +} diff --git a/item/launcheritem.h b/item/launcheritem.h new file mode 100644 index 000000000..472e3c486 --- /dev/null +++ b/item/launcheritem.h @@ -0,0 +1,22 @@ +#ifndef LAUNCHERITEM_H +#define LAUNCHERITEM_H + +#include "dockitem.h" + +class LauncherItem : public DockItem +{ + Q_OBJECT + +public: + explicit LauncherItem(QWidget *parent = 0); + +private: + void paintEvent(QPaintEvent *e); + void resizeEvent(QResizeEvent *e); + void mousePressEvent(QMouseEvent *e); + +private: + QPixmap m_icon; +}; + +#endif // LAUNCHERITEM_H diff --git a/panel/mainpanel.cpp b/panel/mainpanel.cpp index 1f4514844..50e7992c5 100644 --- a/panel/mainpanel.cpp +++ b/panel/mainpanel.cpp @@ -71,6 +71,7 @@ void MainPanel::adjustItemSize() { switch (item->itemType()) { + case DockItem::Launcher: case DockItem::App: item->setFixedWidth(80); break; default:; }