]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/lyx_gui.C
the qtclean-2 patch with some very small changes
[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 <fcntl.h>
26 #include <boost/bind.hpp>
27
28 #include "lyx_gui.h"
29 #include "lyx_main.h"
30 #include "lyxrc.h"
31 #include "lyxfont.h"
32
33 // FIXME: move this stuff out again
34 #include "bufferlist.h"
35 #include "lyxfunc.h"
36 #include "lyxserver.h"
37 #include "BufferView.h"
38
39 // Dear Lord, deliver us from Evil,
40 // aka the Qt headers
41 #include <boost/shared_ptr.hpp>
42 #include <boost/function/function0.hpp>
43 #include <boost/signals/signal1.hpp>
44
45 #include "QtView.h"
46 #include "QLImage.h"
47 #include "qfont_loader.h"
48 #include "io_callback.h"
49
50 #include <qapplication.h>
51 #include <qwidget.h>
52 #include <qpaintdevicemetrics.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
82 void lyx_gui::parse_init(int & argc, char * argv[])
83 {
84         static QApplication a(argc, argv);
85
86         using namespace grfx;
87
88         Image::newImage = boost::bind(&QLImage::newImage);
89         Image::loadableFormats = boost::bind(&QLImage::loadableFormats);
90
91         // needs to be done before reading lyxrc
92         lyxrc.dpi = getDPI();
93 }
94
95
96 void lyx_gui::parse_lyxrc()
97 {
98 }
99
100
101 void lyx_gui::start(string const & batch, vector<string> files)
102 {
103         // initial geometry
104         int xpos = -1;
105         int ypos = -1;
106         unsigned int width = 690;
107         unsigned int height = 510;
108
109         QtView view(width, height);
110         view.show(xpos, ypos, "LyX");
111         view.init();
112
113         Buffer * last = 0;
114
115         // FIXME: some code below needs moving
116
117         lyxserver = new LyXServer(&view.getLyXFunc(), lyxrc.lyxpipes);
118
119         vector<string>::const_iterator cit = files.begin();
120         vector<string>::const_iterator end = files.end();
121         for (; cit != end; ++cit) {
122                 Buffer * b = bufferlist.loadLyXFile(*cit);
123                 if (b) {
124                         last = b;
125                 }
126         }
127
128         // switch to the last buffer successfully loaded
129         if (last) {
130                 view.view()->buffer(last);
131         }
132
133         // handle the batch commands the user asked for
134         if (!batch.empty()) {
135                 view.getLyXFunc().dispatch(batch);
136         }
137
138         qApp->exec();
139
140         // FIXME
141         delete lyxserver;
142 }
143
144
145 void lyx_gui::exit()
146 {
147         qApp->exit(0);
148 }
149
150
151 string const lyx_gui::hexname(LColor::color col)
152 {
153         QColor color(lcolor.getX11Name(col).c_str());
154         return ltrim(color.name().latin1(), "#");
155 }
156
157
158 void lyx_gui::update_color(LColor::color)
159 {
160         // no need
161 }
162
163
164 void lyx_gui::update_fonts()
165 {
166         fontloader.update();
167 }
168
169
170 bool lyx_gui::font_available(LyXFont const & font)
171 {
172         return fontloader.available(font);
173 }
174
175
176 void lyx_gui::set_read_callback(int fd, LyXComm * comm)
177 {
178         io_callbacks[fd] = new io_callback(fd, comm);
179 }
180
181
182 void lyx_gui::remove_read_callback(int fd)
183 {
184         map<int, io_callback *>::iterator it = io_callbacks.find(fd);
185         if (it != io_callbacks.end()) {
186                 delete it->second;
187                 io_callbacks.erase(it);
188         }
189 }