From 880b38ea0032766f04960d421b8277c2fec89298 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E4=B8=87=E9=9D=92?= Date: Fri, 26 Jun 2015 19:26:05 +0800 Subject: [PATCH] Separate DockItem as base class for AppItem and AppletItem --- dde-dock/Widgets/appitem.cpp | 38 ++----------------------- dde-dock/Widgets/appitem.h | 23 ++------------- dde-dock/Widgets/dockitem.cpp | 53 +++++++++++++++++++++++++++++++++++ dde-dock/Widgets/dockitem.h | 42 +++++++++++++++++++++++++++ dde-dock/dde-dock.pro | 6 ++-- 5 files changed, 105 insertions(+), 57 deletions(-) create mode 100644 dde-dock/Widgets/dockitem.cpp create mode 100644 dde-dock/Widgets/dockitem.h diff --git a/dde-dock/Widgets/appitem.cpp b/dde-dock/Widgets/appitem.cpp index b932b80be..156a46c96 100644 --- a/dde-dock/Widgets/appitem.cpp +++ b/dde-dock/Widgets/appitem.cpp @@ -1,7 +1,7 @@ #include "appitem.h" AppItem::AppItem(QWidget *parent) : - QFrame(parent) + DockItem(parent) { setParent(parent); @@ -10,7 +10,7 @@ AppItem::AppItem(QWidget *parent) : } AppItem::AppItem(QString title, QWidget *parent): - QFrame(parent) + DockItem(parent) { this->setParent(parent); this->itemTitle = title; @@ -19,7 +19,7 @@ AppItem::AppItem(QString title, QWidget *parent): } AppItem::AppItem(QString title, QString iconPath, QWidget *parent) : - QFrame(parent) + DockItem(parent) { this->setParent(parent); this->itemTitle = title; @@ -29,18 +29,6 @@ AppItem::AppItem(QString title, QString iconPath, QWidget *parent) : this->setIcon(itemIconPath); } -void AppItem::setTitle(const QString &title) -{ - this->itemTitle = title; -} - -void AppItem::setIcon(const QString &iconPath, int size) -{ - appIcon = new AppIcon(iconPath,this); - appIcon->resize(size,size); - appIcon->move(this->width() / 2, this->height() / 2); -} - void AppItem::resize(const QSize &size) { QFrame::resize(size); @@ -53,26 +41,6 @@ void AppItem::resize(int width, int height) resizeResources(); } -void AppItem::setMoveable(bool value) -{ - this->itemMoveable = value; -} - -bool AppItem::getMoveable() -{ - return this->itemMoveable; -} - -void AppItem::setIndex(int value) -{ - this->itemIndex = value; -} - -int AppItem::getIndex() -{ - return this->itemIndex; -} - QPoint AppItem::getNextPos() { return this->nextPos; diff --git a/dde-dock/Widgets/appitem.h b/dde-dock/Widgets/appitem.h index 727fcbfaa..f03aa4d60 100644 --- a/dde-dock/Widgets/appitem.h +++ b/dde-dock/Widgets/appitem.h @@ -10,14 +10,13 @@ #include #include #include +#include +#include "dockitem.h" #include "dockconstants.h" #include "appicon.h" #include "appbackground.h" -#include "QDebug" -class QDragEnterEvent; -class QDropEvent; -class AppItem : public QFrame +class AppItem : public DockItem { Q_OBJECT Q_PROPERTY(QPoint pos READ pos WRITE move) @@ -27,14 +26,8 @@ public: AppItem(QString title, QString iconPath, QWidget *parent = 0); ~AppItem(); - void setTitle(const QString &title); - void setIcon(const QString &iconPath, int size = 42); void resize(const QSize &size); void resize(int width, int height); - void setMoveable(bool value); - bool getMoveable(); - void setIndex(int value); - int getIndex(); QPoint getNextPos(); void setNextPos(const QPoint &value); void setNextPos(int x, int y); @@ -67,17 +60,7 @@ private: private: AppBackground * appBackground = NULL; - AppIcon * appIcon = NULL; QPoint nextPos; - int itemIndex; - - bool itemMoveable = true; - bool itemHover = false; - bool itemActived = false; - bool itemDraged = false; - - QString itemTitle = ""; - QString itemIconPath = ""; }; #endif // APPITEM_H diff --git a/dde-dock/Widgets/dockitem.cpp b/dde-dock/Widgets/dockitem.cpp new file mode 100644 index 000000000..b43001111 --- /dev/null +++ b/dde-dock/Widgets/dockitem.cpp @@ -0,0 +1,53 @@ +#include "dockitem.h" + +DockItem::DockItem(QWidget *parent) : + QFrame(parent) +{ +} + +QWidget * DockItem::getContents() +{ + return NULL; +} + +void DockItem::setTitle(const QString &title) +{ + this->itemTitle = title; +} + +void DockItem::setIcon(const QString &iconPath, int size) +{ + appIcon = new AppIcon(iconPath,this); + appIcon->resize(size,size); + appIcon->move(this->width() / 2, this->height() / 2); +} + +void DockItem::setActived(bool value) +{ + this->itemActived = value; +} + +bool DockItem::actived() +{ + return this->itemActived; +} + +void DockItem::setMoveable(bool value) +{ + this->itemMoveable = value; +} + +bool DockItem::moveable() +{ + return this->itemMoveable; +} + +void DockItem::setIndex(int value) +{ + this->itemIndex = value; +} + +int DockItem::index() +{ + return this->itemIndex; +} diff --git a/dde-dock/Widgets/dockitem.h b/dde-dock/Widgets/dockitem.h new file mode 100644 index 000000000..03a873aeb --- /dev/null +++ b/dde-dock/Widgets/dockitem.h @@ -0,0 +1,42 @@ +#ifndef DOCKITEM_H +#define DOCKITEM_H + +#include +#include +#include +#include +#include +#include "dockconstants.h" +#include "appicon.h" + +class DockItem : public QFrame +{ + Q_OBJECT +public: + explicit DockItem(QWidget *parent = 0); + virtual ~DockItem(){} + + virtual QWidget * getContents(); + + virtual void setTitle(const QString &title); + virtual void setIcon(const QString &iconPath, int size = 42); + virtual void setMoveable(bool value); + virtual bool moveable(); + virtual void setActived(bool value); + virtual bool actived(); + virtual void setIndex(int value); + virtual int index(); + +protected: + AppIcon * appIcon = NULL; + + bool itemMoveable = true; + bool itemActived = false; + + QString itemTitle = ""; + QString itemIconPath = ""; + int itemIndex = 0; + +}; + +#endif // DOCKITEM_H diff --git a/dde-dock/dde-dock.pro b/dde-dock/dde-dock.pro index 1abe9839f..88b337dea 100644 --- a/dde-dock/dde-dock.pro +++ b/dde-dock/dde-dock.pro @@ -23,7 +23,8 @@ SOURCES += main.cpp\ Widgets/dockitemdelegate.cpp \ Widgets/appitem.cpp \ Widgets/docklayout.cpp \ - Widgets/windowpreview.cpp + Widgets/windowpreview.cpp \ + Widgets/dockitem.cpp HEADERS += mainwidget.h \ Panel/panel.h \ @@ -35,7 +36,8 @@ HEADERS += mainwidget.h \ Widgets/dockitemdelegate.h \ Widgets/appitem.h \ Widgets/docklayout.h \ - Widgets/windowpreview.h + Widgets/windowpreview.h \ + Widgets/dockitem.h RESOURCES += \ images.qrc