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
This commit is contained in:
Abdelrazak Younes 2007-11-11 22:30:21 +00:00
parent 02a20a23e4
commit fe8bce6676
12 changed files with 138 additions and 91 deletions

View File

@ -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();
}

View File

@ -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;
};

View File

@ -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());

View File

@ -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();

View File

@ -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 <boost/noncopyable.hpp>
#include <boost/bind.hpp>
#include <boost/current_function.hpp>
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

View File

@ -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);

View File

@ -52,6 +52,26 @@ void WorkAreaManager::closeAll()
(*work_areas_.begin())->close();
}
void WorkAreaManager::setReadOnly(bool on)
{
for (list<WorkArea *>::iterator it = work_areas_.begin();
it != work_areas_.end(); ) {
(*it)->setReadOnly(on);
++it;
}
}
void WorkAreaManager::updateTitles()
{
for (list<WorkArea *>::iterator it = work_areas_.begin();
it != work_areas_.end(); ) {
(*it)->updateWindowTitle();
++it;
}
}
} // namespace frontend
} // namespace lyx

View File

@ -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<WorkArea *> work_areas_;
};

View File

@ -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.

View File

@ -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);

View File

@ -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

View File

@ -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