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;
}
QLabel#DockAppTitle {
color: rgba(255,255,255,0.8);
}
PanelMenuItem:hover {
background: gray;
color: #ffffff

View File

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

View File

@ -10,6 +10,26 @@ AppItem::AppItem(QWidget *parent) :
connect(dockCons, &DockModeData::dockModeChanged,this, &AppItem::slotDockModeChanged);
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)
@ -195,7 +215,14 @@ void AppItem::initMenu()
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()){
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)));
QJsonObject targetObj;
targetObj.insert("x",QJsonValue(x));
targetObj.insert("y",QJsonValue(y));
targetObj.insert("x",QJsonValue(globalX() + width() / 2));
targetObj.insert("y",QJsonValue(globalY() - 5));
targetObj.insert("isDockMenu",QJsonValue(true));
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)
{
//qWarning() << "mouse press...";
emit mousePress(event->globalX(), event->globalY());
hidePreview();
}
void AppItem::mouseReleaseEvent(QMouseEvent * event)
@ -232,7 +273,7 @@ void AppItem::mouseReleaseEvent(QMouseEvent * event)
if (event->button() == Qt::LeftButton)
m_entryProxyer->Activate(event->globalX(),event->globalY());
else if (event->button() == Qt::RightButton)
showMenu(event->globalX(),event->globalY());
showMenu();
}
void AppItem::mouseDoubleClickEvent(QMouseEvent * event)
@ -267,12 +308,14 @@ void AppItem::enterEvent(QEvent *event)
{
emit mouseEntered();
appBackground->setIsHovered(true);
showPreview();
}
void AppItem::leaveEvent(QEvent *event)
{
emit mouseExited();
appBackground->setIsHovered(false);
hidePreview();
}
void AppItem::dragEnterEvent(QDragEnterEvent *event)

View File

@ -13,6 +13,7 @@
#include <QImage>
#include <QList>
#include <QMap>
#include <QJsonDocument>
#include <QJsonObject>
#include <QDebug>
#include "DBus/dbusentryproxyer.h"
@ -23,6 +24,9 @@
#include "abstractdockitem.h"
#include "appicon.h"
#include "appbackground.h"
#include "apppreviews.h"
#include "arrowrectangle.h"
#include "../dockconstants.h"
struct AppItemData {
QString id;
@ -43,6 +47,7 @@ public:
AppItem(QWidget *parent = 0);
~AppItem();
QWidget *getContents();
void setEntryProxyer(DBusEntryProxyer *entryProxyer);
void destroyItem(const QString &id);
QString itemId() const;
@ -80,17 +85,21 @@ private:
void updateXids();
void updateMenuJsonString();
void initMenu();
void initPreviewAR();
void showMenu(int x, int y);
void showMenu();
void showPreview();
void hidePreview();
private:
AppItemData m_itemData;
DockModeData *dockCons = DockModeData::instance();
DBusEntryProxyer *m_entryProxyer = NULL;
DBusClientManager *m_clientmanager = NULL;
AppBackground * appBackground = NULL;
AppIcon * m_appIcon = NULL;
ArrowRectangle *m_previewAR = NULL;
DBusEntryProxyer *m_entryProxyer = NULL;
DBusClientManager *m_clientmanager = NULL;
QString m_menuInterfacePath = "";
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);
}
void ArrowRectangle::showAtLeft(int x, int y)
void ArrowRectangle::show(int x, int y)
{
if (m_destroyTimer)
m_destroyTimer->stop();
this->move(x,y);
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();
}
void ArrowRectangle::showAtRight(int x, int y)
{
if (m_destroyTimer)
m_destroyTimer->stop();
this->arrowDirection = ArrowRectangle::ArrowRight;
this->move(x,y);
if (this->isHidden())
{
this->show();
QWidget::show();
}
this->arrowDirection = ArrowRectangle::arrowRight;
this->repaint();
}
void ArrowRectangle::showAtTop(int x, int y)
{
if (m_destroyTimer)
m_destroyTimer->stop();
this->arrowDirection = ArrowRectangle::ArrowTop;
this->move(x,y);
if (this->isHidden())
{
this->show();
QWidget::show();
}
this->arrowDirection = ArrowRectangle::arrowTop;
this->repaint();
}
void ArrowRectangle::showAtBottom(int x, int y)
{
if (m_destroyTimer)
m_destroyTimer->stop();
this->arrowDirection = ArrowRectangle::ArrowBottom;
this->move(x,y);
if (this->isHidden())
{
this->show();
QWidget::show();
}
this->arrowDirection = ArrowRectangle::arrowBottom;
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)
{
if (!content)
return;
m_content = content;
content->setParent(this);
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)
{
switch (arrowDirection)
{
case arrowLeft:
case ArrowLeft:
QWidget::move(x,y - height() / 2);
break;
case arrowRight:
case ArrowRight:
QWidget::move(x - width(),y - height() / 2);
break;
case arrowTop:
case ArrowTop:
QWidget::move(x - width() / 2,y);
break;
case arrowBottom:
case ArrowBottom:
QWidget::move(x - width() / 2,y - height());
break;
default:
@ -95,19 +140,19 @@ void ArrowRectangle::paintEvent(QPaintEvent *)
switch (arrowDirection)
{
case ArrowRectangle::arrowLeft:
case ArrowRectangle::ArrowLeft:
border = getLeftCornerPath();
textRec = QRectF(arrowHeight,0,width() - arrowHeight, height());
break;
case ArrowRectangle::arrowRight:
case ArrowRectangle::ArrowRight:
border = getRightCornerPath();
textRec = QRectF(0,0,width() - arrowHeight, height());
break;
case ArrowRectangle::arrowTop:
case ArrowRectangle::ArrowTop:
border = getTopCornerPath();
textRec = QRectF(0,arrowHeight,width(), height() - arrowHeight);
break;
case ArrowRectangle::arrowBottom:
case ArrowRectangle::ArrowBottom:
border = getBottomCornerPath();
textRec = QRectF(0,0,width(), height() - arrowHeight);
break;
@ -123,6 +168,18 @@ void ArrowRectangle::paintEvent(QPaintEvent *)
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()
{
return this->radius;
@ -143,6 +200,11 @@ QString ArrowRectangle::getBackgroundColor()
return this->backgroundColor;
}
void ArrowRectangle::setArrorDirection(ArrowDirection value)
{
arrowDirection = value;
}
void ArrowRectangle::setWidth(int value)
{
this->setMinimumWidth(value);

View File

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

View File

@ -32,6 +32,9 @@ public:
void setNextPos(const QPoint &value) { m_itemNextPos = value; }
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:
void dragStart();
void dragEntered(QDragEnterEvent * event);

View File

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