00001 00002 //------------------------------------------------------------------------------------------------- 00003 // 00004 // Header Name: zpushbutton.h 00005 // 00006 // General Description: EZX-style push buttons 00007 // 00008 //------------------------------------------------------------------------------------------------- 00009 // 00010 // Motorola Confidential Proprietary 00011 // Template ID and version: TMP_LFC_50068 Version 1.2 00012 // (c) Copyright Motorola 200{x}, All Rights Reserved 00013 // 00014 //------------------------------------------------------------------------------------------------- 00015 00016 #ifndef Z_PUSHBUTTON_H 00017 #define Z_PUSHBUTTON_H 00018 00019 #ifndef __cplusplus 00020 #error "This is a C++ header file; it requires C++ to compile." 00021 #endif 00022 00023 #include <qtoolbutton.h> 00024 #include <ZDirectPixmap.h> 00025 #include <ZSkin.h> 00026 00027 /** 00028 * Class that uses resource-file icons to draw pushbuttons. 00029 * 00030 * A ZPushButton has three states: 00031 * 00032 * 1. normal -- the button is not pressed and not disabled 00033 * 2. active -- the button is pressed 00034 * 3. disabled -- the button is diabled 00035 * 00036 * Each state is drawn by two operations. The first operation draws the 00037 * background of the button, and the second draws an overlay on top of 00038 * that background. 00039 * 00040 * If ZPushButton finds a pixmap for the button background in the skin, 00041 * it will load it. If not, ZPushButton will draw the background in the style 00042 * of a Context-Sensitive Toolbar (CST) button. 00043 * 00044 * If ZPushButton finds an overlay pixmap in the skin, it will 00045 * load it. If not, and the user has specified overlay text, ZPushButton 00046 * will use the text. If the user has not specified any text, ZPushButton 00047 * will only draw the background. 00048 * 00049 * If ZPushButton can not find a disabled pixmap in the skin, it will 00050 * 'dim' the normal pixmap. 00051 * 00052 * This means a button can be specified by zero to six pixmaps, as below: 00053 * 00054 * CamV_PhotoAlbum_O.g -- overlay to display when button not pressed 00055 * CamV_PhotoAlbum_OA.g -- overlay to display when button pressed 00056 * CamV_PhotoAlbum_OD.g -- overlay to display when button disabled 00057 * CamV_PhotoAlbum.g-- background when button enabled and not pressed 00058 * CamV_PhotoAlbum_A.g -- background when button enabled and pressed 00059 * CamV_PhotoAlbum_D.g -- background when button disabled. 00060 * 00061 * (Note: .jpg, .png, .gif, files are all stored as .g) 00062 * 00063 * Here are some other options: 00064 * 00065 * - no pixmap, user specifies text: button background is drawn with code 00066 * and text is overlaid. 00067 * 00068 * - CamV_PhotoAlbum.g, CamV_PhotoAlbum_A.g, no text: button is drawn 00069 * with first pixmap, or second pixmap when pressed. Nothing is overlaid. 00070 */ 00071 00072 class ZPushButton : public QToolButton 00073 { 00074 Q_OBJECT 00075 00076 public: 00077 00078 /** 00079 * used in constructor to determine what the left and right side of the button 00080 * look like. 00081 * 00082 * If there is another ZPushButton directly to the left, then 00083 * this button should have the JoinLeft flag set and the button to the left 00084 * should have the JoinRight flag set. This will give the buttons a nice 00085 * appearance at the line where they join. 00086 * 00087 */ 00088 00089 enum Flags 00090 { 00091 NoFlags = 0, // default 00092 CSTStyle = 0, // default button style is CST 00093 JoinLeft = 1, // don't round the left edge 00094 JoinRight = 2, // don't round the right edge 00095 DialogSyle = 4 00096 }; 00097 00098 /** 00099 * 00100 * create a pushbutton 00101 * 00102 * @param parent is a pointer to the parent widget 00103 * @param flags are some combination of the flags above (default 00104 * is a CSTStyle button with no joins) 00105 * @param width is the width of the button 00106 * @param height is the height of the button 00107 * 00108 */ 00109 00110 ZPushButton(QWidget *parent, 00111 int flags = 0, // bitmask of Flags 00112 int width = -1, 00113 int height = -1); 00114 00115 /** 00116 * 00117 * create a pushbutton 00118 * 00119 * @param resourceID is the ID of the pixmap resource(s) inside 00120 * the resource file that are used to draw this button. 00121 * @param parent is a pointer to the parent widget 00122 * @param flags are some combination of the flags above (default 00123 * is a CSTStyle button with no joins) 00124 * @param width is the width of the button 00125 * @param height is the height of the button 00126 * 00127 */ 00128 00129 ZPushButton(const QString& resourceID, // id used to find pixmaps 00130 QWidget *parent, 00131 int flags = 0, // bitmask of Flags 00132 int width = -1, 00133 int height = -1); 00134 00135 /** 00136 * 00137 * create a pushbutton 00138 * 00139 * @param resourceID is the ID of the pixmap resource(s) inside 00140 * the resource file that are used to draw this button. 00141 * @param overlayText is a text string overlaid on top of the button 00142 * @param parent is a pointer to the parent widget 00143 * @param flags are some combination of the flags above (default 00144 * is a CSTStyle button with no joins) 00145 * @param width is the width of the button 00146 * @param height is the height of the button 00147 * 00148 */ 00149 ZPushButton(const QString& resourceID, 00150 const QString& overlayText, 00151 QWidget *parent, 00152 int flags = 0, 00153 int width = -1, 00154 int height = -1); 00155 00156 /** 00157 * reimplemented 00158 */ 00159 virtual QSize sizeHint() const; 00160 00161 /** 00162 * reimplemented 00163 */ 00164 virtual void setMinimumSize(int minw, int minh); 00165 00166 /** 00167 * reimplemented 00168 */ 00169 virtual void setGeometry(int x, int y, int w, int h); 00170 00171 /** 00172 * reimplemented 00173 */ 00174 virtual void setGeometry(const QRect&); 00175 00176 /** 00177 * reimplemented 00178 */ 00179 virtual void resize(int w, int h); 00180 00181 /** 00182 * reimplemented 00183 */ 00184 virtual void resize(const QSize&); 00185 00186 /** 00187 * set the overlay text 00188 * 00189 * @param text text to be overlaid on the button 00190 */ 00191 virtual void setText(const QString& text); 00192 00193 /** 00194 * get the overlay text 00195 */ 00196 virtual QString text() const; 00197 00198 /** 00199 * Set an a popup menu that shows when this button is pressed 00200 * 00201 * @param popup pointer to QPopupMenu to show when this button is pressed 00202 */ 00203 void setPopup(QPopupMenu* popup); 00204 00205 /** 00206 * set the resourceID for this button 00207 */ 00208 void setResourceID(const QString& resourceID); 00209 00210 /** 00211 * returns the resourceID for this button 00212 */ 00213 QString resourceID() const; 00214 00215 /** 00216 * set the pushbutton flags 00217 */ 00218 void setFlags(int flags); 00219 00220 /** 00221 * returns the flags for this button 00222 */ 00223 int flags() const; 00224 00225 public slots: 00226 00227 /** 00228 * reimplemented 00229 */ 00230 virtual void polish(); 00231 00232 protected slots: 00233 00234 /** 00235 * reimplemented 00236 */ 00237 virtual void popupPressed(); 00238 00239 protected: 00240 00241 virtual void drawButton(QPainter*); 00242 00243 /** 00244 * initializers called by the various constructors 00245 */ 00246 void init(const QString& resourceID, 00247 const QString& overlayText, 00248 int flags, 00249 int width, 00250 int height); 00251 00252 00253 static const int minWidth; ///< minimum width 00254 static const int minHeight; ///< minimum height 00255 static const int defaultWidth; ///< default width 00256 static const int defaultHeight; ///< default height 00257 static const unsigned char multSixTenths[]; ///< table to multiply everything by 6/10 00258 00259 bool m_guessSize; ///< true if user hasn't specified size 00260 mutable bool m_isSizeCached; ///< if size has already been calculated 00261 mutable int m_cachedWidth; ///< cached width 00262 mutable int m_cachedHeight; ///< cached height 00263 00264 00265 /** 00266 * used for getting/drawing the actual button 00267 */ 00268 QPixmap normal() const; 00269 QPixmap normalPixmap() const; 00270 QPixmap normalOverlay() const; 00271 QPixmap normalOverlayPixmap() const; 00272 QPixmap active() const; 00273 QPixmap activePixmap() const; 00274 QPixmap activeOverlay() const; 00275 QPixmap activeOverlayPixmap() const; 00276 QPixmap disabled() const; 00277 QPixmap disabledPixmap() const; 00278 QPixmap disabledOverlay() const; 00279 QPixmap disabledOverlayPixmap() const; 00280 00281 /** 00282 * fast fixed-amount alpha blending functions for left and right edges 00283 */ 00284 void dim1(ZDirectPixmap& img, int x, int y, int h) const; 00285 void dim2(ZDirectPixmap& img, int x, int y, int h) const; 00286 void dim3(ZDirectPixmap& img, int x, int y, int h) const; 00287 void dim4(ZDirectPixmap& img, int x, int y, int h) const; 00288 void dim5(ZDirectPixmap& img, int x, int y, int h) const; 00289 00290 /** 00291 * line functions for drawing button edges 00292 */ 00293 void drawHLine(ZDirectPixmap& img, int x, int y, int w, const QColor& wc) const; 00294 void drawVLine(ZDirectPixmap& img, int x, int y, int h, const QColor& wc) const; 00295 00296 /** 00297 * gradient fill for tactium buttons 00298 */ 00299 void drawGrad(ZDirectPixmap& img, int x, int y, int w, int h, 00300 const QColor& start, const QColor& end) const; 00301 00302 /** 00303 * functions to actually draw buttons 00304 */ 00305 QPixmap drawNormal() const; ///< draw it when no PM is available 00306 QPixmap drawActive() const; ///< draw it when no PM is available 00307 QPixmap fade(const QPixmap&) const; ///< fade input pixmap 00308 00309 /** 00310 * state variables 00311 */ 00312 QString m_resourceID; ///< same as normalResourceID 00313 QString m_overlayText; ///< text overlaid on top of the normal pixmap 00314 int m_flags; ///< flags used when rendering the button 00315 bool m_pressed; ///< current button state 00316 }; 00317 00318 #endif // Z_PUSHBUTTON_H