mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 13:18:28 +00:00
Fix usability of EmptyTable widget.
Fixes #3919 (math matrix dialog UX issues).
This commit is contained in:
parent
bc47054be8
commit
17a4acf857
@ -12,6 +12,8 @@
|
|||||||
|
|
||||||
#include "EmptyTable.h"
|
#include "EmptyTable.h"
|
||||||
|
|
||||||
|
#include "support/debug.h"
|
||||||
|
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QMouseEvent>
|
#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();
|
resetCellSize();
|
||||||
setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
||||||
setVerticalScrollBarPolicy(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)
|
for(int i = 0; i < rowCount(); ++i)
|
||||||
setRowHeight(i, cellsize);
|
setRowHeight(i, cellheight);
|
||||||
for(int i=0; i<columnCount(); ++i)
|
for(int i = 0; i < columnCount(); ++i)
|
||||||
setColumnWidth(i, cellsize);
|
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;
|
return;
|
||||||
|
|
||||||
// draw handle
|
// 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 x = cellwidth - step;
|
||||||
int const y = cellsize - space;
|
int const y = cellheight - space;
|
||||||
int const ex = cellsize - space;
|
int const ex = cellwidth - space;
|
||||||
int ey = cellsize - step;
|
int ey = cellheight - step;
|
||||||
while (x > space) {
|
while (x > space) {
|
||||||
p->drawLine(x, y, ex, ey);
|
p->drawLine(x, y, ex, ey);
|
||||||
x -= step;
|
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 cc = columnCount();
|
||||||
int const y = ev->pos().y();
|
int rc = rowCount();
|
||||||
|
int x = ev->x();
|
||||||
if (x > 0)
|
int y = ev->y();
|
||||||
setNumberColumns(x / cellsize + columnCount()-1);
|
int w = cellwidth * cc;
|
||||||
|
int h = cellheight * rc;
|
||||||
if (y > 0)
|
int wl = cellwidth * (cc - 1);
|
||||||
setNumberRows(y / cellsize + rowCount()-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"
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ Q_SIGNALS:
|
|||||||
protected:
|
protected:
|
||||||
/// fill in a cell
|
/// fill in a cell
|
||||||
virtual void paintCell(class QPainter *, int, int);
|
virtual void paintCell(class QPainter *, int, int);
|
||||||
// virtual void mouseMoveEvent(QMouseEvent *);
|
virtual void mouseMoveEvent(QMouseEvent *);
|
||||||
|
|
||||||
/// Reset all the cell size to default
|
/// Reset all the cell size to default
|
||||||
virtual void resetCellSize();
|
virtual void resetCellSize();
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>340</width>
|
<width>398</width>
|
||||||
<height>372</height>
|
<height>372</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
@ -17,7 +17,7 @@
|
|||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
<item row="0" column="0" colspan="2">
|
<item row="0" column="0" colspan="3">
|
||||||
<layout class="QHBoxLayout">
|
<layout class="QHBoxLayout">
|
||||||
<property name="spacing">
|
<property name="spacing">
|
||||||
<number>6</number>
|
<number>6</number>
|
||||||
@ -101,10 +101,10 @@
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="0">
|
<item row="1" column="0" colspan="2">
|
||||||
<widget class="EmptyTable" name="table" native="true">
|
<widget class="EmptyTable" name="table" native="true">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
<verstretch>0</verstretch>
|
<verstretch>0</verstretch>
|
||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
@ -114,7 +114,7 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="1">
|
<item row="1" column="2">
|
||||||
<spacer>
|
<spacer>
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
@ -146,7 +146,7 @@
|
|||||||
</property>
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
<item row="3" column="0" colspan="2">
|
<item row="3" column="0">
|
||||||
<widget class="QGroupBox" name="alignmentGB">
|
<widget class="QGroupBox" name="alignmentGB">
|
||||||
<property name="title">
|
<property name="title">
|
||||||
<string>Alignment</string>
|
<string>Alignment</string>
|
||||||
@ -204,7 +204,7 @@
|
|||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="3" column="2">
|
<item row="3" column="1" colspan="2">
|
||||||
<widget class="QGroupBox" name="decorationtGB">
|
<widget class="QGroupBox" name="decorationtGB">
|
||||||
<property name="title">
|
<property name="title">
|
||||||
<string>Decoration</string>
|
<string>Decoration</string>
|
||||||
@ -233,7 +233,7 @@
|
|||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="4" column="0" colspan="2">
|
<item row="4" column="0">
|
||||||
<layout class="QHBoxLayout">
|
<layout class="QHBoxLayout">
|
||||||
<property name="spacing">
|
<property name="spacing">
|
||||||
<number>6</number>
|
<number>6</number>
|
||||||
|
Loading…
Reference in New Issue
Block a user