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