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"
43 #include <QApplication>
44 #include <QCloseEvent>
50 #include <boost/bind.hpp>
59 using support::libFileSearch;
65 int const statusbar_timer_value = 3000;
70 GuiView::GuiView(int id)
71 : QMainWindow(), LyXView(id), commandbuffer_(0)
73 setAttribute(Qt::WA_DeleteOnClose, true);
74 setAttribute(Qt::WA_QuitOnClose, true);
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)));
104 menubar_.reset(new QLMenubar(this, menubackend));
105 QObject::connect(menuBar(), SIGNAL(triggered(QAction *)),
106 this, SLOT(updateMenu(QAction *)));
108 getToolbars().init();
110 statusBar()->setSizeGripEnabled(false);
112 QObject::connect(&statusbar_timer_, SIGNAL(timeout()),
113 this, SLOT(update_view_state_qt()));
115 // make sure the buttons are disabled if needed
117 updateLayoutChoice();
122 void GuiView::saveGeometry()
125 // change the ifdef to 'geometry = normalGeometry();' only
126 // when Trolltech has fixed the broken normalGeometry on X11:
127 // http://www.trolltech.com/developer/task-tracker/index_html?id=119684+&method=entry
128 // Then also the moveEvent, resizeEvent, and the
129 // code for floatingGeometry_ can be removed;
130 // adjust GuiView::setGeometry()
132 QRect geometry = normalGeometry();
134 updateFloatingGeometry();
135 QRect geometry = floatingGeometry_;
138 // save windows size and position
139 Session & session = LyX::ref().session();
140 session.saveSessionInfo("WindowWidth", convert<string>(geometry.width()));
141 session.saveSessionInfo("WindowHeight", convert<string>(geometry.height()));
142 session.saveSessionInfo("WindowIsMaximized", (isMaximized() ? "yes" : "no"));
143 if (lyxrc.geometry_xysaved) {
144 session.saveSessionInfo("WindowPosX", convert<string>(geometry.x()));
145 session.saveSessionInfo("WindowPosY", convert<string>(geometry.y()));
149 void GuiView::setGeometry(unsigned int width,
154 // only true when the -geometry option was NOT used
155 if (width != 0 && height != 0) {
156 if (posx != -1 && posy != -1) {
158 // FIXME: use only setGeoemtry when Trolltech has
159 // fixed the qt4/X11 bug
160 QMainWindow::setGeometry(posx, posy,width, height);
162 resize(width, height);
166 resize(width, height);
170 setWindowState(Qt::WindowMaximized);
177 void GuiView::updateMenu(QAction * /*action*/)
183 void GuiView::setWindowTitle(docstring const & t, docstring const & it)
185 QMainWindow::setWindowTitle(toqstr(t));
186 QMainWindow::setWindowIconText(toqstr(it));
190 void GuiView::addCommandBuffer(QToolBar * toolbar)
192 commandbuffer_ = new QCommandBuffer(this, *controlcommand_);
193 focus_command_buffer.connect(boost::bind(&GuiView::focus_command_widget, this));
194 toolbar->addWidget(commandbuffer_);
198 void GuiView::message(docstring const & str)
200 statusBar()->showMessage(toqstr(str));
201 statusbar_timer_.stop();
202 statusbar_timer_.start(statusbar_timer_value);
206 void GuiView::clearMessage()
208 update_view_state_qt();
212 void GuiView::focus_command_widget()
215 commandbuffer_->focus_command();
219 void GuiView::update_view_state_qt()
221 statusBar()->showMessage(toqstr(theLyXFunc().viewStatusMessage()));
222 statusbar_timer_.stop();
226 void GuiView::updateStatusBar()
228 // let the user see the explicit message
229 if (statusbar_timer_.isActive())
232 statusBar()->showMessage(toqstr(theLyXFunc().viewStatusMessage()));
236 void GuiView::activated(FuncRequest const & func)
242 bool GuiView::hasFocus() const
244 return qApp->activeWindow() == this;
248 void GuiView::updateFloatingGeometry()
251 floatingGeometry_ = QRect(x(), y(), width(), height());
255 void GuiView::resizeEvent(QResizeEvent *)
257 updateFloatingGeometry();
261 void GuiView::moveEvent(QMoveEvent *)
263 updateFloatingGeometry();
267 void GuiView::closeEvent(QCloseEvent *)
275 QMainWindow::setWindowTitle(qt_("LyX"));
277 updateFloatingGeometry();
281 void GuiView::busy(bool yes) const
284 QApplication::setOverrideCursor(Qt::WaitCursor);
286 QApplication::restoreOverrideCursor();
290 Toolbars::ToolbarPtr GuiView::makeToolbar(ToolbarBackend::Toolbar const & tbb)
292 QLToolbar * Tb = new QLToolbar(tbb, *this);
293 static QLToolbar * lastTb = 0;
295 if (tbb.flags & ToolbarBackend::TOP) {
296 addToolBar(Qt::TopToolBarArea, Tb);
297 addToolBarBreak(Qt::TopToolBarArea);
299 if (tbb.flags & ToolbarBackend::BOTTOM) {
300 addToolBar(Qt::BottomToolBarArea, Tb);
302 insertToolBarBreak(lastTb);
305 if (tbb.flags & ToolbarBackend::LEFT) {
306 addToolBar(Qt::LeftToolBarArea, Tb);
308 if (tbb.flags & ToolbarBackend::RIGHT) {
309 addToolBar(Qt::RightToolBarArea, Tb);
312 return Toolbars::ToolbarPtr(Tb);
315 } // namespace frontend
318 #include "GuiView_moc.cpp"