2010-05-05 09:45 UTC-0800 Pritpal Bedi (pritpal@vouchcac.com)

* contrib/hbide/idedocks.prg
  * contrib/hbide/ideeditor.prg
  * contrib/hbide/ideshortcuts.prg
  * contrib/hbqt/hbqt_hbqplaintextedit.cpp
  * contrib/hbqt/hbqt_hbqplaintextedit.h
  * contrib/hbqt/qtgui/HBQPlainTextEdit.cpp
  * contrib/hbqt/qtgui/THBQPlainTextEdit.prg
  * contrib/hbqt/qth/HBQPlainTextEdit.qth
    ! Removed: close button on "Stats" panel.

    + Implemented: line selection mode. Designated key is F11.
      It is still a work in progress but a working prototype is there and 
      currently selection is available and paste behaves the standard way.

      Mindagaus, please explore as the artifacts are OK.
This commit is contained in:
Pritpal Bedi
2010-05-05 16:50:47 +00:00
parent 1e853cfc15
commit e4b7f2b14f
10 changed files with 200 additions and 51 deletions

View File

@@ -17,6 +17,23 @@
past entries belonging to author(s): Viktor Szakats.
*/
2010-05-05 09:45 UTC-0800 Pritpal Bedi (pritpal@vouchcac.com)
* contrib/hbide/idedocks.prg
* contrib/hbide/ideeditor.prg
* contrib/hbide/ideshortcuts.prg
* contrib/hbqt/hbqt_hbqplaintextedit.cpp
* contrib/hbqt/hbqt_hbqplaintextedit.h
* contrib/hbqt/qtgui/HBQPlainTextEdit.cpp
* contrib/hbqt/qtgui/THBQPlainTextEdit.prg
* contrib/hbqt/qth/HBQPlainTextEdit.qth
! Removed: close button on "Stats" panel.
+ Implemented: line selection mode. Designated key is F11.
It is still a work in progress but a working prototype is there and
currently selection is available and paste behaves the standard way.
Mindagaus, please explore as the artifacts are OK.
2010-05-05 10:39 UTC+0200 Viktor Szakats (harbour.01 syenar.hu)
* config/os2/gcc.mk
* utils/hbmk2/hbmk2.prg

View File

@@ -441,15 +441,15 @@ METHOD IdeDocks:buildViewWidget( cObjectName )
oFrame:oTabWidget := XbpTabWidget():new():create( oFrame, , {0,0}, {200,200}, , .t. )
IF empty( qTBtnClose )
IF !( cObjectName == "Stats" )
qTBtnClose := QToolButton():new()
qTBtnClose:setTooltip( "Close Tab" )
qTBtnClose:setAutoRaise( .t. )
qTBtnClose:setIcon( hbide_image( "closetab" ) )
::connect( qTBtnClose, "clicked()", {|| ::oSM:closeSource() } )
oFrame:oTabWidget:qCornerWidget := qTBtnClose
oFrame:oTabWidget:oWidget:setCornerWidget( qTBtnClose, Qt_TopRightCorner )
ENDIF
oFrame:oTabWidget:qCornerWidget := qTBtnClose
oFrame:oTabWidget:oWidget:setCornerWidget( qTBtnClose, Qt_TopRightCorner )
oFrame:oTabWidget:oWidget:setUsesScrollButtons( .f. )
oFrame:oTabWidget:oWidget:setMovable( .t. )

View File

