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
9 * Full author contact details are available in file CREDITS.
14 #include "BufferView.h"
20 #include "MenuBackend.h"
21 #include "funcrequest.h"
23 #include "frontends/Toolbars.h"
25 #include "support/filetools.h"
26 #include "support/convert.h"
28 #include <boost/bind.hpp>
31 #include "QLMenubar.h"
32 #include "QLToolbar.h"
33 #include "qfont_loader.h"
34 #include "QCommandBuffer.h"
35 #include "qt_helpers.h"
37 #include <qapplication.h>
39 #include <qstatusbar.h>
43 GuiFontLoader fontloader;
47 using support::libFileSearch;
53 int const statusbar_timer_value = 3000;
59 : QMainWindow(), LyXView(), commandbuffer_(0)
61 qApp->setMainWidget(this);
64 // assign an icon to main form. We do not do it under Qt/Mac,
65 // since the icon is provided in the application bundle.
66 string const iconname = libFileSearch("images", "lyx", "xpm");
67 if (!iconname.empty())
68 setIcon(QPixmap(toqstr(iconname)));
80 menubar_.reset(new QLMenubar(this, menubackend));
83 statusBar()->setSizeGripEnabled(false);
85 connect(&statusbar_timer_, SIGNAL(timeout()), this, SLOT(update_view_state_qt()));
87 // make sure the buttons are disabled if needed
90 // allowing the toolbars to tear off is too easily done,
91 // and we don't save their orientation anyway. Disable the handle.
92 setToolBarsMovable(false);
99 void QtView::setGeometry(unsigned int width,
104 // only true when the -geometry option was NOT used
105 if (width != 0 && height != 0) {
106 initFloatingGeometry(QRect(posx, posy, width, height));
107 resize(width, height);
108 if (posx != -1 && posy != -1)
112 setWindowState(Qt::WindowMaximized);
118 void QtView::setWindowTitle(docstring const & t, docstring const & it)
120 setCaption(toqstr(t));
121 setIconText(toqstr(it));
125 void QtView::addCommandBuffer(QWidget * parent)
127 commandbuffer_ = new QCommandBuffer(this, parent, *controlcommand_);
128 focus_command_buffer.connect(boost::bind(&QtView::focus_command_widget, this));
132 void QtView::message(docstring const & str)
134 statusBar()->message(toqstr(str));
135 statusbar_timer_.stop();
136 statusbar_timer_.start(statusbar_timer_value);
140 void QtView::clearMessage()
142 update_view_state_qt();
146 void QtView::focus_command_widget()
149 commandbuffer_->focus_command();
153 void QtView::update_view_state_qt()
155 statusBar()->message(toqstr(getLyXFunc().viewStatusMessage()));
156 statusbar_timer_.stop();
160 void QtView::updateStatusBar()
162 // let the user see the explicit message
163 if (statusbar_timer_.isActive())
166 statusBar()->message(toqstr(getLyXFunc().viewStatusMessage()));
170 void QtView::activated(FuncRequest const & func)
172 getLyXFunc().dispatch(func);
176 bool QtView::hasFocus() const
178 return qApp->activeWindow() == this;
182 void QtView::initFloatingGeometry(QRect const & g)
184 floatingGeometry_ = g;
185 maxWidth = QApplication::desktop()->width() - 20;
189 void QtView::updateFloatingGeometry()
191 if (width() < maxWidth && frameGeometry().x() > 0)
192 floatingGeometry_ = QRect(x(), y(), width(), height());
196 void QtView::resizeEvent(QResizeEvent *)
198 maxWidth = std::max(width(), maxWidth);
200 updateFloatingGeometry();
204 void QtView::moveEvent(QMoveEvent *)
206 updateFloatingGeometry();
210 void QtView::closeEvent(QCloseEvent *)
212 updateFloatingGeometry();
213 QRect geometry = floatingGeometry_;
215 Session & session = LyX::ref().session();
216 session.saveSessionInfo("WindowIsMaximized", (isMaximized() ? "yes" : "no"));
217 // save windows size and position
218 session.saveSessionInfo("WindowWidth", convert<string>(geometry.width()));
219 session.saveSessionInfo("WindowHeight", convert<string>(geometry.height()));
220 if (lyxrc.geometry_xysaved) {
221 session.saveSessionInfo("WindowPosX", convert<string>(geometry.x()));
222 session.saveSessionInfo("WindowPosY", convert<string>(geometry.y()));
224 // trigger LFUN_LYX_QUIT instead of quit directly
225 // since LFUN_LYX_QUIT may have more cleanup stuff
226 getLyXFunc().dispatch(FuncRequest(LFUN_LYX_QUIT));
232 setCaption(qt_("LyX"));
234 updateFloatingGeometry();
238 void QtView::busy(bool yes) const
241 QApplication::setOverrideCursor(Qt::waitCursor);
243 QApplication::restoreOverrideCursor();
247 Toolbars::ToolbarPtr QtView::makeToolbar(ToolbarBackend::Toolbar const & tbb)
249 return make_toolbar(tbb, *this);
252 } // namespace frontend
255 #include "QtView_moc.cpp"