Improve cursor in read only mode.
Signed-off-by: Andrea Odetti <mariofutire@gmail.com>
This commit is contained in:
parent
17d75813a7
commit
520de12f58
1 changed files with 11 additions and 5 deletions
|
@ -6,7 +6,6 @@
|
||||||
|
|
||||||
#include "qhexedit.h"
|
#include "qhexedit.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
|
|
||||||
// ********************************************************************** Constructor, destructor
|
// ********************************************************************** Constructor, destructor
|
||||||
|
@ -44,7 +43,7 @@ QHexEdit::QHexEdit(QWidget *parent) : QAbstractScrollArea(parent)
|
||||||
connect(_undoStack, SIGNAL(indexChanged(int)), this, SLOT(dataChangedPrivate(int)));
|
connect(_undoStack, SIGNAL(indexChanged(int)), this, SLOT(dataChangedPrivate(int)));
|
||||||
|
|
||||||
_cursorTimer.setInterval(500);
|
_cursorTimer.setInterval(500);
|
||||||
_cursorTimer.start();
|
// the timer is started inside setReadOnly() if necessary
|
||||||
|
|
||||||
setAddressWidth(4);
|
setAddressWidth(4);
|
||||||
setAddressArea(true);
|
setAddressArea(true);
|
||||||
|
@ -286,6 +285,10 @@ bool QHexEdit::isReadOnly()
|
||||||
void QHexEdit::setReadOnly(bool readOnly)
|
void QHexEdit::setReadOnly(bool readOnly)
|
||||||
{
|
{
|
||||||
_readOnly = readOnly;
|
_readOnly = readOnly;
|
||||||
|
if (_readOnly)
|
||||||
|
_cursorTimer.stop();
|
||||||
|
else
|
||||||
|
_cursorTimer.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QHexEdit::setHexCaps(const bool isCaps)
|
void QHexEdit::setHexCaps(const bool isCaps)
|
||||||
|
@ -918,9 +921,7 @@ void QHexEdit::paintEvent(QPaintEvent *event)
|
||||||
if ((hexPositionInShowData >= 0) && (hexPositionInShowData < _hexDataShown.size()))
|
if ((hexPositionInShowData >= 0) && (hexPositionInShowData < _hexDataShown.size()))
|
||||||
{
|
{
|
||||||
// paint cursor
|
// paint cursor
|
||||||
if (_blink && !_readOnly && hasFocus())
|
if (_readOnly)
|
||||||
painter.fillRect(_cursorRect, this->palette().color(QPalette::WindowText));
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
// make the background stick out
|
// make the background stick out
|
||||||
QColor color = viewport()->palette().dark().color();
|
QColor color = viewport()->palette().dark().color();
|
||||||
|
@ -939,6 +940,11 @@ void QHexEdit::paintEvent(QPaintEvent *event)
|
||||||
painter.drawText(_pxCursorX - pxOfsX, _pxCursorY, _hexDataShown.mid(hexPositionInShowData, 1));
|
painter.drawText(_pxCursorX - pxOfsX, _pxCursorY, _hexDataShown.mid(hexPositionInShowData, 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (_blink && hasFocus())
|
||||||
|
painter.fillRect(_cursorRect, this->palette().color(QPalette::WindowText));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// emit event, if size has changed
|
// emit event, if size has changed
|
||||||
|
|
Loading…
Add table
Reference in a new issue