]> git.lyx.org Git - features.git/blob - src/frontends/qt3/QtView.C
Add #include "xxx_moc.cpp" to xxx.C files, and stop compiling _moc.cpp individually.
[features.git] / src / frontends / qt3 / 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 "lyxrc.h"
17 #include "lyx_main.h"
18 #include "session.h"
19 #include "lyxfunc.h"
20 #include "MenuBackend.h"
21 #include "funcrequest.h"
22
23 #include "frontends/Toolbars.h"
24
25 #include "support/filetools.h"
26 #include "support/convert.h"
27
28 #include <boost/bind.hpp>
29
30 #include "QtView.h"
31 #include "QLMenubar.h"
32 #include "qfont_loader.h"
33 #include "QCommandBuffer.h"
34 #include "qt_helpers.h"
35
36 #include <qapplication.h>
37 #include <qpixmap.h>
38 #include <qstatusbar.h>
39
40 using std::string;
41
42 FontLoader fontloader;
43
44 namespace lyx {
45
46 using support::libFileSearch;
47
48 namespace frontend {
49
50 namespace {
51
52 int const statusbar_timer_value = 3000;
53
54 } // namespace anon
55
56
57 QtView::QtView(Gui & owner)
58         : QMainWindow(), LyXView(owner), commandbuffer_(0)
59 {
60         qApp->setMainWidget(this);
61
62 #ifndef Q_WS_MACX
63         //  assign an icon to main form. We do not do it under Qt/Mac,
64         //  since the icon is provided in the application bundle.
65         string const iconname = libFileSearch("images", "lyx", "xpm");
66         if (!iconname.empty())
67                 setIcon(QPixmap(toqstr(iconname)));
68 #endif
69 }
70
71
72 QtView::~QtView()
73 {
74 }
75
76
77 void QtView::init()
78 {
79         menubar_.reset(new QLMenubar(this, menubackend));
80         getToolbars().init();
81
82         statusBar()->setSizeGripEnabled(false);
83
84         connect(&statusbar_timer_, SIGNAL(timeout()), this, SLOT(update_view_state_qt()));
85
86         // make sure the buttons are disabled if needed
87         updateToolbars();
88
89         // allowing the toolbars to tear off is too easily done,
90         // and we don't save their orientation anyway. Disable the handle.
91         setToolBarsMovable(false);
92         
93         LyXView::init();
94 }
95
96
97 void QtView::setWindowTitle(string const & t, string const & it)
98 {
99         setCaption(toqstr(t));
100         setIconText(toqstr(it));
101 }
102
103
104 void QtView::addCommandBuffer(QWidget * parent)
105 {
106         commandbuffer_ = new QCommandBuffer(this, parent, *controlcommand_);
107         focus_command_buffer.connect(boost::bind(&QtView::focus_command_widget, this));
108 }
109
110
111 void QtView::message(string const & str)
112 {
113         statusBar()->message(toqstr(str));
114         statusbar_timer_.stop();
115         statusbar_timer_.start(statusbar_timer_value);
116 }
117
118
119 void QtView::clearMessage()
120 {
121         update_view_state_qt();
122 }
123
124
125 void QtView::focus_command_widget()
126 {
127         if (commandbuffer_)
128                 commandbuffer_->focus_command();
129 }
130
131
132 void QtView::update_view_state_qt()
133 {
134         statusBar()->message(toqstr(getLyXFunc().viewStatusMessage()));
135         statusbar_timer_.stop();
136 }
137
138
139 void QtView::updateStatusBar()
140 {
141         // let the user see the explicit message
142         if (statusbar_timer_.isActive())
143                 return;
144
145         statusBar()->message(toqstr(getLyXFunc().viewStatusMessage()));
146 }
147
148
149 void QtView::activated(FuncRequest const & func)
150 {
151         getLyXFunc().dispatch(func);
152 }
153
154
155 bool QtView::hasFocus() const
156 {
157         return qApp->activeWindow() == this;
158 }
159
160
161 void QtView::initFloatingGeometry(QRect const & g)
162 {
163         floatingGeometry_ = g;
164         maxWidth = QApplication::desktop()->width() - 20;
165 }
166
167
168 void QtView::updateFloatingGeometry()
169 {
170         if (width() < maxWidth && frameGeometry().x() > 0)
171                 floatingGeometry_ = QRect(x(), y(), width(), height());
172 }
173
174
175 void QtView::resizeEvent(QResizeEvent *)
176 {
177         maxWidth = std::max(width(), maxWidth);
178
179         updateFloatingGeometry();
180 }
181
182
183 void QtView::moveEvent(QMoveEvent *)
184 {
185         updateFloatingGeometry();
186 }
187
188
189 void QtView::closeEvent(QCloseEvent *)
190 {
191         updateFloatingGeometry();
192         QRect geometry = floatingGeometry_;
193
194         Session & session = LyX::ref().session();
195         session.saveSessionInfo("WindowIsMaximized", (isMaximized() ? "yes" : "no"));
196         // save windows size and position
197         session.saveSessionInfo("WindowWidth", convert<string>(geometry.width()));
198         session.saveSessionInfo("WindowHeight", convert<string>(geometry.height()));
199         if (lyxrc.geometry_xysaved) {
200                 session.saveSessionInfo("WindowPosX", convert<string>(geometry.x()));
201                 session.saveSessionInfo("WindowPosY", convert<string>(geometry.y()));
202         }
203         // trigger LFUN_LYX_QUIT instead of quit directly
204         // since LFUN_LYX_QUIT may have more cleanup stuff
205         getLyXFunc().dispatch(FuncRequest(LFUN_LYX_QUIT));
206 }
207
208
209 void QtView::show()
210 {
211         setCaption(qt_("LyX"));
212         QMainWindow::show();
213         updateFloatingGeometry();
214 }
215
216
217 void QtView::busy(bool yes) const
218 {
219         if (yes)
220                 QApplication::setOverrideCursor(Qt::waitCursor);
221         else
222                 QApplication::restoreOverrideCursor();
223 }
224
225 } // namespace frontend
226 } // namespace lyx
227
228 #include "QtView_moc.cpp"