2010-08-19 19:01 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com)
* contrib/hbqt/qtgui/hbqt_hbqgraphicsrectitem.cpp
* contrib/hbqt/qtgui/hbqt_hbqgraphicsrectitem.h
+ A lot of structural changes.
* contrib/hbide/idereportsmanager.prg
* contrib/hbide/idetoolbar.prg
+ Advanced: "Page" management and "objects" placement.
Page presented is now true to A4 size with margins.
Objects placement is achieved to be dropped exactly at the cursor position.
To play with: try to drag "Rect" node in "Data" tree onto page surface.
Use multiple iterations, move at will the rectangles.
This commit is contained in:
@@ -16,6 +16,20 @@
|
||||
The license applies to all entries newer than 2009-04-28.
|
||||
*/
|
||||
|
||||
2010-08-19 19:01 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com)
|
||||
* contrib/hbqt/qtgui/hbqt_hbqgraphicsrectitem.cpp
|
||||
* contrib/hbqt/qtgui/hbqt_hbqgraphicsrectitem.h
|
||||
+ A lot of structural changes.
|
||||
|
||||
* contrib/hbide/idereportsmanager.prg
|
||||
* contrib/hbide/idetoolbar.prg
|
||||
+ Advanced: "Page" management and "objects" placement.
|
||||
Page presented is now true to A4 size with margins.
|
||||
Objects placement is achieved to be dropped exactly at the cursor position.
|
||||
|
||||
To play with: try to drag "Rect" node in "Data" tree onto page surface.
|
||||
Use multiple iterations, move at will the rectangles.
|
||||
|
||||
2010-08-19 14:28 UTC+0200 Viktor Szakats (harbour.01 syenar.hu)
|
||||
* package/mpkg_win_nightly.bat
|
||||
% Minor.
|
||||
|
||||
@@ -69,6 +69,8 @@
|
||||
#include "hbclass.ch"
|
||||
#include "hbqt.ch"
|
||||
|
||||
#define UNIT 0.1
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
|
||||
CLASS IdeReportsManager INHERIT IdeObject
|
||||
@@ -85,6 +87,8 @@ CLASS IdeReportsManager INHERIT IdeObject
|
||||
DATA qWidget2
|
||||
DATA qWidget3
|
||||
|
||||
DATA qPaper
|
||||
|
||||
DATA qSpliter
|
||||
DATA qLayoutD
|
||||
DATA qFrameL
|
||||
@@ -128,13 +132,20 @@ CLASS IdeReportsManager INHERIT IdeObject
|
||||
|
||||
DATA aStatusPnls INIT {}
|
||||
DATA aItems INIT {}
|
||||
DATA hItems INIT {=>}
|
||||
|
||||
DATA nHPxMM INIT 96 / 25.4
|
||||
DATA nVPxMM INIT 96 / 25.4
|
||||
DATA nPgWidth
|
||||
DATA nPgWidthP
|
||||
DATA nPgHeight
|
||||
DATA nPgHeightP
|
||||
|
||||
METHOD new( oIde )
|
||||
METHOD create( oIde )
|
||||
METHOD destroy()
|
||||
METHOD show()
|
||||
METHOD execEvent( cEvent, p )
|
||||
METHOD execEvent( cEvent, p, p1, p2 )
|
||||
METHOD buildToolbar()
|
||||
METHOD buildToolbarAlign()
|
||||
METHOD buildToolbarLeft()
|
||||
@@ -142,7 +153,9 @@ CLASS IdeReportsManager INHERIT IdeObject
|
||||
METHOD buildStatusBar()
|
||||
METHOD buildTabBar()
|
||||
METHOD buildDesignReport()
|
||||
METHOD addRect()
|
||||
METHOD setPageSize()
|
||||
METHOD setPaper()
|
||||
METHOD addRect( qPos, cType, cName )
|
||||
|
||||
ENDCLASS
|
||||
|
||||
@@ -218,40 +231,6 @@ METHOD IdeReportsManager:show()
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
|
||||
METHOD IdeReportsManager:execEvent( cEvent, p )
|
||||
LOCAL qEvent, qMime
|
||||
|
||||
SWITCH cEvent
|
||||
CASE "tabBar_currentChanged"
|
||||
IF !empty( ::qStack ) .AND. p < ::qStack:count()
|
||||
::qStack:setCurrentIndex( p )
|
||||
ENDIF
|
||||
EXIT
|
||||
CASE "buttonNew_clicked"
|
||||
EXIT
|
||||
CASE "buttonOpen_clicked"
|
||||
EXIT
|
||||
CASE "buttonSave_clicked"
|
||||
EXIT
|
||||
CASE "buttonClose_clicked"
|
||||
EXIT
|
||||
CASE "buttonPrint_clicked"
|
||||
EXIT
|
||||
CASE "viewWidget_dropEvent"
|
||||
qEvent := QDropEvent():from( p )
|
||||
qMime := QMimeData():from( qEvent:mimeData() )
|
||||
HB_TRACE( HB_TR_ALWAYS, "viewWidget_dropEvent", qMime:hasText(), qMime:hasImage(), qMime:hasColor() )
|
||||
EXIT
|
||||
CASE "viewWidget_dragEnterEvent"
|
||||
qEvent := QDragEnterEvent():from( p )
|
||||
qEvent:acceptProposedAction()
|
||||
EXIT
|
||||
ENDSWITCH
|
||||
|
||||
RETURN Self
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
|
||||
METHOD IdeReportsManager:buildDesignReport()
|
||||
STATIC qItem, qItmC
|
||||
|
||||
@@ -371,10 +350,12 @@ METHOD IdeReportsManager:buildDesignReport()
|
||||
//
|
||||
::qTreeData:setDragEnabled( .t. )
|
||||
|
||||
::setPageSize()
|
||||
|
||||
::qDesign := QFrame():new()
|
||||
::qScroll:setWidget( ::qDesign )
|
||||
::qDesign:setBackgroundRole( QPalette_Dark )
|
||||
::qDesign:setGeometry( QRect():new( 0, 0, 600, 900 ) )
|
||||
::qDesign:setGeometry( QRect():new( 0, 0, ::nPgWidth + 60, ::nPgHeight + 60 ) )
|
||||
|
||||
::qHRuler := QFrame():new( ::qDesign )
|
||||
::qHRuler:setGeometry( QRect():new( 30, 0, ::qDesign:width(), 15 ) )
|
||||
@@ -384,24 +365,13 @@ METHOD IdeReportsManager:buildDesignReport()
|
||||
::qVRuler:setGeometry( QRect():new( 0, 30, 15, ::qDesign:height() ) )
|
||||
|
||||
::qView := QGraphicsView():new( ::qDesign )
|
||||
::qView:setGeometry( QRect():new( 30, 30, ::qDesign:width() - 45, ::qDesign:height() - 45 ) )
|
||||
::qView:setGeometry( QRect():new( 30, 30, ::nPgWidth+5, ::nPgHeight+5 ) )
|
||||
|
||||
::qScene := QGraphicsScene():new( ::qView )
|
||||
|
||||
::qScene := QGraphicsScene():new()
|
||||
::qView:setScene( ::qScene )
|
||||
::qScene:setSceneRect_1( 10, 10, 200, 400 )
|
||||
#if 1
|
||||
::qView:setAcceptDrops( .t. )
|
||||
::qView:installEventFilter( ::pEvents )
|
||||
//::connect( ::qView, QEvent_DragEnter, {|p| ::execEvent( "viewWidget_dragEnterEvent", p ) } )
|
||||
::connect( ::qView, QEvent_GraphicsSceneDragEnter, {|p| ::execEvent( "viewWidget_dragEnterEvent", p ) } )
|
||||
//::connect( ::qView, QEvent_Drop , {|p| ::execEvent( "viewWidget_dropEvent" , p ) } )
|
||||
::connect( ::qView, QEvent_GraphicsSceneDrop , {|p| ::execEvent( "viewWidget_dropEvent" , p ) } )
|
||||
#else
|
||||
::qScene:installEventFilter( ::pEvents )
|
||||
::connect( ::qScene, QEvent_GraphicsSceneDragEnter, {|p| ::execEvent( "viewWidget_dragEnterEvent", p ) } )
|
||||
::connect( ::qScene, QEvent_Drop , {|p| ::execEvent( "viewWidget_dropEvent" , p ) } )
|
||||
#endif
|
||||
::addRect()
|
||||
::qScene:setSceneRect_1( 0, 0, ::nPgWidth, ::nPgHeight )
|
||||
::setPaper()
|
||||
|
||||
::qWidget1:show()
|
||||
::qWidget2:show()
|
||||
@@ -411,8 +381,155 @@ METHOD IdeReportsManager:buildDesignReport()
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
|
||||
METHOD IdeReportsManager:addRect()
|
||||
aadd( ::aItems, IdeGraphicsItem():new( Self, "Rect_1", "rect", ::qScene, { 10.0, 10.0, 200.0, 200.0 }, /*qPen*/, /*qBrush*/ ) )
|
||||
METHOD IdeReportsManager:setPageSize()
|
||||
LOCAL p, r, o
|
||||
|
||||
o := HBQGraphicsRectItem():new()
|
||||
o:hbSetBlock( {|p,p1,p2| ::execEvent( "graphicsPaper_block", p, p1, p2 ) } )
|
||||
o := NIL
|
||||
|
||||
p := QPrinter():new()
|
||||
|
||||
p:setPaperSize( QPrinter_A4 )
|
||||
p:setOutputFormat( QPrinter_PdfFormat )
|
||||
p:setOrientation( QPrinter_Portrait )
|
||||
|
||||
p:setFullPage( .t. )
|
||||
r := QRectF():from( p:paperRect_1( QPrinter_Millimeter ) )
|
||||
|
||||
::nPgWidth := r:width() * ::nHPxMM
|
||||
::nPgHeight := r:height() * ::nVPxMM
|
||||
|
||||
p:setFullPage( .f. )
|
||||
r := QRectF():from( p:paperRect_1( QPrinter_Millimeter ) )
|
||||
|
||||
::nPgWidthP := r:width() * ::nHPxMM
|
||||
::nPgHeightP := r:height() * ::nVPxMM
|
||||
|
||||
RETURN Self
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
|
||||
METHOD IdeReportsManager:execEvent( cEvent, p, p1, p2 )
|
||||
LOCAL qEvent, qMime
|
||||
|
||||
SWITCH cEvent
|
||||
CASE "graphicsPaper_block"
|
||||
IF p == 21001
|
||||
::nHPxMM := p1 / 25.4
|
||||
::nVPxMM := p2 / 25.4
|
||||
RETURN Self
|
||||
ENDIF
|
||||
|
||||
qEvent := QGraphicsSceneDragDropEvent():from( p1 )
|
||||
|
||||
DO CASE
|
||||
CASE p == QEvent_GraphicsSceneDragEnter
|
||||
qEvent:acceptProposedAction()
|
||||
|
||||
CASE p == QEvent_GraphicsSceneDragMove
|
||||
qEvent:acceptProposedAction()
|
||||
|
||||
CASE p == QEvent_GraphicsSceneDragLeave
|
||||
|
||||
CASE p == QEvent_GraphicsSceneDrop
|
||||
qMime := QMimeData():from( qEvent:mimeData() )
|
||||
IF qMime:hasFormat( "application/x-qabstractitemmodeldatalist" )
|
||||
HB_TRACE( HB_TR_ALWAYS, "application/x-toolbaricon", p2[ 1 ], p2[ 2 ], p2[ 3 ] )
|
||||
p2[ 2 ] := lower( p2[ 2 ] )
|
||||
IF p2[ 2 ] == "rect"
|
||||
::addRect( QPoint():from( qEvent:scenePos() ), "field" )
|
||||
ENDIF
|
||||
|
||||
ELSEIF qMime:hasFormat( "application/x-toolbaricon" )
|
||||
HB_TRACE( HB_TR_ALWAYS, "application/x-toolbaricon", qMime:data(), qMime:html() )
|
||||
ELSE
|
||||
ENDIF
|
||||
ENDCASE
|
||||
|
||||
EXIT
|
||||
CASE "tabBar_currentChanged"
|
||||
IF !empty( ::qStack ) .AND. p < ::qStack:count()
|
||||
::qStack:setCurrentIndex( p )
|
||||
ENDIF
|
||||
EXIT
|
||||
CASE "buttonNew_clicked"
|
||||
EXIT
|
||||
CASE "buttonOpen_clicked"
|
||||
EXIT
|
||||
CASE "buttonSave_clicked"
|
||||
EXIT
|
||||
CASE "buttonClose_clicked"
|
||||
EXIT
|
||||
CASE "buttonPrint_clicked"
|
||||
EXIT
|
||||
|
||||
ENDSWITCH
|
||||
|
||||
RETURN Self
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
|
||||
METHOD IdeReportsManager:setPaper()
|
||||
LOCAL qPen := QPen():new( "QColor", QColor():new( 0,240,255 ) )
|
||||
LOCAL qBrush := QBrush():new( "QColor", QColor():new( 245,245,245 ) )
|
||||
LOCAL nOffW, nOffH
|
||||
|
||||
::qPaper := HBQGraphicsRectItem():new()
|
||||
::qPaper:hbSetBlock( {|p,p1,p2| ::execEvent( "graphicsPaper_block", p, p1, p2 ) } )
|
||||
::qPaper:setFlag( QGraphicsItem_ItemIsMovable, .f. )
|
||||
::qPaper:setFlag( QGraphicsItem_ItemIsSelectable, .f. )
|
||||
::qPaper:setAcceptDrops( .t. )
|
||||
|
||||
::qPaper:setPen( qPen )
|
||||
::qPaper:setBrush( qBrush )
|
||||
|
||||
nOffW := ::nHPxMM * 10 // 10 mm
|
||||
nOffH := ::nVPxMM * 10 // 10 MM
|
||||
|
||||
::qPaper:setRect_1( nOffW, nOffH, ::nPgWidth - nOffW * 2, ::nPgHeight - nOffH * 2 )
|
||||
|
||||
::qScene:addItem( ::qPaper )
|
||||
|
||||
RETURN Self
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
|
||||
METHOD IdeReportsManager:addRect( qPos, cType, cName )
|
||||
LOCAL oWidget
|
||||
|
||||
STATIC nID := 0
|
||||
|
||||
STATIC nW := 400
|
||||
STATIC nH := 300
|
||||
|
||||
HB_SYMBOL_UNUSED( qPos )
|
||||
HB_SYMBOL_UNUSED( cType )
|
||||
|
||||
nW -= 30
|
||||
nH -= 30
|
||||
|
||||
DEFAULT cName TO "Rect_"
|
||||
cName += hb_ntos( ++nID )
|
||||
|
||||
oWidget := HBQGraphicsRectItem():new()
|
||||
oWidget:hbSetBlock( {|p,p1,p2| ::execEvent( "graphicsPaper_block", p, p1, p2 ) } )
|
||||
oWidget:setFlag( QGraphicsItem_ItemIsMovable , .t. )
|
||||
oWidget:setFlag( QGraphicsItem_ItemIsSelectable, .t. )
|
||||
* oWidget:setFlag( QGraphicsItem_ItemClipsChildrenToShape, .t. )
|
||||
* oWidget:setAcceptDrops( .t. )
|
||||
* oWidget:setAcceptHoverEvents( .t. )
|
||||
* oWidget:setPen( ::qPen )
|
||||
* oWidget:setBrush( ::qBrush )
|
||||
|
||||
::qScene:addItem( oWidget )
|
||||
|
||||
oWidget:setRect_1( 0, 0, nW, nH )
|
||||
IF !empty( qPos )
|
||||
oWidget:setPos( qPos )
|
||||
ENDIF
|
||||
|
||||
::hItems[ cName ] := oWidget
|
||||
RETURN Self
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
@@ -509,10 +626,10 @@ METHOD IdeReportsManager:buildToolbarLeft()
|
||||
::qToolbarL:orientation := Qt_Vertical
|
||||
::qToolbarL:create( "ReportManager_Left_Toolbar" )
|
||||
|
||||
::qToolbarL:addToolButton( "Image" , "Image" , hbide_image( "f-image" ), {|| ::execEvent( "buttonNew_clicked" ) }, .f., .t. )
|
||||
::qToolbarL:addToolButton( "Chart" , "Chart" , hbide_image( "f_chart" ), {|| ::execEvent( "buttonNew_clicked" ) }, .f., .t. )
|
||||
::qToolbarL:addToolButton( "Gradient", "Gradient", hbide_image( "f_gradient" ), {|| ::execEvent( "buttonNew_clicked" ) }, .f., .t. )
|
||||
::qToolbarL:addToolButton( "Barcode" , "Barcode" , hbide_image( "f_barcode" ), {|| ::execEvent( "buttonNew_clicked" ) }, .f., .t. )
|
||||
::qToolbarL:addToolButton( "Image" , "Image" , hbide_image( "f-image" ), {|| ::execEvent( "buttonNew_clicked" ) }, .t., .t. )
|
||||
::qToolbarL:addToolButton( "Chart" , "Chart" , hbide_image( "f_chart" ), {|| ::execEvent( "buttonNew_clicked" ) }, .t., .t. )
|
||||
::qToolbarL:addToolButton( "Gradient", "Gradient", hbide_image( "f_gradient" ), {|| ::execEvent( "buttonNew_clicked" ) }, .t., .t. )
|
||||
::qToolbarL:addToolButton( "Barcode" , "Barcode" , hbide_image( "f_barcode" ), {|| ::execEvent( "buttonNew_clicked" ) }, .t., .t. )
|
||||
|
||||
RETURN Self
|
||||
|
||||
@@ -544,140 +661,4 @@ METHOD IdeReportsManager:buildStatusBar()
|
||||
RETURN Self
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
//
|
||||
// Class IdeReportItem()
|
||||
//
|
||||
/*----------------------------------------------------------------------*/
|
||||
|
||||
CLASS IdeGraphicsItem INHERIT IdeObject
|
||||
|
||||
DATA oRM
|
||||
DATA oWidget
|
||||
|
||||
DATA cName INIT ""
|
||||
DATA cType
|
||||
DATA qScene
|
||||
DATA qPen
|
||||
DATA qBrush
|
||||
DATA aRect //INIT { 20,20,60,20 }
|
||||
DATA isMovable INIT .t.
|
||||
DATA isSelectable INIT .f.
|
||||
DATA isFocusable INIT .f.
|
||||
|
||||
METHOD new( oRM, cName, cType, qScene, aRect, qPen, qBrush )
|
||||
METHOD execEvent( cEvent, p, p1, p2 )
|
||||
METHOD addRect()
|
||||
|
||||
ERROR HANDLER onError( ... )
|
||||
|
||||
ENDCLASS
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
|
||||
METHOD IdeGraphicsItem:new( oRM, cName, cType, qScene, aRect, qPen, qBrush )
|
||||
|
||||
::oRM := oRM
|
||||
::cName := cName
|
||||
::cType := lower( cType )
|
||||
::qScene := qScene
|
||||
|
||||
SWITCH ::cType
|
||||
CASE "band"
|
||||
EXIT
|
||||
CASE "rect"
|
||||
DEFAULT aRect TO { 20, 20, 100, 100 }
|
||||
DEFAULT qPen TO QPen():new( "QColor", QColor():new( 0,0,255 ) )
|
||||
DEFAULT qBrush TO QBrush():new( Qt_yellow )
|
||||
|
||||
::aRect := aRect
|
||||
::qPen := qPen
|
||||
::qBrush := qBrush
|
||||
|
||||
::addRect()
|
||||
|
||||
EXIT
|
||||
CASE "field"
|
||||
EXIT
|
||||
CASE "barcode"
|
||||
EXIT
|
||||
CASE "image"
|
||||
EXIT
|
||||
CASE "textbox"
|
||||
EXIT
|
||||
CASE "textline"
|
||||
EXIT
|
||||
CASE "gradient"
|
||||
EXIT
|
||||
CASE "chart"
|
||||
EXIT
|
||||
ENDSWITCH
|
||||
|
||||
RETURN Self
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
|
||||
METHOD IdeGraphicsItem:execEvent( cEvent, p, p1, p2 )
|
||||
LOCAL qEvent, qMime
|
||||
|
||||
SWITCH cEvent
|
||||
CASE "graphicsItem_block"
|
||||
qEvent := QGraphicsSceneDragDropEvent():from( p1 )
|
||||
|
||||
DO CASE
|
||||
CASE p == QEvent_GraphicsSceneDragEnter
|
||||
qEvent:acceptProposedAction()
|
||||
|
||||
CASE p == QEvent_GraphicsSceneDragMove
|
||||
|
||||
CASE p == QEvent_GraphicsSceneDragLeave
|
||||
|
||||
CASE p == QEvent_GraphicsSceneDrop
|
||||
qMime := QMimeData():from( qEvent:mimeData() )
|
||||
IF qMime:hasFormat( "application/x-qabstractitemmodeldatalist" )
|
||||
HB_TRACE( HB_TR_ALWAYS, "application/x-toolbaricon", p2[ 1 ], p2[ 2 ], p2[ 3 ] )
|
||||
p2[ 2 ] := lower( p2[ 2 ] )
|
||||
IF p2[ 2 ] == "rect"
|
||||
::oRM:addRect()
|
||||
ENDIF
|
||||
|
||||
ELSEIF qMime:hasFormat( "application/x-toolbaricon" )
|
||||
HB_TRACE( HB_TR_ALWAYS, "application/x-toolbaricon", qMime:data(), qMime:html() )
|
||||
ELSE
|
||||
ENDIF
|
||||
ENDCASE
|
||||
EXIT
|
||||
CASE "viewWidget_dragEnterEvent"
|
||||
|
||||
EXIT
|
||||
ENDSWITCH
|
||||
RETURN Self
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
|
||||
METHOD IdeGraphicsItem:onError( ... )
|
||||
LOCAL cMsg := __GetMessage()
|
||||
IF SubStr( cMsg, 1, 1 ) == "_"
|
||||
cMsg := SubStr( cMsg, 2 )
|
||||
ENDIF
|
||||
RETURN ::oWidget:&cMsg( ... )
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
|
||||
METHOD IdeGraphicsItem:addRect()
|
||||
|
||||
::oWidget := HBQGraphicsRectItem():new()
|
||||
::oWidget:hbSetBlock( {|p,p1,p2| ::execEvent( "graphicsItem_block", p, p1, p2 ) } )
|
||||
::oWidget:setFlag( QGraphicsItem_ItemIsMovable, .t. )
|
||||
::oWidget:setFlag( QGraphicsItem_ItemIsSelectable, .t. )
|
||||
::oWidget:setAcceptDrops( .t. )
|
||||
::oWidget:setAcceptHoverEvents( .t. )
|
||||
::oWidget:setRect_1( ::aRect[ 1 ], ::aRect[ 2 ], ::aRect[ 3 ], ::aRect[ 4 ] )
|
||||
::oWidget:setPen( ::qPen )
|
||||
::oWidget:setBrush( ::qBrush )
|
||||
|
||||
::qScene:addItem( ::oWidget )
|
||||
|
||||
RETURN Self
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
|
||||
|
||||
@@ -156,43 +156,48 @@ METHOD IdeToolbar:destroy()
|
||||
/*----------------------------------------------------------------------*/
|
||||
|
||||
METHOD IdeToolbar:execEvent( cEvent, p, p1 )
|
||||
LOCAL qEvent
|
||||
LOCAL qEvent, qRC
|
||||
|
||||
HB_SYMBOL_UNUSED( p )
|
||||
qEvent := QMouseEvent():from( p )
|
||||
|
||||
SWITCH cEvent
|
||||
CASE "QEvent_MouseLeave"
|
||||
EXIT
|
||||
|
||||
CASE "QEvent_MouseMove"
|
||||
::qByte := QByteArray():new( ::hItems[ p1 ]:objectName() )
|
||||
qRC := QRect():from( ( QRect():new( ::qPos:x() - 5, ::qPos:y() - 5, 10, 10 ) ):normalized() )
|
||||
|
||||
::qMime := QMimeData():new()
|
||||
::qMime:setData( "application/x-toolbaricon", ::qByte )
|
||||
//::qMime:setText( ::hItems[ p1 ]:objectName() )
|
||||
::qMime:setHtml( ::hItems[ p1 ]:objectName() )
|
||||
IF qRC:contains( qEvent:pos() )
|
||||
::qByte := QByteArray():new( ::hItems[ p1 ]:objectName() )
|
||||
|
||||
//::qPix := QPixmap():new( hbide_image( "f-generic" ) )
|
||||
::qPix := QPixmap():from( QIcon():from( ::hItems[ p1 ]:icon ):pixmap_1( 16,16 ) )
|
||||
::qMime := QMimeData():new()
|
||||
::qMime:setData( "application/x-toolbaricon", ::qByte )
|
||||
::qMime:setHtml( ::hItems[ p1 ]:objectName() )
|
||||
|
||||
::qDrag := QDrag():new( hbide_setIde():oDlg:oWidget )
|
||||
::qDrag:setMimeData( ::qMime )
|
||||
::qDrag:setPixmap( ::qPix )
|
||||
::qDrag:setHotSpot( QPoint():new( 5,5 ) )
|
||||
::qDrag:setDragCursor( ::qPix, Qt_MoveAction )
|
||||
::qPix := QPixmap():from( QIcon():from( ::hItems[ p1 ]:icon ):pixmap_1( 16,16 ) )
|
||||
|
||||
::qDropAction := ::qDrag:exec( Qt_MoveAction )
|
||||
::qDrag := NIL
|
||||
::qDrag := QDrag():new( hbide_setIde():oDlg:oWidget )
|
||||
::qDrag:setMimeData( ::qMime )
|
||||
::qDrag:setPixmap( ::qPix )
|
||||
::qDrag:setHotSpot( QPoint():new( 15,15 ) )
|
||||
::qDrag:setDragCursor( ::qPix, Qt_MoveAction )
|
||||
|
||||
qEvent := QMouseEvent():new( QEvent_MouseButtonDblClick, QPoint():new( 1,1 ), Qt_LeftButton, Qt_LeftButton, 0 )
|
||||
QApplication():new():postEvent( ::hItems[ p1 ], qEvent )
|
||||
::qDropAction := ::qDrag:exec( Qt_MoveAction )
|
||||
|
||||
::qDrag := NIL
|
||||
::qPos := NIL
|
||||
::hItems[ p1 ]:setChecked( .f. )
|
||||
::hItems[ p1 ]:setWindowState( 0 )
|
||||
ENDIF
|
||||
EXIT
|
||||
|
||||
CASE "QEvent_MouseRelease"
|
||||
HB_TRACE( HB_TR_ALWAYS, "QEvent_MouseRelease" )
|
||||
::qDrag := NIL
|
||||
EXIT
|
||||
|
||||
CASE "QEvent_MousePress"
|
||||
::qPos := QPoint():from( qEvent:pos() )
|
||||
EXIT
|
||||
|
||||
CASE "buttonNew_clicked"
|
||||
|
||||
@@ -61,16 +61,19 @@
|
||||
HBQGraphicsRectItem::HBQGraphicsRectItem( QGraphicsItem * parent ) : QGraphicsRectItem( parent )
|
||||
{
|
||||
block = NULL;
|
||||
resizeMode = RESIZE_MODE_NONE;
|
||||
}
|
||||
|
||||
HBQGraphicsRectItem::HBQGraphicsRectItem( const QRectF & rect, QGraphicsItem * parent ) : QGraphicsRectItem( rect, parent )
|
||||
{
|
||||
block = NULL;
|
||||
resizeMode = RESIZE_MODE_NONE;
|
||||
}
|
||||
|
||||
HBQGraphicsRectItem::HBQGraphicsRectItem( qreal x, qreal y, qreal width, qreal height, QGraphicsItem * parent ) : QGraphicsRectItem( x, y, width, height, parent )
|
||||
{
|
||||
block = NULL;
|
||||
resizeMode = RESIZE_MODE_NONE;
|
||||
}
|
||||
|
||||
HBQGraphicsRectItem::~HBQGraphicsRectItem()
|
||||
@@ -87,6 +90,16 @@ void HBQGraphicsRectItem::hbSetBlock( PHB_ITEM b )
|
||||
if( b )
|
||||
{
|
||||
block = hb_itemNew( b );
|
||||
|
||||
QDesktopWidget * qWid = new QDesktopWidget();
|
||||
|
||||
PHB_ITEM p1 = hb_itemPutNI( NULL, 21001 );
|
||||
PHB_ITEM p2 = hb_itemPutNI( NULL, qWid->screen()->physicalDpiX() );
|
||||
PHB_ITEM p3 = hb_itemPutNI( NULL, qWid->screen()->physicalDpiY() );
|
||||
hb_vmEvalBlockV( block, 3, p1, p2, p3 );
|
||||
hb_itemRelease( p1 );
|
||||
hb_itemRelease( p2 );
|
||||
hb_itemRelease( p3 );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,4 +186,141 @@ void HBQGraphicsRectItem::dropEvent( QGraphicsSceneDragDropEvent * event )
|
||||
QGraphicsItem::dropEvent( event );
|
||||
}
|
||||
|
||||
#endif
|
||||
void HBQGraphicsRectItem::mousePressEvent( QGraphicsSceneMouseEvent * event )
|
||||
{
|
||||
oGeometry = geometry();
|
||||
|
||||
foreach( QGraphicsItem * item, scene()->items() )
|
||||
{
|
||||
if( item->zValue() == 1 ){
|
||||
item->setZValue( 0 );
|
||||
}
|
||||
}
|
||||
setZValue( 1 );
|
||||
|
||||
if( event->buttons() == Qt::LeftButton ){
|
||||
resizeMode = determineResizeMode( event->pos() );
|
||||
}
|
||||
else {
|
||||
resizeMode = RESIZE_MODE_NONE;
|
||||
}
|
||||
|
||||
if( resizeMode == RESIZE_MODE_NONE ){
|
||||
setCursor( QCursor( Qt::ClosedHandCursor ) );
|
||||
}
|
||||
|
||||
QGraphicsItem::mousePressEvent( event );
|
||||
|
||||
if( event->buttons() == Qt::LeftButton ){
|
||||
// emit( itemSelected( this, event->pos() ) );
|
||||
}
|
||||
}
|
||||
|
||||
void HBQGraphicsRectItem::mouseReleaseEvent( QGraphicsSceneMouseEvent * event )
|
||||
{
|
||||
QGraphicsItem::mouseReleaseEvent( event );
|
||||
resizeMode = RESIZE_MODE_NONE;
|
||||
|
||||
QRectF nGeometry = geometry();
|
||||
if( nGeometry != oGeometry ){
|
||||
// emit( geometryChanged( this, nGeometry, oGeometry ) );
|
||||
}
|
||||
}
|
||||
|
||||
void HBQGraphicsRectItem::mouseMoveEvent( QGraphicsSceneMouseEvent * event )
|
||||
{
|
||||
if( event->buttons() == Qt::LeftButton )
|
||||
{
|
||||
if( resizeMode == RESIZE_MODE_NONE ){
|
||||
setPos( pos() + QPoint( ( int ) ( event->scenePos().x() - event->lastScenePos().x() ),
|
||||
( int ) ( event->scenePos().y() - event->lastScenePos().y() ) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
if( resizeMode & RESIZE_MODE_LEFT ){
|
||||
setPos( pos().x() + event->scenePos().x() - event->lastScenePos().x(), pos().y() );
|
||||
setWidth( width() + event->lastScenePos().x() - event->scenePos().x() );
|
||||
}
|
||||
if( resizeMode & RESIZE_MODE_TOP ){
|
||||
setPos( pos().x(), pos().y() + event->scenePos().y() - event->lastScenePos().y() );
|
||||
setHeight( height() + event->lastScenePos().y() - event->scenePos().y() );
|
||||
}
|
||||
if( resizeMode & RESIZE_MODE_RIGHT ){
|
||||
setWidth( ( int ) ( width() + event->scenePos().x() - event->lastScenePos().x() ) );
|
||||
}
|
||||
if( resizeMode & RESIZE_MODE_BOTTOM ){
|
||||
setHeight( ( int ) ( height() + event->scenePos().y() - event->lastScenePos().y() ) );
|
||||
}
|
||||
if( width() < 5 ){
|
||||
setWidth( 5 );
|
||||
}
|
||||
if( height() < 5 ){
|
||||
setHeight( 5 );
|
||||
}
|
||||
}
|
||||
}
|
||||
QGraphicsItem::mouseMoveEvent( event );
|
||||
}
|
||||
|
||||
int HBQGraphicsRectItem::determineResizeMode( const QPointF & pos )
|
||||
{
|
||||
int resizeModes = RESIZE_MODE_LEFT | RESIZE_MODE_TOP | RESIZE_MODE_RIGHT | RESIZE_MODE_BOTTOM ;
|
||||
int mode = RESIZE_MODE_NONE;
|
||||
|
||||
QRectF topRect( 0, 0, width(), 2 );
|
||||
QRectF leftRect( 0, 0, 2, height() );
|
||||
QRectF bottomRect( 0, height() - 2, width(), 2 );
|
||||
QRectF rightRect( width() - 2, 0, width(), height() );
|
||||
|
||||
if( resizeModes & RESIZE_MODE_LEFT && leftRect.contains( pos ) ){
|
||||
mode |= RESIZE_MODE_LEFT;
|
||||
}
|
||||
if( resizeModes & RESIZE_MODE_TOP && topRect.contains( pos ) ){
|
||||
mode |= RESIZE_MODE_TOP;
|
||||
}
|
||||
if( resizeModes & RESIZE_MODE_RIGHT && rightRect.contains( pos ) ){
|
||||
mode |= RESIZE_MODE_RIGHT;
|
||||
}
|
||||
if( resizeModes & RESIZE_MODE_BOTTOM && bottomRect.contains( pos ) ){
|
||||
mode |= RESIZE_MODE_BOTTOM;
|
||||
}
|
||||
return mode;
|
||||
}
|
||||
|
||||
QRectF HBQGraphicsRectItem::geometry()
|
||||
{
|
||||
return QRectF( pos().x(), pos().y(), width(), height() );
|
||||
}
|
||||
|
||||
void HBQGraphicsRectItem::setGeometry( const QRectF & rect )
|
||||
{
|
||||
setPos( rect.x(), rect.y() );
|
||||
setWidth( rect.width() );
|
||||
setHeight( rect.height() );
|
||||
}
|
||||
|
||||
void HBQGraphicsRectItem::setWidth( qreal width )
|
||||
{
|
||||
// prepareGeometryChange();
|
||||
iWidth = width;
|
||||
//emit( geometryChanged( geometry() ) );
|
||||
}
|
||||
|
||||
void HBQGraphicsRectItem::setHeight( qreal height )
|
||||
{
|
||||
// prepareGeometryChange();
|
||||
iHeight = height;
|
||||
//emit( geometryChanged( geometry() ) );
|
||||
}
|
||||
|
||||
qreal HBQGraphicsRectItem::width() const
|
||||
{
|
||||
return iWidth;
|
||||
}
|
||||
|
||||
qreal HBQGraphicsRectItem::height() const
|
||||
{
|
||||
return iHeight;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -56,12 +56,19 @@
|
||||
#include "hbqtgui.h"
|
||||
|
||||
#include <QtGui/QGraphicsRectItem>
|
||||
#include <QtGui/QGraphicsScene>
|
||||
#include <QtGui/QGraphicsSceneDragDropEvent>
|
||||
#include <QtGui/QTreeWidget>
|
||||
#include <QtGui/QDesktopWidget>
|
||||
#include <QtCore/QModelIndex>
|
||||
#include <QtCore/QEvent>
|
||||
#include <QtCore/QMimeData>
|
||||
|
||||
#define RESIZE_MODE_NONE 0
|
||||
#define RESIZE_MODE_LEFT 1
|
||||
#define RESIZE_MODE_TOP 2
|
||||
#define RESIZE_MODE_RIGHT 4
|
||||
#define RESIZE_MODE_BOTTOM 8
|
||||
|
||||
class HBQGraphicsRectItem : public QGraphicsRectItem
|
||||
{
|
||||
@@ -73,18 +80,33 @@ public:
|
||||
~HBQGraphicsRectItem();
|
||||
|
||||
PHB_ITEM block;
|
||||
int determineResizeMode( const QPointF & pos );
|
||||
|
||||
private:
|
||||
bool bYes;
|
||||
int resizeMode;
|
||||
QRectF oGeometry;
|
||||
qreal iWidth;
|
||||
qreal iHeight;
|
||||
|
||||
protected:
|
||||
void dragEnterEvent( QGraphicsSceneDragDropEvent * event );
|
||||
void dragLeaveEvent( QGraphicsSceneDragDropEvent * event );
|
||||
void dragMoveEvent( QGraphicsSceneDragDropEvent * event );
|
||||
void dropEvent( QGraphicsSceneDragDropEvent * event );
|
||||
//
|
||||
void mousePressEvent( QGraphicsSceneMouseEvent * event );
|
||||
void mouseReleaseEvent( QGraphicsSceneMouseEvent * event );
|
||||
void mouseMoveEvent( QGraphicsSceneMouseEvent * event );
|
||||
|
||||
public slots:
|
||||
void hbSetBlock( PHB_ITEM block );
|
||||
QRectF geometry();
|
||||
void setGeometry( const QRectF & rect );
|
||||
qreal width() const;
|
||||
void setWidth( qreal width );
|
||||
qreal height() const;
|
||||
void setHeight( qreal height );
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user