mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 09:23:03 +00:00
add menu to trash plugin
Change-Id: I833ac3ed1a7952cbff43de7664f7dccd02a6a502
This commit is contained in:
parent
ea04ee5226
commit
2d9464b893
Notes:
Deepin Code Review
2016-08-09 07:49:57 +00:00
Verified+1: Anonymous Coward #1000004 Code-Review+2: 石博文 <sbw@sbw.so> Submitted-by: 石博文 <sbw@sbw.so> Submitted-at: Tue, 09 Aug 2016 07:49:57 +0000 Reviewed-on: https://cr.deepin.io/14988 Project: dde/dde-dock Branch: refs/heads/master
@ -56,6 +56,11 @@ void DockPluginsController::itemRemoved(PluginsItemInterface * const itemInter,
|
||||
item->deleteLater();
|
||||
}
|
||||
|
||||
void DockPluginsController::requestRefershWindowVisible()
|
||||
{
|
||||
emit m_pluginList.first().first()->requestRefershWindowVisible();
|
||||
}
|
||||
|
||||
//void DockPluginsController::requestPopupApplet(PluginsItemInterface * const itemInter, const QString &itemKey)
|
||||
//{
|
||||
// PluginsItem *item = pluginItemAt(itemInter, itemKey);
|
||||
|
@ -22,6 +22,7 @@ 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 requestRefershWindowVisible();
|
||||
|
||||
signals:
|
||||
void pluginItemInserted(PluginsItem *pluginItem) const;
|
||||
|
@ -16,6 +16,8 @@ public:
|
||||
void setItemSortKey(const int order) const;
|
||||
void detachPluginWidget();
|
||||
|
||||
using DockItem::showContextMenu;
|
||||
|
||||
inline ItemType itemType() const {return Plugins;}
|
||||
|
||||
private:
|
||||
|
@ -12,6 +12,7 @@ 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 requestRefershWindowVisible() = 0;
|
||||
};
|
||||
|
||||
#endif // PLUGINPROXYINTERFACE_H
|
||||
|
@ -17,12 +17,14 @@ public:
|
||||
QSize sizeHint() const;
|
||||
static const QString trashDir();
|
||||
|
||||
public slots:
|
||||
void openTrashFloder();
|
||||
void clearTrashFloder();
|
||||
|
||||
signals:
|
||||
void emptyChanged(const bool empty) const;
|
||||
|
||||
private slots:
|
||||
void openTrashFloder();
|
||||
void clearTrashFloder();
|
||||
void trashStatusChanged();
|
||||
|
||||
private:
|
||||
|
@ -4,6 +4,9 @@ TrashPlugin::TrashPlugin(QObject *parent)
|
||||
: QObject(parent),
|
||||
m_trashWidget(new TrashWidget)
|
||||
{
|
||||
connect(m_trashWidget, &TrashWidget::requestRefershWindowVisible, [this] {
|
||||
m_proxyInter->requestRefershWindowVisible();
|
||||
});
|
||||
}
|
||||
|
||||
const QString TrashPlugin::pluginName() const
|
||||
@ -29,13 +32,14 @@ QWidget *TrashPlugin::itemPopupApplet(const QString &itemKey)
|
||||
{
|
||||
Q_UNUSED(itemKey);
|
||||
|
||||
return m_trashWidget->popupApplet();
|
||||
return nullptr;
|
||||
// return m_trashWidget->popupApplet();
|
||||
}
|
||||
|
||||
const QString TrashPlugin::itemCommand(const QString &itemKey)
|
||||
{
|
||||
Q_UNUSED(itemKey);
|
||||
|
||||
return QString();
|
||||
// return "gvfs-open trash://";
|
||||
// return QString();
|
||||
return "gvfs-open trash://";
|
||||
}
|
||||
|
@ -7,10 +7,15 @@
|
||||
#include <QApplication>
|
||||
#include <QDragEnterEvent>
|
||||
|
||||
DWIDGET_USE_NAMESPACE
|
||||
|
||||
TrashWidget::TrashWidget(QWidget *parent)
|
||||
: QWidget(parent),
|
||||
|
||||
m_popupApplet(new PopupControlWidget(this))
|
||||
m_popupApplet(new PopupControlWidget(this)),
|
||||
|
||||
m_openAct(tr("Run"), this),
|
||||
m_clearAct(tr("Empty"), this)
|
||||
{
|
||||
QIcon::setThemeName("deepin");
|
||||
|
||||
@ -62,6 +67,36 @@ void TrashWidget::resizeEvent(QResizeEvent *e)
|
||||
updateIcon();
|
||||
}
|
||||
|
||||
void TrashWidget::mousePressEvent(QMouseEvent *e)
|
||||
{
|
||||
const QPoint dis = e->pos() - rect().center();
|
||||
if (e->button() != Qt::RightButton || dis.manhattanLength() > std::min(width(), height()) * 0.8 * 0.5)
|
||||
return QWidget::mousePressEvent(e);
|
||||
|
||||
showMenu();
|
||||
}
|
||||
|
||||
const QPoint TrashWidget::popupMarkPoint()
|
||||
{
|
||||
QPoint p;
|
||||
QWidget *w = this;
|
||||
do {
|
||||
p += w->pos();
|
||||
w = qobject_cast<QWidget *>(w->parent());
|
||||
} while (w);
|
||||
|
||||
const QRect r = rect();
|
||||
switch (qApp->property(PROP_POSITION).value<Dock::Position>())
|
||||
{
|
||||
case Dock::Top: p += QPoint(r.width() / 2, r.height()); break;
|
||||
case Dock::Bottom: p += QPoint(r.width() / 2, 0); break;
|
||||
case Dock::Left: p += QPoint(r.width(), r.height() / 2); break;
|
||||
case Dock::Right: p += QPoint(0, r.height() / 2); break;
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
void TrashWidget::updateIcon()
|
||||
{
|
||||
const Dock::DisplayMode displayMode = qApp->property(PROP_DISPLAY_MODE).value<Dock::DisplayMode>();
|
||||
@ -79,6 +114,46 @@ void TrashWidget::updateIcon()
|
||||
update();
|
||||
}
|
||||
|
||||
void TrashWidget::showMenu()
|
||||
{
|
||||
DMenu *menu = new DMenu(this);
|
||||
menu->setDockMenu(true);
|
||||
|
||||
menu->addAction(&m_openAct);
|
||||
if (m_popupApplet->empty())
|
||||
menu->addAction(&m_clearAct);
|
||||
|
||||
const Dock::Position position = qApp->property(PROP_POSITION).value<Dock::Position>();
|
||||
switch (position)
|
||||
{
|
||||
case Dock::Top: menu->setDirection(DMenu::Top); break;
|
||||
case Dock::Left: menu->setDirection(DMenu::Left); break;
|
||||
case Dock::Bottom: menu->setDirection(DMenu::Bottom); break;
|
||||
case Dock::Right: menu->setDirection(DMenu::Right); break;
|
||||
default: Q_UNREACHABLE();
|
||||
}
|
||||
|
||||
const QPoint p = popupMarkPoint();
|
||||
|
||||
connect(menu, &DMenu::triggered, this, &TrashWidget::menuTriggered);
|
||||
|
||||
menu->exec(p);
|
||||
|
||||
m_clearAct.setParent(this);
|
||||
m_openAct.setParent(this);
|
||||
menu->deleteLater();
|
||||
|
||||
emit requestRefershWindowVisible();
|
||||
}
|
||||
|
||||
void TrashWidget::menuTriggered(DAction *action)
|
||||
{
|
||||
if (action == &m_clearAct)
|
||||
m_popupApplet->clearTrashFloder();
|
||||
else if (action == &m_openAct)
|
||||
m_popupApplet->openTrashFloder();
|
||||
}
|
||||
|
||||
void TrashWidget::moveToTrash(const QUrl &url)
|
||||
{
|
||||
const QFileInfo info = url.toLocalFile();
|
||||
|
@ -6,6 +6,9 @@
|
||||
#include <QWidget>
|
||||
#include <QPixmap>
|
||||
|
||||
#include <DMenu>
|
||||
#include <DAction>
|
||||
|
||||
class TrashWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -17,20 +20,32 @@ public:
|
||||
|
||||
QSize sizeHint() const;
|
||||
|
||||
signals:
|
||||
void requestRefershWindowVisible() const;
|
||||
|
||||
protected:
|
||||
void dragEnterEvent(QDragEnterEvent *e);
|
||||
void dropEvent(QDropEvent *e);
|
||||
void paintEvent(QPaintEvent *e);
|
||||
void resizeEvent(QResizeEvent *e);
|
||||
void mousePressEvent(QMouseEvent *e);
|
||||
|
||||
private:
|
||||
const QPoint popupMarkPoint();
|
||||
|
||||
private slots:
|
||||
void updateIcon();
|
||||
void showMenu();
|
||||
void menuTriggered(Dtk::Widget::DAction *action);
|
||||
void moveToTrash(const QUrl &url);
|
||||
|
||||
private:
|
||||
PopupControlWidget *m_popupApplet;
|
||||
|
||||
QPixmap m_icon;
|
||||
|
||||
Dtk::Widget::DAction m_openAct;
|
||||
Dtk::Widget::DAction m_clearAct;
|
||||
};
|
||||
|
||||
#endif // TRASHWIDGET_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user