]> git.lyx.org Git - lyx.git/blob - src/frontends/kde/dlg/emptytable.C
formskdepatchthingie
[lyx.git] / src / frontends / kde / dlg / 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         setBackgroundMode(NoBackground);
28         setNumCols(5);
29         setNumRows(5);
30         setCellWidth(cellsize);
31         setCellHeight(cellsize);
32         setTableFlags(Tbl_autoScrollBars);
33 }
34
35 void EmptyTable::paintCell(QPainter *p, int row, int col)
36 {
37         int x2 = cellWidth(col) - 1;
38         int y2 = cellHeight(row) - 1;
39
40         p->fillRect(0, 0, x2, y2, QColor("white"));
41         p->drawLine(x2, 0, x2, y2);
42         p->drawLine(0, y2, x2, y2);
43 }
44
45 void EmptyTable::setNumberColumns(int nr_cols)
46 {
47         if (nr_cols < 1)
48                 return;
49         if (nr_cols == numCols())
50                 return;
51         setAutoUpdate(false);
52         setNumCols(nr_cols);
53         setAutoUpdate(true);
54         update();
55         emit colsChanged(nr_cols);
56 }
57
58 void EmptyTable::setNumberRows(int nr_rows)
59 {
60         if (nr_rows < 1)
61                 return;
62         if (nr_rows == numRows())
63                 return;
64         setAutoUpdate(false);
65         setNumRows(nr_rows);
66         setAutoUpdate(true);
67         update();
68         emit rowsChanged(nr_rows);
69 }
70
71 void EmptyTable::mouseMoveEvent(QMouseEvent *ev)
72 {
73         int x = ev->pos().x();
74         int y = ev->pos().y();
75
76         if (x > 0)
77                 setNumberColumns(x / cellsize + leftCell());
78
79         if (y > 0)
80                 setNumberRows(y / cellsize + topCell());
81 }