mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-03 00:15:21 +00:00
add disk item
Change-Id: Ia59042410c24e1e33469fa4db919884ec976965b
This commit is contained in:
parent
bc136137a0
commit
7042c3560f
@ -4,7 +4,7 @@ include(../../interfaces/interfaces.pri)
|
|||||||
QT += widgets svg dbus
|
QT += widgets svg dbus
|
||||||
TEMPLATE = lib
|
TEMPLATE = lib
|
||||||
CONFIG += plugin c++11 link_pkgconfig
|
CONFIG += plugin c++11 link_pkgconfig
|
||||||
PKGCONFIG +=
|
PKGCONFIG += dtkwidget dtkbase
|
||||||
|
|
||||||
TARGET = $$qtLibraryTarget(disk-mount)
|
TARGET = $$qtLibraryTarget(disk-mount)
|
||||||
DESTDIR = $$_PRO_FILE_PWD_/../
|
DESTDIR = $$_PRO_FILE_PWD_/../
|
||||||
@ -16,7 +16,8 @@ HEADERS += \
|
|||||||
dbus/variant/diskinfo.h \
|
dbus/variant/diskinfo.h \
|
||||||
diskcontrolwidget.h \
|
diskcontrolwidget.h \
|
||||||
diskpluginitem.h \
|
diskpluginitem.h \
|
||||||
imageutil.h
|
imageutil.h \
|
||||||
|
diskcontrolitem.h
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
diskmountplugin.cpp \
|
diskmountplugin.cpp \
|
||||||
@ -24,7 +25,8 @@ SOURCES += \
|
|||||||
dbus/variant/diskinfo.cpp \
|
dbus/variant/diskinfo.cpp \
|
||||||
diskcontrolwidget.cpp \
|
diskcontrolwidget.cpp \
|
||||||
diskpluginitem.cpp \
|
diskpluginitem.cpp \
|
||||||
imageutil.cpp
|
imageutil.cpp \
|
||||||
|
diskcontrolitem.cpp
|
||||||
|
|
||||||
target.path = $${PREFIX}/lib/dde-dock/plugins/
|
target.path = $${PREFIX}/lib/dde-dock/plugins/
|
||||||
INSTALLS += target
|
INSTALLS += target
|
||||||
|
93
plugins/disk-mount/diskcontrolitem.cpp
Normal file
93
plugins/disk-mount/diskcontrolitem.cpp
Normal 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";
|
||||||
|
}
|
33
plugins/disk-mount/diskcontrolitem.h
Normal file
33
plugins/disk-mount/diskcontrolitem.h
Normal 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
|
@ -1,11 +1,22 @@
|
|||||||
#include "diskcontrolwidget.h"
|
#include "diskcontrolwidget.h"
|
||||||
|
#include "diskcontrolitem.h"
|
||||||
|
|
||||||
|
#define MAX_HEIGHT 300
|
||||||
|
#define WIDTH 300
|
||||||
|
|
||||||
DiskControlWidget::DiskControlWidget(QWidget *parent)
|
DiskControlWidget::DiskControlWidget(QWidget *parent)
|
||||||
: QScrollArea(parent),
|
: QScrollArea(parent),
|
||||||
|
|
||||||
|
m_centeralLayout(new QVBoxLayout),
|
||||||
|
m_centeralWidget(new QWidget),
|
||||||
|
|
||||||
m_diskInter(new DBusDiskMount(this))
|
m_diskInter(new DBusDiskMount(this))
|
||||||
{
|
{
|
||||||
setFixedWidth(300);
|
m_centeralWidget->setLayout(m_centeralLayout);
|
||||||
|
m_centeralWidget->setFixedWidth(WIDTH);
|
||||||
|
|
||||||
|
setWidget(m_centeralWidget);
|
||||||
|
setFixedWidth(WIDTH);
|
||||||
setFrameStyle(QFrame::NoFrame);
|
setFrameStyle(QFrame::NoFrame);
|
||||||
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||||
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||||
@ -21,4 +32,16 @@ void DiskControlWidget::diskListChanged()
|
|||||||
m_diskInfoList = m_diskInter->diskList();
|
m_diskInfoList = m_diskInter->diskList();
|
||||||
|
|
||||||
emit diskCountChanged(m_diskInfoList.count());
|
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);
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include "dbus/dbusdiskmount.h"
|
#include "dbus/dbusdiskmount.h"
|
||||||
|
|
||||||
#include <QScrollArea>
|
#include <QScrollArea>
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
class DiskControlWidget : public QScrollArea
|
class DiskControlWidget : public QScrollArea
|
||||||
{
|
{
|
||||||
@ -19,6 +20,8 @@ private slots:
|
|||||||
void diskListChanged();
|
void diskListChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
QVBoxLayout *m_centeralLayout;
|
||||||
|
QWidget *m_centeralWidget;
|
||||||
DBusDiskMount *m_diskInter;
|
DBusDiskMount *m_diskInter;
|
||||||
|
|
||||||
DiskInfoList m_diskInfoList;
|
DiskInfoList m_diskInfoList;
|
||||||
|
@ -2,5 +2,8 @@
|
|||||||
<qresource prefix="/icons">
|
<qresource prefix="/icons">
|
||||||
<file>resources/icon-small.svg</file>
|
<file>resources/icon-small.svg</file>
|
||||||
<file>resources/icon.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>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
BIN
plugins/disk-mount/resources/unmount-hover.png
Normal file
BIN
plugins/disk-mount/resources/unmount-hover.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 449 B |
BIN
plugins/disk-mount/resources/unmount-normal.png
Normal file
BIN
plugins/disk-mount/resources/unmount-normal.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 497 B |
BIN
plugins/disk-mount/resources/unmount-press.png
Normal file
BIN
plugins/disk-mount/resources/unmount-press.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 493 B |
Loading…
x
Reference in New Issue
Block a user