]> git.lyx.org Git - lyx.git/commitdiff
Spoiling some fun from Andre': put Application on a diet and remove unnecessary strin...
authorAbdelrazak Younes <younes@lyx.org>
Sun, 18 Nov 2007 20:36:52 +0000 (20:36 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Sun, 18 Nov 2007 20:36:52 +0000 (20:36 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21665 a592a061-630c-0410-9148-cb99ea01b6c8

src/LyX.cpp
src/LyX.h
src/frontends/Application.h
src/frontends/qt4/GuiAlert.cpp
src/frontends/qt4/GuiApplication.cpp
src/frontends/qt4/GuiApplication.h
src/frontends/qt4/GuiLog.cpp
src/frontends/qt4/GuiPrefs.cpp
src/frontends/qt4/GuiViewSource.cpp
src/frontends/qt4/GuiWorkArea.cpp
src/frontends/qt4/LyXFileDialog.cpp

index b6d1df8d4b59027fe8d10a292490deacd7c09c9f..f90e09ce5bfe8cefbb0f20d34f6c83922f0baeaf 100644 (file)
@@ -430,8 +430,6 @@ int LyX::exec(int & argc, char * argv[])
        // Let the frontend parse and remove all arguments that it knows
        pimpl_->application_.reset(createApplication(argc, argv));
 
-       initGuiFont();
-
        // Parse and remove all known arguments in the LyX singleton
        // Give an error for all remaining ones.
        int exit_status = init(argc, argv);
@@ -792,20 +790,6 @@ void LyX::printError(ErrorItem const & ei)
 }
 
 
-void LyX::initGuiFont()
-{
-       if (lyxrc.roman_font_name.empty())
-               lyxrc.roman_font_name = pimpl_->application_->romanFontName();
-
-       if (lyxrc.sans_font_name.empty())
-               lyxrc.sans_font_name = pimpl_->application_->sansFontName();
-
-       if (lyxrc.typewriter_font_name.empty())
-               lyxrc.typewriter_font_name
-                       = pimpl_->application_->typewriterFontName();
-}
-
-
 bool LyX::init()
 {
 #ifdef SIGHUP
index 25529e55d57fce8879a8bca7e09d8b49cbb97b62..5d0cf3340c696e3e1758163aa9a5e5111002020a 100644 (file)
--- a/src/LyX.h
+++ b/src/LyX.h
@@ -133,9 +133,6 @@ private:
        /// Create a View, load files and restore GUI Session.
        void restoreGuiSession();
 
-       /// Initialize RC font for the GUI.
-       void initGuiFont();
-
        /// initial LyX set up
        bool init();
        /// set up the default dead key bindings if requested
index 30f05c2c65628b1b81c3acca2733fb04a340f411..af275ec348751d2eb06447867eb3284ff700bdfc 100644 (file)
@@ -147,18 +147,16 @@ class Application
 {
 public:
        ///
-       Application() : current_view_(0) {}
+       Application() {}
        ///
        virtual ~Application() {}
 
        ///
        virtual bool closeAllViews() = 0;
-
        ///
        virtual LyXView & view(int id) const = 0;
        ///
        virtual size_t viewCount() const = 0;
-
        ///
        virtual void hideDialogs(std::string const & name, Inset * inset) const = 0;
        ///
@@ -176,22 +174,6 @@ public:
        */
        virtual void exit(int status) = 0;
 
-       /**
-       * Synchronise all pending events.
-       */
-       virtual void syncEvents() = 0;
-       ///
-       virtual FontLoader & fontLoader() = 0;
-
-       /// return a suitable serif font name.
-       virtual std::string const romanFontName() = 0;
-
-       /// return a suitable sans serif font name.
-       virtual std::string const sansFontName() = 0;
-
-       /// return a suitable monospaced font name.
-       virtual std::string const typewriterFontName() = 0;
-
        /**
        * Given col, fills r, g, b in the range 0-255.
        * The function returns true if successful.
@@ -225,18 +207,6 @@ public:
        /// Create the main window with given geometry settings.
        /// \param geometry_arg: only for Windows platform.
        virtual LyXView & createView(std::string const & geometry_arg) = 0;
-
-       ///
-       LyXView const * currentView() const { return current_view_; }
-       ///
-       LyXView * currentView() { return current_view_; }
-       ///
-       void setCurrentView(LyXView & view) { current_view_ = &view; }
-
-protected:
-       /// This LyXView is the one receiving Clipboard and Selection
-       /// events
-       LyXView * current_view_;
 };
 
 } // namespace frontend
index 57806eb1863689ad2baf74d20625d73f5ad7065e..88bdce163064b84329b55ef8216d9124999001a1 100644 (file)
@@ -125,7 +125,7 @@ int prompt(docstring const & title0, docstring const & question,
        // This call has no effect if the cursor has not been overridden.
        qApp->changeOverrideCursor(Qt::ArrowCursor);
 
-       // FIXME replace that with theApp->gui()->currentView()
+       // FIXME replace that with guiApp->currentView()
        int res = QMessageBox::information(qApp->focusWidget(),
                                           toqstr(title),
                                           toqstr(formatted(question)),
index 053acade196c046fa2aee6ab543148a5a379b827..0fad5bc9c1740f6816d60cf6b31bd1a568cf9b5a 100644 (file)
@@ -136,7 +136,7 @@ GuiApplication * guiApp;
 
 
 GuiApplication::GuiApplication(int & argc, char ** argv)
-       : QApplication(argc, argv), Application()
+       : QApplication(argc, argv), Application(), current_view_(0)
 {
        QString app_name = "LyX";
        QCoreApplication::setOrganizationName(app_name);
@@ -194,6 +194,16 @@ GuiApplication::GuiApplication(int & argc, char ** argv)
        // Set the cache to 5120 kilobytes which corresponds to screen size of
        // 1280 by 1024 pixels with a color depth of 32 bits.
        QPixmapCache::setCacheLimit(5120);
+
+       // Initialize RC Fonts
+       if (lyxrc.roman_font_name.empty())
+               lyxrc.roman_font_name = fromqstr(romanFontName());
+
+       if (lyxrc.sans_font_name.empty())
+               lyxrc.sans_font_name = fromqstr(sansFontName());
+
+       if (lyxrc.typewriter_font_name.empty())
+               lyxrc.typewriter_font_name = fromqstr(typewriterFontName());
 }
 
 
@@ -203,9 +213,24 @@ GuiApplication::~GuiApplication()
 }
 
 
+static void updateIds(map<int, GuiView *> const & stdmap, vector<int> & ids)
+{
+       ids.clear();
+       map<int, GuiView *>::const_iterator it;
+       for (it = stdmap.begin(); it != stdmap.end(); ++it)
+               ids.push_back(it->first);
+}
+
+
 LyXView & GuiApplication::createView(string const & geometry_arg)
 {
-       int const id = createRegisteredView();
+       updateIds(views_, view_ids_);
+       int id = 0;
+       while (views_.find(id) != views_.end())
+               id++;
+       views_[id] = new GuiView(id);
+       updateIds(views_, view_ids_);
+
        GuiView * view  = views_[id];
        theLyXFunc().setLyXView(view);
 
@@ -265,36 +290,36 @@ void GuiApplication::execBatchCommands()
 }
 
 
-string const GuiApplication::romanFontName()
+QString const GuiApplication::romanFontName()
 {
        QFont font;
        font.setKerning(false);
        font.setStyleHint(QFont::Serif);
        font.setFamily("serif");
 
-       return fromqstr(QFontInfo(font).family());
+       return QFontInfo(font).family();
 }
 
 
-string const GuiApplication::sansFontName()
+QString const GuiApplication::sansFontName()
 {
        QFont font;
        font.setKerning(false);
        font.setStyleHint(QFont::SansSerif);
        font.setFamily("sans");
 
-       return fromqstr(QFontInfo(font).family());
+       return QFontInfo(font).family();
 }
 
 
-string const GuiApplication::typewriterFontName()
+QString const GuiApplication::typewriterFontName()
 {
        QFont font;
        font.setKerning(false);
        font.setStyleHint(QFont::TypeWriter);
        font.setFamily("monospace");
 
-       return fromqstr(QFontInfo(font).family());
+       return QFontInfo(font).family();
 }
 
 
@@ -305,7 +330,7 @@ bool GuiApplication::event(QEvent * e)
                // Open a file; this happens only on Mac OS X for now
                QFileOpenEvent * foe = static_cast<QFileOpenEvent *>(e);
 
-               if (!currentView() || !currentView()->view())
+               if (!current_view_ || !current_view_->view())
                        // The application is not properly initialized yet.
                        // So we acknowledge the event and delay the file opening
                        // until LyX is ready.
@@ -360,16 +385,6 @@ bool GuiApplication::notify(QObject * receiver, QEvent * event)
 }
 
 
-void GuiApplication::syncEvents()
-{
-       // This is the ONLY place where processEvents may be called.
-       // During screen update/ redraw, this method is disabled to
-       // prevent keyboard events being handed to the LyX core, where
-       // they could cause re-entrant calls to screen update.
-       processEvents(QEventLoop::ExcludeUserInputEvents);
-}
-
-
 bool GuiApplication::getRgbColor(ColorCode col, RGBColor & rgbcol)
 {
        QColor const & qcol = color_cache_.get(col);
@@ -438,27 +453,6 @@ void GuiApplication::addMenuTranslator()
 }
 
 
-static void updateIds(map<int, GuiView *> const & stdmap, vector<int> & ids)
-{
-       ids.clear();
-       map<int, GuiView *>::const_iterator it;
-       for (it = stdmap.begin(); it != stdmap.end(); ++it)
-               ids.push_back(it->first);
-}
-
-
-int GuiApplication::createRegisteredView()
-{
-       updateIds(views_, view_ids_);
-       int id = 0;
-       while (views_.find(id) != views_.end())
-               id++;
-       views_[id] = new GuiView(id);
-       updateIds(views_, view_ids_);
-       return id;
-}
-
-
 bool GuiApplication::unregisterView(int id)
 {
        updateIds(views_, view_ids_);
@@ -537,7 +531,7 @@ Buffer const * GuiApplication::updateInset(Inset const * inset) const
 #ifdef Q_WS_X11
 bool GuiApplication::x11EventFilter(XEvent * xev)
 {
-       if (!currentView())
+       if (!current_view_)
                return false;
 
        switch (xev->type) {
@@ -545,7 +539,7 @@ bool GuiApplication::x11EventFilter(XEvent * xev)
                if (xev->xselectionrequest.selection != XA_PRIMARY)
                        break;
                LYXERR(Debug::GUI, "X requested selection.");
-               BufferView * bv = currentView()->view();
+               BufferView * bv = current_view_->view();
                if (bv) {
                        docstring const sel = bv->requestSelection();
                        if (!sel.empty())
@@ -557,7 +551,7 @@ bool GuiApplication::x11EventFilter(XEvent * xev)
                if (xev->xselectionclear.selection != XA_PRIMARY)
                        break;
                LYXERR(Debug::GUI, "Lost selection.");
-               BufferView * bv = currentView()->view();
+               BufferView * bv = current_view_->view();
                if (bv)
                        bv->clearSelection();
                break;
@@ -583,8 +577,8 @@ frontend::FontLoader & theFontLoader()
        if (!use_gui)
                return no_gui_font_loader;
 
-       BOOST_ASSERT(theApp());
-       return theApp()->fontLoader();
+       BOOST_ASSERT(frontend::guiApp);
+       return frontend::guiApp->fontLoader();
 }
 
 
@@ -601,8 +595,8 @@ frontend::FontMetrics const & theFontMetrics(FontInfo const & f)
        if (!use_gui)
                return no_gui_font_metrics;
 
-       BOOST_ASSERT(theApp());
-       return theApp()->fontLoader().metrics(f);
+       BOOST_ASSERT(frontend::guiApp);
+       return frontend::guiApp->fontLoader().metrics(f);
 }
 
 
index 4496a01be8779f1a776a79c14bbbc3e880f2fdc1..7b51eb4777d22ff7388979bfe8eb1c23687b0894 100644 (file)
@@ -62,10 +62,6 @@ public:
        virtual int exec();
        virtual void exit(int status);
        virtual bool event(QEvent * e);
-       void syncEvents();
-       virtual std::string const romanFontName();
-       virtual std::string const sansFontName();
-       virtual std::string const typewriterFontName();
        virtual bool getRgbColor(ColorCode col, RGBColor & rgbcol);
        virtual std::string const hexName(ColorCode col);
        virtual void updateColor(ColorCode col);
@@ -80,7 +76,15 @@ public:
        void commitData(QSessionManager & sm);
        //@}
 
+       ///
+       GuiView const * currentView() const { return current_view_; }
+       ///
+       GuiView * currentView() { return current_view_; }
+       ///
+       void setCurrentView(GuiView & view) { current_view_ = &view; }
+       ///
        virtual size_t viewCount() const { return view_ids_.size(); }
+       ///
        std::vector<int> const & viewIds() { return view_ids_; }
 
        ///
@@ -88,11 +92,19 @@ public:
        ///
        GuiFontLoader & guiFontLoader() { return font_loader_; }
 
+       /// return a suitable serif font name.
+       virtual QString const romanFontName();
 
-       virtual int createRegisteredView();
+       /// return a suitable sans serif font name.
+       virtual QString const sansFontName();
+
+       /// return a suitable monospaced font name.
+       virtual QString const typewriterFontName();
+       ///
        virtual bool closeAllViews();
+       ///
        virtual bool unregisterView(int id);
-
+       ///
        virtual LyXView & view(int id) const;
        ///
        virtual void hideDialogs(std::string const & name, Inset * inset) const;
@@ -136,6 +148,9 @@ public:
        std::map<int, GuiView *> views_;
        ///
        std::vector<int> view_ids_;
+       /// This LyXView is the one receiving Clipboard and Selection
+       /// events
+       GuiView * current_view_;
 }; // GuiApplication
 
 extern GuiApplication * guiApp;
index a1d97c4d1996a9023d2fd825fa7c9832450c2d76..438ecb6099dd8807ae963a39b82c94215dab0027 100644 (file)
 
 #include "GuiLog.h"
 
+#include "GuiApplication.h"
 #include "qt_helpers.h"
 #include "gettext.h"
 #include "Lexer.h"
 
-#include "frontends/Application.h"
-
 #include <QCloseEvent>
 #include <QTextBrowser>
 #include <QSyntaxHighlighter>
@@ -117,7 +116,7 @@ GuiLog::GuiLog(LyXView & lv)
        highlighter = new LogHighlighter(logTB->document());
 
        logTB->setReadOnly(true);
-       QFont font(toqstr(theApp()->typewriterFontName()));
+       QFont font(guiApp->typewriterFontName());
        font.setKerning(false);
        font.setFixedPitch(true);
        font.setStyleHint(QFont::TypeWriter);
index 5ac9daf24b5add0f86d7711aa1cba459517aa50a..6c6fb64b24524d3bd68cee20d812fa31d2d532aa 100644 (file)
@@ -161,15 +161,16 @@ static void setComboxFont(QComboBox * cb, string const & family,
        QFont font;
        font.setKerning(false);
 
-       if (family == theApp()->romanFontName()) {
+       QString const font_family = toqstr(family);
+       if (font_family == guiApp->romanFontName()) {
                font.setStyleHint(QFont::Serif);
-               font.setFamily(family.c_str());
-       } else if (family == theApp()->sansFontName()) {
+               font.setFamily(font_family);
+       } else if (font_family == guiApp->sansFontName()) {
                font.setStyleHint(QFont::SansSerif);
-               font.setFamily(family.c_str());
-       } else if (family == theApp()->typewriterFontName()) {
+               font.setFamily(font_family);
+       } else if (font_family == guiApp->typewriterFontName()) {
                font.setStyleHint(QFont::TypeWriter);
-               font.setFamily(family.c_str());
+               font.setFamily(font_family);
        } else {
                lyxerr << "FAILED to find the default font: '"
                       << foundry << "', '" << family << '\''<< endl;
index e6927e42a572ff6321832a84254e9a77b533f1d1..a5d776d3762a959406d93f0c7ae7fd3d8a3144c5 100644 (file)
 
 #include <config.h>
 
+#include "GuiApplication.h"
 #include "GuiViewSource.h"
 #include "LaTeXHighlighter.h"
 #include "qt_helpers.h"
 
-#include "Application.h"
 #include "BufferView.h"
 #include "Buffer.h"
 #include "Cursor.h"
@@ -57,7 +57,7 @@ ViewSourceWidget::ViewSourceWidget(GuiViewSource & controller)
        viewSourceTV->setReadOnly(true);
        ///dialog_->viewSourceTV->setAcceptRichText(false);
        // this is personal. I think source code should be in fixed-size font
-       QFont font(toqstr(theApp()->typewriterFontName()));
+       QFont font(guiApp->typewriterFontName());
        font.setKerning(false);
        font.setFixedPitch(true);
        font.setStyleHint(QFont::TypeWriter);
index 73e2dac0adb443170109b32aebd04610e9840ade..b2f86248f11e28c721e5235c7dcc3e8f21358ece 100644 (file)
@@ -304,7 +304,7 @@ void GuiWorkArea::redraw()
 
        // No need to do anything if this is the current view. The BufferView
        // metrics are already up to date.
-       if (lyx_view_ != theApp()->currentView()) {
+       if (lyx_view_ != guiApp->currentView()) {
                // FIXME: it would be nice to optimize for the off-screen case.
                buffer_view_->updateMetrics();
                buffer_view_->cursor().fixIfBroken();
index 55734676ff9b6026a049b9cfa4b789780a2b2e0b..96a05ea96cf4371f85fdec9a16673da98cdf0a41 100644 (file)
@@ -48,7 +48,7 @@ LyXFileDialog::LyXFileDialog(docstring const & t,
                             support::FileFilterList const & filters,
                             FileDialog::Button const & b1,
                             FileDialog::Button const & b2)
-                                // FIXME replace that with theApp->gui()->currentView()
+                                // FIXME replace that with guiApp->currentView()
        : QFileDialog(qApp->focusWidget(),
                      toqstr(t), toqstr(p), toqstr(filters.as_string()))
 {