Add app window preview and title

This commit is contained in:
杨万青 2015-07-07 15:54:06 +08:00
parent eaf5c6a305
commit cc58d7cc8e
10 changed files with 231 additions and 35 deletions

View File

@ -33,6 +33,10 @@ QLabel#panelMenuContent {
border-radius: 5px; border-radius: 5px;
} }
QLabel#DockAppTitle {
color: rgba(255,255,255,0.8);
}
PanelMenuItem:hover { PanelMenuItem:hover {
background: gray; background: gray;
color: #ffffff color: #ffffff

View File

@ -36,7 +36,8 @@ SOURCES += \
src/dockpluginproxy.cpp \ src/dockpluginproxy.cpp \
src/dockpluginmanager.cpp\ src/dockpluginmanager.cpp\
src/DBus/dbusmenumanager.cpp \ src/DBus/dbusmenumanager.cpp \
src/DBus/dbusmenu.cpp src/DBus/dbusmenu.cpp \
src/Widgets/apppreviews.cpp
HEADERS += \ HEADERS += \
src/abstractdockitem.h \ src/abstractdockitem.h \
@ -65,7 +66,8 @@ HEADERS += \
src/DBus/dbusmenumanager.h \ src/DBus/dbusmenumanager.h \
src/DBus/dbusmenu.h \ src/DBus/dbusmenu.h \
src/dockpluginmanager.h \ src/dockpluginmanager.h \
src/dockconstants.h src/dockconstants.h \
src/Widgets/apppreviews.h
RESOURCES += \ RESOURCES += \
images.qrc \ images.qrc \

View File

@ -10,6 +10,26 @@ AppItem::AppItem(QWidget *parent) :
connect(dockCons, &DockModeData::dockModeChanged,this, &AppItem::slotDockModeChanged); connect(dockCons, &DockModeData::dockModeChanged,this, &AppItem::slotDockModeChanged);
initMenu(); initMenu();
initPreviewAR();
}
QWidget *AppItem::getContents()
{
AppPreviews *preview = new AppPreviews();
QJsonArray tmpArray = QJsonDocument::fromJson(m_itemData.xidsJsonString.toUtf8()).array();
if (m_itemData.isActived && !tmpArray.isEmpty())
{
foreach (QJsonValue v, tmpArray) {
QString title = v.toObject().value("Title").toString();
int xid = v.toObject().value("Xid").toInt();
preview->addItem(title,xid);
}
}
else
{
preview->setTitle(m_itemData.title);
}
return preview;
} }
void AppItem::setEntryProxyer(DBusEntryProxyer *entryProxyer) void AppItem::setEntryProxyer(DBusEntryProxyer *entryProxyer)
@ -195,7 +215,14 @@ void AppItem::initMenu()
m_menuManager = new DBusMenuManager(this); m_menuManager = new DBusMenuManager(this);
} }
void AppItem::showMenu(int x,int y) void AppItem::initPreviewAR()
{
m_previewAR = new ArrowRectangle();
m_previewAR->setHeight(130);
m_previewAR->setWidth(200);
}
void AppItem::showMenu()
{ {
if (m_menuManager->isValid()){ if (m_menuManager->isValid()){
QDBusPendingReply<QDBusObjectPath> pr = m_menuManager->RegisterMenu(); QDBusPendingReply<QDBusObjectPath> pr = m_menuManager->RegisterMenu();
@ -207,8 +234,8 @@ void AppItem::showMenu(int x,int y)
connect(m_menu,SIGNAL(ItemInvoked(QString,bool)),this,SLOT(menuItemInvoked(QString,bool))); connect(m_menu,SIGNAL(ItemInvoked(QString,bool)),this,SLOT(menuItemInvoked(QString,bool)));
QJsonObject targetObj; QJsonObject targetObj;
targetObj.insert("x",QJsonValue(x)); targetObj.insert("x",QJsonValue(globalX() + width() / 2));
targetObj.insert("y",QJsonValue(y)); targetObj.insert("y",QJsonValue(globalY() - 5));
targetObj.insert("isDockMenu",QJsonValue(true)); targetObj.insert("isDockMenu",QJsonValue(true));
targetObj.insert("menuJsonContent",QJsonValue(m_itemData.menuJsonString)); targetObj.insert("menuJsonContent",QJsonValue(m_itemData.menuJsonString));
@ -217,11 +244,25 @@ void AppItem::showMenu(int x,int y)
} }
} }
void AppItem::showPreview()
{
QWidget *tmpContent = getContents();
m_previewAR->setMinimumSize(tmpContent->width() + Dock::APP_PREVIEW_MARGIN * 2,tmpContent->height() + Dock::APP_PREVIEW_MARGIN * 2);
m_previewAR->resize(tmpContent->width() + Dock::APP_PREVIEW_MARGIN * 2,tmpContent->height() + Dock::APP_PREVIEW_MARGIN * 2);
m_previewAR->setContent(getContents());
m_previewAR->showAtBottom(globalX() + width() / 2,globalY() - 5);
}
void AppItem::hidePreview()
{
m_previewAR->delayHide();
}
void AppItem::mousePressEvent(QMouseEvent * event) void AppItem::mousePressEvent(QMouseEvent * event)
{ {
//qWarning() << "mouse press..."; //qWarning() << "mouse press...";
emit mousePress(event->globalX(), event->globalY()); emit mousePress(event->globalX(), event->globalY());
hidePreview();
} }
void AppItem::mouseReleaseEvent(QMouseEvent * event) void AppItem::mouseReleaseEvent(QMouseEvent * event)
@ -232,7 +273,7 @@ void AppItem::mouseReleaseEvent(QMouseEvent * event)
if (event->button() == Qt::LeftButton) if (event->button() == Qt::LeftButton)
m_entryProxyer->Activate(event->globalX(),event->globalY()); m_entryProxyer->Activate(event->globalX(),event->globalY());
else if (event->button() == Qt::RightButton) else if (event->button() == Qt::RightButton)
showMenu(event->globalX(),event->globalY()); showMenu();
} }
void AppItem::mouseDoubleClickEvent(QMouseEvent * event) void AppItem::mouseDoubleClickEvent(QMouseEvent * event)
@ -267,12 +308,14 @@ void AppItem::enterEvent(QEvent *event)
{ {
emit mouseEntered(); emit mouseEntered();
appBackground->setIsHovered(true); appBackground->setIsHovered(true);
showPreview();
} }
void AppItem::leaveEvent(QEvent *event) void AppItem::leaveEvent(QEvent *event)
{ {
emit mouseExited(); emit mouseExited();
appBackground->setIsHovered(false); appBackground->setIsHovered(false);
hidePreview();
} }
void AppItem::dragEnterEvent(QDragEnterEvent *event) void AppItem::dragEnterEvent(QDragEnterEvent *event)

