diff --git a/development/qmake/qt4/qt4.pro b/development/qmake/qt4/qt4.pro index 649aa6c768..8766ca7164 100644 --- a/development/qmake/qt4/qt4.pro +++ b/development/qmake/qt4/qt4.pro @@ -88,7 +88,7 @@ HPP += PanelStack.h HPP += pch.h HPP += qlkey.h HPP += qt_helpers.h -HPP += socket_callback.h +HPP += SocketCallback.h HPP += TocModel.h HPP += TocWidget.h HPP += Validator.h @@ -168,7 +168,7 @@ CPP += LengthCombo.cpp CPP += LyXFileDialog.cpp CPP += PanelStack.cpp CPP += qt_helpers.cpp -CPP += socket_callback.cpp +CPP += SocketCallback.cpp CPP += TocModel.cpp CPP += TocWidget.cpp CPP += Validator.cpp diff --git a/development/scons/scons_manifest.py b/development/scons/scons_manifest.py index 4a9e52335b..d27ce53a23 100644 --- a/development/scons/scons_manifest.py +++ b/development/scons/scons_manifest.py @@ -913,7 +913,7 @@ src_frontends_qt4_header_files = Split(''' Validator.h qlkey.h qt_helpers.h - socket_callback.h + SocketCallback.h ''') @@ -997,7 +997,7 @@ src_frontends_qt4_files = Split(''' Validator.cpp alert_pimpl.cpp qt_helpers.cpp - socket_callback.cpp + SocketCallback.cpp ''') diff --git a/src/frontends/Application.h b/src/frontends/Application.h index cb8526cd08..3907669f07 100644 --- a/src/frontends/Application.h +++ b/src/frontends/Application.h @@ -153,7 +153,7 @@ public: /// Start the main event loop. /// The batch command is programmed to be execute once /// the event loop is started. - virtual int const exec() = 0; + virtual int exec() = 0; /// Quit running LyX. /** diff --git a/src/frontends/qt4/GuiApplication.cpp b/src/frontends/qt4/GuiApplication.cpp index fa3a2bb549..a65f1d0a33 100644 --- a/src/frontends/qt4/GuiApplication.cpp +++ b/src/frontends/qt4/GuiApplication.cpp @@ -16,7 +16,7 @@ #include "qt_helpers.h" #include "GuiImage.h" -#include "socket_callback.h" +#include "SocketCallback.h" #include "frontends/LyXView.h" @@ -62,26 +62,9 @@ using std::string; using std::endl; -/////////////////////////////////////////////////////////////// -// You can find other X11 specific stuff -// at the end of this file... -/////////////////////////////////////////////////////////////// - -namespace { - -int getDPI() -{ - QWidget w; - return int(0.5 * (w.logicalDpiX() + w.logicalDpiY())); -} - -} // namespace anon - namespace lyx { -using support::FileName; - frontend::Application * createApplication(int & argc, char * argv[]) { return new frontend::GuiApplication(argc, argv); @@ -90,17 +73,39 @@ frontend::Application * createApplication(int & argc, char * argv[]) namespace frontend { +//////////////////////////////////////////////////////////////////////// +// Mac specific stuff goes here... + +class MenuTranslator : public QTranslator +{ +public: + QString translate(const char * /*context*/, + const char * sourceText, + const char * /*comment*/ = 0) + { + string const s = sourceText; + if (s == N_("About %1") || s == N_("Preferences") + || s == N_("Reconfigure") || s == N_("Quit %1")) + return qt_(s); + else + return QString(); + } +}; + + +/////////////////////////////////////////////////////////////// +// You can find more platform specific stuff +// at the end of this file... +/////////////////////////////////////////////////////////////// + + +using support::FileName; + GuiApplication * guiApp; -GuiApplication::~GuiApplication() -{ - socket_callbacks_.clear(); -} - - GuiApplication::GuiApplication(int & argc, char ** argv) - : QApplication(argc, argv), Application(argc, argv) + : QApplication(argc, argv), Application(argc, argv), menu_trans_(0) { // Qt bug? setQuitOnLastWindowClosed(true); does not work setQuitOnLastWindowClosed(false); @@ -145,7 +150,8 @@ GuiApplication::GuiApplication(int & argc, char ** argv) Image::loadableFormats = boost::bind(&GuiImage::loadableFormats); // needs to be done before reading lyxrc - lyxrc.dpi = getDPI(); + QWidget w; + lyxrc.dpi = (w.logicalDpiX() + w.logicalDpiY()) / 2; LoaderQueue::setPriority(10,100); @@ -157,19 +163,26 @@ GuiApplication::GuiApplication(int & argc, char ** argv) } -Clipboard& GuiApplication::clipboard() +GuiApplication::~GuiApplication() +{ + delete menu_trans_; + socket_callbacks_.clear(); +} + + +Clipboard & GuiApplication::clipboard() { return clipboard_; } -Selection& GuiApplication::selection() +Selection & GuiApplication::selection() { return selection_; } -int const GuiApplication::exec() +int GuiApplication::exec() { QTimer::singleShot(1, this, SLOT(execBatchCommands())); return QApplication::exec(); @@ -297,7 +310,7 @@ bool GuiApplication::getRgbColor(Color_color col, string const GuiApplication::hexName(Color_color col) { - return lyx::support::ltrim(fromqstr(color_cache_.get(col).name()), "#"); + return support::ltrim(fromqstr(color_cache_.get(col).name()), "#"); } @@ -310,8 +323,7 @@ void GuiApplication::updateColor(Color_color) void GuiApplication::registerSocketCallback(int fd, boost::function func) { - socket_callbacks_[fd] = - boost::shared_ptr(new socket_callback(fd, func)); + socket_callbacks_[fd] = new SocketCallback(this, fd, func); } @@ -369,36 +381,10 @@ bool GuiApplication::x11EventFilter(XEvent * xev) } #endif - -//////////////////////////////////////////////////////////////////////// -// Mac specific stuff goes here... - -class MenuTranslator : public QTranslator { -public: - virtual ~MenuTranslator() {}; - virtual QString translate(const char * context, - const char * sourceText, - const char * comment = 0) const; -}; - - -QString MenuTranslator::translate(const char * /*context*/, - const char * sourceText, - const char *) const -{ - string const s = sourceText; - if (s == N_("About %1") || s == N_("Preferences") - || s == N_("Reconfigure") || s == N_("Quit %1")) - return qt_(s); - else - return QString(); -} - - void GuiApplication::addMenuTranslator() { - menu_trans_.reset(new MenuTranslator()); - installTranslator(menu_trans_.get()); + menu_trans_ = new MenuTranslator(); + installTranslator(menu_trans_); } diff --git a/src/frontends/qt4/GuiApplication.h b/src/frontends/qt4/GuiApplication.h index 46a50b45f4..17dfd1a3b5 100644 --- a/src/frontends/qt4/GuiApplication.h +++ b/src/frontends/qt4/GuiApplication.h @@ -21,8 +21,6 @@ #include "frontends/Application.h" -#include - #include #include @@ -31,7 +29,7 @@ class QSessionManager; namespace lyx { class BufferView; -class socket_callback; +class SocketCallback; namespace frontend { @@ -60,7 +58,7 @@ public: virtual Clipboard & clipboard(); virtual Selection & selection(); virtual FontLoader & fontLoader() { return font_loader_; } - virtual int const exec(); + virtual int exec(); virtual Gui & gui() { return gui_; } virtual void exit(int status); virtual bool event(QEvent * e); @@ -106,18 +104,18 @@ private: /// QTranslator qt_trans_; /// - std::map > socket_callbacks_; + std::map socket_callbacks_; #ifdef Q_WS_X11 public: - bool x11EventFilter (XEvent * ev); + bool x11EventFilter(XEvent * ev); #endif /// A translator suitable for the entries in the LyX menu. /// Only needed with Qt/Mac. void addMenuTranslator(); /// - boost::scoped_ptr menu_trans_; + MenuTranslator * menu_trans_; }; // GuiApplication extern GuiApplication * guiApp; diff --git a/src/frontends/qt4/Makefile.am b/src/frontends/qt4/Makefile.am index 63c97c5b17..60e2802bdb 100644 --- a/src/frontends/qt4/Makefile.am +++ b/src/frontends/qt4/Makefile.am @@ -111,7 +111,7 @@ SOURCEFILES = \ LyXFileDialog.cpp \ PanelStack.cpp \ qt_helpers.cpp \ - socket_callback.cpp \ + SocketCallback.cpp \ TocModel.cpp \ TocWidget.cpp \ Validator.cpp @@ -194,7 +194,7 @@ MOCHEADER = \ LyXFileDialog.h \ PanelStack.h \ qlkey.h \ - socket_callback.h \ + SocketCallback.h \ TocModel.h \ TocWidget.h \ Validator.h diff --git a/src/frontends/qt4/socket_callback.cpp b/src/frontends/qt4/SocketCallback.cpp similarity index 50% rename from src/frontends/qt4/socket_callback.cpp rename to src/frontends/qt4/SocketCallback.cpp index d3ae2983b5..83971edd8c 100644 --- a/src/frontends/qt4/socket_callback.cpp +++ b/src/frontends/qt4/SocketCallback.cpp @@ -12,24 +12,25 @@ #include -#include "socket_callback.h" +#include "SocketCallback.h" namespace lyx { -socket_callback::socket_callback(int fd, boost::function func) - : func_(func) +SocketCallback::SocketCallback(QObject * parent, + int fd, boost::function func) + : QObject(parent), func_(func) { - sn_.reset(new QSocketNotifier(fd, QSocketNotifier::Read, this)); - connect(sn_.get(), SIGNAL(activated(int)), this, SLOT(data_received())); + sn_ = new QSocketNotifier(fd, QSocketNotifier::Read, this); + connect(sn_, SIGNAL(activated(int)), this, SLOT(dataReceived())); } -void socket_callback::data_received() +void SocketCallback::dataReceived() { func_(); } } // namespace lyx -#include "socket_callback_moc.cpp" +#include "SocketCallback_moc.cpp" diff --git a/src/frontends/qt4/socket_callback.h b/src/frontends/qt4/SocketCallback.h similarity index 80% rename from src/frontends/qt4/socket_callback.h rename to src/frontends/qt4/SocketCallback.h index 7c5b69460a..1c6b4633e3 100644 --- a/src/frontends/qt4/socket_callback.h +++ b/src/frontends/qt4/SocketCallback.h @@ -14,17 +14,14 @@ #ifndef SOCKET_CALLBACK_H #define SOCKET_CALLBACK_H - #include #include -#include #include namespace lyx { - /** * socket_callback - a simple wrapper for asynchronous socket notification * @@ -33,16 +30,21 @@ namespace lyx { * * FIXME: this code apparently will not work on Windows. */ -class socket_callback : public QObject { + +class SocketCallback : public QObject +{ Q_OBJECT + public: /// connect a connection notification from the LyXServerSocket - socket_callback(int fd, boost::function func); + SocketCallback(QObject * parent, int fd, boost::function func); + public Q_SLOTS: - void data_received(); + void dataReceived(); + private: - /// our notifier - boost::scoped_ptr sn_; + /// Our notifier + QSocketNotifier * sn_; /// The callback function boost::function func_; };