disk plugin support unmount

Change-Id: If1e286bfb9f88c4fa268d7ab30b027da95e37452
This commit is contained in:
石博文 2016-07-20 16:30:56 +08:00 committed by Hualet Wang
parent 7042c3560f
commit 9cb9016933
11 changed files with 57 additions and 10 deletions

View File

@ -84,7 +84,7 @@ public Q_SLOTS: // METHODS
} }
Q_SIGNALS: // SIGNALS Q_SIGNALS: // SIGNALS
void ButtonRelease(int in0, int in1, int in2, const QString &in3); void ButtonRelease(int button, int x, int y, const QString &id);
// begin property changed signals // begin property changed signals
}; };

View File

@ -14,6 +14,7 @@ DockItem::DockItem(const ItemType type, QWidget *parent)
: QWidget(parent), : QWidget(parent),
m_type(type), m_type(type),
m_hover(false), m_hover(false),
m_popupShown(false),
m_popupTipsDelayTimer(new QTimer(this)), m_popupTipsDelayTimer(new QTimer(this)),
@ -32,6 +33,12 @@ DockItem::DockItem(const ItemType type, QWidget *parent)
connect(m_popupTipsDelayTimer, &QTimer::timeout, this, &DockItem::showHoverTips); connect(m_popupTipsDelayTimer, &QTimer::timeout, this, &DockItem::showHoverTips);
} }
DockItem::~DockItem()
{
if (m_popupShown)
popupWindowAccept();
}
void DockItem::setDockPosition(const Position side) void DockItem::setDockPosition(const Position side)
{ {
DockPosition = side; DockPosition = side;
@ -82,7 +89,10 @@ void DockItem::leaveEvent(QEvent *e)
// auto hide if popup is not model window // auto hide if popup is not model window
if (!PopupWindow->model()) if (!PopupWindow->model())
{
m_popupShown = false;
PopupWindow->hide(); PopupWindow->hide();
}
update(); update();
@ -158,6 +168,8 @@ void DockItem::showHoverTips()
void DockItem::showPopupWindow(QWidget * const content, const bool model) void DockItem::showPopupWindow(QWidget * const content, const bool model)
{ {
m_popupShown = true;
if (model) if (model)
emit requestWindowAutoHide(false); emit requestWindowAutoHide(false);
@ -191,6 +203,7 @@ void DockItem::popupWindowAccept()
disconnect(PopupWindow.get(), &DockPopupWindow::accept, this, &DockItem::popupWindowAccept); disconnect(PopupWindow.get(), &DockPopupWindow::accept, this, &DockItem::popupWindowAccept);
m_popupShown = false;
PopupWindow->hide(); PopupWindow->hide();
emit requestWindowAutoHide(true); emit requestWindowAutoHide(true);

View File

@ -25,6 +25,8 @@ public:
public: public:
explicit DockItem(const ItemType type, QWidget *parent = nullptr); explicit DockItem(const ItemType type, QWidget *parent = nullptr);
~DockItem();
static void setDockPosition(const Position side); static void setDockPosition(const Position side);
static void setDockDisplayMode(const DisplayMode mode); static void setDockDisplayMode(const DisplayMode mode);
@ -56,6 +58,7 @@ protected:
protected: protected:
ItemType m_type; ItemType m_type;
bool m_hover; bool m_hover;
bool m_popupShown;
QTimer *m_popupTipsDelayTimer; QTimer *m_popupTipsDelayTimer;

View File

@ -12,7 +12,7 @@ LauncherItem::LauncherItem(QWidget *parent)
m_tips(new QLabel(this)) m_tips(new QLabel(this))
{ {
m_tips->setVisible(false); m_tips->setVisible(false);
m_tips->setText("Launcher"); m_tips->setText(tr("Launcher"));
m_tips->setStyleSheet("color:white;" m_tips->setStyleSheet("color:white;"
"padding:5px 10px;"); "padding:5px 10px;");
} }

View File

@ -61,12 +61,17 @@ void DockPopupWindow::mousePressEvent(QMouseEvent *e)
// m_acceptDelayTimer->start(); // m_acceptDelayTimer->start();
} }
void DockPopupWindow::globalMouseRelease() void DockPopupWindow::globalMouseRelease(int button, int x, int y, const QString &id)
{ {
Q_UNUSED(button);
if (id != m_mouseAreaKey)
return;
Q_ASSERT(m_model); Q_ASSERT(m_model);
const QRect rect = QRect(pos(), size()); const QRect rect = QRect(pos(), size());
const QPoint pos = QCursor::pos(); const QPoint pos = QPoint(x, y);
if (rect.contains(pos)) if (rect.contains(pos))
return; return;

View File

@ -26,7 +26,7 @@ protected:
void mousePressEvent(QMouseEvent *e); void mousePressEvent(QMouseEvent *e);
private slots: private slots:
void globalMouseRelease(); void globalMouseRelease(int button, int x, int y, const QString &id);
private: private:
bool m_model; bool m_model;

View File

@ -89,10 +89,10 @@ public Q_SLOTS: // METHODS
return asyncCallWithArgumentList(QStringLiteral("QueryDisk"), argumentList); return asyncCallWithArgumentList(QStringLiteral("QueryDisk"), argumentList);
} }
inline QDBusPendingReply<> Unmount(const QString &in0) inline QDBusPendingReply<> Unmount(const QString &diskId)
{ {
QList<QVariant> argumentList; QList<QVariant> argumentList;
argumentList << QVariant::fromValue(in0); argumentList << QVariant::fromValue(diskId);
return asyncCallWithArgumentList(QStringLiteral("Unmount"), argumentList); return asyncCallWithArgumentList(QStringLiteral("Unmount"), argumentList);
} }

View File

@ -28,7 +28,7 @@ DiskControlItem::DiskControlItem(const DiskInfo &info, QWidget *parent)
"background-color:rgba(255, 255, 255, .3);" "background-color:rgba(255, 255, 255, .3);"
"}" "}"
"QProgressBar::chunk {" "QProgressBar::chunk {"
"background-color:blue;" "background-color:white;"
"}"); "}");
m_unmountButton->setNormalPic(":/icons/resources/unmount-normal.png"); m_unmountButton->setNormalPic(":/icons/resources/unmount-normal.png");
@ -61,6 +61,8 @@ DiskControlItem::DiskControlItem(const DiskInfo &info, QWidget *parent)
setLayout(centeralLayout); setLayout(centeralLayout);
connect(m_unmountButton, &DImageButton::clicked, [this] {emit requestUnmount(m_info.m_id);});
updateInfo(info); updateInfo(info);
} }

