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 "GuiImplementation.h"
38 #include "QLMenubar.h"
39 #include "FontLoader.h"
40 #include "QCommandBuffer.h"
41 #include "qt_helpers.h"
43 #include <QApplication>
47 #include <QCloseEvent>
52 #include "support/lstrings.h"
61 using support::libFileSearch;
67 int const statusbar_timer_value = 3000;
72 GuiView::GuiView(Gui & owner)
73 : QMainWindow(), LyXView(owner), commandbuffer_(0)
77 // setToolButtonStyle(Qt::ToolButtonIconOnly);
78 // setIconSize(QSize(12,12));
80 // bufferview_.reset(new BufferView(this, width, height));
83 // assign an icon to main form. We do not do it under Qt/Mac,
84 // since the icon is provided in the application bundle.
85 string const iconname = libFileSearch("images", "lyx", "xpm");
86 if (!iconname.empty())
87 setWindowIcon(QPixmap(toqstr(iconname)));
99 menubar_.reset(new QLMenubar(this, menubackend));
100 QObject::connect(menuBar(), SIGNAL(triggered(QAction *)), this, SLOT(updateMenu(QAction *)));
102 getToolbars().init();
104 statusBar()->setSizeGripEnabled(false);
106 view_state_changed.connect(boost::bind(&GuiView::update_view_state, this));
107 QObject::connect(&statusbar_timer_, SIGNAL(timeout()), this, SLOT(update_view_state_qt()));
109 // make sure the buttons are disabled if needed
115 void GuiView::updateMenu(QAction *action)
121 void GuiView::setWindowTitle(string const & t, string const & it)
123 QMainWindow::setWindowTitle(toqstr(t));
124 QMainWindow::setWindowIconText(toqstr(it));
128 void GuiView::addCommandBuffer(QToolBar * toolbar)
130 commandbuffer_ = new QCommandBuffer(this, *controlcommand_);
131 focus_command_buffer.connect(boost::bind(&GuiView::focus_command_widget, this));
132 toolbar->addWidget(commandbuffer_);
136 void GuiView::message(string const & str)
138 statusBar()->showMessage(toqstr(str));
139 statusbar_timer_.stop();
140 statusbar_timer_.start(statusbar_timer_value);
144 void GuiView::clearMessage()
146 update_view_state_qt();
150 void GuiView::focus_command_widget()
153 commandbuffer_->focus_command();
157 void GuiView::update_view_state_qt()
159 statusBar()->showMessage(toqstr(getLyXFunc().viewStatusMessage()));
160 statusbar_timer_.stop();
164 void GuiView::update_view_state()
166 // let the user see the explicit message
167 if (statusbar_timer_.isActive())
170 statusBar()->showMessage(toqstr(getLyXFunc().viewStatusMessage()));
174 void GuiView::activated(FuncRequest const & func)
176 getLyXFunc().dispatch(func);
180 bool GuiView::hasFocus() const
182 return qApp->activeWindow() == this;
186 void GuiView::updateFloatingGeometry()
189 floatingGeometry_ = QRect(x(), y(), width(), height());
193 void GuiView::resizeEvent(QResizeEvent *)
195 updateFloatingGeometry();
199 void GuiView::moveEvent(QMoveEvent *)
201 updateFloatingGeometry();
205 void GuiView::closeEvent(QCloseEvent *)
208 // change the ifdef to 'geometry = normalGeometry();' only
209 // when Trolltech has fixed the broken normalGeometry on X11:
210 // http://www.trolltech.com/developer/task-tracker/index_html?id=119684+&method=entry
211 // Then also the moveEvent, resizeEvent, and the
212 // code for floatingGeometry_ can be removed;
213 // adjust lyx_gui::start
215 QRect geometry = normalGeometry();
217 updateFloatingGeometry();
218 QRect geometry = floatingGeometry_;
221 // save windows size and position
222 Session & session = LyX::ref().session();
223 session.saveSessionInfo("WindowWidth", convert<string>(geometry.width()));
224 session.saveSessionInfo("WindowHeight", convert<string>(geometry.height()));
225 session.saveSessionInfo("WindowIsMaximized", (isMaximized() ? "yes" : "no"));
226 if (lyxrc.geometry_xysaved) {
227 session.saveSessionInfo("WindowPosX", convert<string>(geometry.x()));
228 session.saveSessionInfo("WindowPosY", convert<string>(geometry.y()));
230 // trigger LFUN_LYX_QUIT instead of quit directly
231 // since LFUN_LYX_QUIT may have more cleanup stuff
232 getLyXFunc().dispatch(FuncRequest(LFUN_LYX_QUIT));
238 QMainWindow::setWindowTitle(qt_("LyX"));
240 updateFloatingGeometry();
244 void GuiView::busy(bool yes) const
247 QApplication::setOverrideCursor(Qt::WaitCursor);
249 QApplication::restoreOverrideCursor();
253 QMainWindow* GuiView::mainWidget()
258 QMainWindow* GuiView::mainWidget_ = 0;
261 } // namespace frontend
264 #include "GuiView_moc.cpp"