- #include "hex.h"
- #include "ui_hex.h"
- #include "qdebug.h"
- Hex::Hex(QWidget *parent) :
- QMainWindow(parent),
- ui(new Ui::Hex)
- {
- ui->setupUi(this);
- }
- Hex::~Hex()
- {
- delete ui;
- }
- void Hex::on_textEdit_textChanged()
- {
- ui->textEdit->disconnect();
- QString str =ui->textEdit->toPlainText();
- int tem_position=ui->textEdit->textCursor().position();
- qDebug()<<"001,length:"<<str.length();
- qDebug()<<"002,size:"<<str.size();
- qDebug()<<"003:"<<str;
- if(str.length()>0)
- qDebug()<<"004:"<<str.at(str.length()-1);
- qDebug()<<"--------------------------------";
- str=str.toUpper();
- for( int i=0;i<str.length();i++)
- {
- if(((i+1)%3)==0)
- {
- if(!(str.at(i)==' '))
- {
- str.insert(i,' ');
- ui->textEdit->setText(str);
- for (int j=0;j<=tem_position;j++)
- {
- ui->textEdit->moveCursor(QTextCursor::NextCharacter,QTextCursor::MoveAnchor);
- }
- }
- }
- else
- {
- if((str[i]>='0')&&(str[i]<='9'))
- {
- }
- else if ((str[i]>='A')&&(str[i]<='F'))
- {
- }
- else
- {
- str=str.remove(i,1);
- i--;
- }
- ui->textEdit->setText(str);
- for (int j=0;j<=tem_position;j++)
- {
- ui->textEdit->moveCursor(QTextCursor::NextCharacter,QTextCursor::MoveAnchor);
- }
- }
- }
- qDebug()<<"005:"<<str;
- connect(ui->textEdit,SIGNAL(textChanged()),this,SLOT(on_textEdit_textChanged()));
- }
|