3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS.
15 #include "support/lstrings.h"
16 #include "qt_helpers.h"
19 #include "funcrequest.h"
20 #include "graphics/LoaderQueue.h"
22 // FIXME: move this stuff out again
23 #include "bufferlist.h"
24 #include "LyXAction.h"
27 #include "lyxserver.h"
28 #include "BufferView.h"
31 // Dear Lord, deliver us from Evil,
33 #include <boost/signals/signal1.hpp>
34 #include <boost/bind.hpp>
38 #include "qfont_loader.h"
39 #include "io_callback.h"
40 #include "lcolorcache.h"
42 #include <qapplication.h>
43 #include <qpaintdevicemetrics.h>
45 using lyx::support::ltrim;
47 #ifndef CXX_GLOBAL_CSTD
56 extern BufferList bufferlist;
63 QPaintDeviceMetrics pdm(&w);
64 return 0.5 * (pdm.logicalDpiX() + pdm.logicalDpiY());
67 map<int, io_callback *> io_callbacks;
71 // FIXME: wrong place !
72 LyXServer * lyxserver;
75 extern void initEncodings();
78 extern bool lyxX11EventFilter(XEvent * xev);
82 class LQApplication : public QApplication
85 LQApplication(int & argc, char ** argv);
88 bool x11EventFilter (XEvent * ev) { return lyxX11EventFilter(ev); }
93 LQApplication::LQApplication(int & argc, char ** argv)
94 : QApplication(argc, argv)
98 LQApplication::~LQApplication()
106 void parse_init(int & argc, char * argv[])
108 static LQApplication a(argc, argv);
110 using namespace lyx::graphics;
112 Image::newImage = boost::bind(&QLImage::newImage);
113 Image::loadableFormats = boost::bind(&QLImage::loadableFormats);
115 // needs to be done before reading lyxrc
116 lyxrc.dpi = getDPI();
120 LoaderQueue::setPriority(10,100);
128 void start(string const & batch, vector<string> const & files)
131 unsigned int width = 690;
132 unsigned int height = 510;
134 QtView view(width, height);
138 // FIXME: some code below needs moving
140 lyxserver = new LyXServer(&view.getLyXFunc(), lyxrc.lyxpipes);
142 vector<string>::const_iterator cit = files.begin();
143 vector<string>::const_iterator end = files.end();
144 for (; cit != end; ++cit)
145 view.view()->loadLyXFile(*cit, true);
147 // handle the batch commands the user asked for
148 if (!batch.empty()) {
149 view.getLyXFunc().dispatch(lyxaction.lookupFunc(batch));
162 qApp->processEvents();
171 // we cannot call qApp->exit(0) - that could return us
172 // into a static dialog return in the lyx code (for example,
173 // load autosave file QMessageBox. We have to just get the hell
180 FuncStatus getStatus(FuncRequest const & ev)
184 case LFUN_DIALOG_SHOW:
185 if (ev.argument == "preamble" || ev.argument == "forks")
188 case LFUN_TOOLTIPS_TOGGLE:
198 string const hexname(LColor_color col)
200 return ltrim(fromqstr(lcolorcache.get(col).name()), "#");
204 void update_color(LColor_color)
206 // FIXME: Bleh, can't we just clear them all at once ?
217 bool font_available(LyXFont const & font)
219 return fontloader.available(font);
223 void set_read_callback(int fd, LyXComm * comm)
225 io_callbacks[fd] = new io_callback(fd, comm);
229 void remove_read_callback(int fd)
231 map<int, io_callback *>::iterator it = io_callbacks.find(fd);
232 if (it != io_callbacks.end()) {
234 io_callbacks.erase(it);
239 string const roman_font_name()
245 font.setStyleHint(QFont::Serif);
246 font.setFamily("serif");
247 return QFontInfo(font).family().latin1();
251 string const sans_font_name()
257 font.setStyleHint(QFont::SansSerif);
258 font.setFamily("sans");
259 return QFontInfo(font).family().latin1();
263 string const typewriter_font_name()
269 font.setStyleHint(QFont::TypeWriter);
270 font.setFamily("monospace");
271 return QFontInfo(font).family().latin1();
274 }; // namespace lyx_gui