-
Notifications
You must be signed in to change notification settings - Fork 42
/
SimplePIgroupBox.cpp
84 lines (69 loc) · 2.13 KB
/
SimplePIgroupBox.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
73
74
75
76
77
78
79
80
81
82
83
84
#include <QHBoxLayout>
#include <QLabel>
#include "LockBox.h"
#include "SimplePIgroupBox.h"
#include "common.h"
SimplePIgroupBox::SimplePIgroupBox(LockBox *parent, unsigned int configOffset, QString GroupBoxName, int labelSize, int widgetSize) :
QWidget(0),
parent(parent),
GroupBoxName(GroupBoxName),
configOffset(configOffset),
SETTING_WIDGETS_FROM_CONFIG(false)
{
mainGroupBox = new QGroupBox(GroupBoxName);
{
QVBoxLayout *layout = new QVBoxLayout(this);
layout->addWidget(mainGroupBox);
}
mainLayout = new QVBoxLayout();
mainGroupBox->setLayout(mainLayout);
// Input name
{
QHBoxLayout *hLayout = new QHBoxLayout();
NameLabel = new QLabel(tr("Name:"));
NameLineEdit = new QLineEdit();
NameLabel->setMinimumSize(labelSize, 0);
NameLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
NameLineEdit->setMaxLength(16);
NameLineEdit->setMinimumSize(widgetSize, 0);
NameLineEdit->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
hLayout->addWidget(NameLabel);
hLayout->addWidget(NameLineEdit);
mainLayout->addLayout(hLayout);
}
// Hook up on_NameChanged
QObject::connect(NameLineEdit, SIGNAL(returnPressed()), this, SLOT(on_NameChanged()));
setNameEditable(false);
}
void SimplePIgroupBox::setNameEditable(bool editable)
{
NameLabel->setVisible(editable);
NameLineEdit->setVisible(editable);
}
void SimplePIgroupBox::on_NameChanged()
{
QString name = NameLineEdit->text();
mainGroupBox->setTitle(GroupBoxName + " - " + name);
name = name.leftJustified(16, ' ');
QByteArray nameAscii = name.toLatin1();
for (int i = 0; i < 8; i++)
{
parent->set_config(configOffset + i, (nameAscii[2*i+1] << 8) | nameAscii[2*i]);
}
}
void SimplePIgroupBox::set_widgets_from_config()
{
SETTING_WIDGETS_FROM_CONFIG = true;
// Name
QByteArray nameAscii;
nameAscii.resize(16);
for (int i = 0; i < 8; i++)
{
nameAscii[2*i] = parent->config(configOffset + i) & 0x00FF;
nameAscii[2*i+1] = (parent->config(configOffset + i) & 0xFF00) >> 8;
}
QString name = QString::fromLatin1(nameAscii, 16);
NameLineEdit->setText(name);
mainGroupBox->setTitle(GroupBoxName + " - " + name);
SETTING_WIDGETS_FROM_CONFIG = false;
}