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) {
157 // if there are ever startup positioning problems
158 // on a virtual desktop then check the 6 lines below
159 // http://doc.trolltech.com/4.2/qdesktopwidget.html
160 QDesktopWidget& dw = *qApp->desktop();
161 QRect desk = dw.availableGeometry(dw.primaryScreen());
162 if (posx >= desk.width())
163 posx = 0.1 * desk.width();
164 if (posy >= desk.height())
165 posy = 0.1 * desk.height();
167 // FIXME: use only setGeoemtry when Trolltech has
168 // fixed the qt4/X11 bug
169 QMainWindow::setGeometry(posx, posy,width, height);
171 resize(width, height);
175 resize(width, height);
179 setWindowState(Qt::WindowMaximized);
186 void GuiView::updateMenu(QAction * /*action*/)
192 void GuiView::setWindowTitle(docstring const & t, docstring const & it)
194 QMainWindow::setWindowTitle(toqstr(t));
195 QMainWindow::setWindowIconText(toqstr(it));
199 void GuiView::addCommandBuffer(QToolBar * toolbar)
201 commandbuffer_ = new QCommandBuffer(this, *controlcommand_);
202 focus_command_buffer.connect(boost::bind(&GuiView::focus_command_widget, this));
203 toolbar->addWidget(commandbuffer_);
207 void GuiView::message(docstring const & str)
209 statusBar()->showMessage(toqstr(str));
210 statusbar_timer_.stop();
211 statusbar_timer_.start(statusbar_timer_value);
215 void GuiView::clearMessage()
217 update_view_state_qt();
221 void GuiView::focus_command_widget()
224 commandbuffer_->focus_command();
228 void GuiView::update_view_state_qt()
230 statusBar()->showMessage(toqstr(theLyXFunc().viewStatusMessage()));
231 statusbar_timer_.stop();
235 void GuiView::updateStatusBar()
237 // let the user see the explicit message
238 if (statusbar_timer_.isActive())
241 statusBar()->showMessage(toqstr(theLyXFunc().viewStatusMessage()));
245 void GuiView::activated(FuncRequest const & func)
251 bool GuiView::hasFocus() const
253 return qApp->activeWindow() == this;
257 void GuiView::updateFloatingGeometry()
260 floatingGeometry_ = QRect(x(), y(), width(), height());
264 void GuiView::resizeEvent(QResizeEvent *)
266 updateFloatingGeometry();
270 void GuiView::moveEvent(QMoveEvent *)
272 updateFloatingGeometry();
276 void GuiView::closeEvent(QCloseEvent * close_event)
278 GuiImplementation & gui
279 = static_cast<GuiImplementation &>(theApp->gui());
281 vector<int> const & view_ids = gui.viewIds();
283 if (view_ids.size() == 1 && !theBufferList().quitWriteAll()) {
284 close_event->ignore();
289 gui.unregisterView(this);
295 QMainWindow::setWindowTitle(qt_("LyX"));
297 updateFloatingGeometry();
301 void GuiView::busy(bool yes)
303 static_cast<GuiWorkArea *>(work_area_)->setUpdatesEnabled(!yes);
306 work_area_->stopBlinkingCursor();
307 QApplication::setOverrideCursor(Qt::WaitCursor);
310 work_area_->startBlinkingCursor();
311 QApplication::restoreOverrideCursor();
316 Toolbars::ToolbarPtr GuiView::makeToolbar(ToolbarBackend::Toolbar const & tbb)
318 QLToolbar * Tb = new QLToolbar(tbb, *this);
319 static QLToolbar * lastTb = 0;
321 if (tbb.flags & ToolbarBackend::TOP) {
322 addToolBar(Qt::TopToolBarArea, Tb);
323 addToolBarBreak(Qt::TopToolBarArea);
325 if (tbb.flags & ToolbarBackend::BOTTOM) {
326 addToolBar(Qt::BottomToolBarArea, Tb);
328 insertToolBarBreak(lastTb);
331 if (tbb.flags & ToolbarBackend::LEFT) {
332 addToolBar(Qt::LeftToolBarArea, Tb);
334 if (tbb.flags & ToolbarBackend::RIGHT) {
335 addToolBar(Qt::RightToolBarArea, Tb);
338 return Toolbars::ToolbarPtr(Tb);
341 } // namespace frontend
344 #include "GuiView_moc.cpp"