NHDT->ANH, nethack->anethack, nhdat->anhdat
[aNetHack.git] / include / qttableview.h
blobdab31857362d876270f050a63aaedad282b16c11
1 /**********************************************************************
2 ** $ANH-Branch$:$ANH-Revision$ $ANH-Date$
3 ** $Id: qttableview.h,v 1.2 2002/03/09 03:13:13 jwalz Exp $
4 **
5 ** Definition of QtTableView class
6 **
7 ** Created : 941115
8 **
9 ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
11 ** This file contains a class moved out of the Qt GUI Toolkit API. It
12 ** may be used, distributed and modified without limitation.
14 **********************************************************************/
16 #ifndef QTTABLEVIEW_H
17 #define QTTABLEVIEW_H
19 #ifndef QT_H
20 #include <qframe.h>
21 #endif // QT_H
23 #ifndef QT_NO_QTTABLEVIEW
25 class QScrollBar;
26 class QCornerSquare;
28 class QtTableView : public QFrame
30 Q_OBJECT
31 public:
32 virtual void setBackgroundColor(const QColor &);
33 virtual void setPalette(const QPalette &);
34 void show();
36 void repaint(bool erase = TRUE);
37 void repaint(int x, int y, int w, int h, bool erase = TRUE);
38 void repaint(const QRect &, bool erase = TRUE);
40 protected:
41 QtTableView(QWidget *parent = 0, const char *name = 0, WFlags f = 0);
42 ~QtTableView();
44 int numRows() const;
45 virtual void setNumRows(int);
46 int numCols() const;
47 virtual void setNumCols(int);
49 int topCell() const;
50 virtual void setTopCell(int row);
51 int leftCell() const;
52 virtual void setLeftCell(int col);
53 virtual void setTopLeftCell(int row, int col);
55 int xOffset() const;
56 virtual void setXOffset(int);
57 int yOffset() const;
58 virtual void setYOffset(int);
59 virtual void setOffset(int x, int y, bool updateScrBars = TRUE);
61 virtual int cellWidth(int col);
62 virtual int cellHeight(int row);
63 int cellWidth() const;
64 int cellHeight() const;
65 virtual void setCellWidth(int);
66 virtual void setCellHeight(int);
68 virtual int totalWidth();
69 virtual int totalHeight();
71 uint tableFlags() const;
72 bool testTableFlags(uint f) const;
73 virtual void setTableFlags(uint f);
74 void clearTableFlags(uint f = ~0);
76 bool autoUpdate() const;
77 virtual void setAutoUpdate(bool);
79 void updateCell(int row, int column, bool erase = TRUE);
81 QRect cellUpdateRect() const;
82 QRect viewRect() const;
84 int lastRowVisible() const;
85 int lastColVisible() const;
87 bool rowIsVisible(int row) const;
88 bool colIsVisible(int col) const;
90 QScrollBar *verticalScrollBar() const;
91 QScrollBar *horizontalScrollBar() const;
93 private slots:
94 void horSbValue(int);
95 void horSbSliding(int);
96 void horSbSlidingDone();
97 void verSbValue(int);
98 void verSbSliding(int);
99 void verSbSlidingDone();
101 protected:
102 virtual void paintCell(QPainter *, int row, int col) = 0;
103 virtual void setupPainter(QPainter *);
105 void paintEvent(QPaintEvent *);
106 void resizeEvent(QResizeEvent *);
108 int findRow(int yPos) const;
109 int findCol(int xPos) const;
111 bool rowYPos(int row, int *yPos) const;
112 bool colXPos(int col, int *xPos) const;
114 int maxXOffset();
115 int maxYOffset();
116 int maxColOffset();
117 int maxRowOffset();
119 int minViewX() const;
120 int minViewY() const;
121 int maxViewX() const;
122 int maxViewY() const;
123 int viewWidth() const;
124 int viewHeight() const;
126 void scroll(int xPixels, int yPixels);
127 void updateScrollBars();
128 void updateTableSize();
130 private:
131 void coverCornerSquare(bool);
132 void snapToGrid(bool horizontal, bool vertical);
133 virtual void setHorScrollBar(bool on, bool update = TRUE);
134 virtual void setVerScrollBar(bool on, bool update = TRUE);
135 void updateView();
136 int findRawRow(int yPos, int *cellMaxY, int *cellMinY = 0,
137 bool goOutsideView = FALSE) const;
138 int findRawCol(int xPos, int *cellMaxX, int *cellMinX = 0,
139 bool goOutsideView = FALSE) const;
140 int maxColsVisible() const;
142 void updateScrollBars(uint);
143 void updateFrameSize();
145 void doAutoScrollBars();
146 void showOrHideScrollBars();
148 int nRows;
149 int nCols;
150 int xOffs, yOffs;
151 int xCellOffs, yCellOffs;
152 short xCellDelta, yCellDelta;
153 short cellH, cellW;
155 uint eraseInPaint : 1;
156 uint verSliding : 1;
157 uint verSnappingOff : 1;
158 uint horSliding : 1;
159 uint horSnappingOff : 1;
160 uint coveringCornerSquare : 1;
161 uint sbDirty : 8;
162 uint inSbUpdate : 1;
164 uint tFlags;
165 QRect cellUpdateR;
167 QScrollBar *vScrollBar;
168 QScrollBar *hScrollBar;
169 QCornerSquare *cornerSquare;
171 private: // Disabled copy constructor and operator=
172 #if defined(Q_DISABLE_COPY)
173 QtTableView(const QtTableView &);
174 QtTableView &operator=(const QtTableView &);
175 #endif
178 const uint Tbl_vScrollBar = 0x00000001;
179 const uint Tbl_hScrollBar = 0x00000002;
180 const uint Tbl_autoVScrollBar = 0x00000004;
181 const uint Tbl_autoHScrollBar = 0x00000008;
182 const uint Tbl_autoScrollBars = 0x0000000C;
184 const uint Tbl_clipCellPainting = 0x00000100;
185 const uint Tbl_cutCellsV = 0x00000200;
186 const uint Tbl_cutCellsH = 0x00000400;
187 const uint Tbl_cutCells = 0x00000600;
189 const uint Tbl_scrollLastHCell = 0x00000800;
190 const uint Tbl_scrollLastVCell = 0x00001000;
191 const uint Tbl_scrollLastCell = 0x00001800;
193 const uint Tbl_smoothHScrolling = 0x00002000;
194 const uint Tbl_smoothVScrolling = 0x00004000;
195 const uint Tbl_smoothScrolling = 0x00006000;
197 const uint Tbl_snapToHGrid = 0x00008000;
198 const uint Tbl_snapToVGrid = 0x00010000;
199 const uint Tbl_snapToGrid = 0x00018000;
201 inline int
202 QtTableView::numRows() const
204 return nRows;
207 inline int
208 QtTableView::numCols() const
210 return nCols;
213 inline int
214 QtTableView::topCell() const
216 return yCellOffs;
219 inline int
220 QtTableView::leftCell() const
222 return xCellOffs;
225 inline int
226 QtTableView::xOffset() const
228 return xOffs;
231 inline int
232 QtTableView::yOffset() const
234 return yOffs;
237 inline int
238 QtTableView::cellHeight() const
240 return cellH;
243 inline int
244 QtTableView::cellWidth() const
246 return cellW;
249 inline uint
250 QtTableView::tableFlags() const
252 return tFlags;
255 inline bool
256 QtTableView::testTableFlags(uint f) const
258 return (tFlags & f) != 0;
261 inline QRect
262 QtTableView::cellUpdateRect() const
264 return cellUpdateR;
267 inline bool
268 QtTableView::autoUpdate() const
270 return isUpdatesEnabled();
273 inline void
274 QtTableView::repaint(bool erase)
276 repaint(0, 0, width(), height(), erase);
279 inline void
280 QtTableView::repaint(const QRect &r, bool erase)
282 repaint(r.x(), r.y(), r.width(), r.height(), erase);
285 inline void
286 QtTableView::updateScrollBars()
288 updateScrollBars(0);
291 #endif // QT_NO_QTTABLEVIEW
293 #endif // QTTABLEVIEW_H