]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QtView.C
fix math fonts with LyX/Mac
[lyx.git] / src / frontends / qt2 / QtView.C
1 /**
2  * \file QtView.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Lars Gullik Bjønnes
7  * \author John Levon
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "BufferView.h"
15 #include "lyx_cb.h"
16 #include "lyxfunc.h"
17 #include "MenuBackend.h"
18
19 #include "frontends/Toolbars.h"
20
21 #include "support/filetools.h"
22
23 #include <boost/bind.hpp>
24
25 #include "QtView.h"
26 #include "QLMenubar.h"
27 #include "qfont_loader.h"
28 #include "QCommandBuffer.h"
29 #include "qt_helpers.h"
30
31 #include <qapplication.h>
32 #include <qpixmap.h>
33 #include <qstatusbar.h>
34
35 using std::string;
36
37 qfont_loader fontloader;
38
39 namespace lyx {
40
41 using support::LibFileSearch;
42
43 namespace frontend {
44
45 namespace {
46
47 int const statusbar_timer_value = 3000;
48
49 } // namespace anon
50
51
52
53 QtView::QtView(unsigned int width, unsigned int height)
54         : QMainWindow(), LyXView(), commandbuffer_(0)
55 {
56         resize(width, height);
57
58         qApp->setMainWidget(this);
59
60         bufferview_.reset(new BufferView(this, width, height));
61
62         menubar_.reset(new QLMenubar(this, menubackend));
63         getToolbars().init();
64
65         statusBar()->setSizeGripEnabled(false);
66
67         view_state_changed.connect(boost::bind(&QtView::update_view_state, this));
68         connect(&statusbar_timer_, SIGNAL(timeout()), this, SLOT(update_view_state_qt()));
69
70         //  assign an icon to main form
71         string const iconname = LibFileSearch("images", "lyx", "xpm");
72         if (!iconname.empty())
73                 setIcon(QPixmap(toqstr(iconname)));
74
75         // make sure the buttons are disabled if needed
76         updateToolbars();
77
78         // allowing the toolbars to tear off is too easily done,
79         // and we don't save their orientation anyway. Disable the handle.
80         setToolBarsMovable(false);
81 }
82
83
84 QtView::~QtView()
85 {
86 }
87
88
89 void QtView::setWindowTitle(string const & t, string const & it)
90 {
91         setCaption(toqstr(t));
92         setIconText(toqstr(it));
93 }
94
95
96 void QtView::addCommandBuffer(QWidget * parent)
97 {
98         commandbuffer_ = new QCommandBuffer(this, parent, *controlcommand_);
99         focus_command_buffer.connect(boost::bind(&QtView::focus_command_widget, this));
100 }
101
102
103 void QtView::message(string const & str)
104 {
105         statusBar()->message(toqstr(str));
106         statusbar_timer_.stop();
107         statusbar_timer_.start(statusbar_timer_value);
108 }
109
110
111 void QtView::clearMessage()
112 {
113         update_view_state_qt();
114 }
115
116
117 void QtView::focus_command_widget()
118 {
119         if (commandbuffer_)
120                 commandbuffer_->focus_command();
121 }
122
123
124 void QtView::update_view_state_qt()
125 {
126         statusBar()->message(toqstr(getLyXFunc().viewStatusMessage()));
127         statusbar_timer_.stop();
128 }
129
130
131 void QtView::update_view_state()
132 {
133         // let the user see the explicit message
134         if (statusbar_timer_.isActive())
135                 return;
136
137         statusBar()->message(toqstr(getLyXFunc().viewStatusMessage()));
138 }
139
140
141 void QtView::activated(FuncRequest const & func)
142 {
143         getLyXFunc().dispatch(func, true);
144 }
145
146
147 void QtView::closeEvent(QCloseEvent *)
148 {
149         QuitLyX();
150 }
151
152
153 void QtView::show()
154 {
155         setCaption(qt_("LyX"));
156         QMainWindow::show();
157 }
158
159
160 void QtView::busy(bool yes) const
161 {
162         if (yes)
163                 QApplication::setOverrideCursor(Qt::waitCursor);
164         else
165                 QApplication::restoreOverrideCursor();
166 }
167
168 } // namespace frontend
169 } // namespace lyx