]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/emptytable.C
qt2.diff.gz
[lyx.git] / src / frontends / qt2 / emptytable.C
1 /*
2  * emptytable.C
3  * (C) 2000 LyX Team
4  * John Levon, moz@compsoc.man.ac.uk
5  */
6
7 /***************************************************************************
8  *                                                                         *
9  *   This program is free software; you can redistribute it and/or modify  *
10  *   it under the terms of the GNU General Public License as published by  *
11  *   the Free Software Foundation; either version 2 of the License, or     *
12  *   (at your option) any later version.                                   *
13  *                                                                         *
14  ***************************************************************************/
15
16 #include "emptytable.h"
17
18 /**
19  * A simple widget for a quick "preview" in TabularCreateDialog
20  */
21
22 const unsigned int cellsize = 20;
23
24 EmptyTable::EmptyTable(QWidget * parent, const char * name)
25         : QTableView(parent,name)
26 {
27         setNumCols(5);
28         setNumRows(5);
29         setCellWidth(cellsize);
30         setCellHeight(cellsize);
31         setTableFlags(Tbl_autoScrollBars);
32 }
33
34 void EmptyTable::paintCell(QPainter *p, int row, int col)
35 {
36         int x2 = cellWidth(col) - 1;
37         int y2 = cellHeight(row) - 1;
38
39         p->fillRect(0, 0, x2, y2, QColor("white"));
40         p->drawLine(x2, 0, x2, y2);
41         p->drawLine(0, y2, x2, y2);
42 }
43
44 void EmptyTable::setNumberColumns(int nr_cols)
45 {
46         if (nr_cols < 1)
47                 return;
48         if (nr_cols == numCols())
49                 return;
50         setAutoUpdate(false);
51         setNumCols(nr_cols);
52         setAutoUpdate(true);
53         update();
54         emit colsChanged(nr_cols);
55 }
56
57 void EmptyTable::setNumberRows(int nr_rows)
58 {
59         if (nr_rows < 1)
60                 return;
61         if (nr_rows == numRows())
62                 return;
63         setAutoUpdate(false);
64         setNumRows(nr_rows);
65         setAutoUpdate(true);
66         update();
67         emit rowsChanged(nr_rows);
68 }
69
70 void EmptyTable::mouseMoveEvent(QMouseEvent *ev)
71 {
72         int x = ev->pos().x();
73         int y = ev->pos().y();
74
75         if (x > 0) 
76                 setNumberColumns(x / cellsize + leftCell());
77
78         if (y > 0) 
79                 setNumberRows(y / cellsize + topCell());
80 }