From f5194be5a0758bd9d6ce2e417e895104fb4a50c9 Mon Sep 17 00:00:00 2001 From: Pritpal Bedi Date: Mon, 10 Aug 2009 00:17:07 +0000 Subject: [PATCH] 2009-08-09 17:10 UTC-0800 Pritpal Bedi (pritpal@vouchcac.com) * contrib/hbqt/hbqt.ch + Added more constants. * contrib/hbxbp/xbpbrowse.prg ! Column display protocol tweaked to provide a descent view. + Implemented ::sizeCols() instance variable of XbpBrowse() object. This provides for switching off the resizing behavior of the columns. * contrib/hbxbp/tests/demoxbp.prg ! Demonstrated the above facts. --- harbour/ChangeLog | 13 ++++- harbour/contrib/hbqt/hbqt.ch | 16 +++++- harbour/contrib/hbxbp/tests/demoxbp.prg | 42 ++++++++-------- harbour/contrib/hbxbp/xbpbrowse.prg | 65 +++++++++++++++++++++++-- 4 files changed, 110 insertions(+), 26 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index be2ed0244d..30c01e8d87 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -17,6 +17,17 @@ past entries belonging to author(s): Viktor Szakats. */ +2009-08-09 17:10 UTC-0800 Pritpal Bedi (pritpal@vouchcac.com) + * contrib/hbqt/hbqt.ch + + Added more constants. + * contrib/hbxbp/xbpbrowse.prg + ! Column display protocol tweaked to provide a descent view. + + Implemented ::sizeCols() instance variable of XbpBrowse() object. + This provides for switching off the resizing behavior of the columns. + + * contrib/hbxbp/tests/demoxbp.prg + ! Demonstrated the above facts. + 2009-08-10 02:07 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) * ChangeLog ! Typos in prev entry. @@ -73,7 +84,7 @@ * config/global.cf ! Deleted two debug lines from prev commit. -2009-08-09 26:15 UTC-0800 Pritpal Bedi (pritpal@vouchcac.com) +2009-08-09 16:15 UTC-0800 Pritpal Bedi (pritpal@vouchcac.com) * contrib/hbqt/hbqt_slots.cpp * contrib/hbxbp/xbpbrowse.prg + Implemented XbpColumn():type == XBPCOL_TYPE_ICONFILE. diff --git a/harbour/contrib/hbqt/hbqt.ch b/harbour/contrib/hbqt/hbqt.ch index 7b113d2f45..7f16e1fa4a 100644 --- a/harbour/contrib/hbqt/hbqt.ch +++ b/harbour/contrib/hbqt/hbqt.ch @@ -2046,7 +2046,16 @@ // #define QAbstractItemView_SingleSelection 1 // When the user selects an item, any already-selected item becomes unselected, and the user cannot unselect the selected item by clicking on it. #define QAbstractItemView_ContiguousSelection 4 // When the user selects an item in the usual way, the selection is cleared and the new item selected. However, if the user presses the Shift key while clicking on an item, all items between the current item and the clicked item are selected or unselected, depending on the state of the clicked item. -#define QAbstractItemView_ExtendedSelection 3 // When the user selects an item in the usual way, the selection is cleared and the new item selected. However, if the user presses the Ctrl key when clicking on an item, the clicked item gets toggled and all other items are left untouched. If the user presses the Shift key while clicking on an item, all items between the current item and the clicked item are selected or unselected, depending on the state of the clicked item. Multiple items can be selected by dragging the mouse over them. +#define QAbstractItemView_ExtendedSelection 3 // When the user selects an item in the usual way, + // the selection is cleared and the new item + // selected. However, if the user presses the Ctrl key + // when clicking on an item, the clicked item gets toggled + // and all other items are left untouched. + // If the user presses the Shift key while clicking on + // an item, all items between the current item and the + // clicked item are selected or unselected, depending on + // the state of the clicked item. Multiple items can be + // selected by dragging the mouse over them. #define QAbstractItemView_MultiSelection 2 // When the user selects an item in the usual way, the selection status of that item is toggled and the other items are left alone. Multiple items can be toggled by dragging the mouse over them. #define QAbstractItemView_NoSelection 0 // Items cannot be selected. // The most commonly used modes are SingleSelection and ExtendedSelection. @@ -2062,6 +2071,11 @@ #define QAbstractItemView_CollapsingState 5 // The user is closing a branch of items. #define QAbstractItemView_AnimatingState 6 // The item view is performing an animation. +#define QHeaderView_Interactive 0 // The user can resize the section. The section can also be resized programmatically using resizeSection(). The section size defaults to defaultSectionSize. (See also cascadingSectionResizes.) +#define QHeaderView_Fixed 2 // The user cannot resize the section. The section can only be resized programmatically using resizeSection(). The section size defaults to defaultSectionSize. +#define QHeaderView_Stretch 1 // QHeaderView will automatically resize the section to fill the available space. The size cannot be changed by the user or programmatically. +#define QHeaderView_ResizeToContents 3 // QHeaderView will automatically resize the section to its optimal size based on the contents of the entire column or row. The size cannot be changed by the user or programmatically. (This value was introduced in 4.2) + /*----------------------------------------------------------------------*/ #define _HBQT_CH diff --git a/harbour/contrib/hbxbp/tests/demoxbp.prg b/harbour/contrib/hbxbp/tests/demoxbp.prg index 40d0c20e1b..552f984fb6 100644 --- a/harbour/contrib/hbxbp/tests/demoxbp.prg +++ b/harbour/contrib/hbxbp/tests/demoxbp.prg @@ -1587,6 +1587,7 @@ FUNCTION Build_Browse( oWnd ) oXbpBrowse:setFontCompoundName( "10.Courier" ) //oXbpBrowse:hScroll := .f. //oXbpBrowse:vScroll := .f. + oXbpBrowse:sizeCols := .f. oXbpBrowse:cursorMode := XBPBRW_CURSOR_ROW oXbpBrowse:skipBlock := {|n| DbSkipBlock( n ) } @@ -1602,6 +1603,27 @@ FUNCTION Build_Browse( oWnd ) oXbpBrowse:headerRbDown := {|mp1, mp2, o| mp1 := mp1, xbp_debug( o:getColumn( mp2 ):heading ) } + aPresParam := {} + aadd( aPresParam, { XBP_PP_COL_HA_CAPTION , "Icons" } ) + aadd( aPresParam, { XBP_PP_COL_HA_FGCLR , GRA_CLR_CYAN } ) + aadd( aPresParam, { XBP_PP_COL_HA_BGCLR , GRA_CLR_BLUE } ) + aadd( aPresParam, { XBP_PP_COL_HA_HEIGHT , 20 } ) + aadd( aPresParam, { XBP_PP_COL_DA_CELLALIGNMENT, XBPALIGN_HCENTER } ) + aadd( aPresParam, { XBP_PP_COL_DA_FGCLR , GRA_CLR_BLACK } ) + aadd( aPresParam, { XBP_PP_COL_DA_BGCLR , RGB( 5,240,210 ) } ) + aadd( aPresParam, { XBP_PP_COL_DA_HILITE_FGCLR , GRA_CLR_WHITE } ) + aadd( aPresParam, { XBP_PP_COL_DA_HILITE_BGCLR , GRA_CLR_DARKGRAY } ) + aadd( aPresParam, { XBP_PP_COL_DA_ROWHEIGHT , 20 } ) + aadd( aPresParam, { XBP_PP_COL_DA_ROWWIDTH , 40 } ) + // + oXbpColumn := XbpColumn():new() + oXbpColumn:type := XBPCOL_TYPE_FILEICON + cPath := hb_DirBase() + hb_osPathSeparator() + oXbpColumn:dataLink := {|n| n := recno(), IF( n%3 == 0, cPath + "abs3.png", IF( n%5 == 0, cPath + "copy.png", cPath + "vr.png" ) ) } + oXbpColumn:create( , , , , aPresParam ) + // + oXbpBrowse:addColumn( oXbpColumn ) + aPresParam := {} aadd( aPresParam, { XBP_PP_COL_HA_CAPTION , "Last" } ) aadd( aPresParam, { XBP_PP_COL_HA_FGCLR , XBPSYSCLR_WINDOWSTATICTEXT } ) @@ -1721,26 +1743,6 @@ FUNCTION Build_Browse( oWnd ) // oXbpBrowse:addColumn( oXbpColumn ) - aPresParam := {} - aadd( aPresParam, { XBP_PP_COL_HA_CAPTION , "Icons" } ) - aadd( aPresParam, { XBP_PP_COL_HA_FGCLR , GRA_CLR_CYAN } ) - aadd( aPresParam, { XBP_PP_COL_HA_BGCLR , GRA_CLR_BLUE } ) - aadd( aPresParam, { XBP_PP_COL_HA_HEIGHT , 20 } ) - aadd( aPresParam, { XBP_PP_COL_DA_FGCLR , GRA_CLR_BLACK } ) - aadd( aPresParam, { XBP_PP_COL_DA_BGCLR , RGB( 5,240,210 ) } ) - aadd( aPresParam, { XBP_PP_COL_DA_HILITE_FGCLR , GRA_CLR_WHITE } ) - aadd( aPresParam, { XBP_PP_COL_DA_HILITE_BGCLR , GRA_CLR_DARKGRAY } ) - aadd( aPresParam, { XBP_PP_COL_DA_ROWHEIGHT , 20 } ) - aadd( aPresParam, { XBP_PP_COL_DA_ROWWIDTH , 40 } ) - // - oXbpColumn := XbpColumn():new() - oXbpColumn:type := XBPCOL_TYPE_FILEICON - cPath := hb_DirBase() + hb_osPathSeparator() - oXbpColumn:dataLink := {|n| n := recno(), IF( n%3 == 0, cPath + "abs3.png", IF( n%5 == 0, cPath + "copy.png", cPath + "vr.png" ) ) } - oXbpColumn:create( , , , , aPresParam ) - // - oXbpBrowse:addColumn( oXbpColumn ) - RETURN nil /*----------------------------------------------------------------------*/ diff --git a/harbour/contrib/hbxbp/xbpbrowse.prg b/harbour/contrib/hbxbp/xbpbrowse.prg index d890a8a5ac..de54321c89 100644 --- a/harbour/contrib/hbxbp/xbpbrowse.prg +++ b/harbour/contrib/hbxbp/xbpbrowse.prg @@ -407,7 +407,9 @@ EXPORTED: DATA nCursorMode INIT XBPBRW_CURSOR_CELL METHOD cursorMode SETGET - DATA sizeCols INIT .T. + DATA lSizeCols INIT .T. + METHOD sizeCols SETGET + DATA softTrack INIT .T. ENDCLASS @@ -448,7 +450,6 @@ METHOD XbpBrowse:create( oParent, oOwner, aPos, aSize, aPresParams, lVisible ) ::oWidget:setGridStyle( Qt_DotLine ) /* to be based on column definition */ ::oWidget:setSelectionMode( QAbstractItemView_SingleSelection ) ::oWidget:setSelectionBehavior( IF( ::cursorMode == XBPBRW_CURSOR_ROW, QAbstractItemView_SelectRows, QAbstractItemView_SelectItems ) ) - ::oWidget:selectRow( 0 ) /* Connect Keyboard Events */ ::connect( ::pWidget, "keyPressEvent()" , {|o,p| ::exeBlock( 1, p, o ) } ) @@ -816,6 +817,7 @@ METHOD XbpBrowse:supplyInfo( nInfo, p2, p3 ) ::forceStable() ::setVertScrollBarRange( .t. ) ::setHorzScrollBarRange( .f. ) + ::oWidget:selectRow( ::rowPos - 1 ) ENDIF IF ::columns[ p3 ]:type == XBPCOL_TYPE_FILEICON RETURN trim( ::cellValue( p2, p3 ) ) @@ -830,6 +832,7 @@ METHOD XbpBrowse:supplyInfo( nInfo, p2, p3 ) ::forceStable() ::setVertScrollBarRange( .t. ) ::setHorzScrollBarRange( .f. ) + ::oWidget:selectRow( ::rowPos - 1 ) ENDIF RETURN ::cellValue( p2, p3 ) ELSE @@ -944,6 +947,18 @@ METHOD XbpBrowse:vScroll( lYes ) /*----------------------------------------------------------------------*/ +METHOD XbpBrowse:sizeCols( lYes ) + + IF hb_isLogical( lYes ) + ::lSizeCols := lYes + ::setUnstable() + ::configure( 128 ) + ENDIF + + RETURN Self + +/*----------------------------------------------------------------------*/ + METHOD XbpBrowse:cursorMode( nMode ) IF hb_isNumeric( nMode ) @@ -1190,6 +1205,9 @@ METHOD doConfigure() CLASS XbpBrowse ::oWidget:setRowHeight( i-1, nMaxCellH ) NEXT + /* Implement Column Resixig Mode */ + ::oHorzHeaderView:setResizeMode( IF( ::lSizeCols, QHeaderView_Interactive, QHeaderView_Fixed ) ) + /* Set column widths */ oFontMetrics := QFontMetrics():new( "QFont", ::oWidget:font() ) // @@ -1202,6 +1220,11 @@ METHOD doConfigure() CLASS XbpBrowse //::oWidget:setColumnWidth( i-1, oFontMetrics:width( xVal, -1 ) + 8 ) ::oHorzHeaderView:resizeSection( i-1, oFontMetrics:width( xVal, -1 ) + 8 ) ENDIF + IF i == len( ::columns ) + ::oHorzHeaderView:setResizeMode_1( i-1, QHeaderView_Stretch ) + ELSE + ::oHorzHeaderView:setResizeMode_1( i-1, IF( ::lSizeCols, QHeaderView_Interactive, QHeaderView_Fixed ) ) + ENDIF NEXT ENDIF @@ -3397,6 +3420,8 @@ CREATE CLASS XbpColumn INHERIT XbpWindow, XbpDataRef ENDCLASS +/*----------------------------------------------------------------------*/ + METHOD datalink( bBlock ) CLASS XbpColumn IF bBlock != NIL @@ -3405,6 +3430,8 @@ METHOD datalink( bBlock ) CLASS XbpColumn RETURN ::bBlock +/*----------------------------------------------------------------------*/ + METHOD block( bBlock ) CLASS XbpColumn IF bBlock != NIL @@ -3413,6 +3440,8 @@ METHOD block( bBlock ) CLASS XbpColumn RETURN ::bBlock +/*----------------------------------------------------------------------*/ + METHOD colorBlock( bColorBlock ) CLASS XbpColumn IF bColorBlock != NIL @@ -3421,6 +3450,8 @@ METHOD colorBlock( bColorBlock ) CLASS XbpColumn RETURN ::bColorBlock +/*----------------------------------------------------------------------*/ + METHOD defColor( aDefColor ) CLASS XbpColumn IF aDefColor != NIL @@ -3429,6 +3460,8 @@ METHOD defColor( aDefColor ) CLASS XbpColumn RETURN ::aDefColor +/*----------------------------------------------------------------------*/ + METHOD colSep( cColSep ) CLASS XbpColumn IF cColSep != NIL @@ -3437,6 +3470,8 @@ METHOD colSep( cColSep ) CLASS XbpColumn RETURN ::cColSep +/*----------------------------------------------------------------------*/ + METHOD heading( cHeading ) CLASS XbpColumn IF cHeading != NIL @@ -3445,6 +3480,8 @@ METHOD heading( cHeading ) CLASS XbpColumn RETURN ::cHeading +/*----------------------------------------------------------------------*/ + METHOD footing( cFooting ) CLASS XbpColumn IF cFooting != NIL @@ -3453,6 +3490,8 @@ METHOD footing( cFooting ) CLASS XbpColumn RETURN ::cFooting +/*----------------------------------------------------------------------*/ + METHOD headSep( cHeadSep ) CLASS XbpColumn IF cHeadSep != NIL @@ -3461,6 +3500,8 @@ METHOD headSep( cHeadSep ) CLASS XbpColumn RETURN ::cHeadSep +/*----------------------------------------------------------------------*/ + METHOD footSep( cFootSep ) CLASS XbpColumn IF cFootSep != NIL @@ -3469,6 +3510,8 @@ METHOD footSep( cFootSep ) CLASS XbpColumn RETURN ::cFootSep +/*----------------------------------------------------------------------*/ + METHOD width( nWidth ) CLASS XbpColumn IF nWidth != NIL @@ -3477,6 +3520,8 @@ METHOD width( nWidth ) CLASS XbpColumn RETURN ::nWidth +/*----------------------------------------------------------------------*/ + METHOD preBlock( bPreBlock ) CLASS XbpColumn IF bPreBlock != NIL @@ -3485,6 +3530,8 @@ METHOD preBlock( bPreBlock ) CLASS XbpColumn RETURN ::bPreBlock +/*----------------------------------------------------------------------*/ + METHOD postBlock( bPostBlock ) CLASS XbpColumn IF bPostBlock != NIL @@ -3493,6 +3540,8 @@ METHOD postBlock( bPostBlock ) CLASS XbpColumn RETURN ::bPostBlock +/*----------------------------------------------------------------------*/ + METHOD setStyle( nStyle, lNewValue ) CLASS XbpColumn IF nStyle > Len( ::aSetStyle ) .AND. nStyle <= 4096 ASize( ::aSetStyle, nStyle ) @@ -3504,6 +3553,8 @@ METHOD setStyle( nStyle, lNewValue ) CLASS XbpColumn RETURN ::aSetStyle[ nStyle ] +/*----------------------------------------------------------------------*/ + METHOD new( cHeading, bBlock ) CLASS XbpColumn ::cHeading := cHeading @@ -3511,6 +3562,8 @@ METHOD new( cHeading, bBlock ) CLASS XbpColumn RETURN Self +/*----------------------------------------------------------------------*/ + METHOD create( oParent, oOwner, aPos, aSize, aPresParams, lVisible ) CLASS XbpColumn LOCAL n, xVar //, cVar, p, l @@ -3524,8 +3577,12 @@ METHOD create( oParent, oOwner, aPos, aSize, aPresParams, lVisible ) CLASS XbpCo ::valtype := valtype( xVar ) ::blankVariable := IF( ::valtype == "N", 0, IF( ::valtype == "D", ctod( "" ), IF( ::valtype == "L", .f., "" ) ) ) - ::alignment := IF( ::valtype == "N", Qt_AlignRight, IF( ::valtype $ "DL", Qt_AlignHCenter, Qt_AlignLeft ) ) - ::alignment += Qt_AlignVCenter + IF ( n := ascan( ::aPresParams, {|e_| e_[ 1 ] == XBP_PP_COL_DA_CELLALIGNMENT } ) ) > 0 + ::alignment := ::aPresParams[ n,2 ] + ELSE + ::alignment := IF( ::valtype == "N", Qt_AlignRight, IF( ::valtype $ "DL", Qt_AlignHCenter, Qt_AlignLeft ) ) + ::alignment += Qt_AlignVCenter + ENDIF /* Heading Area */ IF ( n := ascan( ::aPresParams, {|e_| e_[ 1 ] == XBP_PP_COL_HA_FGCLR } ) ) > 0