diff --git a/dde-dock/Resources/qss/default.qss b/dde-dock/Resources/qss/default.qss index 0c07bae3e..c47bbc600 100644 --- a/dde-dock/Resources/qss/default.qss +++ b/dde-dock/Resources/qss/default.qss @@ -33,6 +33,10 @@ QLabel#panelMenuContent { border-radius: 5px; } +QLabel#DockAppTitle { + color: rgba(255,255,255,0.8); +} + PanelMenuItem:hover { background: gray; color: #ffffff diff --git a/dde-dock/dde-dock.pro b/dde-dock/dde-dock.pro index ddd0f5af4..f9e2f8f28 100644 --- a/dde-dock/dde-dock.pro +++ b/dde-dock/dde-dock.pro @@ -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 \ diff --git a/dde-dock/src/Widgets/appitem.cpp b/dde-dock/src/Widgets/appitem.cpp index 25a77cc37..f38866344 100644 --- a/dde-dock/src/Widgets/appitem.cpp +++ b/dde-dock/src/Widgets/appitem.cpp @@ -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 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) diff --git a/dde-dock/src/Widgets/appitem.h b/dde-dock/src/Widgets/appitem.h index 2fd61727e..8bd18018b 100644 --- a/dde-dock/src/Widgets/appitem.h +++ b/dde-dock/src/Widgets/appitem.h @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #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; }; diff --git a/dde-dock/src/Widgets/apppreviews.cpp b/dde-dock/src/Widgets/apppreviews.cpp new file mode 100644 index 000000000..769ca2e30 --- /dev/null +++ b/dde-dock/src/Widgets/apppreviews.cpp @@ -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); +} + diff --git a/dde-dock/src/Widgets/apppreviews.h b/dde-dock/src/Widgets/apppreviews.h new file mode 100644 index 000000000..6f5e72cfd --- /dev/null +++ b/dde-dock/src/Widgets/apppreviews.h @@ -0,0 +1,28 @@ +#ifndef APPPREVIEWS_H +#define APPPREVIEWS_H + +#include +#include +#include +#include +#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 m_xidList; +}; + +#endif // APPPREVIEWS_H diff --git a/dde-dock/src/Widgets/arrowrectangle.cpp b/dde-dock/src/Widgets/arrowrectangle.cpp index 9bf428287..199243058 100644 --- a/dde-dock/src/Widgets/arrowrectangle.cpp +++ b/dde-dock/src/Widgets/arrowrectangle.cpp @@ -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); diff --git a/dde-dock/src/Widgets/arrowrectangle.h b/dde-dock/src/Widgets/arrowrectangle.h index 3dd139842..bc654de6c 100644 --- a/dde-dock/src/Widgets/arrowrectangle.h +++ b/dde-dock/src/Widgets/arrowrectangle.h @@ -7,11 +7,20 @@ #include #include #include +#include +#include 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(); diff --git a/dde-dock/src/abstractdockitem.h b/dde-dock/src/abstractdockitem.h index 3328c5d6c..1e8793f17 100644 --- a/dde-dock/src/abstractdockitem.h +++ b/dde-dock/src/abstractdockitem.h @@ -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); diff --git a/dde-dock/src/dockconstants.h b/dde-dock/src/dockconstants.h index bd614ee75..e8ec9e53e 100644 --- a/dde-dock/src/dockconstants.h +++ b/dde-dock/src/dockconstants.h @@ -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