]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/lyx_gui.C
partial fonts fix. Like Juergen said we really need our own dialog.
[lyx.git] / src / frontends / qt2 / lyx_gui.C
1 /**
2  * \file qt2/lyx_gui.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author unknown
7  * \author John Levon
8  *
9  * Full author contact details are available in file CREDITS
10  */
11
12 #include <config.h>
13
14 #ifdef __GNUG__
15 #pragma implementation
16 #endif
17
18 #include "support/lyxlib.h"
19 #include "support/os.h"
20 #include "support/filetools.h"
21 #include "support/lstrings.h"
22 #include "debug.h"
23 #include "gettext.h"
24
25 #include "lyx_gui.h"
26 #include "lyx_main.h"
27 #include "lyxrc.h"
28 #include "lyxfont.h"
29
30 // FIXME: move this stuff out again
31 #include "bufferlist.h"
32 #include "lyxfunc.h"
33 #include "lyxserver.h"
34 #include "BufferView.h"
35
36 // Dear Lord, deliver us from Evil,
37 // aka the Qt headers
38 #include <boost/shared_ptr.hpp>
39 #include <boost/function/function0.hpp>
40 #include <boost/signals/signal1.hpp>
41 #include <boost/bind.hpp>
42
43 #include "QtView.h"
44 #include "QLImage.h"
45 #include "qfont_loader.h"
46 #include "io_callback.h"
47
48 #include <qapplication.h>
49 #include <qwidget.h>
50 #include <qpaintdevicemetrics.h>
51
52 #include <fcntl.h>
53
54 #ifndef CXX_GLOBAL_CSTD
55 using std::exit;
56 #endif
57
58 using std::vector;
59 using std::map;
60 using std::endl;
61
62 extern BufferList bufferlist;
63
64 namespace {
65
66 float getDPI()
67 {
68         QWidget w;
69         QPaintDeviceMetrics pdm(&w);
70         return 0.5 * (pdm.logicalDpiX() + pdm.logicalDpiY());
71 }
72
73 map<int, io_callback *> io_callbacks;
74
75 } // namespace anon
76
77
78 // FIXME: wrong place !
79 LyXServer * lyxserver;
80
81 #ifdef Q_WS_X11
82 extern bool lyxX11EventFilter(XEvent * xev);
83 #endif
84
85 class LQApplication : public QApplication
86 {
87 public:
88         LQApplication(int &argc, char **argv);
89         ~LQApplication();
90 #ifdef Q_WS_X11
91         bool x11EventFilter (XEvent * ev) { return lyxX11EventFilter(ev); }
92 #endif
93 };
94
95 LQApplication::LQApplication(int &argc, char **argv)
96         : QApplication( argc, argv )
97 {}
98
99 LQApplication::~LQApplication()
100 {}
101
102 void lyx_gui::parse_init(int & argc, char * argv[])
103 {
104         static LQApplication a(argc, argv);
105
106         using namespace grfx;
107
108         Image::newImage = boost::bind(&QLImage::newImage);
109         Image::loadableFormats = boost::bind(&QLImage::loadableFormats);
110
111         // needs to be done before reading lyxrc
112         lyxrc.dpi = getDPI();
113 }
114
115
116 void lyx_gui::parse_lyxrc()
117 {
118 }
119
120
121 void lyx_gui::start(string const & batch, vector<string> const & files)
122 {
123         // initial geometry
124         int xpos = -1;
125         int ypos = -1;
126         unsigned int width = 690;
127         unsigned int height = 510;
128
129         QtView view(width, height);
130         view.show(xpos, ypos, "LyX");
131         view.init();
132
133         Buffer * last = 0;
134
135         // FIXME: some code below needs moving
136
137         lyxserver = new LyXServer(&view.getLyXFunc(), lyxrc.lyxpipes);
138
139         vector<string>::const_iterator cit = files.begin();
140         vector<string>::const_iterator end = files.end();
141         for (; cit != end; ++cit) {
142                 Buffer * b = bufferlist.loadLyXFile(*cit);
143                 if (b) {
144                         last = b;
145                 }
146         }
147
148         // switch to the last buffer successfully loaded
149         if (last) {
150                 view.view()->buffer(last);
151         }
152
153         // handle the batch commands the user asked for
154         if (!batch.empty()) {
155                 view.getLyXFunc().dispatch(batch);
156         }
157
158         qApp->exec();
159
160         // FIXME
161         delete lyxserver;
162 }
163
164
165 void lyx_gui::exit()
166 {
167         qApp->exit(0);
168 }
169
170
171 string const lyx_gui::hexname(LColor::color col)
172 {
173         QColor color(lcolor.getX11Name(col).c_str());
174         return ltrim(color.name().latin1(), "#");
175 }
176
177
178 void lyx_gui::update_color(LColor::color)
179 {
180         // no need
181 }
182
183
184 void lyx_gui::update_fonts()
185 {
186         fontloader.update();
187 }
188
189
190 bool lyx_gui::font_available(LyXFont const & font)
191 {
192         return fontloader.available(font);
193 }
194
195
196 void lyx_gui::set_read_callback(int fd, LyXComm * comm)
197 {
198         io_callbacks[fd] = new io_callback(fd, comm);
199 }
200
201
202 void lyx_gui::remove_read_callback(int fd)
203 {
204         map<int, io_callback *>::iterator it = io_callbacks.find(fd);
205         if (it != io_callbacks.end()) {
206                 delete it->second;
207                 io_callbacks.erase(it);
208         }
209 }