Main Page | Namespace List | Class Hierarchy | Compound List | File List | Compound Members | File Members | Related Pages

doubleparam.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 
00003  File:    doubleparam.h
00004  Created: by Aidan Lane, November 26, 2003
00005  Updated: by Aidan Lane, February 26, 2004
00006  
00007  This file is part of Glitch
00008  Copyright (C) 2003-2004  Monash University, Clayton Campus, Australia
00009  Created by Aidan Lane, under the supervision of Jon McCormack.
00010  
00011  This program was developed to aid the students studying the CSE3313
00012  Computer Graphics course at Monash University.
00013  
00014  This software may contain portions that are copyright (C) 1993,
00015  Silicon Graphics, Inc. All Rights Reserved.
00016  
00017  Glitch is free software; you can redistribute it and/or modify
00018  it under the terms of the GNU General Public License as published by
00019  the Free Software Foundation, version 2.
00020  
00021  Glitch is distributed in the hope that it will be useful,
00022  but WITHOUT ANY WARRANTY; without even the implied warranty of
00023  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00024  GNU General Public License for more details.
00025  
00026  You should have received a copy of the GNU General Public License
00027  along with this program; if not, write to the Free Software
00028  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00029 
00030 *****************************************************************************/
00031 
00032 #ifndef __DOUBLEPARAM_H__
00033 #define __DOUBLEPARAM_H__
00034 
00035 
00036 #include <float.h>
00037 
00038 #include "cmdparam.h"
00039 #include "superspinbox.h"
00040 
00041 #define DOUBLE_MIN -DBL_MAX
00042 #define DOUBLE_MAX DBL_MAX
00043 #define DOUBLE_STEP 0.1
00044 #define DOUBLE_MAX_WIDGET_WIDTH 100
00045 
00046 
00056 class DoubleParam : public CmdParam {
00057 
00058     Q_OBJECT    // make QT's signal/slot system work
00059 
00060 public:
00061     DoubleParam( const char* formalVarName, const char* defaultValue,
00062         const char* exactTypeName = "GLdouble",
00063         double minValue = DOUBLE_MIN, double maxValue = DOUBLE_MAX,
00064         double stepValue = DOUBLE_STEP,
00065         int maxWidgetWidth = DOUBLE_MAX_WIDGET_WIDTH )
00066         : CmdParam( formalVarName, defaultValue, exactTypeName ),
00067             myMinValue(minValue), myMaxValue(maxValue), myStepValue(stepValue),
00068             myMaxWidgetWidth(maxWidgetWidth) {}
00069 
00070     // widgets
00071     virtual QWidget* createWidget( QWidget* parent, const char* name,
00072         const QObject *slotOwner, const char* member )
00073     {
00074         SuperSpinBox *w = new SuperSpinBox( myMinValue, myMaxValue,
00075                                             myStepValue, parent, name );
00076         connect( w, SIGNAL( valueChanged(double) ), slotOwner, member );
00077         return (QWidget*)w;
00078     }
00079 
00080     virtual void setWidgetValue( QWidget* widget, const QString& value ) {
00081         if ( widget != NULL )
00082             ((SuperSpinBox*)widget)->setValue( value.toDouble() );
00083     }
00084 
00085     virtual QString getWidgetValue( QWidget* widget ) {
00086         return ( widget != NULL )
00087             ? QString::number( ((SuperSpinBox*)widget)->value() )
00088             : QString::null;
00089     }
00090 
00096     virtual QString getStringRep( const QString& value ) const
00097     {
00098         QString str( value );
00099 
00100         // Ensure precision to atleast decimal point is shown
00101         // (i.e. append "." to integers)
00102         if ( str.find('.') == -1 && str.find('e') == -1 ) {
00103             str += ".0";
00104         }
00105 
00106         return str;
00107     }
00108 
00109     virtual int maxWidgetWidth() const {
00110         return myMaxWidgetWidth;
00111     }
00112 
00113 private:
00114     double myMinValue;
00115     double myMaxValue;
00116     double myStepValue;
00117     int    myMaxWidgetWidth;
00118 };
00119 
00120 
00121 #endif  // __DOUBLEPARAM_H__

Generated on Fri Feb 27 12:01:39 2004 for Glitch by doxygen 1.3.2