From b5bade6d5213e250c1851b2521e2e3e840e50d03 Mon Sep 17 00:00:00 2001 From: Martin Kleusberg Date: Sun, 17 Mar 2013 02:54:07 +0100 Subject: [PATCH] Allow user to switch between text and hex editor Allow the user to change between the text editor and the hex editor. Allow the user to change between insert and overwrite mode in both editors. This makes it possible to enter any binary data into an empty cell. --- src/EditDialog.cpp | 22 +++++++++++++++++--- src/EditDialog.h | 1 + src/EditDialog.ui | 50 +++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 69 insertions(+), 4 deletions(-) diff --git a/src/EditDialog.cpp b/src/EditDialog.cpp index a45b53a2..91682458 100644 --- a/src/EditDialog.cpp +++ b/src/EditDialog.cpp @@ -1,6 +1,8 @@ #include "EditDialog.h" #include "ui_EditDialog.h" #include +#include +#include #include "sqlitedb.h" #include @@ -14,13 +16,15 @@ EditDialog::EditDialog(QWidget* parent) hexEdit = new QHexEdit(this); hexLayout->addWidget(hexEdit); + QShortcut* ins = new QShortcut(QKeySequence(Qt::Key_Insert), this); + connect(ins, SIGNAL(activated()), this, SLOT(toggleOverwriteMode())); + reset(); } EditDialog::~EditDialog() { delete ui; - delete hexEdit; } void EditDialog::reset() @@ -116,6 +120,7 @@ void EditDialog::editTextChanged() void EditDialog::checkDataType() { // Check if data is text only + ui->comboEditor->setVisible(true); if(QString(hexEdit->data()).toAscii() == hexEdit->data()) // Any proper way?? { ui->editorStack->setCurrentIndex(0); @@ -129,16 +134,27 @@ void EditDialog::checkDataType() { // It is. ui->editorImage->setPixmap(QPixmap::fromImage(img)); - ui->editorStack->setCurrentIndex(1); + ui->editorStack->setCurrentIndex(2); ui->labelType->setText(tr("Type of data currently in cell: Image")); ui->labelSize->setText(tr("%1x%2 pixel").arg(ui->editorImage->pixmap()->size().width()).arg(ui->editorImage->pixmap()->size().height())); + + ui->comboEditor->setVisible(false); } else { // It's not. So it's probably some random binary data. - ui->editorStack->setCurrentIndex(2); + ui->editorStack->setCurrentIndex(1); ui->labelType->setText(tr("Type of data currently in cell: Binary")); ui->labelSize->setText(tr("%n byte(s)", "", hexEdit->data().length())); } } } + +void EditDialog::toggleOverwriteMode() +{ + static bool currentMode = false; + currentMode = !currentMode; + + hexEdit->setOverwriteMode(currentMode); + ui->editorText->setOverwriteMode(currentMode); +} diff --git a/src/EditDialog.h b/src/EditDialog.h index f5369623..c74d23c5 100644 --- a/src/EditDialog.h +++ b/src/EditDialog.h @@ -34,6 +34,7 @@ private slots: virtual void accept(); virtual void editTextChanged(); virtual void checkDataType(); + virtual void toggleOverwriteMode(); signals: void goingAway(); diff --git a/src/EditDialog.ui b/src/EditDialog.ui index 27710947..ce50b9b1 100644 --- a/src/EditDialog.ui +++ b/src/EditDialog.ui @@ -55,6 +55,20 @@ + + + + + Text + + + + + Binary + + + + @@ -80,8 +94,8 @@ This area displays information about the data present in this database cell - + @@ -113,6 +127,7 @@ buttomImport buttonExport + comboEditor buttonClear buttonBox @@ -214,11 +229,44 @@ + + comboEditor + currentIndexChanged(int) + editorStack + setCurrentIndex(int) + + + 265 + 16 + + + 185 + 169 + + + + + editorStack + currentChanged(int) + comboEditor + setCurrentIndex(int) + + + 185 + 169 + + + 267 + 16 + + + importData() exportData() clearData() editTextChanged() + checkDataType()