00001 /**************************************************************************** 00002 This file is part of ChainLink 00003 Copyright (C) 2007 Jeremy Magland (Jeremy.Magland@gmail.com) 00004 00005 ChainLink is free software; you can redistribute it and/or modify 00006 it under the terms of the GNU General Public License as published by 00007 the Free Software Foundation; either version 2 of the License, or 00008 (at your option) any later version. 00009 00010 ChainLink is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License 00016 along with ChainLink; if not, write to the Free Software 00017 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00018 00019 *****************************************************************************/ 00020 00021 //Note: this file is not part of the chainlink_base library, 00022 //but it can be included from ChainLink library files 00023 00024 #ifndef WIDGET_HANDLE_H 00025 #define WIDGET_HANDLE_H 00026 00027 #include <QWidget> 00028 00029 class QWidgetHandle : public QObject { 00030 Q_OBJECT 00031 public: 00032 QWidget *widget; 00033 QWidgetHandle() { 00034 widget=0; 00035 } 00036 virtual ~QWidgetHandle() { 00037 } 00038 00039 void setWidget(QWidget *widget_in) { 00040 if (widget) 00041 disconnect(widget); 00042 widget=widget_in; 00043 if (!widget) return; 00044 widget->setAttribute(Qt::WA_DeleteOnClose); 00045 connect_widget(); 00046 } 00047 void connect_widget() { 00048 if (!widget) return; 00049 connect(widget,SIGNAL(destroyed(QObject *)),this,SLOT(on_widget_destroyed(QObject *))); 00050 } 00051 void operator=(QWidgetHandle &H) { 00052 setWidget(H.widget); 00053 } 00054 00055 public slots: 00056 void on_widget_destroyed(QObject *obj) { 00057 widget=0; 00058 } 00059 }; 00060 00061 00062 #endif 00063