00001 /* 00002 * The information in this file is 00003 * Copyright(c) 2007 Ball Aerospace & Technologies Corporation 00004 * and is subject to the terms and conditions of the 00005 * GNU Lesser General Public License Version 2.1 00006 * The license text is available from 00007 * http://www.gnu.org/licenses/lgpl.html 00008 */ 00009 00010 #ifndef ANIMATIONFRAMESPINBOX_H 00011 #define ANIMATIONFRAMESPINBOX_H 00012 00013 #include <vector> 00014 00015 #include <QtGui/QAbstractSpinBox> 00016 00017 #include "TypesFile.h" 00018 00019 class Animation; 00020 class AnimationController; 00021 class AnimationFrame; 00022 00023 /** 00024 * A spin box that will allow a user to select a frame of an animation. 00025 * 00026 * There are two types of animations: frame-based that uses frame values 00027 * to go though the frames and time-based that go though frames by using the number of 00028 * seconds since January 1, 1970. This spin box will handle both of these types. 00029 */ 00030 class AnimationFrameSpinBox : public QAbstractSpinBox 00031 { 00032 Q_OBJECT 00033 00034 public: 00035 /** 00036 * Creates a new animation spin box. 00037 * 00038 * @param pParent 00039 * The parent widget. 00040 */ 00041 AnimationFrameSpinBox(QWidget* pParent); 00042 00043 /** 00044 * Destroys the spin box. 00045 */ 00046 virtual ~AnimationFrameSpinBox(); 00047 00048 /** 00049 * This method will set up the vector of animation frames that will be 00050 * used in the spin box. 00051 * 00052 * @param frames 00053 * the animation frame vector. 00054 * @param type 00055 * The animation type. 00056 */ 00057 void setFrames(const std::vector<AnimationFrame>& frames, FrameType type); 00058 00059 /** 00060 * This method will set up the vector of animation frames that will be 00061 * used in the spin box. 00062 * 00063 * @param pController 00064 * the controller that holds the animation frames. 00065 */ 00066 void setFrames(AnimationController* pController); 00067 00068 /** 00069 * This method will set up the vector of animation frames that will be 00070 * used in the spin box. 00071 * 00072 * @param pAnimation 00073 * A set of animation frames. 00074 */ 00075 void setFrames(Animation* pAnimation); 00076 00077 /** 00078 * Returns a vector containing the spin box frames. 00079 * 00080 * @return The spin box frame vector. 00081 */ 00082 const std::vector<AnimationFrame>& getFrames() const; 00083 00084 /** 00085 * This method will make the spin box select the given animation 00086 * frame if it's in the spin box. 00087 * 00088 * @param frame 00089 * The animation frame to set in the spin box. 00090 */ 00091 void setCurrentFrame(const AnimationFrame& frame); 00092 00093 /** 00094 * This method will get the animation frame that is currently selected 00095 * in the spin box. 00096 * 00097 * @return The selected animation frame in the spin box. 00098 */ 00099 const AnimationFrame& getCurrentFrame() const; 00100 00101 /** 00102 * Updates the spin box text if the user triggers a step. 00103 * 00104 * @param steps 00105 * The number of steps. 00106 */ 00107 virtual void stepBy(int steps); 00108 00109 /** 00110 * Returns the type of animation. 00111 * 00112 * @return The animation type. 00113 */ 00114 FrameType getFrameType() const; 00115 00116 protected: 00117 /** 00118 * This method will determine whether the spin box can step up or step down. 00119 * 00120 * @return The spin box step state. 00121 */ 00122 virtual StepEnabled stepEnabled() const; 00123 00124 /** 00125 * This method will use the given index to get a frame from the animation frame vector 00126 * and convert the frame value to text. 00127 * 00128 * If there are no frames in the spin box, this method will return an empty string. 00129 * 00130 * @param index 00131 * The frame index used to convert the frame to text. 00132 * 00133 * @return The string containing the frame value. 00134 */ 00135 virtual QString convertToText(int index); 00136 00137 signals: 00138 /** 00139 * Called when the spin box text has been changed. 00140 * 00141 * @param frame 00142 * The new selected frame in the spin box. 00143 */ 00144 void frameChanged(const AnimationFrame& frame); 00145 00146 private: 00147 AnimationFrameSpinBox(const AnimationFrameSpinBox& rhs); 00148 AnimationFrameSpinBox& operator=(const AnimationFrameSpinBox& rhs); 00149 FrameType mType; 00150 std::vector<AnimationFrame> mFrames; 00151 int mIndex; 00152 }; 00153 00154 #endif