more cleanup: some formatting and handle mouse events in their event handlers (and not in event())

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@14072 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Edwin Leuven 2006-06-11 14:28:10 +00:00
parent 7c00f14cc1
commit 73a4be7143
2 changed files with 15 additions and 38 deletions

View File

@ -16,7 +16,6 @@
#include "FuncStatus.h" #include "FuncStatus.h"
#include "funcrequest.h" #include "funcrequest.h"
#include "LyXView.h" #include "LyXView.h"
#include "debug.h"
#include "qt_helpers.h" #include "qt_helpers.h"
@ -25,7 +24,6 @@
#include <QString> #include <QString>
#include <QToolTip> #include <QToolTip>
#include <QPainter> #include <QPainter>
#include <QCoreApplication>
namespace lyx { namespace lyx {
@ -75,13 +73,17 @@ void InsertTableWidget::mouseMoveEvent(QMouseEvent * event)
// do this ourselves because when the mouse leaves the app // do this ourselves because when the mouse leaves the app
// we get an enter event (ie underMouse() is true)!! // we get an enter event (ie underMouse() is true)!!
underMouse_ = geometry().contains(event->globalPos()); underMouse_ = geometry().contains(event->globalPos());
if (!underMouse_) if (!underMouse_) {
bottom_ = 0;
right_ = 0;
update();
return; return;
}
int const r0 = right_; int const r0 = right_;
int const b0 = bottom_; int const b0 = bottom_;
right_ = event->x()/colwidth_ + 1; right_ = event->x() / colwidth_ + 1;
bottom_ = event->y()/rowheight_ + 1; bottom_ = event->y() / rowheight_ + 1;
if (bottom_ == rows_) { if (bottom_ == rows_) {
++rows_; ++rows_;
@ -95,41 +97,12 @@ void InsertTableWidget::mouseMoveEvent(QMouseEvent * event)
if (bottom_ != b0 || right_ != r0) { if (bottom_ != b0 || right_ != r0) {
update(); update();
QString status = QString("%1x%2").arg(bottom_).arg(right_); QString const status = QString("%1x%2").arg(bottom_).arg(right_);
QToolTip::showText(event->globalPos(), status , this); QToolTip::showText(event->globalPos(), status , this);
} }
} }
bool InsertTableWidget::event(QEvent * event)
{
switch (event->type()) {
case QEvent::MouseMove: {
QMouseEvent * me = dynamic_cast<QMouseEvent *>(event);
mouseMoveEvent(me);
return true;
}
case QEvent::MouseButtonRelease: {
QMouseEvent * me = dynamic_cast<QMouseEvent *>(event);
mouseReleaseEvent(me);
return true;
}
case QEvent::MouseButtonPress: {
// swallow this one...
return true;
}
case QEvent::Leave: {
bottom_ = 0;
right_ = 0;
update();
return true;
}
default:
return QWidget::event(event);
}
}
void InsertTableWidget::mouseReleaseEvent(QMouseEvent * event) void InsertTableWidget::mouseReleaseEvent(QMouseEvent * event)
{ {
if (underMouse_) { if (underMouse_) {
@ -141,6 +114,12 @@ void InsertTableWidget::mouseReleaseEvent(QMouseEvent * event)
} }
void InsertTableWidget::mousePressEvent(QMouseEvent * event)
{
// swallow this one
}
void InsertTableWidget::paintEvent(QPaintEvent * event) void InsertTableWidget::paintEvent(QPaintEvent * event)
{ {
drawGrid(rows_, cols_, Qt::white); drawGrid(rows_, cols_, Qt::white);

View File

@ -16,8 +16,6 @@
#include "frontends/LyXView.h" #include "frontends/LyXView.h"
#include <QWidget> #include <QWidget>
class QSize;
namespace lyx { namespace lyx {
namespace frontend { namespace frontend {
@ -39,9 +37,9 @@ public slots:
void updateParent(); void updateParent();
protected slots: protected slots:
bool event(QEvent *);
void mouseMoveEvent(QMouseEvent *); void mouseMoveEvent(QMouseEvent *);
void mouseReleaseEvent(QMouseEvent *); void mouseReleaseEvent(QMouseEvent *);
void mousePressEvent(QMouseEvent *);
void paintEvent(QPaintEvent *); void paintEvent(QPaintEvent *);
private: private: