Merge branch 'develop' of gitee.com:cleverxiao/notepad-- into develop

This commit is contained in:
cleverxiao 2023-03-10 17:44:09 +08:00
commit 64c94e549b
2 changed files with 142 additions and 0 deletions

View File

@ -122,6 +122,134 @@ void ScintillaHexEditView::dropEvent(QDropEvent* e)
//qDebug() << ui.leftSrc->geometry() << ui.rightSrc->geometry() << QCursor::pos() << this->mapFromGlobal(QCursor::pos()); //qDebug() << ui.leftSrc->geometry() << ui.rightSrc->geometry() << QCursor::pos() << this->mapFromGlobal(QCursor::pos());
} }
void ScintillaHexEditView::mouseMoveEvent(QMouseEvent* e)
{
if (property("type").toInt() == HEX_TYPE && selecting)
{
long from, to;
int r1, c1, r2, c2;
int begin, end;
const int col_hex_start = 9;
const int col_hex_finish = 56;
const int col_text_start = 57;
const int col_text_finish = 72;
const int col_num = 75;
m_SelTo = Scintilla::Point::FromInts(e->x(), e->y());
from = execute(SCI_POSITIONFROMPOINT, m_SelFrom.x, m_SelFrom.y);
to = execute(SCI_POSITIONFROMPOINT, m_SelTo.x, m_SelTo.y);
lineIndexFromPosition(from, &r1, &c1);
lineIndexFromPosition(to, &r2, &c2);
execute(SCI_CLEARSELECTIONS);
if (r1 < 0 || c1 < 0 || r2 < 0 || c2 < 0)
return;
if (c1 < col_text_start || c1 > col_text_finish)
{
//选择二进制区域
for (int i = r1; i <= r2; ++i)
{
//每行hex显示区域
if (i == r1)
{
if (c1 < col_hex_start)
begin = col_hex_start;
else if (c1 > col_hex_finish)
begin = col_hex_finish;
else begin = c1 / 3 * 3;
}
else
begin = col_hex_start;
if (i == r2)
{
if (c2 < col_hex_start)
end = col_hex_start;
else if (c2 > col_hex_finish)
end = col_hex_finish;
else end = c2 / 3 * 3 + 2;
}
else
end = col_hex_finish;
for (int j = begin; j < end; j += 3)
{
execute(SCI_ADDSELECTION, i * col_num + j, i * col_num + j + 2);
execute(SCI_ADDSELECTION, i * col_num + col_text_start + (j - col_hex_start) / 3,
i * col_num + col_text_start + (j - col_hex_start) / 3 + 1);
}
}
}
else
{
//选择字符区域
for (int i = r1; i <= r2; ++i)
{
//每行字符显示区域
if (i == r1)
{
if (c1 < col_text_start)
begin = col_text_start;
else if (c1 > col_text_finish)
begin = col_text_finish;
else begin = c1;
}
else
begin = col_text_start;
if (i == r2)
{
if (c2 < col_text_start)
end = col_text_start;
else if (c2 > col_text_finish)
end = col_text_finish;
else end = c2;
}
else
end = col_text_finish;
for (int j = begin; j <= end; ++j)
{
execute(SCI_ADDSELECTION, i * col_num + col_hex_start + (j - col_text_start) * 3,
i * col_num + col_hex_start + (j - col_text_start) * 3 + 2);
execute(SCI_ADDSELECTION, i * col_num + j, i * col_num + j + 1);
}
}
}
return;
}
QsciScintillaBase::mouseMoveEvent(e);
}
void ScintillaHexEditView::mousePressEvent(QMouseEvent* e)
{
if (property("type").toInt() == HEX_TYPE && !selecting)
{
execute(SCI_CLEARSELECTIONS);
selecting = true;
m_SelFrom = Scintilla::Point::FromInts(e->x(), e->y());
return;
}
QsciScintillaBase::mousePressEvent(e);
}
void ScintillaHexEditView::mouseReleaseEvent(QMouseEvent* e)
{
if (property("type").toInt() == HEX_TYPE && selecting)
{
selecting = false;
return;
}
QsciScintillaBase::mouseReleaseEvent(e);
}
void ScintillaHexEditView::updateThemes() void ScintillaHexEditView::updateThemes()
{ {

View File

@ -2,6 +2,7 @@
#include <qsciscintilla.h> #include <qsciscintilla.h>
#include <Scintilla.h> #include <Scintilla.h>
#include <Platform.h>
#include <QDragEnterEvent> #include <QDragEnterEvent>
#include <QDropEvent> #include <QDropEvent>
@ -33,6 +34,14 @@ protected:
void dragEnterEvent(QDragEnterEvent * event); void dragEnterEvent(QDragEnterEvent * event);
void dropEvent(QDropEvent * e); void dropEvent(QDropEvent * e);
//! Re-implemented to handle mouse moves.
virtual void mouseMoveEvent(QMouseEvent* e);
//! Re-implemented to handle mouse presses.
virtual void mousePressEvent(QMouseEvent* e);
//! Re-implemented to handle mouse releases.
virtual void mouseReleaseEvent(QMouseEvent* e);
private: private:
static bool _SciInit; static bool _SciInit;
@ -41,4 +50,9 @@ private:
SCINTILLA_PTR m_pScintillaPtr = 0; SCINTILLA_PTR m_pScintillaPtr = 0;
CCNotePad* m_NoteWin; CCNotePad* m_NoteWin;
bool selecting = false;
Scintilla::Point m_SelFrom;
Scintilla::Point m_SelTo;
}; };