[Jahshaka-cvs] jah/jahwidgets/src/qt3/wrapper widget_handle.cpp, 1.19, 1.20 widget_handle.hpp, 1.18
Status: Beta
Brought to you by:
jahshaka
From: John B. <ok_...@us...> - 2007-04-05 16:31:34
|
Update of /cvsroot/jahshaka/jah/jahwidgets/src/qt3/wrapper In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv2757/jahwidgets/src/qt3/wrapper Modified Files: widget_handle.cpp widget_handle.hpp Log Message: * Adding minimize etc methods * Improvements to instance factory Index: widget_handle.cpp =================================================================== RCS file: /cvsroot/jahshaka/jah/jahwidgets/src/qt3/wrapper/widget_handle.cpp,v retrieving revision 1.19 retrieving revision 1.20 diff -u -d -r1.19 -r1.20 --- widget_handle.cpp 27 Mar 2007 20:26:56 -0000 1.19 +++ widget_handle.cpp 5 Apr 2007 16:31:31 -0000 1.20 @@ -53,7 +53,7 @@ widget_handle_private_map::const_iterator I = _static_instances.find( w ); if ( I != _static_instances.end() ) { ++(I->second->ref_count); - return I->second; + return I->second.get(); } else { // c'tor inserts into _static_instances @@ -63,11 +63,7 @@ virtual ~widget_handle_private() { - if ( _static_instances.find( widget ) != _static_instances.end() ) - { - qDebug( "widget_handle_private DTOR - erasing private handle" ); - _static_instances.erase( widget ); - } + } QGuardedPtr< QWidget > widget; @@ -122,8 +118,20 @@ void maximumWidth_changed(); void maximumHeight_changed(); +private slots: + void widgetDestroyed() + { + // Remove from map so that ref count is decremented. We will not be deleted until + // all our widget_handle instances are destroyed + if ( _static_instances.find( widget ) != _static_instances.end() ) + { + qDebug( "widget_handle_private - erasing private handle from map" ); + _static_instances.erase( widget ); + } + } + private: - typedef std::map<QWidget*, widget_handle_private*> widget_handle_private_map; + typedef std::map<QWidget*, widget_handle_private_ptr > widget_handle_private_map; static widget_handle_private_map _static_instances; widget_handle_private( QWidget* w ) @@ -132,7 +140,7 @@ mouse( NULL ), key( NULL ), wheel( NULL ), - ref_count( 1 ) + ref_count( 0 ) // handled by boost::intrusive_ptr { if ( w ) { @@ -149,7 +157,12 @@ ++i; } - _static_instances.insert( widget_handle_private_map::value_type( w, this ) ); + _static_instances.insert( + widget_handle_private_map::value_type( w, widget_handle_private_ptr(this) ) + ); + + // Get notified when our widget is deleted so we can remove the instance from the map + connect( w, SIGNAL(destroyed()), SLOT(widgetDestroyed()) ); } } @@ -313,6 +326,27 @@ b ? m_impl->widget->show() : m_impl->widget->hide(); } +void widget_handle::show_maximized() +{ + if ( m_impl->widget ) { + m_impl->widget->topLevelWidget()->showMaximized(); + } +} + +void widget_handle::show_minimized() +{ + if ( m_impl->widget ) { + m_impl->widget->topLevelWidget()->showMinimized(); + } +} + +void widget_handle::show_normal() +{ + if ( m_impl->widget ) { + m_impl->widget->topLevelWidget()->showNormal(); + } +} + void widget_handle::set_always_on_top( bool b ) { if ( !m_impl->widget ) Index: widget_handle.hpp =================================================================== RCS file: /cvsroot/jahshaka/jah/jahwidgets/src/qt3/wrapper/widget_handle.hpp,v retrieving revision 1.18 retrieving revision 1.19 diff -u -d -r1.18 -r1.19 --- widget_handle.hpp 27 Mar 2007 20:26:56 -0000 1.18 +++ widget_handle.hpp 5 Apr 2007 16:31:31 -0000 1.19 @@ -31,6 +31,8 @@ class action; class widget_handle_private; +typedef boost::intrusive_ptr< widget_handle_private > widget_handle_private_ptr; + /// a trivial opaque wrapper for QWidget to ease handling in python class WRAPPER_DECLSPEC widget_handle { @@ -52,6 +54,11 @@ /// adjust the shown state of the widget i.e. show( false ) == hide void show( bool b ); + /// maximize/minimize/normal + void show_maximized(); + void show_minimized(); + void show_normal(); + /// make the widget always be on top; sets the WStyle_StaysOnTop flag void set_always_on_top( bool b ); @@ -98,8 +105,8 @@ private: // We use an intrusive_ptr here because widget_handle_private implements its own // ref counting to enable sharing between any instance of widget_handle (not just - // copies of an instance) - boost::intrusive_ptr< widget_handle_private > m_impl; + // copies of an instance). Thus the lifetime of the impl is tied to the QWidget, not the handle. + widget_handle_private_ptr m_impl; }; std::ostream& operator<<( std::ostream& os, const widget_handle& wh ); |