From 56e816eefb11b85ad8aa85ffc2ee1696a80b14f9 Mon Sep 17 00:00:00 2001 From: Pritpal Bedi Date: Wed, 17 Jun 2009 06:17:23 +0000 Subject: [PATCH] 2009-06-16 23:06 UTC-0800 Pritpal Bedi (pritpal@vouchcac.com) * harbour/contrib/hbqt/hbqt.ch * harbour/contrib/hbqt/hbqt_slots.cpp * harbour/contrib/hbqt/hbqt_slots.h * harbour/contrib/hbqt/moc_slots.cpp ! Greatly improved SIGNAL/SLOT mechanism. Now SIGNAL to SLOT connection is almost instant no matter how many widgets the application is employing. ! Implemented to relaase code blocks and reuse vacant slots. It reduces the memory leakage considerably. * harbour/contrib/hbqt/tests/demoqt.prg ! Commented out non-available Signal/Slot pair reported by linus distro. --- harbour/ChangeLog | 14 + harbour/contrib/hbqt/hbqt.ch | 21 ++ harbour/contrib/hbqt/hbqt_slots.cpp | 483 ++++++++++++++------------ harbour/contrib/hbqt/hbqt_slots.h | 84 +++-- harbour/contrib/hbqt/moc_slots.cpp | 222 ++++++------ harbour/contrib/hbqt/tests/demoqt.prg | 4 +- 6 files changed, 464 insertions(+), 364 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 4c722797ed..38711af6eb 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -17,6 +17,20 @@ past entries belonging to author(s): Viktor Szakats. */ +2009-06-16 23:06 UTC-0800 Pritpal Bedi (pritpal@vouchcac.com) + * harbour/contrib/hbqt/hbqt.ch + * harbour/contrib/hbqt/hbqt_slots.cpp + * harbour/contrib/hbqt/hbqt_slots.h + * harbour/contrib/hbqt/moc_slots.cpp + ! Greatly improved SIGNAL/SLOT mechanism. + Now SIGNAL to SLOT connection is almost instant no matter how many + widgets the application is employing. + ! Implemented to relaase code blocks and reuse vacant slots. + It reduces the memory leakage considerably. + + * harbour/contrib/hbqt/tests/demoqt.prg + ! Commented out non-available Signal/Slot pair reported by linus distro. + 2009-06-17 00:05 UTC+0300 Mindaugas Kavaliauskas (dbtopas/at/dbtopas.lt) * harbour/contrib/hbwin/axcore.c ! fixed GPF on ActiveX application exit caused by invalid diff --git a/harbour/contrib/hbqt/hbqt.ch b/harbour/contrib/hbqt/hbqt.ch index 8d95f15997..ae665b9554 100644 --- a/harbour/contrib/hbqt/hbqt.ch +++ b/harbour/contrib/hbqt/hbqt.ch @@ -64,6 +64,9 @@ /*----------------------------------------------------------------------*/ /*----------------------------------------------------------------------*/ +#ifndef _HBQT_CH + + #define QEvent_None 0 // Not an event. #define QEvent_AccessibilityDescription 130 // Used to query accessibility description texts (QAccessibleEvent). #define QEvent_AccessibilityHelp 119 // Used to query accessibility help texts (QAccessibleEvent). @@ -223,4 +226,22 @@ #define QPalette_LinkVisited 15 // A text color used for already visited hyperlinks. By default, the linkvisited color is Qt_magenta. #define QPalette_NoRole 17 // No role; this special role is often used to indicate that a role has not been assigned. + +#define QAbstractSlider_SliderNoAction 0 +#define QAbstractSlider_SliderSingleStepAdd 1 +#define QAbstractSlider_SliderSingleStepSub 2 +#define QAbstractSlider_SliderPageStepAdd 3 +#define QAbstractSlider_SliderPageStepSub 4 +#define QAbstractSlider_SliderToMinimum 5 +#define QAbstractSlider_SliderToMaximum 6 +#define QAbstractSlider_SliderMove 7 + +#define QAbstractSlider_SliderRangeChange 0 +#define QAbstractSlider_SliderOrientationChange 1 +#define QAbstractSlider_SliderStepsChange 2 +#define QAbstractSlider_SliderValueChange 3 + /*----------------------------------------------------------------------*/ + +#define _HBQT_CH +#endif \ No newline at end of file diff --git a/harbour/contrib/hbqt/hbqt_slots.cpp b/harbour/contrib/hbqt/hbqt_slots.cpp index e9ef04a583..5c80978170 100644 --- a/harbour/contrib/hbqt/hbqt_slots.cpp +++ b/harbour/contrib/hbqt/hbqt_slots.cpp @@ -52,7 +52,6 @@ */ /*----------------------------------------------------------------------*/ - #include "hbapi.h" #include "hbvm.h" #include "hbapiitm.h" @@ -61,6 +60,10 @@ #if QT_VERSION >= 0x040500 +#if 0 +#include +#endif + #include "hbqt_slots.h" #include @@ -69,128 +72,127 @@ #include #include -#define HBQT_EVT_CLICKED 1 -#define HBQT_EVT_TRIGGERED 2 -#define HBQT_EVT_TRIGGERED_BOOL 3 -#define HBQT_EVT_HOVERED 4 -#define HBQT_EVT_STATECHANGED 5 -#define HBQT_EVT_PRESSED 6 -#define HBQT_EVT_RELEASED 7 - /*----------------------------------------------------------------------*/ static Slots *s = NULL; /*----------------------------------------------------------------------*/ -static void SlotsExec( QWidget* widget, QString event, PHB_ITEM pItem ) -{ - for( int i = 0; i < s->list1.size(); ++i ) - { - if( ( QWidget* ) s->list1.at( i ) == widget ) - { - if( ( ( QString ) s->list2.at( i ) == event ) && ( ( bool ) s->list4.at( i ) == true ) ) - { - PHB_ITEM pWidget = hb_itemPutPtr( NULL, ( QWidget* ) widget ); - hb_vmEvalBlockV( ( PHB_ITEM ) s->list3.at( i ), 1, pWidget ); - hb_itemRelease( pWidget ); - } - } - } - if( pItem != NULL ) - { - hb_itemRelease( pItem ); - } -} - -static void SlotsExecAction( QAction* widget, QString event, PHB_ITEM pItem ) -{ - for( int i = 0; i < s->list1.size(); ++i ) - { - if( ( QAction* ) s->list5.at( i ) == widget ) - { - if( ( ( QString ) s->list2.at( i ) == event ) && ( ( bool ) s->list4.at( i ) == true ) ) - { - PHB_ITEM pWidget = hb_itemPutPtr( NULL, ( QAction* ) widget ); - hb_vmEvalBlockV( ( PHB_ITEM ) s->list3.at( i ), 1, pWidget ); - hb_itemRelease( pWidget ); - } - } - } - if( pItem != NULL ) - { - hb_itemRelease( pItem ); - } -} - -static void SlotsExecInt( QWidget* widget, QString event, PHB_ITEM pItem, int iValue ) -{ - for( int i = 0; i < s->list1.size(); ++i ) - { - if( ( QWidget* ) s->list1.at( i ) == widget ) - { - if( ( ( QString ) s->list2.at( i ) == event ) && ( ( bool ) s->list4.at( i ) == true ) ) - { - PHB_ITEM pWidget = hb_itemPutPtr( NULL, ( QWidget* ) widget ); - PHB_ITEM pState = hb_itemPutNI( NULL, iValue ); - hb_vmEvalBlockV( ( PHB_ITEM ) s->list3.at( i ), 2, pWidget, pState ); - hb_itemRelease( pWidget ); - hb_itemRelease( pState ); - } - } - } - if( pItem != NULL ) - { - hb_itemRelease( pItem ); - } -} - -static void SlotsExecModel( QWidget* widget, QString event, PHB_ITEM pItem, const QModelIndex & index ) -{ - for( int i = 0; i < s->list1.size(); ++i ) - { - if( ( QWidget* ) s->list1.at( i ) == widget ) - { - if( ( ( QString ) s->list2.at( i ) == event ) && ( ( bool ) s->list4.at( i ) == true ) ) - { - PHB_ITEM pWidget = hb_itemPutPtr( NULL, ( QWidget* ) widget ); - PHB_ITEM pState = hb_itemPutPtr( NULL, ( QModelIndex * ) new QModelIndex( index ) ); - hb_vmEvalBlockV( ( PHB_ITEM ) s->list3.at( i ), 2, pWidget, pState ); - hb_itemRelease( pWidget ); - hb_itemRelease( pState ); - } - } - } - if( pItem != NULL ) - { - hb_itemRelease( pItem ); - } -} - Slots::Slots( QObject* parent ) : QObject( parent ) { } - Slots::~Slots() { } +static void SlotsExec( QWidget* widget, char* event ) +{ + if( widget ) + { + int i = widget->property( event ).toInt(); + if( ( i > 0 ) && ( s->listActv.at( i-1 ) == true ) ) + { + PHB_ITEM pWidget = hb_itemPutPtr( NULL, ( QWidget* ) widget ); + hb_vmEvalBlockV( ( PHB_ITEM ) s->listBlock.at( i-1 ), 1, pWidget ); + hb_itemRelease( pWidget ); + } + } +} + +static void SlotsExecAction( QAction* widget, char* event ) +{ + if( widget ) + { + int i = widget->property( event ).toInt(); + if( ( i > 0 ) && ( s->listActv.at( i-1 ) == true ) ) + { + PHB_ITEM pWidget = hb_itemPutPtr( NULL, ( QAction* ) widget ); + hb_vmEvalBlockV( ( PHB_ITEM ) s->listBlock.at( i-1 ), 1, pWidget ); + hb_itemRelease( pWidget ); + } + } +} + +static void SlotsExecInt( QWidget* widget, char* event, int iValue ) +{ + if( widget ) + { + int i = widget->property( event ).toInt(); + if( ( i > 0 ) && ( s->listActv.at( i-1 ) == true ) ) + { + PHB_ITEM pWidget = hb_itemPutPtr( NULL, ( QWidget* ) widget ); + PHB_ITEM pState = hb_itemPutNI( NULL, iValue ); + hb_vmEvalBlockV( ( PHB_ITEM ) s->listBlock.at( i-1 ), 2, pWidget, pState ); + hb_itemRelease( pWidget ); + hb_itemRelease( pState ); + } + } +} + +static void SlotsExecIntInt( QWidget* widget, char* event, int iValue1, int iValue2 ) +{ + if( widget ) + { + int i = widget->property( event ).toInt(); + if( i > 0 && ( s->listActv.at( i-1 ) == true ) ) + { + PHB_ITEM pWidget = hb_itemPutPtr( NULL, ( QWidget* ) widget ); + PHB_ITEM pValue1 = hb_itemPutNI( NULL, iValue1 ); + PHB_ITEM pValue2 = hb_itemPutNI( NULL, iValue2 ); + hb_vmEvalBlockV( ( PHB_ITEM ) s->listBlock.at( i-1 ), 3, pWidget, pValue1, pValue2 ); + hb_itemRelease( pWidget ); + hb_itemRelease( pValue1 ); + hb_itemRelease( pValue2 ); + } + } +} + +static void SlotsExecModel( QWidget* widget, char* event, const QModelIndex & index ) +{ + if( widget ) + { + int i = widget->property( event ).toInt(); + if( ( i > 0 ) && ( s->listActv.at( i-1 ) == true ) ) + { + PHB_ITEM pWidget = hb_itemPutPtr( NULL, ( QWidget* ) widget ); + PHB_ITEM pState = hb_itemPutPtr( NULL, ( QModelIndex * ) new QModelIndex( index ) ); + hb_vmEvalBlockV( ( PHB_ITEM ) s->listBlock.at( i-1 ), 2, pWidget, pState ); + hb_itemRelease( pWidget ); + hb_itemRelease( pState ); + } + } +} + +static void SlotsExecMouseEvent( QWidget* widget, char* event, QMouseEvent* mevent ) +{ + if( widget ) + { + int i = widget->property( event ).toInt(); + if( ( i > 0 ) && ( s->listActv.at( i-1 ) == true ) ) + { + PHB_ITEM pWidget = hb_itemPutPtr( NULL, ( QWidget * ) widget ); + PHB_ITEM pEvent = hb_itemPutPtr( NULL, mevent ); + hb_vmEvalBlockV( ( PHB_ITEM ) s->listBlock.at( i-1 ), 2, pWidget, pEvent ); + hb_itemRelease( pWidget ); + hb_itemRelease( pEvent ); + } + } +} + bool Slots::event( QEvent * event ) { bool bAccepted = true; QObject *widget = qobject_cast( sender() ); - for( int i = 0; i < list1.size(); ++i ) + if( widget ) { - if( ( QObject* ) list1.at( i ) == ( QObject* ) widget ) + int i = widget->property( "event()" ).toInt(); + if( ( i > 0 ) && ( s->listActv.at( i-1 ) == true ) ) { - if( ( ( QString ) list2.at( i ) == ( QString ) "event()" ) && ( ( bool ) list4.at( i ) == true ) ) - { - PHB_ITEM pWidget = hb_itemPutPtr( NULL, ( QWidget * ) widget ); - PHB_ITEM pEvent = hb_itemPutPtr( NULL, event ); - bAccepted = hb_vmEvalBlockV( ( PHB_ITEM ) list3.at( i ), 2, pWidget, pEvent ); - hb_itemRelease( pWidget ); - hb_itemRelease( pEvent ); - } + PHB_ITEM pWidget = hb_itemPutPtr( NULL, ( QWidget * ) widget ); + PHB_ITEM pEvent = hb_itemPutPtr( NULL, event ); + bAccepted = hb_vmEvalBlockV( ( PHB_ITEM ) listBlock.at( i-1 ), 2, pWidget, pEvent ); + hb_itemRelease( pWidget ); + hb_itemRelease( pEvent ); } } return bAccepted; @@ -199,37 +201,33 @@ bool Slots::event( QEvent * event ) void Slots::keyPressEvent( QKeyEvent * event ) { QObject *widget = qobject_cast( sender() ); - for( int i = 0; i < list1.size(); ++i ) + if( widget ) { - if( ( QObject* ) list1.at( i ) == ( QObject* ) widget ) + int i = widget->property( "keyPressEvent()" ).toInt(); + if( ( i > 0 ) && ( s->listActv.at( i-1 ) == true ) ) { - if( ( ( QString ) list2.at( i ) == ( QString ) "keyPressEvent()" ) && ( ( bool ) list4.at( i ) == true ) ) - { - PHB_ITEM pWidget = hb_itemPutPtr( NULL, ( QWidget * ) widget ); - PHB_ITEM pEvent = hb_itemPutPtr( NULL, event ); - hb_vmEvalBlockV( ( PHB_ITEM ) list3.at( i ), 2, pWidget, pEvent ); - hb_itemRelease( pWidget ); - hb_itemRelease( pEvent ); - } + PHB_ITEM pWidget = hb_itemPutPtr( NULL, ( QWidget * ) widget ); + PHB_ITEM pEvent = hb_itemPutPtr( NULL, event ); + hb_vmEvalBlockV( ( PHB_ITEM ) listBlock.at( i-1 ), 2, pWidget, pEvent ); + hb_itemRelease( pWidget ); + hb_itemRelease( pEvent ); } } } -void Slots::mouseMoveEvent( QMouseEvent * event ) +void Slots::triggered( bool checked ) { QObject *widget = qobject_cast( sender() ); - for( int i = 0; i < list1.size(); ++i ) + if( widget ) { - if( ( QObject* ) list1.at( i ) == ( QObject* ) widget ) + int i = widget->property( "triggered(bool)" ).toInt(); + if( ( i > 0 ) && ( s->listActv.at( i-1 ) == true ) ) { - if( ( ( QString ) list2.at( i ) == ( QString ) "mouseMoveEvent()" ) && ( ( bool ) list4.at( i ) == true ) ) - { - PHB_ITEM pWidget = hb_itemPutPtr( NULL, ( QWidget * ) widget ); - PHB_ITEM pEvent = hb_itemPutPtr( NULL, event ); - hb_vmEvalBlockV( ( PHB_ITEM ) list3.at( i ), 2, pWidget, pEvent ); - hb_itemRelease( pWidget ); - hb_itemRelease( pEvent ); - } + PHB_ITEM pWidget = hb_itemPutPtr( NULL, ( QObject * ) widget ); + PHB_ITEM pChecked = hb_itemPutL( NULL, checked ); + hb_vmEvalBlockV( ( PHB_ITEM ) listBlock.at( i-1 ), 2, pWidget, pChecked ); + hb_itemRelease( pWidget ); + hb_itemRelease( pChecked ); } } } @@ -237,132 +235,133 @@ void Slots::mouseMoveEvent( QMouseEvent * event ) void Slots::hovered( QAction * action ) { QObject *widget = qobject_cast( sender() ); - for( int i = 0; i < list1.size(); ++i ) + if( widget ) { - if( ( QObject* ) list1.at( i ) == ( QObject* ) widget ) + int i = widget->property( "hovered(action)" ).toInt(); + if( ( i > 0 ) && ( s->listActv.at( i-1 ) == true ) ) { - if( ( ( QString ) list2.at( i ) == ( QString ) "hovered(action)" ) && ( ( bool ) list4.at( i ) == true ) ) - { - PHB_ITEM pWidget = hb_itemPutPtr( NULL, ( QWidget * ) widget ); - PHB_ITEM pEvent = hb_itemPutPtr( NULL, action ); - hb_vmEvalBlockV( ( PHB_ITEM ) list3.at( i ), 2, pWidget, pEvent ); - hb_itemRelease( pWidget ); - hb_itemRelease( pEvent ); - } + PHB_ITEM pWidget = hb_itemPutPtr( NULL, ( QWidget * ) widget ); + PHB_ITEM pEvent = hb_itemPutPtr( NULL, action ); + hb_vmEvalBlockV( ( PHB_ITEM ) listBlock.at( i-1 ), 2, pWidget, pEvent ); + hb_itemRelease( pWidget ); + hb_itemRelease( pEvent ); } } } +void Slots::mouseMoveEvent( QMouseEvent * event ) +{ + QWidget *widget = qobject_cast( sender() ); + SlotsExecMouseEvent( widget, ( char* ) "mouseMoveEvent()", event ); +} + void Slots::clicked() { QWidget *widget = qobject_cast( sender() ); - SlotsExec( widget, ( QString ) "clicked()", NULL ); + SlotsExec( widget, ( char* ) "clicked()" ); } - void Slots::returnPressed() { QWidget *widget = qobject_cast( sender() ); - SlotsExec( widget, ( QString ) "returnPressed()", NULL ); + SlotsExec( widget, ( char* ) "returnPressed()" ); } - void Slots::viewportEntered() { QWidget *widget = qobject_cast( sender() ); - SlotsExec( widget, ( QString ) "viewportEntered()", NULL ); + SlotsExec( widget, ( char* ) "viewportEntered()" ); } - void Slots::pressed() { QWidget *widget = qobject_cast( sender() ); - SlotsExec( widget, ( QString ) "pressed()", NULL ); + SlotsExec( widget, ( char* ) "pressed()" ); } - void Slots::released() { QWidget *widget = qobject_cast( sender() ); - SlotsExec( widget, ( QString ) "released()", NULL ); + SlotsExec( widget, ( char* ) "released()" ); } - -void Slots::hovered() -{ - //QWidget *widget = qobject_cast( sender() ); - QAction *widget = qobject_cast( sender() ); - if( widget ) - { - SlotsExecAction( widget, ( QString ) "hovered()", NULL ); - } -} - void Slots::triggered() { QWidget *widget = qobject_cast( sender() ); - SlotsExec( widget, ( QString ) "triggered()", NULL ); + SlotsExec( widget, ( char* ) "triggered()" ); } - -void Slots::triggered( bool checked ) +void Slots::hovered() { - QObject *widget = qobject_cast( sender() ); - for( int i = 0; i < list1.size(); ++i ) - { - if( ( QObject* ) list1.at( i ) == ( QObject* ) widget ) - { - if( ( ( QString ) list2.at( i ) == ( QString ) "triggered(bool)" ) && ( ( bool ) list4.at( i ) == true ) ) - { - PHB_ITEM pWidget = hb_itemPutPtr( NULL, ( QObject * ) widget ); - PHB_ITEM pChecked = hb_itemPutL( NULL, checked ); - - hb_vmEvalBlockV( ( PHB_ITEM ) list3.at( i ), 2, pWidget, pChecked ); - hb_itemRelease( pWidget ); - hb_itemRelease( pChecked ); - } - } - } + QAction *widget = qobject_cast( sender() ); + SlotsExecAction( widget, ( char* ) "hovered()" ); } void Slots::stateChanged( int state ) { QWidget *widget = qobject_cast( sender() ); - SlotsExecInt( widget, ( QString ) "stateChanged(int)", NULL, state ); + SlotsExecInt( widget, ( char* ) "stateChanged(int)", state ); } - void Slots::activated( int index ) { QWidget *widget = qobject_cast( sender() ); - SlotsExecInt( widget, ( QString ) "activated(int)", NULL, index ); + SlotsExecInt( widget, ( char* ) "activated(int)", index ); } - void Slots::currentIndexChanged( int index ) { QWidget *widget = qobject_cast( sender() ); - SlotsExecInt( widget, ( QString ) "currentIndexChanged(int)", NULL, index ); + SlotsExecInt( widget, ( char* ) "currentIndexChanged(int)", index ); } - void Slots::currentChanged( int index ) { QWidget *widget = qobject_cast( sender() ); - SlotsExecInt( widget, ( QString ) "currentChanged(int)", NULL, index ); + SlotsExecInt( widget, ( char* ) "currentChanged(int)", index ); } - void Slots::highlighted( int index ) { QWidget *widget = qobject_cast( sender() ); - SlotsExecInt( widget, ( QString ) "highlighted(int)", NULL, index ); + SlotsExecInt( widget, ( char* ) "highlighted(int)", index ); } void Slots::clicked( const QModelIndex & index ) { QWidget * widget = qobject_cast( sender() ); - SlotsExecModel( widget, ( QString ) "clicked(QModelIndex)", NULL, index ); + SlotsExecModel( widget, ( char* ) "clicked(QModelIndex)", index ); } void Slots::doubleClicked( const QModelIndex & index ) { QWidget * widget = qobject_cast( sender() ); - SlotsExecModel( widget, ( QString ) "doubleClicked(QModelIndex)", NULL, index ); + SlotsExecModel( widget, ( char* ) "doubleClicked(QModelIndex)", index ); } void Slots::entered( const QModelIndex & index ) { QWidget * widget = qobject_cast( sender() ); - SlotsExecModel( widget, ( QString ) "entered(QModelIndex)", NULL, index ); + SlotsExecModel( widget, ( char* ) "entered(QModelIndex)", index ); +} + +void Slots::actionTriggered( int action ) +{ + QWidget *widget = qobject_cast( sender() ); + SlotsExecInt( widget, ( char* ) "actionTriggered(int)", action ); +} +void Slots::rangeChanged( int min, int max ) +{ + QWidget *widget = qobject_cast( sender() ); + SlotsExecIntInt( widget, ( char* ) "rangeChanged(int)", min, max ); +} +void Slots::sliderMoved( int value ) +{ + QWidget *widget = qobject_cast( sender() ); + SlotsExecInt( widget, ( char* ) "sliderMoved(int)", value ); +} +void Slots::sliderPressed() +{ + QWidget *widget = qobject_cast( sender() ); + SlotsExec( widget, ( char* ) "sliderPressed()" ); +} +void Slots::sliderReleased() +{ + QWidget *widget = qobject_cast( sender() ); + SlotsExec( widget, ( char* ) "sliderReleased()" ); +} +void Slots::valueChanged( int value ) +{ + QWidget *widget = qobject_cast( sender() ); + SlotsExecInt( widget, ( char* ) "valueChanged(int)", value ); } /* @@ -374,20 +373,12 @@ HB_FUNC( QT_CONNECT_SIGNAL ) QString signal = hb_parc( 2 ); /* get signal */ PHB_ITEM codeblock = hb_itemNew( hb_param( 3, HB_IT_BLOCK | HB_IT_BYREF ) ); /* get codeblock */ bool ret = false; /* return value */ - bool bAct = false; - /* create object s, if not created yet */ if( s == NULL ) { s = new Slots(); } - /* connect signal with slot - * if the list become to long, more classes can be created - * TODO: parameter Qt::AutoConnection - */ - - /* Events with no parameters */ if( signal == ( QString ) "clicked()" ) { ret = widget->connect( widget, SIGNAL( clicked() ) , s, SLOT( clicked() ) , Qt::AutoConnection ); @@ -403,7 +394,6 @@ HB_FUNC( QT_CONNECT_SIGNAL ) if( signal == ( QString ) "hovered()" ) { ret = widget->connect( widget, SIGNAL( hovered() ) , s, SLOT( hovered() ) , Qt::AutoConnection ); - bAct = true; } if( signal == ( QString ) "viewportEntered()" ) { @@ -418,7 +408,6 @@ HB_FUNC( QT_CONNECT_SIGNAL ) ret = widget->connect( widget, SIGNAL( released() ) , s, SLOT( released() ), Qt::AutoConnection ); } - /* Events with int parameter */ if( signal == ( QString ) "stateChanged(int)" ) { ret = widget->connect( widget, SIGNAL( stateChanged( int ) ), @@ -439,13 +428,11 @@ HB_FUNC( QT_CONNECT_SIGNAL ) ret = widget->connect( widget, SIGNAL( highlighted( int ) ) , s, SLOT( highlighted( int ) ) , Qt::AutoConnection ); } - /* Events with bool parameter */ if( signal == ( QString ) "triggered(bool)" ) { ret = widget->connect( widget, SIGNAL( triggered( bool ) ), s, SLOT( triggered( bool ) ) , Qt::AutoConnection ); } - /* Events with miscellaneous parameters */ if( signal == ( QString ) "clicked(QModelIndex)" ) { ret = widget->connect( widget, SIGNAL( clicked( const QModelIndex & ) ), @@ -486,60 +473,114 @@ HB_FUNC( QT_CONNECT_SIGNAL ) ret = widget->connect( widget, SIGNAL( currentChanged( int ) ), s, SLOT( currentChanged( int ) ), Qt::AutoConnection ); } + if( signal == ( QString ) "actionTriggered(int)" ) + { + ret = widget->connect( widget, SIGNAL( actionTriggered(int) ), + s, SLOT( actionTriggered(int) ), Qt::AutoConnection ); + } + if( signal == ( QString ) "rangeChanged(int,int)" ) + { + ret = widget->connect( widget, SIGNAL( rangeChanged(int,int) ), + s, SLOT( rangeChanged(int,int) ), Qt::AutoConnection ); + } + if( signal == ( QString ) "sliderMoved(int)" ) + { + ret = widget->connect( widget, SIGNAL( sliderMoved(int) ), + s, SLOT( sliderMoved(int) ), Qt::AutoConnection ); + } + if( signal == ( QString ) "sliderPressed()" ) + { + ret = widget->connect( widget, SIGNAL( sliderPressed() ), + s, SLOT( sliderPressed() ), Qt::AutoConnection ); + } + if( signal == ( QString ) "sliderReleased()" ) + { + ret = widget->connect( widget, SIGNAL( sliderReleased() ), + s, SLOT( sliderReleased() ), Qt::AutoConnection ); + } + if( signal == ( QString ) "valueChanged(int)" ) + { + ret = widget->connect( widget, SIGNAL( valueChanged(int) ), + s, SLOT( valueChanged(int) ), Qt::AutoConnection ); + } - /* return connect result */ hb_retl( ret ); - /* if connected: store widget, signal, codeblock and flag - * TODO: locate a inactive entry and use it - */ if( ret == true ) { - if( bAct ) + bool bFound = false; + int i; + + for( i = 0; i < s->listBlock.size(); i++ ) { - s->list5 << ( QAction* ) hb_parptr( 1 ); - s->list1 << NULL; + if( s->listBlock.at( i ) == NULL ) + { + bFound = true; + break; + } + } + if( bFound ) + { + s->listBlock[ i ] = codeblock; + s->listActv[ i ] = true; + widget->setProperty( hb_parc( 2 ), ( int ) i+1 ); } else { - s->list5 << NULL; - s->list1 << widget; + s->listBlock << codeblock; + s->listActv << true; + widget->setProperty( hb_parc( 2 ), ( int ) s->listBlock.size() ); } - s->list2 << signal; - s->list3 << codeblock; - s->list4 << true; } } - /* * harbour function to disconnect signals */ HB_FUNC( QT_DISCONNECT_SIGNAL ) { - /* TODO */ + QWidget * widget = ( QWidget* ) hb_parptr( 1 ); + if( widget ) + { + char * event = hb_parc( 2 ); + int i = widget->property( event ).toInt(); + + if( i > 0 && i <= s->listBlock.size() ) + { + if( s->listBlock.at( i-1 ) != NULL ) + { +#if 0 +char buf[40]; +sprintf( buf, "signal %i : %s", i, event ); +OutputDebugString( buf ); +#endif + hb_itemRelease( s->listBlock.at( i-1 ) ); + s->listBlock[ i-1 ] = NULL; + s->listActv[ i-1 ] = false; + } + } + } } /* * harbour function to release all codeblocks storeds */ -#if 0 HB_FUNC( RELEASE_CODEBLOCKS ) { if( s ) { - for( int i = 0; i < s->list1.size(); ++i ) + for( int i = 0; i < s->listBlock.size(); ++i ) { - if( ( bool ) s->list4.at( i ) == true ) + if( ( bool ) s->listActv.at( i ) == true ) { - hb_itemRelease( ( PHB_ITEM ) s->list3.at( i ) ); + hb_itemRelease( ( PHB_ITEM ) s->listBlock.at( i ) ); + s->listBlock[ i ] = NULL; + s->listActv[ i ] = false; } } } } -#endif - /* * C function to release all codeblocks storeds @@ -550,11 +591,11 @@ void release_codeblocks( void ) { if( s ) { - for( int i = 0; i < s->list1.size(); ++i ) + for( int i = 0; i < s->listBlock.size(); ++i ) { - if( ( bool ) s->list4.at( i ) == true ) + if( ( bool ) s->listActv.at( i ) == true ) { - hb_itemRelease( ( PHB_ITEM ) s->list3.at( i ) ); + hb_itemRelease( ( PHB_ITEM ) s->listBlock.at( i ) ); } } } diff --git a/harbour/contrib/hbqt/hbqt_slots.h b/harbour/contrib/hbqt/hbqt_slots.h index c72d6aa757..9aa3a47a90 100644 --- a/harbour/contrib/hbqt/hbqt_slots.h +++ b/harbour/contrib/hbqt/hbqt_slots.h @@ -65,10 +65,45 @@ #include #include - #include "hbapi.h" #include "hbapiitm.h" +/*----------------------------------------------------------------------*/ + +class MyDrawingArea : public QWidget +{ + Q_OBJECT + +public: + MyDrawingArea( QWidget *parent = 0 ); + virtual ~MyDrawingArea( void ); + + void keyPressEvent( QKeyEvent * event ); + void mouseMoveEvent( QMouseEvent * event ); + +signals: + void sg_mouseMoveEvent( QMouseEvent * event ); + void sg_keyPressEvent( QKeyEvent * event ); + +}; + +/*----------------------------------------------------------------------*/ + +class MyMainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MyMainWindow(); + virtual ~MyMainWindow(); + +public: + void closeEvent( QCloseEvent *event ); + +}; + +/*----------------------------------------------------------------------*/ + class Slots: public QObject { Q_OBJECT @@ -76,11 +111,8 @@ class Slots: public QObject public: Slots( QObject *parent = 0 ); ~Slots(); - QList list1; - QList list5; - QList list2; - QList list3; - QList list4; + QList listBlock; + QList listActv; public slots: void clicked(); @@ -103,40 +135,16 @@ public slots: void mouseMoveEvent( QMouseEvent * event ); void hovered( QAction * action ); void currentChanged( int index ); + /* Slots to handle sliders */ + void actionTriggered( int action ); + void rangeChanged( int min, int max ); + void sliderMoved( int value ); + void sliderPressed(); + void sliderReleased(); + void valueChanged( int value ); }; - -class MyDrawingArea : public QWidget -{ - Q_OBJECT - -public: - MyDrawingArea( QWidget *parent = 0 ); - virtual ~MyDrawingArea( void ); - - void keyPressEvent( QKeyEvent * event ); - void mouseMoveEvent( QMouseEvent * event ); - -signals: - void sg_mouseMoveEvent( QMouseEvent * event ); - void sg_keyPressEvent( QKeyEvent * event ); - -}; - - -class MyMainWindow : public QMainWindow -{ - Q_OBJECT - -public: - MyMainWindow(); - virtual ~MyMainWindow(); - -public: - void closeEvent( QCloseEvent *event ); - -}; - +/*----------------------------------------------------------------------*/ #endif diff --git a/harbour/contrib/hbqt/moc_slots.cpp b/harbour/contrib/hbqt/moc_slots.cpp index 7172ac11a9..13ef626d49 100644 --- a/harbour/contrib/hbqt/moc_slots.cpp +++ b/harbour/contrib/hbqt/moc_slots.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** Meta object code from reading C++ file 'hbqt_slots.h' ** -** Created: Mon Jun 15 13:08:25 2009 +** Created: Tue Jun 16 15:09:19 2009 ** by: The Qt Meta Object Compiler version 61 (Qt 4.5.0) ** ** WARNING! All changes made in this file will be lost! @@ -17,108 +17,6 @@ #endif QT_BEGIN_MOC_NAMESPACE -static const uint qt_meta_data_Slots[] = { - - // content: - 2, // revision - 0, // classname - 0, 0, // classinfo - 20, 12, // methods - 0, 0, // properties - 0, 0, // enums/sets - 0, 0, // constructors - - // slots: signature, parameters, type, tag, flags - 7, 6, 6, 6, 0x0a, - 17, 6, 6, 6, 0x0a, - 37, 29, 6, 6, 0x0a, - 53, 6, 6, 6, 0x0a, - 69, 63, 6, 6, 0x0a, - 87, 6, 6, 6, 0x0a, - 97, 6, 6, 6, 0x0a, - 114, 108, 6, 6, 0x0a, - 129, 108, 6, 6, 0x0a, - 154, 108, 6, 6, 0x0a, - 171, 6, 6, 6, 0x0a, - 187, 108, 6, 6, 0x0a, - 208, 108, 6, 6, 0x0a, - 235, 108, 6, 6, 0x0a, - 256, 6, 6, 6, 0x0a, - 285, 279, 274, 6, 0x0a, - 300, 279, 6, 6, 0x0a, - 326, 279, 6, 6, 0x0a, - 362, 355, 6, 6, 0x0a, - 380, 108, 6, 6, 0x0a, - - 0 // eod -}; - -static const char qt_meta_stringdata_Slots[] = { - "Slots\0\0clicked()\0triggered()\0checked\0" - "triggered(bool)\0hovered()\0state\0" - "stateChanged(int)\0pressed()\0released()\0" - "index\0activated(int)\0currentIndexChanged(int)\0" - "highlighted(int)\0returnPressed()\0" - "clicked(QModelIndex)\0doubleClicked(QModelIndex)\0" - "entered(QModelIndex)\0viewportEntered()\0" - "bool\0event\0event(QEvent*)\0" - "keyPressEvent(QKeyEvent*)\0" - "mouseMoveEvent(QMouseEvent*)\0action\0" - "hovered(QAction*)\0currentChanged(int)\0" -}; - -const QMetaObject Slots::staticMetaObject = { - { &QObject::staticMetaObject, qt_meta_stringdata_Slots, - qt_meta_data_Slots, 0 } -}; - -const QMetaObject *Slots::metaObject() const -{ - return &staticMetaObject; -} - -void *Slots::qt_metacast(const char *_clname) -{ - if (!_clname) return 0; - if (!strcmp(_clname, qt_meta_stringdata_Slots)) - return static_cast(const_cast< Slots*>(this)); - return QObject::qt_metacast(_clname); -} - -int Slots::qt_metacall(QMetaObject::Call _c, int _id, void **_a) -{ - _id = QObject::qt_metacall(_c, _id, _a); - if (_id < 0) - return _id; - if (_c == QMetaObject::InvokeMetaMethod) { - switch (_id) { - case 0: clicked(); break; - case 1: triggered(); break; - case 2: triggered((*reinterpret_cast< bool(*)>(_a[1]))); break; - case 3: hovered(); break; - case 4: stateChanged((*reinterpret_cast< int(*)>(_a[1]))); break; - case 5: pressed(); break; - case 6: released(); break; - case 7: activated((*reinterpret_cast< int(*)>(_a[1]))); break; - case 8: currentIndexChanged((*reinterpret_cast< int(*)>(_a[1]))); break; - case 9: highlighted((*reinterpret_cast< int(*)>(_a[1]))); break; - case 10: returnPressed(); break; - case 11: clicked((*reinterpret_cast< const QModelIndex(*)>(_a[1]))); break; - case 12: doubleClicked((*reinterpret_cast< const QModelIndex(*)>(_a[1]))); break; - case 13: entered((*reinterpret_cast< const QModelIndex(*)>(_a[1]))); break; - case 14: viewportEntered(); break; - case 15: { bool _r = event((*reinterpret_cast< QEvent*(*)>(_a[1]))); - if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; } break; - case 16: keyPressEvent((*reinterpret_cast< QKeyEvent*(*)>(_a[1]))); break; - case 17: mouseMoveEvent((*reinterpret_cast< QMouseEvent*(*)>(_a[1]))); break; - case 18: hovered((*reinterpret_cast< QAction*(*)>(_a[1]))); break; - case 19: currentChanged((*reinterpret_cast< int(*)>(_a[1]))); break; - default: ; - } - _id -= 20; - } - return _id; -} static const uint qt_meta_data_MyDrawingArea[] = { // content: @@ -233,4 +131,122 @@ int MyMainWindow::qt_metacall(QMetaObject::Call _c, int _id, void **_a) return _id; return _id; } +static const uint qt_meta_data_Slots[] = { + + // content: + 2, // revision + 0, // classname + 0, 0, // classinfo + 26, 12, // methods + 0, 0, // properties + 0, 0, // enums/sets + 0, 0, // constructors + + // slots: signature, parameters, type, tag, flags + 7, 6, 6, 6, 0x0a, + 17, 6, 6, 6, 0x0a, + 37, 29, 6, 6, 0x0a, + 53, 6, 6, 6, 0x0a, + 69, 63, 6, 6, 0x0a, + 87, 6, 6, 6, 0x0a, + 97, 6, 6, 6, 0x0a, + 114, 108, 6, 6, 0x0a, + 129, 108, 6, 6, 0x0a, + 154, 108, 6, 6, 0x0a, + 171, 6, 6, 6, 0x0a, + 187, 108, 6, 6, 0x0a, + 208, 108, 6, 6, 0x0a, + 235, 108, 6, 6, 0x0a, + 256, 6, 6, 6, 0x0a, + 285, 279, 274, 6, 0x0a, + 300, 279, 6, 6, 0x0a, + 326, 279, 6, 6, 0x0a, + 362, 355, 6, 6, 0x0a, + 380, 108, 6, 6, 0x0a, + 400, 355, 6, 6, 0x0a, + 429, 421, 6, 6, 0x0a, + 457, 451, 6, 6, 0x0a, + 474, 6, 6, 6, 0x0a, + 490, 6, 6, 6, 0x0a, + 507, 451, 6, 6, 0x0a, + + 0 // eod +}; + +static const char qt_meta_stringdata_Slots[] = { + "Slots\0\0clicked()\0triggered()\0checked\0" + "triggered(bool)\0hovered()\0state\0" + "stateChanged(int)\0pressed()\0released()\0" + "index\0activated(int)\0currentIndexChanged(int)\0" + "highlighted(int)\0returnPressed()\0" + "clicked(QModelIndex)\0doubleClicked(QModelIndex)\0" + "entered(QModelIndex)\0viewportEntered()\0" + "bool\0event\0event(QEvent*)\0" + "keyPressEvent(QKeyEvent*)\0" + "mouseMoveEvent(QMouseEvent*)\0action\0" + "hovered(QAction*)\0currentChanged(int)\0" + "actionTriggered(int)\0min,max\0" + "rangeChanged(int,int)\0value\0" + "sliderMoved(int)\0sliderPressed()\0" + "sliderReleased()\0valueChanged(int)\0" +}; + +const QMetaObject Slots::staticMetaObject = { + { &QObject::staticMetaObject, qt_meta_stringdata_Slots, + qt_meta_data_Slots, 0 } +}; + +const QMetaObject *Slots::metaObject() const +{ + return &staticMetaObject; +} + +void *Slots::qt_metacast(const char *_clname) +{ + if (!_clname) return 0; + if (!strcmp(_clname, qt_meta_stringdata_Slots)) + return static_cast(const_cast< Slots*>(this)); + return QObject::qt_metacast(_clname); +} + +int Slots::qt_metacall(QMetaObject::Call _c, int _id, void **_a) +{ + _id = QObject::qt_metacall(_c, _id, _a); + if (_id < 0) + return _id; + if (_c == QMetaObject::InvokeMetaMethod) { + switch (_id) { + case 0: clicked(); break; + case 1: triggered(); break; + case 2: triggered((*reinterpret_cast< bool(*)>(_a[1]))); break; + case 3: hovered(); break; + case 4: stateChanged((*reinterpret_cast< int(*)>(_a[1]))); break; + case 5: pressed(); break; + case 6: released(); break; + case 7: activated((*reinterpret_cast< int(*)>(_a[1]))); break; + case 8: currentIndexChanged((*reinterpret_cast< int(*)>(_a[1]))); break; + case 9: highlighted((*reinterpret_cast< int(*)>(_a[1]))); break; + case 10: returnPressed(); break; + case 11: clicked((*reinterpret_cast< const QModelIndex(*)>(_a[1]))); break; + case 12: doubleClicked((*reinterpret_cast< const QModelIndex(*)>(_a[1]))); break; + case 13: entered((*reinterpret_cast< const QModelIndex(*)>(_a[1]))); break; + case 14: viewportEntered(); break; + case 15: { bool _r = event((*reinterpret_cast< QEvent*(*)>(_a[1]))); + if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; } break; + case 16: keyPressEvent((*reinterpret_cast< QKeyEvent*(*)>(_a[1]))); break; + case 17: mouseMoveEvent((*reinterpret_cast< QMouseEvent*(*)>(_a[1]))); break; + case 18: hovered((*reinterpret_cast< QAction*(*)>(_a[1]))); break; + case 19: currentChanged((*reinterpret_cast< int(*)>(_a[1]))); break; + case 20: actionTriggered((*reinterpret_cast< int(*)>(_a[1]))); break; + case 21: rangeChanged((*reinterpret_cast< int(*)>(_a[1])),(*reinterpret_cast< int(*)>(_a[2]))); break; + case 22: sliderMoved((*reinterpret_cast< int(*)>(_a[1]))); break; + case 23: sliderPressed(); break; + case 24: sliderReleased(); break; + case 25: valueChanged((*reinterpret_cast< int(*)>(_a[1]))); break; + default: ; + } + _id -= 26; + } + return _id; +} QT_END_MOC_NAMESPACE diff --git a/harbour/contrib/hbqt/tests/demoqt.prg b/harbour/contrib/hbqt/tests/demoqt.prg index 897c6c4aa4..67a2d06bd1 100644 --- a/harbour/contrib/hbqt/tests/demoqt.prg +++ b/harbour/contrib/hbqt/tests/demoqt.prg @@ -338,7 +338,7 @@ STATIC FUNCTION Build_TreeView( oWnd ) oTV := QTreeView():new( QT_PTROF( oWnd ) ) oTV:setMouseTracking( .t. ) - Qt_Connect_Signal( QT_PTROF( oTV ), QT_EVE_HOVERED, {|o,i| uiDebug( "oTV:hovered" ) } ) + //Qt_Connect_Signal( QT_PTROF( oTV ), QT_EVE_HOVERED, {|o,i| uiDebug( "oTV:hovered" ) } ) oDirModel := QDirModel():new( QT_PTROF( oTV ) ) oTV:setModel( QT_PTROF( oDirModel ) ) oTV:move( 5, 7 ) @@ -354,7 +354,7 @@ STATIC FUNCTION Build_ListBox( oWnd, aPos, aSize ) oListBox := QListView():New( QT_PTROF( oWnd ) ) oListBox:setMouseTracking( .t. ) - Qt_Connect_Signal( QT_PTROF( oListBox ), QT_EVE_HOVERED, {|o,i| uiDebug( "oListBox:hovered" ) } ) + //Qt_Connect_Signal( QT_PTROF( oListBox ), QT_EVE_HOVERED, {|o,i| uiDebug( "oListBox:hovered" ) } ) oStrList := QStringList():new( QT_PTROF( oListBox ) )