]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt2/emptytable.C
Some string(widget->text()) fixes. Weirdness
[lyx.git] / src / frontends / qt2 / emptytable.C
index 53ef5225b89d5cd07ddfd764e0bfc9df325a1118..4f99a215e813ad5473becdd0353a6e3623930650 100644 (file)
@@ -1,17 +1,18 @@
-/*
- * emptytable.C
- * (C) 2000 LyX Team
- * John Levon, moz@compsoc.man.ac.uk
+/**
+ * \file emptytable.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS
  */
 
-/***************************************************************************
- *                                                                         *
- *   This program is free software; you can redistribute it and/or modify  *
- *   it under the terms of the GNU General Public License as published by  *
- *   the Free Software Foundation; either version 2 of the License, or     *
- *   (at your option) any later version.                                   *
- *                                                                         *
- ***************************************************************************/
+#include <config.h>
+
+#ifdef __GNUG__
+#pragma implementation
+#endif
 
 #include "emptytable.h"
 
  * A simple widget for a quick "preview" in TabularCreateDialog
  */
 
-const unsigned int cellsize = 20;
+unsigned int const cellsize = 20;
+
 
 EmptyTable::EmptyTable(QWidget * parent, const char * name)
-       : QTableView(parent,name)
+       : QtTableView(parent, name, WRepaintNoErase)
 {
        setNumCols(5);
        setNumRows(5);
@@ -31,16 +33,40 @@ EmptyTable::EmptyTable(QWidget * parent, const char * name)
        setTableFlags(Tbl_autoScrollBars);
 }
 
-void EmptyTable::paintCell(QPainter *p, int row, int col)
+
+QSize EmptyTable::sizeHint() const
+{
+       return QSize(cellsize * numCols(), cellsize * numRows());
+}
+
+
+void EmptyTable::paintCell(QPainter * p, int row, int col)
 {
-       int x2 = cellWidth(col) - 1;
-       int y2 = cellHeight(row) - 1;
+       int const x2 = cellWidth(col) - 1;
+       int const y2 = cellHeight(row) - 1;
 
        p->fillRect(0, 0, x2, y2, QColor("white"));
        p->drawLine(x2, 0, x2, y2);
        p->drawLine(0, y2, x2, y2);
+
+       if (row + 1 != numRows() || col + 1 != numCols())
+               return;
+
+       // draw handle
+       int const step = cellsize / 5;
+       int const space = 4;
+       int x = cellsize - step;
+       int const y = cellsize - space;
+       int const ex = cellsize - space;
+       int ey = cellsize - step;
+       while (x > space) {
+               p->drawLine(x, y, ex, ey);
+               x -= step;
+               ey -= step;
+       }
 }
 
+
 void EmptyTable::setNumberColumns(int nr_cols)
 {
        if (nr_cols < 1)
@@ -49,11 +75,13 @@ void EmptyTable::setNumberColumns(int nr_cols)
                return;
        setAutoUpdate(false);
        setNumCols(nr_cols);
+       updateGeometry();
        setAutoUpdate(true);
        update();
        emit colsChanged(nr_cols);
 }
 
+
 void EmptyTable::setNumberRows(int nr_rows)
 {
        if (nr_rows < 1)
@@ -62,19 +90,21 @@ void EmptyTable::setNumberRows(int nr_rows)
                return;
        setAutoUpdate(false);
        setNumRows(nr_rows);
+       updateGeometry();
        setAutoUpdate(true);
        update();
        emit rowsChanged(nr_rows);
 }
 
+
 void EmptyTable::mouseMoveEvent(QMouseEvent *ev)
 {
-       int x = ev->pos().x();
-       int y = ev->pos().y();
+       int const x = ev->pos().x();
+       int const y = ev->pos().y();
 
-       if (x > 0) 
+       if (x > 0)
                setNumberColumns(x / cellsize + leftCell());
 
-       if (y > 0) 
+       if (y > 0)
                setNumberRows(y / cellsize + topCell());
 }