View File

@ -13,6 +13,7 @@
#include <QImage> #include <QImage>
#include <QList> #include <QList>
#include <QMap> #include <QMap>
#include <QJsonDocument>
#include <QJsonObject> #include <QJsonObject>
#include <QDebug> #include <QDebug>
#include "DBus/dbusentryproxyer.h" #include "DBus/dbusentryproxyer.h"
@ -23,6 +24,9 @@
#include "abstractdockitem.h" #include "abstractdockitem.h"
#include "appicon.h" #include "appicon.h"
#include "appbackground.h" #include "appbackground.h"
#include "apppreviews.h"
#include "arrowrectangle.h"
#include "../dockconstants.h"
struct AppItemData { struct AppItemData {
QString id; QString id;
@ -43,6 +47,7 @@ public:
AppItem(QWidget *parent = 0); AppItem(QWidget *parent = 0);
~AppItem(); ~AppItem();
QWidget *getContents();
void setEntryProxyer(DBusEntryProxyer *entryProxyer); void setEntryProxyer(DBusEntryProxyer *entryProxyer);
void destroyItem(const QString &id); void destroyItem(const QString &id);
QString itemId() const; QString itemId() const;
@ -80,17 +85,21 @@ private:
void updateXids(); void updateXids();
void updateMenuJsonString(); void updateMenuJsonString();
void initMenu(); void initMenu();
void initPreviewAR();
void showMenu(int x, int y); void showMenu();
void showPreview();
void hidePreview();
private: private:
AppItemData m_itemData; AppItemData m_itemData;
DockModeData *dockCons = DockModeData::instance(); DockModeData *dockCons = DockModeData::instance();
DBusEntryProxyer *m_entryProxyer = NULL;
DBusClientManager *m_clientmanager = NULL;
AppBackground * appBackground = NULL; AppBackground * appBackground = NULL;
AppIcon * m_appIcon = NULL; AppIcon * m_appIcon = NULL;
ArrowRectangle *m_previewAR = NULL;
DBusEntryProxyer *m_entryProxyer = NULL;
DBusClientManager *m_clientmanager = NULL;
QString m_menuInterfacePath = ""; QString m_menuInterfacePath = "";
DBusMenuManager *m_menuManager = NULL; DBusMenuManager *m_menuManager = NULL;
}; };

