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"
29 // Dear Lord, deliver us from Evil,
31 #include <boost/signals/signal1.hpp>
32 #include <boost/bind.hpp>
36 #include "qfont_loader.h"
37 #include "io_callback.h"
38 #include "lcolorcache.h"
40 #include <qapplication.h>
41 #include <qpaintdevicemetrics.h>
43 using lyx::support::ltrim;
45 #ifndef CXX_GLOBAL_CSTD
53 extern BufferList bufferlist;
60 QPaintDeviceMetrics pdm(&w);
61 return 0.5 * (pdm.logicalDpiX() + pdm.logicalDpiY());
64 map<int, io_callback *> io_callbacks;
68 // FIXME: wrong place !
69 LyXServer * lyxserver;
72 extern void initEncodings();
75 extern bool lyxX11EventFilter(XEvent * xev);
79 class LQApplication : public QApplication
82 LQApplication(int & argc, char ** argv);
85 bool x11EventFilter (XEvent * ev) { return lyxX11EventFilter(ev); }
90 LQApplication::LQApplication(int & argc, char ** argv)
91 : QApplication(argc, argv)
95 LQApplication::~LQApplication()
103 void parse_init(int & argc, char * argv[])
105 static LQApplication a(argc, argv);
107 using namespace lyx::graphics;
109 Image::newImage = boost::bind(&QLImage::newImage);
110 Image::loadableFormats = boost::bind(&QLImage::loadableFormats);
112 // needs to be done before reading lyxrc
113 lyxrc.dpi = getDPI();
117 LoaderQueue::setPriority(10,100);
125 void start(string const & batch, vector<string> const & files)
128 unsigned int width = 690;
129 unsigned int height = 510;
131 QtView view(width, height);
135 // FIXME: some code below needs moving
137 lyxserver = new LyXServer(&view.getLyXFunc(), lyxrc.lyxpipes);
139 vector<string>::const_iterator cit = files.begin();
140 vector<string>::const_iterator end = files.end();
141 for (; cit != end; ++cit)
142 view.view()->loadLyXFile(*cit, true);
144 // handle the batch commands the user asked for
145 if (!batch.empty()) {
146 view.getLyXFunc().dispatch(batch);
159 qApp->processEvents();
168 // we cannot call qApp->exit(0) - that could return us
169 // into a static dialog return in the lyx code (for example,
170 // load autosave file QMessageBox. We have to just get the hell
177 FuncStatus getStatus(FuncRequest const & ev)
181 case LFUN_DIALOG_SHOW:
182 if (ev.argument == "preamble" || ev.argument == "forks")
185 case LFUN_TOOLTIPS_TOGGLE:
195 string const hexname(EnumLColor col)
197 return ltrim(fromqstr(lcolorcache.get(col).name()), "#");
201 void update_color(EnumLColor)
203 // FIXME: Bleh, can't we just clear them all at once ?
214 bool font_available(LyXFont const & font)
216 return fontloader.available(font);
220 void set_read_callback(int fd, LyXComm * comm)
222 io_callbacks[fd] = new io_callback(fd, comm);
226 void remove_read_callback(int fd)
228 map<int, io_callback *>::iterator it = io_callbacks.find(fd);
229 if (it != io_callbacks.end()) {
231 io_callbacks.erase(it);
236 string const roman_font_name()
242 font.setStyleHint(QFont::Serif);
243 font.setFamily("serif");
244 return QFontInfo(font).family().latin1();
248 string const sans_font_name()
254 font.setStyleHint(QFont::SansSerif);
255 font.setFamily("sans");
256 return QFontInfo(font).family().latin1();
260 string const typewriter_font_name()
266 font.setStyleHint(QFont::TypeWriter);
267 font.setFamily("monospace");
268 return QFontInfo(font).family().latin1();
271 }; // namespace lyx_gui