From 018e9d3ea5273618b6c20f8d39be8995c2a10d33 Mon Sep 17 00:00:00 2001 From: Pritpal Bedi Date: Mon, 29 Aug 2011 05:32:28 +0000 Subject: [PATCH] 2011-08-28 22:28 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com) * contrib/hbqt/gtqtc/gtqtc.cpp * contrib/hbqt/gtqtc/gtqtc.h + Enhanced: caret management, now it is almost real-time. --- harbour/ChangeLog | 5 + harbour/contrib/hbqt/gtqtc/gtqtc.cpp | 96 +++++++++----- harbour/contrib/hbqt/gtqtc/gtqtc.h | 192 ++++++++++++++------------- 3 files changed, 170 insertions(+), 123 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 06efe64ae3..c80b88b493 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,6 +16,11 @@ The license applies to all entries newer than 2009-04-28. */ +2011-08-28 22:28 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com) + * contrib/hbqt/gtqtc/gtqtc.cpp + * contrib/hbqt/gtqtc/gtqtc.h + + Enhanced: caret management, now it is almost real-time. + 2011-08-28 15:10 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com) * contrib/hbqt/hbmk2_qt.hbs * Upgraded: one level up - class creation lock for MT compliance. diff --git a/harbour/contrib/hbqt/gtqtc/gtqtc.cpp b/harbour/contrib/hbqt/gtqtc/gtqtc.cpp index 20420b0279..ce2cd50807 100644 --- a/harbour/contrib/hbqt/gtqtc/gtqtc.cpp +++ b/harbour/contrib/hbqt/gtqtc/gtqtc.cpp @@ -288,16 +288,16 @@ static void hb_gt_wvt_QUpdateCaret( PHB_GTWVT pWVT ) else switch( iStyle ) { case SC_INSERT: - iCaretSize = pWVT->PTEXTSIZE.y() >> 1; + iCaretSize = pWVT->PTEXTSIZE.y() / 2; break; case SC_SPECIAL1: - iCaretSize = pWVT->PTEXTSIZE.y(); + iCaretSize = pWVT->PTEXTSIZE.y() * 3 / 4; break; case SC_SPECIAL2: - iCaretSize = - ( pWVT->PTEXTSIZE.y() >> 1 ); + iCaretSize = pWVT->PTEXTSIZE.y(); break; case SC_NORMAL: - iCaretSize = HB_MAX( ( pWVT->PTEXTSIZE.y() >> 2 ) - 1, 1 ); + iCaretSize = pWVT->PTEXTSIZE.y() / 4; break; default: iCaretSize = 0; @@ -319,8 +319,7 @@ static void hb_gt_wvt_QUpdateCaret( PHB_GTWVT pWVT ) { pWVT->CaretSize = iCaretSize; pWVT->CaretWidth = pWVT->PTEXTSIZE.x(); - pWVT->CaretExist = pWVT->qWnd->_drawingArea->createCaret( pWVT->PTEXTSIZE.x(), - pWVT->CaretSize < 0 ? - pWVT->CaretSize : pWVT->CaretSize ); + pWVT->CaretExist = pWVT->qWnd->_drawingArea->createCaret( pWVT->PTEXTSIZE.x(), pWVT->CaretSize ); } if( pWVT->CaretExist ) { @@ -649,9 +648,10 @@ static void hb_gt_wvt_Refresh( PHB_GT pGT ) hb_gt_wvt_QCenterWindow( pWVT ); } pWVT->qWnd->setFocus(); - pWVT->qWnd->_drawingArea->setFocus(); +// pWVT->qWnd->_drawingArea->setFocus(); pWVT->qWnd->show(); pWVT->qWnd->update(); + pWVT->qWnd->_drawingArea->setFocus(); } hb_gt_wvt_QUpdateCaret( pWVT ); } @@ -1373,6 +1373,7 @@ DrawingArea::DrawingArea( QWidget *parent ) /* Important but give it a thought */ //setAttribute(Qt::WA_OpaquePaintEvent); + _bCaretOn = HB_TRUE; _bBlinking = HB_FALSE; _basicTimer = new QBasicTimer(); @@ -1382,6 +1383,9 @@ DrawingArea::DrawingArea( QWidget *parent ) _image = new QImage(); + _crtLastRow = 0; + _crtLastCol = 0; + _rCopying.setRect( -1, -1, -1, -1 ); } @@ -1521,7 +1525,7 @@ void DrawingArea::redrawBuffer( const QRect & rect ) #else usChar = pWVT->chrTransTbl[ usChar & 0xFF ]; #endif - +#if 1 if( bAttr & HB_GT_ATTR_BOX ) { drawBoxCharacter( &painter, usChar, bColor, iCol*_fontWidth, iRow*_fontHeight ); @@ -1532,7 +1536,7 @@ void DrawingArea::redrawBuffer( const QRect & rect ) drawBoxCharacter( &painter, usChar, bColor, iCol*_fontWidth, iRow*_fontHeight ); bAttr = HB_GT_ATTR_BOX; } - +#endif if( len == 0 ) { bOldAttr = bAttr; @@ -1558,10 +1562,7 @@ void DrawingArea::redrawBuffer( const QRect & rect ) if( len > 0 ) { text[ len ] = '\0'; - if( bOldAttr & HB_GT_ATTR_BOX ) - { - } - else + if( ! bOldAttr & HB_GT_ATTR_BOX ) { painter.setPen( QPen( _COLORS[ bOldColor & 0x0F ] ) ); painter.setBackground( QBrush( _COLORS[ bOldColor >> 4 ] ) ); @@ -1591,32 +1592,49 @@ bool DrawingArea::createCaret( int iWidth, int iHeight ) { _crtWidth = iWidth; _crtHeight = iHeight; +//HB_TRACE( HB_TR_ALWAYS, ( "bool DrawingArea::createCaret() %i %i %i %i", _crtLastRow, _crtLastCol, iWidth, iHeight ) ); + _bCaretOn = HB_TRUE; + _bBlinking = HB_FALSE; + displayCell( _crtLastRow, _crtLastCol ); + displayBlock( _crtLastRow, _crtLastCol ); + if( ! _basicTimer->isActive() ) + { + _basicTimer->start( 500, this ); + } return( HB_TRUE ); } void DrawingArea::hideCaret( void ) { - _basicTimer->stop(); - _bBlinking = HB_FALSE; +//HB_TRACE( HB_TR_ALWAYS, ( "bool DrawingArea::hideCaret() %i %i", _crtLastRow, _crtLastCol ) ); + _bCaretOn = HB_FALSE; displayCell( _crtLastRow, _crtLastCol ); } void DrawingArea::showCaret( void ) { - displayCell( _crtLastRow, _crtLastCol ); - _basicTimer->start( 350,this ); +//HB_TRACE( HB_TR_ALWAYS, ( "bool DrawingArea::showCaret() %i %i", _crtLastRow, _crtLastCol ) ); + if( ! _basicTimer->isActive() ) + { + _basicTimer->start( 500, this ); + } + displayBlock( _crtLastRow, _crtLastCol ); + _bCaretOn = HB_TRUE; } void DrawingArea::destroyCaret( void ) { _basicTimer->stop(); + _bCaretOn = HB_FALSE; displayCell( _crtLastRow, _crtLastCol ); +//HB_TRACE( HB_TR_ALWAYS, ( "void DrawingArea::destroyCaret( void )" ) ); } void DrawingArea::setCaretPos( int iCol, int iRow ) { - displayCell( _crtLastRow, _crtLastCol ); _crtLastCol = iCol; _crtLastRow = iRow; } void DrawingArea::displayCell( int iRow, int iCol ) { + PHB_GTWVT pWVT = HB_GTWVT_GET( pGT ); + QPainter painter( _image ); painter.setBackgroundMode( Qt::OpaqueMode ); QFont font( _qFont, painter.device() ); @@ -1624,10 +1642,16 @@ void DrawingArea::displayCell( int iRow, int iCol ) HB_USHORT usChar; HB_BYTE bAttr; - int bColor = 0; + int bColor = 0; if( HB_GTSELF_GETSCRCHAR( pGT, iRow, iCol, &bColor, &bAttr, &usChar ) ) { + #if defined( UNICODE ) + usChar = hb_cdpGetU16Disp( bAttr & HB_GT_ATTR_BOX ? pWVT->boxCDP : pWVT->hostCDP, ( HB_BYTE ) usChar ); + #else + usChar = pWVT->chrTransTbl[ usChar & 0xFF ]; + #endif + painter.setPen( QPen( _COLORS[ bColor & 0x0F ] ) ); painter.setBackground( QBrush( _COLORS[ bColor >> 4 ] ) ); painter.drawText( QPoint( iCol*_fontWidth, ( iRow*_fontHeight ) + _fontAscent ), QString( usChar ) ); @@ -1637,9 +1661,15 @@ void DrawingArea::displayCell( int iRow, int iCol ) } void DrawingArea::displayBlock( int iRow, int iCol ) { - QPainter painter(_image); + QPainter painter( _image ); + #if 0 painter.fillRect( QRect( iCol*_fontWidth, iRow*_fontHeight+(_fontHeight-_crtHeight), - _fontWidth, _crtHeight ), qRgb( 255,255,255 ) ); + _fontWidth, _crtHeight ), qRgb( 255,255,255 ) ); + #else + painter.setCompositionMode( QPainter::RasterOp_SourceXorDestination ); + painter.fillRect( QRect( iCol*_fontWidth, iRow*_fontHeight+(_fontHeight-_crtHeight), + _fontWidth, _crtHeight ), QBrush( qRgb( 255,255,255 ) ) ); + #endif /* We need immediate painting */ repaint( QRect( iCol*_fontWidth, iRow*_fontHeight, _fontWidth, _fontHeight ) ); } @@ -1647,15 +1677,18 @@ void DrawingArea::timerEvent( QTimerEvent *event ) { if( event->timerId() == _basicTimer->timerId() ) { - if( _bBlinking ) + if( _bCaretOn ) { - _bBlinking = HB_FALSE; - displayCell( _crtLastRow, _crtLastCol ); - } - else - { - _bBlinking = HB_TRUE; - displayBlock( _crtLastRow, _crtLastCol ); + if( _bBlinking ) + { + _bBlinking = HB_FALSE; + displayCell( _crtLastRow, _crtLastCol ); + } + else + { + _bBlinking = HB_TRUE; + displayBlock( _crtLastRow, _crtLastCol ); + } } } else @@ -1762,8 +1795,8 @@ void DrawingArea::focusInEvent( QFocusEvent *event ) void DrawingArea::focusOutEvent( QFocusEvent *event ) { - PHB_GTWVT pWVT = HB_GTWVT_GET( pGT ); - hb_gt_wvt_QKillCaret( pWVT ); +//HB_TRACE( HB_TR_ALWAYS, ( "void DrawingArea::focusOutEvent( QFocusEvent *event )" ) ); +// this->hideCaret(); /* Disableing for the time being */ HB_SYMBOL_UNUSED( event ); /* Either of IN or OUT messagess */ /* hb_gt_wvt_FireEvent( pWVT, HB_GTE_KILLFOCUS ); */ @@ -1773,6 +1806,7 @@ void DrawingArea::focusOutEvent( QFocusEvent *event ) void DrawingArea::keyReleaseEvent( QKeyEvent *event ) { HB_SYMBOL_UNUSED( event ); + QWidget::keyReleaseEvent( event ); } void hb_gt_wvt_QSetMousePos( PHB_GTWVT pWVT, int x, int y ) diff --git a/harbour/contrib/hbqt/gtqtc/gtqtc.h b/harbour/contrib/hbqt/gtqtc/gtqtc.h index 14ed386768..8d15138de3 100644 --- a/harbour/contrib/hbqt/gtqtc/gtqtc.h +++ b/harbour/contrib/hbqt/gtqtc/gtqtc.h @@ -151,98 +151,7 @@ /*----------------------------------------------------------------------*/ class MainWindow; - -class DrawingArea : public QWidget -{ - Q_OBJECT - -public: - DrawingArea( QWidget *parent = 0 ); - virtual ~DrawingArea( void ); - - PHB_GT pGT; - - void resetWindowSize( void ); - void redrawBuffer( const QRect & rect ); - - bool createCaret( int iWidth, int iHeight ); - void showCaret( void ); - void hideCaret( void ); - void setCaretPos( int iRow, int iCol ); - void destroyCaret(); - - void displayCell( int iRow, int iCol ); - void displayBlock( int iRow, int iCol ); - void resizeImage( const QSize &newSize ); - void drawBoxCharacter( QPainter *painter, HB_USHORT usChar, HB_BYTE bColor, int x, int y ); - void copyTextOnClipboard( void ); - void paintCopyOperation( void ); - - QImage *_image; - QFont _qFont; - - QRgb _COLORS[ 16 ]; - - int _fontHeight; - int _fontWidth; - int _fontAscent; - - int _iROWS, _iCOLS; - int _wndWidth, _wndHeight; - - int _crtHeight; - int _crtWidth; - bool _bBlinking; - int _crtLastRow; - int _crtLastCol; - - bool _bFirst; - bool _bSizing; - bool _bInvertRect; - - bool _bCopying; - QRect _rCopying; - QRect _rCopyingP; - - QBasicTimer *_basicTimer; - -protected: - void keyPressEvent( QKeyEvent *event ); - void keyReleaseEvent( QKeyEvent *event ); - void mousePressEvent( QMouseEvent *event ); - void mouseMoveEvent( QMouseEvent *event ); - void mouseReleaseEvent( QMouseEvent *event ); - void mouseDoubleClickEvent( QMouseEvent * event ); - void paintEvent( QPaintEvent *event ); - void resizeEvent( QResizeEvent *event ); - void wheelEvent( QWheelEvent *event ); - void timerEvent( QTimerEvent *event ); - void focusInEvent( QFocusEvent *event ); - void focusOutEvent( QFocusEvent *event ); - void moveEvent( QMoveEvent *event ); - bool event( QEvent *event ); - -}; - -/*----------------------------------------------------------------------*/ - -class MainWindow : public QMainWindow -{ - Q_OBJECT - -public: - MainWindow(); - virtual ~MainWindow(); - - DrawingArea *_drawingArea; - PHB_GT pGT; - - void setWindowSize( void ); - -protected: - void closeEvent( QCloseEvent *event ); - -}; +class DrawingArea; /*----------------------------------------------------------------------*/ @@ -315,6 +224,105 @@ typedef struct } HB_GTWVT, * PHB_GTWVT; +/*----------------------------------------------------------------------*/ + +class DrawingArea : public QWidget +{ + Q_OBJECT + +public: + DrawingArea( QWidget *parent = 0 ); + virtual ~DrawingArea( void ); + + PHB_GT pGT; +// PHB_GTWVT pWVT; + + void resetWindowSize( void ); + void redrawBuffer( const QRect & rect ); + + bool createCaret( int iWidth, int iHeight ); + void showCaret( void ); + void hideCaret( void ); + void setCaretPos( int iRow, int iCol ); + void destroyCaret(); + + void displayCell( int iRow, int iCol ); + void displayBlock( int iRow, int iCol ); + void resizeImage( const QSize &newSize ); + void drawBoxCharacter( QPainter *painter, HB_USHORT usChar, HB_BYTE bColor, int x, int y ); + void copyTextOnClipboard( void ); + void paintCopyOperation( void ); + + QImage *_image; + QFont _qFont; + + QRgb _COLORS[ 16 ]; + + int _fontHeight; + int _fontWidth; + int _fontAscent; + + int _iROWS, _iCOLS; + int _wndWidth, _wndHeight; + + bool _bCaretOn; + int _crtHeight; + int _crtWidth; + bool _bBlinking; + int _crtLastRow; + int _crtLastCol; + + bool _bFirst; + bool _bSizing; + bool _bInvertRect; + + bool _bCopying; + QRect _rCopying; + QRect _rCopyingP; + + QBasicTimer *_basicTimer; + +protected: + void keyPressEvent( QKeyEvent *event ); + void keyReleaseEvent( QKeyEvent *event ); + void mousePressEvent( QMouseEvent *event ); + void mouseMoveEvent( QMouseEvent *event ); + void mouseReleaseEvent( QMouseEvent *event ); + void mouseDoubleClickEvent( QMouseEvent * event ); + void paintEvent( QPaintEvent *event ); + void resizeEvent( QResizeEvent *event ); + void wheelEvent( QWheelEvent *event ); + void timerEvent( QTimerEvent *event ); + void focusInEvent( QFocusEvent *event ); + void focusOutEvent( QFocusEvent *event ); + void moveEvent( QMoveEvent *event ); + bool event( QEvent *event ); + +}; + +/*----------------------------------------------------------------------*/ + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(); + virtual ~MainWindow(); + + DrawingArea *_drawingArea; + PHB_GT pGT; + + void setWindowSize( void ); + +protected: + void closeEvent( QCloseEvent *event ); + +}; + +/*----------------------------------------------------------------------*/ + + #define HB_GTI_WIDGET 2001 #define HB_GTI_DRAWINGAREA 2002