View File

@ -0,0 +1,29 @@
#include "apppreviews.h"
AppPreviews::AppPreviews(QWidget *parent) : QWidget(parent)
{
m_mainLayout = new QHBoxLayout(this);
setLayout(m_mainLayout);
resize(Dock::APP_PREVIEW_WIDTH,Dock::APP_PREVIEW_HEIGHT);
}
void AppPreviews::addItem(const QString &title, int xid)
{
if (m_xidList.indexOf(xid) != -1)
return;
m_xidList.append(xid);
WindowPreview * preview = new WindowPreview(xid);
preview->resize(Dock::APP_PREVIEW_WIDTH,Dock::APP_PREVIEW_HEIGHT);
m_mainLayout->addWidget(preview);
resize(m_mainLayout->count() * Dock::APP_PREVIEW_WIDTH,Dock::APP_PREVIEW_HEIGHT);
}
void AppPreviews::setTitle(const QString &title)
{
QLabel *titleLabel = new QLabel(title);
titleLabel->setObjectName("DockAppTitle");
titleLabel->setAlignment(Qt::AlignCenter);
m_mainLayout->addWidget(titleLabel);
resize(100,35);
}

View File

@ -0,0 +1,28 @@
#ifndef APPPREVIEWS_H
#define APPPREVIEWS_H
#include <QWidget>
#include <QHBoxLayout>
#include <QLabel>
#include <QDebug>
#include "windowpreview.h"
#include "../dockconstants.h"
class AppPreviews : public QWidget
{
Q_OBJECT
public:
explicit AppPreviews(QWidget *parent = 0);
void addItem(const QString &title,int xid);
void setTitle(const QString &title);
signals:
public slots:
private:
QHBoxLayout *m_mainLayout = NULL;
QList<int> m_xidList;
};
#endif // APPPREVIEWS_H

View File

