]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiView.cpp
Fix bug 4123:
[lyx.git] / src / frontends / qt4 / GuiView.cpp
1 /**
2  * \file GuiView.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Lars Gullik Bjønnes
7  * \author John Levon
8  * \author Abdelrazak Younes
9  * \author Peter Kümmel
10  *
11  * Full author contact details are available in file CREDITS.
12  */
13
14 #include <config.h>
15
16 #include "GuiView.h"
17
18 #include "GuiImplementation.h"
19 #include "GuiWorkArea.h"
20 #include "QKeySymbol.h"
21 #include "QLMenubar.h"
22 #include "QLToolbar.h"
23 #include "QCommandBuffer.h"
24 #include "qt_helpers.h"
25
26 #include "frontends/Application.h"
27 #include "frontends/Gui.h"
28 #include "frontends/WorkArea.h"
29
30 #include "support/filetools.h"
31 #include "support/convert.h"
32 #include "support/lstrings.h"
33 #include "support/os.h"
34
35 #include "Buffer.h"
36 #include "BufferView.h"
37 #include "BufferList.h"
38 #include "callback.h"
39 #include "debug.h"
40 #include "FuncRequest.h"
41 #include "LyX.h"
42 #include "LyXFunc.h"
43 #include "LyXRC.h"
44 #include "MenuBackend.h"
45 #include "Session.h"
46
47 #include <QAction>
48 #include <QApplication>
49 #include <QCloseEvent>
50 #include <QDesktopWidget>
51 #include <QDragEnterEvent>
52 #include <QDropEvent>
53 #include <QHBoxLayout>
54 #include <QList>
55 #include <QMimeData>
56 #include <QPixmap>
57 #include <QPushButton>
58 #include <QStatusBar>
59 #include <QToolBar>
60 #include <QTabBar>
61 #include <QUrl>
62 #include <QVBoxLayout>
63
64
65 #include <boost/bind.hpp>
66 #include <boost/shared_ptr.hpp>
67
68 using std::endl;
69 using std::string;
70 using std::vector;
71
72 namespace lyx {
73
74 using support::FileName;
75 using support::libFileSearch;
76 using support::makeDisplayPath;
77
78 namespace frontend {
79
80 namespace {
81
82 int const statusbar_timer_value = 3000;
83
84 class TabWidget : public QWidget
85 {
86         QHBoxLayout* hlayout;
87 public:
88         QTabBar* tabbar;
89         QPushButton* closeTabButton;
90
91         void hideTabsIfNecessary()
92         {
93                 if (tabbar->count() > 1) {
94                         tabbar->show();
95                         closeTabButton->show();
96                 } else {
97                         tabbar->hide();
98                         closeTabButton->hide();
99                 }
100         }
101
102         TabWidget(QWidget* w, bool topTabBar)
103         {
104                 closeTabButton = new QPushButton(this);
105                 FileName const file = support::libFileSearch("images", "closetab", "xpm");
106                 if (!file.empty()) {
107                         QPixmap pm(toqstr(file.absFilename()));
108                         closeTabButton->setIcon(QIcon(pm));
109                         closeTabButton->setMaximumSize(pm.size());
110                         closeTabButton->setFlat(true);
111                 } else {
112                         closeTabButton->setText("Close");
113                 }
114                 closeTabButton->setCursor(Qt::ArrowCursor);
115                 closeTabButton->setToolTip(tr("Close tab"));
116                 closeTabButton->setEnabled(true);
117
118                 tabbar = new QTabBar;
119 #if QT_VERSION >= 0x040200
120                 tabbar->setUsesScrollButtons(true);
121 #endif
122                 hlayout = new QHBoxLayout;
123                 QVBoxLayout* vlayout = new QVBoxLayout;
124                 hlayout->addWidget(tabbar);
125                 hlayout->addWidget(closeTabButton);
126                 if (topTabBar) {
127                         vlayout->addLayout(hlayout);
128                         vlayout->addWidget(w);
129                 } else {
130                         tabbar->setShape(QTabBar::RoundedSouth);
131                         vlayout->addWidget(w);
132                         vlayout->addLayout(hlayout);
133                 }
134                 vlayout->setMargin(0);
135                 vlayout->setSpacing(0);
136                 hlayout->setMargin(0);
137                 setLayout(vlayout);
138                 hideTabsIfNecessary();
139         }
140
141         void clearTabbar()
142         {
143                 for (int i = tabbar->count() - 1; i >= 0; --i)
144                         tabbar->removeTab(i);
145         }
146 };
147
148 } // namespace anon
149
150
151 struct GuiView::GuiViewPrivate
152 {
153         vector<string> tabnames;
154         string cur_title;
155
156         TabWidget* tabWidget;
157
158         int posx_offset;
159         int posy_offset;
160
161         GuiViewPrivate() : tabWidget(0), posx_offset(0), posy_offset(0)
162         {}
163
164         unsigned int smallIconSize;
165         unsigned int normalIconSize;
166         unsigned int bigIconSize;
167         // static needed by "New Window"
168         static unsigned int lastIconSize;
169
170         QMenu* toolBarPopup(GuiView *parent)
171         {
172                 // FIXME: translation
173                 QMenu* menu = new QMenu(parent);
174                 QActionGroup *iconSizeGroup = new QActionGroup(parent);
175
176                 QAction *smallIcons = new QAction(iconSizeGroup);
177                 smallIcons->setText(qt_("Small-sized icons"));
178                 smallIcons->setCheckable(true);
179                 QObject::connect(smallIcons, SIGNAL(triggered()), parent, SLOT(smallSizedIcons()));
180                 menu->addAction(smallIcons);
181
182                 QAction *normalIcons = new QAction(iconSizeGroup);
183                 normalIcons->setText(qt_("Normal-sized icons"));
184                 normalIcons->setCheckable(true);
185                 QObject::connect(normalIcons, SIGNAL(triggered()), parent, SLOT(normalSizedIcons()));
186                 menu->addAction(normalIcons);
187
188                 QAction *bigIcons = new QAction(iconSizeGroup);
189                 bigIcons->setText(qt_("Big-sized icons"));
190                 bigIcons->setCheckable(true);
191                 QObject::connect(bigIcons, SIGNAL(triggered()), parent, SLOT(bigSizedIcons()));
192                 menu->addAction(bigIcons);
193
194                 unsigned int cur = parent->iconSize().width();
195                 if ( cur == parent->d.smallIconSize)
196                         smallIcons->setChecked(true);
197                 else if (cur == parent->d.normalIconSize)
198                         normalIcons->setChecked(true);
199                 else if (cur == parent->d.bigIconSize)
200                         bigIcons->setChecked(true);
201
202                 return menu;
203         }
204 };
205
206
207 unsigned int GuiView::GuiViewPrivate::lastIconSize = 0;
208
209
210 GuiView::GuiView(int id)
211         : QMainWindow(), LyXView(id), commandbuffer_(0), quitting_by_menu_(false),
212           d(*new GuiViewPrivate)
213 {
214         // Qt bug? signal lastWindowClosed does not work
215         setAttribute(Qt::WA_QuitOnClose, false);
216         setAttribute(Qt::WA_DeleteOnClose, true);
217
218         // hardcode here the platform specific icon size
219         d.smallIconSize = 14;   // scaling problems
220         d.normalIconSize = 20;  // ok, default
221         d.bigIconSize = 26;             // better for some math icons
222
223 #ifndef Q_WS_MACX
224         //  assign an icon to main form. We do not do it under Qt/Mac,
225         //  since the icon is provided in the application bundle.
226         FileName const iconname = libFileSearch("images", "lyx", "xpm");
227         if (!iconname.empty())
228                 setWindowIcon(QPixmap(toqstr(iconname.absFilename())));
229 #endif
230
231         // For Drag&Drop.
232         setAcceptDrops(true);
233 }
234
235
236 GuiView::~GuiView()
237 {
238         menubar_.reset();
239         delete &d;
240 }
241
242
243 void GuiView::close()
244 {
245         quitting_by_menu_ = true;
246         QMainWindow::close();
247         quitting_by_menu_ = false;
248 }
249
250
251 void GuiView::setFocus()
252 {
253         BOOST_ASSERT(work_area_);
254         static_cast<GuiWorkArea *>(work_area_)->setFocus();
255 }
256
257
258 QMenu* GuiView::createPopupMenu()
259 {
260         return d.toolBarPopup(this);
261 }
262
263
264 void GuiView::init()
265 {
266         menubar_.reset(new QLMenubar(this, menubackend));
267         QObject::connect(menuBar(), SIGNAL(triggered(QAction *)),
268                 this, SLOT(updateMenu(QAction *)));
269
270         getToolbars().init();
271
272         statusBar()->setSizeGripEnabled(true);
273
274         QObject::connect(&statusbar_timer_, SIGNAL(timeout()),
275                 this, SLOT(update_view_state_qt()));
276
277         BOOST_ASSERT(work_area_);
278         if (!work_area_->bufferView().buffer() && !theBufferList().empty())
279                 setBuffer(theBufferList().first());
280
281         // make sure the buttons are disabled if needed
282         updateToolbars();
283         updateLayoutChoice();
284         updateMenubar();
285 }
286
287
288 void GuiView::closeEvent(QCloseEvent * close_event)
289 {
290         // we may have been called through the close window button
291         // which bypasses the LFUN machinery.
292         if (!quitting_by_menu_ && theApp()->gui().viewIds().size() == 1) {
293                 if (!theBufferList().quitWriteAll()) {
294                         close_event->ignore();
295                         return;
296                 }
297         }
298
299         // Make sure that no LFUN use this close to be closed View.
300         theLyXFunc().setLyXView(0);
301         // Make sure the timer time out will not trigger a statusbar update.
302         statusbar_timer_.stop();
303
304         theApp()->gui().unregisterView(id());
305         if (!theApp()->gui().viewIds().empty()) {
306                 // Just close the window and do nothing else if this is not the
307                 // last window.
308                 close_event->accept();
309                 return;
310         }
311
312         quitting = true;
313
314         if (view()->buffer()) {
315                 // save cursor position for opened files to .lyx/session
316                 // only bottom (whole doc) level pit and pos is saved.
317                 LyX::ref().session().lastFilePos().save(
318                         FileName(buffer()->fileName()),
319                         boost::tie(view()->cursor().bottom().pit(),
320                         view()->cursor().bottom().pos()));
321         }
322
323         // this is the place where we leave the frontend.
324         // it is the only point at which we start quitting.
325         saveGeometry();
326         close_event->accept();
327         // quit the event loop
328         qApp->quit();
329 }
330
331
332 void GuiView::dragEnterEvent(QDragEnterEvent * event)
333 {
334         if (event->mimeData()->hasUrls())
335                 event->accept();
336         /// \todo Ask lyx-devel is this is enough:
337         /// if (event->mimeData()->hasFormat("text/plain"))
338         ///     event->acceptProposedAction();
339 }
340
341
342 void GuiView::dropEvent(QDropEvent* event)
343 {
344         QList<QUrl> files = event->mimeData()->urls();
345         if (files.isEmpty())
346                 return;
347
348         LYXERR(Debug::GUI) << BOOST_CURRENT_FUNCTION
349                 << " got URLs!" << endl;
350         for (int i = 0; i!=files.size(); ++i) {
351                 string const file = support::os::internal_path(fromqstr(
352                         files.at(i).toLocalFile()));
353                 if (!file.empty())
354                         dispatch(FuncRequest(LFUN_FILE_OPEN, file));
355         }
356 }
357
358
359 void GuiView::saveGeometry()
360 {
361         static bool done = false;
362         if (done)
363                 return;
364         else
365                 done = true;
366
367         // FIXME:
368         // change the ifdef to 'geometry = normalGeometry();' only
369         // when Trolltech has fixed the broken normalGeometry on X11:
370         // http://www.trolltech.com/developer/task-tracker/index_html?id=119684+&method=entry
371         // Then also the moveEvent, resizeEvent, and the
372         // code for floatingGeometry_ can be removed;
373         // adjust GuiView::setGeometry()
374
375         QRect normal_geometry;
376         int maximized;
377 #ifdef Q_WS_WIN
378         normal_geometry = normalGeometry();
379         if (isMaximized()) {
380                 maximized = CompletelyMaximized;
381         } else {
382                 maximized = NotMaximized;
383         }
384 #else
385         normal_geometry = updateFloatingGeometry();
386
387         QDesktopWidget& dw = *qApp->desktop();
388         QRect desk = dw.availableGeometry(dw.primaryScreen());
389         // Qt bug on Linux: load completely maximized, vert max. save-> frameGeometry().height() is wrong
390         if (isMaximized() && desk.width() <= frameGeometry().width() && desk.height() <= frameGeometry().height()) {
391                 maximized = CompletelyMaximized;
392                 // maximizing does not work when the window is allready hor. or vert. maximized
393                 // Tested only on KDE
394                 int dh = frameGeometry().height() - height();
395                 if (desk.height() <= normal_geometry.height() + dh)
396                         normal_geometry.setHeight(normal_geometry.height() - 1);
397                 int dw = frameGeometry().width() - width();
398                 if (desk.width() <= normal_geometry.width() + dw)
399                         normal_geometry.setWidth(normal_geometry.width() - 1);
400         } else if (desk.height() <= frameGeometry().height()) {
401                 maximized = VerticallyMaximized;
402         } else if (desk.width() <= frameGeometry().width()) {
403                 maximized = HorizontallyMaximized;
404         } else {
405                 maximized = NotMaximized;
406         }
407
408
409 #endif
410         // save windows size and position
411         Session & session = LyX::ref().session();
412         session.sessionInfo().save("WindowWidth", convert<string>(normal_geometry.width()));
413         session.sessionInfo().save("WindowHeight", convert<string>(normal_geometry.height()));
414         session.sessionInfo().save("WindowMaximized", convert<string>(maximized));
415         session.sessionInfo().save("IconSizeXY", convert<string>(iconSize().width()));
416         if (lyxrc.geometry_xysaved) {
417                 session.sessionInfo().save("WindowPosX", convert<string>(normal_geometry.x() + d.posx_offset));
418                 session.sessionInfo().save("WindowPosY", convert<string>(normal_geometry.y() + d.posy_offset));
419         }
420         getToolbars().saveToolbarInfo();
421 }
422
423
424 void GuiView::setGeometry(unsigned int width,
425                           unsigned int height,
426                           int posx, int posy,
427                           int maximized,
428                           unsigned int iconSizeXY,
429                           const string & geometryArg)
430 {
431         // use last value (not at startup)
432         if (d.lastIconSize != 0)
433                 setIconSize(d.lastIconSize);
434         else if (iconSizeXY != 0)
435                 setIconSize(iconSizeXY);
436         else
437                 setIconSize(d.normalIconSize);
438
439         // only true when the -geometry option was NOT used
440         if (width != 0 && height != 0) {
441                 if (posx != -1 && posy != -1) {
442                         // if there are startup positioning problems:
443                         // http://doc.trolltech.com/4.2/qdesktopwidget.html
444                         QDesktopWidget& dw = *qApp->desktop();
445                         if (dw.isVirtualDesktop()) {
446                                 if(!dw.geometry().contains(posx, posy)) {
447                                         posx = 50;
448                                         posy = 50;
449                                 }
450                         } else {
451                                 // Which system doesn't use a virtual desktop?
452                                 // TODO save also last screen number and check if it is still availabe.
453                         }
454 #ifdef Q_WS_WIN
455                         // FIXME: use setGeometry only when Trolltech has fixed the qt4/X11 bug
456                         QWidget::setGeometry(posx, posy, width, height);
457 #else
458                         resize(width, height);
459                         move(posx, posy);
460 #endif
461                 } else {
462                         resize(width, height);
463                 }
464
465                 // remember original size
466                 floatingGeometry_ = QRect(posx, posy, width, height);
467
468                 if (maximized != NotMaximized) {
469                         if (maximized == CompletelyMaximized) {
470                                 setWindowState(Qt::WindowMaximized);
471                         } else {
472 #ifndef Q_WS_WIN
473                                 // TODO How to set by the window manager?
474                                 //      setWindowState(Qt::WindowVerticallyMaximized);
475                                 //      is not possible
476                                 QDesktopWidget& dw = *qApp->desktop();
477                                 QRect desk = dw.availableGeometry(dw.primaryScreen());
478                                 if (maximized == VerticallyMaximized)
479                                         resize(width, desk.height());
480                                 if (maximized == HorizontallyMaximized)
481                                         resize(desk.width(), height);
482 #endif
483                         }
484                 }
485         }
486         else
487         {
488                 // FIXME: move this code into parse_geometry() (LyX.cpp)
489 #ifdef Q_WS_WIN
490                 int x, y;
491                 int w, h;
492                 QRegExp re( "[=]*(?:([0-9]+)[xX]([0-9]+)){0,1}[ ]*(?:([+-][0-9]*)([+-][0-9]*)){0,1}" );
493                 re.indexIn(toqstr(geometryArg.c_str()));
494                 w = re.cap(1).toInt();
495                 h = re.cap(2).toInt();
496                 x = re.cap(3).toInt();
497                 y = re.cap(4).toInt();
498                 QWidget::setGeometry( x, y, w, h );
499 #else
500                 // silence warning
501                 (void)geometryArg;
502 #endif
503         }
504
505         show();
506
507         // For an unknown reason, the Window title update is not effective for
508         // the second windows up until it is shown on screen (Qt bug?).
509         updateWindowTitle();
510
511         // after show geometry() has changed (Qt bug?)
512         // we compensate the drift when storing the position
513         d.posx_offset = 0;
514         d.posy_offset = 0;
515         if (width != 0 && height != 0)
516                 if (posx != -1 && posy != -1) {
517 #ifdef Q_WS_WIN
518                         d.posx_offset = posx - normalGeometry().x();
519                         d.posy_offset = posy - normalGeometry().y();
520 #else
521 #ifndef Q_WS_MACX
522                         if (maximized == NotMaximized) {
523                                 d.posx_offset = posx - geometry().x();
524                                 d.posy_offset = posy - geometry().y();
525                         }
526 #endif
527 #endif
528                 }
529 }
530
531
532 void GuiView::updateMenu(QAction * /*action*/)
533 {
534         menubar_->update();
535 }
536
537
538 void GuiView::setWindowTitle(docstring const & t, docstring const & it)
539 {
540         QString title = windowTitle();
541         QString new_title = toqstr(t);
542         if (title != new_title) {
543                 QMainWindow::setWindowTitle(new_title);
544                 QMainWindow::setWindowIconText(toqstr(it));
545         }
546 }
547
548
549 void GuiView::addCommandBuffer(QToolBar * toolbar)
550 {
551         commandbuffer_ = new QCommandBuffer(this, *controlcommand_);
552         focus_command_buffer.connect(boost::bind(&GuiView::focus_command_widget, this));
553         toolbar->addWidget(commandbuffer_);
554 }
555
556
557 void GuiView::message(docstring const & str)
558 {
559         statusBar()->showMessage(toqstr(str));
560         statusbar_timer_.stop();
561         statusbar_timer_.start(statusbar_timer_value);
562 }
563
564
565 void GuiView::clearMessage()
566 {
567         update_view_state_qt();
568 }
569
570
571 void GuiView::setIconSize(unsigned int size)
572 {
573         d.lastIconSize = size;
574         QMainWindow::setIconSize(QSize(size, size));
575 }
576
577
578 void GuiView::smallSizedIcons()
579 {
580         setIconSize(d.smallIconSize);
581 }
582
583
584 void GuiView::normalSizedIcons()
585 {
586         setIconSize(d.normalIconSize);
587 }
588
589
590 void GuiView::bigSizedIcons()
591 {
592         setIconSize(d.bigIconSize);
593 }
594
595
596 void GuiView::focus_command_widget()
597 {
598         if (commandbuffer_)
599                 commandbuffer_->focus_command();
600 }
601
602
603 void GuiView::update_view_state_qt()
604 {
605         if (!hasFocus())
606                 return;
607         theLyXFunc().setLyXView(this);
608         statusBar()->showMessage(toqstr(theLyXFunc().viewStatusMessage()));
609         statusbar_timer_.stop();
610 }
611
612
613 void GuiView::initTab(QWidget* workarea)
614 {
615         // construct the TabWidget with 'false' to have the tabbar at the bottom
616         d.tabWidget = new TabWidget(workarea, true);
617         setCentralWidget(d.tabWidget);
618         QObject::connect(d.tabWidget->tabbar, SIGNAL(currentChanged(int)),
619                         this, SLOT(currentTabChanged(int)));
620         QObject::connect(d.tabWidget->closeTabButton, SIGNAL(clicked()),
621                         this, SLOT(closeCurrentTab()));
622 }
623
624
625 void GuiView::updateTab()
626 {
627         std::vector<string> const & names = theBufferList().getFileNames();
628
629         string cur_title;
630         if (view()->buffer()) {
631                 cur_title = view()->buffer()->fileName();
632         }
633
634         // avoid unnecessary tabbar rebuild:
635         // check if something has changed
636         if (d.tabnames == names && d.cur_title == cur_title)
637                 return;
638         d.tabnames = names;
639         d.cur_title = cur_title;
640
641         QTabBar & tabbar = *d.tabWidget->tabbar;
642
643         // update when all is done
644         tabbar.blockSignals(true);
645
646         // remove all tab bars
647         d.tabWidget->clearTabbar();
648
649         // rebuild tabbar and function map from scratch
650         if (names.size() > 1) {
651                 for(size_t i = 0; i < names.size(); i++) {
652                         tabbar.addTab(toqstr(makeDisplayPath(names[i], 30)));
653                         // set current tab
654                         if (names[i] == cur_title)
655                                 tabbar.setCurrentIndex(i);
656                 }
657         }
658         tabbar.blockSignals(false);
659         d.tabWidget->hideTabsIfNecessary();
660 }
661
662
663 void GuiView::closeCurrentTab()
664 {
665         dispatch(FuncRequest(LFUN_BUFFER_CLOSE));
666 }
667
668
669 void GuiView::currentTabChanged(int i)
670 {
671         BOOST_ASSERT(i >= 0 && size_type(i) < d.tabnames.size());
672         dispatch(FuncRequest(LFUN_BUFFER_SWITCH, d.tabnames[i]));
673 }
674
675
676 void GuiView::updateStatusBar()
677 {
678         // let the user see the explicit message
679         if (statusbar_timer_.isActive())
680                 return;
681
682         statusBar()->showMessage(toqstr(theLyXFunc().viewStatusMessage()));
683 }
684
685
686 void GuiView::activated(FuncRequest const & func)
687 {
688         dispatch(func);
689 }
690
691
692 bool GuiView::hasFocus() const
693 {
694         return qApp->activeWindow() == this;
695 }
696
697
698 QRect  GuiView::updateFloatingGeometry()
699 {
700         QDesktopWidget& dw = *qApp->desktop();
701         QRect desk = dw.availableGeometry(dw.primaryScreen());
702         // remember only non-maximized sizes
703         if (!isMaximized() && desk.width() > frameGeometry().width() && desk.height() > frameGeometry().height()) {
704                 floatingGeometry_ = QRect(x(), y(), width(), height());
705         }
706         return floatingGeometry_;
707 }
708
709
710 void GuiView::resizeEvent(QResizeEvent *)
711 {
712         updateFloatingGeometry();
713 }
714
715
716 void GuiView::moveEvent(QMoveEvent *)
717 {
718         updateFloatingGeometry();
719 }
720
721
722 bool GuiView::event(QEvent * e)
723 {
724         switch (e->type())
725         {
726         // Useful debug code:
727         //case QEvent::WindowActivate:
728         //case QEvent::ActivationChange:
729         //case QEvent::WindowDeactivate:
730         //case QEvent::Paint:
731         //case QEvent::Enter:
732         //case QEvent::Leave:
733         //case QEvent::HoverEnter:
734         //case QEvent::HoverLeave:
735         //case QEvent::HoverMove:
736         //case QEvent::StatusTip:
737         //case QEvent::DragEnter:
738         //case QEvent::DragLeave:
739         //case QEvent::Drop:
740         //      break;
741
742         case QEvent::ShortcutOverride: {
743                 QKeyEvent * ke = static_cast<QKeyEvent*>(e);
744                 if (ke->key() == Qt::Key_Tab || ke->key() == Qt::Key_Backtab) {
745                         boost::shared_ptr<QKeySymbol> sym(new QKeySymbol);
746                         sym->set(ke);
747                         BOOST_ASSERT(work_area_);
748                         work_area_->processKeySym(sym, key_modifier::none);
749                         e->accept();
750                         return true;
751                 }
752         }
753         default:
754                 return QMainWindow::event(e);
755         }
756 }
757
758
759 bool GuiView::focusNextPrevChild(bool /*next*/)
760 {
761         setFocus();
762         return true;
763 }
764
765
766 void GuiView::show()
767 {
768         QMainWindow::setWindowTitle(qt_("LyX"));
769         QMainWindow::show();
770         updateFloatingGeometry();
771 }
772
773
774 void GuiView::busy(bool yes)
775 {
776         BOOST_ASSERT(work_area_);
777         static_cast<GuiWorkArea *>(work_area_)->setUpdatesEnabled(!yes);
778
779         if (yes) {
780                 work_area_->stopBlinkingCursor();
781                 QApplication::setOverrideCursor(Qt::WaitCursor);
782         }
783         else {
784                 work_area_->startBlinkingCursor();
785                 QApplication::restoreOverrideCursor();
786         }
787 }
788
789
790 Toolbars::ToolbarPtr GuiView::makeToolbar(ToolbarInfo const & tbinfo, bool newline)
791 {
792         QLToolbar * Tb = new QLToolbar(tbinfo, *this);
793
794         if (tbinfo.flags & ToolbarInfo::TOP) {
795                 if (newline)
796                         addToolBarBreak(Qt::TopToolBarArea);
797                 addToolBar(Qt::TopToolBarArea, Tb);
798         }
799
800         if (tbinfo.flags & ToolbarInfo::BOTTOM) {
801 // Qt < 4.2.2 cannot handle ToolBarBreak on non-TOP dock.
802 #if (QT_VERSION >= 0x040202)
803                 if (newline)
804                         addToolBarBreak(Qt::BottomToolBarArea);
805 #endif
806                 addToolBar(Qt::BottomToolBarArea, Tb);
807         }
808
809         if (tbinfo.flags & ToolbarInfo::LEFT) {
810 // Qt < 4.2.2 cannot handle ToolBarBreak on non-TOP dock.
811 #if (QT_VERSION >= 0x040202)
812                 if (newline)
813                         addToolBarBreak(Qt::LeftToolBarArea);
814 #endif
815                 addToolBar(Qt::LeftToolBarArea, Tb);
816         }
817
818         if (tbinfo.flags & ToolbarInfo::RIGHT) {
819 // Qt < 4.2.2 cannot handle ToolBarBreak on non-TOP dock.
820 #if (QT_VERSION >= 0x040202)
821                 if (newline)
822                         addToolBarBreak(Qt::RightToolBarArea);
823 #endif
824                 addToolBar(Qt::RightToolBarArea, Tb);
825         }
826
827         // The following does not work so I cannot restore to exact toolbar location
828         /*
829         ToolbarSection::ToolbarInfo & tbinfo = LyX::ref().session().toolbars().load(tbinfo.name);
830         Tb->move(tbinfo.posx, tbinfo.posy);
831         */
832
833         return Toolbars::ToolbarPtr(Tb);
834 }
835
836 } // namespace frontend
837 } // namespace lyx
838
839 #include "GuiView_moc.cpp"