2016-07-19 11:21:29 +08:00
|
|
|
#include "diskcontrolwidget.h"
|
2016-07-20 15:43:12 +08:00
|
|
|
#include "diskcontrolitem.h"
|
|
|
|
|
|
|
|
#define MAX_HEIGHT 300
|
|
|
|
#define WIDTH 300
|
2016-07-19 11:21:29 +08:00
|
|
|
|
|
|
|
DiskControlWidget::DiskControlWidget(QWidget *parent)
|
2016-07-19 15:08:16 +08:00
|
|
|
: QScrollArea(parent),
|
2016-07-19 11:21:29 +08:00
|
|
|
|
2016-07-20 15:43:12 +08:00
|
|
|
m_centeralLayout(new QVBoxLayout),
|
|
|
|
m_centeralWidget(new QWidget),
|
|
|
|
|
2016-07-19 11:21:29 +08:00
|
|
|
m_diskInter(new DBusDiskMount(this))
|
|
|
|
{
|
2016-07-20 15:43:12 +08:00
|
|
|
m_centeralWidget->setLayout(m_centeralLayout);
|
|
|
|
m_centeralWidget->setFixedWidth(WIDTH);
|
|
|
|
|
|
|
|
setWidget(m_centeralWidget);
|
|
|
|
setFixedWidth(WIDTH);
|
2016-07-19 15:08:16 +08:00
|
|
|
setFrameStyle(QFrame::NoFrame);
|
|
|
|
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
setStyleSheet("background-color:transparent;");
|
2016-07-19 11:21:29 +08:00
|
|
|
|
|
|
|
connect(m_diskInter, &DBusDiskMount::DiskListChanged, this, &DiskControlWidget::diskListChanged);
|
|
|
|
|
|
|
|
QMetaObject::invokeMethod(this, "diskListChanged", Qt::QueuedConnection);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DiskControlWidget::diskListChanged()
|
|
|
|
{
|
|
|
|
m_diskInfoList = m_diskInter->diskList();
|
|
|
|
|
|
|
|
emit diskCountChanged(m_diskInfoList.count());
|
2016-07-20 15:43:12 +08:00
|
|
|
|
|
|
|
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);
|
2016-07-19 11:21:29 +08:00
|
|
|
}
|