]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiView.cpp
* make close tab button smaller
[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         theApp()->gui().unregisterView(id());
292         if (!theApp()->gui().viewIds().empty()) {
293                 // Just close the window and do nothing else if this is not the
294                 // last window.
295                 close_event->accept();
296                 return;
297         }
298
299         if (view()->buffer()) {
300                 // save cursor position for opened files to .lyx/session
301                 // only bottom (whole doc) level pit and pos is saved.
302                 LyX::ref().session().lastFilePos().save(
303                         FileName(buffer()->fileName()),
304                         boost::tie(view()->cursor().bottom().pit(),
305                         view()->cursor().bottom().pos()));
306         }
307
308         // this is the place where we leave the frontend.
309         // it is the only point at which we start quitting.
310         saveGeometry();
311         close_event->accept();
312         // quit the event loop
313         qApp->quit();
314 }
315
316
317 void GuiView::saveGeometry()
318 {
319         static bool done = false;
320         if (done)
321                 return;
322         else
323                 done = true;
324
325         // FIXME:
326         // change the ifdef to 'geometry = normalGeometry();' only
327         // when Trolltech has fixed the broken normalGeometry on X11:
328         // http://www.trolltech.com/developer/task-tracker/index_html?id=119684+&method=entry
329         // Then also the moveEvent, resizeEvent, and the
330         // code for floatingGeometry_ can be removed;
331         // adjust GuiView::setGeometry()
332
333         QRect normal_geometry;
334         int maximized;
335 #ifdef Q_WS_WIN
336         normal_geometry = normalGeometry();
337         if (isMaximized()) {
338                 maximized = CompletelyMaximized;
339         } else {
340                 maximized = NotMaximized;
341         }
342 #else
343         normal_geometry = updateFloatingGeometry();
344
345         QDesktopWidget& dw = *qApp->desktop();
346         QRect desk = dw.availableGeometry(dw.primaryScreen());
347         // Qt bug on Linux: load completely maximized, vert max. save-> frameGeometry().height() is wrong
348         if (isMaximized() && desk.width() <= frameGeometry().width() && desk.height() <= frameGeometry().height()) {
349                 maximized = CompletelyMaximized;
350                 // maximizing does not work when the window is allready hor. or vert. maximized
351                 // Tested only on KDE
352                 int dh = frameGeometry().height() - height();
353                 if (desk.height() <= normal_geometry.height() + dh)
354                         normal_geometry.setHeight(normal_geometry.height() - 1);
355                 int dw = frameGeometry().width() - width();
356                 if (desk.width() <= normal_geometry.width() + dw)
357                         normal_geometry.setWidth(normal_geometry.width() - 1);
358         } else if (desk.height() <= frameGeometry().height()) {
359                 maximized = VerticallyMaximized;
360         } else if (desk.width() <= frameGeometry().width()) {
361                 maximized = HorizontallyMaximized;
362         } else {
363                 maximized = NotMaximized;
364         }
365
366
367 #endif
368         // save windows size and position
369         Session & session = LyX::ref().session();
370         session.sessionInfo().save("WindowWidth", convert<string>(normal_geometry.width()));
371         session.sessionInfo().save("WindowHeight", convert<string>(normal_geometry.height()));
372         session.sessionInfo().save("WindowMaximized", convert<string>(maximized));
373         session.sessionInfo().save("IconSizeXY", convert<string>(iconSize().width()));
374         if (lyxrc.geometry_xysaved) {
375                 session.sessionInfo().save("WindowPosX", convert<string>(normal_geometry.x() + d.posx_offset));
376                 session.sessionInfo().save("WindowPosY", convert<string>(normal_geometry.y() + d.posy_offset));
377         }
378         getToolbars().saveToolbarInfo();
379 }
380
381
382 void GuiView::setGeometry(unsigned int width,
383                           unsigned int height,
384                           int posx, int posy,
385                           int maximized,
386                           unsigned int iconSizeXY,
387                           const string & geometryArg)
388 {
389         // use last value (not at startup)
390         if (d.lastIconSize != 0)
391                 setIconSize(d.lastIconSize);
392         else if (iconSizeXY != 0)
393                 setIconSize(iconSizeXY);
394         else
395                 setIconSize(d.normalIconSize);
396
397         // only true when the -geometry option was NOT used
398         if (width != 0 && height != 0) {
399                 if (posx != -1 && posy != -1) {
400                         // if there are startup positioning problems:
401                         // http://doc.trolltech.com/4.2/qdesktopwidget.html
402                         QDesktopWidget& dw = *qApp->desktop();
403                         if (dw.isVirtualDesktop()) {
404                                 if(!dw.geometry().contains(posx, posy)) {
405                                         posx = 50;
406                                         posy = 50;
407                                 }
408                         } else {
409                                 // Which system doesn't use a virtual desktop?
410                                 // TODO save also last screen number and check if it is still availabe.
411                         }
412 #ifdef Q_WS_WIN
413                         // FIXME: use setGeometry only when Trolltech has fixed the qt4/X11 bug
414                         QWidget::setGeometry(posx, posy, width, height);
415 #else
416                         resize(width, height);
417                         move(posx, posy);
418 #endif
419                 } else {
420                         resize(width, height);
421                 }
422
423                 // remember original size
424                 floatingGeometry_ = QRect(posx, posy, width, height);
425
426                 if (maximized != NotMaximized) {
427                         if (maximized == CompletelyMaximized) {
428                                 setWindowState(Qt::WindowMaximized);
429                         } else {
430 #ifndef Q_WS_WIN
431                                 // TODO How to set by the window manager?
432                                 //      setWindowState(Qt::WindowVerticallyMaximized);
433                                 //      is not possible
434                                 QDesktopWidget& dw = *qApp->desktop();
435                                 QRect desk = dw.availableGeometry(dw.primaryScreen());
436                                 if (maximized == VerticallyMaximized)
437                                         resize(width, desk.height());
438                                 if (maximized == HorizontallyMaximized)
439                                         resize(desk.width(), height);
440 #endif
441                         }
442                 }
443         }
444         else
445         {
446                 // FIXME: move this code into parse_geometry() (LyX.cpp)
447 #ifdef Q_WS_WIN
448                 int x, y;
449                 int w, h;
450                 QRegExp re( "[=]*(?:([0-9]+)[xX]([0-9]+)){0,1}[ ]*(?:([+-][0-9]*)([+-][0-9]*)){0,1}" );
451                 re.indexIn(toqstr(geometryArg.c_str()));
452                 w = re.cap(1).toInt();
453                 h = re.cap(2).toInt();
454                 x = re.cap(3).toInt();
455                 y = re.cap(4).toInt();
456                 QWidget::setGeometry( x, y, w, h );
457 #else
458                 // silence warning
459                 (void)geometryArg;
460 #endif
461         }
462
463         show();
464
465         // For an unknown reason, the Window title update is not effective for
466         // the second windows up until it is shown on screen (Qt bug?).
467         updateWindowTitle();
468
469         // after show geometry() has changed (Qt bug?)
470         // we compensate the drift when storing the position
471         d.posx_offset = 0;
472         d.posy_offset = 0;
473         if (width != 0 && height != 0)
474                 if (posx != -1 && posy != -1) {
475 #ifdef Q_WS_WIN
476                         d.posx_offset = posx - normalGeometry().x();
477                         d.posy_offset = posy - normalGeometry().y();
478 #else
479 #ifndef Q_WS_MACX
480                         if (maximized == NotMaximized) {
481                                 d.posx_offset = posx - geometry().x();
482                                 d.posy_offset = posy - geometry().y();
483                         }
484 #endif
485 #endif
486                 }
487 }
488
489
490 void GuiView::updateMenu(QAction * /*action*/)
491 {
492         menubar_->update();
493 }
494
495
496 void GuiView::setWindowTitle(docstring const & t, docstring const & it)
497 {
498         QString title = windowTitle();
499         QString new_title = toqstr(t);
500         if (title != new_title) {
501                 QMainWindow::setWindowTitle(new_title);
502                 QMainWindow::setWindowIconText(toqstr(it));
503         }
504 }
505
506
507 void GuiView::addCommandBuffer(QToolBar * toolbar)
508 {
509         commandbuffer_ = new QCommandBuffer(this, *controlcommand_);
510         focus_command_buffer.connect(boost::bind(&GuiView::focus_command_widget, this));
511         toolbar->addWidget(commandbuffer_);
512 }
513
514
515 void GuiView::message(docstring const & str)
516 {
517         statusBar()->showMessage(toqstr(str));
518         statusbar_timer_.stop();
519         statusbar_timer_.start(statusbar_timer_value);
520 }
521
522
523 void GuiView::clearMessage()
524 {
525         update_view_state_qt();
526 }
527
528
529 void GuiView::setIconSize(unsigned int size)
530 {
531         d.lastIconSize = size;
532         QMainWindow::setIconSize(QSize(size, size));
533 }
534
535
536 void GuiView::smallSizedIcons()
537 {
538         setIconSize(d.smallIconSize);
539 }
540
541
542 void GuiView::normalSizedIcons()
543 {
544         setIconSize(d.normalIconSize);
545 }
546
547
548 void GuiView::bigSizedIcons()
549 {
550         setIconSize(d.bigIconSize);
551 }
552
553
554 void GuiView::focus_command_widget()
555 {
556         if (commandbuffer_)
557                 commandbuffer_->focus_command();
558 }
559
560
561 void GuiView::update_view_state_qt()
562 {
563         statusBar()->showMessage(toqstr(theLyXFunc().viewStatusMessage()));
564         statusbar_timer_.stop();
565 }
566
567
568 void GuiView::initTab(QWidget* workarea)
569 {
570         // construct the TabWidget with 'false' to have the tabbar at the bottom
571         d.tabWidget = new TabWidget(workarea, true);
572         setCentralWidget(d.tabWidget);
573         QObject::connect(d.tabWidget->tabbar, SIGNAL(currentChanged(int)),
574                         this, SLOT(currentTabChanged(int)));
575         QObject::connect(d.tabWidget->closeTabButton, SIGNAL(clicked()),
576                         this, SLOT(closeCurrentTab()));
577 }
578
579
580 void GuiView::updateTab()
581 {
582         std::vector<string> const & names = theBufferList().getFileNames();
583
584         string cur_title;
585         if (view()->buffer()) {
586                 cur_title = view()->buffer()->fileName();
587         }
588
589         // avoid unnecessary tabbar rebuild:
590         // check if something has changed
591         if (d.tabnames == names && d.cur_title == cur_title)
592                 return;
593         d.tabnames = names;
594         d.cur_title = cur_title;
595
596         QTabBar & tabbar = *d.tabWidget->tabbar;
597
598         // update when all is done
599         tabbar.blockSignals(true);
600
601         // remove all tab bars
602         d.tabWidget->clearTabbar();
603
604         // rebuild tabbar and function map from scratch
605         if (names.size() > 1) {
606                 for(size_t i = 0; i < names.size(); i++) {
607                         tabbar.addTab(toqstr(makeDisplayPath(names[i], 30)));
608                         // set current tab
609                         if (names[i] == cur_title)
610                                 tabbar.setCurrentIndex(i);
611                 }
612         }
613         tabbar.blockSignals(false);
614         d.tabWidget->hideTabsIfNecessary();
615 }
616
617
618 void GuiView::closeCurrentTab()
619 {
620         dispatch(FuncRequest(LFUN_BUFFER_CLOSE));
621 }
622
623
624 void GuiView::currentTabChanged(int i)
625 {
626         BOOST_ASSERT(i >= 0 && size_type(i) < d.tabnames.size());
627         dispatch(FuncRequest(LFUN_BUFFER_SWITCH, d.tabnames[i]));
628 }
629
630
631 void GuiView::updateStatusBar()
632 {
633         // let the user see the explicit message
634         if (statusbar_timer_.isActive())
635                 return;
636
637         statusBar()->showMessage(toqstr(theLyXFunc().viewStatusMessage()));
638 }
639
640
641 void GuiView::activated(FuncRequest const & func)
642 {
643         dispatch(func);
644 }
645
646
647 bool GuiView::hasFocus() const
648 {
649         return qApp->activeWindow() == this;
650 }
651
652
653 QRect  GuiView::updateFloatingGeometry()
654 {
655         QDesktopWidget& dw = *qApp->desktop();
656         QRect desk = dw.availableGeometry(dw.primaryScreen());
657         // remember only non-maximized sizes
658         if (!isMaximized() && desk.width() > frameGeometry().width() && desk.height() > frameGeometry().height()) {
659                 floatingGeometry_ = QRect(x(), y(), width(), height());
660         }
661         return floatingGeometry_;
662 }
663
664
665 void GuiView::resizeEvent(QResizeEvent *)
666 {
667         updateFloatingGeometry();
668 }
669
670
671 void GuiView::moveEvent(QMoveEvent *)
672 {
673         updateFloatingGeometry();
674 }
675
676
677 bool GuiView::event(QEvent * e)
678 {
679         // Useful debug code:
680         /*
681         switch (e->type())
682         {
683         case QEvent::WindowActivate:
684         case QEvent::ActivationChange:
685         case QEvent::WindowDeactivate:
686         case QEvent::Paint:
687         case QEvent::Enter:
688         case QEvent::Leave:
689         case QEvent::HoverEnter:
690         case QEvent::HoverLeave:
691         case QEvent::HoverMove:
692         case QEvent::StatusTip:
693                 break;
694         default:
695         */
696
697         if (e->type() == QEvent::ShortcutOverride) {
698                 QKeyEvent * ke = static_cast<QKeyEvent*>(e);
699                 if (ke->key() == Qt::Key_Tab || ke->key() == Qt::Key_Backtab) {
700                         boost::shared_ptr<QKeySymbol> sym(new QKeySymbol);
701                         sym->set(ke);
702                         BOOST_ASSERT(work_area_);
703                         work_area_->processKeySym(sym, key_modifier::none);
704                         e->accept();
705                         return true;
706                 }
707         }
708         //} for the debug switch above.
709
710         return QMainWindow::event(e);
711 }
712
713
714 bool GuiView::focusNextPrevChild(bool /*next*/)
715 {
716         setFocus();
717         return true;
718 }
719
720
721 void GuiView::show()
722 {
723         QMainWindow::setWindowTitle(qt_("LyX"));
724         QMainWindow::show();
725         updateFloatingGeometry();
726 }
727
728
729 void GuiView::busy(bool yes)
730 {
731         BOOST_ASSERT(work_area_);
732         static_cast<GuiWorkArea *>(work_area_)->setUpdatesEnabled(!yes);
733
734         if (yes) {
735                 work_area_->stopBlinkingCursor();
736                 QApplication::setOverrideCursor(Qt::WaitCursor);
737         }
738         else {
739                 work_area_->startBlinkingCursor();
740                 QApplication::restoreOverrideCursor();
741         }
742 }
743
744
745 Toolbars::ToolbarPtr GuiView::makeToolbar(ToolbarInfo const & tbinfo, bool newline)
746 {
747         QLToolbar * Tb = new QLToolbar(tbinfo, *this);
748
749         if (tbinfo.flags & ToolbarInfo::TOP) {
750                 if (newline)
751                         addToolBarBreak(Qt::TopToolBarArea);
752                 addToolBar(Qt::TopToolBarArea, Tb);
753         }
754
755         if (tbinfo.flags & ToolbarInfo::BOTTOM) {
756 // Qt < 4.2.2 cannot handle ToolBarBreak on non-TOP dock.
757 #if (QT_VERSION >= 0x040202)
758                 if (newline)
759                         addToolBarBreak(Qt::BottomToolBarArea);
760 #endif
761                 addToolBar(Qt::BottomToolBarArea, Tb);
762         }
763
764         if (tbinfo.flags & ToolbarInfo::LEFT) {
765 // Qt < 4.2.2 cannot handle ToolBarBreak on non-TOP dock.
766 #if (QT_VERSION >= 0x040202)
767                 if (newline)
768                         addToolBarBreak(Qt::LeftToolBarArea);
769 #endif
770                 addToolBar(Qt::LeftToolBarArea, Tb);
771         }
772
773         if (tbinfo.flags & ToolbarInfo::RIGHT) {
774 // Qt < 4.2.2 cannot handle ToolBarBreak on non-TOP dock.
775 #if (QT_VERSION >= 0x040202)
776                 if (newline)
777                         addToolBarBreak(Qt::RightToolBarArea);
778 #endif
779                 addToolBar(Qt::RightToolBarArea, Tb);
780         }
781
782         // The following does not work so I cannot restore to exact toolbar location
783         /*
784         ToolbarSection::ToolbarInfo & tbinfo = LyX::ref().session().toolbars().load(tbinfo.name);
785         Tb->move(tbinfo.posx, tbinfo.posy);
786         */
787
788         return Toolbars::ToolbarPtr(Tb);
789 }
790
791 } // namespace frontend
792 } // namespace lyx
793
794 #include "GuiView_moc.cpp"