@@ -149,6 +149,7 @@ CLASS IdeEditsManager INHERIT IdeObject
METHOD convertDQuotes()
METHOD toggleSelectionMode()
METHOD toggleLineNumbers()
METHOD toggleLineSelectionMode()
METHOD getText()
METHOD getWord( lSelect )
@@ -546,6 +547,15 @@ METHOD IdeEditsManager:selectAll()
/*----------------------------------------------------------------------*/
METHOD IdeEditsManager:toggleLineSelectionMode()
LOCAL oEdit
IF !empty( oEdit := ::getEditObjectCurrent() )
oEdit:toggleLineSelectionMode()
ENDIF
RETURN Self
/*----------------------------------------------------------------------*/
METHOD IdeEditsManager:toggleSelectionMode()
LOCAL oEdit
IF !empty( oEdit := ::getEditObjectCurrent() )
@@ -1415,6 +1425,7 @@ CLASS IdeEdit INHERIT IdeObject
DATA currentPointSize INIT 10
DATA qFont
DATA aBlockCopyContents INIT {}
DATA isLineSelectionMode INIT .f.
METHOD new( oEditor, nMode )
METHOD create( oEditor, nMode )
@@ -1455,6 +1466,7 @@ CLASS IdeEdit INHERIT IdeObject
METHOD goto( nLine )
METHOD gotoFunction()
METHOD toggleLineNumbers()
METHOD toggleLineSelectionMode()
METHOD getWord( lSelect )
METHOD getLine( nLine, lSelect )
@@ -1483,7 +1495,7 @@ CLASS IdeEdit INHERIT IdeObject
METHOD setFont()
METHOD markCurrentFunction()
METHOD copyBlockContents( aCord )
METHOD pasteBlockContents()
METHOD pasteBlockContents( nMode )
METHOD insertBlockContents( aCord )
METHOD deleteBlockContents( aCord )
METHOD zoom( nKey )
@@ -1935,7 +1947,7 @@ METHOD IdeEdit:execKeyEvent( nMode, nEvent, p, p1 )
::copyBlockContents( p1 )
ELSEIF p == 21012
::pasteBlockContents()
::pasteBlockContents( p1 )
ELSEIF p == 21013
::insertBlockContents( p1 )
@@ -1956,34 +1968,44 @@ METHOD IdeEdit:execKeyEvent( nMode, nEvent, p, p1 )
/*----------------------------------------------------------------------*/
METHOD IdeEdit:copyBlockContents( aCord )
LOCAL nT, nL, nB, nR, nW, i, cLine, cClip := ""
LOCAL nT, nL, nB, nR, nW, i, cLine, cClip := "", nMode
nT := iif( aCord[ 1 ] > aCord[ 3 ], aCord[ 3 ], aCord[ 1 ] )
nB := iif( aCord[ 1 ] > aCord[ 3 ], aCord[ 1 ], aCord[ 3 ] )
nL := iif( aCord[ 2 ] > aCord[ 4 ], aCord[ 4 ], aCord[ 2 ] )
nR := iif( aCord[ 2 ] > aCord[ 4 ], aCord[ 2 ], aCord[ 4 ] )
nMode := aCord[ 5 ]
nW := nR - nL
::aBlockCopyContents := {}
FOR i := nT TO nB
cLine := ::getLine( i + 1 )
cLine := pad( substr( cLine, nL + 1, nW ), nW )
aadd( ::aBlockCopyContents, cLine )
IF nMode == 2 /* Column */
cLine := pad( substr( cLine, nL + 1, nW ), nW )
ELSEIF nMode == 3 /* Line */
// Nothing to do, complete line is already pulled
ELSEIF nMode == 1 /* Stream */
IF i == 1
cLine := substr( cLine, nL + 1 )
ELSEIF i == nB
cLine := substr( cLine, 1, nR + 1 )
ENDIF
ENDIF
cClip += cLine + hb_osNewLine()
NEXT
HB_TRACE( HB_TR_ALWAYS, cClip )
QClipboard():new():setText( cClip )
RETURN Self
/*----------------------------------------------------------------------*/
METHOD IdeEdit:pasteBlockContents()
METHOD IdeEdit:pasteBlockContents( nMode )
LOCAL i, nRow, nCol, qCursor, nMaxCol
HB_SYMBOL_UNUSED( nMode )
::aBlockCopyContents := hbide_memoToArray( QClipboard():new():text() )
hb_trace( HB_TR_ALWAYS, "MMMMMMMM", LEN( ::aBlockCopyContents ) )
IF empty( ::aBlockCopyContents )
RETURN Self
ENDIF
@@ -2169,6 +2191,13 @@ METHOD IdeEdit:toggleSelectionMode()
/*----------------------------------------------------------------------*/
METHOD IdeEdit:toggleLineSelectionMode()
::isLineSelectionMode := ! ::isLineSelectionMode
::qEdit:hbSetSelectionMode( 3, ::isLineSelectionMode )
RETURN Self
/*----------------------------------------------------------------------*/
METHOD IdeEdit:redo()
::qEdit:redo()
RETURN Self

