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)
76 resize(width, height);
80 // setToolButtonStyle(Qt::ToolButtonIconOnly);
81 // setIconSize(QSize(12,12));
83 bufferview_.reset(new BufferView(this, width, height));
85 menubar_.reset(new QLMenubar(this, menubackend));
86 connect(menuBar(), SIGNAL(triggered(QAction *)), this, SLOT(updateMenu(QAction *)));
90 statusBar()->setSizeGripEnabled(false);
92 view_state_changed.connect(boost::bind(&QtView::update_view_state, this));
93 connect(&statusbar_timer_, SIGNAL(timeout()), this, SLOT(update_view_state_qt()));
96 // assign an icon to main form. We do not do it under Qt/Mac,
97 // since the icon is provided in the application bundle.
98 string const iconname = libFileSearch("images", "lyx", "xpm");
99 if (!iconname.empty())
100 setWindowIcon(QPixmap(toqstr(iconname)));
103 // make sure the buttons are disabled if needed
112 void QtView::updateMenu(QAction *action)
117 void QtView::setWindowTitle(string const & t, string const & it)
119 QMainWindow::setWindowTitle(toqstr(t));
120 QMainWindow::setWindowIconText(toqstr(it));
124 void QtView::addCommandBuffer(QToolBar * toolbar)
126 commandbuffer_ = new QCommandBuffer(this, *controlcommand_);
127 focus_command_buffer.connect(boost::bind(&QtView::focus_command_widget, this));
128 toolbar->addWidget(commandbuffer_);
132 void QtView::message(string const & str)
134 statusBar()->showMessage(toqstr(str));
135 statusbar_timer_.stop();
136 statusbar_timer_.start(statusbar_timer_value);
140 void QtView::clearMessage()
142 update_view_state_qt();
146 void QtView::focus_command_widget()
149 commandbuffer_->focus_command();
153 void QtView::update_view_state_qt()
155 statusBar()->showMessage(toqstr(getLyXFunc().viewStatusMessage()));
156 statusbar_timer_.stop();
160 void QtView::update_view_state()
162 // let the user see the explicit message
163 if (statusbar_timer_.isActive())
166 statusBar()->showMessage(toqstr(getLyXFunc().viewStatusMessage()));
170 void QtView::activated(FuncRequest const & func)
172 getLyXFunc().dispatch(func);
176 bool QtView::hasFocus() const
178 return qApp->activeWindow() == this;
182 void QtView::closeEvent(QCloseEvent *)
184 // save windows size and position
185 LyX::ref().session().saveSessionInfo("WindowWidth", convert<string>(width()));
186 LyX::ref().session().saveSessionInfo("WindowHeight", convert<string>(height()));
187 if (lyxrc.geometry_xysaved) {
188 LyX::ref().session().saveSessionInfo("WindowPosX", convert<string>(x()));
189 LyX::ref().session().saveSessionInfo("WindowPosY", convert<string>(y()));
191 // trigger LFUN_LYX_QUIT instead of quit directly
192 // since LFUN_LYX_QUIT may have more cleanup stuff
193 getLyXFunc().dispatch(FuncRequest(LFUN_LYX_QUIT));
199 QMainWindow::setWindowTitle(qt_("LyX"));
204 void QtView::busy(bool yes) const
207 QApplication::setOverrideCursor(Qt::WaitCursor);
209 QApplication::restoreOverrideCursor();
212 QMainWindow* QtView::mainWidget()
217 QMainWindow* QtView::mainWidget_ = 0;
220 } // namespace frontend
223 #include "QtView_moc.cpp"