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.
15 #include "BufferView.h"
21 #include "MenuBackend.h"
22 #include "funcrequest.h"
23 #include "funcrequest.h"
27 #include "frontends/Toolbars.h"
29 #include "support/filetools.h"
31 #include "support/convert.h"
32 #include <boost/bind.hpp>
35 #include "QLMenubar.h"
36 #include "qfont_loader.h"
37 #include "QCommandBuffer.h"
38 #include "qt_helpers.h"
40 #include <QApplication>
44 #include <QCloseEvent>
49 #include "support/lstrings.h"
55 FontLoader fontloader;
60 using support::libFileSearch;
66 int const statusbar_timer_value = 3000;
71 QtView::QtView(unsigned int width, unsigned int height)
72 : QMainWindow(), LyXView(), commandbuffer_(0)
74 resize(width, height);
76 qApp->setMainWidget(this);
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 setIcon(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()->message(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()->message(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()->message(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 // save windows size and position
183 LyX::ref().session().saveSessionInfo("WindowWidth", convert<string>(width()));
184 LyX::ref().session().saveSessionInfo("WindowHeight", convert<string>(height()));
185 if (lyxrc.geometry_xysaved) {
186 LyX::ref().session().saveSessionInfo("WindowPosX", convert<string>(x()));
187 LyX::ref().session().saveSessionInfo("WindowPosY", convert<string>(y()));
189 // trigger LFUN_QUIT instead of quit directly
190 // since LFUN_QUIT may have more cleanup stuff
191 getLyXFunc().dispatch(FuncRequest(LFUN_QUIT));
197 setCaption(qt_("LyX"));
202 void QtView::busy(bool yes) const
205 QApplication::setOverrideCursor(Qt::waitCursor);
207 QApplication::restoreOverrideCursor();
210 } // namespace frontend