View File

@@ -198,6 +198,7 @@ CLASS IdeShortcuts INHERIT IdeObject
METHOD toggleLineNumbersDisplay()
METHOD toggleSelectionMode()
METHOD toggleStatusBar()
METHOD toggleLineSelectionMode()
ENDCLASS
@@ -1112,6 +1113,10 @@ METHOD IdeShortcuts:toggleStatusBar()
::lStatusBarVisible := ! ::lStatusBarVisible
RETURN Self
/*----------------------------------------------------------------------*/
METHOD IdeShortcuts:toggleLineSelectionMode()
RETURN ::oEM:toggleLineSelectionMode()
/*----------------------------------------------------------------------*/
METHOD IdeShortcuts:loadMethods()
@@ -1281,6 +1286,9 @@ METHOD IdeShortcuts:loadMethods()
aadd( ::aMethods, { 'toggleStatusBar()', ;
'toggleStatusBar()', ;
'Toggles display of statusbar. The action is not saved for next run.' } )
aadd( ::aMethods, { 'toggleLineSelectionMode()', ;
'toggleLineSelectionMode()', ;
'Toggles line selection mode.' } )
RETURN Self
@@ -1335,6 +1343,8 @@ METHOD IdeShortcuts:loadDftSCuts()
aadd( b_, { "Insert Text" , "F7" , "NO", "YES", "NO" , "", '::insert( "" )' , "insert-external-file", "", "" } )
aadd( b_, { "Insert Separator", "F7" , "NO", "NO" , "NO" , "", '::separator( "" )' , "insert-separator", "", "" } )
aadd( b_, { "Toggle Line Selection Mode", "F11", "NO", "NO" , "NO" , "", '::toggleLineSelectionMode()', "" , "", "" } )
::aDftSCuts := b_
ENDIF

View File

@@ -69,7 +69,7 @@
:hbCut() -> NIL
:hbCopy() -> NIL
:hbPaste() -> NIL
:hbSetSelectionMode( nMode ) -> NIL
:hbSetSelectionMode( nMode, lOn ) -> NIL
$DESCRIPTION$

View File

