]> git.lyx.org Git - lyx.git/commitdiff
Fix usability of EmptyTable widget.
authorJuergen Spitzmueller <spitz@lyx.org>
Fri, 1 May 2015 16:10:36 +0000 (18:10 +0200)
committerJuergen Spitzmueller <spitz@lyx.org>
Fri, 1 May 2015 16:10:36 +0000 (18:10 +0200)
Fixes #3919 (math matrix dialog UX issues).

src/frontends/qt4/EmptyTable.cpp
src/frontends/qt4/EmptyTable.h
src/frontends/qt4/ui/MathMatrixUi.ui

index d95d7a2443204243b11662427309e2fd5263b604..647b56381052e90e9a9c71f9fcee5b0c1bca6ff2 100644 (file)
@@ -12,6 +12,8 @@
 
 #include "EmptyTable.h"
 
 
 #include "EmptyTable.h"
 
+#include "support/debug.h"
+
 #include <QPainter>
 #include <QMouseEvent>
 
 #include <QPainter>
 #include <QMouseEvent>
 
@@ -19,7 +21,8 @@
  * A simple widget for a quick "preview" in TabularCreateDialog
  */
 
  * A simple widget for a quick "preview" in TabularCreateDialog
  */
 
-unsigned int const cellsize = 20;
+unsigned int const cellheight = 20;
+unsigned int const cellwidth = 30;
 
 
 EmptyTable::EmptyTable(QWidget * parent, int rows, int columns)
 
 
 EmptyTable::EmptyTable(QWidget * parent, int rows, int columns)
@@ -28,21 +31,23 @@ EmptyTable::EmptyTable(QWidget * parent, int rows, int columns)
        resetCellSize();
        setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
        setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
        resetCellSize();
        setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
        setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
-       viewport()->resize(cellsize*rows,cellsize*columns);
+       viewport()->resize(cellheight * rows, cellwidth * columns);
+       setSelectionMode(QAbstractItemView::NoSelection);
+       setEditTriggers(QAbstractItemView::NoEditTriggers);
 }
 
 
 QSize EmptyTable::sizeHint() const
 {
 }
 
 
 QSize EmptyTable::sizeHint() const
 {
-       return QSize(cellsize * (2+columnCount()), cellsize * (2+rowCount()));
+       return QSize(cellwidth * (2 + columnCount()), cellheight * (2 + rowCount()));
 }
 
 void EmptyTable::resetCellSize()
 {
 }
 
 void EmptyTable::resetCellSize()
 {
-       for(int i=0; i<rowCount(); ++i)
-               setRowHeight(i, cellsize);
-       for(int i=0; i<columnCount(); ++i)
-               setColumnWidth(i, cellsize);
+       for(int i = 0; i < rowCount(); ++i)
+               setRowHeight(i, cellheight);
+       for(int i = 0; i < columnCount(); ++i)
+               setColumnWidth(i, cellwidth);
 }
 
 void EmptyTable::paintCell(QPainter * p, int row, int col)
 }
 
 void EmptyTable::paintCell(QPainter * p, int row, int col)
@@ -58,12 +63,12 @@ void EmptyTable::paintCell(QPainter * p, int row, int col)
                return;
 
        // draw handle
                return;
 
        // draw handle
-       int const step = cellsize / 5;
+       int const step = cellheight / 5;
        int const space = 4;
        int const space = 4;
-       int x = cellsize - step;
-       int const y = cellsize - space;
-       int const ex = cellsize - space;
-       int ey = cellsize - step;
+       int x = cellwidth - step;
+       int const y = cellheight - space;
+       int const ex = cellwidth - space;
+       int ey = cellheight - step;
        while (x > space) {
                p->drawLine(x, y, ex, ey);
                x -= step;
        while (x > space) {
                p->drawLine(x, y, ex, ey);
                x -= step;
@@ -99,19 +104,26 @@ void EmptyTable::setNumberRows(int nr_rows)
        rowsChanged(nr_rows);
 }
 
        rowsChanged(nr_rows);
 }
 
