2 * \file GuiWorkArea.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
7 * \author Abdelrazak Younes
9 * Full author contact details are available in file CREDITS.
14 #include "GuiWorkArea.h"
16 #include "ColorCache.h"
17 #include "FontLoader.h"
21 #include "BufferList.h"
22 #include "BufferParams.h"
23 #include "BufferView.h"
24 #include "CoordCache.h"
27 #include "FuncRequest.h"
28 #include "GuiApplication.h"
29 #include "GuiCompleter.h"
30 #include "GuiKeySymbol.h"
31 #include "GuiPainter.h"
33 #include "KeySymbol.h"
38 #include "MetricsInfo.h"
39 #include "qt_helpers.h"
43 #include "graphics/GraphicsImage.h"
44 #include "graphics/GraphicsLoader.h"
46 #include "support/convert.h"
47 #include "support/debug.h"
48 #include "support/gettext.h"
49 #include "support/FileName.h"
51 #include "frontends/Application.h"
52 #include "frontends/FontMetrics.h"
53 #include "frontends/WorkAreaManager.h"
55 #include <QContextMenuEvent>
56 #include <QInputContext>
61 #include <QMainWindow>
65 #include <QPixmapCache>
68 #include <QToolButton>
72 #include <boost/bind.hpp>
78 extern "C" int XEventsQueued(Display *display, int mode);
82 int const CursorWidth = 2;
84 int const CursorWidth = 1;
86 int const TabIndicatorWidth = 3;
92 using namespace lyx::support;
97 /// return the LyX mouse button state from Qt's
98 static mouse_button::state q_button_state(Qt::MouseButton button)
100 mouse_button::state b = mouse_button::none;
103 b = mouse_button::button1;
106 b = mouse_button::button2;
108 case Qt::RightButton:
109 b = mouse_button::button3;
118 /// return the LyX mouse button state from Qt's
119 mouse_button::state q_motion_state(Qt::MouseButtons state)
121 mouse_button::state b = mouse_button::none;
122 if (state & Qt::LeftButton)
123 b |= mouse_button::button1;
124 if (state & Qt::MidButton)
125 b |= mouse_button::button2;
126 if (state & Qt::RightButton)
127 b |= mouse_button::button3;
138 void draw(QPainter & painter)
140 if (!show_ || !rect_.isValid())
144 int l = x_ - rect_.left();
145 int r = rect_.right() - x_;
146 int bot = rect_.bottom();
148 // draw vertica linel
149 painter.fillRect(x_, y, CursorWidth, rect_.height(), color_);
151 // draw RTL/LTR indication
152 painter.setPen(color_);
155 painter.drawLine(x_, bot, x_ - l, bot);
157 painter.drawLine(x_, bot, x_ + CursorWidth + r, bot);
160 // draw completion triangle
162 int m = y + rect_.height() / 2;
163 int d = TabIndicatorWidth - 1;
165 painter.drawLine(x_ - 1, m - d, x_ - 1 - d, m);
166 painter.drawLine(x_ - 1, m + d, x_ - 1 - d, m);
168 painter.drawLine(x_ + CursorWidth, m - d, x_ + CursorWidth + d, m);
169 painter.drawLine(x_ + CursorWidth, m + d, x_ + CursorWidth + d, m);
174 void update(int x, int y, int h, bool l_shape,
175 bool rtl, bool completable)
177 color_ = guiApp->colorCache().get(Color_cursor);
180 completable_ = completable;
183 // extension to left and right
187 // RTL/LTR indication
195 // completion triangle
198 l = max(l, TabIndicatorWidth);
200 r = max(r, TabIndicatorWidth);
203 // compute overall rectangle
204 rect_ = QRect(x - l, y, CursorWidth + r + l, h);
207 void show(bool set_show = true) { show_ = set_show; }
208 void hide() { show_ = false; }
210 QRect const & rect() { return rect_; }
213 /// cursor is in RTL or LTR text
215 /// indication for RTL or LTR
217 /// triangle to show that a completion is available
223 /// rectangle, possibly with l_shape and completion triangle
225 /// x position (were the vertical line is drawn)
230 // This is a 'heartbeat' generating synthetic mouse move events when the
231 // cursor is at the top or bottom edge of the viewport. One scroll per 0.2 s
232 SyntheticMouseEvent::SyntheticMouseEvent()
233 : timeout(200), restart_timeout(true),
234 x_old(-1), y_old(-1), min_scrollbar_old(-1.0), max_scrollbar_old(-1.0)
238 GuiWorkArea::GuiWorkArea(QWidget *)
239 : buffer_view_(0), lyx_view_(0),
240 cursor_visible_(false),
241 need_resize_(false), schedule_redraw_(false),
242 preedit_lines_(1), completer_(new GuiCompleter(this))
247 GuiWorkArea::GuiWorkArea(Buffer & buffer, GuiView & gv)
248 : buffer_view_(0), lyx_view_(0),
249 cursor_visible_(false),
250 need_resize_(false), schedule_redraw_(false),
251 preedit_lines_(1), completer_(new GuiCompleter(this))
259 void GuiWorkArea::init()
262 connect(&cursor_timeout_, SIGNAL(timeout()),
263 this, SLOT(toggleCursor()));
265 int const time = QApplication::cursorFlashTime() / 2;
267 cursor_timeout_.setInterval(time);
268 cursor_timeout_.start();
270 // let's initialize this just to be safe
271 cursor_timeout_.setInterval(500);
274 screen_ = QPixmap(viewport()->width(), viewport()->height());
275 // With Qt4.5 a mouse event will happen before the first paint event
276 // so make sure that the buffer view has an up to date metrics.
277 buffer_view_->resize(viewport()->width(), viewport()->height());
278 cursor_ = new frontend::CursorWidget();
281 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
282 setAcceptDrops(true);
283 setMouseTracking(true);
284 setMinimumSize(100, 70);
285 setFrameStyle(QFrame::NoFrame);
288 viewport()->setAutoFillBackground(false);
289 // We don't need double-buffering nor SystemBackground on
290 // the viewport because we have our own backing pixmap.
291 viewport()->setAttribute(Qt::WA_NoSystemBackground);
293 setFocusPolicy(Qt::StrongFocus);
295 viewport()->setCursor(Qt::IBeamCursor);
297 synthetic_mouse_event_.timeout.timeout.connect(
298 boost::bind(&GuiWorkArea::generateSyntheticMouseEvent,
301 // Initialize the vertical Scroll Bar
302 QObject::connect(verticalScrollBar(), SIGNAL(valueChanged(int)),
303 this, SLOT(scrollTo(int)));
305 LYXERR(Debug::GUI, "viewport width: " << viewport()->width()
306 << " viewport height: " << viewport()->height());
308 // Enables input methods for asian languages.
309 // Must be set when creating custom text editing widgets.
310 setAttribute(Qt::WA_InputMethodEnabled, true);
312 dialog_mode_ = false;
316 GuiWorkArea::~GuiWorkArea()
318 buffer_view_->buffer().workAreaManager().remove(this);
321 // Completer has a QObject parent and is thus automatically destroyed.
322 // delete completer_;
326 void GuiWorkArea::setGuiView(GuiView & gv)
332 void GuiWorkArea::setBuffer(Buffer & buffer)
335 buffer_view_ = new BufferView(buffer),
336 buffer.workAreaManager().add(this);
338 // HACK: Prevents an additional redraw when the scrollbar pops up
339 // which regularily happens on documents with more than one page.
340 // The policy should be set to "Qt::ScrollBarAsNeeded" soon.
341 // Since we have no geometry information yet, we assume that
342 // a document needs a scrollbar if there is more then four
343 // paragraph in the outermost text.
344 if (buffer.text().paragraphs().size() > 4)
345 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
346 QTimer::singleShot(50, this, SLOT(fixVerticalScrollBar()));
350 void GuiWorkArea::fixVerticalScrollBar()
353 setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
357 void GuiWorkArea::close()
359 lyx_view_->removeWorkArea(this);
363 void GuiWorkArea::setFullScreen(bool full_screen)
365 buffer_view_->setFullScreen(full_screen);
366 setFrameStyle(QFrame::NoFrame);
368 setFrameStyle(QFrame::NoFrame);
369 if (lyxrc.full_screen_scrollbar)
370 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
372 setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
376 BufferView & GuiWorkArea::bufferView()
378 return *buffer_view_;
382 BufferView const & GuiWorkArea::bufferView() const
384 return *buffer_view_;
388 void GuiWorkArea::stopBlinkingCursor()
390 cursor_timeout_.stop();
395 void GuiWorkArea::startBlinkingCursor()
398 //we're not supposed to cache this value.
399 int const time = QApplication::cursorFlashTime() / 2;
402 cursor_timeout_.setInterval(time);
403 cursor_timeout_.start();
407 void GuiWorkArea::redraw()
410 // No need to redraw in this case.
413 // No need to do anything if this is the current view. The BufferView
414 // metrics are already up to date.
415 if (lyx_view_ != guiApp->currentView()
416 || lyx_view_->currentWorkArea() != this) {
417 // FIXME: it would be nice to optimize for the off-screen case.
418 buffer_view_->updateMetrics();
419 buffer_view_->cursor().fixIfBroken();
422 // update cursor position, because otherwise it has to wait until
423 // the blinking interval is over
424 if (cursor_visible_) {
429 LYXERR(Debug::WORKAREA, "WorkArea::redraw screen");
431 update(0, 0, viewport()->width(), viewport()->height());
433 /// \warning: scrollbar updating *must* be done after the BufferView is drawn
434 /// because \c BufferView::updateScrollbar() is called in \c BufferView::draw().
436 lyx_view_->updateStatusBar();
438 if (lyxerr.debugging(Debug::WORKAREA))
439 buffer_view_->coordCache().dump();
443 void GuiWorkArea::processKeySym(KeySymbol const & key, KeyModifier mod)
445 if (lyx_view_->isFullScreen() && lyx_view_->menuBar()->isVisible()
446 && lyxrc.full_screen_menubar) {
447 // FIXME HACK: we should not have to do this here. See related comment
448 // in GuiView::event() (QEvent::ShortcutOverride)
449 lyx_view_->menuBar()->hide();
452 // In order to avoid bad surprise in the middle of an operation,
453 // we better stop the blinking cursor...
454 // the cursor gets restarted in GuiView::restartCursor()
455 stopBlinkingCursor();
457 theLyXFunc().setLyXView(lyx_view_);
458 theLyXFunc().processKeySym(key, mod);
462 void GuiWorkArea::dispatch(FuncRequest const & cmd0, KeyModifier mod)
465 if (cmd0.action == LFUN_FILE_OPEN) {
466 lyx_view_->dispatch(cmd0);
470 theLyXFunc().setLyXView(lyx_view_);
474 if (cmd0.action == LFUN_MOUSE_PRESS) {
475 if (mod == ShiftModifier)
476 cmd = FuncRequest(cmd0, "region-select");
477 else if (mod == ControlModifier)
478 cmd = FuncRequest(cmd0, "paragraph-select");
485 bool const notJustMovingTheMouse =
486 cmd.action != LFUN_MOUSE_MOTION || cmd.button() != mouse_button::none;
488 // In order to avoid bad surprise in the middle of an operation, we better stop
489 // the blinking cursor.
490 if (notJustMovingTheMouse)
491 stopBlinkingCursor();
493 buffer_view_->mouseEventDispatch(cmd);
495 // Skip these when selecting
496 if (cmd.action != LFUN_MOUSE_MOTION) {
497 completer_->updateVisibility(false, false);
498 lyx_view_->updateDialogs();
499 lyx_view_->updateStatusBar();
502 // GUI tweaks except with mouse motion with no button pressed.
503 if (notJustMovingTheMouse) {
504 // Slight hack: this is only called currently when we
505 // clicked somewhere, so we force through the display
506 // of the new status here.
507 lyx_view_->clearMessage();
509 // Show the cursor immediately after any operation
510 startBlinkingCursor();
515 void GuiWorkArea::resizeBufferView()
517 // WARNING: Please don't put any code that will trigger a repaint here!
518 // We are already inside a paint event.
519 lyx_view_->setBusy(true);
522 buffer_view_->cursorPosAndHeight(p, h);
523 bool const cursor_in_view = buffer_view_->cursorInView(p, h);
524 buffer_view_->resize(viewport()->width(), viewport()->height());
526 buffer_view_->scrollToCursor();
529 // Update scrollbars which might have changed due different
530 // BufferView dimension. This is especially important when the
531 // BufferView goes from zero-size to the real-size for the first time,
532 // as the scrollbar paramters are then set for the first time.
535 lyx_view_->updateLayoutList();
536 lyx_view_->setBusy(false);
537 need_resize_ = false;
541 void GuiWorkArea::showCursor()
547 bool l_shape = false;
548 Font const & realfont = buffer_view_->cursor().real_current_font;
549 BufferParams const & bp = buffer_view_->buffer().params();
550 bool const samelang = realfont.language() == bp.language;
551 bool const isrtl = realfont.isVisibleRightToLeft();
553 if (!samelang || isrtl != bp.language->rightToLeft())
556 // The ERT language hack needs fixing up
557 if (realfont.language() == latex_language)
562 buffer_view_->cursorPosAndHeight(p, h);
563 // show cursor on screen
564 Cursor & cur = buffer_view_->cursor();
565 bool completable = cur.inset().showCompletionCursor()
566 && completer_->completionAvailable()
567 && !completer_->popupVisible()
568 && !completer_->inlineVisible();
569 if (buffer_view_->cursorInView(p, h)) {
570 cursor_visible_ = true;
571 showCursor(p.x_, p.y_, h, l_shape, isrtl, completable);
576 void GuiWorkArea::hideCursor()
578 if (!cursor_visible_)
581 cursor_visible_ = false;
586 void GuiWorkArea::toggleCursor()
595 void GuiWorkArea::updateScrollbar()
597 ScrollbarParameters const & scroll_ = buffer_view_->scrollbarParameters();
598 // WARNING: don't touch at the scrollbar value like this:
599 // verticalScrollBar()->setValue(scroll_.position);
600 // because this would cause a recursive signal/slot calling with
601 // GuiWorkArea::scrollTo
602 verticalScrollBar()->setRange(scroll_.min, scroll_.max);
603 verticalScrollBar()->setPageStep(scroll_.page_step);
604 verticalScrollBar()->setSingleStep(scroll_.single_step);
605 verticalScrollBar()->setSliderPosition(scroll_.position);
609 void GuiWorkArea::scrollTo(int value)
611 stopBlinkingCursor();
612 buffer_view_->scrollDocView(value);
614 if (lyxrc.cursor_follows_scrollbar) {
615 buffer_view_->setCursorFromScrollbar();
616 lyx_view_->updateLayoutList();
618 // Show the cursor immediately after any operation.
619 startBlinkingCursor();
620 QApplication::syncX();
624 bool GuiWorkArea::event(QEvent * e)
627 case QEvent::ToolTip: {
628 QHelpEvent * helpEvent = static_cast<QHelpEvent *>(e);
629 if (lyxrc.use_tooltip) {
630 QPoint pos = helpEvent->pos();
631 if (pos.x() < viewport()->width()) {
632 QString s = toqstr(buffer_view_->toolTip(pos.x(), pos.y()));
633 QToolTip::showText(helpEvent->globalPos(), s);
636 QToolTip::hideText();
638 // Don't forget to accept the event!
643 case QEvent::ShortcutOverride: {
644 // We catch this event in order to catch the Tab or Shift+Tab key press
645 // which are otherwise reserved to focus switching between controls
647 QKeyEvent * ke = static_cast<QKeyEvent*>(e);
648 if ((ke->key() != Qt::Key_Tab && ke->key() != Qt::Key_Backtab)
649 || ke->modifiers() & Qt::ControlModifier)
650 return QAbstractScrollArea::event(e);
656 return QAbstractScrollArea::event(e);
662 void GuiWorkArea::contextMenuEvent(QContextMenuEvent * e)
664 QPoint pos = e->pos();
665 Cursor const & cur = buffer_view_->cursor();
666 if (e->reason() == QContextMenuEvent::Keyboard && cur.inTexted()) {
667 // Do not access the context menu of math right in front of before
668 // the cursor. This does not work when the cursor is in text.
669 Inset * inset = cur.paragraph().getInset(cur.pos());
670 if (inset && inset->asInsetMath())
672 else if (cur.pos() > 0) {
673 Inset * inset = cur.paragraph().getInset(cur.pos() - 1);
678 docstring name = buffer_view_->contextMenu(pos.x(), pos.y());
680 QAbstractScrollArea::contextMenuEvent(e);
683 QMenu * menu = guiApp->menus().menu(toqstr(name), *lyx_view_);
685 QAbstractScrollArea::contextMenuEvent(e);
688 // Position the menu to the right.
689 // FIXME: menu position should be different for RTL text.
690 menu->exec(e->globalPos());
695 void GuiWorkArea::focusInEvent(QFocusEvent * e)
698 LYXERR(Debug::DEBUG, "GuiWorkArea::focusInEvent(): " << this << std::endl);
699 GuiWorkArea * old_gwa = theGuiApp()->currentView()->currentWorkArea();
701 old_gwa->stopBlinkingCursor();
702 lyx_view_->setCurrentWorkArea(this);
705 if (lyx_view_->currentWorkArea() != this)
706 lyx_view_->setCurrentWorkArea(this);
708 startBlinkingCursor();
709 QAbstractScrollArea::focusInEvent(e);
713 void GuiWorkArea::focusOutEvent(QFocusEvent * e)
715 LYXERR(Debug::DEBUG, "GuiWorkArea::focusOutEvent(): " << this << std::endl);
716 stopBlinkingCursor();
717 QAbstractScrollArea::focusOutEvent(e);
721 void GuiWorkArea::mousePressEvent(QMouseEvent * e)
723 if (dc_event_.active && dc_event_ == *e) {
724 dc_event_.active = false;
725 FuncRequest cmd(LFUN_MOUSE_TRIPLE, e->x(), e->y(),
726 q_button_state(e->button()));
732 inputContext()->reset();
734 FuncRequest const cmd(LFUN_MOUSE_PRESS, e->x(), e->y(),
735 q_button_state(e->button()));
736 dispatch(cmd, q_key_state(e->modifiers()));
741 void GuiWorkArea::mouseReleaseEvent(QMouseEvent * e)
743 if (synthetic_mouse_event_.timeout.running())
744 synthetic_mouse_event_.timeout.stop();
746 FuncRequest const cmd(LFUN_MOUSE_RELEASE, e->x(), e->y(),
747 q_button_state(e->button()));
753 void GuiWorkArea::mouseMoveEvent(QMouseEvent * e)
755 // we kill the triple click if we move
756 doubleClickTimeout();
757 FuncRequest cmd(LFUN_MOUSE_MOTION, e->x(), e->y(),
758 q_motion_state(e->buttons()));
762 // If we're above or below the work area...
763 if (e->y() <= 20 || e->y() >= viewport()->height() - 20) {
764 // Make sure only a synthetic event can cause a page scroll,
765 // so they come at a steady rate:
767 // _Force_ a scroll up:
770 cmd.y = viewport()->height();
771 // Store the event, to be handled when the timeout expires.
772 synthetic_mouse_event_.cmd = cmd;
774 if (synthetic_mouse_event_.timeout.running())
775 // Discard the event. Note that it _may_ be handled
776 // when the timeout expires if
777 // synthetic_mouse_event_.cmd has not been overwritten.
778 // Ie, when the timeout expires, we handle the
779 // most recent event but discard all others that
780 // occurred after the one used to start the timeout
781 // in the first place.
784 synthetic_mouse_event_.restart_timeout = true;
785 synthetic_mouse_event_.timeout.start();
786 // Fall through to handle this event...
788 } else if (synthetic_mouse_event_.timeout.running()) {
789 // Store the event, to be possibly handled when the timeout
791 // Once the timeout has expired, normal control is returned
792 // to mouseMoveEvent (restart_timeout = false).
793 // This results in a much smoother 'feel' when moving the
794 // mouse back into the work area.
795 synthetic_mouse_event_.cmd = cmd;
796 synthetic_mouse_event_.restart_timeout = false;
800 // Has anything changed on-screen since the last QMouseEvent
802 if (e->x() == synthetic_mouse_event_.x_old
803 && e->y() == synthetic_mouse_event_.y_old
804 && synthetic_mouse_event_.min_scrollbar_old == verticalScrollBar()->minimum()
805 && synthetic_mouse_event_.max_scrollbar_old == verticalScrollBar()->maximum()) {
806 // Nothing changed on-screen since the last QMouseEvent.
810 // Yes something has changed. Store the params used to check this.
811 synthetic_mouse_event_.x_old = e->x();
812 synthetic_mouse_event_.y_old = e->y();
813 synthetic_mouse_event_.min_scrollbar_old = verticalScrollBar()->minimum();
814 synthetic_mouse_event_.max_scrollbar_old = verticalScrollBar()->maximum();
816 // ... and dispatch the event to the LyX core.
821 void GuiWorkArea::wheelEvent(QWheelEvent * ev)
823 // Wheel rotation by one notch results in a delta() of 120 (see
824 // documentation of QWheelEvent)
825 int const delta = ev->delta() / 120;
826 if (ev->modifiers() & Qt::ControlModifier) {
827 docstring arg = convert<docstring>(5 * delta);
828 lyx::dispatch(FuncRequest(LFUN_BUFFER_ZOOM_IN, arg));
832 // Take into account the desktop wide settings.
833 int const lines = qApp->wheelScrollLines();
834 int const page_step = verticalScrollBar()->pageStep();
835 // Test if the wheel mouse is set to one screen at a time.
836 int scroll_value = lines > page_step
837 ? page_step : lines * verticalScrollBar()->singleStep();
839 // Take into account the rotation.
840 scroll_value *= delta;
842 // Take into account user preference.
843 scroll_value *= lyxrc.mouse_wheel_speed;
844 LYXERR(Debug::SCROLLING, "wheelScrollLines = " << lines
845 << " delta = " << delta << " scroll_value = " << scroll_value
846 << " page_step = " << page_step);
848 verticalScrollBar()->setValue(verticalScrollBar()->value() - scroll_value);
854 void GuiWorkArea::generateSyntheticMouseEvent()
856 // Set things off to generate the _next_ 'pseudo' event.
857 if (synthetic_mouse_event_.restart_timeout)
858 synthetic_mouse_event_.timeout.start();
860 // Has anything changed on-screen since the last timeout signal
862 int const min_scrollbar = verticalScrollBar()->minimum();
863 int const max_scrollbar = verticalScrollBar()->maximum();
864 if (min_scrollbar == synthetic_mouse_event_.min_scrollbar_old
865 && max_scrollbar == synthetic_mouse_event_.max_scrollbar_old) {
868 // Yes it has. Store the params used to check this.
869 synthetic_mouse_event_.min_scrollbar_old = min_scrollbar;
870 synthetic_mouse_event_.max_scrollbar_old = max_scrollbar;
871 // ... and dispatch the event to the LyX core.
872 dispatch(synthetic_mouse_event_.cmd);
876 void GuiWorkArea::keyPressEvent(QKeyEvent * ev)
878 // Do not process here some keys if dialog_mode_ is set
880 && (ev->modifiers() == Qt::NoModifier
881 || ev->modifiers() == Qt::ShiftModifier)
882 && (ev->key() == Qt::Key_Escape
883 || ev->key() == Qt::Key_Enter
884 || ev->key() == Qt::Key_Return)
890 // intercept some keys if completion popup is visible
891 if (completer_->popupVisible()) {
895 completer_->activate();
901 // do nothing if there are other events
902 // (the auto repeated events come too fast)
903 // \todo FIXME: remove hard coded Qt keys, process the key binding
905 if (XEventsQueued(QX11Info::display(), 0) > 1 && ev->isAutoRepeat()
906 && (Qt::Key_PageDown || Qt::Key_PageUp)) {
907 LYXERR(Debug::KEY, "system is busy: scroll key event ignored");
913 LYXERR(Debug::KEY, " count: " << ev->count() << " text: " << ev->text()
914 << " isAutoRepeat: " << ev->isAutoRepeat() << " key: " << ev->key());
917 setKeySymbol(&sym, ev);
919 processKeySym(sym, q_key_state(ev->modifiers()));
927 void GuiWorkArea::doubleClickTimeout()
929 dc_event_.active = false;
933 void GuiWorkArea::mouseDoubleClickEvent(QMouseEvent * ev)
935 dc_event_ = DoubleClick(ev);
936 QTimer::singleShot(QApplication::doubleClickInterval(), this,
937 SLOT(doubleClickTimeout()));
938 FuncRequest cmd(LFUN_MOUSE_DOUBLE,
940 q_button_state(ev->button()));
946 void GuiWorkArea::resizeEvent(QResizeEvent * ev)
948 QAbstractScrollArea::resizeEvent(ev);
954 void GuiWorkArea::update(int x, int y, int w, int h)
956 viewport()->repaint(x, y, w, h);
960 void GuiWorkArea::paintEvent(QPaintEvent * ev)
962 QRect const rc = ev->rect();
963 // LYXERR(Debug::PAINTING, "paintEvent begin: x: " << rc.x()
964 // << " y: " << rc.y() << " w: " << rc.width() << " h: " << rc.height());
967 screen_ = QPixmap(viewport()->width(), viewport()->height());
973 QPainter pain(viewport());
974 pain.drawPixmap(rc, screen_, rc);
980 void GuiWorkArea::updateScreen()
982 GuiPainter pain(&screen_);
983 buffer_view_->draw(pain);
987 void GuiWorkArea::showCursor(int x, int y, int h,
988 bool l_shape, bool rtl, bool completable)
990 if (schedule_redraw_) {
991 // This happens when a graphic conversion is finished. As we don't know
992 // the size of the new graphics, it's better the update everything.
993 // We can't use redraw() here because this would trigger a infinite
994 // recursive loop with showCursor().
995 buffer_view_->resize(viewport()->width(), viewport()->height());
998 viewport()->update(QRect(0, 0, viewport()->width(), viewport()->height()));
999 schedule_redraw_ = false;
1000 // Show the cursor immediately after the update.
1006 cursor_->update(x, y, h, l_shape, rtl, completable);
1008 viewport()->update(cursor_->rect());
1012 void GuiWorkArea::removeCursor()
1015 //if (!qApp->focusWidget())
1016 viewport()->update(cursor_->rect());
1020 void GuiWorkArea::inputMethodEvent(QInputMethodEvent * e)
1022 QString const & commit_string = e->commitString();
1023 docstring const & preedit_string
1024 = qstring_to_ucs4(e->preeditString());
1026 if (!commit_string.isEmpty()) {
1028 LYXERR(Debug::KEY, "preeditString: " << e->preeditString()
1029 << " commitString: " << e->commitString());
1033 // FIXME Iwami 04/01/07: we should take care also of UTF16 surrogates here.
1034 for (int i = 0; i != commit_string.size(); ++i) {
1035 QKeyEvent ev(QEvent::KeyPress, key, Qt::NoModifier, commit_string[i]);
1040 // Hide the cursor during the kana-kanji transformation.
1041 if (preedit_string.empty())
1042 startBlinkingCursor();
1044 stopBlinkingCursor();
1046 // last_width : for checking if last preedit string was/wasn't empty.
1047 static bool last_width = false;
1048 if (!last_width && preedit_string.empty()) {
1049 // if last_width is last length of preedit string.
1054 GuiPainter pain(&screen_);
1055 buffer_view_->updateMetrics();
1056 buffer_view_->draw(pain);
1057 FontInfo font = buffer_view_->cursor().getFont().fontInfo();
1058 FontMetrics const & fm = theFontMetrics(font);
1059 int height = fm.maxHeight();
1060 int cur_x = cursor_->rect().left();
1061 int cur_y = cursor_->rect().bottom();
1063 // redraw area of preedit string.
1064 update(0, cur_y - height, viewport()->width(),
1065 (height + 1) * preedit_lines_);
1067 if (preedit_string.empty()) {
1075 // att : stores an IM attribute.
1076 QList<QInputMethodEvent::Attribute> const & att = e->attributes();
1078 // get attributes of input method cursor.
1079 // cursor_pos : cursor position in preedit string.
1080 size_t cursor_pos = 0;
1081 bool cursor_is_visible = false;
1082 for (int i = 0; i != att.size(); ++i) {
1083 if (att.at(i).type == QInputMethodEvent::Cursor) {
1084 cursor_pos = att.at(i).start;
1085 cursor_is_visible = att.at(i).length != 0;
1090 size_t preedit_length = preedit_string.length();
1092 // get position of selection in input method.
1093 // FIXME: isn't there a way to do this simplier?
1094 // rStart : cursor position in selected string in IM.
1096 // rLength : selected string length in IM.
1098 if (cursor_pos < preedit_length) {
1099 for (int i = 0; i != att.size(); ++i) {
1100 if (att.at(i).type == QInputMethodEvent::TextFormat) {
1101 if (att.at(i).start <= int(cursor_pos)
1102 && int(cursor_pos) < att.at(i).start + att.at(i).length) {
1103 rStart = att.at(i).start;
1104 rLength = att.at(i).length;
1105 if (!cursor_is_visible)
1106 cursor_pos += rLength;
1113 rStart = cursor_pos;
1117 int const right_margin = buffer_view_->rightMargin();
1118 Painter::preedit_style ps;
1119 // Most often there would be only one line:
1121 for (size_t pos = 0; pos != preedit_length; ++pos) {
1122 char_type const typed_char = preedit_string[pos];
1123 // reset preedit string style
1124 ps = Painter::preedit_default;
1126 // if we reached the right extremity of the screen, go to next line.
1127 if (cur_x + fm.width(typed_char) > viewport()->width() - right_margin) {
1128 cur_x = right_margin;
1129 cur_y += height + 1;
1132 // preedit strings are displayed with dashed underline
1133 // and partial strings are displayed white on black indicating
1134 // that we are in selecting mode in the input method.
1135 // FIXME: rLength == preedit_length is not a changing condition
1136 // FIXME: should be put out of the loop.
1138 && pos < rStart + rLength
1139 && !(cursor_pos < rLength && rLength == preedit_length))
1140 ps = Painter::preedit_selecting;
1142 if (pos == cursor_pos
1143 && (cursor_pos < rLength && rLength == preedit_length))
1144 ps = Painter::preedit_cursor;
1146 // draw one character and update cur_x.
1147 cur_x += pain.preeditText(cur_x, cur_y, typed_char, font, ps);
1150 // update the preedit string screen area.
1151 update(0, cur_y - preedit_lines_*height, viewport()->width(),
1152 (height + 1) * preedit_lines_);
1154 // Don't forget to accept the event!
1159 QVariant GuiWorkArea::inputMethodQuery(Qt::InputMethodQuery query) const
1161 QRect cur_r(0, 0, 0, 0);
1163 // this is the CJK-specific composition window position and
1164 // the context menu position when the menu key is pressed.
1165 case Qt::ImMicroFocus:
1166 cur_r = cursor_->rect();
1167 if (preedit_lines_ != 1)
1169 cur_r.moveBottom(cur_r.bottom()
1170 + cur_r.height() * (preedit_lines_ - 1));
1171 // return lower right of cursor in LyX.
1174 return QWidget::inputMethodQuery(query);
1179 void GuiWorkArea::updateWindowTitle()
1181 docstring maximize_title;
1182 docstring minimize_title;
1184 Buffer & buf = buffer_view_->buffer();
1185 FileName const fileName = buf.fileName();
1186 if (!fileName.empty()) {
1187 maximize_title = fileName.displayName(30);
1188 minimize_title = from_utf8(fileName.onlyFileName());
1189 if (buf.lyxvc().inUse()) {
1190 if (buf.lyxvc().locker().empty())
1191 maximize_title += _(" (version control)");
1193 maximize_title += _(" (version control, locking)");
1195 if (!buf.isClean()) {
1196 maximize_title += _(" (changed)");
1197 minimize_title += char_type('*');
1199 if (buf.isReadonly())
1200 maximize_title += _(" (read only)");
1203 QString title = windowTitle();
1204 QString new_title = toqstr(maximize_title);
1205 if (title == new_title)
1208 QWidget::setWindowTitle(new_title);
1209 QWidget::setWindowIconText(toqstr(minimize_title));
1214 void GuiWorkArea::setReadOnly(bool)
1216 updateWindowTitle();
1217 if (this == lyx_view_->currentWorkArea())
1218 lyx_view_->updateDialogs();
1222 bool GuiWorkArea::isFullScreen()
1224 return lyx_view_ && lyx_view_->isFullScreen();
1228 ////////////////////////////////////////////////////////////////////
1232 ////////////////////////////////////////////////////////////////////
1235 EmbeddedWorkArea::EmbeddedWorkArea(QWidget * w): GuiWorkArea(w)
1237 buffer_ = theBufferList().newBuffer(
1238 support::FileName::tempName().absFilename() + "_embedded.internal");
1239 buffer_->setUnnamed(true);
1240 buffer_->setFullyLoaded(true);
1241 setBuffer(*buffer_);
1242 setDialogMode(true);
1246 EmbeddedWorkArea::~EmbeddedWorkArea()
1248 // No need to destroy buffer and bufferview here, because it is done
1249 // in theBuffeerList() destruction loop at application exit
1253 void EmbeddedWorkArea::closeEvent(QCloseEvent * ev)
1256 GuiWorkArea::closeEvent(ev);
1260 void EmbeddedWorkArea::hideEvent(QHideEvent * ev)
1263 GuiWorkArea::hideEvent(ev);
1267 void EmbeddedWorkArea::disable()
1269 stopBlinkingCursor();
1270 if (view().currentWorkArea() != this)
1272 LASSERT(view().currentMainWorkArea(), /* */);
1273 view().setCurrentWorkArea(view().currentMainWorkArea());
1276 ////////////////////////////////////////////////////////////////////
1280 ////////////////////////////////////////////////////////////////////
1283 class NoTabFrameMacStyle : public QMacStyle {
1286 QRect subElementRect(SubElement element, const QStyleOption * option,
1287 const QWidget * widget = 0) const
1289 QRect rect = QMacStyle::subElementRect(element, option, widget);
1290 bool noBar = static_cast<QTabWidget const *>(widget)->count() <= 1;
1292 // The Qt Mac style puts the contents into a 3 pixel wide box
1293 // which looks very ugly and not like other Mac applications.
1294 // Hence we remove this here, and moreover the 16 pixel round
1295 // frame above if the tab bar is hidden.
1296 if (element == QStyle::SE_TabWidgetTabContents) {
1297 rect.adjust(- rect.left(), 0, rect.left(), 0);
1306 NoTabFrameMacStyle noTabFrameMacStyle;
1310 TabWorkArea::TabWorkArea(QWidget * parent)
1311 : QTabWidget(parent), clicked_tab_(-1)
1314 setStyle(&noTabFrameMacStyle);
1317 QPalette pal = palette();
1318 pal.setColor(QPalette::Active, QPalette::Button,
1319 pal.color(QPalette::Active, QPalette::Window));
1320 pal.setColor(QPalette::Disabled, QPalette::Button,
1321 pal.color(QPalette::Disabled, QPalette::Window));
1322 pal.setColor(QPalette::Inactive, QPalette::Button,
1323 pal.color(QPalette::Inactive, QPalette::Window));
1325 QObject::connect(this, SIGNAL(currentChanged(int)),
1326 this, SLOT(on_currentTabChanged(int)));
1328 #if QT_VERSION < 0x040500
1329 closeBufferButton = new QToolButton(this);
1330 closeBufferButton->setPalette(pal);
1331 // FIXME: rename the icon to closebuffer.png
1332 closeBufferButton->setIcon(QIcon(getPixmap("images/", "closetab", "png")));
1333 closeBufferButton->setText("Close File");
1334 closeBufferButton->setAutoRaise(true);
1335 closeBufferButton->setCursor(Qt::ArrowCursor);
1336 closeBufferButton->setToolTip(qt_("Close File"));
1337 closeBufferButton->setEnabled(true);
1338 QObject::connect(closeBufferButton, SIGNAL(clicked()),
1339 this, SLOT(closeCurrentBuffer()));
1340 setCornerWidget(closeBufferButton, Qt::TopRightCorner);
1343 // setup drag'n'drop
1344 QTabBar* tb = new DragTabBar;
1345 connect(tb, SIGNAL(tabMoveRequested(int, int)),
1346 this, SLOT(moveTab(int, int)));
1347 tb->setElideMode(Qt::ElideNone);
1350 // make us responsible for the context menu of the tabbar
1351 tb->setContextMenuPolicy(Qt::CustomContextMenu);
1352 connect(tb, SIGNAL(customContextMenuRequested(const QPoint &)),
1353 this, SLOT(showContextMenu(const QPoint &)));
1354 #if QT_VERSION >= 0x040500
1355 connect(tb, SIGNAL(tabCloseRequested(int)),
1356 tb, SLOT(on_tabCloseRequested(int)));
1359 setUsesScrollButtons(true);
1363 void TabWorkArea::setFullScreen(bool full_screen)
1365 for (int i = 0; i != count(); ++i) {
1366 if (GuiWorkArea * wa = dynamic_cast<GuiWorkArea *>(widget(i)))
1367 wa->setFullScreen(full_screen);
1370 if (lyxrc.full_screen_tabbar)
1371 showBar(!full_screen && count() > 1);
1375 void TabWorkArea::showBar(bool show)
1377 tabBar()->setEnabled(show);
1378 tabBar()->setVisible(show);
1379 #if QT_VERSION < 0x040500
1380 closeBufferButton->setVisible(show);
1385 GuiWorkArea * TabWorkArea::currentWorkArea()
1390 GuiWorkArea * wa = dynamic_cast<GuiWorkArea *>(currentWidget());
1396 GuiWorkArea * TabWorkArea::workArea(Buffer & buffer)
1398 for (int i = 0; i != count(); ++i) {
1399 GuiWorkArea * wa = dynamic_cast<GuiWorkArea *>(widget(i));
1400 LASSERT(wa, return 0);
1401 if (&wa->bufferView().buffer() == &buffer)
1408 void TabWorkArea::closeAll()
1411 GuiWorkArea * wa = dynamic_cast<GuiWorkArea *>(widget(0));
1419 bool TabWorkArea::setCurrentWorkArea(GuiWorkArea * work_area)
1421 LASSERT(work_area, /**/);
1422 int index = indexOf(work_area);
1426 if (index == currentIndex())
1427 // Make sure the work area is up to date.
1428 on_currentTabChanged(index);
1430 // Switch to the work area.
1431 setCurrentIndex(index);
1432 work_area->setFocus();
1438 GuiWorkArea * TabWorkArea::addWorkArea(Buffer & buffer, GuiView & view)
1440 GuiWorkArea * wa = new GuiWorkArea(buffer, view);
1441 wa->setUpdatesEnabled(false);
1442 // Hide tabbar if there's no tab (avoid a resize and a flashing tabbar
1443 // when hiding it again below).
1444 if (!(currentWorkArea() && currentWorkArea()->isFullScreen()))
1445 showBar(count() > 0);
1446 addTab(wa, wa->windowTitle());
1447 QObject::connect(wa, SIGNAL(titleChanged(GuiWorkArea *)),
1448 this, SLOT(updateTabTexts()));
1449 if (currentWorkArea() && currentWorkArea()->isFullScreen())
1450 setFullScreen(true);
1452 // Hide tabbar if there's only one tab.
1453 showBar(count() > 1);
1461 bool TabWorkArea::removeWorkArea(GuiWorkArea * work_area)
1463 LASSERT(work_area, return false);
1464 int index = indexOf(work_area);
1468 work_area->setUpdatesEnabled(false);
1473 // make sure the next work area is enabled.
1474 currentWidget()->setUpdatesEnabled(true);
1475 if (currentWorkArea() && currentWorkArea()->isFullScreen())
1476 setFullScreen(true);
1478 // Show tabbar only if there's more than one tab.
1479 showBar(count() > 1);
1481 lastWorkAreaRemoved();
1489 void TabWorkArea::on_currentTabChanged(int i)
1491 // returns e.g. on application destruction
1494 GuiWorkArea * wa = dynamic_cast<GuiWorkArea *>(widget(i));
1495 LASSERT(wa, return);
1496 BufferView & bv = wa->bufferView();
1497 bv.cursor().fixIfBroken();
1499 wa->setUpdatesEnabled(true);
1503 currentWorkAreaChanged(wa);
1505 LYXERR(Debug::GUI, "currentTabChanged " << i
1506 << "File" << bv.buffer().absFileName());
1510 void TabWorkArea::closeCurrentBuffer()
1512 if (clicked_tab_ != -1)
1513 setCurrentIndex(clicked_tab_);
1515 // Before dispatching the LFUN we should be sure this
1516 // is the current workarea.
1517 currentWorkAreaChanged(currentWorkArea());
1519 lyx::dispatch(FuncRequest(LFUN_BUFFER_CLOSE));
1523 void TabWorkArea::closeCurrentTab()
1525 if (clicked_tab_ == -1)
1526 removeWorkArea(currentWorkArea());
1528 GuiWorkArea * wa = dynamic_cast<GuiWorkArea *>(widget(clicked_tab_));
1537 /// make vector happy
1540 DisplayPath(int tab, FileName const & filename)
1543 filename_ = toqstr(filename.onlyFileNameWithoutExt());
1544 postfix_ = toqstr(filename.absoluteFilePath()).
1545 split("/", QString::SkipEmptyParts);
1546 postfix_.pop_back();
1547 abs_ = toqstr(filename.absoluteFilePath());
1548 dottedPrefix_ = false;
1551 /// Absolute path for debugging.
1556 /// Add the first segment from the postfix or three dots to the prefix.
1557 /// Merge multiple dot tripples. In fact dots are added lazily, i.e. only
1558 /// when really needed.
1559 void shiftPathSegment(bool dotted)
1561 if (postfix_.count() <= 0)
1565 if (dottedPrefix_ && !prefix_.isEmpty())
1567 prefix_ += postfix_.front() + "/";
1569 dottedPrefix_ = dotted && !prefix_.isEmpty();
1570 postfix_.pop_front();
1573 QString displayString() const
1575 if (prefix_.isEmpty())
1578 bool dots = dottedPrefix_ || !postfix_.isEmpty();
1579 return prefix_ + (dots ? ".../" : "") + filename_;
1582 QString forecastPathString() const
1584 if (postfix_.count() == 0)
1585 return displayString();
1588 + (dottedPrefix_ ? ".../" : "")
1589 + postfix_.front() + "/";
1592 bool final() const { return postfix_.empty(); }
1594 int tab() const { return tab_; }
1600 QStringList postfix_;
1613 bool operator<(DisplayPath const & a, DisplayPath const & b)
1615 return a.displayString() < b.displayString();
1619 bool operator==(DisplayPath const & a, DisplayPath const & b)
1621 return a.displayString() == b.displayString();
1625 void TabWorkArea::updateTabTexts()
1630 std::list<DisplayPath> paths;
1631 typedef std::list<DisplayPath>::iterator It;
1633 // collect full names first: path into postfix, empty prefix and
1634 // filename without extension
1635 for (size_t i = 0; i < n; ++i) {
1636 GuiWorkArea * i_wa = dynamic_cast<GuiWorkArea *>(widget(i));
1637 FileName const fn = i_wa->bufferView().buffer().fileName();
1638 paths.push_back(DisplayPath(i, fn));
1641 // go through path segments and see if it helps to make the path more unique
1642 bool somethingChanged = true;
1643 bool allFinal = false;
1644 while (somethingChanged && !allFinal) {
1645 // adding path segments changes order
1648 LYXERR(Debug::GUI, "updateTabTexts() iteration start");
1649 somethingChanged = false;
1652 // find segments which are not unique (i.e. non-atomic)
1653 It it = paths.begin();
1655 QString segString = it->displayString();
1656 for (; it != paths.end(); ++it) {
1657 // look to the next item
1662 allFinal = allFinal && it->final();
1664 LYXERR(Debug::GUI, "it = " << it->abs()
1665 << " => " << it->displayString());
1667 // still the same segment?
1669 if ((next != paths.end()
1670 && (nextString = next->displayString()) == segString))
1672 LYXERR(Debug::GUI, "segment ended");
1674 // only a trivial one with one element?
1675 if (it == segStart) {
1676 // start new segment
1678 segString = nextString;
1682 // we found a non-atomic segment segStart <= sit <= it < next.
1683 // Shift path segments and hope for the best
1684 // that it makes the path more unique.
1685 somethingChanged = true;
1687 QString dspString = sit->forecastPathString();
1688 LYXERR(Debug::GUI, "first forecast found for "
1689 << sit->abs() << " => " << dspString);
1691 bool moreUnique = false;
1692 for (; sit != next; ++sit) {
1693 if (sit->forecastPathString() != dspString) {
1694 LYXERR(Debug::GUI, "different forecast found for "
1695 << sit->abs() << " => " << sit->forecastPathString());
1699 LYXERR(Debug::GUI, "same forecast found for "
1700 << sit->abs() << " => " << dspString);
1703 // if the path segment helped, add it. Otherwise add dots
1704 bool dots = !moreUnique;
1705 LYXERR(Debug::GUI, "using dots = " << dots);
1706 for (sit = segStart; sit != next; ++sit) {
1707 sit->shiftPathSegment(dots);
1708 LYXERR(Debug::GUI, "shifting "
1709 << sit->abs() << " => " << sit->displayString());
1712 // start new segment
1714 segString = nextString;
1718 // set new tab titles
1719 for (It it = paths.begin(); it != paths.end(); ++it) {
1720 GuiWorkArea * i_wa = dynamic_cast<GuiWorkArea *>(widget(it->tab()));
1721 Buffer & buf = i_wa->bufferView().buffer();
1722 if (!buf.fileName().empty() && !buf.isClean())
1723 setTabText(it->tab(), it->displayString() + "*");
1725 setTabText(it->tab(), it->displayString());
1730 void TabWorkArea::showContextMenu(const QPoint & pos)
1733 clicked_tab_ = static_cast<DragTabBar *>(tabBar())->tabAt(pos);
1734 if (clicked_tab_ == -1)
1739 popup.addAction(QIcon(getPixmap("images/", "hidetab", "png")),
1740 qt_("Hide tab"), this, SLOT(closeCurrentTab()));
1741 popup.addAction(QIcon(getPixmap("images/", "closetab", "png")),
1742 qt_("Close tab"), this, SLOT(closeCurrentBuffer()));
1743 popup.exec(tabBar()->mapToGlobal(pos));
1749 void TabWorkArea::moveTab(int fromIndex, int toIndex)
1751 QWidget * w = widget(fromIndex);
1752 QIcon icon = tabIcon(fromIndex);
1753 QString text = tabText(fromIndex);
1755 setCurrentIndex(fromIndex);
1756 removeTab(fromIndex);
1757 insertTab(toIndex, w, icon, text);
1758 setCurrentIndex(toIndex);
1762 DragTabBar::DragTabBar(QWidget* parent)
1765 setAcceptDrops(true);
1766 #if QT_VERSION >= 0x040500
1767 setTabsClosable(true);
1772 void DragTabBar::on_tabCloseRequested(int index)
1774 setCurrentIndex(index);
1775 lyx::dispatch(FuncRequest(LFUN_BUFFER_CLOSE));
1779 #if QT_VERSION < 0x040300
1780 int DragTabBar::tabAt(QPoint const & position) const
1782 const int max = count();
1783 for (int i = 0; i < max; ++i) {
1784 if (tabRect(i).contains(position))
1792 void DragTabBar::mousePressEvent(QMouseEvent * event)
1794 if (event->button() == Qt::LeftButton)
1795 dragStartPos_ = event->pos();
1796 QTabBar::mousePressEvent(event);
1800 void DragTabBar::mouseMoveEvent(QMouseEvent * event)
1802 // If the left button isn't pressed anymore then return
1803 if (!(event->buttons() & Qt::LeftButton))
1806 // If the distance is too small then return
1807 if ((event->pos() - dragStartPos_).manhattanLength()
1808 < QApplication::startDragDistance())
1811 // did we hit something after all?
1812 int tab = tabAt(dragStartPos_);
1816 // simulate button release to remove highlight from button
1817 int i = currentIndex();
1818 QMouseEvent me(QEvent::MouseButtonRelease, dragStartPos_,
1819 event->button(), event->buttons(), 0);
1820 QTabBar::mouseReleaseEvent(&me);
1824 QDrag * drag = new QDrag(this);
1825 QMimeData * mimeData = new QMimeData;
1826 // a crude way to distinguish tab-reodering drops from other ones
1827 mimeData->setData("action", "tab-reordering") ;
1828 drag->setMimeData(mimeData);
1830 #if QT_VERSION >= 0x040300
1831 // get tab pixmap as cursor
1832 QRect r = tabRect(tab);
1833 QPixmap pixmap(r.size());
1834 render(&pixmap, - r.topLeft());
1835 drag->setPixmap(pixmap);
1838 drag->start(Qt::MoveAction);
1844 void DragTabBar::dragEnterEvent(QDragEnterEvent * event)
1846 // Only accept if it's an tab-reordering request
1847 QMimeData const * m = event->mimeData();
1848 QStringList formats = m->formats();
1849 if (formats.contains("action")
1850 && m->data("action") == "tab-reordering")
1851 event->acceptProposedAction();
1855 void DragTabBar::dropEvent(QDropEvent * event)
1857 int fromIndex = tabAt(dragStartPos_);
1858 int toIndex = tabAt(event->pos());
1860 // Tell interested objects that
1861 if (fromIndex != toIndex)
1862 tabMoveRequested(fromIndex, toIndex);
1863 event->acceptProposedAction();
1867 } // namespace frontend
1870 #include "moc_GuiWorkArea.cpp"