]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/emptytable.C
Some string(widget->text()) fixes. Weirdness
[lyx.git] / src / frontends / qt2 / emptytable.C
1 /**
2  * \file emptytable.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author John Levon
7  *
8  * Full author contact details are available in file CREDITS
9  */
10
11 #include <config.h>
12
13 #ifdef __GNUG__
14 #pragma implementation
15 #endif
16
17 #include "emptytable.h"
18
19 /**
20  * A simple widget for a quick "preview" in TabularCreateDialog
21  */
22
23 unsigned int const cellsize = 20;
24
25
26 EmptyTable::EmptyTable(QWidget * parent, const char * name)
27         : QtTableView(parent, name, WRepaintNoErase)
28 {
29         setNumCols(5);
30         setNumRows(5);
31         setCellWidth(cellsize);
32         setCellHeight(cellsize);
33         setTableFlags(Tbl_autoScrollBars);
34 }
35
36
37 QSize EmptyTable::sizeHint() const
38 {
39         return QSize(cellsize * numCols(), cellsize * numRows());
40 }
41
42
43 void EmptyTable::paintCell(QPainter * p, int row, int col)
44 {
45         int const x2 = cellWidth(col) - 1;
46         int const y2 = cellHeight(row) - 1;
47
48         p->fillRect(0, 0, x2, y2, QColor("white"));
49         p->drawLine(x2, 0, x2, y2);
50         p->drawLine(0, y2, x2, y2);
51
52         if (row + 1 != numRows() || col + 1 != numCols())
53                 return;
54
55         // draw handle
56         int const step = cellsize / 5;
57         int const space = 4;
58         int x = cellsize - step;
59         int const y = cellsize - space;
60         int const ex = cellsize - space;
61         int ey = cellsize - step;
62         while (x > space) {
63                 p->drawLine(x, y, ex, ey);
64                 x -= step;
65                 ey -= step;
66         }
67 }
68
69
70 void EmptyTable::setNumberColumns(int nr_cols)
71 {
72         if (nr_cols < 1)
73                 return;
74         if (nr_cols == numCols())
75                 return;
76         setAutoUpdate(false);
77         setNumCols(nr_cols);
78         updateGeometry();
79         setAutoUpdate(true);
80         update();
81         emit colsChanged(nr_cols);
82 }
83
84
85 void EmptyTable::setNumberRows(int nr_rows)
86 {
87         if (nr_rows < 1)
88                 return;
89         if (nr_rows == numRows())
90                 return;
91         setAutoUpdate(false);
92         setNumRows(nr_rows);
93         updateGeometry();
94         setAutoUpdate(true);
95         update();
96         emit rowsChanged(nr_rows);
97 }
98
99
100 void EmptyTable::mouseMoveEvent(QMouseEvent *ev)
101 {
102         int const x = ev->pos().x();
103         int const y = ev->pos().y();
104
105         if (x > 0)
106                 setNumberColumns(x / cellsize + leftCell());
107
108         if (y > 0)
109                 setNumberRows(y / cellsize + topCell());
110 }