add trash plugin menu

Change-Id: I409788973046d6f463c68ee97eb3558b95407bab
This commit is contained in:
石博文 2016-08-01 14:26:15 +08:00 committed by Hualet Wang
parent 70253afad8
commit 14873b08af
8 changed files with 90 additions and 7 deletions

View File

@ -54,9 +54,20 @@ DockItem::ItemType DockItem::itemType() const
return m_type;
}
void DockItem::updatePopupPosition()
{
if (!m_popupShown)
return;
const QPoint p = popupMarkPoint();
PopupWindow->show(p, PopupWindow->model());
}
void DockItem::paintEvent(QPaintEvent *e)
{
QWidget::paintEvent(e);
updatePopupPosition();
}
void DockItem::mouseMoveEvent(QMouseEvent *e)

View File

@ -56,6 +56,7 @@ protected:
virtual QWidget *popupTips();
private:
void updatePopupPosition();
void showPopupWindow(QWidget * const content, const bool model = false);
protected:

View File

@ -71,7 +71,7 @@ void DockPopupWindow::mousePressEvent(QMouseEvent *e)
DArrowRectangle::mousePressEvent(e);
// if (e->button() == Qt::LeftButton)
// m_acceptDelayTimer->start();
// m_acceptDelayTimer->start();
}
bool DockPopupWindow::eventFilter(QObject *o, QEvent *e)

View File

@ -0,0 +1,34 @@
#include "popupcontrolwidget.h"
#include <QVBoxLayout>
#include <QProcess>
#include <QDebug>
#include <QMouseEvent>
DWIDGET_USE_NAMESPACE
PopupControlWidget::PopupControlWidget(QWidget *parent)
: QWidget(parent),
m_openBtn(new DLinkButton(tr("Open"), this)),
m_clearBtn(new DLinkButton(tr("Clear"), this))
{
QVBoxLayout *centeralLayout = new QVBoxLayout;
centeralLayout->addWidget(m_openBtn);
centeralLayout->addWidget(m_clearBtn);
connect(m_openBtn, &DLinkButton::clicked, this, &PopupControlWidget::openTrashFloder);
setLayout(centeralLayout);
setFixedWidth(80);
setFixedHeight(60);
}
void PopupControlWidget::openTrashFloder()
{
QProcess *proc = new QProcess;
connect(proc, static_cast<void (QProcess::*)(int)>(&QProcess::finished), proc, &QProcess::deleteLater);
proc->startDetached("gvfs-open trash://");
}

View File

@ -0,0 +1,23 @@
#ifndef POPUPCONTROLWIDGET_H
#define POPUPCONTROLWIDGET_H
#include <QWidget>
#include <dlinkbutton.h>
class PopupControlWidget : public QWidget
{
Q_OBJECT
public:
explicit PopupControlWidget(QWidget *parent = 0);
private slots:
void openTrashFloder();
private:
Dtk::Widget::DLinkButton *m_openBtn;
Dtk::Widget::DLinkButton *m_clearBtn;
};
#endif // POPUPCONTROLWIDGET_H

View File

@ -4,7 +4,7 @@ include(../../interfaces/interfaces.pri)
QT += widgets svg
TEMPLATE = lib
CONFIG += plugin c++11 link_pkgconfig
PKGCONFIG +=
PKGCONFIG += dtkbase dtkwidget
TARGET = $$qtLibraryTarget(trash)
DESTDIR = $$_PRO_FILE_PWD_/../
@ -12,11 +12,13 @@ DISTFILES += trash.json
HEADERS += \
trashplugin.h \
trashwidget.h
trashwidget.h \
popupcontrolwidget.h
SOURCES += \
trashplugin.cpp \
trashwidget.cpp
trashwidget.cpp \
popupcontrolwidget.cpp
target.path = $${PREFIX}/lib/dde-dock/plugins/
INSTALLS += target

View File

@ -2,9 +2,10 @@
TrashPlugin::TrashPlugin(QObject *parent)
: QObject(parent),
m_trashWidget(new TrashWidget)
m_trashWidget(new TrashWidget),
m_popupApplet(new PopupControlWidget)
{
m_popupApplet->setVisible(false);
}
const QString TrashPlugin::pluginName() const
@ -26,9 +27,17 @@ QWidget *TrashPlugin::itemWidget(const QString &itemKey)
return m_trashWidget;
}
QWidget *TrashPlugin::itemPopupApplet(const QString &itemKey)
{
Q_UNUSED(itemKey);
return m_popupApplet;
}
const QString TrashPlugin::itemCommand(const QString &itemKey)
{
Q_UNUSED(itemKey);
return "gvfs-open trash://";
return QString();
// return "gvfs-open trash://";
}

View File

@ -3,6 +3,7 @@
#include "pluginsiteminterface.h"
#include "trashwidget.h"
#include "popupcontrolwidget.h"
class TrashPlugin : public QObject, PluginsItemInterface
{
@ -17,10 +18,12 @@ public:
void init(PluginProxyInterface *proxyInter);
QWidget *itemWidget(const QString &itemKey);
QWidget *itemPopupApplet(const QString &itemKey);
const QString itemCommand(const QString &itemKey);
private:
TrashWidget *m_trashWidget;
PopupControlWidget *m_popupApplet;
};
#endif // TRASHPLUGIN_H