3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
8 * \author Abdelrazak Younes
10 * Full author contact details are available in file CREDITS.
15 #include "BufferView.h"
21 #include "MenuBackend.h"
22 #include "funcrequest.h"
23 #include "funcrequest.h"
27 #include "frontends/WorkArea.h"
28 #include "support/filetools.h"
29 #include "support/convert.h"
30 #include "support/lstrings.h"
32 // This include must be declared before everything else because
33 // of boost/Qt/LyX clash...
34 #include "GuiImplementation.h"
37 #include "QLMenubar.h"
38 #include "QLToolbar.h"
39 #include "FontLoader.h"
40 #include "QCommandBuffer.h"
41 #include "qt_helpers.h"
43 #include <QApplication>
47 #include <QCloseEvent>
51 #include <boost/bind.hpp>
60 using support::libFileSearch;
66 int const statusbar_timer_value = 3000;
72 : QMainWindow(), LyXView(), commandbuffer_(0)
74 // setToolButtonStyle(Qt::ToolButtonIconOnly);
75 // setIconSize(QSize(12,12));
77 // bufferview_.reset(new BufferView(this, width, height));
80 // assign an icon to main form. We do not do it under Qt/Mac,
81 // since the icon is provided in the application bundle.
82 string const iconname = libFileSearch("images", "lyx", "xpm");
83 if (!iconname.empty())
84 setWindowIcon(QPixmap(toqstr(iconname)));
96 menubar_.reset(new QLMenubar(this, menubackend));
97 QObject::connect(menuBar(), SIGNAL(triggered(QAction *)), this, SLOT(updateMenu(QAction *)));
101 statusBar()->setSizeGripEnabled(false);
103 QObject::connect(&statusbar_timer_, SIGNAL(timeout()), this, SLOT(update_view_state_qt()));
105 // make sure the buttons are disabled if needed
107 updateLayoutChoice();
112 void GuiView::setGeometry(unsigned int width,
117 // only true when the -geometry option was NOT used
118 if (width != 0 && height != 0) {
119 if (posx != -1 && posy != -1) {
121 // FIXME: use only setGeoemtry when Trolltech has
122 // fixed the qt4/X11 bug
123 QMainWindow::setGeometry(posx, posy,width, height);
125 resize(width, height);
129 resize(width, height);
133 setWindowState(Qt::WindowMaximized);
140 void GuiView::updateMenu(QAction * /*action*/)
146 void GuiView::setWindowTitle(docstring const & t, docstring const & it)
148 QMainWindow::setWindowTitle(toqstr(t));
149 QMainWindow::setWindowIconText(toqstr(it));
153 void GuiView::addCommandBuffer(QToolBar * toolbar)
155 commandbuffer_ = new QCommandBuffer(this, *controlcommand_);
156 focus_command_buffer.connect(boost::bind(&GuiView::focus_command_widget, this));
157 toolbar->addWidget(commandbuffer_);
161 void GuiView::message(docstring const & str)
163 statusBar()->showMessage(toqstr(str));
164 statusbar_timer_.stop();
165 statusbar_timer_.start(statusbar_timer_value);
169 void GuiView::clearMessage()
171 update_view_state_qt();
175 void GuiView::focus_command_widget()
178 commandbuffer_->focus_command();
182 void GuiView::update_view_state_qt()
184 statusBar()->showMessage(toqstr(getLyXFunc().viewStatusMessage()));
185 statusbar_timer_.stop();
189 void GuiView::updateStatusBar()
191 // let the user see the explicit message
192 if (statusbar_timer_.isActive())
195 statusBar()->showMessage(toqstr(getLyXFunc().viewStatusMessage()));
199 void GuiView::activated(FuncRequest const & func)
201 getLyXFunc().dispatch(func);
205 bool GuiView::hasFocus() const
207 return qApp->activeWindow() == this;
211 void GuiView::updateFloatingGeometry()
214 floatingGeometry_ = QRect(x(), y(), width(), height());
218 void GuiView::resizeEvent(QResizeEvent *)
220 updateFloatingGeometry();
224 void GuiView::moveEvent(QMoveEvent *)
226 updateFloatingGeometry();
230 void GuiView::closeEvent(QCloseEvent *)
233 // change the ifdef to 'geometry = normalGeometry();' only
234 // when Trolltech has fixed the broken normalGeometry on X11:
235 // http://www.trolltech.com/developer/task-tracker/index_html?id=119684+&method=entry
236 // Then also the moveEvent, resizeEvent, and the
237 // code for floatingGeometry_ can be removed;
238 // adjust GuiView::setGeometry()
240 QRect geometry = normalGeometry();
242 updateFloatingGeometry();
243 QRect geometry = floatingGeometry_;
246 // save windows size and position
247 Session & session = LyX::ref().session();
248 session.saveSessionInfo("WindowWidth", convert<string>(geometry.width()));
249 session.saveSessionInfo("WindowHeight", convert<string>(geometry.height()));
250 session.saveSessionInfo("WindowIsMaximized", (isMaximized() ? "yes" : "no"));
251 if (lyxrc.geometry_xysaved) {
252 session.saveSessionInfo("WindowPosX", convert<string>(geometry.x()));
253 session.saveSessionInfo("WindowPosY", convert<string>(geometry.y()));
255 // trigger LFUN_LYX_QUIT instead of quit directly
256 // since LFUN_LYX_QUIT may have more cleanup stuff
257 getLyXFunc().dispatch(FuncRequest(LFUN_LYX_QUIT));
263 QMainWindow::setWindowTitle(qt_("LyX"));
265 updateFloatingGeometry();
269 void GuiView::busy(bool yes) const
272 QApplication::setOverrideCursor(Qt::WaitCursor);
274 QApplication::restoreOverrideCursor();
278 Toolbars::ToolbarPtr GuiView::makeToolbar(ToolbarBackend::Toolbar const & tbb)
280 QLToolbar * Tb = new QLToolbar(tbb, *this);
281 static QLToolbar * lastTb = 0;
283 if (tbb.flags & ToolbarBackend::TOP) {
284 addToolBar(Qt::TopToolBarArea, Tb);
285 addToolBarBreak(Qt::TopToolBarArea);
287 if (tbb.flags & ToolbarBackend::BOTTOM) {
288 addToolBar(Qt::BottomToolBarArea, Tb);
290 insertToolBarBreak(lastTb);
293 if (tbb.flags & ToolbarBackend::LEFT) {
294 addToolBar(Qt::LeftToolBarArea, Tb);
296 if (tbb.flags & ToolbarBackend::RIGHT) {
297 addToolBar(Qt::RightToolBarArea, Tb);
300 return Toolbars::ToolbarPtr(Tb);
303 } // namespace frontend
306 #include "GuiView_moc.cpp"