diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 1242305fee..562c602ae5 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -17,6 +17,18 @@ past entries belonging to author(s): Viktor Szakats. */ +2010-04-29 02:00 UTC-0800 Pritpal Bedi (pritpal@vouchcac.com) + * contrib/hbxbp/xbplistbox.prg + % Fixed a nasty bug. + + * contrib/hbqt/hbqt_hbqplaintextedit.cpp + * contrib/hbqt/hbqt_hbqplaintextedit.h + + * contrib/hbqt/hbqt_hbslots.cpp + + + Implemented: horizontal ruler in the editor instances at the top + of the window. Opinions are welcome about its base and tab colors. + 2010-04-29 10:51 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/src/vm/strapi.c * harbour/include/hbapistr.h diff --git a/harbour/contrib/hbqt/hbqt_hbqplaintextedit.cpp b/harbour/contrib/hbqt/hbqt_hbqplaintextedit.cpp index 3a5c2f2004..fce95a6e70 100644 --- a/harbour/contrib/hbqt/hbqt_hbqplaintextedit.cpp +++ b/harbour/contrib/hbqt/hbqt_hbqplaintextedit.cpp @@ -77,6 +77,10 @@ HBQPlainTextEdit::HBQPlainTextEdit( QWidget * parent ) : QPlainTextEdit( parent ) { + m_currentLineColor.setNamedColor( "#e8e8ff" ); + m_lineAreaBkColor.setNamedColor( "#e4e4e4" ); + m_horzRulerBkColor.setNamedColor( "whitesmoke" ); + spaces = 3; spacesTab = ""; styleHightlighter = "prg"; @@ -86,6 +90,7 @@ HBQPlainTextEdit::HBQPlainTextEdit( QWidget * parent ) : QPlainTextEdit( parent columnBegins = -1; columnEnds = -1; isColumnSelectionEnabled = false; + horzRuler = new HorzRuler( this ); connect( this, SIGNAL( blockCountChanged( int ) ) , this, SLOT( hbUpdateLineNumberAreaWidth( int ) ) ); connect( this, SIGNAL( updateRequest( const QRect &, int ) ), this, SLOT( hbUpdateLineNumberArea( const QRect &, int ) ) ); @@ -93,9 +98,10 @@ HBQPlainTextEdit::HBQPlainTextEdit( QWidget * parent ) : QPlainTextEdit( parent hbUpdateLineNumberAreaWidth( 0 ); connect( this, SIGNAL( cursorPositionChanged() ) , this, SLOT( hbSlotCursorPositionChanged() ) ); + connect( this, SIGNAL( cursorPositionChanged() ) , this, SLOT( hbUpdateHorzRuler() ) ); - m_currentLineColor.setNamedColor( "#e8e8ff" ); - m_lineAreaBkColor.setNamedColor( "#e4e4e4" ); + horzRuler->setFrameShape( QFrame::Panel ); + horzRuler->setFrameShadow( QFrame::Sunken ); } HBQPlainTextEdit::~HBQPlainTextEdit() @@ -260,7 +266,9 @@ void HBQPlainTextEdit::resizeEvent( QResizeEvent *e ) QPlainTextEdit::resizeEvent( e ); QRect cr = contentsRect(); - lineNumberArea->setGeometry( QRect( cr.left(), cr.top(), hbLineNumberAreaWidth(), cr.height() ) ); + lineNumberArea->setGeometry( QRect( cr.left(), cr.top() + HORZRULER_HEIGHT, hbLineNumberAreaWidth(), cr.height() ) ); + + horzRuler->setGeometry( QRect( cr.left(), cr.top(), cr.width(), HORZRULER_HEIGHT ) ); } void HBQPlainTextEdit::focusInEvent( QFocusEvent * event ) @@ -404,6 +412,43 @@ QBrush HBQPlainTextEdit::brushForBookmark( int index ) return br; } +void HBQPlainTextEdit::horzRulerPaintEvent( QPaintEvent *event ) +{ + QRect cr = event->rect(); + QPainter painter( horzRuler ); + + painter.fillRect( cr, m_horzRulerBkColor ); + painter.setPen( Qt::gray ); + painter.drawLine( cr.left(), cr.bottom(), cr.width(), cr.bottom() ); + painter.setPen( Qt::black ); + int fontWidth = fontMetrics().averageCharWidth(); + int fontHeight = fontMetrics().height(); + int left = cr.left() + ( fontWidth / 2 ) + ( lineNumberArea->isVisible() ? lineNumberArea->width() : 0 ); + int i; + for( i = 0; left < cr.width(); i++ ) + { + if( i % 10 == 0 ) + { + painter.drawLine( left, cr.bottom()-3, left, cr.bottom()-5 ); + QString number = QString::number( i ); + painter.drawText( left - fontWidth, cr.top()-2, fontWidth * 2, fontHeight, Qt::AlignCenter, number ); + } + else if( i % 5 == 0 ) + { + painter.drawLine( left, cr.bottom()-3, left, cr.bottom()-5 ); + } + else + { + painter.drawLine( left, cr.bottom()-3, left, cr.bottom()-4 ); + } + if( i == textCursor().columnNumber() ) + { + painter.fillRect( QRect( left, cr.top() + 2, fontWidth, fontHeight - 6 ), QColor( 198,198,198 ) ); + } + left += fontWidth; + } +} + void HBQPlainTextEdit::lineNumberAreaPaintEvent( QPaintEvent *event ) { QPainter painter( lineNumberArea ); @@ -570,14 +615,19 @@ void HBQPlainTextEdit::hbUpdateLineNumberAreaWidth( int ) { if( numberBlock ) { - setViewportMargins( hbLineNumberAreaWidth(), 0, 0, 0 ); + setViewportMargins( hbLineNumberAreaWidth(), HORZRULER_HEIGHT, 0, 0 ); } else { - setViewportMargins( 0, 0, 0, 0 ); + setViewportMargins( 0, HORZRULER_HEIGHT, 0, 0 ); } } +void HBQPlainTextEdit::hbUpdateHorzRuler() +{ + horzRuler->update(); +} + void HBQPlainTextEdit::hbUpdateLineNumberArea( const QRect &rect, int dy ) { if( dy ) diff --git a/harbour/contrib/hbqt/hbqt_hbqplaintextedit.h b/harbour/contrib/hbqt/hbqt_hbqplaintextedit.h index f7d1ab7069..ec82bf2d1b 100644 --- a/harbour/contrib/hbqt/hbqt_hbqplaintextedit.h +++ b/harbour/contrib/hbqt/hbqt_hbqplaintextedit.h @@ -70,7 +70,10 @@ #include "hbqt_hbqsyntaxhighlighter.h" +#define HORZRULER_HEIGHT 20 + class LineNumberArea; +class HorzRuler; class HBQPlainTextEdit : public QPlainTextEdit { @@ -83,11 +86,13 @@ public: PHB_ITEM block; QColor m_currentLineColor; QColor m_lineAreaBkColor; + QColor m_horzRulerBkColor; long m_matchingBegin; long m_matchingEnd; void paintEvent( QPaintEvent * event ); void lineNumberAreaPaintEvent( QPaintEvent * event ); + void horzRulerPaintEvent( QPaintEvent * event ); HBQSyntaxHighlighter * highlighter; @@ -113,6 +118,7 @@ private: QVector bookMark; QList bookMarksGoto; QWidget * lineNumberArea; + QFrame * horzRuler; int spaces; bool numberBlock; bool highlightCurLine; @@ -168,6 +174,7 @@ public slots: private slots: void hbSlotCursorPositionChanged(); void hbUpdateLineNumberArea( const QRect &, int ); + void hbUpdateHorzRuler(); void hbPaintColumnSelection( QPaintEvent * ); }; @@ -195,5 +202,30 @@ private: HBQPlainTextEdit *codeEditor; }; + + +class HorzRuler : public QFrame +{ +public: + HorzRuler( HBQPlainTextEdit * editor = 0 ) : QFrame( editor ) + { + codeEditor = editor; + } + +protected: + QSize sizeHint() const + { + return QSize( codeEditor->viewport()->width(), HORZRULER_HEIGHT ); + } + +private: + void paintEvent( QPaintEvent *event ) + { + codeEditor->horzRulerPaintEvent( event ); + } + + HBQPlainTextEdit *codeEditor; +}; + #endif diff --git a/harbour/contrib/hbqt/hbqt_hbslots.cpp b/harbour/contrib/hbqt/hbqt_hbslots.cpp index 3e60b7268d..8eec8d4a34 100644 --- a/harbour/contrib/hbqt/hbqt_hbslots.cpp +++ b/harbour/contrib/hbqt/hbqt_hbslots.cpp @@ -113,7 +113,7 @@ static bool connect_signal( QString signal, QObject * object, HBSlots * t_slots if( signal == ( QString ) "itemSelectionChanged()" ) return object->connect( object, SIGNAL( itemSelectionChanged() ), t_slots, SLOT( itemSelectionChanged() ), Qt::AutoConnection ); /* QListWidget */ if( signal == ( QString ) "currentRowChanged(int)" ) return object->connect( object, SIGNAL( currentRowChanged( int ) ), t_slots, SLOT( currentRowChanged( int ) ), Qt::AutoConnection ); - if( signal == ( QString ) "currentTextChanged(QString,currentText)" ) return object->connect( object, SIGNAL( currentTextChanged( const QString & ) ), t_slots, SLOT( currentTextChanged( const QString & ) ), Qt::AutoConnection ); + if( signal == ( QString ) "currentTextChanged(QString)" ) return object->connect( object, SIGNAL( currentTextChanged( const QString & ) ), t_slots, SLOT( currentTextChanged( const QString & ) ), Qt::AutoConnection ); if( signal == ( QString ) "currentItemChanged(QLWItem,QLWItem)" ) return object->connect( object, SIGNAL( currentItemChanged( QListWidgetItem *, QListWidgetItem * ) ), t_slots, SLOT( currentItemChanged( QListWidgetItem *, QListWidgetItem * ) ), Qt::AutoConnection ); if( signal == ( QString ) "itemActivated(QLWItem)" ) return object->connect( object, SIGNAL( itemActivated( QListWidgetItem * ) ), t_slots, SLOT( itemActivated( QListWidgetItem * ) ), Qt::AutoConnection ); if( signal == ( QString ) "itemChanged(QLWItem)" ) return object->connect( object, SIGNAL( itemChanged( QListWidgetItem * ) ), t_slots, SLOT( itemChanged( QListWidgetItem * ) ), Qt::AutoConnection ); @@ -376,7 +376,7 @@ static bool disconnect_signal( QObject * object, const char * signal ) /* QListWidget */ if( signal == ( QString ) "currentItemChanged(QLWItem,QLWItem)" ) return object->disconnect( SIGNAL( currentItemChanged( QListWidgetItem *, QListWidgetItem * ) ) ); if( signal == ( QString ) "currentRowChanged(int)" ) return object->disconnect( SIGNAL( currentRowChanged( int ) ) ); - if( signal == ( QString ) "currentTextChanged(QString,currentText)" ) return object->disconnect( SIGNAL( currentTextChanged( const QString & ) ) ); + if( signal == ( QString ) "currentTextChanged(QString)" ) return object->disconnect( SIGNAL( currentTextChanged( const QString & ) ) ); if( signal == ( QString ) "itemActivated(QLWItem)" ) return object->disconnect( SIGNAL( itemActivated( QListWidgetItem * ) ) ); if( signal == ( QString ) "itemChanged(QLWItem)" ) return object->disconnect( SIGNAL( itemChanged( QListWidgetItem * ) ) ); if( signal == ( QString ) "itemClicked(QLWItem)" ) return object->disconnect( SIGNAL( itemClicked( QListWidgetItem * ) ) ); diff --git a/harbour/contrib/hbxbp/xbplistbox.prg b/harbour/contrib/hbxbp/xbplistbox.prg index 7774cb1293..aac06f61fe 100644 --- a/harbour/contrib/hbxbp/xbplistbox.prg +++ b/harbour/contrib/hbxbp/xbplistbox.prg @@ -414,7 +414,7 @@ METHOD XbpListBox:setItem( nIndex, cItem ) METHOD XbpListBox:setItemColorFG( nIndex, aRGB ) IF hb_isNumeric( nIndex ) .AND. nIndex > 0 .AND. nIndex <= len( ::aItems ) - IF ::nOldIndex > 0 .AND. nIndex <= len( ::aItems ) + IF ::nOldIndex > 0 .AND. ::nOldIndex <= len( ::aItems ) ::aItems[ ::nOldIndex ]:setForeGround( QBrush():new( "QColor", QColor():new( 0,0,0 ) ) ) ENDIF ::aItems[ nIndex ]:setForeGround( QBrush():new( "QColor", QColor():new( aRGB[ 1 ], aRGB[ 2 ], aRGB[ 3 ] ) ) )