add disk item

Change-Id: Ia59042410c24e1e33469fa4db919884ec976965b
This commit is contained in:
石博文 2016-07-20 15:43:12 +08:00 committed by Hualet Wang
parent bc136137a0
commit 7042c3560f
9 changed files with 161 additions and 4 deletions

View File

@ -4,7 +4,7 @@ include(../../interfaces/interfaces.pri)
QT += widgets svg dbus
TEMPLATE = lib
CONFIG += plugin c++11 link_pkgconfig
PKGCONFIG +=
PKGCONFIG += dtkwidget dtkbase
TARGET = $$qtLibraryTarget(disk-mount)
DESTDIR = $$_PRO_FILE_PWD_/../
@ -16,7 +16,8 @@ HEADERS += \
dbus/variant/diskinfo.h \
diskcontrolwidget.h \
diskpluginitem.h \
imageutil.h
imageutil.h \
diskcontrolitem.h
SOURCES += \
diskmountplugin.cpp \
@ -24,7 +25,8 @@ SOURCES += \
dbus/variant/diskinfo.cpp \
diskcontrolwidget.cpp \
diskpluginitem.cpp \
imageutil.cpp
imageutil.cpp \
diskcontrolitem.cpp
target.path = $${PREFIX}/lib/dde-dock/plugins/
INSTALLS += target

View File

@ -0,0 +1,93 @@
#include "diskcontrolitem.h"
#include <QVBoxLayout>
#include <QIcon>
DWIDGET_USE_NAMESPACE
DiskControlItem::DiskControlItem(const DiskInfo &info, QWidget *parent)
: QWidget(parent),
m_diskIcon(new QLabel),
m_diskName(new QLabel),
m_diskCapacity(new QLabel),
m_capacityValueBar(new QProgressBar),
m_unmountButton(new DImageButton)
{
QIcon::setThemeName("deepin");
m_diskName->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
m_diskName->setStyleSheet("color:white;");
m_diskCapacity->setStyleSheet("color:white;");
m_capacityValueBar->setTextVisible(false);
m_capacityValueBar->setFixedHeight(3);
m_capacityValueBar->setStyleSheet("QProgressBar {"
"border:none;"
"background-color:rgba(255, 255, 255, .3);"
"}"
"QProgressBar::chunk {"
"background-color:blue;"
"}");
m_unmountButton->setNormalPic(":/icons/resources/unmount-normal.png");
m_unmountButton->setHoverPic(":/icons/resources/unmount-hover.png");
m_unmountButton->setPressPic(":/icons/resources/unmount-press.png");
QVBoxLayout *infoLayout = new QVBoxLayout;
infoLayout->addWidget(m_diskName);
infoLayout->addWidget(m_diskCapacity);
infoLayout->setSpacing(0);
infoLayout->setMargin(0);
QHBoxLayout *unmountLayout = new QHBoxLayout;
unmountLayout->addLayout(infoLayout);
unmountLayout->addWidget(m_unmountButton);
unmountLayout->setSpacing(0);
unmountLayout->setMargin(0);
QVBoxLayout *progressLayout = new QVBoxLayout;
progressLayout->addLayout(unmountLayout);
progressLayout->addWidget(m_capacityValueBar);
progressLayout->setSpacing(0);
progressLayout->setMargin(0);
QHBoxLayout *centeralLayout = new QHBoxLayout;
centeralLayout->addWidget(m_diskIcon);
centeralLayout->addLayout(progressLayout);
centeralLayout->setSpacing(0);
centeralLayout->setMargin(0);
setLayout(centeralLayout);
updateInfo(info);
}
void DiskControlItem::updateInfo(const DiskInfo &info)
{
m_info = info;
m_diskIcon->setPixmap(QIcon::fromTheme(info.m_icon).pixmap(32, 32));
m_diskName->setText(info.m_name);
m_diskCapacity->setText(QString("%1/%2").arg(formatDiskSize(info.m_usedSize)).arg(formatDiskSize(info.m_totalSize)));
m_capacityValueBar->setMinimum(0);
m_capacityValueBar->setMaximum(info.m_totalSize);
m_capacityValueBar->setValue(info.m_usedSize);
}
const QString DiskControlItem::formatDiskSize(const quint64 size) const
{
const quint64 mSize = 1000;
const quint64 gSize = mSize * 1000;
const quint64 tSize = gSize * 1000;
if (size >= tSize)
return QString::number(double(size) / tSize, 'f', 2) + 'T';
else if (size >= gSize)
return QString::number(double(size) / gSize, 'f', 2) + "G";
else if (size >= mSize)
return QString::number(double(size) / mSize, 'f', 1) + "M";
else
return QString::number(size) + "K";
}

View File

@ -0,0 +1,33 @@
#ifndef DISKCONTROLITEM_H
#define DISKCONTROLITEM_H
#include "dbus/dbusdiskmount.h"
#include <dimagebutton.h>
#include <QWidget>
#include <QLabel>
#include <QProgressBar>
class DiskControlItem : public QWidget
{
Q_OBJECT
public:
explicit DiskControlItem(const DiskInfo &info, QWidget *parent = 0);
private slots:
void updateInfo(const DiskInfo &info);
const QString formatDiskSize(const quint64 size) const;
private:
DiskInfo m_info;
QLabel *m_diskIcon;
QLabel *m_diskName;
QLabel *m_diskCapacity;
QProgressBar *m_capacityValueBar;
Dtk::Widget::DImageButton *m_unmountButton;
};
#endif // DISKCONTROLITEM_H

View File

@ -1,11 +1,22 @@
#include "diskcontrolwidget.h"
#include "diskcontrolitem.h"
#define MAX_HEIGHT 300
#define WIDTH 300
DiskControlWidget::DiskControlWidget(QWidget *parent)
: QScrollArea(parent),
m_centeralLayout(new QVBoxLayout),
m_centeralWidget(new QWidget),
m_diskInter(new DBusDiskMount(this))
{
setFixedWidth(300);
m_centeralWidget->setLayout(m_centeralLayout);
m_centeralWidget->setFixedWidth(WIDTH);
setWidget(m_centeralWidget);
setFixedWidth(WIDTH);
setFrameStyle(QFrame::NoFrame);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
@ -21,4 +32,16 @@ void DiskControlWidget::diskListChanged()
m_diskInfoList = m_diskInter->diskList();
emit diskCountChanged(m_diskInfoList.count());
for (auto info : m_diskInfoList)
{
DiskControlItem *item = new DiskControlItem(info, this);
m_centeralLayout->addWidget(item);
}
const int contentHeight = m_diskInfoList.count() * 70;
const int maxHeight = std::min(contentHeight, MAX_HEIGHT);
m_centeralWidget->setFixedHeight(contentHeight);
setFixedHeight(maxHeight);
}

View File

@ -4,6 +4,7 @@
#include "dbus/dbusdiskmount.h"
#include <QScrollArea>
#include <QVBoxLayout>
class DiskControlWidget : public QScrollArea
{
@ -19,6 +20,8 @@ private slots:
void diskListChanged();
private:
QVBoxLayout *m_centeralLayout;
QWidget *m_centeralWidget;
DBusDiskMount *m_diskInter;
DiskInfoList m_diskInfoList;

View File

@ -2,5 +2,8 @@
<qresource prefix="/icons">
<file>resources/icon-small.svg</file>
<file>resources/icon.svg</file>
<file>resources/unmount-press.png</file>
<file>resources/unmount-normal.png</file>
<file>resources/unmount-hover.png</file>
</qresource>
</RCC>

Binary file not shown.

After

Width:  |  Height:  |  Size: 449 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 497 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 493 B