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, bool maximize)
74 : QMainWindow(), LyXView(), commandbuffer_(0)
76 resize(width, height);
79 this->setWindowState(Qt::WindowMaximized);
83 // setToolButtonStyle(Qt::ToolButtonIconOnly);
84 // setIconSize(QSize(12,12));
86 bufferview_.reset(new BufferView(this, width, height));
88 menubar_.reset(new QLMenubar(this, menubackend));
89 connect(menuBar(), SIGNAL(triggered(QAction *)), this, SLOT(updateMenu(QAction *)));
93 statusBar()->setSizeGripEnabled(false);
95 view_state_changed.connect(boost::bind(&QtView::update_view_state, this));
96 connect(&statusbar_timer_, SIGNAL(timeout()), this, SLOT(update_view_state_qt()));
99 // assign an icon to main form. We do not do it under Qt/Mac,
100 // since the icon is provided in the application bundle.
101 string const iconname = libFileSearch("images", "lyx", "xpm");
102 if (!iconname.empty())
103 setWindowIcon(QPixmap(toqstr(iconname)));
106 // make sure the buttons are disabled if needed
115 void QtView::updateMenu(QAction *action)
120 void QtView::setWindowTitle(string const & t, string const & it)
122 QMainWindow::setWindowTitle(toqstr(t));
123 QMainWindow::setWindowIconText(toqstr(it));
127 void QtView::addCommandBuffer(QToolBar * toolbar)
129 commandbuffer_ = new QCommandBuffer(this, *controlcommand_);
130 focus_command_buffer.connect(boost::bind(&QtView::focus_command_widget, this));
131 toolbar->addWidget(commandbuffer_);
135 void QtView::message(string const & str)
137 statusBar()->showMessage(toqstr(str));
138 statusbar_timer_.stop();
139 statusbar_timer_.start(statusbar_timer_value);
143 void QtView::clearMessage()
145 update_view_state_qt();
149 void QtView::focus_command_widget()
152 commandbuffer_->focus_command();
156 void QtView::update_view_state_qt()
158 statusBar()->showMessage(toqstr(getLyXFunc().viewStatusMessage()));
159 statusbar_timer_.stop();
163 void QtView::update_view_state()
165 // let the user see the explicit message
166 if (statusbar_timer_.isActive())
169 statusBar()->showMessage(toqstr(getLyXFunc().viewStatusMessage()));
173 void QtView::activated(FuncRequest const & func)
175 getLyXFunc().dispatch(func);
179 bool QtView::hasFocus() const
181 return qApp->activeWindow() == this;
185 void QtView::closeEvent(QCloseEvent *)
187 // save windows size and position
188 LyX::ref().session().saveSessionInfo("WindowWidth", convert<string>(this->normalGeometry().width()));
189 LyX::ref().session().saveSessionInfo("WindowHeight", convert<string>(this->normalGeometry().height()));
190 LyX::ref().session().saveSessionInfo("WindowIsMaximized", (this->isMaximized() ? "yes" : "no"));
191 if (lyxrc.geometry_xysaved) {
192 LyX::ref().session().saveSessionInfo("WindowPosX", convert<string>(this->normalGeometry().x()));
193 LyX::ref().session().saveSessionInfo("WindowPosY", convert<string>(this->normalGeometry().y()));
195 // trigger LFUN_LYX_QUIT instead of quit directly
196 // since LFUN_LYX_QUIT may have more cleanup stuff
197 getLyXFunc().dispatch(FuncRequest(LFUN_LYX_QUIT));
203 QMainWindow::setWindowTitle(qt_("LyX"));
208 void QtView::busy(bool yes) const
211 QApplication::setOverrideCursor(Qt::WaitCursor);
213 QApplication::restoreOverrideCursor();
216 QMainWindow* QtView::mainWidget()
221 QMainWindow* QtView::mainWidget_ = 0;
224 } // namespace frontend
227 #include "QtView_moc.cpp"