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 "qfont_loader.h"
33 #include "QCommandBuffer.h"
34 #include "qt_helpers.h"
36 #include <qapplication.h>
38 #include <qstatusbar.h>
42 FontLoader fontloader;
46 using support::libFileSearch;
52 int const statusbar_timer_value = 3000;
57 QtView::QtView(Gui & owner)
58 : QMainWindow(), LyXView(owner), commandbuffer_(0)
60 qApp->setMainWidget(this);
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)));
79 menubar_.reset(new QLMenubar(this, menubackend));
82 statusBar()->setSizeGripEnabled(false);
84 connect(&statusbar_timer_, SIGNAL(timeout()), this, SLOT(update_view_state_qt()));
86 // make sure the buttons are disabled if needed
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);
97 void QtView::setWindowTitle(string const & t, string const & it)
99 setCaption(toqstr(t));
100 setIconText(toqstr(it));
104 void QtView::addCommandBuffer(QWidget * parent)
106 commandbuffer_ = new QCommandBuffer(this, parent, *controlcommand_);
107 focus_command_buffer.connect(boost::bind(&QtView::focus_command_widget, this));
111 void QtView::message(string const & str)
113 statusBar()->message(toqstr(str));
114 statusbar_timer_.stop();
115 statusbar_timer_.start(statusbar_timer_value);
119 void QtView::clearMessage()
121 update_view_state_qt();
125 void QtView::focus_command_widget()
128 commandbuffer_->focus_command();
132 void QtView::update_view_state_qt()
134 statusBar()->message(toqstr(getLyXFunc().viewStatusMessage()));
135 statusbar_timer_.stop();
139 void QtView::updateStatusBar()
141 // let the user see the explicit message
142 if (statusbar_timer_.isActive())
145 statusBar()->message(toqstr(getLyXFunc().viewStatusMessage()));
149 void QtView::activated(FuncRequest const & func)
151 getLyXFunc().dispatch(func);
155 bool QtView::hasFocus() const
157 return qApp->activeWindow() == this;
161 void QtView::initFloatingGeometry(QRect const & g)
163 floatingGeometry_ = g;
164 maxWidth = QApplication::desktop()->width() - 20;
168 void QtView::updateFloatingGeometry()
170 if (width() < maxWidth && frameGeometry().x() > 0)
171 floatingGeometry_ = QRect(x(), y(), width(), height());
175 void QtView::resizeEvent(QResizeEvent *)
177 maxWidth = std::max(width(), maxWidth);
179 updateFloatingGeometry();
183 void QtView::moveEvent(QMoveEvent *)
185 updateFloatingGeometry();
189 void QtView::closeEvent(QCloseEvent *)
191 updateFloatingGeometry();
192 QRect geometry = floatingGeometry_;
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()));
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));
211 setCaption(qt_("LyX"));
213 updateFloatingGeometry();
217 void QtView::busy(bool yes) const
220 QApplication::setOverrideCursor(Qt::waitCursor);
222 QApplication::restoreOverrideCursor();
225 } // namespace frontend