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/WorkArea.h"
28 #include "support/filetools.h"
29 #include "support/convert.h"
30 #include "support/lstrings.h"
32 // This include must be declared before everything else because
33 // of boost/Qt/LyX clash...
34 #include "GuiImplementation.h"
37 #include "QLMenubar.h"
38 #include "QLToolbar.h"
39 #include "QCommandBuffer.h"
40 #include "qt_helpers.h"
42 #include <QApplication>
46 #include <QCloseEvent>
50 #include <boost/bind.hpp>
59 using support::libFileSearch;
65 int const statusbar_timer_value = 3000;
71 : QMainWindow(), LyXView(), commandbuffer_(0)
73 // setToolButtonStyle(Qt::ToolButtonIconOnly);
74 // setIconSize(QSize(12,12));
76 // bufferview_.reset(new BufferView(this, width, height));
79 // assign an icon to main form. We do not do it under Qt/Mac,
80 // since the icon is provided in the application bundle.
81 string const iconname = libFileSearch("images", "lyx", "xpm");
82 if (!iconname.empty())
83 setWindowIcon(QPixmap(toqstr(iconname)));
95 menubar_.reset(new QLMenubar(this, menubackend));
96 QObject::connect(menuBar(), SIGNAL(triggered(QAction *)), this, SLOT(updateMenu(QAction *)));
100 statusBar()->setSizeGripEnabled(false);
102 QObject::connect(&statusbar_timer_, SIGNAL(timeout()), this, SLOT(update_view_state_qt()));
104 // make sure the buttons are disabled if needed
106 updateLayoutChoice();
111 void GuiView::setGeometry(unsigned int width,
116 // only true when the -geometry option was NOT used
117 if (width != 0 && height != 0) {
118 if (posx != -1 && posy != -1) {
120 // FIXME: use only setGeoemtry when Trolltech has
121 // fixed the qt4/X11 bug
122 QMainWindow::setGeometry(posx, posy,width, height);
124 resize(width, height);
128 resize(width, height);
132 setWindowState(Qt::WindowMaximized);
139 void GuiView::updateMenu(QAction * /*action*/)
145 void GuiView::setWindowTitle(docstring const & t, docstring const & it)
147 QMainWindow::setWindowTitle(toqstr(t));
148 QMainWindow::setWindowIconText(toqstr(it));
152 void GuiView::addCommandBuffer(QToolBar * toolbar)
154 commandbuffer_ = new QCommandBuffer(this, *controlcommand_);
155 focus_command_buffer.connect(boost::bind(&GuiView::focus_command_widget, this));
156 toolbar->addWidget(commandbuffer_);
160 void GuiView::message(docstring const & str)
162 statusBar()->showMessage(toqstr(str));
163 statusbar_timer_.stop();
164 statusbar_timer_.start(statusbar_timer_value);
168 void GuiView::clearMessage()
170 update_view_state_qt();
174 void GuiView::focus_command_widget()
177 commandbuffer_->focus_command();
181 void GuiView::update_view_state_qt()
183 statusBar()->showMessage(toqstr(theLyXFunc().viewStatusMessage()));
184 statusbar_timer_.stop();
188 void GuiView::updateStatusBar()
190 // let the user see the explicit message
191 if (statusbar_timer_.isActive())
194 statusBar()->showMessage(toqstr(theLyXFunc().viewStatusMessage()));
198 void GuiView::activated(FuncRequest const & func)
204 bool GuiView::hasFocus() const
206 return qApp->activeWindow() == this;
210 void GuiView::updateFloatingGeometry()
213 floatingGeometry_ = QRect(x(), y(), width(), height());
217 void GuiView::resizeEvent(QResizeEvent *)
219 updateFloatingGeometry();
223 void GuiView::moveEvent(QMoveEvent *)
225 updateFloatingGeometry();
229 void GuiView::closeEvent(QCloseEvent *)
232 // change the ifdef to 'geometry = normalGeometry();' only
233 // when Trolltech has fixed the broken normalGeometry on X11:
234 // http://www.trolltech.com/developer/task-tracker/index_html?id=119684+&method=entry
235 // Then also the moveEvent, resizeEvent, and the
236 // code for floatingGeometry_ can be removed;
237 // adjust GuiView::setGeometry()
239 QRect geometry = normalGeometry();
241 updateFloatingGeometry();
242 QRect geometry = floatingGeometry_;
245 // save windows size and position
246 Session & session = LyX::ref().session();
247 session.saveSessionInfo("WindowWidth", convert<string>(geometry.width()));
248 session.saveSessionInfo("WindowHeight", convert<string>(geometry.height()));
249 session.saveSessionInfo("WindowIsMaximized", (isMaximized() ? "yes" : "no"));
250 if (lyxrc.geometry_xysaved) {
251 session.saveSessionInfo("WindowPosX", convert<string>(geometry.x()));
252 session.saveSessionInfo("WindowPosY", convert<string>(geometry.y()));
254 // trigger LFUN_LYX_QUIT instead of quit directly
255 // since LFUN_LYX_QUIT may have more cleanup stuff
256 dispatch(FuncRequest(LFUN_LYX_QUIT));
262 QMainWindow::setWindowTitle(qt_("LyX"));
264 updateFloatingGeometry();
268 void GuiView::busy(bool yes) const
271 QApplication::setOverrideCursor(Qt::WaitCursor);
273 QApplication::restoreOverrideCursor();
277 Toolbars::ToolbarPtr GuiView::makeToolbar(ToolbarBackend::Toolbar const & tbb)
279 QLToolbar * Tb = new QLToolbar(tbb, *this);
280 static QLToolbar * lastTb = 0;
282 if (tbb.flags & ToolbarBackend::TOP) {
283 addToolBar(Qt::TopToolBarArea, Tb);
284 addToolBarBreak(Qt::TopToolBarArea);
286 if (tbb.flags & ToolbarBackend::BOTTOM) {
287 addToolBar(Qt::BottomToolBarArea, Tb);
289 insertToolBarBreak(lastTb);
292 if (tbb.flags & ToolbarBackend::LEFT) {
293 addToolBar(Qt::LeftToolBarArea, Tb);
295 if (tbb.flags & ToolbarBackend::RIGHT) {
296 addToolBar(Qt::RightToolBarArea, Tb);
299 return Toolbars::ToolbarPtr(Tb);
302 } // namespace frontend
305 #include "GuiView_moc.cpp"