]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/lyx_gui.C
minor changes
[lyx.git] / src / frontends / qt2 / lyx_gui.C
1 /**
2  * \file lyx_gui.C
3  * Copyright 2002 the LyX Team
4  * Read the file COPYING
5  *
6  * \author unknown
7  * \author John Levon <moz@compsoc.man.ac.uk>
8  */
9
10 #include <config.h>
11  
12 #include "support/lyxlib.h"
13 #include "support/os.h"
14 #include "support/filetools.h"
15 #include "debug.h"
16 #include "gettext.h"
17  
18 #include <fcntl.h>
19 #include <boost/bind.hpp>
20  
21 #include "lyx_gui.h"
22 #include "lyx_main.h"
23 #include "lyxrc.h"
24 #include "lyxfont.h"
25  
26 // FIXME: move this stuff out again
27 #include "bufferlist.h"
28 #include "lyxfunc.h"
29 #include "lyxserver.h"
30 #include "BufferView.h"
31
32 // Dear Lord, deliver us from Evil,
33 // aka the Qt headers
34 #include <boost/shared_ptr.hpp>
35 #include <boost/function/function0.hpp>
36 #include <boost/signals/signal1.hpp>
37  
38 #include "QtView.h"
39 #include "QLImage.h"
40 #include "qfont_loader.h"
41  
42 #include <qapplication.h>
43  
44 #ifndef CXX_GLOBAL_CSTD
45 using std::exit;
46 #endif
47
48 using std::vector;
49 using std::hex;
50 using std::endl;
51  
52 extern bool finished;
53 extern BufferList bufferlist;
54  
55 // FIXME: wrong place !
56 LyXServer * lyxserver;
57  
58 void lyx_gui::parse_init(int & argc, char * argv[])
59 {
60         static QApplication a(argc, argv);
61  
62         using namespace grfx;
63
64         Image::newImage = boost::bind(&QLImage::newImage);
65         Image::loadableFormats = boost::bind(&QLImage::loadableFormats);
66 }
67  
68
69 void lyx_gui::parse_lyxrc()
70 {
71         // FIXME !!!! 
72         lyxrc.dpi = 95;
73 }
74
75  
76 void lyx_gui::start(string const & batch, vector<string> files)
77 {
78         // initial geometry
79         int xpos = -1;
80         int ypos = -1;
81         unsigned int width = 690;
82         unsigned int height = 510;
83  
84         QtView view(width, height);
85         view.show(xpos, ypos, "LyX");
86         view.init();
87
88         Buffer * last = 0;
89  
90         // FIXME: some code below needs moving
91
92         lyxserver = new LyXServer(view.getLyXFunc(), lyxrc.lyxpipes);
93  
94         vector<string>::const_iterator cit = files.begin();
95         vector<string>::const_iterator end = files.end();
96         for (; cit != end; ++cit) {
97                 Buffer * b = bufferlist.loadLyXFile(*cit);
98                 if (b) {
99                         last = b;
100                 }
101         }
102
103         // switch to the last buffer successfully loaded
104         if (last) {
105                 view.view()->buffer(last);
106         }
107
108         // handle the batch commands the user asked for
109         if (!batch.empty()) {
110                 view.getLyXFunc()->verboseDispatch(batch, false);
111         }
112
113         while (!finished) {
114                 qApp->processEvents();
115         }
116                  
117         // FIXME 
118         delete lyxserver;
119 }
120  
121  
122 string const lyx_gui::hexname(LColor::color col)
123 {
124         QColor color(lcolor.getX11Name(col).c_str());
125         return color.name().latin1();
126 }
127
128
129 void lyx_gui::update_color(LColor::color)
130 {
131         // no need
132 }
133
134
135 void lyx_gui::update_fonts()
136 {
137         fontloader.update();
138 }
139
140
141 bool lyx_gui::font_available(LyXFont const & font)
142 {
143         return fontloader.available(font);
144 }