Separate DockItem as base class for AppItem and AppletItem

This commit is contained in:
杨万青 2015-06-26 19:26:05 +08:00
parent 6a1866d0dd
commit 880b38ea00
5 changed files with 105 additions and 57 deletions

View File

@ -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;

View File

@ -10,14 +10,13 @@
#include <QDrag>
#include <QMimeData>
#include <QPixmap>
#include <QDebug>
#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

View File

@ -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;
}

View File

@ -0,0 +1,42 @@
#ifndef DOCKITEM_H
#define DOCKITEM_H
#include <QWidget>
#include <QFrame>
#include <QMouseEvent>
#include <QRectF>
#include <QDebug>
#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

View File

@ -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