casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
QtGuiEntry.qo.h
Go to the documentation of this file.
00001 //# QtGuiEntry.qo.h: Individual interface elements for general-purpose
00002 //#               Qt options widget (QtAutoGui).
00003 //# Copyright (C) 2005
00004 //# Associated Universities, Inc. Washington DC, USA.
00005 //#
00006 //# This library is free software; you can redistribute it and/or modify it
00007 //# under the terms of the GNU Library General Public License as published by
00008 //# the Free Software Foundation; either version 2 of the License, or (at your
00009 //# option) any later version.
00010 //#
00011 //# This library is distributed in the hope that it will be useful, but WITHOUT
00012 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00013 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00014 //# License for more details.
00015 //#
00016 //# You should have received a copy of the GNU Library General Public License
00017 //# along with this library; if not, write to the Free Software Foundation,
00018 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00019 //#
00020 //# Correspondence concerning AIPS++ should be addressed as follows:
00021 //#        Internet email: aips2-request@nrao.edu.
00022 //#        Postal address: AIPS++ Project Office
00023 //#                        National Radio Astronomy Observatory
00024 //#                        520 Edgemont Road
00025 //#                        Charlottesville, VA 22903-2475 USA
00026 //#
00027 //# $Id$
00028 
00029 #ifndef QTGUIENTRY_H
00030 #define QTGUIENTRY_H
00031 
00032 #include <casa/aips.h>
00033 #include <casa/BasicSL/String.h>
00034 #include <casa/BasicMath/Math.h>
00035 
00036 #include <graphics/X11/X_enter.h>
00037 #  include <QDomDocument>
00038 #  include <QCheckBox>
00039    //#dk Be careful to put ui_*.h within X_enter/exit bracket too,
00040    //#   because they'll have Qt includes.
00041    //#   E.g. <QApplication> needs the X11 definition of 'Display'
00042 #  include "adjustmentBottom.ui.h"
00043 #  include "sliderLabelItem.ui.h"
00044 #  include "sliderEditorItem.ui.h"
00045 #  include "lineEditorItem.ui.h"
00046 #  include "comboItem.ui.h"
00047 #  include "checkButtonItem.ui.h"
00048 #  include "pushButtonItem.ui.h"
00049 #  include "minMaxEditorItem.ui.h"
00050 #  include "pairItem.ui.h"
00051 #include <graphics/X11/X_exit.h>
00052 
00053 #include <utility>
00054 
00055  
00056 namespace casa { //# NAMESPACE CASA - BEGIN
00057 
00058 
00059 class QtAutoGui;
00060 
00061 
00062 //# ////////////////   QtAdjustmentBottom //////////////////////////////////
00063 
00064 class QtAdjustmentTop : public QWidget, private Ui::AdjustmentBottom {
00065     Q_OBJECT
00066 public:
00067     QtAdjustmentTop(QtAutoGui *parent=0, QString name="");
00068     void setText(QString txt) {dataName->setText(txt);}
00069     ~QtAdjustmentTop();
00070 public slots:   
00071    void dataNameChanged(QString value); 
00072    void setOriginal();
00073    void setDefault();
00074    void setMemory();
00075    void setClear();
00076    void setCopy();
00077    void setPaste();    
00078    void apply();
00079    void load();
00080    void save();
00081    void restore();
00082    void close();
00083    
00084    void hideDismiss();          //#dk
00085 
00086 private:
00087    QtAutoGui *parent; 
00088    bool blockSignal;
00089 };
00090 
00091 
00092 //# ///////////////////  QtSliderBase //////////////////////////////////////
00093 
00094 
00095 // <summary>
00096 // Base class for QtAutoGui slider interface elements.
00097 // </summary>
00098 
00099 // <synopsis>
00100 // This is a base with common functionality for the two slider 'guientries':
00101 // QtSliderEditor, which has a value edit box, and QtSliderLabel, with a
00102 // non-editable value label.  This class is abstract; its constructor can only
00103 // be called by a derived class.  That class should also call constructBase()
00104 // after cxreating its interface elements, to complete construction.
00105 // </synopsis>
00106 
00107 class QtSliderBase : public QWidget {
00108   
00109   Q_OBJECT      //# Allows slot/signal definition.  Must only occur in
00110                 //# implement/.../*.h files; also, makefile must include
00111                 //# name of this file in 'mocs' section.
00112  
00113  public:
00114   
00115   // Set interface label text ('listname').
00116   void setLabelText(QString txt) { nameLabel_->setText(txt);  }
00117   
00118   // Internal name ('dlformat')
00119   QString name(){ return itemName; }
00120 
00121   // Set up main state (value, etc.) and external appearance of
00122   // this widget, according to options record (passed as a QDomElement).
00123   // Called via constructor, and from QtAutoGui::changeOptions().
00124   // Does not trigger (significant) signals; it is intended to set this
00125   // interface element to library's internal value (not vice versa).
00126   void reSet(QDomElement& ele);
00127  
00128  protected:
00129 
00130   // Only for use by derived classes.
00131   // <group>
00132   QtSliderBase(QWidget *parent=0) : QWidget(parent) {  }
00133   ~QtSliderBase() {  }
00134   // </group>
00135   
00136   // Derived class should call this within its constructor, after it
00137   // has a valid QSlider, name QLabel and menu QToolButton (usually,
00138   // after calling setUi()), passing them down in the parameters below.
00139   // ele is the QDomElement (an xml version of an option Record) used to
00140   // construct the derived class.
00141   void constructBase(QDomElement &ele,  QSlider* slider,
00142                      QLabel* nameLabel, QToolButton* menuBtn);
00143 
00144   // Fetch numeric value of attribute of ele named attnm, into val. 
00145   // Does nothing if attr doesn't exist or is not valid numerically.
00146   void getAttr(const QDomElement& ele, QString attnm, Double& val);
00147 
00148  protected slots:   
00149    
00150   // slider changed by user
00151   virtual void slChg(int slval) { update(externalVal(slval));
00152                                   if ( ! onrelease_ ) emitVal( ); }
00153   virtual void release( )       { if (   onrelease_ ) emitVal( ); }
00154   
00155   // 'revert-to-original' selected in menu.
00156   virtual void setOriginal();
00157    
00158  
00159  signals:
00160   
00161   // Main output signal.  Main parameters of interest are item name and
00162   // new value.
00163   void itemValueChanged(QString name, QString value, int action, bool apply);
00164   
00165   // class user may wish to connect to and display these.
00166   void errMsg(String errmsg);   
00167 
00168     
00169  protected: 
00170   
00171   // Derived class should implement: set value text box or label (if any)
00172   // to (normalized) current value.  (Should not trigger class's own slots).
00173   virtual void updateText() = 0;
00174     
00175   
00176   Int round(Double val) { return ifloor(val + .5);  }
00177   
00178   // Integer values with in [0, slMax_] on the internal slider are scaled
00179   // to external values within [dMin_, dMax_].
00180   // These two routines convert between the two scalings.
00181   // <group>
00182   Double externalVal(Int sldVal) {
00183     return min(dMax_, (dMin_ + max(0., dIncr_*sldVal)));  }
00184     
00185   Int sliderVal(Double extVal) {
00186     return round(max(0., min(slMax_, (extVal-dMin_)/dIncr_)));  }
00187   // </group>
00188   
00189   // These two routines convert 'external' values between Double and
00190   // text.
00191   // <group>
00192   QString toText(Double val);
00193   Double toNumber(QString text, bool* ok=0);
00194   // </group>
00195   
00196   // Current external value, as text.
00197   QString textVal() { return toText(dVal_);  }
00198   
00199   // Adjusts integer slider range (slMax_) and the increment that each
00200   // unit on the slider represents (dIncr_), according to latest
00201   // increment and range request (dIncr0_,  dMin_, dMax_).
00202   void adjSlIncr();
00203 
00204   // Sets slider to latest range and value (without
00205   // triggering slider signals or slChg slot below). 
00206   void updateSlider();
00207 
00208   // emit current value -- widget's main output.
00209   void emitVal();
00210 
00211   // Accepts new value (if any), updates interface (without
00212   // retriggering any internal slots).
00213   // New value should already have been validated.
00214   void update(Double dval);
00215 
00216     
00217   // main state.  Determines the float scaling for the (necessarily int)
00218   // QSlider.  dVal_ is the slider's 'external' value (which may be
00219   // floating-point).  dMin_ and dMax_ are its 'external' range.
00220   // dIncr0_ is the requested 'external' slider increment ('presolution'),
00221   // dIncr_ is the increment actually used (normally, these will be the same).
00222   //
00223   // Internally, the slider's range will be [0, slMax_]; slMax_
00224   // will be a non-negative integer value.  Both of the QSlider's
00225   // internal increments (singleStep, pageStep) will be 1.
00226 
00227   Double dVal_,  dMin_, dMax_,  dIncr_, dIncr0_,  slMax_;
00228   
00229   // Whether this element emits float values (ptype 'floatrange')
00230   // vs. ints (ptype 'intrange').
00231   Bool floatrng_;
00232 
00233   // Should the event be generated only upon releasing the slider?
00234   bool onrelease_;
00235 
00236   // For restoring 'original' value.
00237   Double origVal_;
00238   
00239   // Relevant user interface elements.  Must be created by
00240   // derived class and passed in via constructBase().
00241   // <group>
00242   QSlider* slider_;
00243   QLabel* nameLabel_;
00244   QToolButton* menuBtn_;
00245   // </group>
00246     
00247   // Internal name ('dlformat').
00248   QString itemName;  
00249   
00250 };
00251 
00252 
00253 
00254 //# ////////////////////  QtSliderEditor ///////////////////////////////////
00255 
00256 
00257 class QtSliderEditor : public QtSliderBase, private Ui::SliderEditorItem {
00258   
00259   Q_OBJECT      //# Allows slot/signal definition.  Must only occur in
00260                 //# implement/.../*.h files; also, makefile must include
00261                 //# name of this file in 'mocs' section.
00262 
00263  public:
00264   
00265   QtSliderEditor(QDomElement& ele, QWidget *parent=0);
00266   ~QtSliderEditor() {  }
00267 
00268  protected:
00269 
00270   // (not intended for use at present).
00271   QtSliderEditor(QWidget *parent=0): QtSliderBase(parent) { 
00272     setupUi(this);
00273     radioButton->hide();  }
00274   
00275   // Sets text box to (normalized) current value.
00276   // (Should not trigger class's own slots either).
00277   void updateText() { lineEdit->setText(textVal());  }
00278 
00279   // main validation/update routine for changes to text version of value.
00280   // strval is the candidate text, which is still to be validated/normalized.
00281   void textChg(QString strval);
00282    
00283  protected slots:   
00284    
00285   //# text edited by user
00286   virtual void edited()      { textChg(lineEdit->text());  }
00287   
00288   //# // Triggered when 'revert-to-original' selected in menu
00289   //# virtual void setOriginal() { textChg(toText(origVal_));  }
00290   //#   //# (This version _will expand slider limits, if necessary).
00291   
00292 };
00293 
00294 
00295 
00296 //# ///////////////////////  QtSliderLabel /////////////////////////////////
00297 
00298 
00299 class QtSliderLabel : public QtSliderBase, private Ui::SliderLabelItem {
00300   
00301   Q_OBJECT      //# Allows slot/signal definition.  Must only occur in
00302                 //# implement/.../*.h files; also, makefile must include
00303                 //# name of this file in 'mocs' section.
00304 
00305  public:
00306   
00307   QtSliderLabel(QDomElement& ele, QWidget *parent=0);
00308   ~QtSliderLabel() {  }
00309 
00310  protected:
00311 
00312   // (not intended for use at present).
00313   QtSliderLabel(QWidget *parent=0): QtSliderBase(parent) { setupUi(this);  }
00314   
00315   // Sets value label to (normalized) current value.
00316   void updateText();
00317    
00318 };
00319 
00320 
00321 
00322 
00323 //# ////////////////////////  QtMinMaxEditor ///////////////////////////////
00324 
00325 class QtMinMaxEditor : public QWidget, private Ui::MinMaxEditorItem {
00326     Q_OBJECT
00327 public:
00328      QtMinMaxEditor(QWidget *parent=0);
00329      QtMinMaxEditor(QDomElement &ele, QWidget *parent=0);
00330     ~QtMinMaxEditor();
00331     bool validate(QString value);
00332     void setLabelText(QString txt) {nameLabel->setText(txt);}
00333     QString name(){ return itemName; } 
00334     void reSet(QString);
00335 public slots:  
00336    void display2(); 
00337    void display2(int value);  
00338    void display2(QString value);
00339    void setOriginal();
00340    void setDefault();
00341    void setCopy();
00342    void setPaste();
00343    void setHistogram();   
00344 signals:
00345    void itemValueChanged(QString name, QString value, int action, bool apply);
00346 private:
00347    QString itemName;  
00348    double scale;
00349    bool blockSignal;
00350    QString orig;
00351 };
00352 
00353 
00354 //# ////////////////////////  QtLineEditor  ////////////////////////////////
00355 
00356 class QtLineEditor : public QWidget, private Ui::LineEditorItem {
00357     Q_OBJECT
00358 public:
00359      QtLineEditor(QWidget *parent=0);
00360      QtLineEditor(QDomElement &ele, QWidget *parent=0);
00361     ~QtLineEditor();
00362     Bool validate(QString value);
00363     void setLabelText(QString txt) {nameLabel->setText(txt);}
00364     QString name(){ return itemName; } 
00365     void reSet(QString);
00366 public slots:   
00367    void validateAndEmit(QString value);    
00368    void editingFinished();
00369    void setOriginal();
00370    void setDefault();
00371    void setCopy();
00372    void setPaste();   
00373 signals:
00374    void itemValueChanged(QString name, QString value, int action, bool apply);
00375 private:
00376    QString ptype;
00377    QString itemName;  
00378    QString origValue;
00379    bool blockSignal;
00380 };
00381 
00382 
00383 //# ////////////////////////   QtCombo  ////////////////////////////////////
00384 
00385 class QtCombo : public QWidget, private Ui::ComboItem {
00386     Q_OBJECT
00387 public:
00388      QtCombo(QWidget *parent=0);
00389      QtCombo(QDomElement &ele, QWidget *parent=0);
00390     ~QtCombo();
00391     void setLabelText(QString txt) {nameLabel->setText(txt);}
00392     QString name(){ return itemName; } 
00393     void reSet(QString);
00394 public slots:   
00395    void setOriginal();
00396    void setDefault();
00397    void setCopy();
00398    void setPaste();    
00399 signals:
00400    void itemValueChanged(QString name, QString value, int action, bool apply);
00401 protected slots:   
00402    void emitValue(); 
00403 private:
00404    QString itemName;     
00405    bool blockSignal;
00406    QString orig;
00407 };
00408 
00409 
00410 //# ////////////////////////   QtBoolean  //////////////////////////////////
00411 
00412 class QtBool : public QWidget, private Ui::ComboItem {
00413     Q_OBJECT
00414 public:
00415      QtBool(QWidget *parent=0);
00416      QtBool(QDomElement &ele, QWidget *parent=0);
00417     ~QtBool();
00418     void setLabelText(QString txt) {nameLabel->setText(txt);}
00419     QString name(){ return itemName; } 
00420     void reSet(QString);
00421 public slots:   
00422    void setOriginal();
00423    void setDefault();
00424    void setCopy();
00425    void setPaste();    
00426 signals:
00427    void itemValueChanged(QString name, QString value, int action, bool apply);
00428 protected slots:   
00429    void emitValue(); 
00430 private:
00431    QString itemName;     
00432    bool blockSignal;
00433    QString orig;
00434 };
00435 
00436 
00437 //# ////////////////////////  QtPushButton  ////////////////////////////////
00438 
00439 class QtPushButton : public QWidget, private Ui::PushButtonItem {
00440     Q_OBJECT
00441 public:
00442      QtPushButton(QWidget *parent=0);
00443      QtPushButton(QDomElement &ele, QWidget *parent=0);
00444     ~QtPushButton();
00445     void setLabelText(QString txt) {nameLabel->setText(txt);}
00446     QString name(){ return itemName; } 
00447     void reSet(QString);
00448 signals:
00449    void itemValueChanged(QString name, QString value, int action, bool apply);
00450 protected slots:   
00451    void emitValue(); 
00452 private:
00453    QString itemName;     
00454    bool blockSignal;
00455 };
00456 
00457 
00458 //# ////////////////////////  QtCheck  /////////////////////////////////////
00459 
00460 class QtCheck : public QWidget, private Ui::CheckItem {
00461     Q_OBJECT
00462 public:
00463      QtCheck(QWidget *parent=0);
00464      QtCheck(QDomElement &ele, QWidget *parent=0);
00465     ~QtCheck();
00466     void setLabelText(QString txt) {nameLabel->setText(txt);}
00467     QString name(){ return itemName; } 
00468     // [Re]sets state of checkboxes and internal record of that,
00469     // without emitting itemValueChanged.
00470     void reSet(QString);
00471     
00472 public slots:   
00473    void setOriginal();
00474    void setDefault();
00475    void setCopy();
00476    void setPaste();     
00477 signals:
00478    void itemValueChanged(QString name, QString value, int action, bool apply);
00479 protected slots:   
00480    void checkboxChanged(int newState);
00481    void emitValue(); 
00482    void reSet(QStringList);
00483    void reSet();
00484 private:
00485    QList<QCheckBox*> checkboxes_;        //# all checkboxes
00486    QStringList allopts_;                //# Names of all checkboxes
00487    QStringList opts_;           //# Names of currently checked boxes
00488    QStringList orig_;           //# Names of boxes checked originally
00489    QString itemName;     
00490 };
00491 
00492 
00493 //# //////////////////////QtRegion//////////////////////////////////////////
00494 
00495 class QtRegionEditor : public QWidget, private Ui::LineEditorItem {
00496     Q_OBJECT
00497 public:
00498      QtRegionEditor(QWidget *parent=0);
00499      QtRegionEditor(QDomElement &ele, QWidget *parent=0);
00500     ~QtRegionEditor();
00501     bool validate(QString value);
00502     void setLabelText(QString txt) {nameLabel->setText(txt);}
00503     QString name(){ return itemName; } 
00504     void reSet(QString);
00505 public slots:   
00506    void display2(QString value);    
00507    void editingFinished();
00508    void setOriginal();
00509    void setDefault();
00510    void fromImg();
00511    void createRegion();
00512     void unset();
00513    void setCopy();
00514    void setPaste();
00515 signals:
00516    void itemValueChanged(QString name, QString value, int action, bool apply);
00517    
00518 private:
00519    QString ptype;
00520    QString itemName;  
00521    QString iamunset;
00522    bool blockSignal;
00523 };
00524 
00525 
00526 //# ////////////////////// QtPair ///////////////////////////////////////////
00527 
00528 class QtPairEditor : public QWidget, private Ui::PairItem {
00529     Q_OBJECT  
00530     
00531 public:
00532     QtPairEditor(QDomElement& ele, QWidget* parent = NULL);
00533     
00534     ~QtPairEditor();
00535     
00536     void reSet(QString value);
00537     
00538 signals:
00539     void itemValueChanged(QString name, QString value, int action, bool apply);
00540     
00541 protected slots:
00542     void editingFinished();
00543     
00544     void setOriginal();
00545     
00546 private:
00547     QString itemName;
00548     bool isDouble;
00549     QAbstractSpinBox* val1, *val2;
00550     std::pair<int, int> origVal1;
00551     std::pair<double, double> origVal2;
00552     
00553     std::pair<int, int> readIntPair(QString value);
00554     
00555     std::pair<double, double> readDoublePair(QString value);
00556 };
00557 
00558 
00559 //# ///////////////////// QtNumber ////////////////////////////////////////
00560 
00561 // can use PairItem because it's just a frame
00562 class QtNumberEditor : public QWidget, private Ui::PairItem {
00563     Q_OBJECT
00564     
00565 public:
00566     QtNumberEditor(QDomElement& ele, QWidget* parent = NULL);
00567     
00568     ~QtNumberEditor();
00569     
00570     void reSet(QString value);
00571     
00572 signals:
00573     void itemValueChanged(QString name, QString value, int action, bool apply);
00574     
00575 protected slots:
00576     void editingFinished();
00577     
00578     void setOriginal();
00579     
00580 private:
00581     QString itemName;
00582     bool isDouble;
00583     QAbstractSpinBox* val;
00584     int origVal1;
00585     double origVal2;
00586 };
00587 
00588 
00589 } //# NAMESPACE CASA - END
00590 
00591 
00592 
00593 #endif