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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
|
/***************************************************************************
* Copyright (C) 2005 Nicolas Hadacek <hadacek@kde.org> *
* Copyright (C) 2003-2004 Alain Gibaud <alain.gibaud@free.fr> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#include "pic_config_word_editor.h"
#include <qlabel.h>
#include <qlayout.h>
#include <qcombobox.h>
#include <klocale.h>
#include "common/common/misc.h"
#include "common/gui/misc_gui.h"
//----------------------------------------------------------------------------
Pic::ConfigWordComboBox::ConfigWordComboBox(QWidget *parent)
: ComboBox(parent)
{
setIgnoreWheelEvent(true);
}
uint Pic::ConfigWordComboBox::index() const
{
if ( isValid() ) return _map[currentItem()];
if ( currentItem()==0 ) return _invalidIndex;
return _map[currentItem()-1];
}
void Pic::ConfigWordComboBox::setItem(uint i)
{
if ( !isValid() ) removeItem(0);
for (uint l=0; l<_map.count(); l++)
if ( _map[l]==i ) setCurrentItem(l);
}
void Pic::ConfigWordComboBox::setInvalidItem(uint i, const QString &label)
{
if ( !isValid() ) changeItem(label, 0);
else insertItem(label, 0);
setCurrentItem(0);
_invalidIndex = i;
}
//----------------------------------------------------------------------------
Pic::ConfigWordDialog::ConfigWordDialog(const Memory &memory, uint ci, QWidget *parent)
: Dialog(parent, "config_word_dialog", true, i18n("Config Word Details"), Close, Close, false)
{
uint nbChars = memory.device().nbCharsWord(MemoryRangeType::Config);
const Config::Word &cword = memory.device().config()._words[ci];
QGridLayout *grid = new QGridLayout(mainWidget(), 0, 0, 10, 10);
uint row = 0;
QLabel *label = new QLabel(i18n("Name:"), mainWidget());
grid->addWidget(label, row, 0);
label = new QLabel(cword.name, mainWidget());
grid->addWidget(label, row, 1);
row++;
label = new QLabel(i18n("Index:"), mainWidget());
grid->addWidget(label, row, 0);
label = new QLabel(QString::number(ci), mainWidget());
grid->addWidget(label, row, 1);
row++;
label = new QLabel(i18n("Raw Value:"), mainWidget());
grid->addWidget(label, row, 0);
label = new QLabel(toHexLabel(memory.word(MemoryRangeType::Config, ci), nbChars), mainWidget());
grid->addWidget(label, row, 1);
row++;
label = new QLabel(i18n("Value:"), mainWidget());
grid->addWidget(label, row, 0);
label = new QLabel(toHexLabel(memory.normalizedWord(MemoryRangeType::Config, ci), nbChars), mainWidget());
grid->addWidget(label, row, 1);
row++;
label = new QLabel(i18n("Raw Blank Value:"), mainWidget());
grid->addWidget(label, row, 0);
label = new QLabel(toHexLabel(cword.bvalue, nbChars), mainWidget());
grid->addWidget(label, row, 1);
row++;
label = new QLabel(i18n("Used Mask:"), mainWidget());
grid->addWidget(label, row, 0);
label = new QLabel(toHexLabel(cword.usedMask(), nbChars), mainWidget());
grid->addWidget(label, row, 1);
row++;
label = new QLabel(i18n("Write Mask:"), mainWidget());
grid->addWidget(label, row, 0);
label = new QLabel(toHexLabel(cword.wmask, nbChars), mainWidget());
grid->addWidget(label, row, 1);
row++;
label = new QLabel(i18n("Protected Mask:"), mainWidget());
grid->addWidget(label, row, 0);
label = new QLabel(toHexLabel(cword.pmask, nbChars), mainWidget());
grid->addWidget(label, row, 1);
row++;
label = new QLabel(i18n("Checksum Mask:"), mainWidget());
grid->addWidget(label, row, 0);
label = new QLabel(toHexLabel(cword.cmask, nbChars), mainWidget());
grid->addWidget(label, row, 1);
row++;
}
//----------------------------------------------------------------------------
Pic::ConfigWordEditor::ConfigWordEditor(Memory &memory, uint ci, bool withWordEditor, QWidget *parent)
: MemoryEditor(MemoryRangeType::Config, memory, parent, "pic_config_word_editor"), _configIndex(ci)
{
if (withWordEditor) {
QHBoxLayout *hbox = new QHBoxLayout(_top);
_mdb = new MemoryRangeEditor(MemoryRangeType::Config, memory, 1, 1, ci, 1, this);
_mdb->init();
connect(_mdb, SIGNAL(modified()), SIGNAL(modified()));
connect(_mdb, SIGNAL(modified()), SLOT(updateDisplay()));
hbox->addWidget(_mdb);
KPushButton *button = new KPushButton(i18n("Details..."), this);
button->setFixedHeight(button->sizeHint().height());
connect(button, SIGNAL(clicked()), SLOT(showDialog()));
hbox->addWidget(button);
hbox->addStretch(1);
} else _mdb = 0;
QGridLayout *grid = new QGridLayout(_top);
grid->setColStretch(2, 1);
const Config::Word &cword = device().config()._words[ci];
_combos.resize(cword.masks.count());
uint nbChars = device().nbCharsWord(MemoryRangeType::Config);
for (uint k=0; k<_combos.count(); k++) {
const Config::Mask &cmask = cword.masks[k];
QLabel *label = new QLabel(Config::maskLabel(cmask.name) + ":", this);
grid->addWidget(label, k, 0);
label = new QLabel(cmask.name, this);
grid->addWidget(label, k, 1);
_combos[k] = new ConfigWordComboBox(this);
for (uint i=0; i<cmask.values.count(); i++) {
if ( !cmask.values[i].isValid() ) continue;
QString label = Config::valueLabel(cmask.name, cmask.values[i].name);
label += " (" + toHexLabel(cmask.values[i].value, nbChars) + ")";
_combos[k]->appendItem(label, i);
}
connect(_combos[k], SIGNAL(activated(int)), SLOT(slotModified()));
grid->addWidget(_combos[k], k, 2);
}
}
void Pic::ConfigWordEditor::setReadOnly(bool readOnly)
{
if (_mdb) _mdb->setReadOnly(readOnly);
const Config::Word &cword = device().config()._words[_configIndex];
for (uint k=0; k<_combos.count(); k++) {
const Config::Mask &cmask = cword.masks[k];
_combos[k]->setEnabled(!readOnly && !cmask.value.isOverlapping(cword.pmask) && cmask.values.count()!=1);
}
}
void Pic::ConfigWordEditor::slotModified()
{
BitValue v = memory().word(MemoryRangeType::Config, _configIndex);
//qDebug("BinWordEditor::slotModified %i: %s", _configIndex, toHex(v, 4).data());
for (uint k=0; k<_combos.count(); k++) {
const Config::Mask &cmask = device().config()._words[_configIndex].masks[k];
v = v.clearMaskBits(cmask.value);
v |= cmask.values[_combos[k]->index()].value; // set value
}
memory().setWord(MemoryRangeType::Config, _configIndex, v);
//qDebug(" now: %s", toHex(v, 4).data());
if (_mdb) _mdb->updateDisplay();
emit modified();
}
void Pic::ConfigWordEditor::updateDisplay()
{
BitValue v = memory().word(MemoryRangeType::Config, _configIndex);
uint nbChars = device().nbCharsWord(MemoryRangeType::Config);
//qDebug("BinWordEditor::updateDisplay %i: %s", _configIndex, toHex(v, 4).data());
for (uint k=0; k<_combos.count(); k++) {
const Config::Mask &cmask = device().config()._words[_configIndex].masks[k];
for (int i=cmask.values.count()-1; i>=0; i--) {
if ( cmask.values[i].value.isInside(v) ) {
if ( cmask.values[i].isValid() ) _combos[k]->setItem(i);
else {
QString label = i18n("<invalid>") + " (" + toHexLabel(cmask.values[i].value, nbChars) + ")";
_combos[k]->setInvalidItem(i, label);
}
break;
}
}
}
if (_mdb) _mdb->updateDisplay();
}
void Pic::ConfigWordEditor::showDialog()
{
ConfigWordDialog dialog(memory(), _configIndex, this);
dialog.exec();
}
|