View File

@ -16,6 +16,9 @@ class DiskControlItem : public QWidget
public: public:
explicit DiskControlItem(const DiskInfo &info, QWidget *parent = 0); explicit DiskControlItem(const DiskInfo &info, QWidget *parent = 0);
signals:
void requestUnmount(const QString &diskId) const;
private slots: private slots:
void updateInfo(const DiskInfo &info); void updateInfo(const DiskInfo &info);
const QString formatDiskSize(const quint64 size) const; const QString formatDiskSize(const quint64 size) const;

View File

@ -31,17 +31,37 @@ void DiskControlWidget::diskListChanged()
{ {
m_diskInfoList = m_diskInter->diskList(); m_diskInfoList = m_diskInter->diskList();
emit diskCountChanged(m_diskInfoList.count()); while (QLayoutItem *item = m_centeralLayout->takeAt(0))
{
delete item->widget();
delete item;
}
int mountedCount = 0;
for (auto info : m_diskInfoList) for (auto info : m_diskInfoList)
{ {
if (info.m_mountPoint.isEmpty())
continue;
else
++mountedCount;
DiskControlItem *item = new DiskControlItem(info, this); DiskControlItem *item = new DiskControlItem(info, this);
connect(item, &DiskControlItem::requestUnmount, this, &DiskControlWidget::unmountDisk);
m_centeralLayout->addWidget(item); m_centeralLayout->addWidget(item);
} }
const int contentHeight = m_diskInfoList.count() * 70; emit diskCountChanged(mountedCount);
const int contentHeight = mountedCount * 70;
const int maxHeight = std::min(contentHeight, MAX_HEIGHT); const int maxHeight = std::min(contentHeight, MAX_HEIGHT);
m_centeralWidget->setFixedHeight(contentHeight); m_centeralWidget->setFixedHeight(contentHeight);
setFixedHeight(maxHeight); setFixedHeight(maxHeight);
} }
void DiskControlWidget::unmountDisk(const QString &diskId) const
{
m_diskInter->Unmount(diskId);
}

View File

@ -18,6 +18,7 @@ signals:
private slots: private slots:
void diskListChanged(); void diskListChanged();
void unmountDisk(const QString &diskId) const;
private: private:
QVBoxLayout *m_centeralLayout; QVBoxLayout *m_centeralLayout;