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"
30 #include "frontends/WorkArea.h"
31 #include "support/filetools.h"
32 #include "support/convert.h"
33 #include "support/lstrings.h"
35 // This include must be declared before everything else because
36 // of boost/Qt/LyX clash...
37 #include "GuiImplementation.h"
40 #include "QLMenubar.h"
41 #include "FontLoader.h"
42 #include "QCommandBuffer.h"
43 #include "qt_helpers.h"
45 #include <QApplication>
49 #include <QCloseEvent>
53 #include <boost/bind.hpp>
62 using support::libFileSearch;
68 int const statusbar_timer_value = 3000;
73 GuiView::GuiView(Gui & owner)
74 : QMainWindow(), LyXView(owner), commandbuffer_(0)
76 // setToolButtonStyle(Qt::ToolButtonIconOnly);
77 // setIconSize(QSize(12,12));
79 // bufferview_.reset(new BufferView(this, width, height));
82 // assign an icon to main form. We do not do it under Qt/Mac,
83 // since the icon is provided in the application bundle.
84 string const iconname = libFileSearch("images", "lyx", "xpm");
85 if (!iconname.empty())
86 setWindowIcon(QPixmap(toqstr(iconname)));
98 menubar_.reset(new QLMenubar(this, menubackend));
99 QObject::connect(menuBar(), SIGNAL(triggered(QAction *)), this, SLOT(updateMenu(QAction *)));
101 getToolbars().init();
103 statusBar()->setSizeGripEnabled(false);
105 QObject::connect(&statusbar_timer_, SIGNAL(timeout()), this, SLOT(update_view_state_qt()));
107 // make sure the buttons are disabled if needed
113 void GuiView::updateMenu(QAction * /*action*/)
119 void GuiView::setWindowTitle(string const & t, string const & it)
121 QMainWindow::setWindowTitle(toqstr(t));
122 QMainWindow::setWindowIconText(toqstr(it));
126 void GuiView::addCommandBuffer(QToolBar * toolbar)
128 commandbuffer_ = new QCommandBuffer(this, *controlcommand_);
129 focus_command_buffer.connect(boost::bind(&GuiView::focus_command_widget, this));
130 toolbar->addWidget(commandbuffer_);
134 void GuiView::message(string const & str)
136 statusBar()->showMessage(toqstr(str));
137 statusbar_timer_.stop();
138 statusbar_timer_.start(statusbar_timer_value);
142 void GuiView::clearMessage()
144 update_view_state_qt();
148 void GuiView::focus_command_widget()
151 commandbuffer_->focus_command();
155 void GuiView::update_view_state_qt()
157 statusBar()->showMessage(toqstr(getLyXFunc().viewStatusMessage()));
158 statusbar_timer_.stop();
162 void GuiView::updateStatusBar()
164 // let the user see the explicit message
165 if (statusbar_timer_.isActive())
168 statusBar()->showMessage(toqstr(getLyXFunc().viewStatusMessage()));
172 void GuiView::activated(FuncRequest const & func)
174 getLyXFunc().dispatch(func);
178 bool GuiView::hasFocus() const
180 return qApp->activeWindow() == this;
184 void GuiView::updateFloatingGeometry()
187 floatingGeometry_ = QRect(x(), y(), width(), height());
191 void GuiView::resizeEvent(QResizeEvent *)
193 updateFloatingGeometry();
197 void GuiView::moveEvent(QMoveEvent *)
199 updateFloatingGeometry();
203 void GuiView::closeEvent(QCloseEvent *)
206 // change the ifdef to 'geometry = normalGeometry();' only
207 // when Trolltech has fixed the broken normalGeometry on X11:
208 // http://www.trolltech.com/developer/task-tracker/index_html?id=119684+&method=entry
209 // Then also the moveEvent, resizeEvent, and the
210 // code for floatingGeometry_ can be removed;
211 // adjust lyx_gui::start
213 QRect geometry = normalGeometry();
215 updateFloatingGeometry();
216 QRect geometry = floatingGeometry_;
219 // save windows size and position
220 Session & session = LyX::ref().session();
221 session.saveSessionInfo("WindowWidth", convert<string>(geometry.width()));
222 session.saveSessionInfo("WindowHeight", convert<string>(geometry.height()));
223 session.saveSessionInfo("WindowIsMaximized", (isMaximized() ? "yes" : "no"));
224 if (lyxrc.geometry_xysaved) {
225 session.saveSessionInfo("WindowPosX", convert<string>(geometry.x()));
226 session.saveSessionInfo("WindowPosY", convert<string>(geometry.y()));
228 // trigger LFUN_LYX_QUIT instead of quit directly
229 // since LFUN_LYX_QUIT may have more cleanup stuff
230 getLyXFunc().dispatch(FuncRequest(LFUN_LYX_QUIT));
236 QMainWindow::setWindowTitle(qt_("LyX"));
238 updateFloatingGeometry();
242 void GuiView::busy(bool yes) const
245 QApplication::setOverrideCursor(Qt::WaitCursor);
247 QApplication::restoreOverrideCursor();
250 } // namespace frontend
253 #include "GuiView_moc.cpp"