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/Toolbars.h"
28 #include "frontends/WorkArea.h"
29 #include "support/filetools.h"
30 #include "support/convert.h"
31 #include "support/lstrings.h"
33 // This include must be declared before everything else because
34 // of boost/Qt/LyX clash...
35 #include "GuiImplementation.h"
38 #include "QLMenubar.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;
71 GuiView::GuiView(Gui & owner)
72 : QMainWindow(), LyXView(owner), 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
111 void GuiView::updateMenu(QAction * /*action*/)
117 void GuiView::setWindowTitle(string const & t, string const & it)
119 QMainWindow::setWindowTitle(toqstr(t));
120 QMainWindow::setWindowIconText(toqstr(it));
124 void GuiView::addCommandBuffer(QToolBar * toolbar)
126 commandbuffer_ = new QCommandBuffer(this, *controlcommand_);
127 focus_command_buffer.connect(boost::bind(&GuiView::focus_command_widget, this));
128 toolbar->addWidget(commandbuffer_);
132 void GuiView::message(string const & str)
134 statusBar()->showMessage(toqstr(str));
135 statusbar_timer_.stop();
136 statusbar_timer_.start(statusbar_timer_value);
140 void GuiView::clearMessage()
142 update_view_state_qt();
146 void GuiView::focus_command_widget()
149 commandbuffer_->focus_command();
153 void GuiView::update_view_state_qt()
155 statusBar()->showMessage(toqstr(getLyXFunc().viewStatusMessage()));
156 statusbar_timer_.stop();
160 void GuiView::updateStatusBar()
162 // let the user see the explicit message
163 if (statusbar_timer_.isActive())
166 statusBar()->showMessage(toqstr(getLyXFunc().viewStatusMessage()));
170 void GuiView::activated(FuncRequest const & func)
172 getLyXFunc().dispatch(func);
176 bool GuiView::hasFocus() const
178 return qApp->activeWindow() == this;
182 void GuiView::updateFloatingGeometry()
185 floatingGeometry_ = QRect(x(), y(), width(), height());
189 void GuiView::resizeEvent(QResizeEvent *)
191 updateFloatingGeometry();
195 void GuiView::moveEvent(QMoveEvent *)
197 updateFloatingGeometry();
201 void GuiView::closeEvent(QCloseEvent *)
204 // change the ifdef to 'geometry = normalGeometry();' only
205 // when Trolltech has fixed the broken normalGeometry on X11:
206 // http://www.trolltech.com/developer/task-tracker/index_html?id=119684+&method=entry
207 // Then also the moveEvent, resizeEvent, and the
208 // code for floatingGeometry_ can be removed;
209 // adjust lyx_gui::start
211 QRect geometry = normalGeometry();
213 updateFloatingGeometry();
214 QRect geometry = floatingGeometry_;
217 // save windows size and position
218 Session & session = LyX::ref().session();
219 session.saveSessionInfo("WindowWidth", convert<string>(geometry.width()));
220 session.saveSessionInfo("WindowHeight", convert<string>(geometry.height()));
221 session.saveSessionInfo("WindowIsMaximized", (isMaximized() ? "yes" : "no"));
222 if (lyxrc.geometry_xysaved) {
223 session.saveSessionInfo("WindowPosX", convert<string>(geometry.x()));
224 session.saveSessionInfo("WindowPosY", convert<string>(geometry.y()));
226 // trigger LFUN_LYX_QUIT instead of quit directly
227 // since LFUN_LYX_QUIT may have more cleanup stuff
228 getLyXFunc().dispatch(FuncRequest(LFUN_LYX_QUIT));
234 QMainWindow::setWindowTitle(qt_("LyX"));
236 updateFloatingGeometry();
240 void GuiView::busy(bool yes) const
243 QApplication::setOverrideCursor(Qt::WaitCursor);
245 QApplication::restoreOverrideCursor();
248 } // namespace frontend
251 #include "GuiView_moc.cpp"