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 "GuiImplementation.h"
18 #include "GuiWorkArea.h"
19 #include "QLMenubar.h"
20 #include "QLToolbar.h"
21 #include "QCommandBuffer.h"
22 #include "qt_helpers.h"
24 #include "frontends/Application.h"
25 #include "frontends/Gui.h"
26 #include "frontends/WorkArea.h"
28 #include "support/filetools.h"
29 #include "support/convert.h"
30 #include "support/lstrings.h"
32 #include "BufferView.h"
33 #include "bufferlist.h"
35 #include "funcrequest.h"
41 #include "MenuBackend.h"
44 #include <QApplication>
45 #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 * close_event)
269 GuiImplementation & gui
270 = static_cast<GuiImplementation &>(theApp->gui());
272 vector<int> const & view_ids = gui.viewIds();
274 if (view_ids.size() == 1 && !theBufferList().quitWriteAll()) {
275 close_event->ignore();
280 gui.unregisterView(this);
286 QMainWindow::setWindowTitle(qt_("LyX"));
288 updateFloatingGeometry();
292 void GuiView::busy(bool yes)
294 static_cast<GuiWorkArea *>(work_area_)->setUpdatesEnabled(!yes);
297 work_area_->stopBlinkingCursor();
298 QApplication::setOverrideCursor(Qt::WaitCursor);
301 work_area_->startBlinkingCursor();
302 QApplication::restoreOverrideCursor();
307 Toolbars::ToolbarPtr GuiView::makeToolbar(ToolbarBackend::Toolbar const & tbb)
309 QLToolbar * Tb = new QLToolbar(tbb, *this);
310 static QLToolbar * lastTb = 0;
312 if (tbb.flags & ToolbarBackend::TOP) {
313 addToolBar(Qt::TopToolBarArea, Tb);
314 addToolBarBreak(Qt::TopToolBarArea);
316 if (tbb.flags & ToolbarBackend::BOTTOM) {
317 addToolBar(Qt::BottomToolBarArea, Tb);
319 insertToolBarBreak(lastTb);
322 if (tbb.flags & ToolbarBackend::LEFT) {
323 addToolBar(Qt::LeftToolBarArea, Tb);
325 if (tbb.flags & ToolbarBackend::RIGHT) {
326 addToolBar(Qt::RightToolBarArea, Tb);
329 return Toolbars::ToolbarPtr(Tb);
332 } // namespace frontend
335 #include "GuiView_moc.cpp"