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