From 93e56f88a3f0c59efd83face4f406e56eb581486 Mon Sep 17 00:00:00 2001 From: Pritpal Bedi Date: Fri, 12 Mar 2010 09:08:06 +0000 Subject: [PATCH] 2010-03-12 01:03 UTC-0800 Pritpal Bedi (pritpal@vouchcac.com) * contrib/hbqt/hbqt_hbqplaintextedit.cpp * contrib/hbqt/hbqt_hbqplaintextedit.h ! Fixed behavior of book-marks. Now color representation on bookmarked lines is persistent and consistent with corresponding buttons in the statusbar. --- harbour/ChangeLog | 7 ++ .../contrib/hbqt/hbqt_hbqplaintextedit.cpp | 107 +++++++++++------- harbour/contrib/hbqt/hbqt_hbqplaintextedit.h | 1 + 3 files changed, 76 insertions(+), 39 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 723ede5ca7..9dd2ee458d 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -17,6 +17,13 @@ past entries belonging to author(s): Viktor Szakats. */ +2010-03-12 01:03 UTC-0800 Pritpal Bedi (pritpal@vouchcac.com) + * contrib/hbqt/hbqt_hbqplaintextedit.cpp + * contrib/hbqt/hbqt_hbqplaintextedit.h + ! Fixed behavior of book-marks. Now color representation + on bookmarked lines is persistent and consistent with + corresponding buttons in the statusbar. + 2010-03-12 02:10 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) * contrib/hbssl/evpmd.c ! Disabled md2 support for >= 1.0.0 OpenSSL versions. diff --git a/harbour/contrib/hbqt/hbqt_hbqplaintextedit.cpp b/harbour/contrib/hbqt/hbqt_hbqplaintextedit.cpp index c78f62fd30..81216b645a 100644 --- a/harbour/contrib/hbqt/hbqt_hbqplaintextedit.cpp +++ b/harbour/contrib/hbqt/hbqt_hbqplaintextedit.cpp @@ -261,52 +261,76 @@ void HBQPlainTextEdit::paintEvent( QPaintEvent * event ) { QPainter painter( viewport() ); - if( m_currentLineColor.isValid() ) + int curBlock = textCursor().blockNumber(); + + QTextBlock block = firstVisibleBlock(); + int blockNumber = block.blockNumber(); + int height = ( int ) blockBoundingRect( block ).height(); + int top = ( int ) blockBoundingGeometry( block ).translated( contentOffset() ).top(); + int bottom = top + height; + + while( block.isValid() && top <= event->rect().bottom() ) { - QRect r = HBQPlainTextEdit::cursorRect(); - r.setX( 0 ); - r.setWidth( viewport()->width() ); - - int index = bookMark.indexOf( textCursor().blockNumber() + 1 ); - if( index != -1 ) + if( block.isVisible() && bottom >= event->rect().top() ) { - QBrush br = QBrush( m_currentLineColor ); - - if( index == 0 ) - br = QBrush( QColor( 255, 255, 127 ) ); - else if( index == 1 ) - br = QBrush( QColor( 175, 175, 255 ) ); - else if( index == 2 ) - br = QBrush( QColor( 255, 175, 175 ) ); - else if( index == 3 ) - br = QBrush( QColor( 175, 255, 175 ) ); - else if( index == 4 ) - br = QBrush( QColor( 255, 190, 125 ) ); - else if( index == 5 ) - br = QBrush( QColor( 175, 255, 255 ) ); - else - br = QBrush( m_currentLineColor ); - - painter.fillRect( r, br ); + int index = bookMarksGoto.indexOf( blockNumber + 1 ); + if( index != -1 ) + { + QRect r( 0, top, viewport()->width(), height ); + painter.fillRect( r, brushForBookmark( index ) ); + } + else if( curBlock == blockNumber && m_currentLineColor.isValid() ) + { + if( highlightCurLine == true ) + { + QRect r = HBQPlainTextEdit::cursorRect(); + r.setX( 0 ); + r.setWidth( viewport()->width() ); + painter.fillRect( r, QBrush( m_currentLineColor ) ); + } + } } - else if( highlightCurLine == true ) - painter.fillRect( r, QBrush( m_currentLineColor ) ); + block = block.next(); + top = bottom; + bottom = top + height;//( int ) blockBoundingRect( block ).height(); + ++blockNumber; } this->hbPaintColumnSelection( event ); - painter.end(); QPlainTextEdit::paintEvent( event ); } +QBrush HBQPlainTextEdit::brushForBookmark( int index ) +{ + QBrush br; + + if( index == 0 ) + br = QBrush( QColor( 255, 255, 127 ) ); + else if( index == 1 ) + br = QBrush( QColor( 175, 175, 255 ) ); + else if( index == 2 ) + br = QBrush( QColor( 255, 175, 175 ) ); + else if( index == 3 ) + br = QBrush( QColor( 175, 255, 175 ) ); + else if( index == 4 ) + br = QBrush( QColor( 255, 190, 125 ) ); + else if( index == 5 ) + br = QBrush( QColor( 175, 255, 255 ) ); + else + br = QBrush( m_currentLineColor ); + + return br; +} + void HBQPlainTextEdit::lineNumberAreaPaintEvent( QPaintEvent *event ) { QPainter painter( lineNumberArea ); painter.fillRect( event->rect(), m_lineAreaBkColor ); QTextBlock block = firstVisibleBlock(); - int blockNumber = block.blockNumber(); - int top = ( int ) blockBoundingGeometry( block ).translated( contentOffset() ).top(); - int bottom = top +( int ) blockBoundingRect( block ).height(); + int blockNumber = block.blockNumber(); + int top = ( int ) blockBoundingGeometry( block ).translated( contentOffset() ).top(); + int bottom = top +( int ) blockBoundingRect( block ).height(); while( block.isValid() && top <= event->rect().bottom() ) { @@ -315,24 +339,26 @@ void HBQPlainTextEdit::lineNumberAreaPaintEvent( QPaintEvent *event ) QString number = QString::number( blockNumber + 1 ); painter.setPen( ( blockNumber + 1 ) % 10 == 0 ? Qt::red : Qt::black ); painter.drawText( 0, top, lineNumberArea->width()-2, fontMetrics().height(), Qt::AlignRight, number ); - int index = bookMark.indexOf( number.toInt() ); + int index = bookMarksGoto.indexOf( number.toInt() ); if( index != -1 ) { //painter.drawText( 0, top, 30, fontMetrics().height(), Qt::AlignCenter, "+" ); - painter.setBrush( QBrush( Qt::yellow, Qt::SolidPattern ) ); - painter.drawEllipse( 5, top +( fontMetrics().height()/4 ), + //painter.setBrush( QBrush( Qt::yellow, Qt::SolidPattern ) ); + painter.setBrush( brushForBookmark( index ) ); + #if 0 + painter.drawEllipse( 5, top + ( fontMetrics().height()/4 ), fontMetrics().height()/2, fontMetrics().height()/2 ); + #endif + painter.drawRect( 5, top+2, fontMetrics().height()-4, fontMetrics().height()-4 ); } } - block = block.next(); - top = bottom; + block = block.next(); + top = bottom; bottom = top +( int ) blockBoundingRect( block ).height(); ++blockNumber; } } - - void HBQPlainTextEdit::hbBookmarks( int block ) { int found = bookMark.indexOf( block ); @@ -342,7 +368,9 @@ void HBQPlainTextEdit::hbBookmarks( int block ) qSort( bookMark ); } else + { bookMark.remove( found ); + } found = -1; int i = 0; @@ -357,8 +385,9 @@ void HBQPlainTextEdit::hbBookmarks( int block ) } if( found == -1 ) + { bookMarksGoto.append( block ); - + } lineNumberArea->repaint(); update(); } diff --git a/harbour/contrib/hbqt/hbqt_hbqplaintextedit.h b/harbour/contrib/hbqt/hbqt_hbqplaintextedit.h index 95838eb3c5..f7d1ab7069 100644 --- a/harbour/contrib/hbqt/hbqt_hbqplaintextedit.h +++ b/harbour/contrib/hbqt/hbqt_hbqplaintextedit.h @@ -128,6 +128,7 @@ private: bool isColumnSelectionEnabled; bool isTipActive; QCompleter * c; + QBrush brushForBookmark( int index ); protected: bool event( QEvent * event );