mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-19 18:40:13 -06:00
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:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ private slots:
|
||||
virtual void accept();
|
||||
virtual void editTextChanged();
|
||||
virtual void checkDataType();
|
||||
virtual void toggleOverwriteMode();
|
||||
|
||||
signals:
|
||||
void goingAway();
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user