Commit f0300b9e authored by hjk's avatar hjk
Browse files

debugger: display cosmetics

parent 0216a001
......@@ -1356,50 +1356,53 @@ void WatchHandler::showEditValue(const WatchData &data)
delete w;
} else if (data.editformat == 1 || data.editformat == 3) {
// QImage
if (!w) {
w = new QLabel;
m_editHandlers[data.iname] = w;
QLabel *l = qobject_cast<QLabel *>(w);
if (!l) {
delete w;
l = new QLabel;
QString addr = tr("unknown address");
if (!data.addr.isEmpty())
addr = QString::fromLatin1(data.addr);
l->setWindowTitle(tr("%1 object at %2").arg(data.type, addr));
m_editHandlers[data.iname] = l;
}
if (QLabel *l = qobject_cast<QLabel *>(w)) {
int width, height, format;
QByteArray ba;
uchar *bits;
if (data.editformat == 1) {
ba = QByteArray::fromHex(data.editvalue);
const int *header = (int *)(ba.data());
swapEndian(ba.data(), ba.size());
bits = 12 + (uchar *)(ba.data());
width = header[0];
height = header[1];
format = header[2];
} else { // data.editformat == 3
QTextStream ts(data.editvalue);
QString fileName;
ts >> width >> height >> format >> fileName;
QFile f(fileName);
f.open(QIODevice::ReadOnly);
ba = f.readAll();
bits = (uchar*)ba.data();
}
QImage im(bits, width, height, QImage::Format(format));
l->setPixmap(QPixmap::fromImage(im));
l->resize(width, height);
l->show();
int width, height, format;
QByteArray ba;
uchar *bits;
if (data.editformat == 1) {
ba = QByteArray::fromHex(data.editvalue);
const int *header = (int *)(ba.data());
swapEndian(ba.data(), ba.size());
bits = 12 + (uchar *)(ba.data());
width = header[0];
height = header[1];
format = header[2];
} else { // data.editformat == 3
QTextStream ts(data.editvalue);
QString fileName;
ts >> width >> height >> format >> fileName;
QFile f(fileName);
f.open(QIODevice::ReadOnly);
ba = f.readAll();
bits = (uchar*)ba.data();
}
QImage im(bits, width, height, QImage::Format(format));
l->setPixmap(QPixmap::fromImage(im));
l->resize(width, height);
l->show();
} else if (data.editformat == 2) {
// QString
if (!w) {
w = new QTextEdit;
m_editHandlers[data.iname] = w;
QTextEdit *t = qobject_cast<QTextEdit *>(w);
if (!t) {
delete w;
t = new QTextEdit;
m_editHandlers[data.iname] = t;
}
QByteArray ba = QByteArray::fromHex(data.editvalue);
QString str = QString::fromUtf16((ushort *)ba.constData(), ba.size()/2);
if (QTextEdit *t = qobject_cast<QTextEdit *>(w)) {
t->setText(str);
t->resize(400, 200);
t->show();
}
t->setText(str);
t->resize(400, 200);
t->show();
} else if (data.editformat == 4) {
// Generic Process.
int pos = data.editvalue.indexOf('|');
......
......@@ -220,22 +220,13 @@ void WatchWindow::contextMenuEvent(QContextMenuEvent *ev)
individualFormat == -1 ? typeFormat : individualFormat;
QMenu typeFormatMenu;
QMenu individualFormatMenu;
QList<QAction *> typeFormatActions;
QList<QAction *> individualFormatActions;
QAction *clearIndividualFormatAction = 0;
if (idx.isValid()) {
typeFormatMenu.setTitle(
tr("Change Format for Type '%1'").arg(type));
individualFormatMenu.setTitle(
tr("Change Format for Object at %1").arg(addr));
if (alternativeFormats.isEmpty()) {
typeFormatMenu.setEnabled(false);
individualFormatMenu.setEnabled(false);
} else {
clearIndividualFormatAction = individualFormatMenu.addAction(tr("Clear"));
clearIndividualFormatAction->setEnabled(individualFormat != -1);
individualFormatMenu.addSeparator();
for (int i = 0; i != alternativeFormats.size(); ++i) {
const QString format = alternativeFormats.at(i);
QAction *act = new QAction(format, &typeFormatMenu);
......@@ -244,7 +235,28 @@ void WatchWindow::contextMenuEvent(QContextMenuEvent *ev)
act->setChecked(true);
typeFormatMenu.addAction(act);
typeFormatActions.append(act);
act = new QAction(format, &individualFormatMenu);
}
}
} else {
typeFormatMenu.setTitle(tr("Change Format for Type"));
typeFormatMenu.setEnabled(false);
}
QMenu individualFormatMenu;
QList<QAction *> individualFormatActions;
QAction *clearIndividualFormatAction = 0;
if (idx.isValid() && !addr.isEmpty()) {
individualFormatMenu.setTitle(
tr("Change Format for Object at %1").arg(addr));
if (alternativeFormats.isEmpty()) {
individualFormatMenu.setEnabled(false);
} else {
clearIndividualFormatAction = individualFormatMenu.addAction(tr("Clear"));
clearIndividualFormatAction->setEnabled(individualFormat != -1);
individualFormatMenu.addSeparator();
for (int i = 0; i != alternativeFormats.size(); ++i) {
const QString format = alternativeFormats.at(i);
QAction *act = new QAction(format, &individualFormatMenu);
act->setCheckable(true);
if (i == effectiveIndividualFormat)
act->setChecked(true);
......@@ -253,8 +265,6 @@ void WatchWindow::contextMenuEvent(QContextMenuEvent *ev)
}
}
} else {
typeFormatMenu.setTitle(tr("Change Format for Type"));
typeFormatMenu.setEnabled(false);
individualFormatMenu.setTitle(tr("Change Format for Object"));
individualFormatMenu.setEnabled(false);
}
......@@ -344,10 +354,12 @@ void WatchWindow::contextMenuEvent(QContextMenuEvent *ev)
} else if (clearIndividualFormatAction && act == clearIndividualFormatAction) {
model()->setData(mi1, -1, IndividualFormatRole);
} else {
for (int i = 0; i != alternativeFormats.size(); ++i) {
for (int i = 0; i != typeFormatActions.size(); ++i) {
if (act == typeFormatActions.at(i))
model()->setData(mi1, i, TypeFormatRole);
else if (act == individualFormatActions.at(i))
}
for (int i = 0; i != individualFormatActions.size(); ++i) {
if (act == individualFormatActions.at(i))
model()->setData(mi1, i, IndividualFormatRole);
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment