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 using namespace lyx::support;
60 #ifndef CXX_GLOBAL_CSTD
68 extern BufferList bufferlist;
75 QPaintDeviceMetrics pdm(&w);
76 return 0.5 * (pdm.logicalDpiX() + pdm.logicalDpiY());
79 map<int, io_callback *> io_callbacks;
83 // FIXME: wrong place !
84 LyXServer * lyxserver;
87 extern void initEncodings();
90 extern bool lyxX11EventFilter(XEvent * xev);
94 class LQApplication : public QApplication
97 LQApplication(int & argc, char ** argv);
100 bool x11EventFilter (XEvent * ev) { return lyxX11EventFilter(ev); }
105 LQApplication::LQApplication(int & argc, char ** argv)
106 : QApplication(argc, argv)
110 LQApplication::~LQApplication()
118 void parse_init(int & argc, char * argv[])
120 static LQApplication a(argc, argv);
122 using namespace grfx;
124 Image::newImage = boost::bind(&QLImage::newImage);
125 Image::loadableFormats = boost::bind(&QLImage::loadableFormats);
127 // needs to be done before reading lyxrc
128 lyxrc.dpi = getDPI();
132 LoaderQueue::setPriority(10,100);
140 void start(string const & batch, vector<string> const & files)
143 unsigned int width = 690;
144 unsigned int height = 510;
146 QtView view(width, height);
150 // FIXME: some code below needs moving
152 lyxserver = new LyXServer(&view.getLyXFunc(), lyxrc.lyxpipes);
154 vector<string>::const_iterator cit = files.begin();
155 vector<string>::const_iterator end = files.end();
156 for (; cit != end; ++cit)
157 view.view()->loadLyXFile(*cit, true);
159 // handle the batch commands the user asked for
160 if (!batch.empty()) {
161 view.getLyXFunc().dispatch(batch);
174 qApp->processEvents();
183 // we cannot call qApp->exit(0) - that could return us
184 // into a static dialog return in the lyx code (for example,
185 // load autosave file QMessageBox. We have to just get the hell
192 FuncStatus getStatus(FuncRequest const & ev)
196 case LFUN_DIALOG_SHOW:
197 if (ev.argument == "preamble" || ev.argument == "forks")
200 case LFUN_TOOLTIPS_TOGGLE:
210 string const hexname(LColor::color col)
212 return ltrim(fromqstr(lcolorcache.get(col).name()), "#");
216 void update_color(LColor::color)
218 // FIXME: Bleh, can't we just clear them all at once ?
229 bool font_available(LyXFont const & font)
231 return fontloader.available(font);
235 void set_read_callback(int fd, LyXComm * comm)
237 io_callbacks[fd] = new io_callback(fd, comm);
241 void remove_read_callback(int fd)
243 map<int, io_callback *>::iterator it = io_callbacks.find(fd);
244 if (it != io_callbacks.end()) {
246 io_callbacks.erase(it);
251 string const roman_font_name()
257 font.setStyleHint(QFont::Serif);
258 font.setFamily("serif");
259 return QFontInfo(font).family().latin1();
263 string const sans_font_name()
269 font.setStyleHint(QFont::SansSerif);
270 font.setFamily("sans");
271 return QFontInfo(font).family().latin1();
275 string const typewriter_font_name()
281 font.setStyleHint(QFont::TypeWriter);
282 font.setFamily("monospace");
283 return QFontInfo(font).family().latin1();
286 }; // namespace lyx_gui