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 "GuiImplementation.h"
18 #include "QLMenubar.h"
19 #include "QLToolbar.h"
20 #include "QCommandBuffer.h"
21 #include "qt_helpers.h"
23 #include "frontends/Application.h"
24 #include "frontends/Gui.h"
25 #include "frontends/WorkArea.h"
27 #include "support/filetools.h"
28 #include "support/convert.h"
29 #include "support/lstrings.h"
31 #include "BufferView.h"
32 #include "bufferlist.h"
34 #include "funcrequest.h"
40 #include "MenuBackend.h"
43 #include <QApplication>
44 #include <QCloseEvent>
49 #include <boost/bind.hpp>
58 using support::libFileSearch;
64 int const statusbar_timer_value = 3000;
69 GuiView::GuiView(int id)
70 : QMainWindow(), LyXView(id), commandbuffer_(0)
72 setAttribute(Qt::WA_DeleteOnClose, true);
73 setAttribute(Qt::WA_QuitOnClose, true);
75 // setToolButtonStyle(Qt::ToolButtonIconOnly);
76 // setIconSize(QSize(12,12));
78 // bufferview_.reset(new BufferView(this, width, height));
81 // assign an icon to main form. We do not do it under Qt/Mac,
82 // since the icon is provided in the application bundle.
83 string const iconname = libFileSearch("images", "lyx", "xpm");
84 if (!iconname.empty())
85 setWindowIcon(QPixmap(toqstr(iconname)));
103 menubar_.reset(new QLMenubar(this, menubackend));
104 QObject::connect(menuBar(), SIGNAL(triggered(QAction *)),
105 this, SLOT(updateMenu(QAction *)));
107 getToolbars().init();
109 statusBar()->setSizeGripEnabled(false);
111 QObject::connect(&statusbar_timer_, SIGNAL(timeout()),
112 this, SLOT(update_view_state_qt()));
114 // make sure the buttons are disabled if needed
116 updateLayoutChoice();
121 void GuiView::saveGeometry()
124 // change the ifdef to 'geometry = normalGeometry();' only
125 // when Trolltech has fixed the broken normalGeometry on X11:
126 // http://www.trolltech.com/developer/task-tracker/index_html?id=119684+&method=entry
127 // Then also the moveEvent, resizeEvent, and the
128 // code for floatingGeometry_ can be removed;
129 // adjust GuiView::setGeometry()
131 QRect geometry = normalGeometry();
133 updateFloatingGeometry();
134 QRect geometry = floatingGeometry_;
137 // save windows size and position
138 Session & session = LyX::ref().session();
139 session.saveSessionInfo("WindowWidth", convert<string>(geometry.width()));
140 session.saveSessionInfo("WindowHeight", convert<string>(geometry.height()));
141 session.saveSessionInfo("WindowIsMaximized", (isMaximized() ? "yes" : "no"));
142 if (lyxrc.geometry_xysaved) {
143 session.saveSessionInfo("WindowPosX", convert<string>(geometry.x()));
144 session.saveSessionInfo("WindowPosY", convert<string>(geometry.y()));
148 void GuiView::setGeometry(unsigned int width,
153 // only true when the -geometry option was NOT used
154 if (width != 0 && height != 0) {
155 if (posx != -1 && posy != -1) {
157 // FIXME: use only setGeoemtry when Trolltech has
158 // fixed the qt4/X11 bug
159 QMainWindow::setGeometry(posx, posy,width, height);
161 resize(width, height);
165 resize(width, height);
169 setWindowState(Qt::WindowMaximized);
176 void GuiView::updateMenu(QAction * /*action*/)
182 void GuiView::setWindowTitle(docstring const & t, docstring const & it)
184 QMainWindow::setWindowTitle(toqstr(t));
185 QMainWindow::setWindowIconText(toqstr(it));
189 void GuiView::addCommandBuffer(QToolBar * toolbar)
191 commandbuffer_ = new QCommandBuffer(this, *controlcommand_);
192 focus_command_buffer.connect(boost::bind(&GuiView::focus_command_widget, this));
193 toolbar->addWidget(commandbuffer_);
197 void GuiView::message(docstring const & str)
199 statusBar()->showMessage(toqstr(str));
200 statusbar_timer_.stop();
201 statusbar_timer_.start(statusbar_timer_value);
205 void GuiView::clearMessage()
207 update_view_state_qt();
211 void GuiView::focus_command_widget()
214 commandbuffer_->focus_command();
218 void GuiView::update_view_state_qt()
220 statusBar()->showMessage(toqstr(theLyXFunc().viewStatusMessage()));
221 statusbar_timer_.stop();
225 void GuiView::updateStatusBar()
227 // let the user see the explicit message
228 if (statusbar_timer_.isActive())
231 statusBar()->showMessage(toqstr(theLyXFunc().viewStatusMessage()));
235 void GuiView::activated(FuncRequest const & func)
241 bool GuiView::hasFocus() const
243 return qApp->activeWindow() == this;
247 void GuiView::updateFloatingGeometry()
250 floatingGeometry_ = QRect(x(), y(), width(), height());
254 void GuiView::resizeEvent(QResizeEvent *)
256 updateFloatingGeometry();
260 void GuiView::moveEvent(QMoveEvent *)
262 updateFloatingGeometry();
266 void GuiView::closeEvent(QCloseEvent * close_event)
268 GuiImplementation & gui
269 = static_cast<GuiImplementation &>(theApp->gui());
271 vector<int> const & view_ids = gui.viewIds();
273 if (view_ids.size() == 1 && !theBufferList().quitWriteAll()) {
274 close_event->ignore();
279 gui.unregisterView(this);
285 QMainWindow::setWindowTitle(qt_("LyX"));
287 updateFloatingGeometry();
291 void GuiView::busy(bool yes) const
294 QApplication::setOverrideCursor(Qt::WaitCursor);
296 QApplication::restoreOverrideCursor();
300 Toolbars::ToolbarPtr GuiView::makeToolbar(ToolbarBackend::Toolbar const & tbb)
302 QLToolbar * Tb = new QLToolbar(tbb, *this);
303 static QLToolbar * lastTb = 0;
305 if (tbb.flags & ToolbarBackend::TOP) {
306 addToolBar(Qt::TopToolBarArea, Tb);
307 addToolBarBreak(Qt::TopToolBarArea);
309 if (tbb.flags & ToolbarBackend::BOTTOM) {
310 addToolBar(Qt::BottomToolBarArea, Tb);
312 insertToolBarBreak(lastTb);
315 if (tbb.flags & ToolbarBackend::LEFT) {
316 addToolBar(Qt::LeftToolBarArea, Tb);
318 if (tbb.flags & ToolbarBackend::RIGHT) {
319 addToolBar(Qt::RightToolBarArea, Tb);
322 return Toolbars::ToolbarPtr(Tb);
325 } // namespace frontend
328 #include "GuiView_moc.cpp"