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