/**
- * \file qt2/lyx_gui.C
+ * \file qt4/lyx_gui.C
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author unknown
* \author John Levon
+ * \author Abdelrazak Younes
*
* Full author contact details are available in file CREDITS.
*/
+#undef QT3_SUPPORT
+
#include <config.h>
#include "lyx_gui.h"
#include "lyxrc.h"
#include "lyxserver.h"
#include "lyxsocket.h"
-#include "session.h"
#include "graphics/LoaderQueue.h"
#include "support/lstrings.h"
-#include "support/convert.h"
#include "support/os.h"
#include "support/package.h"
#include "debug.h"
-// Dear Lord, deliver us from Evil, aka the Qt headers
-// Qt defines a macro 'signals' that clashes with a boost namespace.
-// All is well if the namespace is visible first.
-#include <boost/signal.hpp> // FIXME: Is this needed? (Lgb)
#include <boost/bind.hpp>
#include <boost/shared_ptr.hpp>
-#include "QtView.h"
-#include "lcolorcache.h"
-#include "qfont_loader.h"
+#include "GuiView.h"
+#include "ColorCache.h"
+#include "FontLoader.h"
#include "QLImage.h"
#include "qt_helpers.h"
#include "socket_callback.h"
-
-#ifdef Q_WS_MACX
-#include <Carbon/Carbon.h>
-#endif
+#include "Application.h"
#include <QApplication>
#include <QEventLoop>
#include <QTranslator>
#include <QTextCodec>
+#include <QLocale>
+#include <QLibraryInfo>
+
+
using lyx::support::ltrim;
using lyx::support::package;
-using lyx::frontend::QtView;
+using lyx::frontend::GuiView;
+using lyx::frontend::Application;
namespace os = lyx::support::os;
using std::vector;
using std::string;
-
-extern BufferList bufferlist;
+// FIXME: wrong place !
+LyXServer * lyxserver;
+LyXServerSocket * lyxsocket;
namespace {
map<int, shared_ptr<socket_callback> > socket_callbacks;
-} // namespace anon
-
-// FIXME: wrong place !
-LyXServer * lyxserver;
-LyXServerSocket * lyxsocket;
-
-// in QLyXKeySym.C
-extern void initEncodings();
-
-#ifdef Q_WS_X11
-extern bool lyxX11EventFilter(XEvent * xev);
-#endif
-
-#ifdef Q_WS_MACX
-extern bool macEventFilter(EventRef event);
-extern pascal OSErr
-handleOpenDocuments(const AppleEvent* inEvent, AppleEvent* /*reply*/,
- long /*refCon*/);
-#endif
-
-class LQApplication : public QApplication
-{
-public:
- LQApplication(int & argc, char ** argv);
- ~LQApplication();
-#ifdef Q_WS_X11
- bool x11EventFilter (XEvent * ev) { return lyxX11EventFilter(ev); }
-#endif
-#ifdef Q_WS_MACX
- bool macEventFilter(EventRef event);
-#endif
-};
-
-
-LQApplication::LQApplication(int & argc, char ** argv)
- : QApplication(argc, argv)
+void cleanup()
{
-#ifdef Q_WS_MACX
- AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments,
- NewAEEventHandlerUPP(handleOpenDocuments),
- 0, false);
-#endif
+ delete lyxsocket;
+ lyxsocket = 0;
+ delete lyxserver;
+ lyxserver = 0;
}
+} // namespace anon
-LQApplication::~LQApplication()
-{}
-
-
-#ifdef Q_WS_MACX
-bool LQApplication::macEventFilter(EventRef event)
-{
- if (GetEventClass(event) == kEventClassAppleEvent) {
- EventRecord eventrec;
- ConvertEventRefToEventRecord(event, &eventrec);
- AEProcessAppleEvent(&eventrec);
-
- return false;
- }
- return false;
-}
-#endif
-
+// in QLyXKeySym.C
+extern void initEncodings();
namespace lyx_gui {
bool use_gui = true;
-void parse_init(int & argc, char * argv[])
-{
+void exec(int & argc, char * argv[])
+{
+ /*
+ FIXME : Abdel 29/05/2006 (younes.a@free.fr)
+ reorganize this code. In particular make sure that this
+ advice from Qt documentation is respected:
+
+ Since the QApplication object does so much initialization, it
+ must be created before any other objects related to the user
+ interface are created.
+
+ Right now this is not the case, I suspect that a number of global variables
+ contains Qt object that are initialized before the passage through
+ parse_init(). This might also explain the message displayed by Qt
+ that caused the hanging:
+
+ QObject::killTimer: timers cannot be stopped from another thread
+ */
+
// Force adding of font path _before_ QApplication is initialized
FontLoader::initFontPath();
- static LQApplication app(argc, argv);
+#ifdef Q_WS_WIN
+ static Application app(argc, argv);
+#else
+ Application app(argc, argv);
+#endif
+
// install translation file for Qt built-in dialogs
// These are only installed since Qt 3.2.x
- static QTranslator qt_trans(0);
- if (qt_trans.load(QString("qt_") + QTextCodec::locale(),
- qInstallPathTranslations())) {
- app.installTranslator(&qt_trans);
+ QTranslator qt_trans;
+ QString language_name = QString("qt_") + QLocale::system().name();
+ language_name.truncate(5);
+ if (qt_trans.load(language_name,
+ QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
+ {
+ qApp->installTranslator(&qt_trans);
// even if the language calls for RtL, don't do that
- app.setReverseLayout(false);
+ qApp->setLayoutDirection(Qt::LeftToRight);
lyxerr[Debug::GUI]
<< "Successfully installed Qt translations for locale "
- << QTextCodec::locale() << std::endl;
+ << fromqstr(language_name) << std::endl;
} else
lyxerr[Debug::GUI]
<< "Could not find Qt translations for locale "
- << QTextCodec::locale() << std::endl;
+ << fromqstr(language_name) << std::endl;
/*#ifdef Q_WS_MACX
// These translations are meant to break Qt/Mac menu merging
// algorithm on some entries. It lists the menu names that
// should not be moved to the LyX menu
- static QTranslator aqua_trans(0);
+ QTranslator aqua_trans(0);
aqua_trans.insert(QTranslatorMessage("QMenuBar", "Setting", 0,
"do_not_merge_me"));
aqua_trans.insert(QTranslatorMessage("QMenuBar", "Config", 0,
aqua_trans.insert(QTranslatorMessage("QMenuBar", "Setup", 0,
"do_not_merge_me"));
- app.installTranslator(&aqua_trans);
+ qApp->installTranslator(&aqua_trans);
#endif
*/
using namespace lyx::graphics;
lyxrc.dpi = getDPI();
LoaderQueue::setPriority(10,100);
+
+ LyX::ref().exec2(argc, argv);
}
{}
-void start(string const & batch, vector<string> const & files)
+void start(string const & batch, vector<string> const & files,
+ unsigned int width, unsigned int height, int posx, int posy, bool maximize)
{
// this can't be done before because it needs the Languages object
initEncodings();
- // initial geometry
- unsigned int width = 690;
- unsigned int height = 510;
- // first try lyxrc
- if (lyxrc.geometry_width != 0 && lyxrc.geometry_height != 0 ) {
- width = lyxrc.geometry_width;
- height = lyxrc.geometry_height;
- }
- // if lyxrc returns (0,0), then use session info
- else {
- string val = LyX::ref().session().loadSessionInfo("WindowWidth");
- if (val != "")
- width = convert<unsigned int>(val);
- val = LyX::ref().session().loadSessionInfo("WindowHeight");
- if (val != "")
- height = convert<unsigned int>(val);
- }
+ boost::shared_ptr<GuiView> view_ptr(new GuiView);
- boost::shared_ptr<QtView> view_ptr(new QtView(width, height));
LyX::ref().addLyXView(view_ptr);
- QtView & view = *view_ptr.get();
-
- // if user wants to restore window position
- if (lyxrc.geometry_xysaved) {
- QPoint p = view.pos();
- string val = LyX::ref().session().loadSessionInfo("WindowPosX");
- if (val != "")
- p.setX(convert<unsigned int>(val));
- val = LyX::ref().session().loadSessionInfo("WindowPosY");
- if (val != "")
- p.setY(convert<unsigned int>(val));
- view.move(p);
+ GuiView & view = *view_ptr.get();
+
+ view.init();
+
+ // only true when the -geometry option was NOT used
+ if (width != -1 && height != -1) {
+ if (posx != -1 && posy != -1) {
+#ifdef Q_OS_WIN32
+ // FIXME: use only setGeoemtry when Trolltech has
+ // fixed the qt4/X11 bug
+ view.setGeometry(posx, posy,width, height);
+#else
+ view.resize(width, height);
+ view.move(posx, posy);
+#endif
+ } else {
+ view.resize(width, height);
+ }
+
+ if (maximize)
+ view.setWindowState(Qt::WindowMaximized);
}
+
view.show();
- view.init();
// FIXME: some code below needs moving
qApp->exec();
// FIXME
- delete lyxsocket;
- delete lyxserver;
- lyxserver = 0;
+ cleanup();
}
// 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.
-#if QT_VERSION >= 0x030100
- qApp->processEvents(QEventLoop::ExcludeUserInput);
-#endif
+ qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
}
-void exit()
+void exit(int status)
{
- delete lyxsocket;
- delete lyxserver;
- lyxserver = 0;
+ cleanup();
- // we cannot call qApp->exit(0) - that could return us
+ // we cannot call QApplication::exit(status) - that could return us
// into a static dialog return in the lyx code (for example,
// load autosave file QMessageBox. We have to just get the hell
// out.
- ::exit(0);
+ ::exit(status);
}