diff --git a/src/LyX.cpp b/src/LyX.cpp index b6d1df8d4b..f90e09ce5b 100644 --- a/src/LyX.cpp +++ b/src/LyX.cpp @@ -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 diff --git a/src/LyX.h b/src/LyX.h index 25529e55d5..5d0cf3340c 100644 --- 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 diff --git a/src/frontends/Application.h b/src/frontends/Application.h index 30f05c2c65..af275ec348 100644 --- a/src/frontends/Application.h +++ b/src/frontends/Application.h @@ -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 diff --git a/src/frontends/qt4/GuiAlert.cpp b/src/frontends/qt4/GuiAlert.cpp index 57806eb186..88bdce1630 100644 --- a/src/frontends/qt4/GuiAlert.cpp +++ b/src/frontends/qt4/GuiAlert.cpp @@ -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)), diff --git a/src/frontends/qt4/GuiApplication.cpp b/src/frontends/qt4/GuiApplication.cpp index 053acade19..0fad5bc9c1 100644 --- a/src/frontends/qt4/GuiApplication.cpp +++ b/src/frontends/qt4/GuiApplication.cpp @@ -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 const & stdmap, vector & ids) +{ + ids.clear(); + map::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(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 const & stdmap, vector & ids) -{ - ids.clear(); - map::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); } diff --git a/src/frontends/qt4/GuiApplication.h b/src/frontends/qt4/GuiApplication.h index 4496a01be8..7b51eb4777 100644 --- a/src/frontends/qt4/GuiApplication.h +++ b/src/frontends/qt4/GuiApplication.h @@ -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 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 views_; /// std::vector view_ids_; + /// This LyXView is the one receiving Clipboard and Selection + /// events + GuiView * current_view_; }; // GuiApplication extern GuiApplication * guiApp; diff --git a/src/frontends/qt4/GuiLog.cpp b/src/frontends/qt4/GuiLog.cpp index a1d97c4d19..438ecb6099 100644 --- a/src/frontends/qt4/GuiLog.cpp +++ b/src/frontends/qt4/GuiLog.cpp @@ -13,12 +13,11 @@ #include "GuiLog.h" +#include "GuiApplication.h" #include "qt_helpers.h" #include "gettext.h" #include "Lexer.h" -#include "frontends/Application.h" - #include #include #include @@ -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); diff --git a/src/frontends/qt4/GuiPrefs.cpp b/src/frontends/qt4/GuiPrefs.cpp index 5ac9daf24b..6c6fb64b24 100644 --- a/src/frontends/qt4/GuiPrefs.cpp +++ b/src/frontends/qt4/GuiPrefs.cpp @@ -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; diff --git a/src/frontends/qt4/GuiViewSource.cpp b/src/frontends/qt4/GuiViewSource.cpp index e6927e42a5..a5d776d376 100644 --- a/src/frontends/qt4/GuiViewSource.cpp +++ b/src/frontends/qt4/GuiViewSource.cpp @@ -12,11 +12,11 @@ #include +#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); diff --git a/src/frontends/qt4/GuiWorkArea.cpp b/src/frontends/qt4/GuiWorkArea.cpp index 73e2dac0ad..b2f86248f1 100644 --- a/src/frontends/qt4/GuiWorkArea.cpp +++ b/src/frontends/qt4/GuiWorkArea.cpp @@ -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(); diff --git a/src/frontends/qt4/LyXFileDialog.cpp b/src/frontends/qt4/LyXFileDialog.cpp index 55734676ff..96a05ea96c 100644 --- a/src/frontends/qt4/LyXFileDialog.cpp +++ b/src/frontends/qt4/LyXFileDialog.cpp @@ -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())) {