Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef QTTABLEVIEW_H
00016 #define QTTABLEVIEW_H
00017
00018 #ifndef QT_H
00019 #include <qframe.h>
00020 #endif // QT_H
00021
00022 #ifndef QT_NO_QTTABLEVIEW
00023
00024 class QScrollBar;
00025 class QCornerSquare;
00026
00027
00028 class QtTableView : public QFrame
00029 {
00030 Q_OBJECT
00031 public:
00032 virtual void setBackgroundColor( const QColor & );
00033 virtual void setPalette( const QPalette & );
00034 void show();
00035
00036 void repaint( bool erase=TRUE );
00037 void repaint( int x, int y, int w, int h, bool erase=TRUE );
00038 void repaint( const QRect &, bool erase=TRUE );
00039
00040 protected:
00041 QtTableView( QWidget *parent=0, const char *name=0, WFlags f=0 );
00042 ~QtTableView();
00043
00044 int numRows() const;
00045 virtual void setNumRows( int );
00046 int numCols() const;
00047 virtual void setNumCols( int );
00048
00049 int topCell() const;
00050 virtual void setTopCell( int row );
00051 int leftCell() const;
00052 virtual void setLeftCell( int col );
00053 virtual void setTopLeftCell( int row, int col );
00054
00055 int xOffset() const;
00056 virtual void setXOffset( int );
00057 int yOffset() const;
00058 virtual void setYOffset( int );
00059 virtual void setOffset( int x, int y, bool updateScrBars = TRUE );
00060
00061 virtual int cellWidth( int col );
00062 virtual int cellHeight( int row );
00063 int cellWidth() const;
00064 int cellHeight() const;
00065 virtual void setCellWidth( int );
00066 virtual void setCellHeight( int );
00067
00068 virtual int totalWidth();
00069 virtual int totalHeight();
00070
00071 uint tableFlags() const;
00072 bool testTableFlags( uint f ) const;
00073 virtual void setTableFlags( uint f );
00074 void clearTableFlags( uint f = ~0 );
00075
00076 bool autoUpdate() const;
00077 virtual void setAutoUpdate( bool );
00078
00079 void updateCell( int row, int column, bool erase=TRUE );
00080
00081 QRect cellUpdateRect() const;
00082 QRect viewRect() const;
00083
00084 int lastRowVisible() const;
00085 int lastColVisible() const;
00086
00087 bool rowIsVisible( int row ) const;
00088 bool colIsVisible( int col ) const;
00089
00090 QScrollBar *verticalScrollBar() const;
00091 QScrollBar *horizontalScrollBar() const;
00092
00093 private slots:
00094 void horSbValue( int );
00095 void horSbSliding( int );
00096 void horSbSlidingDone();
00097 void verSbValue( int );
00098 void verSbSliding( int );
00099 void verSbSlidingDone();
00100
00101 protected:
00102 virtual void paintCell( QPainter *, int row, int col ) = 0;
00103 virtual void setupPainter( QPainter * );
00104
00105 void paintEvent( QPaintEvent * );
00106 void resizeEvent( QResizeEvent * );
00107
00108 int findRow( int yPos ) const;
00109 int findCol( int xPos ) const;
00110
00111 bool rowYPos( int row, int *yPos ) const;
00112 bool colXPos( int col, int *xPos ) const;
00113
00114 int maxXOffset();
00115 int maxYOffset();
00116 int maxColOffset();
00117 int maxRowOffset();
00118
00119 int minViewX() const;
00120 int minViewY() const;
00121 int maxViewX() const;
00122 int maxViewY() const;
00123 int viewWidth() const;
00124 int viewHeight() const;
00125
00126 void scroll( int xPixels, int yPixels );
00127 void updateScrollBars();
00128 void updateTableSize();
00129
00130 private:
00131 void coverCornerSquare( bool );
00132 void snapToGrid( bool horizontal, bool vertical );
00133 virtual void setHorScrollBar( bool on, bool update = TRUE );
00134 virtual void setVerScrollBar( bool on, bool update = TRUE );
00135 void updateView();
00136 int findRawRow( int yPos, int *cellMaxY, int *cellMinY = 0,
00137 bool goOutsideView = FALSE ) const;
00138 int findRawCol( int xPos, int *cellMaxX, int *cellMinX = 0,
00139 bool goOutsideView = FALSE ) const;
00140 int maxColsVisible() const;
00141
00142 void updateScrollBars( uint );
00143 void updateFrameSize();
00144
00145 void doAutoScrollBars();
00146 void showOrHideScrollBars();
00147
00148 int nRows;
00149 int nCols;
00150 int xOffs, yOffs;
00151 int xCellOffs, yCellOffs;
00152 short xCellDelta, yCellDelta;
00153 short cellH, cellW;
00154
00155 uint eraseInPaint : 1;
00156 uint verSliding : 1;
00157 uint verSnappingOff : 1;
00158 uint horSliding : 1;
00159 uint horSnappingOff : 1;
00160 uint coveringCornerSquare : 1;
00161 uint sbDirty : 8;
00162 uint inSbUpdate : 1;
00163
00164 uint tFlags;
00165 QRect cellUpdateR;
00166
00167 QScrollBar *vScrollBar;
00168 QScrollBar *hScrollBar;
00169 QCornerSquare *cornerSquare;
00170
00171 private:
00172 #if defined(Q_DISABLE_COPY)
00173 QtTableView( const QtTableView & );
00174 QtTableView &operator=( const QtTableView & );
00175 #endif
00176 };
00177
00178
00179 const uint Tbl_vScrollBar = 0x00000001;
00180 const uint Tbl_hScrollBar = 0x00000002;
00181 const uint Tbl_autoVScrollBar = 0x00000004;
00182 const uint Tbl_autoHScrollBar = 0x00000008;
00183 const uint Tbl_autoScrollBars = 0x0000000C;
00184
00185 const uint Tbl_clipCellPainting = 0x00000100;
00186 const uint Tbl_cutCellsV = 0x00000200;
00187 const uint Tbl_cutCellsH = 0x00000400;
00188 const uint Tbl_cutCells = 0x00000600;
00189
00190 const uint Tbl_scrollLastHCell = 0x00000800;
00191 const uint Tbl_scrollLastVCell = 0x00001000;
00192 const uint Tbl_scrollLastCell = 0x00001800;
00193
00194 const uint Tbl_smoothHScrolling = 0x00002000;
00195 const uint Tbl_smoothVScrolling = 0x00004000;
00196 const uint Tbl_smoothScrolling = 0x00006000;
00197
00198 const uint Tbl_snapToHGrid = 0x00008000;
00199 const uint Tbl_snapToVGrid = 0x00010000;
00200 const uint Tbl_snapToGrid = 0x00018000;
00201
00202
00203 inline int QtTableView::numRows() const
00204 { return nRows; }
00205
00206 inline int QtTableView::numCols() const
00207 { return nCols; }
00208
00209 inline int QtTableView::topCell() const
00210 { return yCellOffs; }
00211
00212 inline int QtTableView::leftCell() const
00213 { return xCellOffs; }
00214
00215 inline int QtTableView::xOffset() const
00216 { return xOffs; }
00217
00218 inline int QtTableView::yOffset() const
00219 { return yOffs; }
00220
00221 inline int QtTableView::cellHeight() const
00222 { return cellH; }
00223
00224 inline int QtTableView::cellWidth() const
00225 { return cellW; }
00226
00227 inline uint QtTableView::tableFlags() const
00228 { return tFlags; }
00229
00230 inline bool QtTableView::testTableFlags( uint f ) const
00231 { return (tFlags & f) != 0; }
00232
00233 inline QRect QtTableView::cellUpdateRect() const
00234 { return cellUpdateR; }
00235
00236 inline bool QtTableView::autoUpdate() const
00237 { return isUpdatesEnabled(); }
00238
00239 inline void QtTableView::repaint( bool erase )
00240 { repaint( 0, 0, width(), height(), erase ); }
00241
00242 inline void QtTableView::repaint( const QRect &r, bool erase )
00243 { repaint( r.x(), r.y(), r.width(), r.height(), erase ); }
00244
00245 inline void QtTableView::updateScrollBars()
00246 { updateScrollBars( 0 ); }
00247
00248
00249 #endif // QT_NO_QTTABLEVIEW
00250
00251 #endif // QTTABLEVIEW_H