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>
49 #include <QDesktopWidget>
51 #include <boost/bind.hpp>
60 using support::libFileSearch;
66 int const statusbar_timer_value = 3000;
71 GuiView::GuiView(int id)
72 : QMainWindow(), LyXView(id), commandbuffer_(0)
74 setAttribute(Qt::WA_DeleteOnClose, true);
75 setAttribute(Qt::WA_QuitOnClose, true);
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)));
105 menubar_.reset(new QLMenubar(this, menubackend));
106 QObject::connect(menuBar(), SIGNAL(triggered(QAction *)),
107 this, SLOT(updateMenu(QAction *)));
109 getToolbars().init();
111 statusBar()->setSizeGripEnabled(false);
113 QObject::connect(&statusbar_timer_, SIGNAL(timeout()),
114 this, SLOT(update_view_state_qt()));
116 // make sure the buttons are disabled if needed
118 updateLayoutChoice();
123 void GuiView::saveGeometry()
126 // change the ifdef to 'geometry = normalGeometry();' only
127 // when Trolltech has fixed the broken normalGeometry on X11:
128 // http://www.trolltech.com/developer/task-tracker/index_html?id=119684+&method=entry
129 // Then also the moveEvent, resizeEvent, and the
130 // code for floatingGeometry_ can be removed;
131 // adjust GuiView::setGeometry()
133 QRect geometry = normalGeometry();
135 updateFloatingGeometry();
136 QRect geometry = floatingGeometry_;
139 // save windows size and position
140 Session & session = LyX::ref().session();
141 session.sessionInfo().save("WindowWidth", convert<string>(geometry.width()));
142 session.sessionInfo().save("WindowHeight", convert<string>(geometry.height()));
143 session.sessionInfo().save("WindowIsMaximized", (isMaximized() ? "yes" : "no"));
144 if (lyxrc.geometry_xysaved) {
145 session.sessionInfo().save("WindowPosX", convert<string>(geometry.x()));
146 session.sessionInfo().save("WindowPosY", convert<string>(geometry.y()));
150 void GuiView::setGeometry(unsigned int width,
155 // only true when the -geometry option was NOT used
156 if (width != 0 && height != 0) {
157 if (posx != -1 && posy != -1) {
158 // if there are ever startup positioning problems
159 // on a virtual desktop then check the 6 lines below
160 // http://doc.trolltech.com/4.2/qdesktopwidget.html
161 QDesktopWidget& dw = *qApp->desktop();
162 QRect desk = dw.availableGeometry(dw.primaryScreen());
163 (posx >= desk.width() ? posx = 50 : true);
164 (posy >= desk.height()? posy = 50 : true);
166 // FIXME: use only setGeoemtry when Trolltech has
167 // fixed the qt4/X11 bug
168 QMainWindow::setGeometry(posx, posy,width, height);
170 resize(width, height);
174 resize(width, height);
178 setWindowState(Qt::WindowMaximized);
185 void GuiView::updateMenu(QAction * /*action*/)
191 void GuiView::setWindowTitle(docstring const & t, docstring const & it)
193 QMainWindow::setWindowTitle(toqstr(t));
194 QMainWindow::setWindowIconText(toqstr(it));
198 void GuiView::addCommandBuffer(QToolBar * toolbar)
200 commandbuffer_ = new QCommandBuffer(this, *controlcommand_);
201 focus_command_buffer.connect(boost::bind(&GuiView::focus_command_widget, this));
202 toolbar->addWidget(commandbuffer_);
206 void GuiView::message(docstring const & str)
208 statusBar()->showMessage(toqstr(str));
209 statusbar_timer_.stop();
210 statusbar_timer_.start(statusbar_timer_value);
214 void GuiView::clearMessage()
216 update_view_state_qt();
220 void GuiView::focus_command_widget()
223 commandbuffer_->focus_command();
227 void GuiView::update_view_state_qt()
229 statusBar()->showMessage(toqstr(theLyXFunc().viewStatusMessage()));
230 statusbar_timer_.stop();
234 void GuiView::updateStatusBar()
236 // let the user see the explicit message
237 if (statusbar_timer_.isActive())
240 statusBar()->showMessage(toqstr(theLyXFunc().viewStatusMessage()));
244 void GuiView::activated(FuncRequest const & func)
250 bool GuiView::hasFocus() const
252 return qApp->activeWindow() == this;
256 void GuiView::updateFloatingGeometry()
259 floatingGeometry_ = QRect(x(), y(), width(), height());
263 void GuiView::resizeEvent(QResizeEvent *)
265 updateFloatingGeometry();
269 void GuiView::moveEvent(QMoveEvent *)
271 updateFloatingGeometry();
275 void GuiView::closeEvent(QCloseEvent * close_event)
277 GuiImplementation & gui
278 = static_cast<GuiImplementation &>(theApp->gui());
280 vector<int> const & view_ids = gui.viewIds();
282 if (view_ids.size() == 1 && !theBufferList().quitWriteAll()) {
283 close_event->ignore();
288 gui.unregisterView(this);
294 QMainWindow::setWindowTitle(qt_("LyX"));
296 updateFloatingGeometry();
300 void GuiView::busy(bool yes)
302 static_cast<GuiWorkArea *>(work_area_)->setUpdatesEnabled(!yes);
305 work_area_->stopBlinkingCursor();
306 QApplication::setOverrideCursor(Qt::WaitCursor);
309 work_area_->startBlinkingCursor();
310 QApplication::restoreOverrideCursor();
315 Toolbars::ToolbarPtr GuiView::makeToolbar(ToolbarBackend::Toolbar const & tbb)
317 QLToolbar * Tb = new QLToolbar(tbb, *this);
318 static QLToolbar * lastTb = 0;
320 if (tbb.flags & ToolbarBackend::TOP) {
321 addToolBar(Qt::TopToolBarArea, Tb);
322 addToolBarBreak(Qt::TopToolBarArea);
324 if (tbb.flags & ToolbarBackend::BOTTOM) {
325 addToolBar(Qt::BottomToolBarArea, Tb);
327 insertToolBarBreak(lastTb);
330 if (tbb.flags & ToolbarBackend::LEFT) {
331 addToolBar(Qt::LeftToolBarArea, Tb);
333 if (tbb.flags & ToolbarBackend::RIGHT) {
334 addToolBar(Qt::RightToolBarArea, Tb);
337 return Toolbars::ToolbarPtr(Tb);
340 } // namespace frontend
343 #include "GuiView_moc.cpp"