1
0
Fork 0

GUI: removed XBytesLineEdit

This commit is contained in:
Mr. eXoDia 2014-07-05 03:00:08 +02:00
parent 78e90c5ad1
commit d43579ef14
2 changed files with 0 additions and 121 deletions

View File

@ -1,90 +0,0 @@
#include "XBytesLineEdit.h"
#include <QClipboard>
#include <QApplication>
#include <QDebug>
#include <QKeyEvent>
XBytesLineEdit::XBytesLineEdit(QWidget *parent) : QLineEdit(parent)
{
connect(this,SIGNAL(textChanged(QString)),this,SLOT(autoMask(QString)));
connect(this,SIGNAL(selectionChanged()),this,SLOT(modSelection()));
mParts = 1;
setInputMask("HH");
setContextMenuPolicy(Qt::NoContextMenu);
}
void XBytesLineEdit::autoMask(QString content)
{
int len = content.replace(' ',"").length();
int remainder = len%2;
int parts = (len-remainder)/2;
if(parts != mParts)
{
QString m("HH ");
int backupPosition = cursorPosition();
setInputMask(m.repeated(parts+1));
mParts = parts;
setCursorPosition(backupPosition);
}
}
void XBytesLineEdit::paste()
{
QString rawClipboardText = QApplication::clipboard()->text().replace(' ',"").toUpper();
int currentCursorPosition = cursorPosition();
QString textBeforeCursor = QLineEdit::text().mid( 0, currentCursorPosition);
QString textAfterCursor = QLineEdit::text().mid( currentCursorPosition, text().length()-currentCursorPosition);
autoMask(QString("%1%2%3").arg(textBeforeCursor).arg(rawClipboardText).arg(textAfterCursor));
setText(QString("%1%2%3").arg(textBeforeCursor).arg(rawClipboardText).arg(textAfterCursor));
}
void XBytesLineEdit::copy()
{
// copy whole content
QApplication::clipboard()->setText(text());
//QApplication::clipboard()->setText(selectedText().replace(' ',"").toUpper());
}
void XBytesLineEdit::cut()
{
// prevent cutting
}
QString XBytesLineEdit::text()
{
return QLineEdit::text().replace(' ',"").toUpper();
}
void XBytesLineEdit::keyPressEvent(QKeyEvent *event)
{
if(event->matches(QKeySequence::Paste))
{
paste();
}
else if(event->matches(QKeySequence::Copy))
{
copy();
}
else if(event->matches(QKeySequence::Cut))
{
//prevent cutting
}
else
{
return QLineEdit::keyPressEvent(event);
}
}
void XBytesLineEdit::modSelection()
{
// prevent Selection
deselect();
}

View File

@ -1,31 +0,0 @@
#ifndef XBYTESLINEEDIT_H
#define XBYTESLINEEDIT_H
#include <QLineEdit>
// non-fixed bytesedit (QLineEdit with auto-grow InputMask)
class XBytesLineEdit : public QLineEdit
{
Q_OBJECT
public:
explicit XBytesLineEdit(QWidget *parent = 0);
void copy();
void cut();
QString text();
signals:
public slots:
void paste();
void keyPressEvent(QKeyEvent *event);
protected:
protected slots:
void autoMask(QString content);
void modSelection();
private:
int mParts;
};
#endif // XBYTEEDIT_H