add popup window

Change-Id: I969ba51d02828a1d8689797a31f8e78161f4981f
This commit is contained in:
石博文 2016-07-15 11:00:55 +08:00 committed by Hualet Wang
parent 6d7a835ae0
commit b5543494ba
10 changed files with 89 additions and 40 deletions

View File

@ -55,11 +55,6 @@ void DockPluginsController::itemRemoved(PluginsItemInterface * const itemInter,
item->deleteLater();
}
void DockPluginsController::setDockAutoHide(const bool autoHide)
{
Q_UNUSED(autoHide);
}
//void DockPluginsController::requestPopupApplet(PluginsItemInterface * const itemInter, const QString &itemKey)
//{
// PluginsItem *item = pluginItemAt(itemInter, itemKey);

View File

@ -22,7 +22,6 @@ public:
void itemAdded(PluginsItemInterface * const itemInter, const QString &itemKey);
void itemUpdate(PluginsItemInterface * const itemInter, const QString &itemKey);
void itemRemoved(PluginsItemInterface * const itemInter, const QString &itemKey);
void setDockAutoHide(const bool autoHide);
signals:
void pluginItemInserted(PluginsItem *pluginItem) const;

View File

@ -29,7 +29,8 @@ SOURCES += main.cpp \
dbus/dbusmenu.cpp \
item/pluginsitem.cpp \
controller/dockpluginscontroller.cpp \
util/imagefactory.cpp
util/imagefactory.cpp \
util/dockpopupwindow.cpp
HEADERS += \
window/mainwindow.h \
@ -50,7 +51,8 @@ HEADERS += \
dbus/dbusmenu.h \
item/pluginsitem.h \
controller/dockpluginscontroller.h \
util/imagefactory.h
util/imagefactory.h \
util/dockpopupwindow.h
dbus_service.files += com.deepin.dde.dock.service
dbus_service.path = /usr/share/dbus-1/services

View File

@ -8,7 +8,7 @@
Position DockItem::DockPosition = Position::Top;
DisplayMode DockItem::DockDisplayMode = DisplayMode::Efficient;
std::unique_ptr<DArrowRectangle> DockItem::PopupTips(nullptr);
std::unique_ptr<DockPopupWindow> DockItem::PopupWindow(nullptr);
DockItem::DockItem(const ItemType type, QWidget *parent)
: QWidget(parent),
@ -19,17 +19,17 @@ DockItem::DockItem(const ItemType type, QWidget *parent)
m_menuManagerInter(new DBusMenuManager(this))
{
if (!PopupTips.get())
if (!PopupWindow.get())
{
DArrowRectangle *arrowRectangle = new DArrowRectangle(DArrowRectangle::ArrowBottom, nullptr);
DockPopupWindow *arrowRectangle = new DockPopupWindow(nullptr);
arrowRectangle->setShadowBlurRadius(0);
PopupTips.reset(arrowRectangle);
PopupWindow.reset(arrowRectangle);
}
m_popupTipsDelayTimer->setInterval(200);
m_popupTipsDelayTimer->setSingleShot(true);
connect(m_popupTipsDelayTimer, &QTimer::timeout, this, &DockItem::showPopupTips);
connect(m_popupTipsDelayTimer, &QTimer::timeout, this, &DockItem::showHoverTips);
}
void DockItem::setDockPosition(const Position side)
@ -80,7 +80,7 @@ void DockItem::leaveEvent(QEvent *e)
m_hover = false;
m_popupTipsDelayTimer->stop();
PopupTips->hide();
PopupWindow->hide();
update();
@ -141,31 +141,36 @@ void DockItem::showContextMenu()
menuInter->ShowMenu(QString(QJsonDocument(menuObject).toJson()));
}
void DockItem::showPopupTips()
void DockItem::showHoverTips()
{
QWidget * const content = popupTips();
if (!content)
return;
DArrowRectangle *tips = PopupTips.get();
QWidget *lastContent = tips->getContent();
showPopupWindow(content);
}
void DockItem::showPopupWindow(QWidget *content, const bool model)
{
DockPopupWindow *popup = PopupWindow.get();
QWidget *lastContent = popup->getContent();
if (lastContent)
lastContent->hide();
switch (DockPosition)
{
case Top: tips->setArrowDirection(DArrowRectangle::ArrowTop); break;
case Bottom:tips->setArrowDirection(DArrowRectangle::ArrowBottom); break;
case Left: tips->setArrowDirection(DArrowRectangle::ArrowLeft); break;
case Right: tips->setArrowDirection(DArrowRectangle::ArrowRight); break;
case Top: popup->setArrowDirection(DockPopupWindow::ArrowTop); break;
case Bottom:popup->setArrowDirection(DockPopupWindow::ArrowBottom); break;
case Left: popup->setArrowDirection(DockPopupWindow::ArrowLeft); break;
case Right: popup->setArrowDirection(DockPopupWindow::ArrowRight); break;
}
tips->setContent(content);
tips->setMargin(5);
tips->setWidth(content->sizeHint().width());
tips->setHeight(content->sizeHint().height());
popup->setContent(content);
popup->setMargin(5);
popup->setWidth(content->sizeHint().width());
popup->setHeight(content->sizeHint().height());
const QPoint p = popupMarkPoint();
tips->show(p.x(), p.y());
popup->show(p, model);
}
void DockItem::invokedMenuItem(const QString &itemId, const bool checked)

