mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-25 10:58:52 +00:00
Add new tableinsertwidget
+ Remove table widget from inserttable dialog git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@13972 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
7bc451a1ee
commit
5c8f40106a
@ -856,6 +856,7 @@ if build_qt4:
|
||||
floatplacement.C
|
||||
iconpalette.C
|
||||
lengthcombo.C
|
||||
InsertTableWidget.C
|
||||
panelstack.C
|
||||
QAboutDialog.C
|
||||
QBibitemDialog.C
|
||||
|
171
src/frontends/qt4/InsertTableWidget.C
Normal file
171
src/frontends/qt4/InsertTableWidget.C
Normal file
@ -0,0 +1,171 @@
|
||||
/**
|
||||
* \file InsertTableWidget.C
|
||||
*
|
||||
* This file is part of LyX, the document processor.
|
||||
* Licence details can be found in the file COPYING.
|
||||
*
|
||||
* \author Edwin Leuven
|
||||
*
|
||||
* Full author contact details are available in file CREDITS.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "BufferView.h" // needed for lyxfunc
|
||||
#include "lyxfunc.h"
|
||||
#include "FuncStatus.h"
|
||||
#include "funcrequest.h"
|
||||
#include "LyXView.h"
|
||||
#include "debug.h"
|
||||
|
||||
#include "qt_helpers.h"
|
||||
|
||||
#include "InsertTableWidget.h"
|
||||
#include <QMouseEvent>
|
||||
#include <QString>
|
||||
#include <QToolTip>
|
||||
#include <QPainter>
|
||||
#include <QCoreApplication>
|
||||
|
||||
|
||||
namespace lyx {
|
||||
namespace frontend {
|
||||
|
||||
InsertTableWidget::InsertTableWidget(LyXView & lyxView, FuncRequest const & func, QWidget * parent)
|
||||
: QWidget(parent, Qt::Popup), colwidth_(20), rowheight_(12), lyxView_(lyxView), func_(func)
|
||||
{
|
||||
init();
|
||||
setMouseTracking(true);
|
||||
}
|
||||
|
||||
|
||||
void InsertTableWidget::init()
|
||||
{
|
||||
rows_ = 5;
|
||||
cols_ = 5;
|
||||
bottom_ = 0;
|
||||
right_ = 0;
|
||||
underMouse_ = false;
|
||||
}
|
||||
|
||||
|
||||
void InsertTableWidget::show(bool show)
|
||||
{
|
||||
if (!show)
|
||||
return;
|
||||
|
||||
init();
|
||||
resetGeometry();
|
||||
setVisible(true);
|
||||
emit visible(true);
|
||||
}
|
||||
|
||||
|
||||
void InsertTableWidget::resetGeometry()
|
||||
{
|
||||
QPoint p = parentWidget()->mapToGlobal(parentWidget()->geometry().bottomLeft());
|
||||
setGeometry(p.x() - parentWidget()->pos().x(),
|
||||
p.y() - parentWidget()->pos().y(),
|
||||
cols_ * colwidth_ + 1, rows_ * rowheight_ + 1);
|
||||
}
|
||||
|
||||
|
||||
void InsertTableWidget::mouseMoveEvent(QMouseEvent * event)
|
||||
{
|
||||
// do this ourselves because when the mouse leaves the app
|
||||
// we get an enter event (ie underMouse() is true)!!
|
||||
underMouse_ = geometry().contains(event->globalPos());
|
||||
if (!underMouse_)
|
||||
return;
|
||||
|
||||
int const r0 = right_;
|
||||
int const b0 = bottom_;
|
||||
right_ = event->x()/colwidth_ + 1;
|
||||
bottom_ = event->y()/rowheight_ + 1;
|
||||
|
||||
if (bottom_ == rows_) {
|
||||
++rows_;
|
||||
resetGeometry();
|
||||
}
|
||||
|
||||
if (right_ == cols_) {
|
||||
++cols_;
|
||||
resetGeometry();
|
||||
}
|
||||
|
||||
if (bottom_ != b0 || right_ != r0)
|
||||
update();
|
||||
|
||||
QString status = QString("%1x%2").arg(bottom_).arg(right_);
|
||||
QToolTip::showText(event->globalPos(), status , this);
|
||||
}
|
||||
|
||||
|
||||
bool InsertTableWidget::event(QEvent * event)
|
||||
{
|
||||
if (event->type() == QEvent::MouseMove) {
|
||||
QMouseEvent * me = dynamic_cast<QMouseEvent *>(event);
|
||||
mouseMoveEvent(me);
|
||||
return true;
|
||||
} else if (event->type() == QEvent::MouseButtonRelease) {
|
||||
QMouseEvent * me = dynamic_cast<QMouseEvent *>(event);
|
||||
mouseReleaseEvent(me);
|
||||
return true;
|
||||
} else if (event->type() == QEvent::MouseButtonPress) {
|
||||
// swallow this one...
|
||||
return true;
|
||||
} else if (event->type() == QEvent::Leave) {
|
||||
bottom_ = 0;
|
||||
right_ = 0;
|
||||
update();
|
||||
return true;
|
||||
}
|
||||
return QWidget::event(event);
|
||||
}
|
||||
|
||||
|
||||
void InsertTableWidget::mouseReleaseEvent(QMouseEvent * event)
|
||||
{
|
||||
if (underMouse_) {
|
||||
QString const data = QString("%1 %2").arg(bottom_).arg(right_);
|
||||
lyxView_.getLyXFunc().dispatch(FuncRequest(LFUN_TABULAR_INSERT, fromqstr(data)));
|
||||
}
|
||||
emit visible(false);
|
||||
close();
|
||||
}
|
||||
|
||||
|
||||
void InsertTableWidget::paintEvent(QPaintEvent * event)
|
||||
{
|
||||
drawGrid(rows_, cols_, Qt::white);
|
||||
if (underMouse_)
|
||||
drawGrid(bottom_, right_, Qt::darkBlue);
|
||||
}
|
||||
|
||||
|
||||
void InsertTableWidget::drawGrid(int const rows, int const cols, Qt::GlobalColor const color)
|
||||
{
|
||||
QPainter painter(this);
|
||||
painter.setPen(Qt::darkGray);
|
||||
painter.setBrush(color);
|
||||
|
||||
for (int r = 0 ; r < rows ; ++r ) {
|
||||
for (int c = 0 ; c < cols ; ++c ) {
|
||||
QRect rectangle(c * colwidth_, r * rowheight_, colwidth_, rowheight_);
|
||||
painter.drawRect(rectangle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void InsertTableWidget::updateParent()
|
||||
{
|
||||
FuncStatus const status = lyxView_.getLyXFunc().getStatus(func_);
|
||||
parentWidget()->setEnabled(status.enabled());
|
||||
}
|
||||
|
||||
|
||||
} // namespace frontend
|
||||
} // namespace lyx
|
||||
|
||||
#include "InsertTableWidget_moc.cpp"
|
78
src/frontends/qt4/InsertTableWidget.h
Normal file
78
src/frontends/qt4/InsertTableWidget.h
Normal file
@ -0,0 +1,78 @@
|
||||
// -*- C++ -*-
|
||||
/**
|
||||
* \file InsertTableWidget.h
|
||||
* This file is part of LyX, the document processor.
|
||||
* Licence details can be found in the file COPYING.
|
||||
*
|
||||
* \author Edwin Leuven
|
||||
*
|
||||
* Full author contact details are available in file CREDITS.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef INSERTTABLEWIDGET_H
|
||||
#define INSERTTABLEWIDGET_H
|
||||
|
||||
#include "frontends/LyXView.h"
|
||||
#include <QWidget>
|
||||
|
||||
class QSize;
|
||||
|
||||
namespace lyx {
|
||||
namespace frontend {
|
||||
|
||||
|
||||
class InsertTableWidget : public QWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
||||
InsertTableWidget(LyXView &, FuncRequest const &, QWidget *);
|
||||
|
||||
signals:
|
||||
//! widget is visible
|
||||
void visible(bool);
|
||||
|
||||
public slots:
|
||||
//! show the widget
|
||||
void show(bool);
|
||||
//! enable/disable parent
|
||||
void updateParent();
|
||||
|
||||
protected slots:
|
||||
bool event(QEvent *);
|
||||
void mouseMoveEvent(QMouseEvent *);
|
||||
void mouseReleaseEvent(QMouseEvent *);
|
||||
void paintEvent(QPaintEvent *);
|
||||
|
||||
private:
|
||||
//! update the geometry
|
||||
void resetGeometry();
|
||||
//! initialize parameters to default values
|
||||
void init();
|
||||
//! draw the grid
|
||||
void drawGrid(int rows, int cols, Qt::GlobalColor color);
|
||||
|
||||
//! colwidth in pixels
|
||||
int colwidth_;
|
||||
//! rowheight in pixels
|
||||
int rowheight_;
|
||||
//! total rows
|
||||
int rows_;
|
||||
//! total cols
|
||||
int cols_;
|
||||
//! row of pointer
|
||||
int bottom_;
|
||||
//! column of pointer
|
||||
int right_;
|
||||
//! the tabular_insert funcrequest
|
||||
FuncRequest const & func_ ;
|
||||
//! the lyxview we need to dispatch the funcrequest
|
||||
LyXView & lyxView_;
|
||||
//! widget under mouse
|
||||
bool underMouse_;
|
||||
};
|
||||
|
||||
} // namespace frontend
|
||||
} // namespace lyx
|
||||
|
||||
#endif // INSERTTABLEWIDGET_H
|
@ -77,6 +77,7 @@ MOCFILES = \
|
||||
FileDialog_private.C FileDialog_private.h \
|
||||
floatplacement.C floatplacement.h \
|
||||
iconpalette.C iconpalette.h \
|
||||
InsertTableWidget.C InsertTableWidget.h \
|
||||
lengthcombo.C lengthcombo.h \
|
||||
panelstack.C panelstack.h \
|
||||
QAboutDialog.C QAboutDialog.h \
|
||||
|
@ -26,12 +26,12 @@
|
||||
#include "QLToolbar.h"
|
||||
#include "QLAction.h"
|
||||
#include "qt_helpers.h"
|
||||
#include "InsertTableWidget.h"
|
||||
|
||||
#include <QComboBox>
|
||||
#include <QToolBar>
|
||||
#include <QToolButton>
|
||||
#include <QAction>
|
||||
//Added by qt3to4:
|
||||
#include <QPixmap>
|
||||
|
||||
using std::endl;
|
||||
@ -235,6 +235,19 @@ void QLToolbar::add(FuncRequest const & func, string const & tooltip)
|
||||
/// \todo find a Qt4 equivalent to setHorizontalStretchable(true);
|
||||
//toolbar_->setHorizontalStretchable(true);
|
||||
break;
|
||||
case LFUN_TABULAR_INSERT: {
|
||||
QToolButton * tb = new QToolButton;
|
||||
tb->setCheckable(true);
|
||||
tb->setIcon(QPixmap(toqstr(toolbarbackend.getIcon(func))));
|
||||
tb->setToolTip(toqstr(tooltip));
|
||||
tb->setFocusPolicy(Qt::NoFocus);
|
||||
InsertTableWidget * iv = new InsertTableWidget(owner_, func, tb);
|
||||
connect(tb, SIGNAL(toggled(bool)), iv, SLOT(show(bool)));
|
||||
connect(iv, SIGNAL(visible(bool)), tb, SLOT(setChecked(bool)));
|
||||
connect(this, SIGNAL(updated()), iv, SLOT(updateParent()));
|
||||
toolbar_->addWidget(tb);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
if (owner_.getLyXFunc().getStatus(func).unknown())
|
||||
break;
|
||||
@ -242,9 +255,8 @@ void QLToolbar::add(FuncRequest const & func, string const & tooltip)
|
||||
QLAction * action = new QLAction(owner_, toolbarbackend.getIcon(func), "", func, tooltip);
|
||||
toolbar_->addAction(action);
|
||||
ActionVector.push_back(action);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -265,6 +277,8 @@ void QLToolbar::update()
|
||||
{
|
||||
for (size_t i=0; i<ActionVector.size(); ++i)
|
||||
ActionVector[i]->update();
|
||||
|
||||
emit updated();
|
||||
}
|
||||
|
||||
|
||||
|
@ -71,6 +71,9 @@ public:
|
||||
void update();
|
||||
LayoutBox * layout() const { return layout_.get(); }
|
||||
|
||||
signals:
|
||||
void updated();
|
||||
|
||||
private:
|
||||
|
||||
std::vector<QLAction *> ActionVector;
|
||||
|
@ -26,7 +26,6 @@ QTabularCreateDialog::QTabularCreateDialog(QTabularCreate * form)
|
||||
{
|
||||
setupUi(this);
|
||||
|
||||
table->setMinimumSize(100,100);
|
||||
rowsSB->setValue(5);
|
||||
columnsSB->setValue(5);
|
||||
|
||||
@ -34,13 +33,10 @@ QTabularCreateDialog::QTabularCreateDialog(QTabularCreate * form)
|
||||
form_, SLOT(slotOK()));
|
||||
connect(closePB, SIGNAL(clicked()),
|
||||
form_, SLOT(slotClose()));
|
||||
|
||||
connect( table, SIGNAL( rowsChanged(int) ), rowsSB, SLOT( setValue(int) ) );
|
||||
connect( table, SIGNAL( colsChanged(int) ), columnsSB, SLOT( setValue(int) ) );
|
||||
connect( rowsSB, SIGNAL( valueChanged(int) ), table, SLOT( setNumberRows(int) ) );
|
||||
connect( columnsSB, SIGNAL( valueChanged(int) ), table, SLOT( setNumberColumns(int) ) );
|
||||
connect( rowsSB, SIGNAL( valueChanged(int) ), this, SLOT( rowsChanged(int) ) );
|
||||
connect( columnsSB, SIGNAL( valueChanged(int) ), this, SLOT( columnsChanged(int) ) );
|
||||
connect(rowsSB, SIGNAL(valueChanged(int)),
|
||||
this, SLOT( rowsChanged(int)));
|
||||
connect(columnsSB, SIGNAL(valueChanged(int)),
|
||||
this, SLOT(columnsChanged(int)));
|
||||
}
|
||||
|
||||
|
||||
|
@ -8,8 +8,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>272</width>
|
||||
<height>243</height>
|
||||
<width>198</width>
|
||||
<height>125</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle" >
|
||||
@ -18,170 +18,27 @@
|
||||
<property name="sizeGripEnabled" >
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" >
|
||||
<layout class="QGridLayout" >
|
||||
<property name="margin" >
|
||||
<number>11</number>
|
||||
<number>9</number>
|
||||
</property>
|
||||
<property name="spacing" >
|
||||
<number>6</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" >
|
||||
<property name="margin" >
|
||||
<number>0</number>
|
||||
<item row="2" column="1" >
|
||||
<spacer>
|
||||
<property name="orientation" >
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="spacing" >
|
||||
<number>6</number>
|
||||
<property name="sizeHint" >
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="rowsL" >
|
||||
<property name="toolTip" >
|
||||
<string>Number of rows</string>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>&Rows:</string>
|
||||
</property>
|
||||
<property name="buddy" >
|
||||
<cstring>rowsSB</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="rowsSB" >
|
||||
<property name="toolTip" >
|
||||
<string>Number of rows</string>
|
||||
</property>
|
||||
<property name="buttonSymbols" >
|
||||
<enum>QAbstractSpinBox::PlusMinus</enum>
|
||||
</property>
|
||||
<property name="maximum" >
|
||||
<number>511</number>
|
||||
</property>
|
||||
<property name="minimum" >
|
||||
<number>1</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="columnsL" >
|
||||
<property name="toolTip" >
|
||||
<string>Number of columns</string>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>&Columns:</string>
|
||||
</property>
|
||||
<property name="buddy" >
|
||||
<cstring>columnsSB</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="columnsSB" >
|
||||
<property name="toolTip" >
|
||||
<string>Number of columns</string>
|
||||
</property>
|
||||
<property name="buttonSymbols" >
|
||||
<enum>QAbstractSpinBox::PlusMinus</enum>
|
||||
</property>
|
||||
<property name="maximum" >
|
||||
<number>511</number>
|
||||
</property>
|
||||
<property name="minimum" >
|
||||
<number>1</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer>
|
||||
<property name="orientation" >
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType" >
|
||||
<enum>QSizePolicy::Expanding</enum>
|
||||
</property>
|
||||
<property name="sizeHint" >
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QGridLayout" >
|
||||
<property name="margin" >
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="spacing" >
|
||||
<number>6</number>
|
||||
</property>
|
||||
<item row="0" column="1" >
|
||||
<spacer>
|
||||
<property name="orientation" >
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType" >
|
||||
<enum>QSizePolicy::MinimumExpanding</enum>
|
||||
</property>
|
||||
<property name="sizeHint" >
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="1" column="0" >
|
||||
<spacer>
|
||||
<property name="orientation" >
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeType" >
|
||||
<enum>QSizePolicy::MinimumExpanding</enum>
|
||||
</property>
|
||||
<property name="sizeHint" >
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="0" column="0" >
|
||||
<widget class="EmptyTable" name="table" >
|
||||
<property name="sizePolicy" >
|
||||
<sizepolicy>
|
||||
<hsizetype>5</hsizetype>
|
||||
<vsizetype>5</vsizetype>
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize" >
|
||||
<size>
|
||||
<width>100</width>
|
||||
<height>100</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize" >
|
||||
<size>
|
||||
<width>600</width>
|
||||
<height>600</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="focusPolicy" >
|
||||
<enum>Qt::NoFocus</enum>
|
||||
</property>
|
||||
<property name="toolTip" >
|
||||
<string>Resize this to the correct table dimensions</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<item row="3" column="0" colspan="3" >
|
||||
<layout class="QHBoxLayout" >
|
||||
<property name="margin" >
|
||||
<number>0</number>
|
||||
@ -221,22 +78,86 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="0" column="0" >
|
||||
<widget class="QLabel" name="rowsL" >
|
||||
<property name="toolTip" >
|
||||
<string>Number of rows</string>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>&Rows:</string>
|
||||
</property>
|
||||
<property name="buddy" >
|
||||
<cstring>rowsSB</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2" >
|
||||
<spacer>
|
||||
<property name="orientation" >
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType" >
|
||||
<enum>QSizePolicy::Expanding</enum>
|
||||
</property>
|
||||
<property name="sizeHint" >
|
||||
<size>
|
||||
<width>58</width>
|
||||
<height>22</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="1" column="0" >
|
||||
<widget class="QLabel" name="columnsL" >
|
||||
<property name="toolTip" >
|
||||
<string>Number of columns</string>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>&Columns:</string>
|
||||
</property>
|
||||
<property name="buddy" >
|
||||
<cstring>columnsSB</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1" >
|
||||
<widget class="QSpinBox" name="rowsSB" >
|
||||
<property name="toolTip" >
|
||||
<string>Number of rows</string>
|
||||
</property>
|
||||
<property name="buttonSymbols" >
|
||||
<enum>QAbstractSpinBox::PlusMinus</enum>
|
||||
</property>
|
||||
<property name="maximum" >
|
||||
<number>511</number>
|
||||
</property>
|
||||
<property name="minimum" >
|
||||
<number>1</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1" >
|
||||
<widget class="QSpinBox" name="columnsSB" >
|
||||
<property name="toolTip" >
|
||||
<string>Number of columns</string>
|
||||
</property>
|
||||
<property name="buttonSymbols" >
|
||||
<enum>QAbstractSpinBox::PlusMinus</enum>
|
||||
</property>
|
||||
<property name="maximum" >
|
||||
<number>511</number>
|
||||
</property>
|
||||
<property name="minimum" >
|
||||
<number>1</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<pixmapfunction></pixmapfunction>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>EmptyTable</class>
|
||||
<extends></extends>
|
||||
<header>emptytable.h</header>
|
||||
<container>0</container>
|
||||
<pixmap></pixmap>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<tabstops>
|
||||
<tabstop>rowsSB</tabstop>
|
||||
<tabstop>columnsSB</tabstop>
|
||||
<tabstop>table</tabstop>
|
||||
<tabstop>okPB</tabstop>
|
||||
<tabstop>closePB</tabstop>
|
||||
</tabstops>
|
||||
|
Loading…
Reference in New Issue
Block a user