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;
58 QtView::QtView(unsigned int width, unsigned int height)
59 : QMainWindow(), LyXView(), commandbuffer_(0)
61 qApp->setMainWidget(this);
63 bufferview_.reset(new BufferView(this, width, height));
65 menubar_.reset(new QLMenubar(this, menubackend));
68 statusBar()->setSizeGripEnabled(false);
70 view_state_changed.connect(boost::bind(&QtView::update_view_state, this));
71 connect(&statusbar_timer_, SIGNAL(timeout()), this, SLOT(update_view_state_qt()));
74 // assign an icon to main form. We do not do it under Qt/Mac,
75 // since the icon is provided in the application bundle.
76 string const iconname = libFileSearch("images", "lyx", "xpm");
77 if (!iconname.empty())
78 setIcon(QPixmap(toqstr(iconname)));
81 // make sure the buttons are disabled if needed
84 // allowing the toolbars to tear off is too easily done,
85 // and we don't save their orientation anyway. Disable the handle.
86 setToolBarsMovable(false);
95 void QtView::setWindowTitle(string const & t, string const & it)
97 setCaption(toqstr(t));
98 setIconText(toqstr(it));
102 void QtView::addCommandBuffer(QWidget * parent)
104 commandbuffer_ = new QCommandBuffer(this, parent, *controlcommand_);
105 focus_command_buffer.connect(boost::bind(&QtView::focus_command_widget, this));
109 void QtView::message(string const & str)
111 statusBar()->message(toqstr(str));
112 statusbar_timer_.stop();
113 statusbar_timer_.start(statusbar_timer_value);
117 void QtView::clearMessage()
119 update_view_state_qt();
123 void QtView::focus_command_widget()
126 commandbuffer_->focus_command();
130 void QtView::update_view_state_qt()
132 statusBar()->message(toqstr(getLyXFunc().viewStatusMessage()));
133 statusbar_timer_.stop();
137 void QtView::update_view_state()
139 // let the user see the explicit message
140 if (statusbar_timer_.isActive())
143 statusBar()->message(toqstr(getLyXFunc().viewStatusMessage()));
147 void QtView::activated(FuncRequest const & func)
149 getLyXFunc().dispatch(func);
153 bool QtView::hasFocus() const
155 return qApp->activeWindow() == this;
159 void QtView::closeEvent(QCloseEvent *)
161 Session & session = LyX::ref().session();
162 session.saveSessionInfo("WindowIsMaximized", (isMaximized() ? "yes" : "no"));
163 // don't save maximized values
165 // save windows size and position
166 session.saveSessionInfo("WindowWidth", convert<string>(width()));
167 session.saveSessionInfo("WindowHeight", convert<string>(height()));
168 if (lyxrc.geometry_xysaved) {
169 session.saveSessionInfo("WindowPosX", convert<string>(x()));
170 session.saveSessionInfo("WindowPosY", convert<string>(y()));
172 // trigger LFUN_LYX_QUIT instead of quit directly
173 // since LFUN_LYX_QUIT may have more cleanup stuff
174 getLyXFunc().dispatch(FuncRequest(LFUN_LYX_QUIT));
180 setCaption(qt_("LyX"));
185 void QtView::busy(bool yes) const
188 QApplication::setOverrideCursor(Qt::waitCursor);
190 QApplication::restoreOverrideCursor();
193 } // namespace frontend