diff --git a/UEFITool/CMakeLists.txt b/UEFITool/CMakeLists.txt index 54bbeed..2ee226d 100644 --- a/UEFITool/CMakeLists.txt +++ b/UEFITool/CMakeLists.txt @@ -32,7 +32,7 @@ SET(PROJECT_SOURCES uefitool.cpp searchdialog.cpp hexviewdialog.cpp - guidlineedit.cpp + hexlineedit.cpp ffsfinder.cpp hexspinbox.cpp qhexedit2/qhexedit.cpp diff --git a/UEFITool/guidlineedit.cpp b/UEFITool/hexlineedit.cpp similarity index 56% rename from UEFITool/guidlineedit.cpp rename to UEFITool/hexlineedit.cpp index 68818ac..8e73c84 100644 --- a/UEFITool/guidlineedit.cpp +++ b/UEFITool/hexlineedit.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 +#else +#include +#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) { @@ -56,7 +65,25 @@ 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); + } } diff --git a/UEFITool/guidlineedit.h b/UEFITool/hexlineedit.h similarity index 54% rename from UEFITool/guidlineedit.h rename to UEFITool/hexlineedit.h index e9a4bc4..d1dc672 100644 --- a/UEFITool/guidlineedit.h +++ b/UEFITool/hexlineedit.h @@ -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 +#include #include #include #include @@ -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 diff --git a/UEFITool/searchdialog.ui b/UEFITool/searchdialog.ui index 510a46f..5f321d0 100644 --- a/UEFITool/searchdialog.ui +++ b/UEFITool/searchdialog.ui @@ -35,7 +35,10 @@ - + + + false + @@ -89,7 +92,10 @@ - + + + true + xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx @@ -241,9 +247,9 @@ - GuidLineEdit + HexLineEdit QLineEdit -
guidlineedit.h
+
hexlineedit.h
diff --git a/UEFITool/uefitool.pro b/UEFITool/uefitool.pro index 023c563..c8e9fdb 100644 --- a/UEFITool/uefitool.pro +++ b/UEFITool/uefitool.pro @@ -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 \