From 769185bc90f40499692b94eb66ebb645b7d27ce2 Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Sun, 7 Oct 2007 08:05:02 +0000 Subject: [PATCH] Transfer some code from GuiView to TabWorkArea. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20806 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt4/GuiView.cpp | 26 ++++---------------- src/frontends/qt4/GuiWorkArea.cpp | 40 +++++++++++++++++++++++++++++++ src/frontends/qt4/GuiWorkArea.h | 2 ++ 3 files changed, 46 insertions(+), 22 deletions(-) diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp index a50889e0fe..bd4872d955 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -868,13 +868,7 @@ void GuiViewBase::setCurrentWorkArea(WorkArea * work_area) GuiWorkArea * wa = dynamic_cast(work_area); BOOST_ASSERT(wa); - if (wa != d.tab_widget_->currentWidget()) - // Switch to the work area. - d.tab_widget_->setCurrentWidget(wa); - else - // Make sure the work area is up to date. - d.tab_widget_->on_currentTabChanged(d.tab_widget_->currentIndex()); - wa->setFocus(); + d.tab_widget_->setCurrentWorkArea(wa); } @@ -891,26 +885,14 @@ void GuiViewBase::removeWorkArea(WorkArea * work_area) updateToc(); GuiWorkArea * gwa = dynamic_cast(work_area); - gwa->setUpdatesEnabled(false); BOOST_ASSERT(gwa); - int index = d.tab_widget_->indexOf(gwa); - d.tab_widget_->removeTab(index); - - delete gwa; - - if (d.tab_widget_->count()) { - // make sure the next work area is enabled. - d.tab_widget_->currentWidget()->setUpdatesEnabled(true); - // Hide tabbar if there's only one tab. - d.tab_widget_->showBar(d.tab_widget_->count() > 1); - return; - } + d.tab_widget_->removeWorkArea(gwa); getDialogs().hideBufferDependent(); - if (d.stack_widget_) { + + if (d.tab_widget_->count() == 0 && d.stack_widget_) // No more work area, switch to the background widget. d.setBackground(); - } } diff --git a/src/frontends/qt4/GuiWorkArea.cpp b/src/frontends/qt4/GuiWorkArea.cpp index c25d392531..0bb9100904 100644 --- a/src/frontends/qt4/GuiWorkArea.cpp +++ b/src/frontends/qt4/GuiWorkArea.cpp @@ -728,6 +728,46 @@ void TabWorkArea::showBar(bool show) } +bool TabWorkArea::setCurrentWorkArea(GuiWorkArea * work_area) +{ + BOOST_ASSERT(work_area); + int index = indexOf(work_area); + if (index == -1) + return false; + + if (index == currentIndex()) + // Make sure the work area is up to date. + on_currentTabChanged(index); + else + // Switch to the work area. + setCurrentIndex(index); + work_area->setFocus(); + + return true; +} + + +bool TabWorkArea::removeWorkArea(GuiWorkArea * work_area) +{ + BOOST_ASSERT(work_area); + int index = indexOf(work_area); + if (index == -1) + return false; + + work_area->setUpdatesEnabled(false); + removeTab(index); + delete work_area; + + if (count()) { + // make sure the next work area is enabled. + currentWidget()->setUpdatesEnabled(true); + // Hide tabbar if there's only one tab. + showBar(count() > 1); + } + return true; +} + + void TabWorkArea::on_currentTabChanged(int i) { GuiWorkArea * wa = dynamic_cast(widget(i)); diff --git a/src/frontends/qt4/GuiWorkArea.h b/src/frontends/qt4/GuiWorkArea.h index dc9c84c2a4..2ddad927b0 100644 --- a/src/frontends/qt4/GuiWorkArea.h +++ b/src/frontends/qt4/GuiWorkArea.h @@ -180,6 +180,8 @@ class TabWorkArea : public QTabWidget public: TabWorkArea(QWidget * parent = 0); void showBar(bool show); + bool setCurrentWorkArea(GuiWorkArea *); + bool removeWorkArea(GuiWorkArea *); Q_SIGNALS: ///