-
Notifications
You must be signed in to change notification settings - Fork 19
/
btsetupdialog.cpp
55 lines (44 loc) · 1.31 KB
/
btsetupdialog.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
#include "btsetupdialog.h"
#include "defines.h"
#include <QLabel>
#include <QCheckBox>
#include "btitem.h"
BtSetupDialog::BtSetupDialog(QWidget *parent) :
QDialog(parent)
{
setupUi(this);
connect(pbOK, &QPushButton::clicked,
this, &BtSetupDialog::applySettings);
}
void BtSetupDialog::addDevice(const QBluetoothDeviceInfo &device)
{
devList.append(device);
QWidget *itemWgt = new QWidget;
QLayout *layout = new QHBoxLayout;
layout->setMargin(0);
layout->setSpacing(0);
BtItem *btItem = new BtItem();
btItem->setBtName(device.name());
btItem->setBtAddress(device.address().toString());
layout->addWidget(btItem);
itemWgt->setLayout(layout);
QListWidgetItem *item = new QListWidgetItem(lwDevices);
item->setSizeHint(itemWgt->sizeHint());
lwDevices->setItemWidget(item, itemWgt);
}
void BtSetupDialog::saveSettings()
{
QSettings settings(ORGANIZATION_NAME, APPLICATION_NAME);
if (lwDevices->selectedItems().count()) {
QWidget *wgt = lwDevices->itemWidget(lwDevices->selectedItems().at(0));
if (wgt) {
BtItem *btItem = wgt->findChild<BtItem *>("BtItem");
settings.setValue(SETTINGS_BT_DEVICE, btItem->getBtAddress());
}
}
}
void BtSetupDialog::applySettings()
{
saveSettings();
hide();
}