forked from QNnovation/ZBC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zbc_drivebuttonswidget.cpp
72 lines (61 loc) · 2.42 KB
/
zbc_drivebuttonswidget.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//#include <QDebug>
#include "zbc_drivebuttonswidget.h"
#include <QHBoxLayout>
#include <QPushButton>
#include <QSignalMapper>
#include <QStorageInfo>
#include <windows.h>
//C-tor
ZBC_DriveButtonsWidget::ZBC_DriveButtonsWidget(const QStringList& lstPath, QWidget* pwgt) : QFrame(pwgt)
{
QSignalMapper* psglMapper = new QSignalMapper(this);
QHBoxLayout* pLayout = new QHBoxLayout(this);
pLayout->setSpacing(0);
pLayout->setMargin(0);
for( QString sPath : lstPath ){
QPushButton* pBtn = new QPushButton(getIcon(sPath.utf16()), sPath, this);
pBtn->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
QStorageInfo* pStorInfo = new QStorageInfo(sPath);
pBtn->setToolTip(pStorInfo->displayName());
delete pStorInfo;
pBtn->setFocusPolicy(Qt::NoFocus);
pBtn->setFixedSize(pBtn->sizeHint());
connect(pBtn,
&QPushButton::clicked,
psglMapper,
static_cast<void (QSignalMapper::*)()>(&QSignalMapper::map));
psglMapper->setMapping(pBtn, sPath);
pLayout->addWidget(pBtn);
}
connect(psglMapper,
static_cast<void (QSignalMapper::*)(const QString&)>(&QSignalMapper::mapped),
this,
&ZBC_DriveButtonsWidget::clicked);
setFrameStyle(QFrame::Box | QFrame::Sunken);
setFixedHeight(minimumSizeHint().height());
setLayout(pLayout);
}
//Get type of volume and return QIcon
QIcon ZBC_DriveButtonsWidget::getIcon(const ushort* sDrive)
{
uint type = GetDriveType( reinterpret_cast<LPCWSTR>(sDrive) );
switch(type) {
case DRIVE_REMOVABLE:
return QIcon(":/buttons/drives/resource/usbdrive.ico");
case DRIVE_FIXED:
return QIcon(":/buttons/drives/resource/logicaldrive.ico");
case DRIVE_REMOTE:
return QIcon(":/buttons/drives/resource/networkdrive.ico");
case DRIVE_CDROM:
return QIcon(":/buttons/drives/resource/cddrive.ico");
case DRIVE_RAMDISK:
return QIcon(":/buttons/drives/resource/unknowndrive.ico");
case DRIVE_UNKNOWN:
return QIcon(":/buttons/drives/resource/unknowndrive.ico");
case DRIVE_NO_ROOT_DIR:
return QIcon(":/buttons/drives/resource/unknowndrive.ico");
default:
return QIcon(":/buttons/drives/resource/unknowndrive.ico");
}
return QIcon(":/buttons/drives/resource/unknowndrive.ico");
}