00001 //------------------------------------------------------------------------------------------------- 00002 // 00003 // Header Name: ZScrollView.h 00004 // 00005 // General Description: EZX ScrollView class 00006 // 00007 //------------------------------------------------------------------------------------------------- 00008 // 00009 // Motorola Confidential Proprietary 00010 // Template ID and version: TMP_LFC_50068 Version 1.2 00011 // (c) Copyright Motorola 200{x}, All Rights Reserved 00012 // 00013 //------------------------------------------------------------------------------------------------- 00014 00015 #ifndef Z_SCROLLVIEW_H 00016 #define Z_SCROLLVIEW_H 00017 00018 #ifndef __cplusplus 00019 #error "This is a C++ header file;it requires C++ to compile." 00020 #endif 00021 00022 #include <qscrollview.h> 00023 #include <qsize.h> 00024 #include <qrect.h> 00025 00026 class ZScrollViewData; 00027 00028 /** 00029 * ZScrollView is similar to QScrollView, but has a few additional behaviors: 00030 * 00031 * 1. Adjusts the children's geometry automatically when the size of 00032 * ZMultiLineEdit child is changed because of text set. 00033 * 00034 * 2. Changes the geometry of the text-entry area when the keyboard is shown/ 00035 * hidden. 00036 * 00037 * @code 00038 * ZScrollView* sv = new ZScrollView( this, "sv" ); 00039 * sv->enableClipper(true); 00040 * UTIL_MulitLineEdit *ml1, *ml2; 00041 * 00042 * //add a 6 lines ZMultiLineEdit 00043 * ml1 = new ZMultiLineEdit(sv->viewport(),true,6); 00044 * sv->addChild(ml1,0,0); 00045 * 00046 * //set indent 00047 * ml1->setIndent(20); 00048 * ml2 = new ZMultiLineEdit(sv->viewport()); 00049 * 00050 * //need to change the widget width when ZScrollView's scrollbar is shown/hidden 00051 * sv->addChild(ml2,0,30,true); 00052 * @endcode 00053 00054 * @see ZMultiLineEdit 00055 * 00056 * @note for the class, has change the scrollview's resize policy to Manual 00057 * setResizePolicy(Manual), and turn off the horizon scroll bar 00058 * setHScrollBarMode(QScrollView::AlwaysOff). 00059 */ 00060 00061 class ZScrollView : public QScrollView 00062 { 00063 Q_OBJECT 00064 00065 public: 00066 00067 /** 00068 * Constructor of ZScrollView 00069 */ 00070 ZScrollView( QWidget* parent = 0, const char* name = 0, WFlags f = 0) ; 00071 00072 /** 00073 * Destructor of ZScrollView. 00074 */ 00075 virtual ~ZScrollView(); 00076 00077 /** 00078 * Reimplement 00079 */ 00080 virtual void addChild( QWidget* child, int x = 0, int y = 0 ); 00081 00082 /** 00083 * ZScrollView's addChild. 00084 * 00085 * @param autoAdjustWidth if true when vertical scrollbar appears/disappear, 00086 * the widget's width will be adjusted, it is width() -(+) verticalScrollBar->width() 00087 */ 00088 virtual void addChild( QWidget* child, int x, int y, bool autoAdjustWidth ); 00089 00090 /** 00091 * ZScrollView's moveChild. 00092 * 00093 * @param autoAdjustWidth if true when vertical scrollbar appears/disappear, 00094 * the widget's width will be adjusted, it is width() -(+) verticalScrollBar->width() 00095 */ 00096 virtual void moveChild( QWidget* child, int x, int y, bool autoAdjustWidth = false ); 00097 00098 /** 00099 * Update Content Size correctly by the all children's frame geometry 00100 */ 00101 void updateContentSize(); 00102 00103 /** 00104 * Set a flag for flush events in doLayout(), it is to call sendPostedEvents() 00105 * which reduces screen flash. 00106 * 00107 * By default, the flag is on. 00108 * 00109 * If the application needs to assure the sequence of the events during the period, 00110 * please turn off the flag. 00111 * 00112 * @param flush if true need to flush the events during doLayout 00113 * 00114 * @see doLayout() 00115 */ 00116 void setFlushEvents( bool flush = true ); 00117 00118 /** 00119 * Get the flush event flag 00120 * 00121 * @see setFlushEvents() 00122 */ 00123 bool getFlushEvents() const; 00124 00125 /** 00126 * Set the flag to do layout automatically, usually doing layout is caused 00127 * by the ZMultiLineEdit's text change. 00128 * 00129 * @param doLayout if true, do layout automatically, or need to do layout by yourself 00130 * The default is to do layout automatically. 00131 * 00132 * @see doLayout() 00133 */ 00134 void setAutoLayout( bool doLayout = true ); 00135 00136 /** 00137 * Get the DoLayout flag 00138 * 00139 * @see setDoLayout() 00140 */ 00141 bool getAutoLayout() const; 00142 00143 public slots: 00144 00145 /** 00146 * Reimplement 00147 */ 00148 virtual void show(); 00149 00150 /** 00151 * Reimplement 00152 */ 00153 virtual void hide(); 00154 00155 /** 00156 * Layout the children in the ZScrollView. 00157 * 00158 * @param widget the widget whose geometry changed. 00159 * @param size the size(height and width) changed. Now only supports height 00160 * @param cursorPos the cursor's position. 00161 * @param enlarge if true the size of widget is enlarged 00162 */ 00163 virtual void doLayout( QWidget* widget,QSize size,QPoint cursorPos,int enlarge ); 00164 00165 /** 00166 * ZScrollView's enableClipper 00167 */ 00168 void enableClipper( bool clipper ); 00169 00170 signals: 00171 00172 /** 00173 * Emitted when the vertical scrollbar of the ZScrollView is shown/hidden 00174 * 00175 * @param show if true, the vertical scrollbar is shown 00176 */ 00177 void vScrollBarStateChanged( int show ); 00178 00179 protected: 00180 00181 /** 00182 * Reimplement 00183 */ 00184 virtual bool eventFilter( QObject *obj, QEvent* event ); 00185 00186 /** 00187 * Reimplement 00188 */ 00189 virtual bool event ( QEvent* event ); 00190 00191 /** 00192 * Reimplement 00193 */ 00194 virtual void keyPressEvent( QKeyEvent* event ); 00195 00196 00197 private: 00198 00199 void removeSVChild( QWidget* child ); 00200 00201 private slots: 00202 00203 void updateFieldsWidth( int cause ); 00204 void makeFocusWidgetVisible( bool show ); 00205 00206 private: 00207 00208 bool flushEvents; 00209 bool autoLayout; 00210 ZScrollViewData* d; 00211 }; 00212 00213 #endif