mirror of
https://github.com/LongSoft/UEFITool.git
synced 2024-11-24 08:58:23 +08:00
Apply hex cleaning to search dialog paste operations
- Permits pasting to 'GUID' search directly from cpp representation - Provides hex cleaning (e.g. auto-remove 0x) in 'Hex pattern' search as well
This commit is contained in:
parent
71a7336730
commit
1d560bd0be
@ -32,7 +32,7 @@ SET(PROJECT_SOURCES
|
||||
uefitool.cpp
|
||||
searchdialog.cpp
|
||||
hexviewdialog.cpp
|
||||
guidlineedit.cpp
|
||||
hexlineedit.cpp
|
||||
ffsfinder.cpp
|
||||
hexspinbox.cpp
|
||||
qhexedit2/qhexedit.cpp
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* guidlineedit.cpp
|
||||
/* hexlineedit.cpp
|
||||
|
||||
Copyright (c) 2014, Nikolaj Schlej. All rights reserved.
|
||||
This program and the accompanying materials
|
||||
@ -11,25 +11,34 @@
|
||||
|
||||
*/
|
||||
|
||||
#include "guidlineedit.h"
|
||||
#include "hexlineedit.h"
|
||||
|
||||
GuidLineEdit::GuidLineEdit(QWidget * parent)
|
||||
#if QT_VERSION_MAJOR >= 6
|
||||
#include <QRegularExpression>
|
||||
#else
|
||||
#include <QRegExp>
|
||||
#endif
|
||||
|
||||
HexLineEdit::HexLineEdit(QWidget * parent)
|
||||
:QLineEdit(parent)
|
||||
{
|
||||
}
|
||||
|
||||
GuidLineEdit::GuidLineEdit(const QString & contents, QWidget * parent)
|
||||
HexLineEdit::HexLineEdit(const QString & contents, QWidget * parent)
|
||||
:QLineEdit(contents, parent)
|
||||
{
|
||||
}
|
||||
|
||||
GuidLineEdit::~GuidLineEdit()
|
||||
HexLineEdit::~HexLineEdit()
|
||||
{
|
||||
}
|
||||
|
||||
void GuidLineEdit::keyPressEvent(QKeyEvent * event)
|
||||
void HexLineEdit::keyPressEvent(QKeyEvent * event)
|
||||
{
|
||||
if (event == QKeySequence::Delete || event->key() == Qt::Key_Backspace)
|
||||
QClipboard *clipboard;
|
||||
QString originalText;
|
||||
|
||||
if (m_editAsGuid && (event == QKeySequence::Delete || event->key() == Qt::Key_Backspace))
|
||||
{
|
||||
int pos = cursorPosition();
|
||||
if (event->key() == Qt::Key_Backspace && pos > 0) {
|
||||
@ -57,6 +66,24 @@ void GuidLineEdit::keyPressEvent(QKeyEvent * event)
|
||||
return;
|
||||
}
|
||||
|
||||
if (event == QKeySequence::Paste)
|
||||
{
|
||||
clipboard = QApplication::clipboard();
|
||||
originalText = clipboard->text();
|
||||
QString cleanedHex = QString(originalText).replace(QString("0x"), QString(""), Qt::CaseInsensitive);
|
||||
#if QT_VERSION_MAJOR >= 6
|
||||
cleanedHex.remove(QRegularExpression("[^a-fA-F\\d]+"));
|
||||
#else
|
||||
cleanedHex.remove(QRegExp("[^a-fA-F\\d]+"));
|
||||
#endif
|
||||
clipboard->setText(cleanedHex);
|
||||
}
|
||||
|
||||
// Call original event handler
|
||||
QLineEdit::keyPressEvent(event);
|
||||
|
||||
if (event == QKeySequence::Paste)
|
||||
{
|
||||
clipboard->setText(originalText);
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
/* guidlineedit.h
|
||||
/* hexlineedit.h
|
||||
|
||||
Copyright (c) 2014, Nikolaj Schlej. All rights reserved.
|
||||
This program and the accompanying materials
|
||||
@ -11,9 +11,11 @@
|
||||
|
||||
*/
|
||||
|
||||
#ifndef GUIDLINEEDIT_H
|
||||
#define GUIDLINEEDIT_H
|
||||
#ifndef HEXLINEEDIT_H
|
||||
#define HEXLINEEDIT_H
|
||||
|
||||
#include <QApplication>
|
||||
#include <QClipboard>
|
||||
#include <QLineEdit>
|
||||
#include <QKeyEvent>
|
||||
#include <QKeySequence>
|
||||
@ -21,16 +23,29 @@
|
||||
|
||||
#include "../common/basetypes.h"
|
||||
|
||||
class GuidLineEdit : public QLineEdit
|
||||
class HexLineEdit : public QLineEdit
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(bool editAsGuid READ editAsGuid WRITE setEditAsGuid)
|
||||
|
||||
public:
|
||||
GuidLineEdit(QWidget * parent = 0);
|
||||
GuidLineEdit(const QString & contents, QWidget * parent = 0);
|
||||
~GuidLineEdit();
|
||||
HexLineEdit(QWidget * parent = 0);
|
||||
HexLineEdit(const QString & contents, QWidget * parent = 0);
|
||||
~HexLineEdit();
|
||||
|
||||
void setEditAsGuid(bool editAsGuid)
|
||||
{
|
||||
m_editAsGuid = editAsGuid;
|
||||
}
|
||||
bool editAsGuid() const
|
||||
{ return m_editAsGuid; }
|
||||
|
||||
private:
|
||||
bool m_editAsGuid;
|
||||
|
||||
protected:
|
||||
void keyPressEvent(QKeyEvent * event);
|
||||
|
||||
};
|
||||
|
||||
#endif // GUIDLINEEDIT_H
|
||||
#endif // HEXLINEEDIT_H
|
@ -35,7 +35,10 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="hexEdit">
|
||||
<widget class="HexLineEdit" name="hexEdit">
|
||||
<property name="editAsGuid">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="inputMask">
|
||||
<string/>
|
||||
</property>
|
||||
@ -89,7 +92,10 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="GuidLineEdit" name="guidEdit">
|
||||
<widget class="HexLineEdit" name="guidEdit">
|
||||
<property name="editAsGuid">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="inputMask">
|
||||
<string>xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx</string>
|
||||
</property>
|
||||
@ -241,9 +247,9 @@
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>GuidLineEdit</class>
|
||||
<class>HexLineEdit</class>
|
||||
<extends>QLineEdit</extends>
|
||||
<header>guidlineedit.h</header>
|
||||
<header>hexlineedit.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<tabstops>
|
||||
|
@ -15,7 +15,7 @@ HEADERS += uefitool.h \
|
||||
hexviewdialog.h \
|
||||
gotobasedialog.h \
|
||||
gotoaddressdialog.h \
|
||||
guidlineedit.h \
|
||||
hexlineedit.h \
|
||||
ffsfinder.h \
|
||||
hexspinbox.h \
|
||||
../common/fitparser.h \
|
||||
@ -69,7 +69,7 @@ SOURCES += uefitool_main.cpp \
|
||||
uefitool.cpp \
|
||||
searchdialog.cpp \
|
||||
hexviewdialog.cpp \
|
||||
guidlineedit.cpp \
|
||||
hexlineedit.cpp \
|
||||
ffsfinder.cpp \
|
||||
hexspinbox.cpp \
|
||||
../common/fitparser.cpp \
|
||||
|
Loading…
Reference in New Issue
Block a user