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, bool maximize)
59 : QMainWindow(), LyXView(), commandbuffer_(0)
61 resize(width, height);
64 this->setWindowState(WindowMaximized);
66 qApp->setMainWidget(this);
68 bufferview_.reset(new BufferView(this, width, height));
70 menubar_.reset(new QLMenubar(this, menubackend));
73 statusBar()->setSizeGripEnabled(false);
75 view_state_changed.connect(boost::bind(&QtView::update_view_state, this));
76 connect(&statusbar_timer_, SIGNAL(timeout()), this, SLOT(update_view_state_qt()));
79 // assign an icon to main form. We do not do it under Qt/Mac,
80 // since the icon is provided in the application bundle.
81 string const iconname = libFileSearch("images", "lyx", "xpm");
82 if (!iconname.empty())
83 setIcon(QPixmap(toqstr(iconname)));
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);
100 void QtView::setWindowTitle(string const & t, string const & it)
102 setCaption(toqstr(t));
103 setIconText(toqstr(it));
107 void QtView::addCommandBuffer(QWidget * parent)
109 commandbuffer_ = new QCommandBuffer(this, parent, *controlcommand_);
110 focus_command_buffer.connect(boost::bind(&QtView::focus_command_widget, this));
114 void QtView::message(string const & str)
116 statusBar()->message(toqstr(str));
117 statusbar_timer_.stop();
118 statusbar_timer_.start(statusbar_timer_value);
122 void QtView::clearMessage()
124 update_view_state_qt();
128 void QtView::focus_command_widget()
131 commandbuffer_->focus_command();
135 void QtView::update_view_state_qt()
137 statusBar()->message(toqstr(getLyXFunc().viewStatusMessage()));
138 statusbar_timer_.stop();
142 void QtView::update_view_state()
144 // let the user see the explicit message
145 if (statusbar_timer_.isActive())
148 statusBar()->message(toqstr(getLyXFunc().viewStatusMessage()));
152 void QtView::activated(FuncRequest const & func)
154 getLyXFunc().dispatch(func);
158 bool QtView::hasFocus() const
160 return qApp->activeWindow() == this;
164 void QtView::closeEvent(QCloseEvent *)
166 LyX::ref().session().saveSessionInfo("WindowIsMaximized", (this->isMaximized() ? "yes" : "no"));
167 // don't save maximized values
169 // save windows size and position
170 LyX::ref().session().saveSessionInfo("WindowWidth", convert<string>(width()));
171 LyX::ref().session().saveSessionInfo("WindowHeight", convert<string>(height()));
172 if (lyxrc.geometry_xysaved) {
173 LyX::ref().session().saveSessionInfo("WindowPosX", convert<string>(x()));
174 LyX::ref().session().saveSessionInfo("WindowPosY", convert<string>(y()));
176 // trigger LFUN_LYX_QUIT instead of quit directly
177 // since LFUN_LYX_QUIT may have more cleanup stuff
178 getLyXFunc().dispatch(FuncRequest(LFUN_LYX_QUIT));
184 setCaption(qt_("LyX"));
189 void QtView::busy(bool yes) const
192 QApplication::setOverrideCursor(Qt::waitCursor);
194 QApplication::restoreOverrideCursor();
197 } // namespace frontend