X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fqt%2FInsertTableWidget.cpp;h=07ae06124f4dd3bd0b16a8880b06d66251e20559;hb=b41293352ea8d52890b7668f059fd07f09bd6bb6;hp=773151f00d57e606e3b88bd3e452588ad666449b;hpb=c293be56bd12c5dc46e5cedd2828e33918fccef7;p=features.git diff --git a/src/frontends/qt/InsertTableWidget.cpp b/src/frontends/qt/InsertTableWidget.cpp index 773151f00d..07ae06124f 100644 --- a/src/frontends/qt/InsertTableWidget.cpp +++ b/src/frontends/qt/InsertTableWidget.cpp @@ -33,7 +33,7 @@ namespace lyx { namespace frontend { InsertTableWidget::InsertTableWidget(QWidget * parent) - : QWidget(parent, Qt::Popup), colwidth_(20), rowheight_(12) + : QWidget(parent, Qt::Popup), colwidth_(15), rowheight_(15), minrows_(5), mincols_(5) { init(); setMouseTracking(true); @@ -42,8 +42,8 @@ InsertTableWidget::InsertTableWidget(QWidget * parent) void InsertTableWidget::init() { - rows_ = 5; - cols_ = 5; + rows_ = minrows_; + cols_ = mincols_; bottom_ = 0; right_ = 0; underMouse_ = false; @@ -76,7 +76,11 @@ void InsertTableWidget::mouseMoveEvent(QMouseEvent * event) { // do this ourselves because when the mouse leaves the app // we get an enter event (ie underMouse() is true)!! +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + underMouse_ = geometry().contains(event->globalPosition().toPoint()); +#else underMouse_ = geometry().contains(event->globalPos()); +#endif if (!underMouse_) { bottom_ = 0; right_ = 0; @@ -86,23 +90,34 @@ void InsertTableWidget::mouseMoveEvent(QMouseEvent * event) int const r0 = right_; int const b0 = bottom_; +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + right_ = event->position().x() / colwidth_ + 1; + bottom_ = event->position().y() / rowheight_ + 1; +#else right_ = event->x() / colwidth_ + 1; bottom_ = event->y() / rowheight_ + 1; +#endif - if (bottom_ == rows_) { - ++rows_; + int const newrows = std::max(minrows_, bottom_ + 1); + if (rows_ != newrows) { + rows_ = newrows; resetGeometry(); } - if (right_ == cols_) { - ++cols_; + int const newcols = std::max(mincols_, right_ + 1); + if (cols_ != newcols) { + cols_ = newcols; resetGeometry(); } if (bottom_ != b0 || right_ != r0) { update(); QString const status = QString("%1x%2").arg(bottom_).arg(right_); +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + QToolTip::showText(event->globalPosition().toPoint(), status , this); +#else QToolTip::showText(event->globalPos(), status , this); +#endif } } @@ -127,17 +142,20 @@ void InsertTableWidget::mousePressEvent(QMouseEvent * /*event*/) void InsertTableWidget::paintEvent(QPaintEvent * /*event*/) { - drawGrid(rows_, cols_, Qt::white); + QPalette const palette = this->palette(); + drawGrid(rows_, cols_, palette.base(), palette.text().color()); if (underMouse_) - drawGrid(bottom_, right_, Qt::darkBlue); + drawGrid(bottom_, right_, palette.highlight(), + palette.highlightedText().color()); } -void InsertTableWidget::drawGrid(int const rows, int const cols, Qt::GlobalColor const color) +void InsertTableWidget::drawGrid(int const rows, int const cols, + QBrush const fillBrush, QColor lineColor) { QPainter painter(this); - painter.setPen(Qt::darkGray); - painter.setBrush(color); + painter.setPen(lineColor); + painter.setBrush(fillBrush); for (int r = 0 ; r < rows ; ++r ) { for (int c = 0 ; c < cols ; ++c ) {