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.
This commit is contained in:
Martin Kleusberg
2013-03-17 02:54:07 +01:00
parent 15f685a1eb
commit b5bade6d52
3 changed files with 69 additions and 4 deletions

View File

@@ -1,6 +1,8 @@
#include "EditDialog.h"
#include "ui_EditDialog.h"
#include <QFileDialog>
#include <QKeySequence>
#include <QShortcut>
#include "sqlitedb.h"
#include <src/qhexedit.h>
@@ -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);
}

View File

@@ -34,6 +34,7 @@ private slots:
virtual void accept();
virtual void editTextChanged();
virtual void checkDataType();
virtual void toggleOverwriteMode();
signals:
void goingAway();

View File

@@ -55,6 +55,20 @@
</property>
</spacer>
</item>
<item>
<widget class="QComboBox" name="comboEditor">
<item>
<property name="text">
<string>Text</string>
</property>
</item>
<item>
<property name="text">
<string>Binary</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QPushButton" name="buttonClear">
<property name="toolTip">
@@ -80,8 +94,8 @@
<string>This area displays information about the data present in this database cell</string>
</property>
</widget>
<widget class="QLabel" name="editorImage"/>
<widget class="QWidget" name="editorBinary"/>
<widget class="QLabel" name="editorImage"/>
</widget>
</item>
<item>
@@ -113,6 +127,7 @@
<tabstops>
<tabstop>buttomImport</tabstop>
<tabstop>buttonExport</tabstop>
<tabstop>comboEditor</tabstop>
<tabstop>buttonClear</tabstop>
<tabstop>buttonBox</tabstop>
</tabstops>
@@ -214,11 +229,44 @@
</hint>
</hints>
</connection>
<connection>
<sender>comboEditor</sender>
<signal>currentIndexChanged(int)</signal>
<receiver>editorStack</receiver>
<slot>setCurrentIndex(int)</slot>
<hints>
<hint type="sourcelabel">
<x>265</x>
<y>16</y>
</hint>
<hint type="destinationlabel">
<x>185</x>
<y>169</y>
</hint>
</hints>
</connection>
<connection>
<sender>editorStack</sender>
<signal>currentChanged(int)</signal>
<receiver>comboEditor</receiver>
<slot>setCurrentIndex(int)</slot>
<hints>
<hint type="sourcelabel">
<x>185</x>
<y>169</y>
</hint>
<hint type="destinationlabel">
<x>267</x>
<y>16</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>importData()</slot>
<slot>exportData()</slot>
<slot>clearData()</slot>
<slot>editTextChanged()</slot>
<slot>checkDataType()</slot>
</slots>
</ui>