View File

@ -2,15 +2,12 @@
#define DOCKITEM_H
#include "constants.h"
#include "util/dockpopupwindow.h"
#include <QFrame>
#include <darrowrectangle.h>
#include <memory>
DWIDGET_USE_NAMESPACE
using namespace Dock;
class DBusMenuManager;
@ -48,7 +45,8 @@ protected:
const QPoint popupMarkPoint();
void showContextMenu();
void showPopupTips();
void showHoverTips();
void showPopupWindow(QWidget *content, const bool model = false);
virtual void invokedMenuItem(const QString &itemId, const bool checked);
virtual const QString contextMenu() const;
virtual QWidget *popupTips();
@ -63,7 +61,7 @@ protected:
static Position DockPosition;
static DisplayMode DockDisplayMode;
static std::unique_ptr<DArrowRectangle> PopupTips;
static std::unique_ptr<DockPopupWindow> PopupWindow;
};
#endif // DOCKITEM_H

View File

@ -135,12 +135,19 @@ void PluginsItem::startDrag()
void PluginsItem::mouseClicked()
{
const QString command = m_pluginInter->itemCommand(m_itemKey);
if (command.isEmpty())
if (!command.isEmpty())
{
QProcess *proc = new QProcess(this);
connect(proc, static_cast<void (QProcess::*)(int)>(&QProcess::finished), proc, &QProcess::deleteLater);
proc->startDetached(command);
return;
}
QProcess *proc = new QProcess(this);
connect(proc, static_cast<void (QProcess::*)(int)>(&QProcess::finished), proc, &QProcess::deleteLater);
proc->startDetached(command);
// request popup applet
QWidget *w = m_pluginInter->itemPopupApplet(m_itemKey);
qDebug() << w;
if (w)
showPopupWindow(w, true);
}

View File

@ -0,0 +1,22 @@
#include "dockpopupwindow.h"
DWIDGET_USE_NAMESPACE
DockPopupWindow::DockPopupWindow(QWidget *parent)
: DArrowRectangle(ArrowBottom, parent),
m_model(false)
{
}
bool DockPopupWindow::model() const
{
return m_model;
}
void DockPopupWindow::show(const QPoint &pos, const bool model)
{
m_model = model;
DArrowRectangle::show(pos.x(), pos.y());
}

View File

@ -0,0 +1,21 @@
#ifndef DOCKPOPUPWINDOW_H
#define DOCKPOPUPWINDOW_H
#include <darrowrectangle.h>
class DockPopupWindow : public Dtk::Widget::DArrowRectangle
{
Q_OBJECT
public:
explicit DockPopupWindow(QWidget *parent = 0);
bool model() const;
void show(const QPoint &pos, const bool model = false);
private:
bool m_model;
};
#endif // DOCKPOPUPWINDOW_H

View File

@ -12,7 +12,6 @@ public:
virtual void itemAdded(PluginsItemInterface * const itemInter, const QString &itemKey) = 0;
virtual void itemUpdate(PluginsItemInterface * const itemInter, const QString &itemKey) = 0;
virtual void itemRemoved(PluginsItemInterface * const itemInter, const QString &itemKey) = 0;
virtual void setDockAutoHide(const bool autoHide) = 0;
};
#endif // PLUGINPROXYINTERFACE_H

View File

@ -67,7 +67,8 @@ void FashionTrayItem::mousePressEvent(QMouseEvent *e)
void FashionTrayItem::mouseReleaseEvent(QMouseEvent *e)
{
Q_UNUSED(e);
QWidget::mouseReleaseEvent(e);
const QPoint point = e->pos() - m_pressPoint;
if (point.manhattanLength() > DRAG_THRESHOLD)