casa
$Rev:20696$
|
00001 //# QCloseableWidget.qo.h: Wrapper around a QWidget with a "Close" button. 00002 //# Copyright (C) 2005 00003 //# Associated Universities, Inc. Washington DC, USA. 00004 //# 00005 //# This library is free software; you can redistribute it and/or modify it 00006 //# under the terms of the GNU Library General Public License as published by 00007 //# the Free Software Foundation; either version 2 of the License, or (at your 00008 //# option) any later version. 00009 //# 00010 //# This library is distributed in the hope that it will be useful, but WITHOUT 00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00012 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00013 //# License for more details. 00014 //# 00015 //# You should have received a copy of the GNU Library General Public License 00016 //# along with this library; if not, write to the Free Software Foundation, 00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 00018 //# 00019 //# Correspondence concerning AIPS++ should be addressed as follows: 00020 //# Internet email: aips2-request@nrao.edu. 00021 //# Postal address: AIPS++ Project Office 00022 //# National Radio Astronomy Observatory 00023 //# 520 Edgemont Road 00024 //# Charlottesville, VA 22903-2475 USA 00025 //# 00026 //# $Id: $ 00027 #ifndef QCLOSEABLEWIDGET_H_ 00028 #define QCLOSEABLEWIDGET_H_ 00029 00030 #include <casaqt/QtBrowser/QCloseableWidget.ui.h> 00031 00032 #include <QtGui> 00033 00034 #include <casa/BasicSL/String.h> 00035 00036 #include <casa/namespace.h> 00037 00038 namespace casa { 00039 00040 // <summary> 00041 // Wrapper around a QWidget with a "Close" button 00042 // </summary> 00043 // 00044 // <synopsis> 00045 // A QCloseableWidget is a convenience class that adds a "close" functionality 00046 // to any QWidget subclass. It does this by providing methods (such as getting, 00047 // setting, and clearing the QWidget) and signals indicating when the close 00048 // button has been pressed. <b>Important</b>: it is the responsibility of the 00049 // caller/parent to actually close the object; the QCloseableWidget just 00050 // provides the signal. 00051 // </synopsis> 00052 00053 class QCloseableWidget : public QWidget, Ui::Widget { 00054 Q_OBJECT 00055 00056 public: 00057 // Default Constructor. Creates a blank widget with a close button. 00058 QCloseableWidget(); 00059 00060 // Constructor that takes the initial widget to display and the text for 00061 // the close button. If the text is empty, the default close button text 00062 // is displayed. 00063 QCloseableWidget(QWidget* widget, String closeText = ""); 00064 00065 ~QCloseableWidget(); 00066 00067 00068 // Returns the current widget held by the wrapper. 00069 QWidget* getCurrentWidget(); 00070 00071 // Sets the current widget to the given widget. If shouldDeleteOld is true, 00072 // the old widget held by the wrapper is deleted. 00073 void setWidget(QWidget* widget, bool shouldDeleteOld = false); 00074 00075 // Sets the text on the "close" button to the given String. 00076 void setCloseButtonText(String name); 00077 00078 00079 // "Clears" the current widget by replacing it with a blank widget. 00080 // This method does delete the old widget. 00081 void clearWidget(); 00082 00083 signals: 00084 // The closeRequested signal is emitted whenever the "Close" button is 00085 // pressed. The widget paramater points to the currently shown widget, 00086 // or NULL if there is none. 00087 void closeRequested(QWidget* widget); 00088 00089 private: 00090 // Convenience pointer to the layout of this QCloseableWidget. 00091 QGridLayout* grid; 00092 00093 // The current widget held by the wrapper. 00094 QWidget* currWidget; 00095 00096 00097 // Initial set-up of GUI components. 00098 void setup(); 00099 00100 private slots: 00101 // Slot to handle the "Close" button's clicked() signal. Emits the 00102 // closeRequested() signal. 00103 void closeRequest(); 00104 }; 00105 00106 } 00107 00108 #endif /* QCLOSEABLEWIDGET_H_ */