@@ -75,6 +75,18 @@
#include "hbqt_hbqplaintextedit.h"
#define selectionState_off 0
#define selectionState_on 1
#define selectionMode_none 0
#define selectionMode_stream 1
#define selectionMode_column 2
#define selectionMode_line 3
#define selectionDisplay_none 0
#define selectionDisplay_qt 1
#define selectionDisplay_ide 2
/*----------------------------------------------------------------------*/
HBQPlainTextEdit::HBQPlainTextEdit( QWidget * parent ) : QPlainTextEdit( parent )
@@ -91,9 +103,11 @@ HBQPlainTextEdit::HBQPlainTextEdit( QWidget * parent ) : QPlainTextEdit( parent
isTipActive = false;
columnBegins = -1;
columnEnds = -1;
selectionState = 0;
selectionMode = 0;
selectionState = selectionState_off;
selectionMode = selectionMode_none;
selectionDisplay = selectionDisplay_none;
isColumnSelectionEnabled = false;
isLineSelectionON = false;
horzRuler = new HorzRuler( this );
connect( this, SIGNAL( blockCountChanged( int ) ) , this, SLOT( hbUpdateLineNumberAreaWidth( int ) ) );
@@ -240,7 +254,7 @@ void HBQPlainTextEdit::hbHighlightSelectedColumns( bool yes )
{
if( yes )
{
selectionMode = 2;
selectionMode = selectionMode_column;
isColumnSelectionEnabled = true;
QTextCursor c = textCursor();
@@ -258,7 +272,7 @@ void HBQPlainTextEdit::hbHighlightSelectedColumns( bool yes )
}
else
{
selectionMode = 1;
selectionMode = selectionMode_stream;
if( columnBegins >= 0 )
{
@@ -285,13 +299,13 @@ void HBQPlainTextEdit::hbHighlightSelectedColumns( bool yes )
/*----------------------------------------------------------------------*/
void HBQPlainTextEdit::hbSetSelectionMode( int mode )
void HBQPlainTextEdit::hbSetSelectionMode( int mode, bool on )
{
switch( mode )
{
case 1: /* Stream Selection */
{
selectionMode = 1;
selectionMode = selectionMode_stream;
if( columnBegins >= 0 )
{
int cb = columnBegins <= columnEnds ? columnBegins : columnEnds;
@@ -315,7 +329,7 @@ void HBQPlainTextEdit::hbSetSelectionMode( int mode )
}
case 2: /* Columns Selection */
{
selectionMode = 2;
selectionMode = selectionMode_column;
QTextCursor c = textCursor();
if( columnBegins == -1 && c.hasSelection() )
@@ -332,14 +346,28 @@ void HBQPlainTextEdit::hbSetSelectionMode( int mode )
isColumnSelectionEnabled = true;
break;
}
case 3: /* Line Selection */
case 3: /* Line Selection : activated through keyboard */
{
selectionMode = 3;
isColumnSelectionEnabled = false;
if( on )
{
isLineSelectionON = true;
hbClearColumnSelection();
QTextCursor c = textCursor();
rowBegins = c.blockNumber();
rowEnds = c.blockNumber();
}
else
{
isLineSelectionON = false;
}
selectionMode = selectionMode_line;
break;
}
default:
{
selectionMode = 0;
selectionMode = selectionMode_none;
}
}
update();
@@ -376,15 +404,16 @@ void HBQPlainTextEdit::hbCut()
void HBQPlainTextEdit::hbCopy()
{
if( isColumnSelectionEnabled )
if( isColumnSelectionEnabled || selectionMode == selectionMode_line )
{
PHB_ITEM p1 = hb_itemPutNI( NULL, 21011 );
PHB_ITEM p2 = hb_itemNew( NULL );
hb_arrayNew( p2, 4 );
hb_arraySetNI( p2, 1, rowBegins );
hb_arraySetNI( p2, 2, columnBegins );
hb_arraySetNI( p2, 3, rowEnds );
hb_arraySetNI( p2, 4, columnEnds );
hb_arrayNew( p2, 5 );
hb_arraySetNI( p2, 1, rowBegins );
hb_arraySetNI( p2, 2, columnBegins );
hb_arraySetNI( p2, 3, rowEnds );
hb_arraySetNI( p2, 4, columnEnds );
hb_arraySetNI( p2, 5, selectionMode );
hb_vmEvalBlockV( block, 2, p1, p2 );
hb_itemRelease( p1 );
@@ -400,11 +429,13 @@ void HBQPlainTextEdit::hbCopy()
void HBQPlainTextEdit::hbPaste()
{
if( isColumnSelectionEnabled )
if( isColumnSelectionEnabled || selectionMode == selectionMode_line )
{
PHB_ITEM p1 = hb_itemPutNI( NULL, 21012 );
hb_vmEvalBlockV( block, 1, p1 );
PHB_ITEM p2 = hb_itemPutNI( NULL, selectionMode );
hb_vmEvalBlockV( block, 1, p1, p2 );
hb_itemRelease( p1 );
hb_itemRelease( p2 );
}
else
{
@@ -440,7 +471,7 @@ void HBQPlainTextEdit::mouseReleaseEvent( QMouseEvent *event )
{
setCursorWidth( 1 );
selectionState = 0;
if( selectionMode == 1 )
if( selectionMode == selectionMode_stream )
{
QTextCursor c( textCursor() );
rowEnds = c.blockNumber();
@@ -454,10 +485,15 @@ void HBQPlainTextEdit::mouseReleaseEvent( QMouseEvent *event )
void HBQPlainTextEdit::mouseMoveEvent( QMouseEvent *event )
{
if( isColumnSelectionEnabled )
selectionMode = 2;
selectionMode = selectionMode_column;
else
{
selectionMode = 1;
selectionMode = selectionMode_stream;
if( selectionState == 1 )
{
selectionState = 0;
hbClearColumnSelection();
}
QPlainTextEdit::mouseMoveEvent( event );
return;
}
@@ -522,7 +558,7 @@ bool HBQPlainTextEdit::hbKeyPressColumnSelection( QKeyEvent * event )
if( isColumnSelectionEnabled )
{
selectionMode = 2;
selectionMode = selectionMode_column;
QTextCursor c( textCursor() );
int col = c.columnNumber();
@@ -544,8 +580,8 @@ bool HBQPlainTextEdit::hbKeyPressColumnSelection( QKeyEvent * event )
{
QTextBlock b = c.document()->findBlock( c.selectionStart() );
columnBegins = c.selectionStart() - b.position();
columnEnds = c.columnNumber();
rowBegins = b.blockNumber();
columnEnds = c.columnNumber();
b = c.document()->findBlock( c.selectionEnd() );
rowEnds = b.blockNumber();
update();
@@ -676,14 +712,50 @@ bool HBQPlainTextEdit::hbKeyPressColumnSelection( QKeyEvent * event )
}
}
}
else
else if( selectionMode == selectionMode_stream )
{
selectionMode = 1;
selectionMode = selectionMode_stream;
if( shift && isNavableKey( k ) )
{
if( selectionState == 0 )
{
hbClearColumnSelection();
selectionState == 1;
}
}
else
{
selectionState = 0;
hbClearColumnSelection();
QTextCursor c( textCursor() );
if( c.hasSelection() )
{
QTextBlock b = c.document()->findBlock( c.selectionStart() );
columnBegins = c.selectionStart() - b.position();
rowBegins = b.blockNumber();
columnEnds = c.columnNumber();
b = c.document()->findBlock( c.selectionEnd() );
rowEnds = b.blockNumber();
}
QPlainTextEdit::keyPressEvent( event );
event->ignore();
return true;
}
}
else if( selectionMode == selectionMode_line )
{
if( isLineSelectionON && ( k == Qt::Key_Up || k == Qt::Key_Down ) )
{
QPlainTextEdit::keyPressEvent( event );
QTextCursor c( textCursor() );
if( ( k == Qt::Key_Down && c.blockNumber() == rowEnds + 1 ) ||
( k == Qt::Key_Up && c.blockNumber() == rowBegins - 1 ) )
{
rowEnds = c.blockNumber();
}
event->ignore();
update();
return true;
}
}
return false;
@@ -1015,26 +1087,45 @@ void HBQPlainTextEdit::hbPaintColumnSelection( QPaintEvent * event )
int rb = rowBegins <= rowEnds ? rowBegins : rowEnds;
int re = rowBegins <= rowEnds ? rowEnds : rowBegins;
QPainter p( viewport() );
int t = cursorForPosition( QPoint( 1,1 ) ).blockNumber();
if( re >= t )
{
QPainter p( viewport() );
int c = cursorForPosition( QPoint( 1,1 ) ).columnNumber();
int y = ( ( rb <= t ) ? 0 : ( ( rb - t ) * fontMetrics().height() ) );
int top = ( ( rb <= t ) ? 0 : ( ( rb - t ) * fontMetrics().height() ) );
int btm = ( ( re - t + 1 ) * fontMetrics().height() ) - top;
int fontWidth = fontMetrics().averageCharWidth();
int x = ( ( cb - c ) * fontWidth ) + ( c > 0 ? 0 : contentsRect().left() );
int w = ( ce - cb ) * fontWidth;
QRect r( x, y, ( w == 0 ? 1 : w ), ( ( re - t + 1 ) * fontMetrics().height() ) - y );
QRect r( x, top, ( w == 0 ? 1 : w ), btm );
p.fillRect( r, QBrush( QColor( 175, 255, 175 ) ) );
}
}
}
else if( selectionMode == selectionMode_line )
{
int rb = rowBegins <= rowEnds ? rowBegins : rowEnds;
int re = rowBegins <= rowEnds ? rowEnds : rowBegins;
int t = cursorForPosition( QPoint( 1,1 ) ).blockNumber();
if( re >= t )
{
QPainter p( viewport() );
int top = ( ( rb <= t ) ? 0 : ( ( rb - t ) * fontMetrics().height() ) );
int btm = ( ( re - t + 1 ) * fontMetrics().height() ) - top ;
QRect r( 0, top, viewport()->width(), btm );
p.fillRect( r, QBrush( QColor( 175, 255, 175 ) ) );
}
}
}
/*----------------------------------------------------------------------*/

View File

@@ -136,6 +136,8 @@ private:
int columnEnds;
int selectionState;
int selectionMode;
int selectionDisplay;
bool isLineSelectionON;
bool isColumnSelectionEnabled;
bool isTipActive;
QCompleter * c;
@@ -183,7 +185,7 @@ public slots:
void hbCut();
void hbCopy();
void hbPaste();
void hbSetSelectionMode( int mode );
void hbSetSelectionMode( int mode, bool on );
private slots:
void hbSlotCursorPositionChanged();

View File

@@ -735,16 +735,16 @@ HB_FUNC( QT_HBQPLAINTEXTEDIT_HBPASTE )
}
/*
* void hbSetSelectionMode( int mode )
* void hbSetSelectionMode( int mode, bool on )
*/
HB_FUNC( QT_HBQPLAINTEXTEDIT_HBSETSELECTIONMODE )
{
HBQPlainTextEdit * p = hbqt_par_HBQPlainTextEdit( 1 );
if( p )
( p )->hbSetSelectionMode( hb_parni( 2 ) );
( p )->hbSetSelectionMode( hb_parni( 2 ), hb_parl( 3 ) );
else
{
HB_TRACE( HB_TR_DEBUG, ( "............................... F=QT_HBQPLAINTEXTEDIT_HBSETSELECTIONMODE FP=( p )->hbSetSelectionMode( hb_parni( 2 ) ); p is NULL" ) );
HB_TRACE( HB_TR_DEBUG, ( "............................... F=QT_HBQPLAINTEXTEDIT_HBSETSELECTIONMODE FP=( p )->hbSetSelectionMode( hb_parni( 2 ), hb_parl( 3 ) ); p is NULL" ) );
}
}

View File

@@ -108,7 +108,7 @@ CREATE CLASS HBQPlainTextEdit INHERIT HbQtObjectHandler, QPlainTextEdit
METHOD hbCut()
METHOD hbCopy()
METHOD hbPaste()
METHOD hbSetSelectionMode( nMode )
METHOD hbSetSelectionMode( nMode, lOn )
ENDCLASS
@@ -286,6 +286,6 @@ METHOD HBQPlainTextEdit:hbPaste()
RETURN Qt_HBQPlainTextEdit_hbPaste( ::pPtr )
METHOD HBQPlainTextEdit:hbSetSelectionMode( nMode )
RETURN Qt_HBQPlainTextEdit_hbSetSelectionMode( ::pPtr, nMode )
METHOD HBQPlainTextEdit:hbSetSelectionMode( nMode, lOn )
RETURN Qt_HBQPlainTextEdit_hbSetSelectionMode( ::pPtr, nMode, lOn )

View File

@@ -139,7 +139,7 @@ HB_FUNC( QT_HBQPLAINTEXTEDIT )
void hbCut()
void hbCopy()
void hbPaste()
void hbSetSelectionMode( int mode )
void hbSetSelectionMode( int mode, bool on )
</SLOTS>