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"
26 #include "lyxserver.h"
27 #include "BufferView.h"
30 // Dear Lord, deliver us from Evil,
32 #include <boost/signals/signal1.hpp>
33 #include <boost/bind.hpp>
37 #include "qfont_loader.h"
38 #include "io_callback.h"
39 #include "lcolorcache.h"
41 #include <qapplication.h>
42 #include <qpaintdevicemetrics.h>
44 using lyx::support::ltrim;
46 #ifndef CXX_GLOBAL_CSTD
54 extern BufferList bufferlist;
61 QPaintDeviceMetrics pdm(&w);
62 return 0.5 * (pdm.logicalDpiX() + pdm.logicalDpiY());
65 map<int, io_callback *> io_callbacks;
69 // FIXME: wrong place !
70 LyXServer * lyxserver;
73 extern void initEncodings();
76 extern bool lyxX11EventFilter(XEvent * xev);
80 class LQApplication : public QApplication
83 LQApplication(int & argc, char ** argv);
86 bool x11EventFilter (XEvent * ev) { return lyxX11EventFilter(ev); }
91 LQApplication::LQApplication(int & argc, char ** argv)
92 : QApplication(argc, argv)
96 LQApplication::~LQApplication()
104 void parse_init(int & argc, char * argv[])
106 static LQApplication a(argc, argv);
108 using namespace lyx::graphics;
110 Image::newImage = boost::bind(&QLImage::newImage);
111 Image::loadableFormats = boost::bind(&QLImage::loadableFormats);
113 // needs to be done before reading lyxrc
114 lyxrc.dpi = getDPI();
118 LoaderQueue::setPriority(10,100);
126 void start(string const & batch, vector<string> const & files)
129 unsigned int width = 690;
130 unsigned int height = 510;
132 QtView view(width, height);
136 // FIXME: some code below needs moving
138 lyxserver = new LyXServer(&view.getLyXFunc(), lyxrc.lyxpipes);
140 vector<string>::const_iterator cit = files.begin();
141 vector<string>::const_iterator end = files.end();
142 for (; cit != end; ++cit)
143 view.view()->loadLyXFile(*cit, true);
145 // handle the batch commands the user asked for
146 if (!batch.empty()) {
147 view.getLyXFunc().dispatch(batch);
160 qApp->processEvents();
169 // we cannot call qApp->exit(0) - that could return us
170 // into a static dialog return in the lyx code (for example,
171 // load autosave file QMessageBox. We have to just get the hell
178 FuncStatus getStatus(FuncRequest const & ev)
182 case LFUN_DIALOG_SHOW:
183 if (ev.argument == "preamble" || ev.argument == "forks")
186 case LFUN_TOOLTIPS_TOGGLE:
196 string const hexname(EnumLColor col)
198 return ltrim(fromqstr(lcolorcache.get(col).name()), "#");
202 void update_color(EnumLColor)
204 // FIXME: Bleh, can't we just clear them all at once ?
215 bool font_available(LyXFont const & font)
217 return fontloader.available(font);
221 void set_read_callback(int fd, LyXComm * comm)
223 io_callbacks[fd] = new io_callback(fd, comm);
227 void remove_read_callback(int fd)
229 map<int, io_callback *>::iterator it = io_callbacks.find(fd);
230 if (it != io_callbacks.end()) {
232 io_callbacks.erase(it);
237 string const roman_font_name()
243 font.setStyleHint(QFont::Serif);
244 font.setFamily("serif");
245 return QFontInfo(font).family().latin1();
249 string const sans_font_name()
255 font.setStyleHint(QFont::SansSerif);
256 font.setFamily("sans");
257 return QFontInfo(font).family().latin1();
261 string const typewriter_font_name()
267 font.setStyleHint(QFont::TypeWriter);
268 font.setFamily("monospace");
269 return QFontInfo(font).family().latin1();
272 }; // namespace lyx_gui