]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiView.C
This commit transfers most of the LyXView use from BufferView to WorkArea, most notably:
[lyx.git] / src / frontends / qt4 / GuiView.C
1 /**
2  * \file GuiView.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  * \author Abdelrazak Younes
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #undef QT3_SUPPORT
14
15 #include <config.h>
16
17 #include "BufferView.h"
18 #include "lyx_cb.h"
19 #include "lyxrc.h"
20 #include "lyx_main.h"
21 #include "session.h"
22 #include "lyxfunc.h"
23 #include "MenuBackend.h"
24 #include "funcrequest.h"
25 #include "funcrequest.h"
26
27 #include "debug.h"
28
29 #include "frontends/Toolbars.h"
30 #include "frontends/WorkArea.h"
31 #include "support/filetools.h"
32 #include "support/convert.h"
33 #include "support/lstrings.h"
34
35 // This include must be declared before everything else because
36 // of boost/Qt/LyX clash...
37 #include "GuiImplementation.h"
38
39 #include "GuiView.h"
40 #include "QLMenubar.h"
41 #include "FontLoader.h"
42 #include "QCommandBuffer.h"
43 #include "qt_helpers.h"
44
45 #include <QApplication>
46 #include <QPixmap>
47 #include <QStatusBar>
48 #include <QToolBar>
49 #include <QCloseEvent>
50 #include <QAction>
51
52
53 #include <boost/bind.hpp>
54
55
56 using std::string;
57 using std::endl;
58
59 namespace lyx {
60
61 using support::subst;
62 using support::libFileSearch;
63
64 namespace frontend {
65
66 namespace {
67
68 int const statusbar_timer_value = 3000;
69
70 } // namespace anon
71
72
73 GuiView::GuiView(Gui & owner)
74         : QMainWindow(), LyXView(owner), commandbuffer_(0)
75 {
76 //      setToolButtonStyle(Qt::ToolButtonIconOnly);
77 //      setIconSize(QSize(12,12));
78
79 //      bufferview_.reset(new BufferView(this, width, height));
80
81 #ifndef Q_WS_MACX
82         //  assign an icon to main form. We do not do it under Qt/Mac,
83         //  since the icon is provided in the application bundle.
84         string const iconname = libFileSearch("images", "lyx", "xpm");
85         if (!iconname.empty())
86                 setWindowIcon(QPixmap(toqstr(iconname)));
87 #endif
88 }
89
90
91 GuiView::~GuiView()
92 {
93 }
94
95
96 void GuiView::init()
97 {
98         menubar_.reset(new QLMenubar(this, menubackend));
99         QObject::connect(menuBar(), SIGNAL(triggered(QAction *)), this, SLOT(updateMenu(QAction *)));
100
101         getToolbars().init();
102
103         statusBar()->setSizeGripEnabled(false);
104
105         QObject::connect(&statusbar_timer_, SIGNAL(timeout()), this, SLOT(update_view_state_qt()));
106
107         // make sure the buttons are disabled if needed
108         updateToolbars();
109
110         LyXView::init();
111 }
112
113 void GuiView::updateMenu(QAction * /*action*/)
114 {
115         menubar_->update();
116 }
117
118
119 void GuiView::setWindowTitle(string const & t, string const & it)
120 {
121         QMainWindow::setWindowTitle(toqstr(t));
122         QMainWindow::setWindowIconText(toqstr(it));
123 }
124
125
126 void GuiView::addCommandBuffer(QToolBar * toolbar)
127 {
128         commandbuffer_ = new QCommandBuffer(this, *controlcommand_);
129         focus_command_buffer.connect(boost::bind(&GuiView::focus_command_widget, this));
130         toolbar->addWidget(commandbuffer_);
131 }
132
133
134 void GuiView::message(string const & str)
135 {
136         statusBar()->showMessage(toqstr(str));
137         statusbar_timer_.stop();
138         statusbar_timer_.start(statusbar_timer_value);
139 }
140
141
142 void GuiView::clearMessage()
143 {
144         update_view_state_qt();
145 }
146
147
148 void GuiView::focus_command_widget()
149 {
150         if (commandbuffer_)
151                 commandbuffer_->focus_command();
152 }
153
154
155 void GuiView::update_view_state_qt()
156 {
157         statusBar()->showMessage(toqstr(getLyXFunc().viewStatusMessage()));
158         statusbar_timer_.stop();
159 }
160
161
162 void GuiView::updateStatusBar()
163 {
164         // let the user see the explicit message
165         if (statusbar_timer_.isActive())
166                 return;
167
168         statusBar()->showMessage(toqstr(getLyXFunc().viewStatusMessage()));
169 }
170
171
172 void GuiView::activated(FuncRequest const & func)
173 {
174         getLyXFunc().dispatch(func);
175 }
176
177
178 bool GuiView::hasFocus() const
179 {
180         return qApp->activeWindow() == this;
181 }
182
183
184 void  GuiView::updateFloatingGeometry()
185 {
186         if (!isMaximized())
187                 floatingGeometry_ = QRect(x(), y(), width(), height());
188 }
189
190
191 void GuiView::resizeEvent(QResizeEvent *)
192 {
193         updateFloatingGeometry();
194 }
195
196
197 void GuiView::moveEvent(QMoveEvent *)
198 {
199         updateFloatingGeometry();
200 }
201
202
203 void GuiView::closeEvent(QCloseEvent *)
204 {
205         // FIXME:
206         // change the ifdef to 'geometry = normalGeometry();' only
207         // when Trolltech has fixed the broken normalGeometry on X11:
208         // http://www.trolltech.com/developer/task-tracker/index_html?id=119684+&method=entry
209         // Then also the moveEvent, resizeEvent, and the
210         // code for floatingGeometry_ can be removed;
211         // adjust lyx_gui::start
212 #ifdef Q_OS_WIN32
213         QRect geometry = normalGeometry();
214 #else
215         updateFloatingGeometry();
216         QRect geometry = floatingGeometry_;
217 #endif
218
219         // save windows size and position
220         Session & session = LyX::ref().session();
221         session.saveSessionInfo("WindowWidth", convert<string>(geometry.width()));
222         session.saveSessionInfo("WindowHeight", convert<string>(geometry.height()));
223         session.saveSessionInfo("WindowIsMaximized", (isMaximized() ? "yes" : "no"));
224         if (lyxrc.geometry_xysaved) {
225                 session.saveSessionInfo("WindowPosX", convert<string>(geometry.x()));
226                 session.saveSessionInfo("WindowPosY", convert<string>(geometry.y()));
227         }
228         // trigger LFUN_LYX_QUIT instead of quit directly
229         // since LFUN_LYX_QUIT may have more cleanup stuff
230         getLyXFunc().dispatch(FuncRequest(LFUN_LYX_QUIT));
231 }
232
233
234 void GuiView::show()
235 {
236         QMainWindow::setWindowTitle(qt_("LyX"));
237         QMainWindow::show();
238         updateFloatingGeometry();
239 }
240
241
242 void GuiView::busy(bool yes) const
243 {
244         if (yes)
245                 QApplication::setOverrideCursor(Qt::WaitCursor);
246         else
247                 QApplication::restoreOverrideCursor();
248 }
249
250 } // namespace frontend
251 } // namespace lyx
252
253 #include "GuiView_moc.cpp"