From fe8bce66763174f67f8546cb51008e2bc8863144 Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Sun, 11 Nov 2007 22:30:21 +0000 Subject: [PATCH] Transfer readOnly() and updateWindowTitle() from Delegates to WorkArea/WorkAreaManager. This permits to automatically update Windows and Tabs titles (thanks to Qt signal/slot connections). git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21551 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/Buffer.cpp | 8 ++--- src/frontends/Delegates.h | 4 --- src/frontends/LyXView.cpp | 31 ------------------- src/frontends/LyXView.h | 14 --------- src/frontends/WorkArea.cpp | 40 +++++++++++++++++++++++-- src/frontends/WorkArea.h | 14 +++++++++ src/frontends/WorkAreaManager.cpp | 20 +++++++++++++ src/frontends/WorkAreaManager.h | 6 ++++ src/frontends/qt4/GuiView.cpp | 50 ++++++++++++++----------------- src/frontends/qt4/GuiView.h | 10 ++----- src/frontends/qt4/GuiWorkArea.cpp | 23 ++++++++++++++ src/frontends/qt4/GuiWorkArea.h | 9 ++++++ 12 files changed, 138 insertions(+), 91 deletions(-) diff --git a/src/Buffer.cpp b/src/Buffer.cpp index edb0684b73..8ee9e09764 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -1996,15 +1996,15 @@ void Buffer::setBusy(bool on) const void Buffer::setReadOnly(bool on) const { - if (gui_) - gui_->setReadOnly(on); + if (pimpl_->wa_) + pimpl_->wa_->setReadOnly(on); } void Buffer::updateTitles() const { - if (gui_) - gui_->updateTitles(); + if (pimpl_->wa_) + pimpl_->wa_->updateTitles(); } diff --git a/src/frontends/Delegates.h b/src/frontends/Delegates.h index 3c75c66c4b..270e4fabf1 100644 --- a/src/frontends/Delegates.h +++ b/src/frontends/Delegates.h @@ -59,10 +59,6 @@ public: virtual void message(docstring const &) = 0; /// This function is called when the buffer busy status change. virtual void setBusy(bool) = 0; - /// This function is called when the buffer readonly status change. - virtual void setReadOnly(bool) = 0; - /// Update window titles of all users. - virtual void updateTitles() = 0; /// Reset autosave timers for all users. virtual void resetAutosaveTimers() = 0; }; diff --git a/src/frontends/LyXView.cpp b/src/frontends/LyXView.cpp index 9d9029dd57..eeceb2f2fb 100644 --- a/src/frontends/LyXView.cpp +++ b/src/frontends/LyXView.cpp @@ -217,13 +217,6 @@ void LyXView::updateDialog(string const & name, string const & data) } -void LyXView::setReadOnly(bool) -{ - updateWindowTitle(); - getDialogs().updateBufferDependent(false); -} - - BufferView * LyXView::view() { WorkArea * wa = currentWorkArea(); @@ -259,30 +252,6 @@ void LyXView::resetAutosaveTimer() } -void LyXView::updateWindowTitle() -{ - docstring maximize_title = from_ascii("LyX"); - docstring minimize_title = from_ascii("LyX"); - - Buffer * buf = buffer(); - if (buf) { - string const cur_title = buf->absFileName(); - if (!cur_title.empty()) { - maximize_title += ": " + makeDisplayPath(cur_title, 30); - minimize_title = lyx::from_utf8(onlyFilename(cur_title)); - if (!buf->isClean()) { - maximize_title += _(" (changed)"); - minimize_title += char_type('*'); - } - if (buf->isReadonly()) - maximize_title += _(" (read only)"); - } - } - - setWindowTitle(maximize_title, minimize_title); -} - - void LyXView::dispatch(FuncRequest const & cmd) { string const argument = to_utf8(cmd.argument()); diff --git a/src/frontends/LyXView.h b/src/frontends/LyXView.h index 29508f2ef3..433074a958 100644 --- a/src/frontends/LyXView.h +++ b/src/frontends/LyXView.h @@ -158,9 +158,6 @@ public: /// clear any temporary message and replace with current status virtual void clearMessage() = 0; - /// updates the title of the window - void updateWindowTitle(); - /// reset autosave timer void resetAutosaveTimer(); @@ -186,10 +183,6 @@ public: void structureChanged() { updateToc(); } /// This function is called when some parsing error shows up. void errors(std::string const & err) { showErrorList(err); } - /// This function is called when the buffer readonly status change. - void setReadOnly(bool on); - /// Update window titles of all users. - void updateTitles() { updateWindowTitle(); } /// Reset autosave timers for all users. void resetAutosaveTimers() { resetAutosaveTimer(); } @@ -203,13 +196,6 @@ public: void disconnectBuffer(); private: - /** - * setWindowTitle - set title of window - * @param t main window title - * @param it iconified (short) title - */ - virtual void setWindowTitle(docstring const & t, docstring const & it) = 0; - /// called on timeout void autoSave(); diff --git a/src/frontends/WorkArea.cpp b/src/frontends/WorkArea.cpp index c791877ac6..849cadeaec 100644 --- a/src/frontends/WorkArea.cpp +++ b/src/frontends/WorkArea.cpp @@ -16,6 +16,7 @@ #include "frontends/WorkArea.h" #include "frontends/Application.h" +#include "frontends/Dialogs.h" #include "frontends/FontMetrics.h" #include "frontends/LyXView.h" #include "frontends/WorkAreaManager.h" @@ -35,15 +36,14 @@ #include "MetricsInfo.h" #include "gettext.h" -#include "support/ForkedcallsController.h" #include "support/FileName.h" +#include "support/filetools.h" +#include "support/ForkedcallsController.h" #include #include #include -using lyx::support::ForkedcallsController; - using std::endl; using std::min; using std::max; @@ -62,6 +62,11 @@ boost::signals::connection timecon; } // anon namespace namespace lyx { + +using support::ForkedcallsController; +using support::makeDisplayPath; +using support::onlyFilename; + namespace frontend { WorkArea::WorkArea(Buffer & buffer, LyXView & lv) @@ -311,5 +316,34 @@ void WorkArea::toggleCursor() cursor_timeout_.restart(); } +void WorkArea::updateWindowTitle() +{ + docstring maximize_title; + docstring minimize_title; + + Buffer & buf = buffer_view_->buffer(); + string const cur_title = buf.absFileName(); + if (!cur_title.empty()) { + maximize_title = makeDisplayPath(cur_title, 30); + minimize_title = from_utf8(onlyFilename(cur_title)); + if (!buf.isClean()) { + maximize_title += _(" (changed)"); + minimize_title += char_type('*'); + } + if (buf.isReadonly()) + maximize_title += _(" (read only)"); + } + + setWindowTitle(maximize_title, minimize_title); +} + + +void WorkArea::setReadOnly(bool) +{ + updateWindowTitle(); + if (this == lyx_view_->currentWorkArea()) + lyx_view_->getDialogs().updateBufferDependent(false); +} + } // namespace frontend } // namespace lyx diff --git a/src/frontends/WorkArea.h b/src/frontends/WorkArea.h index 74a875f241..306b655532 100644 --- a/src/frontends/WorkArea.h +++ b/src/frontends/WorkArea.h @@ -104,9 +104,23 @@ public: /// Slot for Buffer::closing signal. void close(); + /// This function is called when the buffer readonly status change. + virtual void setReadOnly(bool); + + /// Update window titles of all users. + virtual void updateWindowTitle(); + protected: /// cause the display of the given area of the work area virtual void expose(int x, int y, int w, int h) = 0; + + /// set title of window. + /** + * @param t main window title + * @param it iconified (short) title + */ + virtual void setWindowTitle(docstring const & t, docstring const & it) = 0; + /// void dispatch(FuncRequest const & cmd0, KeyModifier = NoModifier); diff --git a/src/frontends/WorkAreaManager.cpp b/src/frontends/WorkAreaManager.cpp index 4957f7bc3b..e3c8d3e2a7 100644 --- a/src/frontends/WorkAreaManager.cpp +++ b/src/frontends/WorkAreaManager.cpp @@ -52,6 +52,26 @@ void WorkAreaManager::closeAll() (*work_areas_.begin())->close(); } + +void WorkAreaManager::setReadOnly(bool on) +{ + for (list::iterator it = work_areas_.begin(); + it != work_areas_.end(); ) { + (*it)->setReadOnly(on); + ++it; + } +} + + +void WorkAreaManager::updateTitles() +{ + for (list::iterator it = work_areas_.begin(); + it != work_areas_.end(); ) { + (*it)->updateWindowTitle(); + ++it; + } +} + } // namespace frontend } // namespace lyx diff --git a/src/frontends/WorkAreaManager.h b/src/frontends/WorkAreaManager.h index f2c93be019..00f7de53fe 100644 --- a/src/frontends/WorkAreaManager.h +++ b/src/frontends/WorkAreaManager.h @@ -42,6 +42,12 @@ public: /// void closeAll(); + /// This function is called when the buffer readonly status change. + virtual void setReadOnly(bool); + + /// Update window titles of all users. + virtual void updateTitles(); + private: std::list work_areas_; }; diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp index 02dced7e54..c79fc1a319 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -76,8 +76,6 @@ using std::vector; namespace lyx { -using support::makeDisplayPath; - extern bool quitting; namespace frontend { @@ -541,10 +539,6 @@ void GuiView::setGeometry(unsigned int width, show(); - // For an unknown reason, the Window title update is not effective for - // the second windows up until it is shown on screen (Qt bug?). - updateWindowTitle(); - // after show geometry() has changed (Qt bug?) // we compensate the drift when storing the position d.posx_offset = 0; @@ -566,23 +560,6 @@ void GuiView::setGeometry(unsigned int width, } -void GuiView::setWindowTitle(docstring const & t, docstring const & it) -{ - QString title = windowTitle(); - QString new_title = toqstr(t); - if (title != new_title) { - QMainWindow::setWindowTitle(new_title); - QMainWindow::setWindowIconText(toqstr(it)); - } - if (Buffer const * buf = buffer()) { - QString tabtext = toqstr(buf->fileName().displayName(30)); - d.current_work_area_->setWindowTitle(tabtext); - TabWorkArea * twa = d.currentTabWorkArea(); - twa->setTabText(twa->currentIndex(), tabtext); - } -} - - void GuiView::message(docstring const & str) { statusBar()->showMessage(toqstr(str)); @@ -632,12 +609,25 @@ void GuiView::update_view_state_qt() } +void GuiView::updateWindowTitle(GuiWorkArea * wa) +{ + if (wa != d.current_work_area_) + return; + setWindowTitle(qt_("LyX: ") + wa->windowTitle()); + setWindowIconText(wa->windowIconText()); +} + + void GuiView::on_currentWorkAreaChanged(GuiWorkArea * wa) { disconnectBuffer(); disconnectBufferView(); connectBufferView(wa->bufferView()); connectBuffer(wa->bufferView().buffer()); + d.current_work_area_ = wa; + QObject::connect(wa, SIGNAL(titleChanged(GuiWorkArea *)), + this, SLOT(updateWindowTitle(GuiWorkArea *))); + updateWindowTitle(wa); updateToc(); // Buffer-dependent dialogs should be updated or @@ -646,7 +636,6 @@ void GuiView::on_currentWorkAreaChanged(GuiWorkArea * wa) getDialogs().updateBufferDependent(true); updateToolbars(); updateLayoutChoice(false); - updateWindowTitle(); updateStatusBar(); } @@ -724,8 +713,10 @@ bool GuiView::event(QEvent * e) connectBuffer(bv.buffer()); // The document structure, name and dialogs might have // changed in another view. - updateWindowTitle(); getDialogs().updateBufferDependent(true); + } else { + setWindowTitle(qt_("LyX")); + setWindowIconText(qt_("LyX")); } return QMainWindow::event(e); } @@ -762,8 +753,8 @@ bool GuiView::focusNextPrevChild(bool /*next*/) void GuiView::showView() { - QMainWindow::setWindowTitle(qt_("LyX")); - QMainWindow::show(); + setWindowTitle(qt_("LyX")); + show(); updateFloatingGeometry(); } @@ -853,7 +844,10 @@ WorkArea * GuiView::addWorkArea(Buffer & buffer) addTabWorkArea(); TabWorkArea * tab_widget = d.currentTabWorkArea(); - tab_widget->addTab(wa, toqstr(buffer.fileName().displayName(30))); + 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. diff --git a/src/frontends/qt4/GuiView.h b/src/frontends/qt4/GuiView.h index 14bf01a2e6..78a7859a24 100644 --- a/src/frontends/qt4/GuiView.h +++ b/src/frontends/qt4/GuiView.h @@ -99,6 +99,9 @@ public Q_SLOTS: /// idle timeout void update_view_state_qt(); + /// + void updateWindowTitle(GuiWorkArea * wa); + /// void on_currentWorkAreaChanged(GuiWorkArea *); @@ -134,13 +137,6 @@ private: /// void dropEvent(QDropEvent * ev); - /** - * setWindowTitle - set title of window - * @param t main window title - * @param it iconified (short) title - */ - virtual void setWindowTitle(docstring const & t, docstring const & it); - /// in order to catch Tab key press. bool event(QEvent * e); bool focusNextPrevChild(bool); diff --git a/src/frontends/qt4/GuiWorkArea.cpp b/src/frontends/qt4/GuiWorkArea.cpp index a6206460bf..e6deea60bd 100644 --- a/src/frontends/qt4/GuiWorkArea.cpp +++ b/src/frontends/qt4/GuiWorkArea.cpp @@ -187,6 +187,7 @@ GuiWorkArea::GuiWorkArea(Buffer & buf, LyXView & lv) setAcceptDrops(true); setMouseTracking(true); setMinimumSize(100, 70); + updateWindowTitle(); viewport()->setAutoFillBackground(false); // We don't need double-buffering nor SystemBackground on @@ -496,6 +497,19 @@ void GuiWorkArea::expose(int x, int y, int w, int h) } +void GuiWorkArea::setWindowTitle(docstring const & t, docstring const & it) +{ + QString title = windowTitle(); + QString new_title = toqstr(t); + if (title == new_title) + return; + + QWidget::setWindowTitle(new_title); + QWidget::setWindowIconText(toqstr(it)); + titleChanged(this); +} + + void GuiWorkArea::updateScreen() { GuiPainter pain(&screen_); @@ -827,6 +841,15 @@ void TabWorkArea::closeCurrentTab() lyx::dispatch(FuncRequest(LFUN_BUFFER_CLOSE)); } + +void TabWorkArea::updateTabText(GuiWorkArea * wa) +{ + int const i = indexOf(wa); + if (i < 0) + return; + setTabText(i, wa->windowTitle()); +} + } // namespace frontend } // namespace lyx diff --git a/src/frontends/qt4/GuiWorkArea.h b/src/frontends/qt4/GuiWorkArea.h index d6ad4baa3f..ae1f752601 100644 --- a/src/frontends/qt4/GuiWorkArea.h +++ b/src/frontends/qt4/GuiWorkArea.h @@ -117,6 +117,12 @@ public: /// hide the cursor virtual void removeCursor(); + void setWindowTitle(docstring const & t, docstring const & it); + +Q_SIGNALS: + /// + void titleChanged(GuiWorkArea *); + private: /// void focusInEvent(QFocusEvent *); @@ -183,6 +189,7 @@ class TabWorkArea : public QTabWidget Q_OBJECT public: TabWorkArea(QWidget * parent = 0); + void showBar(bool show); void closeAll(); bool setCurrentWorkArea(GuiWorkArea *); @@ -199,6 +206,8 @@ public Q_SLOTS: void on_currentTabChanged(int index); /// void closeCurrentTab(); + /// + void updateTabText(GuiWorkArea *); }; // TabWorkArea } // namespace frontend -- 2.39.2