mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 17:33:05 +00:00
dde-dock initial commit
This commit is contained in:
parent
39dbbe20b9
commit
6d1f869fd8
34
dde-dock/Panel/panel.cpp
Normal file
34
dde-dock/Panel/panel.cpp
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
#include "panel.h"
|
||||||
|
|
||||||
|
Panel::Panel(QWidget *parent) : QWidget(parent)
|
||||||
|
{
|
||||||
|
leftLayout = new DockLayout(this);
|
||||||
|
leftLayout->resize(1024,50);
|
||||||
|
leftLayout->move(0,0);
|
||||||
|
|
||||||
|
for (int i = 0; i < 5; i ++)
|
||||||
|
{
|
||||||
|
AppItem * tmpButton = new AppItem("App" + QString::number(i),":/test/Resources/images/google-chrome.png");
|
||||||
|
tmpButton->resize(50,50);
|
||||||
|
|
||||||
|
leftLayout->addItem(tmpButton);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Panel::resize(const QSize &size)
|
||||||
|
{
|
||||||
|
QWidget::resize(size);
|
||||||
|
leftLayout->resize(this->width() * 2 / 3,this->height());
|
||||||
|
}
|
||||||
|
|
||||||
|
void Panel::resize(int width, int height)
|
||||||
|
{
|
||||||
|
QWidget::resize(width,height);
|
||||||
|
leftLayout->resize(this->width() * 2 / 3,this->height());
|
||||||
|
}
|
||||||
|
|
||||||
|
Panel::~Panel()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
27
dde-dock/Panel/panel.h
Normal file
27
dde-dock/Panel/panel.h
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
#ifndef PANEL_H
|
||||||
|
#define PANEL_H
|
||||||
|
|
||||||
|
#include <QWidget>
|
||||||
|
#include <QPushButton>
|
||||||
|
#include <QDebug>
|
||||||
|
#include "Widgets/appitem.h"
|
||||||
|
#include "Widgets/docklayout.h"
|
||||||
|
|
||||||
|
class Panel : public QWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit Panel(QWidget *parent = 0);
|
||||||
|
~Panel();
|
||||||
|
|
||||||
|
void resize(const QSize &size);
|
||||||
|
void resize(int width,int height);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
private:
|
||||||
|
DockLayout * leftLayout;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // PANEL_H
|
BIN
dde-dock/Resources/images/google-chrome.png
Normal file
BIN
dde-dock/Resources/images/google-chrome.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.7 KiB |
7
dde-dock/Widgets/appbackground.cpp
Normal file
7
dde-dock/Widgets/appbackground.cpp
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#include "appbackground.h"
|
||||||
|
|
||||||
|
AppBackground::AppBackground(QWidget *parent) :
|
||||||
|
QLabel(parent)
|
||||||
|
{
|
||||||
|
this->setStyleSheet("background:#121922;border-radius: 4px;");
|
||||||
|
}
|
21
dde-dock/Widgets/appbackground.h
Normal file
21
dde-dock/Widgets/appbackground.h
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#ifndef APPBACKGROUND_H
|
||||||
|
#define APPBACKGROUND_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QDebug>
|
||||||
|
#include "dockconstants.h"
|
||||||
|
|
||||||
|
class AppBackground : public QLabel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit AppBackground(QWidget *parent = 0);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // APPBACKGROUND_H
|
85
dde-dock/Widgets/appicon.cpp
Normal file
85
dde-dock/Widgets/appicon.cpp
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
#include "appicon.h"
|
||||||
|
|
||||||
|
#undef signals
|
||||||
|
extern "C" {
|
||||||
|
#include <gtk/gtk.h>
|
||||||
|
}
|
||||||
|
#define signals public
|
||||||
|
|
||||||
|
AppIcon::AppIcon(QWidget *parent,Qt::WindowFlags f) :
|
||||||
|
QLabel(parent)
|
||||||
|
{
|
||||||
|
this->setParent(parent);
|
||||||
|
this->setWindowFlags(f);
|
||||||
|
}
|
||||||
|
|
||||||
|
AppIcon::AppIcon(QString iconPath, QWidget *parent, Qt::WindowFlags f) :
|
||||||
|
QLabel(parent)
|
||||||
|
{
|
||||||
|
this->setParent(parent);
|
||||||
|
this->setWindowFlags(f);
|
||||||
|
|
||||||
|
QString sysIconPath = getSysIcon(iconPath);
|
||||||
|
QPixmap iconPixmap(this->width(),this->height());
|
||||||
|
if (sysIconPath != "")
|
||||||
|
{
|
||||||
|
iconPixmap.load(sysIconPath);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
iconPixmap.load(iconPath);
|
||||||
|
}
|
||||||
|
this->setPixmap(iconPixmap);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AppIcon::setIcon(const QString &iconPath)
|
||||||
|
{
|
||||||
|
QString sysIconPath = getSysIcon(iconPath);
|
||||||
|
QPixmap iconPixmap(this->width(),this->height());
|
||||||
|
if (sysIconPath != "")
|
||||||
|
{
|
||||||
|
iconPixmap.load(sysIconPath);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
iconPixmap.load(iconPath);
|
||||||
|
}
|
||||||
|
this->setPixmap(iconPixmap);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString AppIcon::getSysIcon(const QString &iconName, int size)
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
// char *name = iconName.toUtf8().data();
|
||||||
|
// GtkIconTheme* theme;
|
||||||
|
|
||||||
|
// if (g_path_is_absolute(name))
|
||||||
|
// return iconName;
|
||||||
|
// g_return_val_if_fail(name != NULL, NULL);
|
||||||
|
|
||||||
|
// int pic_name_len = strlen(name);
|
||||||
|
// char* ext = strrchr(name, '.');
|
||||||
|
// if (ext != NULL) {
|
||||||
|
// if (g_ascii_strcasecmp(ext+1, "png") == 0 || g_ascii_strcasecmp(ext+1, "svg") == 0 || g_ascii_strcasecmp(ext+1, "jpg") == 0) {
|
||||||
|
// pic_name_len = ext - name;
|
||||||
|
// g_debug("Icon name should an absoulte path or an basename without extension");
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// char* pic_name = g_strndup(name, pic_name_len);
|
||||||
|
// theme = gtk_icon_theme_get_default();
|
||||||
|
|
||||||
|
// GtkIconInfo* info = gtk_icon_theme_lookup_icon(theme, pic_name, size, GTK_ICON_LOOKUP_GENERIC_FALLBACK);
|
||||||
|
// g_free(pic_name);
|
||||||
|
// if (info) {
|
||||||
|
// char* path = g_strdup(gtk_icon_info_get_filename(info));
|
||||||
|
//#if GTK_MAJOR_VERSION >= 3
|
||||||
|
// g_object_unref(info);
|
||||||
|
//#elif GTK_MAJOR_VERSION == 2
|
||||||
|
// gtk_icon_info_free(info);
|
||||||
|
//#endif
|
||||||
|
// return QString(path);
|
||||||
|
// } else {
|
||||||
|
// return NULL;
|
||||||
|
// }
|
||||||
|
}
|
24
dde-dock/Widgets/appicon.h
Normal file
24
dde-dock/Widgets/appicon.h
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#ifndef APPICON_H
|
||||||
|
#define APPICON_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QWidget>
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QPixmap>
|
||||||
|
|
||||||
|
class AppIcon : public QLabel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit AppIcon(QWidget *parent = 0,Qt::WindowFlags f = 0);
|
||||||
|
explicit AppIcon(QString iconPath, QWidget *parent = 0,Qt::WindowFlags f = 0);//default search system icon path
|
||||||
|
|
||||||
|
void setIcon(const QString &iconPath);
|
||||||
|
signals:
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
|
||||||
|
QString getSysIcon(const QString &iconName, int size = 42);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // APPICON_H
|
123
dde-dock/Widgets/appitem.cpp
Normal file
123
dde-dock/Widgets/appitem.cpp
Normal file
@ -0,0 +1,123 @@
|
|||||||
|
#include "appitem.h"
|
||||||
|
|
||||||
|
AppItem::AppItem(QWidget *parent) :
|
||||||
|
QFrame(parent)
|
||||||
|
{
|
||||||
|
this->setParent(parent);
|
||||||
|
|
||||||
|
this->initBackground();
|
||||||
|
}
|
||||||
|
|
||||||
|
AppItem::AppItem(QString title, QWidget *parent):
|
||||||
|
QFrame(parent)
|
||||||
|
{
|
||||||
|
this->setParent(parent);
|
||||||
|
this->itemTitle = title;
|
||||||
|
|
||||||
|
this->initBackground();
|
||||||
|
}
|
||||||
|
|
||||||
|
AppItem::AppItem(QString title, QString iconPath, QWidget *parent) :
|
||||||
|
QFrame(parent)
|
||||||
|
{
|
||||||
|
this->setParent(parent);
|
||||||
|
this->itemTitle = title;
|
||||||
|
this->itemIconPath = iconPath;
|
||||||
|
|
||||||
|
this->initBackground();
|
||||||
|
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->setIcon(iconPath);
|
||||||
|
appIcon->move(this->width() / 2, this->height() / 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AppItem::resize(const QSize &size)
|
||||||
|
{
|
||||||
|
QFrame::resize(size);
|
||||||
|
resizeResources();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AppItem::resize(int width, int height)
|
||||||
|
{
|
||||||
|
QFrame::resize(width,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;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AppItem::resizeResources()
|
||||||
|
{
|
||||||
|
if (appIcon != NULL)
|
||||||
|
{
|
||||||
|
appIcon->resize(DockConstants::getInstants()->getIconSize(),DockConstants::getInstants()->getIconSize());
|
||||||
|
appIcon->move(this->width() / 2 - appIcon->width() / 2, this->height() / 2 - appIcon->height() / 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (appBackground != NULL)
|
||||||
|
{
|
||||||
|
appBackground->resize(this->width(),this->height());
|
||||||
|
appBackground->move(0,0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AppItem::initBackground()
|
||||||
|
{
|
||||||
|
appBackground = new AppBackground(this);
|
||||||
|
appBackground->resize(this->width(),this->height());
|
||||||
|
appBackground->move(0,0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AppItem::mousePressEvent(QMouseEvent * event)
|
||||||
|
{
|
||||||
|
qWarning() << "press...";
|
||||||
|
emit mousePress(event->globalX(), event->globalY(),this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AppItem::mouseReleaseEvent(QMouseEvent * event)
|
||||||
|
{
|
||||||
|
emit mouseRelease(event->globalX(), event->globalY(),this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AppItem::mouseMoveEvent(QMouseEvent * event)
|
||||||
|
{
|
||||||
|
emit mouseMove(event->globalX(), event->globalY(),this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AppItem::mouseDoubleClickEvent(QMouseEvent * event)
|
||||||
|
{
|
||||||
|
emit mouseDoubleClick(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
AppItem::~AppItem()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
63
dde-dock/Widgets/appitem.h
Normal file
63
dde-dock/Widgets/appitem.h
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
#ifndef APPITEM_H
|
||||||
|
#define APPITEM_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QWidget>
|
||||||
|
#include <QPushButton>
|
||||||
|
#include <QMouseEvent>
|
||||||
|
#include <QDrag>
|
||||||
|
#include <QRectF>
|
||||||
|
#include "dockconstants.h"
|
||||||
|
#include "appicon.h"
|
||||||
|
#include "appbackground.h"
|
||||||
|
#include "QDebug"
|
||||||
|
|
||||||
|
class AppItem : public QFrame
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
AppItem(QWidget *parent = 0);
|
||||||
|
AppItem(QString title, QWidget *parent = 0);
|
||||||
|
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();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void mousePressEvent(QMouseEvent *);
|
||||||
|
void mouseReleaseEvent(QMouseEvent *);
|
||||||
|
void mouseMoveEvent(QMouseEvent *);
|
||||||
|
void mouseDoubleClickEvent(QMouseEvent *);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void mousePress(int x, int y, AppItem *item);
|
||||||
|
void mouseRelease(int x, int y, AppItem *item);
|
||||||
|
void mouseMove(int x, int y, AppItem *item);
|
||||||
|
void mouseDoubleClick( AppItem *item);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void resizeResources();
|
||||||
|
void initBackground();
|
||||||
|
|
||||||
|
private:
|
||||||
|
AppBackground * appBackground = NULL;
|
||||||
|
AppIcon * appIcon = NULL;
|
||||||
|
int itemIndex;
|
||||||
|
|
||||||
|
bool itemMoveable = true;
|
||||||
|
bool itemHover = false;
|
||||||
|
bool itemActived = false;
|
||||||
|
bool itemDraged = false;
|
||||||
|
|
||||||
|
QString itemTitle = "";
|
||||||
|
QString itemIconPath = "";
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // APPITEM_H
|
25
dde-dock/Widgets/dockconstants.cpp
Normal file
25
dde-dock/Widgets/dockconstants.cpp
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#include "dockconstants.h"
|
||||||
|
|
||||||
|
DockConstants::DockConstants(QObject *parent) :
|
||||||
|
QObject(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
DockConstants * DockConstants::dockConstants = NULL;
|
||||||
|
DockConstants * DockConstants::getInstants()
|
||||||
|
{
|
||||||
|
if (dockConstants == NULL)
|
||||||
|
dockConstants = new DockConstants();
|
||||||
|
|
||||||
|
return dockConstants;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DockConstants::getIconSize()
|
||||||
|
{
|
||||||
|
return this->iconSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DockConstants::setIconSize(int value)
|
||||||
|
{
|
||||||
|
this->iconSize = value;
|
||||||
|
}
|
41
dde-dock/Widgets/dockconstants.h
Normal file
41
dde-dock/Widgets/dockconstants.h
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
#ifndef DOCKCONSTANTS_H
|
||||||
|
#define DOCKCONSTANTS_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QStringList>
|
||||||
|
|
||||||
|
struct DockItemData {
|
||||||
|
QString appTitle;
|
||||||
|
QString appIconPath;
|
||||||
|
QString appExePath;
|
||||||
|
bool appActived;
|
||||||
|
QStringList appPreviews;
|
||||||
|
};
|
||||||
|
|
||||||
|
class DockConstants : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(int iconSize READ getIconSize WRITE setIconSize)
|
||||||
|
public:
|
||||||
|
static DockConstants * getInstants();
|
||||||
|
|
||||||
|
enum DockMode {
|
||||||
|
FashionMode,
|
||||||
|
EfficientMode,
|
||||||
|
ClassicMode
|
||||||
|
};
|
||||||
|
|
||||||
|
int getIconSize();
|
||||||
|
void setIconSize(int value);
|
||||||
|
|
||||||
|
private:
|
||||||
|
explicit DockConstants(QObject *parent = 0);
|
||||||
|
|
||||||
|
private:
|
||||||
|
static DockConstants * dockConstants;
|
||||||
|
|
||||||
|
DockMode currentMode = DockConstants::FashionMode;
|
||||||
|
int iconSize = 42;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DOCKCONSTANTS_H
|
51
dde-dock/Widgets/dockitemdelegate.cpp
Normal file
51
dde-dock/Widgets/dockitemdelegate.cpp
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
#include "dockitemdelegate.h"
|
||||||
|
|
||||||
|
DockItemDelegate::DockItemDelegate(QObject *parent) : QItemDelegate(parent)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
QWidget * DockItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||||
|
{
|
||||||
|
AppItem * editor = new AppItem(parent);
|
||||||
|
editor->resize(50,50);
|
||||||
|
|
||||||
|
return editor;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DockItemDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
|
||||||
|
{
|
||||||
|
QJsonObject dataObj = index.model()->data(index, Qt::DisplayRole).toJsonValue().toObject();
|
||||||
|
|
||||||
|
if (dataObj.isEmpty())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
AppItem *appItem = static_cast<AppItem*>(editor);
|
||||||
|
if (dataObj.contains("itemIconPath"))
|
||||||
|
appItem->setIcon(dataObj.value("itemIconPath").toString());
|
||||||
|
if (dataObj.contains("itemTitle"))
|
||||||
|
appItem->setTitle(dataObj.value("itemTitle").toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
void DockItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
|
||||||
|
{
|
||||||
|
|
||||||
|
AppItem *appItem = static_cast<AppItem*>(editor);
|
||||||
|
// appItem->interpretText();
|
||||||
|
// int value = appItem->value();
|
||||||
|
|
||||||
|
// model->setData(index, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DockItemDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||||
|
{
|
||||||
|
editor->setGeometry(option.rect);
|
||||||
|
}
|
||||||
|
|
||||||
|
DockItemDelegate::~DockItemDelegate()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
30
dde-dock/Widgets/dockitemdelegate.h
Normal file
30
dde-dock/Widgets/dockitemdelegate.h
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#ifndef DOCKITEMDELEGATE_H
|
||||||
|
#define DOCKITEMDELEGATE_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QJsonObject>
|
||||||
|
#include <QItemDelegate>
|
||||||
|
#include <QStyleOptionViewItem>
|
||||||
|
#include <QModelIndex>
|
||||||
|
#include <QAbstractItemModel>
|
||||||
|
#include <QDebug>
|
||||||
|
#include "appitem.h"
|
||||||
|
|
||||||
|
class DockItemDelegate : public QItemDelegate
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit DockItemDelegate(QObject *parent = 0);
|
||||||
|
~DockItemDelegate();
|
||||||
|
|
||||||
|
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,const QModelIndex &index) const;
|
||||||
|
void setEditorData(QWidget * editor, const QModelIndex & index) const;
|
||||||
|
void setModelData(QWidget * editor, QAbstractItemModel * model, const QModelIndex & index) const;
|
||||||
|
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DOCKITEMDELEGATE_H
|
149
dde-dock/Widgets/docklayout.cpp
Normal file
149
dde-dock/Widgets/docklayout.cpp
Normal file
@ -0,0 +1,149 @@
|
|||||||
|
#include "docklayout.h"
|
||||||
|
|
||||||
|
DockLayout::DockLayout(QWidget *parent) :
|
||||||
|
QWidget(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void DockLayout::setParent(QWidget *parent)
|
||||||
|
{
|
||||||
|
this->setParent(parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DockLayout::addItem(AppItem *item)
|
||||||
|
{
|
||||||
|
insertItem(item,appList.count());
|
||||||
|
}
|
||||||
|
|
||||||
|
void DockLayout::insertItem(AppItem *item, int index)
|
||||||
|
{
|
||||||
|
item->setParent(this);
|
||||||
|
int appCount = appList.count();
|
||||||
|
index = index > appCount ? appCount : (index < 0 ? 0 : index);
|
||||||
|
|
||||||
|
appList.insert(index,item);
|
||||||
|
connect(item, SIGNAL(mouseMove(int,int,AppItem*)),this,SLOT(slotItemDrag(int,int,AppItem*)));
|
||||||
|
|
||||||
|
relayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DockLayout::removeItem(int index)
|
||||||
|
{
|
||||||
|
delete appList.takeAt(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DockLayout::moveItem(int from, int to)
|
||||||
|
{
|
||||||
|
appList.move(from,to);
|
||||||
|
relayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DockLayout::setItemMoveable(int index, bool moveable)
|
||||||
|
{
|
||||||
|
appList.at(index)->setMoveable(moveable);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DockLayout::setMargin(qreal margin)
|
||||||
|
{
|
||||||
|
this->leftMargin = margin;
|
||||||
|
this->rightMargin = margin;
|
||||||
|
this->topMargin = margin;
|
||||||
|
this->bottomMargin = margin;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DockLayout::setMargin(DockLayout::MarginEdge edge, qreal margin)
|
||||||
|
{
|
||||||
|
switch(edge)
|
||||||
|
{
|
||||||
|
case DockLayout::LeftMargin:
|
||||||
|
this->leftMargin = margin;
|
||||||
|
break;
|
||||||
|
case DockLayout::RightMargin:
|
||||||
|
this->rightMargin = margin;
|
||||||
|
break;
|
||||||
|
case DockLayout::TopMargin:
|
||||||
|
this->topMargin = margin;
|
||||||
|
break;
|
||||||
|
case DockLayout::BottomMargin:
|
||||||
|
this->bottomMargin = margin;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DockLayout::setSpacing(qreal spacing)
|
||||||
|
{
|
||||||
|
this->itemSpacing = spacing;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DockLayout::setSortDirection(DockLayout::Direction value)
|
||||||
|
{
|
||||||
|
this->sortDirection = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DockLayout::relayout()
|
||||||
|
{
|
||||||
|
switch (sortDirection)
|
||||||
|
{
|
||||||
|
case LeftToRight:
|
||||||
|
sortLeftToRight();
|
||||||
|
break;
|
||||||
|
case RightToLeft:
|
||||||
|
sortRightToLeft();
|
||||||
|
break;
|
||||||
|
case TopToBottom:
|
||||||
|
sortTopToBottom();
|
||||||
|
break;
|
||||||
|
case BottomToTop:
|
||||||
|
sortBottomToTop();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DockLayout::sortLeftToRight()
|
||||||
|
{
|
||||||
|
if (appList.count() <= 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
appList.at(0)->move(0,0);
|
||||||
|
|
||||||
|
for (int i = 1; i < appList.count(); i ++)
|
||||||
|
{
|
||||||
|
AppItem * frontItem = appList.at(i - 1);
|
||||||
|
appList.at(i)->move(frontItem->pos().x() + frontItem->width() + itemSpacing,0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DockLayout::sortRightToLeft()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void DockLayout::sortTopToBottom()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void DockLayout::sortBottomToTop()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int DockLayout::indexOf(AppItem *item)
|
||||||
|
{
|
||||||
|
return appList.indexOf(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
int DockLayout::indexOf(int x, int y)
|
||||||
|
{
|
||||||
|
//TODO
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DockLayout::slotItemDrag(int x, int y, AppItem *item)
|
||||||
|
{
|
||||||
|
qWarning() << "Item draging..."<<x<<y<<item;
|
||||||
|
}
|
66
dde-dock/Widgets/docklayout.h
Normal file
66
dde-dock/Widgets/docklayout.h
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
#ifndef DOCKLAYOUT_H
|
||||||
|
#define DOCKLAYOUT_H
|
||||||
|
|
||||||
|
#include <QWidget>
|
||||||
|
#include <QList>
|
||||||
|
#include "appitem.h"
|
||||||
|
|
||||||
|
class DockLayout : public QWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
enum Direction{
|
||||||
|
LeftToRight,
|
||||||
|
RightToLeft,
|
||||||
|
TopToBottom,
|
||||||
|
BottomToTop
|
||||||
|
};
|
||||||
|
|
||||||
|
enum MarginEdge{
|
||||||
|
LeftMargin,
|
||||||
|
RightMargin,
|
||||||
|
TopMargin,
|
||||||
|
BottomMargin
|
||||||
|
};
|
||||||
|
|
||||||
|
explicit DockLayout(QWidget *parent = 0);
|
||||||
|
|
||||||
|
void setParent(QWidget *parent);
|
||||||
|
void addItem(AppItem * item);
|
||||||
|
void insertItem(AppItem *item, int index);
|
||||||
|
void removeItem(int index);
|
||||||
|
void moveItem(int from, int to);
|
||||||
|
void setItemMoveable(int index, bool moveable);
|
||||||
|
void setMargin(qreal margin);
|
||||||
|
void setMargin(DockLayout::MarginEdge edge, qreal margin);
|
||||||
|
void setSpacing(qreal spacing);
|
||||||
|
void setSortDirection(DockLayout::Direction value);
|
||||||
|
void relayout();
|
||||||
|
int indexOf(AppItem * item);
|
||||||
|
int indexOf(int x,int y);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void slotItemDrag(int x,int y,AppItem *item);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void sortLeftToRight();
|
||||||
|
void sortRightToLeft();
|
||||||
|
void sortTopToBottom();
|
||||||
|
void sortBottomToTop();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QList<AppItem *> appList;
|
||||||
|
|
||||||
|
DockLayout::Direction sortDirection = DockLayout::LeftToRight;
|
||||||
|
qreal itemSpacing = 10;
|
||||||
|
qreal leftMargin = 0;
|
||||||
|
qreal rightMargin = 0;
|
||||||
|
qreal topMargin = 0;
|
||||||
|
qreal bottomMargin = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DOCKLAYOUT_H
|
135
dde-dock/Widgets/dockmodel.cpp
Normal file
135
dde-dock/Widgets/dockmodel.cpp
Normal file
@ -0,0 +1,135 @@
|
|||||||
|
#include "dockmodel.h"
|
||||||
|
|
||||||
|
DockModel::DockModel(QObject *parent) :
|
||||||
|
QAbstractItemModel(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
int DockModel::count()
|
||||||
|
{
|
||||||
|
return this->rowCount(QModelIndex());
|
||||||
|
}
|
||||||
|
|
||||||
|
void DockModel::append(const QJsonObject &dataObj)
|
||||||
|
{
|
||||||
|
insert(count(),dataObj);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DockModel::clear()
|
||||||
|
{
|
||||||
|
this->removeRows(0,count());
|
||||||
|
}
|
||||||
|
|
||||||
|
QJsonObject DockModel::get(int index)
|
||||||
|
{
|
||||||
|
QModelIndex tmpIndex = getIndex(index);
|
||||||
|
QJsonObject tmpObj = this->data(tmpIndex,0).toJsonValue().toObject();
|
||||||
|
|
||||||
|
return tmpObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DockModel::insert(int index, const QJsonObject &dataObj)
|
||||||
|
{
|
||||||
|
if (insertRow(index))
|
||||||
|
{
|
||||||
|
if (setData(getIndex(index),QVariant(dataObj)))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
qWarning() << "setData error";
|
||||||
|
}
|
||||||
|
qWarning() << "insertRow error" ;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DockModel::move(int from, int to, int count)
|
||||||
|
{
|
||||||
|
Q_UNUSED(from)
|
||||||
|
Q_UNUSED(to)
|
||||||
|
Q_UNUSED(count)
|
||||||
|
}
|
||||||
|
|
||||||
|
void DockModel::remove(int index, int count)
|
||||||
|
{
|
||||||
|
this->removeRows(index,count);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DockModel::set(int index, const QJsonObject &dataObj)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void DockModel::setProperty(int index, const QString &property, const QVariant &value)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int DockModel::indexOf(const QString &property)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
QModelIndex DockModel::getIndex(int row)
|
||||||
|
{
|
||||||
|
return this->index(row,0,QModelIndex());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DockModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||||
|
{
|
||||||
|
if (index.isValid() && role == Qt::EditRole)
|
||||||
|
{
|
||||||
|
dataArray.replace(index.row(),QJsonValue(value.toJsonObject()));
|
||||||
|
emit dataChanged(index, index);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
QModelIndex DockModel::index(int row, int column, const QModelIndex &parent) const
|
||||||
|
{
|
||||||
|
Q_UNUSED(column)
|
||||||
|
Q_UNUSED(parent)
|
||||||
|
return this->createIndex(row,0);
|
||||||
|
}
|
||||||
|
|
||||||
|
QModelIndex DockModel::parent(const QModelIndex &child) const
|
||||||
|
{
|
||||||
|
return QModelIndex();
|
||||||
|
}
|
||||||
|
|
||||||
|
int DockModel::rowCount(const QModelIndex &parent) const
|
||||||
|
{
|
||||||
|
return dataArray.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
int DockModel::columnCount(const QModelIndex &parent) const
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant DockModel::data(const QModelIndex &index, int role) const
|
||||||
|
{
|
||||||
|
if (!index.isValid())
|
||||||
|
return QVariant();
|
||||||
|
if (index.row() >= dataArray.count())
|
||||||
|
return QVariant();
|
||||||
|
if (role == Qt::DisplayRole || role == Qt::EditRole)
|
||||||
|
{
|
||||||
|
return QVariant(dataArray.at(index.row()));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DockModel::insertRows(int row, int count, const QModelIndex &parent)
|
||||||
|
{
|
||||||
|
beginInsertRows(QModelIndex(), row, row + count-1);
|
||||||
|
for (int i = row; i < row + count; i++)
|
||||||
|
{
|
||||||
|
dataArray.insert(i,QJsonValue());
|
||||||
|
}
|
||||||
|
endInsertRows();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
44
dde-dock/Widgets/dockmodel.h
Normal file
44
dde-dock/Widgets/dockmodel.h
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
#ifndef DOCKMODEL_H
|
||||||
|
#define DOCKMODEL_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QVariant>
|
||||||
|
#include <QJsonObject>
|
||||||
|
#include <QJsonArray>
|
||||||
|
#include <QAbstractItemModel>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
class DockModel : public QAbstractItemModel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit DockModel(QObject *parent = 0);
|
||||||
|
|
||||||
|
int count();
|
||||||
|
void append(const QJsonObject &dataObj);
|
||||||
|
void clear();
|
||||||
|
QJsonObject get(int index);
|
||||||
|
bool insert(int index, const QJsonObject &dataObj);
|
||||||
|
void move(int from, int to, int count);
|
||||||
|
void remove(int index, int count = 1);
|
||||||
|
void set(int index, const QJsonObject &dataObj);
|
||||||
|
void setProperty(int index, const QString &property, const QVariant &value);
|
||||||
|
int indexOf(const QString &property);
|
||||||
|
QModelIndex getIndex(int row);
|
||||||
|
|
||||||
|
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
|
||||||
|
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
|
||||||
|
QModelIndex parent(const QModelIndex &child) const;
|
||||||
|
int rowCount(const QModelIndex &parent) const;
|
||||||
|
int columnCount(const QModelIndex &parent) const;
|
||||||
|
QVariant data(const QModelIndex &index, int role = Qt::EditRole) const;
|
||||||
|
bool insertRows(int row, int count, const QModelIndex &parent);
|
||||||
|
signals:
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
|
||||||
|
private:
|
||||||
|
QJsonArray dataArray;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DOCKMODEL_H
|
6
dde-dock/Widgets/dockview.cpp
Normal file
6
dde-dock/Widgets/dockview.cpp
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#include "dockview.h"
|
||||||
|
|
||||||
|
DockView::DockView(QWidget *parent) :
|
||||||
|
QAbstractItemView(parent)
|
||||||
|
{
|
||||||
|
}
|
16
dde-dock/Widgets/dockview.h
Normal file
16
dde-dock/Widgets/dockview.h
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#ifndef DOCKVIEW_H
|
||||||
|
#define DOCKVIEW_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QWidget>
|
||||||
|
#include <QAbstractItemView>
|
||||||
|
|
||||||
|
class DockView : public QAbstractItemView
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit DockView(QWidget *parent = 0);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DOCKVIEW_H
|
42
dde-dock/dde-dock.pro
Normal file
42
dde-dock/dde-dock.pro
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
#-------------------------------------------------
|
||||||
|
#
|
||||||
|
# Project created by QtCreator 2015-06-20T10:09:57
|
||||||
|
#
|
||||||
|
#-------------------------------------------------
|
||||||
|
|
||||||
|
QT += core gui
|
||||||
|
|
||||||
|
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||||
|
|
||||||
|
TARGET = dde-dock
|
||||||
|
TEMPLATE = app
|
||||||
|
|
||||||
|
|
||||||
|
SOURCES += main.cpp\
|
||||||
|
mainwidget.cpp \
|
||||||
|
Panel/panel.cpp \
|
||||||
|
Widgets/appicon.cpp \
|
||||||
|
Widgets/appbackground.cpp \
|
||||||
|
Widgets/dockconstants.cpp \
|
||||||
|
Widgets/dockmodel.cpp \
|
||||||
|
Widgets/dockview.cpp \
|
||||||
|
Widgets/dockitemdelegate.cpp \
|
||||||
|
Widgets/appitem.cpp \
|
||||||
|
Widgets/docklayout.cpp
|
||||||
|
|
||||||
|
HEADERS += mainwidget.h \
|
||||||
|
Panel/panel.h \
|
||||||
|
Widgets/appicon.h \
|
||||||
|
Widgets/appbackground.h \
|
||||||
|
Widgets/dockconstants.h \
|
||||||
|
Widgets/dockmodel.h \
|
||||||
|
Widgets/dockview.h \
|
||||||
|
Widgets/dockitemdelegate.h \
|
||||||
|
Widgets/appitem.h \
|
||||||
|
Widgets/docklayout.h
|
||||||
|
|
||||||
|
RESOURCES += \
|
||||||
|
images.qrc
|
||||||
|
|
||||||
|
PKGCONFIG += gtk+-2.0
|
||||||
|
CONFIG += c++11 link_pkgconfig
|
5
dde-dock/images.qrc
Normal file
5
dde-dock/images.qrc
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<RCC>
|
||||||
|
<qresource prefix="/test">
|
||||||
|
<file>Resources/images/google-chrome.png</file>
|
||||||
|
</qresource>
|
||||||
|
</RCC>
|
11
dde-dock/main.cpp
Normal file
11
dde-dock/main.cpp
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#include <QApplication>
|
||||||
|
#include "mainwidget.h"
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
QApplication a(argc, argv);
|
||||||
|
MainWidget w;
|
||||||
|
w.show();
|
||||||
|
|
||||||
|
return a.exec();
|
||||||
|
}
|
17
dde-dock/mainwidget.cpp
Normal file
17
dde-dock/mainwidget.cpp
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#include "mainwidget.h"
|
||||||
|
|
||||||
|
MainWidget::MainWidget(QWidget *parent)
|
||||||
|
: QWidget(parent)
|
||||||
|
{
|
||||||
|
QRect rec = QApplication::desktop()->screenGeometry();
|
||||||
|
this->resize(rec.width(),50);
|
||||||
|
Panel * mainPanel = new Panel(this);
|
||||||
|
mainPanel->setMinimumSize(this->width(),this->height());
|
||||||
|
mainPanel->move(0,0);
|
||||||
|
this->setWindowFlags(Qt::ToolTip);
|
||||||
|
}
|
||||||
|
|
||||||
|
MainWidget::~MainWidget()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
20
dde-dock/mainwidget.h
Normal file
20
dde-dock/mainwidget.h
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#ifndef MAINWIDGET_H
|
||||||
|
#define MAINWIDGET_H
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QDesktopWidget>
|
||||||
|
#include <QWidget>
|
||||||
|
#include <QScreen>
|
||||||
|
#include <QDebug>
|
||||||
|
#include <Panel/panel.h>
|
||||||
|
|
||||||
|
class MainWidget : public QWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
MainWidget(QWidget *parent = 0);
|
||||||
|
~MainWidget();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // MAINWIDGET_H
|
Loading…
x
Reference in New Issue
Block a user