]> git.lyx.org Git - features.git/blob - src/frontends/qt2/lyx_gui.C
qt does not implement forks-show either
[features.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 "qt_helpers.h"
24
25 #include "lyx_gui.h"
26 #include "lyx_main.h"
27 #include "lyxrc.h"
28 #include "lyxfont.h"
29 #include "funcrequest.h"
30
31 // FIXME: move this stuff out again
32 #include "bufferlist.h"
33 #include "lyxfunc.h"
34 #include "lyxserver.h"
35 #include "BufferView.h"
36
37 // Dear Lord, deliver us from Evil,
38 // aka the Qt headers
39 #include <boost/shared_ptr.hpp>
40 #include <boost/function/function0.hpp>
41 #include <boost/signals/signal1.hpp>
42 #include <boost/bind.hpp>
43
44 #include "QtView.h"
45 #include "QLImage.h"
46 #include "qfont_loader.h"
47 #include "io_callback.h"
48
49 #include <qapplication.h>
50 #include <qwidget.h>
51 #include <qpaintdevicemetrics.h>
52
53 #include <fcntl.h>
54
55 #ifndef CXX_GLOBAL_CSTD
56 using std::exit;
57 #endif
58
59 using std::vector;
60 using std::map;
61 using std::endl;
62
63 extern BufferList bufferlist;
64
65 namespace {
66
67 float getDPI()
68 {
69         QWidget w;
70         QPaintDeviceMetrics pdm(&w);
71         return 0.5 * (pdm.logicalDpiX() + pdm.logicalDpiY());
72 }
73
74 map<int, io_callback *> io_callbacks;
75
76 } // namespace anon
77
78
79 // FIXME: wrong place !
80 LyXServer * lyxserver;
81
82 #ifdef Q_WS_X11
83 extern bool lyxX11EventFilter(XEvent * xev);
84 #endif
85
86 class LQApplication : public QApplication
87 {
88 public:
89         LQApplication(int &argc, char **argv);
90         ~LQApplication();
91 #ifdef Q_WS_X11
92         bool x11EventFilter (XEvent * ev) { return lyxX11EventFilter(ev); }
93 #endif
94 };
95
96 LQApplication::LQApplication(int &argc, char **argv)
97         : QApplication( argc, argv )
98 {}
99
100 LQApplication::~LQApplication()
101 {}
102
103 void lyx_gui::parse_init(int & argc, char * argv[])
104 {
105         static LQApplication a(argc, argv);
106
107         using namespace grfx;
108
109         Image::newImage = boost::bind(&QLImage::newImage);
110         Image::loadableFormats = boost::bind(&QLImage::loadableFormats);
111
112         // needs to be done before reading lyxrc
113         lyxrc.dpi = getDPI();
114 }
115
116
117 void lyx_gui::parse_lyxrc()
118 {
119 }
120
121
122 void lyx_gui::start(string const & batch, vector<string> const & files)
123 {
124         // initial geometry
125         int xpos = -1;
126         int ypos = -1;
127         unsigned int width = 690;
128         unsigned int height = 510;
129
130         QtView view(width, height);
131         view.show(xpos, ypos, "LyX");
132         view.init();
133
134         Buffer * last = 0;
135
136         // FIXME: some code below needs moving
137
138         lyxserver = new LyXServer(&view.getLyXFunc(), lyxrc.lyxpipes);
139
140         vector<string>::const_iterator cit = files.begin();
141         vector<string>::const_iterator end = files.end();
142         for (; cit != end; ++cit) {
143                 Buffer * b = bufferlist.loadLyXFile(*cit);
144                 if (b) {
145                         last = b;
146                 }
147         }
148
149         // switch to the last buffer successfully loaded
150         if (last) {
151                 view.view()->buffer(last);
152         }
153
154         // handle the batch commands the user asked for
155         if (!batch.empty()) {
156                 view.getLyXFunc().dispatch(batch);
157         }
158
159         qApp->exec();
160
161         // FIXME
162         delete lyxserver;
163 }
164
165
166 void lyx_gui::exit()
167 {
168         qApp->exit(0);
169 }
170
171
172 FuncStatus lyx_gui::getStatus(FuncRequest const & ev)
173 {
174         FuncStatus flag;
175         switch (ev.action) {
176         case LFUN_LAYOUT_PREAMBLE:
177         case LFUN_TOOLTIPS_TOGGLE:
178         case LFUN_FORKS_SHOW:
179                 flag.unknown(true);
180                 break;
181         default:
182                 break;
183         }
184         return flag;
185 }
186
187
188 string const lyx_gui::hexname(LColor::color col)
189 {
190         QColor color(toqstr(lcolor.getX11Name(col)));
191         return ltrim(fromqstr(color.name()), "#");
192 }
193
194
195 void lyx_gui::update_color(LColor::color)
196 {
197         // no need
198 }
199
200
201 void lyx_gui::update_fonts()
202 {
203         fontloader.update();
204 }
205
206
207 bool lyx_gui::font_available(LyXFont const & font)
208 {
209         return fontloader.available(font);
210 }
211
212
213 void lyx_gui::set_read_callback(int fd, LyXComm * comm)
214 {
215         io_callbacks[fd] = new io_callback(fd, comm);
216 }
217
218
219 void lyx_gui::remove_read_callback(int fd)
220 {
221         map<int, io_callback *>::iterator it = io_callbacks.find(fd);
222         if (it != io_callbacks.end()) {
223                 delete it->second;
224                 io_callbacks.erase(it);
225         }
226 }