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.saveSessionInfo("WindowWidth", convert<string>(geometry.width()));
142 session.saveSessionInfo("WindowHeight", convert<string>(geometry.height()));
143 session.saveSessionInfo("WindowIsMaximized", (isMaximized() ? "yes" : "no"));
144 if (lyxrc.geometry_xysaved) {
145 session.saveSessionInfo("WindowPosX", convert<string>(geometry.x()));
146 session.saveSessionInfo("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 if (posx >= desk.width())
164 posx = 0.1 * desk.width();
165 if (posy >= desk.height())
166 posy = 0.1 * desk.height();
168 // FIXME: use only setGeoemtry when Trolltech has
169 // fixed the qt4/X11 bug
170 QMainWindow::setGeometry(posx, posy,width, height);
172 resize(width, height);
176 resize(width, height);
180 setWindowState(Qt::WindowMaximized);
187 void GuiView::updateMenu(QAction * /*action*/)
193 void GuiView::setWindowTitle(docstring const & t, docstring const & it)
195 QMainWindow::setWindowTitle(toqstr(t));
196 QMainWindow::setWindowIconText(toqstr(it));
200 void GuiView::addCommandBuffer(QToolBar * toolbar)
202 commandbuffer_ = new QCommandBuffer(this, *controlcommand_);
203 focus_command_buffer.connect(boost::bind(&GuiView::focus_command_widget, this));
204 toolbar->addWidget(commandbuffer_);
208 void GuiView::message(docstring const & str)
210 statusBar()->showMessage(toqstr(str));
211 statusbar_timer_.stop();
212 statusbar_timer_.start(statusbar_timer_value);
216 void GuiView::clearMessage()
218 update_view_state_qt();
222 void GuiView::focus_command_widget()
225 commandbuffer_->focus_command();
229 void GuiView::update_view_state_qt()
231 statusBar()->showMessage(toqstr(theLyXFunc().viewStatusMessage()));
232 statusbar_timer_.stop();
236 void GuiView::updateStatusBar()
238 // let the user see the explicit message
239 if (statusbar_timer_.isActive())
242 statusBar()->showMessage(toqstr(theLyXFunc().viewStatusMessage()));
246 void GuiView::activated(FuncRequest const & func)
252 bool GuiView::hasFocus() const
254 return qApp->activeWindow() == this;
258 void GuiView::updateFloatingGeometry()
261 floatingGeometry_ = QRect(x(), y(), width(), height());
265 void GuiView::resizeEvent(QResizeEvent *)
267 updateFloatingGeometry();
271 void GuiView::moveEvent(QMoveEvent *)
273 updateFloatingGeometry();
277 void GuiView::closeEvent(QCloseEvent * close_event)
279 GuiImplementation & gui
280 = static_cast<GuiImplementation &>(theApp->gui());
282 vector<int> const & view_ids = gui.viewIds();
284 if (view_ids.size() == 1 && !theBufferList().quitWriteAll()) {
285 close_event->ignore();
290 gui.unregisterView(this);
296 QMainWindow::setWindowTitle(qt_("LyX"));
298 updateFloatingGeometry();
302 void GuiView::busy(bool yes)
304 static_cast<GuiWorkArea *>(work_area_)->setUpdatesEnabled(!yes);
307 work_area_->stopBlinkingCursor();
308 QApplication::setOverrideCursor(Qt::WaitCursor);
311 work_area_->startBlinkingCursor();
312 QApplication::restoreOverrideCursor();
317 Toolbars::ToolbarPtr GuiView::makeToolbar(ToolbarBackend::Toolbar const & tbb)
319 QLToolbar * Tb = new QLToolbar(tbb, *this);
320 static QLToolbar * lastTb = 0;
322 if (tbb.flags & ToolbarBackend::TOP) {
323 addToolBar(Qt::TopToolBarArea, Tb);
324 addToolBarBreak(Qt::TopToolBarArea);
326 if (tbb.flags & ToolbarBackend::BOTTOM) {
327 addToolBar(Qt::BottomToolBarArea, Tb);
329 insertToolBarBreak(lastTb);
332 if (tbb.flags & ToolbarBackend::LEFT) {
333 addToolBar(Qt::LeftToolBarArea, Tb);
335 if (tbb.flags & ToolbarBackend::RIGHT) {
336 addToolBar(Qt::RightToolBarArea, Tb);
339 return Toolbars::ToolbarPtr(Tb);
342 } // namespace frontend
345 #include "GuiView_moc.cpp"