-/*
+
 void EmptyTable::mouseMoveEvent(QMouseEvent *ev)
 {
 void EmptyTable::mouseMoveEvent(QMouseEvent *ev)
 {
-       int const x = ev->pos().x();
-       int const y = ev->pos().y();
-
-       if (x > 0)
-               setNumberColumns(x / cellsize + columnCount()-1);
-
-       if (y > 0)
-               setNumberRows(y / cellsize + rowCount()-1);
+       int cc = columnCount();
+       int rc = rowCount();
+       int x = ev->x();
+       int y = ev->y();
+       int w = cellwidth * cc;
+       int h = cellheight * rc;
+       int wl = cellwidth * (cc - 1);
+       int hl = cellheight * (rc - 1);
+       if (x > w)
+               setNumberColumns(cc + 1);
+       if (y > h)
+               setNumberRows(rc + 1);
+       if (x < wl)
+               setNumberColumns(cc - 1);
+       if (y < hl)
+               setNumberRows(rc - 1);
 }
 }
-*/
 
 #include "moc_EmptyTable.cpp"
 
 
 #include "moc_EmptyTable.cpp"
 
index d9ffa030377c1ef2ec9200987286cf0857884d72..6fb07e0d9e185e0ee36da504c61d333b254add0d 100644 (file)
@@ -42,7 +42,7 @@ Q_SIGNALS:
 protected:
        /// fill in a cell
        virtual void paintCell(class QPainter *, int, int);
 protected:
        /// fill in a cell
        virtual void paintCell(class QPainter *, int, int);
-//     virtual void mouseMoveEvent(QMouseEvent *);
+       virtual void mouseMoveEvent(QMouseEvent *);
 
        /// Reset all the cell size to default
        virtual void resetCellSize();
 
        /// Reset all the cell size to default
        virtual void resetCellSize();
index 9666160f508a51cdeae1b1796e7a02f59b006db0..b96a792f853293ec4ba8aeeac49992f1ac1f9918 100644 (file)
@@ -6,7 +6,7 @@
    <rect>
     <x>0</x>
     <y>0</y>
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>340</width>
+    <width>398</width>
     <height>372</height>
    </rect>
   </property>
     <height>372</height>
    </rect>
   </property>
@@ -17,7 +17,7 @@
    <bool>true</bool>
   </property>
   <layout class="QGridLayout" name="gridLayout">
    <bool>true</bool>
   </property>
   <layout class="QGridLayout" name="gridLayout">
-   <item row="0" column="0" colspan="2">
+   <item row="0" column="0" colspan="3">
     <layout class="QHBoxLayout">
      <property name="spacing">
       <number>6</number>
     <layout class="QHBoxLayout">
      <property name="spacing">
       <number>6</number>
      </item>
     </layout>
    </item>
      </item>
     </layout>
    </item>
-   <item row="1" column="0">
+   <item row="1" column="0" colspan="2">
     <widget class="EmptyTable" name="table" native="true">
      <property name="sizePolicy">
     <widget class="EmptyTable" name="table" native="true">
      <property name="sizePolicy">
-      <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
+      <sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
        <horstretch>0</horstretch>
        <verstretch>0</verstretch>
       </sizepolicy>
        <horstretch>0</horstretch>
        <verstretch>0</verstretch>
       </sizepolicy>
      </property>
     </widget>
    </item>
      </property>
     </widget>
    </item>
-   <item row="1" column="1">
+   <item row="1" column="2">
     <spacer>
      <property name="orientation">
       <enum>Qt::Horizontal</enum>
     <spacer>
      <property name="orientation">
       <enum>Qt::Horizontal</enum>
      </property>
     </spacer>
    </item>
      </property>
     </spacer>
    </item>
-   <item row="3" column="0" colspan="2">
+   <item row="3" column="0">
     <widget class="QGroupBox" name="alignmentGB">
      <property name="title">
       <string>Alignment</string>
     <widget class="QGroupBox" name="alignmentGB">
      <property name="title">
       <string>Alignment</string>
      </layout>
     </widget>
    </item>
      </layout>
     </widget>
    </item>
-   <item row="3" column="2">
+   <item row="3" column="1" colspan="2">
     <widget class="QGroupBox" name="decorationtGB">
      <property name="title">
       <string>Decoration</string>
     <widget class="QGroupBox" name="decorationtGB">
      <property name="title">
       <string>Decoration</string>
      </layout>
     </widget>
    </item>
      </layout>
     </widget>
    </item>
-   <item row="4" column="0" colspan="2">
+   <item row="4" column="0">
     <layout class="QHBoxLayout">
      <property name="spacing">
       <number>6</number>
     <layout class="QHBoxLayout">
      <property name="spacing">
       <number>6</number>