@ -7,74 +7,119 @@ ArrowRectangle::ArrowRectangle(QWidget * parent) :
this->setAttribute(Qt::WA_TranslucentBackground); this->setAttribute(Qt::WA_TranslucentBackground);
} }
void ArrowRectangle::showAtLeft(int x, int y) void ArrowRectangle::show(int x, int y)
{ {
if (m_destroyTimer)
m_destroyTimer->stop();
this->move(x,y); this->move(x,y);
if (this->isHidden()) if (this->isHidden())
{ {
this->show(); QWidget::show();
}
this->repaint();
}
void ArrowRectangle::showAtLeft(int x, int y)
{
if (m_destroyTimer)
m_destroyTimer->stop();
this->arrowDirection = ArrowRectangle::ArrowLeft;
this->move(x,y);
if (this->isHidden())
{
QWidget::show();
} }
this->arrowDirection = ArrowRectangle::arrowLeft;
this->repaint(); this->repaint();
} }
void ArrowRectangle::showAtRight(int x, int y) void ArrowRectangle::showAtRight(int x, int y)
{ {
if (m_destroyTimer)
m_destroyTimer->stop();
this->arrowDirection = ArrowRectangle::ArrowRight;
this->move(x,y); this->move(x,y);
if (this->isHidden()) if (this->isHidden())
{ {
this->show(); QWidget::show();
} }
this->arrowDirection = ArrowRectangle::arrowRight;
this->repaint(); this->repaint();
} }
void ArrowRectangle::showAtTop(int x, int y) void ArrowRectangle::showAtTop(int x, int y)
{ {
if (m_destroyTimer)
m_destroyTimer->stop();
this->arrowDirection = ArrowRectangle::ArrowTop;
this->move(x,y); this->move(x,y);
if (this->isHidden()) if (this->isHidden())
{ {
this->show(); QWidget::show();
} }
this->arrowDirection = ArrowRectangle::arrowTop;
this->repaint(); this->repaint();
} }
void ArrowRectangle::showAtBottom(int x, int y) void ArrowRectangle::showAtBottom(int x, int y)
{ {
if (m_destroyTimer)
m_destroyTimer->stop();
this->arrowDirection = ArrowRectangle::ArrowBottom;
this->move(x,y); this->move(x,y);
if (this->isHidden()) if (this->isHidden())
{ {
this->show(); QWidget::show();
} }
this->arrowDirection = ArrowRectangle::arrowBottom;
this->repaint(); this->repaint();
} }
void ArrowRectangle::delayHide(int interval)
{
if (!m_destroyTimer)
{
m_destroyTimer = new QTimer(this);
connect(m_destroyTimer,&QTimer::timeout,this,&ArrowRectangle::slotHide);
connect(m_destroyTimer,&QTimer::timeout,m_destroyTimer,&QTimer::stop);
}
m_destroyTimer->stop();
m_destroyTimer->start(interval);
}
void ArrowRectangle::setContent(QWidget *content) void ArrowRectangle::setContent(QWidget *content)
{ {
if (!content)
return;
m_content = content;
content->setParent(this); content->setParent(this);
content->move((width() - content->width()) / 2,(height() - content->height()) / 2); content->move((width() - content->width()) / 2,(height() - content->height()) / 2);
} }
void ArrowRectangle::destroyContent()
{
if (m_content)
{
delete m_content;
m_content = NULL;
}
}
void ArrowRectangle::move(int x, int y) void ArrowRectangle::move(int x, int y)
{ {
switch (arrowDirection) switch (arrowDirection)
{ {
case arrowLeft: case ArrowLeft:
QWidget::move(x,y - height() / 2); QWidget::move(x,y - height() / 2);
break; break;
case arrowRight: case ArrowRight:
QWidget::move(x - width(),y - height() / 2); QWidget::move(x - width(),y - height() / 2);
break; break;
case arrowTop: case ArrowTop:
QWidget::move(x - width() / 2,y); QWidget::move(x - width() / 2,y);
break; break;
case arrowBottom: case ArrowBottom:
QWidget::move(x - width() / 2,y - height()); QWidget::move(x - width() / 2,y - height());
break; break;
default: default:
@ -95,19 +140,19 @@ void ArrowRectangle::paintEvent(QPaintEvent *)
switch (arrowDirection) switch (arrowDirection)
{ {
case ArrowRectangle::arrowLeft: case ArrowRectangle::ArrowLeft:
border = getLeftCornerPath(); border = getLeftCornerPath();
textRec = QRectF(arrowHeight,0,width() - arrowHeight, height()); textRec = QRectF(arrowHeight,0,width() - arrowHeight, height());
break; break;
case ArrowRectangle::arrowRight: case ArrowRectangle::ArrowRight:
border = getRightCornerPath(); border = getRightCornerPath();
textRec = QRectF(0,0,width() - arrowHeight, height()); textRec = QRectF(0,0,width() - arrowHeight, height());
break; break;
case ArrowRectangle::arrowTop: case ArrowRectangle::ArrowTop:
border = getTopCornerPath(); border = getTopCornerPath();
textRec = QRectF(0,arrowHeight,width(), height() - arrowHeight); textRec = QRectF(0,arrowHeight,width(), height() - arrowHeight);
break; break;
case ArrowRectangle::arrowBottom: case ArrowRectangle::ArrowBottom:
border = getBottomCornerPath(); border = getBottomCornerPath();
textRec = QRectF(0,0,width(), height() - arrowHeight); textRec = QRectF(0,0,width(), height() - arrowHeight);
break; break;
@ -123,6 +168,18 @@ void ArrowRectangle::paintEvent(QPaintEvent *)
painter.fillPath(border, QBrush(backgroundColor == "" ? QColor(0,0,0,150) : QColor(backgroundColor))); painter.fillPath(border, QBrush(backgroundColor == "" ? QColor(0,0,0,150) : QColor(backgroundColor)));
} }
void ArrowRectangle::slotHide()
{
destroyContent();
hide();
}
void ArrowRectangle::slotCancelHide()
{
if (m_destroyTimer)
m_destroyTimer->stop();
}
int ArrowRectangle::getRadius() int ArrowRectangle::getRadius()
{ {
return this->radius; return this->radius;
@ -143,6 +200,11 @@ QString ArrowRectangle::getBackgroundColor()
return this->backgroundColor; return this->backgroundColor;
} }
void ArrowRectangle::setArrorDirection(ArrowDirection value)
{
arrowDirection = value;
}
void ArrowRectangle::setWidth(int value) void ArrowRectangle::setWidth(int value)
{ {
this->setMinimumWidth(value); this->setMinimumWidth(value);

View File

@ -7,11 +7,20 @@
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QPainter> #include <QPainter>
#include <QTimer>
#include <QDebug>
class ArrowRectangle : public QWidget class ArrowRectangle : public QWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
enum ArrowDirection {
ArrowLeft,
ArrowRight,
ArrowTop,
ArrowBottom
};
explicit ArrowRectangle(QWidget * parent = 0); explicit ArrowRectangle(QWidget * parent = 0);
~ArrowRectangle(); ~ArrowRectangle();
@ -20,6 +29,7 @@ public:
int getArrowWidth(); int getArrowWidth();
QString getBackgroundColor(); QString getBackgroundColor();
void setArrorDirection(ArrowDirection value);
void setWidth(int value); void setWidth(int value);
void setHeight(int value); void setHeight(int value);
void setRadius(int value); void setRadius(int value);
@ -27,24 +37,24 @@ public:
void setArrowWidth(int value); void setArrowWidth(int value);
void setBackgroundColor(QString value); void setBackgroundColor(QString value);
void show(int x,int y);
void showAtLeft(int x,int y); void showAtLeft(int x,int y);
void showAtRight(int x,int y); void showAtRight(int x,int y);
void showAtTop(int x,int y); void showAtTop(int x,int y);
void showAtBottom(int x,int y); void showAtBottom(int x,int y);
void delayHide(int interval = 500);
void setContent(QWidget *content); void setContent(QWidget *content);
void destroyContent();
void move(int x,int y); void move(int x,int y);
public slots:
void slotHide();
void slotCancelHide();
protected: protected:
virtual void paintEvent(QPaintEvent *); virtual void paintEvent(QPaintEvent *);
private: private:
enum ArrowDirection {
arrowLeft,
arrowRight,
arrowTop,
arrowBottom
};
int radius = 3; int radius = 3;
int arrowHeight = 8; int arrowHeight = 8;
int arrowWidth = 20; int arrowWidth = 20;
@ -55,8 +65,10 @@ private:
int shadowWidth = 2; int shadowWidth = 2;
QColor shadowColor = Qt::black; QColor shadowColor = Qt::black;
ArrowDirection arrowDirection = ArrowRectangle::arrowRight; ArrowDirection arrowDirection = ArrowRectangle::ArrowRight;
QWidget *m_content = NULL;
QTimer *m_destroyTimer = NULL;
private: private:
QPainterPath getLeftCornerPath(); QPainterPath getLeftCornerPath();
QPainterPath getRightCornerPath(); QPainterPath getRightCornerPath();

View File

@ -32,6 +32,9 @@ public:
void setNextPos(const QPoint &value) { m_itemNextPos = value; } void setNextPos(const QPoint &value) { m_itemNextPos = value; }
void setNextPos(int x, int y) { m_itemNextPos.setX(x); m_itemNextPos.setY(y); } void setNextPos(int x, int y) { m_itemNextPos.setX(x); m_itemNextPos.setY(y); }
int globalX(){return mapToGlobal(QPoint(0,0)).x();}
int globalY(){return mapToGlobal(QPoint(0,0)).y();}
QPoint globalPos(){return mapToGlobal(QPoint(0,0));}
signals: signals:
void dragStart(); void dragStart();
void dragEntered(QDragEnterEvent * event); void dragEntered(QDragEnterEvent * event);

View File

@ -9,6 +9,10 @@ enum DockMode {
ClassicMode ClassicMode
}; };
const int APP_PREVIEW_WIDTH = 200;
const int APP_PREVIEW_HEIGHT = 130;
const int APP_PREVIEW_MARGIN = 5;
} }
#endif // DOCKCONSTANTS_H #endif // DOCKCONSTANTS_H