00001 //# QtEditingWidget.qo.h: Simple editing widgets. 00002 //# Copyright (C) 2009 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 QTEDITINGWIDGET_QO_H_ 00028 #define QTEDITINGWIDGET_QO_H_ 00029 00030 #include <casaqt/QtUtilities/PlotFileWidget.ui.h> 00031 #include <casaqt/QtUtilities/PlotLabelWidget.ui.h> 00032 00033 #include <casa/BasicSL/String.h> 00034 00035 namespace casa { 00036 00037 // A simple parent for editing widgets. 00038 class QtEditingWidget : public QWidget { 00039 Q_OBJECT 00040 00041 public: 00042 // Constructor which takes an optional parent widget. 00043 QtEditingWidget(QWidget* parent = NULL) : QWidget(parent) { } 00044 00045 // Destructor. 00046 virtual ~QtEditingWidget() { } 00047 00048 // Adds any radio buttons in the widget to the given button group. This 00049 // method should be overridden by children that have radio buttons. 00050 virtual void addRadioButtonsToGroup(QButtonGroup* group) const { (void)group; } 00051 00052 signals: 00053 // This signal should be emitted whenever the user changes any value 00054 // settings in the GUI. 00055 void changed(); 00056 00057 // This signal should be emitted when the user changes any value settings 00058 // in the GUI AND the new value is different from the last set value. 00059 void differentFromSet(); 00060 }; 00061 00062 00063 // Widget for choosing a label. Lets the user choose between no label, a 00064 // default label given at construction, or a custom label they can set. 00065 class QtLabelWidget : public QtEditingWidget, Ui::LabelWidget { 00066 Q_OBJECT 00067 00068 public: 00069 // Constructor which takes the label associated with the "default" option, 00070 // and an optional parent widget. 00071 QtLabelWidget(const String& defaultLabel, QWidget* parent = NULL); 00072 00073 // Destructor. 00074 ~QtLabelWidget(); 00075 00076 // Gets/Sets the currently set label on the widget. 00077 // <group> 00078 String getValue() const; 00079 void setValue(const String& value); 00080 // </group> 00081 00082 // Overrides PlotMSWidget::addRadioButtonsToGroup(). 00083 void addRadioButtonsToGroup(QButtonGroup* group) const; 00084 00085 private: 00086 // Default label. 00087 String itsDefault_; 00088 00089 // Last set label. 00090 String itsValue_; 00091 00092 private slots: 00093 // Slot for when the set label changes. The "check" flag can be used to 00094 // avoid emitting the changed signals twice (for example, when one radio 00095 // button turns off when another turns on). 00096 void labelChanged(bool check = true); 00097 }; 00098 00099 00100 // Widget for choosing a file. 00101 class QtFileWidget : public QtEditingWidget, Ui::FileWidget { 00102 Q_OBJECT 00103 00104 public: 00105 // Constructor which takes a flag for whether the file is a directory or 00106 // not (for the file chooser), a flag for whether the file is for saving 00107 // (and thus doesn't need to exist, for the file chooser), and an optional 00108 // parent widget. 00109 QtFileWidget(bool chooseDirectory, bool saveFile, QWidget* parent= NULL); 00110 00111 // Destructor. 00112 ~QtFileWidget(); 00113 00114 // Gets/Sets the currently set file. 00115 // <group> 00116 String getFile() const; 00117 void setFile(const String& file); 00118 // </group> 00119 00120 private: 00121 // File chooser directory flag. 00122 bool isDirectory_; 00123 00124 // File chooser save file flag. 00125 bool isSave_; 00126 00127 // Last set file. 00128 String itsFile_; 00129 00130 private slots: 00131 // Slot to show a file chooser and set the result in the line edit. 00132 void browse(); 00133 00134 // Slot for when the set file changes. 00135 void fileChanged(); 00136 void trimFileName(); 00137 }; 00138 00139 } 00140 00141 #endif /* QTEDITINGWIDGET_QO_H_ */