From c0a9d2587ced13525940ef53078d87ffc9a8fe31 Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Mon, 19 Nov 2007 10:04:14 +0000 Subject: [PATCH] Painting tweaks: - avoid one redraw on file loading due to a resize event. - fix the initial offset_ref_ value of BufferView. - add new TabWorkArea::addWorkArea() method. - avoid tab bar flashing when only one file is opened. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21674 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView.cpp | 9 +++++++-- src/frontends/qt4/GuiView.cpp | 12 +----------- src/frontends/qt4/GuiWorkArea.cpp | 24 +++++++++++++++++++----- src/frontends/qt4/GuiWorkArea.h | 5 +++-- 4 files changed, 30 insertions(+), 20 deletions(-) diff --git a/src/BufferView.cpp b/src/BufferView.cpp index 1c911517ab..4bd4a99c24 100644 --- a/src/BufferView.cpp +++ b/src/BufferView.cpp @@ -647,8 +647,13 @@ bool BufferView::moveToPosition(pit_type bottom_pit, pos_type bottom_pos, setCursor(doc_it); // set the current font. d->cursor_.setCurrentFont(); - // center the screen on this new position. - center(); + // To center the screen on this new position we need the + // paragraph position which is computed at draw() time. + // So we need a redraw! + buffer_.changed(); + if (fitCursor()) + // We need another redraw because of the screen recentering. + buffer_.changed(); } return success; diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp index 5d9a1615b1..fc781eddca 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -703,23 +703,13 @@ GuiWorkArea * GuiView::workArea(Buffer & buffer) GuiWorkArea * GuiView::addWorkArea(Buffer & buffer) { - GuiWorkArea * wa = new GuiWorkArea(buffer, *this); - wa->setUpdatesEnabled(false); // Automatically create a TabWorkArea if there are none yet. if (!d.splitter_->count()) addTabWorkArea(); TabWorkArea * tab_widget = d.currentTabWorkArea(); - tab_widget->addTab(wa, wa->windowTitle()); - QObject::connect(wa, SIGNAL(titleChanged(GuiWorkArea *)), - tab_widget, SLOT(updateTabText(GuiWorkArea *))); - - wa->bufferView().updateMetrics(); - - // Hide tabbar if there's only one tab. - tab_widget->showBar(tab_widget->count() > 1); - return wa; + return tab_widget->addWorkArea(buffer, *this); } diff --git a/src/frontends/qt4/GuiWorkArea.cpp b/src/frontends/qt4/GuiWorkArea.cpp index b2f86248f1..19998a732f 100644 --- a/src/frontends/qt4/GuiWorkArea.cpp +++ b/src/frontends/qt4/GuiWorkArea.cpp @@ -216,7 +216,7 @@ GuiWorkArea::GuiWorkArea(Buffer & buffer, GuiView & lv) cursor_ = new frontend::CursorWidget(); cursor_->hide(); - setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); + setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setAcceptDrops(true); setMouseTracking(true); @@ -398,6 +398,7 @@ void GuiWorkArea::resizeBufferView() buffer_view_->resize(viewport()->width(), viewport()->height()); lyx_view_->updateLayoutChoice(false); lyx_view_->setBusy(false); + need_resize_ = false; } @@ -471,8 +472,6 @@ void GuiWorkArea::toggleCursor() void GuiWorkArea::updateScrollbar() { - if (verticalScrollBarPolicy() != Qt::ScrollBarAlwaysOn) - setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); verticalScrollBar()->setTracking(false); buffer_view_->updateScrollbar(); @@ -725,7 +724,6 @@ void GuiWorkArea::paintEvent(QPaintEvent * ev) updateScreen(); hideCursor(); showCursor(); - need_resize_ = false; } QPainter pain(viewport()); @@ -1058,6 +1056,22 @@ bool TabWorkArea::setCurrentWorkArea(GuiWorkArea * work_area) } +GuiWorkArea * TabWorkArea::addWorkArea(Buffer & buffer, GuiView & view) +{ + GuiWorkArea * wa = new GuiWorkArea(buffer, view); + wa->setUpdatesEnabled(false); + // Hide tabbar if there's no tab (avoid a resize when hiding it again). + showBar(count() > 0); + addTab(wa, wa->windowTitle()); + QObject::connect(wa, SIGNAL(titleChanged(GuiWorkArea *)), + this, SLOT(updateTabText(GuiWorkArea *))); + // Hide tabbar if there's only one tab. + showBar(count() > 1); + wa->resizeBufferView(); + return wa; +} + + bool TabWorkArea::removeWorkArea(GuiWorkArea * work_area) { BOOST_ASSERT(work_area); @@ -1084,8 +1098,8 @@ void TabWorkArea::on_currentTabChanged(int i) GuiWorkArea * wa = dynamic_cast(widget(i)); BOOST_ASSERT(wa); BufferView & bv = wa->bufferView(); - bv.updateMetrics(); bv.cursor().fixIfBroken(); + bv.updateMetrics(); wa->setUpdatesEnabled(true); wa->redraw(); wa->setFocus(); diff --git a/src/frontends/qt4/GuiWorkArea.h b/src/frontends/qt4/GuiWorkArea.h index 0da23ceff3..a542517f8a 100644 --- a/src/frontends/qt4/GuiWorkArea.h +++ b/src/frontends/qt4/GuiWorkArea.h @@ -125,6 +125,8 @@ public: /// Process Key pressed event. /// This needs to be public because it is accessed externally by GuiView. void processKeySym(KeySymbol const & key, KeyModifier mod); + /// + void resizeBufferView(); Q_SIGNALS: /// @@ -191,8 +193,6 @@ private: void generateSyntheticMouseEvent(); /// void dispatch(FuncRequest const & cmd0, KeyModifier = NoModifier); - /// - void resizeBufferView(); /// hide the visible cursor, if it is visible void hideCursor(); /// show the cursor if it is not visible @@ -239,6 +239,7 @@ public: void showBar(bool show); void closeAll(); bool setCurrentWorkArea(GuiWorkArea *); + GuiWorkArea * addWorkArea(Buffer & buffer, GuiView & view); bool removeWorkArea(GuiWorkArea *); GuiWorkArea * currentWorkArea(); GuiWorkArea * workArea(Buffer & buffer); -- 2.39.5