Hello,
With this patch Fontloader becomes a member of the Application class and
the Gui class now contains the infrastructure to handle multiple
LyXViews. In other words, this is step 2 of my Clenup plan. Only
scons/qt4 support for now. Note that it still crashes on startup.
I would prefer to merge the current "younes" tree before applying that.
I have an OK from Georg, Andre and I would guess Angus also. Jean-Marc
didn't seem to have any objection.
Opinion?
Abdel
Index: src/BufferView_pimpl.C
===================================================================
--- src/BufferView_pimpl.C (revision 14138)
+++ src/BufferView_pimpl.C (working copy)
@@ -145,7 +145,8 @@
{
xsel_cache_.set = false;
- work_area_id_ = owner_->gui().newWorkArea(width, height);
+ // FIXME: for now we assume that there is only one LyXView with id = 0.
+ work_area_id_ = owner_->gui().newWorkArea(width, height, 0);
work_area_ = & owner_->gui().workArea(work_area_id_);
// Setup the signals
Index: src/frontends/Gui.h
===================================================================
--- src/frontends/Gui.h (revision 14138)
+++ src/frontends/Gui.h (working copy)
@@ -16,6 +16,8 @@
#include "frontends/GuiCursor.h"
+class LyXView;
+
namespace lyx {
namespace frontend {
@@ -33,9 +35,17 @@
///
virtual Clipboard& clipboard() = 0;
+
///
- virtual int newWorkArea(int w, int h) = 0;
+ virtual int newView(unsigned int width, unsigned int height) = 0;
///
+ virtual LyXView& view(int id) = 0;
+ ///
+ virtual void destroyView(int id) = 0;
+
+ ///
+ virtual int newWorkArea(unsigned int width, unsigned int height, int
view_id) = 0;
+ ///
virtual WorkArea& workArea(int id) = 0;
///
virtual void destroyWorkArea(int id) = 0;
Index: src/frontends/LyXView.C
===================================================================
--- src/frontends/LyXView.C (revision 14138)
+++ src/frontends/LyXView.C (working copy)
@@ -12,6 +12,7 @@
#include <config.h>
#include "LyXView.h"
+#include "Gui.h"
#include "Dialogs.h"
#include "Timeout.h"
#include "Toolbars.h"
@@ -46,6 +47,8 @@
# include <unistd.h>
#endif
+using lyx::frontend::Gui;
+
using lyx::support::makeDisplayPath;
using lyx::support::onlyFilename;
@@ -56,9 +59,14 @@
string current_layout;
+Gui & LyXView::gui()
+{
+ return owner_;
+}
-LyXView::LyXView()
- : toolbars_(new Toolbars(*this)),
+LyXView::LyXView(Gui & owner)
+ : owner_(owner),
+ toolbars_(new Toolbars(*this)),
intl_(new Intl),
autosave_timeout_(new Timeout(5000)),
lyxfunc_(new LyXFunc(this)),
Index: src/frontends/LyXView.h
===================================================================
--- src/frontends/LyXView.h (revision 14138)
+++ src/frontends/LyXView.h (working copy)
@@ -33,12 +33,8 @@
class FuncRequest;
namespace lyx {
-
namespace frontend {
class Gui;
-} // namespace frontend
-
-namespace frontend {
class ControlCommandBuffer;
} // namespace frontend
@@ -60,7 +56,7 @@
class LyXView : public boost::signals::trackable, boost::noncopyable {
public:
- LyXView();
+ LyXView(lyx::frontend::Gui & owner);
virtual ~LyXView();
@@ -148,10 +144,11 @@
*/
Buffer const * const updateInset(InsetBase const *) const;
- // returns true if this view has the focus.
+ /// returns true if this view has the focus.
virtual bool hasFocus() const = 0;
- virtual lyx::frontend::Gui & gui() = 0;
+ ///
+ virtual lyx::frontend::Gui & gui();
protected:
/// view of a buffer. Eventually there will be several.
@@ -161,6 +158,7 @@
boost::scoped_ptr<Menubar> menubar_;
private:
+ lyx::frontend::Gui & owner_;
/**
* setWindowTitle - set title of window
* @param t main window title
Index: src/frontends/qt4/Action.C
===================================================================
--- src/frontends/qt4/Action.C (revision 14138)
+++ src/frontends/qt4/Action.C (working copy)
@@ -19,7 +19,7 @@
#include <boost/bind.hpp>
-#include "LyXView.h"
+#include "frontends/LyXView.h"
#include "qt_helpers.h"
#include "Action.h"
Index: src/frontends/qt4/Application.h
===================================================================
--- src/frontends/qt4/Application.h (revision 14138)
+++ src/frontends/qt4/Application.h (working copy)
@@ -13,6 +13,9 @@
#ifndef LYX_APPLICATION_H
#define LYX_APPLICATION_H
+#include "TheGui.h"
+#include "FontLoader.h"
+
#include <QApplication>
///////////////////////////////////////////////////////////////
@@ -41,12 +44,23 @@
public:
Application(int & argc, char ** argv);
+ //
+ Gui & gui() { return gui_; }
+ ///
+ FontLoader & fontLoader() { return font_loader_; }
+
void connect(GuiWorkArea * work_area);
private:
///
GuiWorkArea * work_area_;
+ ///
+ TheGui gui_;
+
+ ///
+ FontLoader font_loader_;
+
#ifdef Q_WS_X11
public:
bool x11EventFilter (XEvent * ev);
@@ -65,4 +79,6 @@
} // namespace frontend
} // namespace lyx
+extern lyx::frontend::Application * theApp;
+
#endif // LYX_APPLICATION_H
Index: src/frontends/qt4/FontLoader.h
===================================================================
--- src/frontends/qt4/FontLoader.h (revision 14138)
+++ src/frontends/qt4/FontLoader.h (working copy)
@@ -97,6 +97,4 @@
QLFontInfo * fontinfo_[LyXFont::NUM_FAMILIES][2][4][10];
};
-extern FontLoader fontloader;
-
#endif // QFONT_LOADER_H
Index: src/frontends/qt4/GuiView.C
===================================================================
--- src/frontends/qt4/GuiView.C (revision 14133)
+++ src/frontends/qt4/GuiView.C (working copy)
@@ -1,5 +1,5 @@
/**
- * \file QtView.C
+ * \file GuiView.C
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
@@ -33,7 +33,8 @@
#include "support/convert.h"
#include <boost/bind.hpp>
-#include "QtView.h"
+#include "GuiView.h"
+#include "TheGui.h"
#include "QLMenubar.h"
#include "FontLoader.h"
#include "QCommandBuffer.h"
@@ -54,8 +55,6 @@
using std::string;
using std::endl;
-FontLoader fontloader;
-
namespace lyx {
using support::subst;
@@ -70,8 +69,8 @@
} // namespace anon
-QtView::QtView(unsigned int width, unsigned int height)
- : QMainWindow(), LyXView(), commandbuffer_(0), frontend_(*this)
+GuiView::GuiView(Gui & owner, unsigned int width, unsigned int height)
+ : QMainWindow(), LyXView(owner), commandbuffer_(0)
{
mainWidget_ = this;
@@ -87,7 +86,7 @@
statusBar()->setSizeGripEnabled(false);
- view_state_changed.connect(boost::bind(&QtView::update_view_state,
this));
+ view_state_changed.connect(boost::bind(&GuiView::update_view_state,
this));
connect(&statusbar_timer_, SIGNAL(timeout()), this,
SLOT(update_view_state_qt()));
#ifndef Q_WS_MACX
@@ -103,31 +102,31 @@
}
-QtView::~QtView()
+GuiView::~GuiView()
{
}
-void QtView::updateMenu(QAction *action)
+void GuiView::updateMenu(QAction *action)
{
menubar_->update();
}
-void QtView::setWindowTitle(string const & t, string const & it)
+void GuiView::setWindowTitle(string const & t, string const & it)
{
QMainWindow::setWindowTitle(toqstr(t));
QMainWindow::setWindowIconText(toqstr(it));
}
-void QtView::addCommandBuffer(QToolBar * toolbar)
+void GuiView::addCommandBuffer(QToolBar * toolbar)
{
commandbuffer_ = new QCommandBuffer(this, *controlcommand_);
- focus_command_buffer.connect(boost::bind(&QtView::focus_command_widget,
this));
+
focus_command_buffer.connect(boost::bind(&GuiView::focus_command_widget, this));
toolbar->addWidget(commandbuffer_);
}
-void QtView::message(string const & str)
+void GuiView::message(string const & str)
{
statusBar()->showMessage(toqstr(str));
statusbar_timer_.stop();
@@ -135,27 +134,27 @@
}
-void QtView::clearMessage()
+void GuiView::clearMessage()
{
update_view_state_qt();
}
-void QtView::focus_command_widget()
+void GuiView::focus_command_widget()
{
if (commandbuffer_)
commandbuffer_->focus_command();
}
-void QtView::update_view_state_qt()
+void GuiView::update_view_state_qt()
{
statusBar()->showMessage(toqstr(getLyXFunc().viewStatusMessage()));
statusbar_timer_.stop();
}
-void QtView::update_view_state()
+void GuiView::update_view_state()
{
// let the user see the explicit message
if (statusbar_timer_.isActive())
@@ -165,19 +164,19 @@
}
-void QtView::activated(FuncRequest const & func)
+void GuiView::activated(FuncRequest const & func)
{
getLyXFunc().dispatch(func);
}
-bool QtView::hasFocus() const
+bool GuiView::hasFocus() const
{
return qApp->activeWindow() == this;
}
-void QtView::closeEvent(QCloseEvent *)
+void GuiView::closeEvent(QCloseEvent *)
{
QRect geometry = normalGeometry();
Session & session = LyX::ref().session();
@@ -195,14 +194,14 @@
}
-void QtView::show()
+void GuiView::show()
{
QMainWindow::setWindowTitle(qt_("LyX"));
QMainWindow::show();
}
-void QtView::busy(bool yes) const
+void GuiView::busy(bool yes) const
{
if (yes)
QApplication::setOverrideCursor(Qt::WaitCursor);
@@ -210,15 +209,15 @@
QApplication::restoreOverrideCursor();
}
-QMainWindow* QtView::mainWidget()
+QMainWindow* GuiView::mainWidget()
{
return mainWidget_;
}
-QMainWindow* QtView::mainWidget_ = 0;
+QMainWindow* GuiView::mainWidget_ = 0;
} // namespace frontend
} // namespace lyx
-#include "QtView_moc.cpp"
+#include "GuiView_moc.cpp"
Index: src/frontends/qt4/GuiView.h
===================================================================
--- src/frontends/qt4/GuiView.h (revision 14133)
+++ src/frontends/qt4/GuiView.h (working copy)
@@ -1,6 +1,6 @@
// -*- C++ -*-
/**
- * \file QtView.h
+ * \file GuiView.h
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
@@ -11,14 +11,12 @@
* Full author contact details are available in file CREDITS.
*/
-#ifndef QTVIEW_H
-#define QTVIEW_H
+#ifndef GUI_VIEW_H
+#define GUI_VIEW_H
// Must be here because of moc.
#include <config.h>
-#include "TheGui.h"
-
#include "frontends/LyXView.h"
#include "funcrequest.h"
@@ -41,17 +39,17 @@
QWidget* mainWindow();
/**
- * QtView - Qt implementation of LyXView
+ * GuiView - Qt4 implementation of LyXView
*
- * Qt-private implementation of the main LyX window.
+ * qt4-private implementation of the main LyX window.
*/
-class QtView : public QMainWindow, public LyXView {
+class GuiView : public QMainWindow, public LyXView {
Q_OBJECT
public:
/// create a main window of the given dimensions
- QtView(unsigned int w, unsigned int h);
+ GuiView(Gui & owner, unsigned int w, unsigned int h);
- ~QtView();
+ ~GuiView();
/// show - display the top-level window
void show();
@@ -71,12 +69,9 @@
/// menu item has been selected
void activated(FuncRequest const &);
- // returns true if this view has the focus.
+ /// returns true if this view has the focus.
virtual bool hasFocus() const;
- //
- Gui & gui() { return frontend_; }
-
static QMainWindow* mainWidget();
public slots:
@@ -90,6 +85,7 @@
/// make sure we quit cleanly
virtual void closeEvent(QCloseEvent * e);
private:
+
/// focus the command buffer widget
void focus_command_widget();
@@ -110,11 +106,9 @@
///
static QMainWindow* mainWidget_;
-
- TheGui frontend_;
};
} // namespace frontend
} // namespace lyx
-#endif // QTVIEW_H
+#endif // GUI_VIEW_H
Index: src/frontends/qt4/GuiWorkArea.C
===================================================================
--- src/frontends/qt4/GuiWorkArea.C (revision 14138)
+++ src/frontends/qt4/GuiWorkArea.C (working copy)
@@ -16,7 +16,7 @@
#include "GuiWorkArea.h"
#include "QLPainter.h"
#include "QLyXKeySym.h"
-#include "QtView.h"
+#include "GuiView.h"
#include "ColorCache.h"
#include "qt_helpers.h"
@@ -112,12 +112,12 @@
GuiWorkArea::GuiWorkArea(LyXView & owner, int w, int h)
-: QAbstractScrollArea(QtView::mainWidget()), WorkArea(owner, w, h),
view_(owner), painter_(this)
+: QAbstractScrollArea(GuiView::mainWidget()), WorkArea(owner, w, h),
view_(owner), painter_(this)
{
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
- QtView::mainWidget()->setCentralWidget(this);
+ GuiView::mainWidget()->setCentralWidget(this);
setAcceptDrops(true);
Index: src/frontends/qt4/GuiWorkArea.h
===================================================================
--- src/frontends/qt4/GuiWorkArea.h (revision 14138)
+++ src/frontends/qt4/GuiWorkArea.h (working copy)
@@ -190,8 +190,8 @@
void adjustViewWithScrollBar(int action = 0);
private:
- ///
- LyXView & view_;
+ ///
+ LyXView & view_;
/// Buffer view width.
int workWidth_;
Index: src/frontends/qt4/lyx_gui.C
===================================================================
--- src/frontends/qt4/lyx_gui.C (revision 14138)
+++ src/frontends/qt4/lyx_gui.C (working copy)
@@ -39,7 +39,7 @@
#include <boost/bind.hpp>
#include <boost/shared_ptr.hpp>
-#include "QtView.h"
+#include "GuiView.h"
#include "ColorCache.h"
#include "FontLoader.h"
#include "QLImage.h"
@@ -59,7 +59,8 @@
using lyx::support::ltrim;
using lyx::support::package;
-using lyx::frontend::QtView;
+using lyx::frontend::TheGui;
+using lyx::frontend::GuiView;
using lyx::frontend::Application;
namespace os = lyx::support::os;
@@ -78,6 +79,8 @@
LyXServer * lyxserver;
LyXServerSocket * lyxsocket;
+lyx::frontend::Application * theApp;
+
namespace {
int getDPI()
@@ -133,7 +136,9 @@
Application app(argc, argv);
#endif
+ theApp = &app;
+
// install translation file for Qt built-in dialogs
// These are only installed since Qt 3.2.x
QTranslator qt_trans;
@@ -194,10 +199,10 @@
// this can't be done before because it needs the Languages object
initEncodings();
- boost::shared_ptr<QtView> view_ptr(new QtView(width, height));
- LyX::ref().addLyXView(view_ptr);
+ int view_id = theApp->gui().newView(width, height);
+ GuiView & view = static_cast<GuiView &> (theApp->gui().view(view_id));
- QtView & view = *view_ptr.get();
+ LyX::ref().addLyXView(&view);
view.init();
@@ -303,13 +308,13 @@
void update_fonts()
{
- fontloader.update();
+ theApp->fontLoader().update();
}
bool font_available(LyXFont const & font)
{
- return fontloader.available(font);
+ return theApp->fontLoader().available(font);
}
Index: src/frontends/qt4/QCommandBuffer.C
===================================================================
--- src/frontends/qt4/QCommandBuffer.C (revision 14138)
+++ src/frontends/qt4/QCommandBuffer.C (working copy)
@@ -12,7 +12,7 @@
// Qt defines a macro 'signals' that clashes with a boost namespace.
// All is well if the namespace is visible first.
-#include "QtView.h"
+#include "GuiView.h"
#include "QCommandBuffer.h"
#include "QCommandEdit.h"
@@ -74,7 +74,7 @@
} // end of anon
-QCommandBuffer::QCommandBuffer(QtView * view, ControlCommandBuffer & control,
QWidget * parent)
+QCommandBuffer::QCommandBuffer(GuiView * view, ControlCommandBuffer & control,
QWidget * parent)
: QWidget(parent), view_(view), controller_(control)
{
QPixmap qpup(toqstr(libFileSearch("images", "up", "xpm")));
Index: src/frontends/qt4/QCommandBuffer.h
===================================================================
--- src/frontends/qt4/QCommandBuffer.h (revision 14138)
+++ src/frontends/qt4/QCommandBuffer.h (working copy)
@@ -20,13 +20,13 @@
namespace frontend {
class QCommandEdit;
-class QtView;
+class GuiView;
class ControlCommandBuffer;
class QCommandBuffer : public QWidget {
Q_OBJECT
public:
- QCommandBuffer(QtView * view, ControlCommandBuffer & control, QWidget *
parent=NULL);
+ QCommandBuffer(GuiView * view, ControlCommandBuffer & control, QWidget
* parent=NULL);
/// focus the edit widget
void focus_command();
@@ -45,7 +45,7 @@
void down();
private:
/// owning view
- QtView * view_;
+ GuiView * view_;
/// controller
ControlCommandBuffer & controller_;
Index: src/frontends/qt4/qfont_metrics.C
===================================================================
--- src/frontends/qt4/qfont_metrics.C (revision 14138)
+++ src/frontends/qt4/qfont_metrics.C (working copy)
@@ -15,6 +15,7 @@
#include "frontends/lyx_gui.h"
#include "FontLoader.h"
+#include "Application.h"
#include "language.h"
@@ -28,7 +29,7 @@
{
if (!lyx_gui::use_gui)
return 1;
- return fontloader.metrics(f).ascent();
+ return theApp->fontLoader().metrics(f).ascent();
}
@@ -38,7 +39,7 @@
return 1;
// We add 1 as the value returned by QT is different than X
// See http://doc.trolltech.com/2.3/qfontmetrics.html#200b74
- return fontloader.metrics(f).descent() + 1;
+ return theApp->fontLoader().metrics(f).descent() + 1;
}
@@ -46,7 +47,7 @@
{
if (!lyx_gui::use_gui)
return 1;
- QRect const & r = fontloader.metrics(f).boundingRect(c);
+ QRect const & r = theApp->fontLoader().metrics(f).boundingRect(c);
// Qt/Win 3.2.1nc (at least) corrects the GetGlyphOutlineA|W y
// value by the height: (x, -y-height, width, height).
// Other versions return: (x, -y, width, height)
@@ -62,7 +63,7 @@
{
if (!lyx_gui::use_gui)
return 1;
- QRect const & r = fontloader.metrics(f).boundingRect(c);
+ QRect const & r = theApp->fontLoader().metrics(f).boundingRect(c);
// Qt/Win 3.2.1nc (at least) corrects the GetGlyphOutlineA|W y
// value by the height: (x, -y-height, width, height).
// Other versions return: (x, -y, width, height)
@@ -78,7 +79,7 @@
{
if (!lyx_gui::use_gui)
return 1;
- return fontloader.metrics(f).leftBearing(c);
+ return theApp->fontLoader().metrics(f).leftBearing(c);
}
@@ -86,7 +87,7 @@
{
if (!lyx_gui::use_gui)
return 1;
- QFontMetrics const & m = fontloader.metrics(f);
+ QFontMetrics const & m = theApp->fontLoader().metrics(f);
// Qt rbearing is from the right edge of the char's width().
return m.width(c) - m.rightBearing(c);
@@ -111,8 +112,8 @@
LyXFont smallfont = f;
smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
- QFontMetrics const & qm = fontloader.metrics(f);
- QFontMetrics const & qsmallm = fontloader.metrics(smallfont);
+ QFontMetrics const & qm = theApp->fontLoader().metrics(f);
+ QFontMetrics const & qsmallm = theApp->fontLoader().metrics(smallfont);
Encoding const * encoding = fontencoding(f);
@@ -139,7 +140,7 @@
return smallcapswidth(s, ls, f);
Encoding const * encoding = fontencoding(f);
- QLFontInfo & fi = fontloader.fontinfo(f);
+ QLFontInfo & fi = theApp->fontLoader().fontinfo(f);
if (ls == 1)
return fi.width(encoding->ucs(s[0]));
@@ -164,7 +165,7 @@
void rectText(string const & str, LyXFont const & f,
int & w, int & ascent, int & descent)
{
- QFontMetrics const & m = fontloader.metrics(f);
+ QFontMetrics const & m = theApp->fontLoader().metrics(f);
static int const d = 2;
w = width(str, f) + d * 2 + 2;
ascent = m.ascent() + d;
@@ -176,7 +177,7 @@
void buttonText(string const & str, LyXFont const & f,
int & w, int & ascent, int & descent)
{
- QFontMetrics const & m = fontloader.metrics(f);
+ QFontMetrics const & m = theApp->fontLoader().metrics(f);
static int const d = 3;
w = width(str, f) + d * 2 + 2;
ascent = m.ascent() + d;
Index: src/frontends/qt4/QLMenubar.C
===================================================================
--- src/frontends/qt4/QLMenubar.C (revision 14138)
+++ src/frontends/qt4/QLMenubar.C (working copy)
@@ -12,7 +12,7 @@
// Qt defines a macro 'signals' that clashes with a boost namespace.
// All is well if the namespace is visible first.
-#include "QtView.h"
+#include "GuiView.h"
#include "QLMenubar.h"
#include "QLPopupMenu.h"
@@ -43,7 +43,7 @@
// MacOSX specific stuff is at the end.
QLMenubar::QLMenubar(LyXView * view, MenuBackend & mbe)
- : owner_(static_cast<QtView*>(view)), menubackend_(mbe)
+ : owner_(static_cast<GuiView*>(view)), menubackend_(mbe)
{
macxMenuBarInit();
@@ -114,7 +114,7 @@
void QLMenubar::update()
{ }
-QtView * QLMenubar::view()
+GuiView * QLMenubar::view()
{
return owner_;
}
Index: src/frontends/qt4/QLMenubar.h
===================================================================
--- src/frontends/qt4/QLMenubar.h (revision 14138)
+++ src/frontends/qt4/QLMenubar.h (working copy)
@@ -23,7 +23,7 @@
#include "QLPopupMenu.h"
-class LyXView;
+class LyxView;
class MenuBackend;
class Menu;
class MenuItem;
@@ -33,7 +33,7 @@
namespace frontend {
-class QtView;
+class GuiView;
class QLMenubar : public QObject, public Menubar {
Q_OBJECT
@@ -44,7 +44,7 @@
void openByName(std::string const &);
/// return the owning view
- QtView * view();
+ GuiView * view();
/// return the menu controller
MenuBackend const & backend();
@@ -64,7 +64,7 @@
void macxMenuBarInit();
/// owning view
- QtView * owner_;
+ GuiView * owner_;
/// menu controller
MenuBackend & menubackend_;
Index: src/frontends/qt4/QLPainter.C
===================================================================
--- src/frontends/qt4/QLPainter.C (revision 14138)
+++ src/frontends/qt4/QLPainter.C (working copy)
@@ -15,10 +15,11 @@
#include "GuiWorkArea.h"
#include "QLImage.h"
-
#include "ColorCache.h"
#include "FontLoader.h"
+#include "Application.h"
+
#include "debug.h"
#include "language.h"
#include "LColor.h"
@@ -203,8 +204,8 @@
LyXFont smallfont(f);
smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
- QFont const & qfont = fontloader.get(f);
- QFont const & qsmallfont = fontloader.get(smallfont);
+ QFont const & qfont = theApp->fontLoader().get(f);
+ QFont const & qsmallfont = theApp->fontLoader().get(smallfont);
QFontMetrics const & qfontm = QFontMetrics(qfont);
QFontMetrics const & qsmallfontm = QFontMetrics(qsmallfont);
@@ -247,7 +248,7 @@
if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
QPainter qp(qwa_->paintDevice());
setQPainterPen(qp, f.realColor());
- qp.setFont(fontloader.get(f));
+ qp.setFont(theApp->fontLoader().get(f));
// We need to draw the text as LTR as we use our own bidi code.
qp.setLayoutDirection(Qt::LeftToRight);
qp.drawText(x, y, str);
Index: src/frontends/qt4/QLPopupMenu.C
===================================================================
--- src/frontends/qt4/QLPopupMenu.C (revision 14138)
+++ src/frontends/qt4/QLPopupMenu.C (working copy)
@@ -15,7 +15,7 @@
// Qt defines a macro 'signals' that clashes with a boost namespace.
// All is well if the namespace is visible first.
-#include "QtView.h"
+#include "GuiView.h"
#include "Action.h"
#include "QLPopupMenu.h"
Index: src/frontends/qt4/QLToolbar.C
===================================================================
--- src/frontends/qt4/QLToolbar.C (revision 14138)
+++ src/frontends/qt4/QLToolbar.C (working copy)
@@ -24,7 +24,7 @@
#include "gettext.h"
#include "lyxfunc.h"
-#include "QtView.h"
+#include "GuiView.h"
#include "QLToolbar.h"
#include "Action.h"
#include "qt_helpers.h"
@@ -81,7 +81,7 @@
} // namespace anon
-QLayoutBox::QLayoutBox(QToolBar * toolbar, QtView & owner)
+QLayoutBox::QLayoutBox(QToolBar * toolbar, GuiView & owner)
: owner_(owner)
{
combo_ = new QComboBox;
@@ -189,7 +189,7 @@
namespace frontend {
QLToolbar::QLToolbar(ToolbarBackend::Toolbar const & tbb, LyXView & owner)
- : owner_(dynamic_cast<QtView &>(owner)),
+ : owner_(dynamic_cast<GuiView &>(owner)),
toolbar_(new QToolBar(qt_(tbb.gui_name), (QWidget*) &owner_)) //,
getPosition(tbb.flags)))
{
/// \toto Move \a addToolBar call into QView because, in Qt4,
Index: src/frontends/qt4/QLToolbar.h
===================================================================
--- src/frontends/qt4/QLToolbar.h (revision 14138)
+++ src/frontends/qt4/QLToolbar.h (working copy)
@@ -29,14 +29,14 @@
namespace frontend {
class QLayoutBox;
-class QtView;
+class GuiView;
class Action;
class QLayoutBox : public QObject, public LayoutBox {
Q_OBJECT
public:
- QLayoutBox(QToolBar *, QtView &);
+ QLayoutBox(QToolBar *, GuiView &);
/// select the right layout in the combox.
void set(std::string const & layout);
@@ -54,7 +54,7 @@
private:
QComboBox * combo_;
- QtView & owner_;
+ GuiView & owner_;
};
@@ -77,7 +77,7 @@
private:
std::vector<Action *> ActionVector;
- QtView & owner_;
+ GuiView & owner_;
QToolBar * toolbar_;
boost::scoped_ptr<QLayoutBox> layout_;
Index: src/frontends/qt4/QtView.C
===================================================================
--- src/frontends/qt4/QtView.C (revision 14138)
+++ src/frontends/qt4/QtView.C (working copy)
@@ -1,224 +0,0 @@
-/**
- * \file QtView.C
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Lars Gullik Bjønnes
- * \author John Levon
- * \author Abdelrazak Younes
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#undef QT3_SUPPORT
-
-#include <config.h>
-
-#include "BufferView.h"
-#include "lyx_cb.h"
-#include "lyxrc.h"
-#include "lyx_main.h"
-#include "session.h"
-#include "lyxfunc.h"
-#include "MenuBackend.h"
-#include "funcrequest.h"
-#include "funcrequest.h"
-
-#include "debug.h"
-
-#include "frontends/Toolbars.h"
-
-#include "support/filetools.h"
-
-#include "support/convert.h"
-#include <boost/bind.hpp>
-
-#include "QtView.h"
-#include "QLMenubar.h"
-#include "FontLoader.h"
-#include "QCommandBuffer.h"
-#include "qt_helpers.h"
-
-#include <QApplication>
-#include <QPixmap>
-#include <QStatusBar>
-#include <QToolBar>
-#include <QCloseEvent>
-#include <QAction>
-//#include <QMenu>
-//#include <QMenuBar>
-
-#include "support/lstrings.h"
-
-
-using std::string;
-using std::endl;
-
-FontLoader fontloader;
-
-namespace lyx {
-
-using support::subst;
-using support::libFileSearch;
-
-namespace frontend {
-
-namespace {
-
-int const statusbar_timer_value = 3000;
-
-} // namespace anon
-
-
-QtView::QtView(unsigned int width, unsigned int height)
- : QMainWindow(), LyXView(), commandbuffer_(0), frontend_(*this)
-{
- mainWidget_ = this;
-
-// setToolButtonStyle(Qt::ToolButtonIconOnly);
-// setIconSize(QSize(12,12));
-
- bufferview_.reset(new BufferView(this, width, height));
-
- menubar_.reset(new QLMenubar(this, menubackend));
- connect(menuBar(), SIGNAL(triggered(QAction *)), this,
SLOT(updateMenu(QAction *)));
-
- getToolbars().init();
-
- statusBar()->setSizeGripEnabled(false);
-
- view_state_changed.connect(boost::bind(&QtView::update_view_state,
this));
- connect(&statusbar_timer_, SIGNAL(timeout()), this,
SLOT(update_view_state_qt()));
-
-#ifndef Q_WS_MACX
- // assign an icon to main form. We do not do it under Qt/Mac,
- // since the icon is provided in the application bundle.
- string const iconname = libFileSearch("images", "lyx", "xpm");
- if (!iconname.empty())
- setWindowIcon(QPixmap(toqstr(iconname)));
-#endif
-
- // make sure the buttons are disabled if needed
- updateToolbars();
-}
-
-
-QtView::~QtView()
-{
-}
-
-void QtView::updateMenu(QAction *action)
-{
- menubar_->update();
-}
-
-void QtView::setWindowTitle(string const & t, string const & it)
-{
- QMainWindow::setWindowTitle(toqstr(t));
- QMainWindow::setWindowIconText(toqstr(it));
-}
-
-
-void QtView::addCommandBuffer(QToolBar * toolbar)
-{
- commandbuffer_ = new QCommandBuffer(this, *controlcommand_);
- focus_command_buffer.connect(boost::bind(&QtView::focus_command_widget,
this));
- toolbar->addWidget(commandbuffer_);
-}
-
-
-void QtView::message(string const & str)
-{
- statusBar()->showMessage(toqstr(str));
- statusbar_timer_.stop();
- statusbar_timer_.start(statusbar_timer_value);
-}
-
-
-void QtView::clearMessage()
-{
- update_view_state_qt();
-}
-
-
-void QtView::focus_command_widget()
-{
- if (commandbuffer_)
- commandbuffer_->focus_command();
-}
-
-
-void QtView::update_view_state_qt()
-{
- statusBar()->showMessage(toqstr(getLyXFunc().viewStatusMessage()));
- statusbar_timer_.stop();
-}
-
-
-void QtView::update_view_state()
-{
- // let the user see the explicit message
- if (statusbar_timer_.isActive())
- return;
-
- statusBar()->showMessage(toqstr(getLyXFunc().viewStatusMessage()));
-}
-
-
-void QtView::activated(FuncRequest const & func)
-{
- getLyXFunc().dispatch(func);
-}
-
-
-bool QtView::hasFocus() const
-{
- return qApp->activeWindow() == this;
-}
-
-
-void QtView::closeEvent(QCloseEvent *)
-{
- QRect geometry = normalGeometry();
- Session & session = LyX::ref().session();
- // save windows size and position
- session.saveSessionInfo("WindowWidth",
convert<string>(geometry.width()));
- session.saveSessionInfo("WindowHeight",
convert<string>(geometry.height()));
- session.saveSessionInfo("WindowIsMaximized", (isMaximized() ? "yes" :
"no"));
- if (lyxrc.geometry_xysaved) {
- session.saveSessionInfo("WindowPosX",
convert<string>(geometry.x()));
- session.saveSessionInfo("WindowPosY",
convert<string>(geometry.y()));
- }
- // trigger LFUN_LYX_QUIT instead of quit directly
- // since LFUN_LYX_QUIT may have more cleanup stuff
- getLyXFunc().dispatch(FuncRequest(LFUN_LYX_QUIT));
-}
-
-
-void QtView::show()
-{
- QMainWindow::setWindowTitle(qt_("LyX"));
- QMainWindow::show();
-}
-
-
-void QtView::busy(bool yes) const
-{
- if (yes)
- QApplication::setOverrideCursor(Qt::WaitCursor);
- else
- QApplication::restoreOverrideCursor();
-}
-
-QMainWindow* QtView::mainWidget()
-{
- return mainWidget_;
-}
-
-QMainWindow* QtView::mainWidget_ = 0;
-
-
-} // namespace frontend
-} // namespace lyx
-
-#include "QtView_moc.cpp"
Index: src/frontends/qt4/QtView.h
===================================================================
--- src/frontends/qt4/QtView.h (revision 14138)
+++ src/frontends/qt4/QtView.h (working copy)
@@ -1,120 +0,0 @@
-// -*- C++ -*-
-/**
- * \file QtView.h
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Lars Gullik Bjornes
- * \author John Levon
- * \author Abdelrazak Younes
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#ifndef QTVIEW_H
-#define QTVIEW_H
-
-// Must be here because of moc.
-#include <config.h>
-
-#include "TheGui.h"
-
-#include "frontends/LyXView.h"
-#include "funcrequest.h"
-
-#include <QMainWindow>
-#include <QTimer>
-#include <QAction>
-#include <QCloseEvent>
-
-class QToolBar;
-
-//class FuncRequest;
-
-//class string;
-
-namespace lyx {
-namespace frontend {
-
-class QCommandBuffer;
-
-QWidget* mainWindow();
-
-/**
- * QtView - Qt implementation of LyXView
- *
- * Qt-private implementation of the main LyX window.
- */
-class QtView : public QMainWindow, public LyXView {
- Q_OBJECT
-public:
- /// create a main window of the given dimensions
- QtView(unsigned int w, unsigned int h);
-
- ~QtView();
-
- /// show - display the top-level window
- void show();
-
- /// show busy cursor
- virtual void busy(bool) const;
-
- /// display a status message
- virtual void message(std::string const & str);
-
- /// clear status message
- virtual void clearMessage();
-
- /// add the command buffer
- void addCommandBuffer(QToolBar * toolbar);
-
- /// menu item has been selected
- void activated(FuncRequest const &);
-
- // returns true if this view has the focus.
- virtual bool hasFocus() const;
-
- //
- Gui & gui() { return frontend_; }
-
- static QMainWindow* mainWidget();
-
-public slots:
- /// idle timeout
- void update_view_state_qt();
-
- /// populate a toplevel menu and all its children on demand
- void updateMenu(QAction *);
-
-protected:
- /// make sure we quit cleanly
- virtual void closeEvent(QCloseEvent * e);
-private:
- /// focus the command buffer widget
- void focus_command_widget();
-
- /// update status bar
- void update_view_state();
-
- /**
- * setWindowTitle - set title of window
- * @param t main window title
- * @param it iconified (short) title
- */
- virtual void setWindowTitle(std::string const & t, std::string const &
it);
-
- QTimer statusbar_timer_;
-
- /// command buffer
- QCommandBuffer * commandbuffer_;
-
- ///
- static QMainWindow* mainWidget_;
-
- TheGui frontend_;
-};
-
-} // namespace frontend
-} // namespace lyx
-
-#endif // QTVIEW_H
Index: src/frontends/qt4/TheGui.C
===================================================================
--- src/frontends/qt4/TheGui.C (revision 14138)
+++ src/frontends/qt4/TheGui.C (working copy)
@@ -12,14 +12,14 @@
#include "TheGui.h"
#include "GuiWorkArea.h"
-#include "QtView.h"
+#include "GuiView.h"
using boost::shared_ptr;
namespace lyx {
namespace frontend {
-TheGui::TheGui(QtView & owner): owner_(owner), max_id_(0)
+TheGui::TheGui(): max_view_id_(0), max_wa_id_(0)
{
}
@@ -30,14 +30,38 @@
}
-int TheGui::newWorkArea(int w, int h)
+int TheGui::newView(unsigned int w, unsigned int h)
{
- size_t const id = max_id_;
- ++max_id_;
- work_areas_[id].reset(new GuiWorkArea(owner_, w, h));
+ size_t const id = max_view_id_;
+ ++max_view_id_;
+ views_[id].reset(new GuiView(*this, w, h));
return id;
}
+
+LyXView& TheGui::view(int id)
+{
+ BOOST_ASSERT(views_.find(id) != views_.end());
+
+ return *views_[id].get();
+}
+
+
+void TheGui::destroyView(int id)
+{
+ views_.erase(id);
+}
+
+
+int TheGui::newWorkArea(unsigned int w, unsigned int h, int view_id)
+{
+ size_t const id = max_wa_id_;
+ ++max_wa_id_;
+ work_areas_[id].reset(new GuiWorkArea(*views_[view_id].get(), w, h));
+ return id;
+}
+
+
WorkArea& TheGui::workArea(int id)
{
BOOST_ASSERT(work_areas_.find(id) != work_areas_.end());
Index: src/frontends/qt4/TheGui.h
===================================================================
--- src/frontends/qt4/TheGui.h (revision 14138)
+++ src/frontends/qt4/TheGui.h (working copy)
@@ -20,11 +20,13 @@
#include <map>
+class LyXView;
+
namespace lyx {
namespace frontend {
class GuiWorkArea;
-class QtView;
+class GuiView;
/**
* The TheGui class is the interface to all Qt4 components.
@@ -32,24 +34,31 @@
class TheGui: public Gui
{
public:
- TheGui(QtView & owner);
+ TheGui();
virtual ~TheGui() {}
Clipboard& clipboard();
+ int newView(unsigned int width, unsigned int height);
+ LyXView& view(int id);
+ void destroyView(int id);
+ int newWorkArea(unsigned int width, unsigned int height, int view_id);
int newWorkArea(int w, int h);
WorkArea& workArea(int id);
void destroyWorkArea(int id);
+
private:
///
GuiClipboard clipboard_;
///
+ std::map<int, boost::shared_ptr<GuiView> > views_;
+ ///
std::map<int, boost::shared_ptr<GuiWorkArea> > work_areas_;
///
- QtView & owner_;
+ size_t max_view_id_;
///
- size_t max_id_;
+ size_t max_wa_id_;
};
} // namespace frontend
Index: src/lyx_main.C
===================================================================
--- src/lyx_main.C (revision 14138)
+++ src/lyx_main.C (working copy)
@@ -188,7 +188,7 @@
}
-void LyX::addLyXView(boost::shared_ptr<LyXView> const & lyxview)
+void LyX::addLyXView(LyXView * lyxview)
{
views_.push_back(lyxview);
}
Index: src/lyx_main.h
===================================================================
--- src/lyx_main.h (revision 14138)
+++ src/lyx_main.h (working copy)
@@ -58,7 +58,7 @@
lyx::Session & session();
lyx::Session const & session() const;
- void addLyXView(boost::shared_ptr<LyXView> const & lyxview);
+ void addLyXView(LyXView * lyxview);
/** redraw \c inset in all the BufferViews in which it is currently
* visible. If successful return a pointer to the owning Buffer.
@@ -105,7 +105,7 @@
/// lyx session, containing lastfiles, lastfilepos, and lastopened
boost::scoped_ptr<lyx::Session> session_;
///
- typedef std::list<boost::shared_ptr<LyXView> > ViewList;
+ typedef std::list<LyXView * > ViewList;
ViewList views_;
};