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.
17 #include "BufferView.h"
23 #include "MenuBackend.h"
24 #include "funcrequest.h"
25 #include "funcrequest.h"
29 #include "frontends/Toolbars.h"
31 #include "support/filetools.h"
33 #include "support/convert.h"
34 #include <boost/bind.hpp>
37 #include "QLMenubar.h"
38 #include "qfont_loader.h"
39 #include "QCommandBuffer.h"
40 #include "qt_helpers.h"
42 #include <QApplication>
46 #include <QCloseEvent>
51 #include "support/lstrings.h"
57 FontLoader fontloader;
62 using support::libFileSearch;
68 int const statusbar_timer_value = 3000;
73 QtView::QtView(unsigned int width, unsigned int height)
74 : QMainWindow(), LyXView(), commandbuffer_(0)
78 // setToolButtonStyle(Qt::ToolButtonIconOnly);
79 // setIconSize(QSize(12,12));
81 bufferview_.reset(new BufferView(this, width, height));
83 menubar_.reset(new QLMenubar(this, menubackend));
84 connect(menuBar(), SIGNAL(triggered(QAction *)), this, SLOT(updateMenu(QAction *)));
88 statusBar()->setSizeGripEnabled(false);
90 view_state_changed.connect(boost::bind(&QtView::update_view_state, this));
91 connect(&statusbar_timer_, SIGNAL(timeout()), this, SLOT(update_view_state_qt()));
94 // assign an icon to main form. We do not do it under Qt/Mac,
95 // since the icon is provided in the application bundle.
96 string const iconname = libFileSearch("images", "lyx", "xpm");
97 if (!iconname.empty())
98 setWindowIcon(QPixmap(toqstr(iconname)));
101 // make sure the buttons are disabled if needed
110 void QtView::updateMenu(QAction *action)
115 void QtView::setWindowTitle(string const & t, string const & it)
117 QMainWindow::setWindowTitle(toqstr(t));
118 QMainWindow::setWindowIconText(toqstr(it));
122 void QtView::addCommandBuffer(QToolBar * toolbar)
124 commandbuffer_ = new QCommandBuffer(this, *controlcommand_);
125 focus_command_buffer.connect(boost::bind(&QtView::focus_command_widget, this));
126 toolbar->addWidget(commandbuffer_);
130 void QtView::message(string const & str)
132 statusBar()->showMessage(toqstr(str));
133 statusbar_timer_.stop();
134 statusbar_timer_.start(statusbar_timer_value);
138 void QtView::clearMessage()
140 update_view_state_qt();
144 void QtView::focus_command_widget()
147 commandbuffer_->focus_command();
151 void QtView::update_view_state_qt()
153 statusBar()->showMessage(toqstr(getLyXFunc().viewStatusMessage()));
154 statusbar_timer_.stop();
158 void QtView::update_view_state()
160 // let the user see the explicit message
161 if (statusbar_timer_.isActive())
164 statusBar()->showMessage(toqstr(getLyXFunc().viewStatusMessage()));
168 void QtView::activated(FuncRequest const & func)
170 getLyXFunc().dispatch(func);
174 bool QtView::hasFocus() const
176 return qApp->activeWindow() == this;
180 void QtView::closeEvent(QCloseEvent *)
182 QRect geometry = normalGeometry();
183 Session & session = LyX::ref().session();
184 // save windows size and position
185 session.saveSessionInfo("WindowWidth", convert<string>(geometry.width()));
186 session.saveSessionInfo("WindowHeight", convert<string>(geometry.height()));
187 session.saveSessionInfo("WindowIsMaximized", (isMaximized() ? "yes" : "no"));
188 if (lyxrc.geometry_xysaved) {
189 session.saveSessionInfo("WindowPosX", convert<string>(geometry.x()));
190 session.saveSessionInfo("WindowPosY", convert<string>(geometry.y()));
192 // trigger LFUN_LYX_QUIT instead of quit directly
193 // since LFUN_LYX_QUIT may have more cleanup stuff
194 getLyXFunc().dispatch(FuncRequest(LFUN_LYX_QUIT));
200 QMainWindow::setWindowTitle(qt_("LyX"));
205 void QtView::busy(bool yes) const
208 QApplication::setOverrideCursor(Qt::WaitCursor);
210 QApplication::restoreOverrideCursor();
213 QMainWindow* QtView::mainWidget()
218 QMainWindow* QtView::mainWidget_ = 0;
221 } // namespace frontend
224 #include "QtView_moc.cpp"