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/lyxlib.h"
16 #include "support/os.h"
17 #include "support/filetools.h"
18 #include "support/lstrings.h"
20 #include "qt_helpers.h"
26 #include "funcrequest.h"
27 #include "graphics/LoaderQueue.h"
29 // FIXME: move this stuff out again
30 #include "bufferlist.h"
31 #include "buffer_funcs.h"
33 #include "lyxserver.h"
34 #include "BufferView.h"
36 // Dear Lord, deliver us from Evil,
38 #include <boost/shared_ptr.hpp>
39 #include <boost/function/function0.hpp>
40 #include <boost/signals/signal1.hpp>
41 #include <boost/bind.hpp>
45 #include "qfont_loader.h"
46 #include "io_callback.h"
47 #include "lcolorcache.h"
49 #include <qapplication.h>
51 #include <qpaintdevicemetrics.h>
53 #include <qfontinfo.h>
58 #ifndef CXX_GLOBAL_CSTD
66 extern BufferList bufferlist;
73 QPaintDeviceMetrics pdm(&w);
74 return 0.5 * (pdm.logicalDpiX() + pdm.logicalDpiY());
77 map<int, io_callback *> io_callbacks;
81 // FIXME: wrong place !
82 LyXServer * lyxserver;
85 extern void initEncodings();
88 extern bool lyxX11EventFilter(XEvent * xev);
92 class LQApplication : public QApplication
95 LQApplication(int & argc, char ** argv);
98 bool x11EventFilter (XEvent * ev) { return lyxX11EventFilter(ev); }
103 LQApplication::LQApplication(int & argc, char ** argv)
104 : QApplication(argc, argv)
108 LQApplication::~LQApplication()
116 void parse_init(int & argc, char * argv[])
118 static LQApplication a(argc, argv);
120 using namespace grfx;
122 Image::newImage = boost::bind(&QLImage::newImage);
123 Image::loadableFormats = boost::bind(&QLImage::loadableFormats);
125 // needs to be done before reading lyxrc
126 lyxrc.dpi = getDPI();
130 LoaderQueue::setPriority(10,100);
138 void start(string const & batch, vector<string> const & files)
141 unsigned int width = 690;
142 unsigned int height = 510;
144 QtView view(width, height);
148 // FIXME: some code below needs moving
150 lyxserver = new LyXServer(&view.getLyXFunc(), lyxrc.lyxpipes);
152 vector<string>::const_iterator cit = files.begin();
153 vector<string>::const_iterator end = files.end();
154 for (; cit != end; ++cit)
155 view.view()->loadLyXFile(*cit, true);
157 // handle the batch commands the user asked for
158 if (!batch.empty()) {
159 view.getLyXFunc().dispatch(batch);
172 qApp->processEvents();
181 // we cannot call qApp->exit(0) - that could return us
182 // into a static dialog return in the lyx code (for example,
183 // load autosave file QMessageBox. We have to just get the hell
190 FuncStatus getStatus(FuncRequest const & ev)
194 case LFUN_DIALOG_SHOW:
195 if (ev.argument == "preamble" || ev.argument == "forks")
198 case LFUN_TOOLTIPS_TOGGLE:
208 string const hexname(LColor::color col)
210 return ltrim(fromqstr(lcolorcache.get(col).name()), "#");
214 void update_color(LColor::color)
216 // FIXME: Bleh, can't we just clear them all at once ?
227 bool font_available(LyXFont const & font)
229 return fontloader.available(font);
233 void set_read_callback(int fd, LyXComm * comm)
235 io_callbacks[fd] = new io_callback(fd, comm);
239 void remove_read_callback(int fd)
241 map<int, io_callback *>::iterator it = io_callbacks.find(fd);
242 if (it != io_callbacks.end()) {
244 io_callbacks.erase(it);
249 string const roman_font_name()
255 font.setStyleHint(QFont::Serif);
256 font.setFamily("serif");
257 return QFontInfo(font).family().latin1();
261 string const sans_font_name()
267 font.setStyleHint(QFont::SansSerif);
268 font.setFamily("sans");
269 return QFontInfo(font).family().latin1();
273 string const typewriter_font_name()
279 font.setStyleHint(QFont::TypeWriter);
280 font.setFamily("monospace");
281 return QFontInfo(font).family().latin1();
284 }; // namespace lyx_gui