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) {
00069                         dataName->setText(txt);
00070                 }
00071                 ~QtAdjustmentTop();
00072         public slots:
00073                 void dataNameChanged(QString value);
00074                 void setOriginal();
00075                 void setDefault();
00076                 void setMemory();
00077                 void setClear();
00078                 void setCopy();
00079                 void setPaste();
00080                 void apply();
00081                 void load();
00082                 void save();
00083                 void restore();
00084                 void close();
00085 
00086                 void hideDismiss();             //#dk
00087 
00088         private:
00089                 QtAutoGui *parent;
00090                 bool blockSignal;
00091         };
00092 
00093 
00094 //# ///////////////////  QtSliderBase //////////////////////////////////////
00095 
00096 
00097 // <summary>
00098 // Base class for QtAutoGui slider interface elements.
00099 // </summary>
00100 
00101 // <synopsis>
00102 // This is a base with common functionality for the two slider 'guientries':
00103 // QtSliderEditor, which has a value edit box, and QtSliderLabel, with a
00104 // non-editable value label.  This class is abstract; its constructor can only
00105 // be called by a derived class.  That class should also call constructBase()
00106 // after cxreating its interface elements, to complete construction.
00107 // </synopsis>
00108 
00109         class QtSliderBase : public QWidget {
00110 
00111                 Q_OBJECT        //# Allows slot/signal definition.  Must only occur in
00112                 //# implement/.../*.h files; also, makefile must include
00113                 //# name of this file in 'mocs' section.
00114 
00115         public:
00116 
00117                 // Set interface label text ('listname').
00118                 void setLabelText(QString txt) {
00119                         nameLabel_->setText(txt);
00120                 }
00121 
00122                 // Internal name ('dlformat')
00123                 QString name() {
00124                         return itemName;
00125                 }
00126 
00127                 // Set up main state (value, etc.) and external appearance of
00128                 // this widget, according to options record (passed as a QDomElement).
00129                 // Called via constructor, and from QtAutoGui::changeOptions().
00130                 // Does not trigger (significant) signals; it is intended to set this
00131                 // interface element to library's internal value (not vice versa).
00132                 void reSet(QDomElement& ele);
00133 
00134         protected:
00135 
00136                 // Only for use by derived classes.
00137                 // <group>
00138                 QtSliderBase(QWidget *parent=0) : QWidget(parent) {  }
00139                 ~QtSliderBase() {  }
00140                 // </group>
00141 
00142                 // Derived class should call this within its constructor, after it
00143                 // has a valid QSlider, name QLabel and menu QToolButton (usually,
00144                 // after calling setUi()), passing them down in the parameters below.
00145                 // ele is the QDomElement (an xml version of an option Record) used to
00146                 // construct the derived class.
00147                 void constructBase(QDomElement &ele,  QSlider* slider,
00148                                    QLabel* nameLabel, QToolButton* menuBtn);
00149 
00150                 // Fetch numeric value of attribute of ele named attnm, into val.
00151                 // Does nothing if attr doesn't exist or is not valid numerically.
00152                 void getAttr(const QDomElement& ele, QString attnm, Double& val);
00153 
00154         protected slots:
00155 
00156                 // slider changed by user
00157                 virtual void slChg(int slval) {
00158                         update(externalVal(slval));
00159                         if ( ! onrelease_ ) emitVal( );
00160                 }
00161                 virtual void release( )         {
00162                         if (   onrelease_ ) emitVal( );
00163                 }
00164 
00165                 // 'revert-to-original' selected in menu.
00166                 virtual void setOriginal();
00167 
00168 
00169         signals:
00170 
00171                 // Main output signal.  Main parameters of interest are item name and
00172                 // new value.
00173                 void itemValueChanged(QString name, QString value, int action, bool apply);
00174 
00175                 // class user may wish to connect to and display these.
00176                 void errMsg(String errmsg);
00177 
00178 
00179         protected:
00180 
00181                 // Derived class should implement: set value text box or label (if any)
00182                 // to (normalized) current value.  (Should not trigger class's own slots).
00183                 virtual void updateText() = 0;
00184 
00185 
00186                 Int round(Double val) {
00187                         return ifloor(val + .5);
00188                 }
00189 
00190                 // Integer values with in [0, slMax_] on the internal slider are scaled
00191                 // to external values within [dMin_, dMax_].
00192                 // These two routines convert between the two scalings.
00193                 // <group>
00194                 Double externalVal(Int sldVal) {
00195                         return min(dMax_, (dMin_ + max(0., dIncr_*sldVal)));
00196                 }
00197 
00198                 Int sliderVal(Double extVal) {
00199                         return round(max(0., min(slMax_, (extVal-dMin_)/dIncr_)));
00200                 }
00201                 // </group>
00202 
00203                 // These two routines convert 'external' values between Double and
00204                 // text.
00205                 // <group>
00206                 QString toText(Double val);
00207                 Double toNumber(QString text, bool* ok=0);
00208                 // </group>
00209 
00210                 // Current external value, as text.
00211                 QString textVal() {
00212                         return toText(dVal_);
00213                 }
00214 
00215                 // Adjusts integer slider range (slMax_) and the increment that each
00216                 // unit on the slider represents (dIncr_), according to latest
00217                 // increment and range request (dIncr0_,  dMin_, dMax_).
00218                 void adjSlIncr();
00219 
00220                 // Sets slider to latest range and value (without
00221                 // triggering slider signals or slChg slot below).
00222                 void updateSlider();
00223 
00224                 // emit current value -- widget's main output.
00225                 void emitVal();
00226 
00227                 // Accepts new value (if any), updates interface (without
00228                 // retriggering any internal slots).
00229                 // New value should already have been validated.
00230                 void update(Double dval);
00231 
00232 
00233                 // main state.  Determines the float scaling for the (necessarily int)
00234                 // QSlider.  dVal_ is the slider's 'external' value (which may be
00235                 // floating-point).  dMin_ and dMax_ are its 'external' range.
00236                 // dIncr0_ is the requested 'external' slider increment ('presolution'),
00237                 // dIncr_ is the increment actually used (normally, these will be the same).
00238                 //
00239                 // Internally, the slider's range will be [0, slMax_]; slMax_
00240                 // will be a non-negative integer value.  Both of the QSlider's
00241                 // internal increments (singleStep, pageStep) will be 1.
00242 
00243                 Double dVal_,  dMin_, dMax_,  dIncr_, dIncr0_,  slMax_;
00244 
00245                 // Whether this element emits float values (ptype 'floatrange')
00246                 // vs. ints (ptype 'intrange').
00247                 Bool floatrng_;
00248 
00249                 // Should the event be generated only upon releasing the slider?
00250                 bool onrelease_;
00251 
00252                 // For restoring 'original' value.
00253                 Double origVal_;
00254 
00255                 // Relevant user interface elements.  Must be created by
00256                 // derived class and passed in via constructBase().
00257                 // <group>
00258                 QSlider* slider_;
00259                 QLabel* nameLabel_;
00260                 QToolButton* menuBtn_;
00261                 // </group>
00262 
00263                 // Internal name ('dlformat').
00264                 QString itemName;
00265 
00266         };
00267 
00268 
00269 
00270 //# ////////////////////  QtSliderEditor ///////////////////////////////////
00271 
00272 
00273         class QtSliderEditor : public QtSliderBase, private Ui::SliderEditorItem {
00274 
00275                 Q_OBJECT        //# Allows slot/signal definition.  Must only occur in
00276                 //# implement/.../*.h files; also, makefile must include
00277                 //# name of this file in 'mocs' section.
00278 
00279         public:
00280 
00281                 QtSliderEditor(QDomElement& ele, QWidget *parent=0);
00282                 ~QtSliderEditor() {  }
00283 
00284         protected:
00285 
00286                 // (not intended for use at present).
00287                 QtSliderEditor(QWidget *parent=0): QtSliderBase(parent) {
00288                         setupUi(this);
00289                         radioButton->hide();
00290                 }
00291 
00292                 // Sets text box to (normalized) current value.
00293                 // (Should not trigger class's own slots either).
00294                 void updateText() {
00295                         lineEdit->setText(textVal());
00296                 }
00297 
00298                 // main validation/update routine for changes to text version of value.
00299                 // strval is the candidate text, which is still to be validated/normalized.
00300                 void textChg(QString strval);
00301 
00302         protected slots:
00303 
00304                 //# text edited by user
00305                 virtual void edited()      {
00306                         textChg(lineEdit->text());
00307                 }
00308 
00309                 //# // Triggered when 'revert-to-original' selected in menu
00310                 //# virtual void setOriginal() { textChg(toText(origVal_));  }
00311                 //#     //# (This version _will expand slider limits, if necessary).
00312 
00313         };
00314 
00315 
00316 
00317 //# ///////////////////////  QtSliderLabel /////////////////////////////////
00318 
00319 
00320         class QtSliderLabel : public QtSliderBase, private Ui::SliderLabelItem {
00321 
00322                 Q_OBJECT        //# Allows slot/signal definition.  Must only occur in
00323                 //# implement/.../*.h files; also, makefile must include
00324                 //# name of this file in 'mocs' section.
00325 
00326         public:
00327 
00328                 QtSliderLabel(QDomElement& ele, QWidget *parent=0);
00329                 ~QtSliderLabel() {  }
00330 
00331         protected:
00332 
00333                 // (not intended for use at present).
00334                 QtSliderLabel(QWidget *parent=0): QtSliderBase(parent) {
00335                         setupUi(this);
00336                 }
00337 
00338                 // Sets value label to (normalized) current value.
00339                 void updateText();
00340 
00341         };
00342 
00343 
00344 
00345 
00346 //# ////////////////////////  QtMinMaxEditor ///////////////////////////////
00347 
00348         class QtMinMaxEditor : public QWidget, private Ui::MinMaxEditorItem {
00349                 Q_OBJECT
00350         public:
00351                 QtMinMaxEditor(QWidget *parent=0);
00352                 QtMinMaxEditor(QDomElement &ele, QWidget *parent=0);
00353                 ~QtMinMaxEditor();
00354                 bool validate(QString value);
00355                 void setLabelText(QString txt) {
00356                         nameLabel->setText(txt);
00357                 }
00358                 QString name() {
00359                         return itemName;
00360                 }
00361                 void reSet(QString);
00362         public slots:
00363                 void display2();
00364                 void display2(int value);
00365                 void display2(QString value);
00366                 void setOriginal();
00367                 void setDefault();
00368                 void setCopy();
00369                 void setPaste();
00370                 void setHistogram();
00371         signals:
00372                 void itemValueChanged(QString name, QString value, int action, bool apply);
00373         private:
00374                 QString itemName;
00375                 double scale;
00376                 bool blockSignal;
00377                 QString orig;
00378         };
00379 
00380 
00381 //# ////////////////////////  QtLineEditor  ////////////////////////////////
00382 
00383         class QtLineEditor : public QWidget, private Ui::LineEditorItem {
00384                 Q_OBJECT
00385         public:
00386                 QtLineEditor(QWidget *parent=0);
00387                 QtLineEditor(QDomElement &ele, QWidget *parent=0);
00388                 ~QtLineEditor();
00389                 Bool validate(QString value);
00390                 void setLabelText(QString txt) {
00391                         nameLabel->setText(txt);
00392                 }
00393                 QString name() {
00394                         return itemName;
00395                 }
00396                 void reSet(QString);
00397         public slots:
00398                 void validateAndEmit(QString value);
00399                 void editingFinished();
00400                 void setOriginal();
00401                 void setDefault();
00402                 void setCopy();
00403                 void setPaste();
00404         signals:
00405                 void itemValueChanged(QString name, QString value, int action, bool apply);
00406         protected:
00407                 void leaveEvent(QEvent*);
00408         private:
00409                 QString ptype;
00410                 QString itemName;
00411                 QString origValue;
00412                 bool blockSignal;
00413         };
00414 
00415 
00416 //# ////////////////////////   QtCombo  ////////////////////////////////////
00417 
00418         class QtCombo : public QWidget, private Ui::ComboItem {
00419                 Q_OBJECT
00420         public:
00421                 QtCombo(QWidget *parent=0);
00422                 QtCombo(QDomElement &ele, QWidget *parent=0);
00423                 ~QtCombo();
00424                 void setLabelText(QString txt) {
00425                         nameLabel->setText(txt);
00426                 }
00427                 QString name() {
00428                         return itemName;
00429                 }
00430                 void reSet(QString);
00431         public slots:
00432                 void setOriginal();
00433                 void setDefault();
00434                 void setCopy();
00435                 void setPaste();
00436         signals:
00437                 void itemValueChanged(QString name, QString value, int action, bool apply);
00438         protected slots:
00439                 void emitValue();
00440         private:
00441                 QString itemName;
00442                 bool blockSignal;
00443                 QString orig;
00444         };
00445 
00446 
00447 //# ////////////////////////   QtBoolean  //////////////////////////////////
00448 
00449         class QtBool : public QWidget, private Ui::ComboItem {
00450                 Q_OBJECT
00451         public:
00452                 QtBool(QWidget *parent=0);
00453                 QtBool(QDomElement &ele, QWidget *parent=0);
00454                 ~QtBool();
00455                 void setLabelText(QString txt) {
00456                         nameLabel->setText(txt);
00457                 }
00458                 QString name() {
00459                         return itemName;
00460                 }
00461                 void reSet(QString);
00462         public slots:
00463                 void setOriginal();
00464                 void setDefault();
00465                 void setCopy();
00466                 void setPaste();
00467         signals:
00468                 void itemValueChanged(QString name, QString value, int action, bool apply);
00469         protected slots:
00470                 void emitValue();
00471         private:
00472                 QString itemName;
00473                 bool blockSignal;
00474                 QString orig;
00475         };
00476 
00477 
00478 //# ////////////////////////  QtPushButton  ////////////////////////////////
00479 
00480         class QtPushButton : public QWidget, private Ui::PushButtonItem {
00481                 Q_OBJECT
00482         public:
00483                 QtPushButton(QWidget *parent=0);
00484                 QtPushButton(QDomElement &ele, QWidget *parent=0);
00485                 ~QtPushButton();
00486                 void setLabelText(QString txt) {
00487                         nameLabel->setText(txt);
00488                 }
00489                 QString name() {
00490                         return itemName;
00491                 }
00492                 void reSet(QString);
00493         signals:
00494                 void itemValueChanged(QString name, QString value, int action, bool apply);
00495         protected slots:
00496                 void emitValue();
00497         private:
00498                 QString itemName;
00499                 bool blockSignal;
00500         };
00501 
00502 
00503 //# ////////////////////////  QtCheck  /////////////////////////////////////
00504 
00505         class QtCheck : public QWidget, private Ui::CheckItem {
00506                 Q_OBJECT
00507         public:
00508                 QtCheck(QWidget *parent=0);
00509                 QtCheck(QDomElement &ele, QWidget *parent=0);
00510                 ~QtCheck();
00511                 void setLabelText(QString txt) {
00512                         nameLabel->setText(txt);
00513                 }
00514                 QString name() {
00515                         return itemName;
00516                 }
00517                 // [Re]sets state of checkboxes and internal record of that,
00518                 // without emitting itemValueChanged.
00519                 void reSet(QString);
00520 
00521         public slots:
00522                 void setOriginal();
00523                 void setDefault();
00524                 void setCopy();
00525                 void setPaste();
00526         signals:
00527                 void itemValueChanged(QString name, QString value, int action, bool apply);
00528         protected slots:
00529                 void checkboxChanged(int newState);
00530                 void emitValue();
00531                 void reSet(QStringList);
00532                 void reSet();
00533         private:
00534                 QList<QCheckBox*> checkboxes_;   //# all checkboxes
00535                 QStringList allopts_;           //# Names of all checkboxes
00536                 QStringList opts_;              //# Names of currently checked boxes
00537                 QStringList orig_;              //# Names of boxes checked originally
00538                 QString itemName;
00539         };
00540 
00541 
00542 //# //////////////////////QtRegion//////////////////////////////////////////
00543 
00544         class QtRegionEditor : public QWidget, private Ui::LineEditorItem {
00545                 Q_OBJECT
00546         public:
00547                 QtRegionEditor(QWidget *parent=0);
00548                 QtRegionEditor(QDomElement &ele, QWidget *parent=0);
00549                 ~QtRegionEditor();
00550                 bool validate(QString value);
00551                 void setLabelText(QString txt) {
00552                         nameLabel->setText(txt);
00553                 }
00554                 QString name() {
00555                         return itemName;
00556                 }
00557                 void reSet(QString);
00558         public slots:
00559                 void display2(QString value);
00560                 void editingFinished();
00561                 void setOriginal();
00562                 void setDefault();
00563                 void fromImg();
00564                 void createRegion();
00565                 void unset();
00566                 void setCopy();
00567                 void setPaste();
00568         signals:
00569                 void itemValueChanged(QString name, QString value, int action, bool apply);
00570 
00571         private:
00572                 QString ptype;
00573                 QString itemName;
00574                 QString iamunset;
00575                 bool blockSignal;
00576         };
00577 
00578 
00579 //# ////////////////////// QtPair ///////////////////////////////////////////
00580 
00581         class QtPairEditor : public QWidget, private Ui::PairItem {
00582                 Q_OBJECT
00583 
00584         public:
00585                 QtPairEditor(QDomElement& ele, QWidget* parent = NULL);
00586 
00587                 ~QtPairEditor();
00588 
00589                 void reSet(QString value);
00590 
00591         signals:
00592                 void itemValueChanged(QString name, QString value, int action, bool apply);
00593 
00594         protected slots:
00595                 void editingFinished();
00596 
00597                 void setOriginal();
00598 
00599         private:
00600                 QString itemName;
00601                 bool isDouble;
00602                 QAbstractSpinBox* val1, *val2;
00603                 std::pair<int, int> origVal1;
00604                 std::pair<double, double> origVal2;
00605 
00606                 std::pair<int, int> readIntPair(QString value);
00607 
00608                 std::pair<double, double> readDoublePair(QString value);
00609         };
00610 
00611 
00612 //# ///////////////////// QtNumber ////////////////////////////////////////
00613 
00614 // can use PairItem because it's just a frame
00615         class QtNumberEditor : public QWidget, private Ui::PairItem {
00616                 Q_OBJECT
00617 
00618         public:
00619                 QtNumberEditor(QDomElement& ele, QWidget* parent = NULL);
00620 
00621                 ~QtNumberEditor();
00622 
00623                 void reSet(QString value);
00624 
00625         signals:
00626                 void itemValueChanged(QString name, QString value, int action, bool apply);
00627 
00628         protected slots:
00629                 void editingFinished();
00630 
00631                 void setOriginal();
00632 
00633         private:
00634                 QString itemName;
00635                 bool isDouble;
00636                 QAbstractSpinBox* val;
00637                 int origVal1;
00638                 double origVal2;
00639         };
00640 
00641 
00642 } //# NAMESPACE CASA - END
00643 
00644 
00645 
00646 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1