]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiWorkArea.cpp
Move TabWidget related code to TabWorkArea class in GuiWorkArea.{cpp,h}
[lyx.git] / src / frontends / qt4 / GuiWorkArea.cpp
1 /**
2  * \file GuiWorkArea.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author John Levon
7  * \author Abdelrazak Younes
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "GuiWorkArea.h"
15
16 #include "GuiApplication.h"
17 #include "GuiPainter.h"
18 #include "GuiKeySymbol.h"
19 #include "qt_helpers.h"
20
21 #include "frontends/LyXView.h"
22
23 #include "Buffer.h"
24 #include "BufferView.h"
25 #include "Color.h"
26 #include "debug.h"
27 #include "FuncRequest.h"
28 #include "LyXFunc.h"
29 #include "LyXRC.h"
30 #include "version.h"
31
32 #include "support/filetools.h" // LibFileSearch
33
34 #include "graphics/GraphicsImage.h"
35 #include "graphics/GraphicsLoader.h"
36
37 #include <QInputContext>
38 #include <QLayout>
39 #include <QMainWindow>
40 #include <QPainter>
41 #include <QPushButton>
42 #include <QScrollBar>
43 #include <QTabBar>
44 #include <QTimer>
45
46 #include <boost/bind.hpp>
47 #include <boost/current_function.hpp>
48
49 #ifdef Q_WS_X11
50 #include <QX11Info>
51 extern "C" int XEventsQueued(Display *display, int mode);
52 #endif
53
54 #ifdef Q_WS_WIN
55 int const CursorWidth = 2;
56 #else
57 int const CursorWidth = 1;
58 #endif
59
60 #undef KeyPress
61 #undef NoModifier 
62
63 using std::endl;
64 using std::string;
65
66 namespace lyx {
67
68 using support::FileName;
69
70 /// return the LyX mouse button state from Qt's
71 static mouse_button::state q_button_state(Qt::MouseButton button)
72 {
73         mouse_button::state b = mouse_button::none;
74         switch (button) {
75                 case Qt::LeftButton:
76                         b = mouse_button::button1;
77                         break;
78                 case Qt::MidButton:
79                         b = mouse_button::button2;
80                         break;
81                 case Qt::RightButton:
82                         b = mouse_button::button3;
83                         break;
84                 default:
85                         break;
86         }
87         return b;
88 }
89
90
91 /// return the LyX mouse button state from Qt's
92 mouse_button::state q_motion_state(Qt::MouseButtons state)
93 {
94         mouse_button::state b = mouse_button::none;
95         if (state & Qt::LeftButton)
96                 b |= mouse_button::button1;
97         if (state & Qt::MidButton)
98                 b |= mouse_button::button2;
99         if (state & Qt::RightButton)
100                 b |= mouse_button::button3;
101         return b;
102 }
103
104
105 namespace frontend {
106
107 class CursorWidget {
108 public:
109         CursorWidget() {}
110
111         void draw(QPainter & painter)
112         {
113                 if (show_ && rect_.isValid()) {
114                         switch (shape_) {
115                         case L_SHAPE:
116                                 painter.fillRect(rect_.x(), rect_.y(), CursorWidth, rect_.height(), color_);
117                                 painter.setPen(color_);
118                                 painter.drawLine(rect_.bottomLeft().x() + CursorWidth, rect_.bottomLeft().y(),
119                                                                                                  rect_.bottomRight().x(), rect_.bottomLeft().y());
120                                 break;
121                         
122                         case REVERSED_L_SHAPE:
123                                 painter.fillRect(rect_.x() + rect_.height() / 3, rect_.y(), CursorWidth, rect_.height(), color_);
124                                 painter.setPen(color_);
125                                 painter.drawLine(rect_.bottomRight().x() - CursorWidth, rect_.bottomLeft().y(),
126                                                                                                          rect_.bottomLeft().x(), rect_.bottomLeft().y());
127                                 break;
128                                         
129                         default:
130                                 painter.fillRect(rect_, color_);
131                                 break;
132                         }
133                 }
134         }
135
136         void update(int x, int y, int h, CursorShape shape)
137         {
138                 color_ = guiApp->colorCache().get(Color::cursor);
139                 shape_ = shape;
140                 switch (shape) {
141                 case L_SHAPE:
142                         rect_ = QRect(x, y, CursorWidth + h / 3, h);
143                         break;
144                 case REVERSED_L_SHAPE:
145                         rect_ = QRect(x - h / 3, y, CursorWidth + h / 3, h);
146                         break;
147                 default: 
148                         rect_ = QRect(x, y, CursorWidth, h);
149                         break;
150                 }
151         }
152
153         void show(bool set_show = true) { show_ = set_show; }
154         void hide() { show_ = false; }
155
156         QRect const & rect() { return rect_; }
157
158 private:
159         ///
160         CursorShape shape_;
161         ///
162         bool show_;
163         ///
164         QColor color_;
165         ///
166         QRect rect_;
167 };
168
169
170 // This is a 'heartbeat' generating synthetic mouse move events when the
171 // cursor is at the top or bottom edge of the viewport. One scroll per 0.2 s
172 SyntheticMouseEvent::SyntheticMouseEvent()
173         : timeout(200), restart_timeout(true),
174           x_old(-1), y_old(-1), scrollbar_value_old(-1.0)
175 {}
176
177
178 GuiWorkArea::GuiWorkArea(Buffer & buf, LyXView & lv)
179         : WorkArea(buf, lv), need_resize_(false), schedule_redraw_(false),
180           preedit_lines_(1)
181 {
182         screen_ = QPixmap(viewport()->width(), viewport()->height());
183         cursor_ = new frontend::CursorWidget();
184         cursor_->hide();
185
186         setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
187         setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
188         setAcceptDrops(true);
189         setMouseTracking(true);
190         setMinimumSize(100, 70);
191
192         viewport()->setAutoFillBackground(false);
193         // We don't need double-buffering nor SystemBackground on
194         // the viewport because we have our own backing pixmap.
195         viewport()->setAttribute(Qt::WA_NoSystemBackground);
196
197         setFocusPolicy(Qt::WheelFocus);
198
199         viewport()->setCursor(Qt::IBeamCursor);
200
201         synthetic_mouse_event_.timeout.timeout.connect(
202                 boost::bind(&GuiWorkArea::generateSyntheticMouseEvent,
203                             this));
204
205         // Initialize the vertical Scroll Bar
206         QObject::connect(verticalScrollBar(), SIGNAL(actionTriggered(int)),
207                 this, SLOT(adjustViewWithScrollBar(int)));
208
209         // disable context menu for the scrollbar
210         verticalScrollBar()->setContextMenuPolicy(Qt::NoContextMenu);
211
212         // PageStep only depends on the viewport height.
213         verticalScrollBar()->setPageStep(viewport()->height());
214
215         LYXERR(Debug::GUI) << BOOST_CURRENT_FUNCTION
216                 << "\n Area width\t" << width()
217                 << "\n Area height\t" << height()
218                 << "\n viewport width\t" << viewport()->width()
219                 << "\n viewport height\t" << viewport()->height()
220                 << endl;
221
222         // Enables input methods for asian languages.
223         // Must be set when creating custom text editing widgets.
224         setAttribute(Qt::WA_InputMethodEnabled, true);
225 }
226
227
228 void GuiWorkArea::setScrollbarParams(int h, int scroll_pos, int scroll_line_step)
229 {
230         if (verticalScrollBarPolicy() != Qt::ScrollBarAlwaysOn)
231                 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
232
233         verticalScrollBar()->setTracking(false);
234
235         // do what cursor movement does (some grey)
236         h += height() / 4;
237         int scroll_max_ = std::max(0, h - height());
238
239         verticalScrollBar()->setRange(0, scroll_max_);
240         verticalScrollBar()->setSliderPosition(scroll_pos);
241         verticalScrollBar()->setSingleStep(scroll_line_step);
242         verticalScrollBar()->setValue(scroll_pos);
243
244         verticalScrollBar()->setTracking(true);
245 }
246
247
248 void GuiWorkArea::adjustViewWithScrollBar(int action)
249 {
250         stopBlinkingCursor();
251         if (action == QAbstractSlider::SliderPageStepAdd)
252                 buffer_view_->scrollDown(viewport()->height());
253         else if (action == QAbstractSlider::SliderPageStepSub)
254                 buffer_view_->scrollUp(viewport()->height());
255         else
256                 buffer_view_->scrollDocView(verticalScrollBar()->sliderPosition());
257
258         if (lyxrc.cursor_follows_scrollbar) {
259                 buffer_view_->setCursorFromScrollbar();
260                 lyx_view_->updateLayoutChoice();
261         }
262         // Show the cursor immediately after any operation.
263         startBlinkingCursor();
264         QApplication::syncX();
265 }
266
267
268 void GuiWorkArea::focusInEvent(QFocusEvent * /*event*/)
269 {
270         // Repaint the whole screen.
271         // Note: this is different from redraw() as only the backing pixmap
272         // will be redrawn, which is cheap.
273         viewport()->repaint();
274
275         startBlinkingCursor();
276 }
277
278
279 void GuiWorkArea::focusOutEvent(QFocusEvent * /*event*/)
280 {
281         stopBlinkingCursor();
282 }
283
284
285 void GuiWorkArea::mousePressEvent(QMouseEvent * e)
286 {
287         if (dc_event_.active && dc_event_ == *e) {
288                 dc_event_.active = false;
289                 FuncRequest cmd(LFUN_MOUSE_TRIPLE,
290                         e->x(), e->y(),
291                         q_button_state(e->button()));
292                 dispatch(cmd);
293                 return;
294         }
295
296         inputContext()->reset();
297
298         FuncRequest const cmd(LFUN_MOUSE_PRESS, e->x(), e->y(),
299                 q_button_state(e->button()));
300         dispatch(cmd, q_key_state(e->modifiers()));
301 }
302
303
304 void GuiWorkArea::mouseReleaseEvent(QMouseEvent * e)
305 {
306         if (synthetic_mouse_event_.timeout.running())
307                 synthetic_mouse_event_.timeout.stop();
308
309         FuncRequest const cmd(LFUN_MOUSE_RELEASE, e->x(), e->y(),
310                               q_button_state(e->button()));
311         dispatch(cmd);
312 }
313
314
315 void GuiWorkArea::mouseMoveEvent(QMouseEvent * e)
316 {
317         // we kill the triple click if we move
318         doubleClickTimeout();
319         FuncRequest cmd(LFUN_MOUSE_MOTION, e->x(), e->y(),
320                               q_motion_state(e->buttons()));
321
322         // If we're above or below the work area...
323         if (e->y() <= 20 || e->y() >= viewport()->height() - 20) {
324                 // Make sure only a synthetic event can cause a page scroll,
325                 // so they come at a steady rate:
326                 if (e->y() <= 20)
327                         // _Force_ a scroll up:
328                         cmd.y = -40;
329                 else
330                         cmd.y = viewport()->height();
331                 // Store the event, to be handled when the timeout expires.
332                 synthetic_mouse_event_.cmd = cmd;
333
334                 if (synthetic_mouse_event_.timeout.running())
335                         // Discard the event. Note that it _may_ be handled
336                         // when the timeout expires if
337                         // synthetic_mouse_event_.cmd has not been overwritten.
338                         // Ie, when the timeout expires, we handle the
339                         // most recent event but discard all others that
340                         // occurred after the one used to start the timeout
341                         // in the first place.
342                         return;
343                 else {
344                         synthetic_mouse_event_.restart_timeout = true;
345                         synthetic_mouse_event_.timeout.start();
346                         // Fall through to handle this event...
347                 }
348
349         } else if (synthetic_mouse_event_.timeout.running()) {
350                 // Store the event, to be possibly handled when the timeout
351                 // expires.
352                 // Once the timeout has expired, normal control is returned
353                 // to mouseMoveEvent (restart_timeout = false).
354                 // This results in a much smoother 'feel' when moving the
355                 // mouse back into the work area.
356                 synthetic_mouse_event_.cmd = cmd;
357                 synthetic_mouse_event_.restart_timeout = false;
358                 return;
359         }
360
361         // Has anything changed on-screen since the last QMouseEvent
362         // was received?
363         double const scrollbar_value = verticalScrollBar()->value();
364         if (e->x() != synthetic_mouse_event_.x_old ||
365             e->y() != synthetic_mouse_event_.y_old ||
366             scrollbar_value != synthetic_mouse_event_.scrollbar_value_old) {
367                 // Yes it has. Store the params used to check this.
368                 synthetic_mouse_event_.x_old = e->x();
369                 synthetic_mouse_event_.y_old = e->y();
370                 synthetic_mouse_event_.scrollbar_value_old = scrollbar_value;
371
372                 // ... and dispatch the event to the LyX core.
373                 dispatch(cmd);
374         }
375 }
376
377
378 void GuiWorkArea::wheelEvent(QWheelEvent * e)
379 {
380         // Wheel rotation by one notch results in a delta() of 120 (see
381         // documentation of QWheelEvent)
382         int const lines = qApp->wheelScrollLines() * e->delta() / 120;
383         verticalScrollBar()->setValue(verticalScrollBar()->value() -
384                         lines *  verticalScrollBar()->singleStep());
385         adjustViewWithScrollBar();
386 }
387
388
389 void GuiWorkArea::generateSyntheticMouseEvent()
390 {
391 // Set things off to generate the _next_ 'pseudo' event.
392         if (synthetic_mouse_event_.restart_timeout)
393                 synthetic_mouse_event_.timeout.start();
394
395         // Has anything changed on-screen since the last timeout signal
396         // was received?
397         double const scrollbar_value = verticalScrollBar()->value();
398         if (scrollbar_value != synthetic_mouse_event_.scrollbar_value_old) {
399                 // Yes it has. Store the params used to check this.
400                 synthetic_mouse_event_.scrollbar_value_old = scrollbar_value;
401
402                 // ... and dispatch the event to the LyX core.
403                 dispatch(synthetic_mouse_event_.cmd);
404         }
405 }
406
407
408 void GuiWorkArea::keyPressEvent(QKeyEvent * ev)
409 {
410         // do nothing if there are other events
411         // (the auto repeated events come too fast)
412         // \todo FIXME: remove hard coded Qt keys, process the key binding
413 #ifdef Q_WS_X11
414         if (XEventsQueued(QX11Info::display(), 0) > 1 && ev->isAutoRepeat() 
415                         && (Qt::Key_PageDown || Qt::Key_PageUp)) {
416                 LYXERR(Debug::KEY)      
417                         << BOOST_CURRENT_FUNCTION << endl
418                         << "system is busy: scroll key event ignored" << endl;
419                 ev->ignore();
420                 return;
421         }
422 #endif
423
424         LYXERR(Debug::KEY) << BOOST_CURRENT_FUNCTION
425                 << " count=" << ev->count()
426                 << " text=" << fromqstr(ev->text())
427                 << " isAutoRepeat=" << ev->isAutoRepeat()
428                 << " key=" << ev->key()
429                 << endl;
430
431         KeySymbol sym;
432         setKeySymbol(&sym, ev);
433         processKeySym(sym, q_key_state(ev->modifiers()));
434 }
435
436
437 void GuiWorkArea::doubleClickTimeout()
438 {
439         dc_event_.active = false;
440 }
441
442
443 void GuiWorkArea::mouseDoubleClickEvent(QMouseEvent * ev)
444 {
445         dc_event_ = double_click(ev);
446         QTimer::singleShot(QApplication::doubleClickInterval(), this,
447                            SLOT(doubleClickTimeout()));
448         FuncRequest cmd(LFUN_MOUSE_DOUBLE,
449                         ev->x(), ev->y(),
450                         q_button_state(ev->button()));
451         dispatch(cmd);
452 }
453
454
455 void GuiWorkArea::resizeEvent(QResizeEvent * ev)
456 {
457         QAbstractScrollArea::resizeEvent(ev);
458         need_resize_ = true;
459 }
460
461
462 void GuiWorkArea::update(int x, int y, int w, int h)
463 {
464         viewport()->repaint(x, y, w, h);
465 }
466
467
468 void GuiWorkArea::paintEvent(QPaintEvent * ev)
469 {
470         QRect const rc = ev->rect();
471         /*
472         LYXERR(Debug::PAINTING) << "paintEvent begin: x: " << rc.x()
473                 << " y: " << rc.y()
474                 << " w: " << rc.width()
475                 << " h: " << rc.height() << endl;
476         */
477
478         if (need_resize_) {
479                 verticalScrollBar()->setPageStep(viewport()->height());
480                 screen_ = QPixmap(viewport()->width(), viewport()->height());
481                 resizeBufferView();
482                 updateScreen();
483                 WorkArea::hideCursor();
484                 WorkArea::showCursor();
485                 need_resize_ = false;
486         }
487
488         QPainter pain(viewport());
489         pain.drawPixmap(rc, screen_, rc);
490         cursor_->draw(pain);
491 }
492
493
494 void GuiWorkArea::expose(int x, int y, int w, int h)
495 {
496         updateScreen();
497         update(x, y, w, h);
498 }
499
500
501 void GuiWorkArea::updateScreen()
502 {
503         GuiPainter pain(&screen_);
504         verticalScrollBar()->show();
505         buffer_view_->draw(pain);
506 }
507
508
509 void GuiWorkArea::showCursor(int x, int y, int h, CursorShape shape)
510 {
511         if (schedule_redraw_) {
512                 buffer_view_->update(Update::Force);
513                 updateScreen();
514                 viewport()->update(QRect(0, 0, viewport()->width(), viewport()->height()));
515                 schedule_redraw_ = false;
516                 // Show the cursor immediately after the update.
517                 hideCursor();
518                 toggleCursor();
519                 return;
520         }
521
522         cursor_->update(x, y, h, shape);
523         cursor_->show();
524         viewport()->update(cursor_->rect());
525 }
526
527
528 void GuiWorkArea::removeCursor()
529 {
530         cursor_->hide();
531         //if (!qApp->focusWidget())
532                 viewport()->update(cursor_->rect());
533 }
534
535
536 void GuiWorkArea::inputMethodEvent(QInputMethodEvent * e)
537 {
538         QString const & commit_string = e->commitString();
539         docstring const & preedit_string
540                 = qstring_to_ucs4(e->preeditString());
541
542         if (!commit_string.isEmpty()) {
543
544                 LYXERR(Debug::KEY) << BOOST_CURRENT_FUNCTION
545                         << " preeditString =" << fromqstr(e->preeditString())
546                         << " commitString  =" << fromqstr(e->commitString())
547                         << endl;
548
549                 int key = 0;
550
551                 // FIXME Iwami 04/01/07: we should take care also of UTF16 surrogates here.
552                 for (int i = 0; i < commit_string.size(); ++i) {
553                         QKeyEvent ev(QEvent::KeyPress, key, Qt::NoModifier, commit_string[i]);
554                         keyPressEvent(&ev);
555                 }
556         }
557
558         // Hide the cursor during the kana-kanji transformation.
559         if (preedit_string.empty())
560                 startBlinkingCursor();
561         else
562                 stopBlinkingCursor();
563
564         // last_width : for checking if last preedit string was/wasn't empty.
565         static bool last_width = false;
566         if (!last_width && preedit_string.empty()) {
567                 // if last_width is last length of preedit string.
568                 e->accept();
569                 return;
570         }
571
572         GuiPainter pain(&screen_);
573         buffer_view_->updateMetrics(false);
574         buffer_view_->draw(pain);
575         Font font = buffer_view_->cursor().getFont();
576         FontMetrics const & fm = theFontMetrics(font);
577         int height = fm.maxHeight();
578         int cur_x = cursor_->rect().left();
579         int cur_y = cursor_->rect().bottom();
580
581         // redraw area of preedit string.
582         update(0, cur_y - height, GuiWorkArea::width(),
583                 (height + 1) * preedit_lines_);
584
585         if (preedit_string.empty()) {
586                 last_width = false;
587                 preedit_lines_ = 1;
588                 e->accept();
589                 return;
590         }
591         last_width = true;
592
593         // att : stores an IM attribute.
594         QList<QInputMethodEvent::Attribute> const & att = e->attributes();
595
596         // get attributes of input method cursor.
597         // cursor_pos : cursor position in preedit string.
598         size_t cursor_pos = 0;
599         bool cursor_is_visible = false;
600         for (int i = 0; i < att.size(); ++i) {
601                 if (att.at(i).type == QInputMethodEvent::Cursor) {
602                         cursor_pos = att.at(i).start;
603                         cursor_is_visible = att.at(i).length != 0;
604                         break;
605                 }
606         }
607
608         size_t preedit_length = preedit_string.length();
609
610         // get position of selection in input method.
611         // FIXME: isn't there a way to do this simplier?
612         // rStart : cursor position in selected string in IM.
613         size_t rStart = 0;
614         // rLength : selected string length in IM.
615         size_t rLength = 0;
616         if (cursor_pos < preedit_length) {
617                 for (int i = 0; i < att.size(); ++i) {
618                         if (att.at(i).type == QInputMethodEvent::TextFormat) {
619                                 if (att.at(i).start <= int(cursor_pos)
620                                         && int(cursor_pos) < att.at(i).start + att.at(i).length) {
621                                                 rStart = att.at(i).start;
622                                                 rLength = att.at(i).length;
623                                                 if (!cursor_is_visible)
624                                                         cursor_pos += rLength;
625                                                 break;
626                                 }
627                         }
628                 }
629         }
630         else {
631                 rStart = cursor_pos;
632                 rLength = 0;
633         }
634
635         int const right_margin = rightMargin();
636         Painter::preedit_style ps;
637         // Most often there would be only one line:
638         preedit_lines_ = 1;
639         for (size_t pos = 0; pos != preedit_length; ++pos) {
640                 char_type const typed_char = preedit_string[pos];
641                 // reset preedit string style
642                 ps = Painter::preedit_default;
643
644                 // if we reached the right extremity of the screen, go to next line.
645                 if (cur_x + fm.width(typed_char) > GuiWorkArea::width() - right_margin) {
646                         cur_x = right_margin;
647                         cur_y += height + 1;
648                         ++preedit_lines_;
649                 }
650                 // preedit strings are displayed with dashed underline
651                 // and partial strings are displayed white on black indicating
652                 // that we are in selecting mode in the input method.
653                 // FIXME: rLength == preedit_length is not a changing condition
654                 // FIXME: should be put out of the loop.
655                 if (pos >= rStart
656                         && pos < rStart + rLength
657                         && !(cursor_pos < rLength && rLength == preedit_length))
658                         ps = Painter::preedit_selecting;
659
660                 if (pos == cursor_pos
661                         && (cursor_pos < rLength && rLength == preedit_length))
662                         ps = Painter::preedit_cursor;
663
664                 // draw one character and update cur_x.
665                 cur_x += pain.preeditText(cur_x, cur_y, typed_char, font, ps);
666         }
667
668         // update the preedit string screen area.
669         update(0, cur_y - preedit_lines_*height, GuiWorkArea::width(),
670                 (height + 1) * preedit_lines_);
671
672         // Don't forget to accept the event!
673         e->accept();
674 }
675
676
677 QVariant GuiWorkArea::inputMethodQuery(Qt::InputMethodQuery query) const
678 {
679         QRect cur_r(0,0,0,0);
680         switch (query) {
681                 // this is the CJK-specific composition window position.
682                 case Qt::ImMicroFocus:
683                         cur_r = cursor_->rect();
684                         if (preedit_lines_ != 1)
685                                 cur_r.moveLeft(10);
686                         cur_r.moveBottom(cur_r.bottom() + cur_r.height() * preedit_lines_);
687                         // return lower right of cursor in LyX.
688                         return cur_r;
689                 default:
690                         return QWidget::inputMethodQuery(query);
691         }
692 }
693
694 ////////////////////////////////////////////////////////////////////
695 // TabWorkArea implementation.
696 ////////////////////////////////////////////////////////////////////
697 TabWorkArea::TabWorkArea(QWidget * parent): QTabWidget(parent)
698 {
699         QPushButton * closeTabButton = new QPushButton(this);
700         FileName const file = support::libFileSearch("images", "closetab", "png");
701         if (!file.empty()) {
702                 QPixmap pm(toqstr(file.absFilename()));
703                 closeTabButton->setIcon(QIcon(pm));
704                 closeTabButton->setMaximumSize(pm.size());
705                 closeTabButton->setFlat(true);
706         } else {
707                 closeTabButton->setText("Close");
708         }
709         closeTabButton->setCursor(Qt::ArrowCursor);
710         closeTabButton->setToolTip(tr("Close tab"));
711         closeTabButton->setEnabled(true);
712
713         QObject::connect(this, SIGNAL(currentChanged(int)),
714                 this, SLOT(on_currentTabChanged(int)));
715         QObject::connect(closeTabButton, SIGNAL(clicked()),
716                 this, SLOT(closeCurrentTab()));
717
718         setCornerWidget(closeTabButton);
719 #if QT_VERSION >= 0x040200
720         setUsesScrollButtons(true);
721 #endif
722 }
723
724
725 void TabWorkArea::showBar(bool show)
726 {
727         tabBar()->setVisible(show);
728 }
729
730
731 void TabWorkArea::on_currentTabChanged(int i)
732 {
733         GuiWorkArea * wa = dynamic_cast<GuiWorkArea *>(widget(i));
734         BOOST_ASSERT(wa);
735         BufferView & bv = wa->bufferView();
736         bv.updateMetrics(false);
737         bv.cursor().fixIfBroken();
738         wa->setUpdatesEnabled(true);
739         wa->redraw();
740         wa->setFocus();
741         ///
742         currentWorkAreaChanged(wa);
743
744         LYXERR(Debug::GUI) << "currentTabChanged " << i
745                 << "File" << bv.buffer().fileName() << endl;
746 }
747
748
749 void TabWorkArea::closeCurrentTab()
750 {
751         lyx::dispatch(FuncRequest(LFUN_BUFFER_CLOSE));
752 }
753
754 } // namespace frontend
755 } // namespace lyx
756
757 #include "GuiWorkArea_moc.cpp"