@@ -323,7 +323,9 @@ void QHexView::keyPressEvent(QKeyEvent *e) {
323323}
324324
325325QPoint QHexView::absolutePosition (const QPoint &pos) const {
326- QPoint shift (horizontalScrollBar ()->value (), 0 );
326+ auto margins = viewport ()->contentsMargins ();
327+ QPoint shift (horizontalScrollBar ()->value () - margins.left (),
328+ -margins.top () * m_renderer->lineHeight ());
327329 return pos + shift;
328330}
329331
@@ -567,23 +569,34 @@ QColor QHexView::selBackgroundColor() const {
567569 return m_renderer->selBackgroundColor ();
568570}
569571
572+ QColor QHexView::borderColor () const { return m_renderer->borderColor (); }
573+
570574void QHexView::setSelBackgroundColor (const QColor &newSelBackgroundColor) {
571575 m_renderer->setSelBackgroundColor (newSelBackgroundColor);
572576 Q_EMIT selBackgroundColorChanged ();
577+ this ->viewport ()->update ();
578+ }
579+
580+ void QHexView::setBorderColor (const QColor &newBorderColor) {
581+ m_renderer->setBorderColor (newBorderColor);
582+ Q_EMIT borderColorChanged ();
583+ this ->viewport ()->update ();
573584}
574585
575586void QHexView::setFontSize (qreal size) {
576587 Q_ASSERT (size > 0 );
577588 auto font = this ->font ();
578589 font.setPointSizeF (size * m_scaleRate);
579590 this ->setFont (font);
591+ this ->viewport ()->update ();
580592}
581593
582594QColor QHexView::selectionColor () const { return m_renderer->selectionColor (); }
583595
584596void QHexView::setSelectionColor (const QColor &newSelectionColor) {
585597 m_renderer->setSelectionColor (newSelectionColor);
586598 Q_EMIT selectionColorChanged ();
599+ this ->viewport ()->update ();
587600}
588601
589602QColor QHexView::bytesAlterBackground () const {
@@ -593,13 +606,15 @@ QColor QHexView::bytesAlterBackground() const {
593606void QHexView::setBytesAlterBackground (const QColor &newBytesAlterBackground) {
594607 m_renderer->setBytesAlterBackground (newBytesAlterBackground);
595608 Q_EMIT bytesAlterBackgroundChanged ();
609+ this ->viewport ()->update ();
596610}
597611
598612QColor QHexView::bytesColor () const { return m_renderer->bytesColor (); }
599613
600614void QHexView::setBytesColor (const QColor &newBytesColor) {
601615 m_renderer->setBytesColor (newBytesColor);
602616 Q_EMIT bytesColorChanged ();
617+ this ->viewport ()->update ();
603618}
604619
605620QColor QHexView::bytesBackground () const {
@@ -609,20 +624,23 @@ QColor QHexView::bytesBackground() const {
609624void QHexView::setBytesBackground (const QColor &newBytesBackground) {
610625 m_renderer->setBytesBackground (newBytesBackground);
611626 Q_EMIT bytesBackgroundChanged ();
627+ this ->viewport ()->update ();
612628}
613629
614630QColor QHexView::addressColor () const { return m_renderer->addressColor (); }
615631
616632void QHexView::setAddressColor (const QColor &newAddressColor) {
617633 m_renderer->setAddressColor (newAddressColor);
618634 Q_EMIT addressColorChanged ();
635+ this ->viewport ()->update ();
619636}
620637
621638QColor QHexView::headerColor () const { return m_renderer->headerColor (); }
622639
623640void QHexView::setHeaderColor (const QColor &newHeaderColor) {
624641 m_renderer->setHeaderColor (newHeaderColor);
625642 Q_EMIT headerColorChanged ();
643+ this ->viewport ()->update ();
626644}
627645
628646void QHexView::mousePressEvent (QMouseEvent *e) {
@@ -764,21 +782,27 @@ void QHexView::paintEvent(QPaintEvent *e) {
764782 const int lineHeight = m_renderer->lineHeight ();
765783 const int headerCount = m_renderer->headerLineCount ();
766784
785+ auto m = viewport ()->contentsMargins ();
786+
767787 // these are lines from the point of view of the visible rect
768788 // where the first "headerCount" are taken by the header
769- const int first = (r.top () / lineHeight); // included
770- const int lastPlusOne = (r.bottom () / lineHeight) + 1 ; // excluded
789+ const int first = (r.top () / lineHeight); // included
790+ const int lastPlusOne =
791+ (r.bottom () / lineHeight) + 1 - m.top () - m.bottom (); // excluded
771792
772793 // compute document lines, adding firstVisible and removing the header
773794 // the max is necessary if the rect covers the header
774795 const qsizetype begin = firstVisible + std::max (first - headerCount, 0 );
775796 const qsizetype end = firstVisible + std::max (lastPlusOne - headerCount, 0 );
776797
798+ Q_EMIT onPaintCustomEventBegin ();
777799 painter.save ();
778- painter.translate (-this ->horizontalScrollBar ()->value (), 0 );
800+ auto xOff = this ->horizontalScrollBar ()->value ();
801+ painter.translate (-xOff + m.left (), m.top () * m_renderer->lineHeight ());
779802 m_renderer->render (&painter, begin, end, firstVisible);
780803 m_renderer->renderFrame (&painter);
781804 painter.restore ();
805+ Q_EMIT onPaintCustomEvent (xOff, firstVisible, begin, end);
782806}
783807
784808void QHexView::moveToSelection () {
@@ -1160,6 +1184,7 @@ void QHexView::adjustScrollBars() {
11601184
11611185 auto docLines = m_renderer->documentLines ();
11621186 auto visLines = this ->visibleLines ();
1187+ auto margins = viewport ()->contentsMargins ();
11631188
11641189 // modified by wingsummer,fix the scrollbar bug
11651190 if (docLines > visLines && !m_document->isEmpty ()) {
@@ -1180,11 +1205,13 @@ void QHexView::adjustScrollBars() {
11801205 this ->setHorizontalScrollBarPolicy (Qt::ScrollBarAlwaysOn);
11811206 // +1 to see the rightmost vertical line, +2 seems more pleasant to the
11821207 // eyes
1183- hscrollbar->setMaximum (documentWidth - viewportWidth + 2 );
1208+ hscrollbar->setMaximum (documentWidth - viewportWidth + 2 +
1209+ margins.left () + margins.right ());
11841210 } else {
11851211 this ->setHorizontalScrollBarPolicy (Qt::ScrollBarAlwaysOff);
11861212 hscrollbar->setValue (0 );
1187- hscrollbar->setMaximum (documentWidth);
1213+ hscrollbar->setMaximum (documentWidth + margins.left () +
1214+ margins.right ());
11881215 }
11891216}
11901217
@@ -1203,9 +1230,10 @@ qsizetype QHexView::lastVisibleLine() const {
12031230}
12041231
12051232qsizetype QHexView::visibleLines () const {
1206- auto visLines =
1207- qsizetype (std::ceil (this ->height () / m_renderer->lineHeight () -
1208- m_renderer->headerLineCount ()));
1233+ auto margins = viewport ()->contentsMargins ();
1234+ auto visLines = qsizetype (std::ceil (
1235+ this ->height () / m_renderer->lineHeight () -
1236+ m_renderer->headerLineCount () - margins.top () - margins.bottom ()));
12091237 return std::min (visLines, m_renderer->documentLines ());
12101238}
12111239
0 commit comments