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), max_scrollbar_old(-1)
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, this)),
243 context_target_pos_()
248 GuiWorkArea::GuiWorkArea(Buffer & buffer, GuiView & gv)
249 : buffer_view_(0), lyx_view_(0),
250 cursor_visible_(false),
251 need_resize_(false), schedule_redraw_(false),
252 preedit_lines_(1), completer_(new GuiCompleter(this, this)),
253 context_target_pos_()
261 void GuiWorkArea::init()
264 connect(&cursor_timeout_, SIGNAL(timeout()),
265 this, SLOT(toggleCursor()));
267 int const time = QApplication::cursorFlashTime() / 2;
269 cursor_timeout_.setInterval(time);
270 cursor_timeout_.start();
272 // let's initialize this just to be safe
273 cursor_timeout_.setInterval(500);
276 screen_ = QPixmap(viewport()->width(), viewport()->height());
277 // With Qt4.5 a mouse event will happen before the first paint event
278 // so make sure that the buffer view has an up to date metrics.
279 buffer_view_->resize(viewport()->width(), viewport()->height());
280 cursor_ = new frontend::CursorWidget();
283 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
284 setAcceptDrops(true);
285 setMouseTracking(true);
286 setMinimumSize(100, 70);
287 setFrameStyle(QFrame::NoFrame);
290 viewport()->setAutoFillBackground(false);
291 // We don't need double-buffering nor SystemBackground on
292 // the viewport because we have our own backing pixmap.
293 viewport()->setAttribute(Qt::WA_NoSystemBackground);
295 setFocusPolicy(Qt::StrongFocus);
297 viewport()->setCursor(Qt::IBeamCursor);
299 synthetic_mouse_event_.timeout.timeout.connect(
300 boost::bind(&GuiWorkArea::generateSyntheticMouseEvent,
303 // Initialize the vertical Scroll Bar
304 QObject::connect(verticalScrollBar(), SIGNAL(valueChanged(int)),
305 this, SLOT(scrollTo(int)));
307 LYXERR(Debug::GUI, "viewport width: " << viewport()->width()
308 << " viewport height: " << viewport()->height());
310 // Enables input methods for asian languages.
311 // Must be set when creating custom text editing widgets.
312 setAttribute(Qt::WA_InputMethodEnabled, true);
314 dialog_mode_ = false;
318 GuiWorkArea::~GuiWorkArea()
320 buffer_view_->buffer().workAreaManager().remove(this);
323 // Completer has a QObject parent and is thus automatically destroyed.
325 // delete completer_;
329 void GuiWorkArea::setGuiView(GuiView & gv)
335 void GuiWorkArea::setBuffer(Buffer & buffer)
338 buffer_view_ = new BufferView(buffer);
339 buffer.workAreaManager().add(this);
341 // HACK: Prevents an additional redraw when the scrollbar pops up
342 // which regularily happens on documents with more than one page.
343 // The policy should be set to "Qt::ScrollBarAsNeeded" soon.
344 // Since we have no geometry information yet, we assume that
345 // a document needs a scrollbar if there is more then four
346 // paragraph in the outermost text.
347 if (buffer.text().paragraphs().size() > 4)
348 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
349 QTimer::singleShot(50, this, SLOT(fixVerticalScrollBar()));
353 void GuiWorkArea::fixVerticalScrollBar()
356 setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
360 void GuiWorkArea::close()
362 lyx_view_->removeWorkArea(this);
366 void GuiWorkArea::setFullScreen(bool full_screen)
368 buffer_view_->setFullScreen(full_screen);
369 setFrameStyle(QFrame::NoFrame);
371 setFrameStyle(QFrame::NoFrame);
372 if (lyxrc.full_screen_scrollbar)
373 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
375 setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
379 BufferView & GuiWorkArea::bufferView()
381 return *buffer_view_;
385 BufferView const & GuiWorkArea::bufferView() const
387 return *buffer_view_;
391 void GuiWorkArea::stopBlinkingCursor()
393 cursor_timeout_.stop();
398 void GuiWorkArea::startBlinkingCursor()
401 //we're not supposed to cache this value.
402 int const time = QApplication::cursorFlashTime() / 2;
405 cursor_timeout_.setInterval(time);
406 cursor_timeout_.start();
410 void GuiWorkArea::redraw(bool update_metrics)
413 // No need to redraw in this case.
416 // No need to do anything if this is the current view. The BufferView
417 // metrics are already up to date.
418 if (update_metrics || lyx_view_ != guiApp->currentView()
419 || lyx_view_->currentWorkArea() != this) {
420 // FIXME: it would be nice to optimize for the off-screen case.
421 buffer_view_->updateMetrics();
422 buffer_view_->cursor().fixIfBroken();
425 // update cursor position, because otherwise it has to wait until
426 // the blinking interval is over
427 if (cursor_visible_) {
432 LYXERR(Debug::WORKAREA, "WorkArea::redraw screen");
434 update(0, 0, viewport()->width(), viewport()->height());
436 /// \warning: scrollbar updating *must* be done after the BufferView is drawn
437 /// because \c BufferView::updateScrollbar() is called in \c BufferView::draw().
439 lyx_view_->updateStatusBar();
441 if (lyxerr.debugging(Debug::WORKAREA))
442 buffer_view_->coordCache().dump();
446 void GuiWorkArea::processKeySym(KeySymbol const & key, KeyModifier mod)
448 if (lyx_view_->isFullScreen() && lyx_view_->menuBar()->isVisible()
449 && lyxrc.full_screen_menubar) {
450 // FIXME HACK: we should not have to do this here. See related comment
451 // in GuiView::event() (QEvent::ShortcutOverride)
452 lyx_view_->menuBar()->hide();
455 // In order to avoid bad surprise in the middle of an operation,
456 // we better stop the blinking cursor...
457 // the cursor gets restarted in GuiView::restartCursor()
458 stopBlinkingCursor();
459 guiApp->processKeySym(key, mod);
463 void GuiWorkArea::dispatch(FuncRequest const & cmd0, KeyModifier mod)
466 if (cmd0.action == LFUN_FILE_OPEN) {
467 lyx_view_->dispatch(cmd0);
473 if (cmd0.action == LFUN_MOUSE_PRESS) {
474 if (mod == ShiftModifier)
475 cmd = FuncRequest(cmd0, "region-select");
476 else if (mod == ControlModifier)
477 cmd = FuncRequest(cmd0, "paragraph-select");
484 bool const notJustMovingTheMouse =
485 cmd.action != LFUN_MOUSE_MOTION || cmd.button() != mouse_button::none;
487 // In order to avoid bad surprise in the middle of an operation, we better stop
488 // the blinking cursor.
489 if (notJustMovingTheMouse)
490 stopBlinkingCursor();
492 buffer_view_->mouseEventDispatch(cmd);
494 // Skip these when selecting
495 if (cmd.action != LFUN_MOUSE_MOTION) {
496 completer_->updateVisibility(false, false);
497 lyx_view_->updateDialogs();
498 lyx_view_->updateStatusBar();
501 // GUI tweaks except with mouse motion with no button pressed.
502 if (notJustMovingTheMouse) {
503 // Slight hack: this is only called currently when we
504 // clicked somewhere, so we force through the display
505 // of the new status here.
506 lyx_view_->clearMessage();
508 // Show the cursor immediately after any operation
509 startBlinkingCursor();
514 void GuiWorkArea::resizeBufferView()
516 // WARNING: Please don't put any code that will trigger a repaint here!
517 // We are already inside a paint event.
518 lyx_view_->setBusy(true);
521 buffer_view_->cursorPosAndHeight(p, h);
522 bool const cursor_in_view = buffer_view_->cursorInView(p, h);
523 buffer_view_->resize(viewport()->width(), viewport()->height());
525 buffer_view_->scrollToCursor();
528 // Update scrollbars which might have changed due different
529 // BufferView dimension. This is especially important when the
530 // BufferView goes from zero-size to the real-size for the first time,
531 // as the scrollbar paramters are then set for the first time.
534 lyx_view_->updateLayoutList();
535 lyx_view_->setBusy(false);
536 need_resize_ = false;
540 void GuiWorkArea::showCursor()
546 bool l_shape = false;
547 Font const & realfont = buffer_view_->cursor().real_current_font;
548 BufferParams const & bp = buffer_view_->buffer().params();
549 bool const samelang = realfont.language() == bp.language;
550 bool const isrtl = realfont.isVisibleRightToLeft();
552 if (!samelang || isrtl != bp.language->rightToLeft())
555 // The ERT language hack needs fixing up
556 if (realfont.language() == latex_language)
561 buffer_view_->cursorPosAndHeight(p, h);
562 // show cursor on screen
563 Cursor & cur = buffer_view_->cursor();
564 bool completable = cur.inset().showCompletionCursor()
565 && completer_->completionAvailable()
566 && !completer_->popupVisible()
567 && !completer_->inlineVisible();
568 if (buffer_view_->cursorInView(p, h)) {
569 cursor_visible_ = true;
570 showCursor(p.x_, p.y_, h, l_shape, isrtl, completable);
575 void GuiWorkArea::hideCursor()
577 if (!cursor_visible_)
580 cursor_visible_ = false;
585 void GuiWorkArea::toggleCursor()
594 void GuiWorkArea::updateScrollbar()
596 ScrollbarParameters const & scroll_ = buffer_view_->scrollbarParameters();
597 // WARNING: don't touch at the scrollbar value like this:
598 // verticalScrollBar()->setValue(scroll_.position);
599 // because this would cause a recursive signal/slot calling with
600 // GuiWorkArea::scrollTo
601 verticalScrollBar()->setRange(scroll_.min, scroll_.max);
602 verticalScrollBar()->setPageStep(scroll_.page_step);
603 verticalScrollBar()->setSingleStep(scroll_.single_step);
604 verticalScrollBar()->setSliderPosition(scroll_.position);
608 void GuiWorkArea::scrollTo(int value)
610 stopBlinkingCursor();
611 buffer_view_->scrollDocView(value);
613 if (lyxrc.cursor_follows_scrollbar) {
614 buffer_view_->setCursorFromScrollbar();
615 lyx_view_->updateLayoutList();
617 // Show the cursor immediately after any operation.
618 startBlinkingCursor();
619 QApplication::syncX();
623 bool GuiWorkArea::event(QEvent * e)
626 case QEvent::ToolTip: {
627 QHelpEvent * helpEvent = static_cast<QHelpEvent *>(e);
628 if (lyxrc.use_tooltip) {
629 QPoint pos = helpEvent->pos();
630 if (pos.x() < viewport()->width()) {
631 QString s = toqstr(buffer_view_->toolTip(pos.x(), pos.y()));
632 QToolTip::showText(helpEvent->globalPos(), s);
635 QToolTip::hideText();
637 // Don't forget to accept the event!
642 case QEvent::ShortcutOverride: {
643 // We catch this event in order to catch the Tab or Shift+Tab key press
644 // which are otherwise reserved to focus switching between controls
646 QKeyEvent * ke = static_cast<QKeyEvent*>(e);
647 if ((ke->key() != Qt::Key_Tab && ke->key() != Qt::Key_Backtab)
648 || ke->modifiers() & Qt::ControlModifier)
649 return QAbstractScrollArea::event(e);
655 return QAbstractScrollArea::event(e);
661 void GuiWorkArea::contextMenuEvent(QContextMenuEvent * e)
664 if (e->reason() == QContextMenuEvent::Mouse)
665 // the position is set on mouse press
666 pos = context_target_pos_;
669 Cursor const & cur = buffer_view_->cursor();
670 if (e->reason() == QContextMenuEvent::Keyboard && cur.inTexted()) {
671 // Do not access the context menu of math right in front of before
672 // the cursor. This does not work when the cursor is in text.
673 Inset * inset = cur.paragraph().getInset(cur.pos());
674 if (inset && inset->asInsetMath())
676 else if (cur.pos() > 0) {
677 Inset * inset = cur.paragraph().getInset(cur.pos() - 1);
682 docstring name = buffer_view_->contextMenu(pos.x(), pos.y());
684 QAbstractScrollArea::contextMenuEvent(e);
687 QMenu * menu = guiApp->menus().menu(toqstr(name), *lyx_view_);
689 QAbstractScrollArea::contextMenuEvent(e);
692 // Position the menu to the right.
693 // FIXME: menu position should be different for RTL text.
694 menu->exec(e->globalPos());
699 void GuiWorkArea::focusInEvent(QFocusEvent * e)
702 LYXERR(Debug::DEBUG, "GuiWorkArea::focusInEvent(): " << this << std::endl);
703 GuiWorkArea * old_gwa = theGuiApp()->currentView()->currentWorkArea();
705 old_gwa->stopBlinkingCursor();
706 lyx_view_->setCurrentWorkArea(this);
709 if (lyx_view_->currentWorkArea() != this)
710 lyx_view_->setCurrentWorkArea(this);
712 startBlinkingCursor();
713 QAbstractScrollArea::focusInEvent(e);
717 void GuiWorkArea::focusOutEvent(QFocusEvent * e)
719 LYXERR(Debug::DEBUG, "GuiWorkArea::focusOutEvent(): " << this << std::endl);
720 stopBlinkingCursor();
721 QAbstractScrollArea::focusOutEvent(e);
725 void GuiWorkArea::mousePressEvent(QMouseEvent * e)
727 if (dc_event_.active && dc_event_ == *e) {
728 dc_event_.active = false;
729 FuncRequest cmd(LFUN_MOUSE_TRIPLE, e->x(), e->y(),
730 q_button_state(e->button()));
736 if (e->button() == Qt::RightButton)
737 context_target_pos_ = e->pos();
739 inputContext()->reset();
741 FuncRequest const cmd(LFUN_MOUSE_PRESS, e->x(), e->y(),
742 q_button_state(e->button()));
743 dispatch(cmd, q_key_state(e->modifiers()));
748 void GuiWorkArea::mouseReleaseEvent(QMouseEvent * e)
750 if (synthetic_mouse_event_.timeout.running())
751 synthetic_mouse_event_.timeout.stop();
753 FuncRequest const cmd(LFUN_MOUSE_RELEASE, e->x(), e->y(),
754 q_button_state(e->button()));
760 void GuiWorkArea::mouseMoveEvent(QMouseEvent * e)
762 // we kill the triple click if we move
763 doubleClickTimeout();
764 FuncRequest cmd(LFUN_MOUSE_MOTION, e->x(), e->y(),
765 q_motion_state(e->buttons()));
769 // If we're above or below the work area...
770 if (e->y() <= 20 || e->y() >= viewport()->height() - 20) {
771 // Make sure only a synthetic event can cause a page scroll,
772 // so they come at a steady rate:
774 // _Force_ a scroll up:
777 cmd.y = viewport()->height();
778 // Store the event, to be handled when the timeout expires.
779 synthetic_mouse_event_.cmd = cmd;
781 if (synthetic_mouse_event_.timeout.running())
782 // Discard the event. Note that it _may_ be handled
783 // when the timeout expires if
784 // synthetic_mouse_event_.cmd has not been overwritten.
785 // Ie, when the timeout expires, we handle the
786 // most recent event but discard all others that
787 // occurred after the one used to start the timeout
788 // in the first place.
791 synthetic_mouse_event_.restart_timeout = true;
792 synthetic_mouse_event_.timeout.start();
793 // Fall through to handle this event...
795 } else if (synthetic_mouse_event_.timeout.running()) {
796 // Store the event, to be possibly handled when the timeout
798 // Once the timeout has expired, normal control is returned
799 // to mouseMoveEvent (restart_timeout = false).
800 // This results in a much smoother 'feel' when moving the
801 // mouse back into the work area.
802 synthetic_mouse_event_.cmd = cmd;
803 synthetic_mouse_event_.restart_timeout = false;
807 // Has anything changed on-screen since the last QMouseEvent
809 if (e->x() == synthetic_mouse_event_.x_old
810 && e->y() == synthetic_mouse_event_.y_old
811 && synthetic_mouse_event_.min_scrollbar_old == verticalScrollBar()->minimum()
812 && synthetic_mouse_event_.max_scrollbar_old == verticalScrollBar()->maximum()) {
813 // Nothing changed on-screen since the last QMouseEvent.
817 // Yes something has changed. Store the params used to check this.
818 synthetic_mouse_event_.x_old = e->x();
819 synthetic_mouse_event_.y_old = e->y();
820 synthetic_mouse_event_.min_scrollbar_old = verticalScrollBar()->minimum();
821 synthetic_mouse_event_.max_scrollbar_old = verticalScrollBar()->maximum();
823 // ... and dispatch the event to the LyX core.
828 void GuiWorkArea::wheelEvent(QWheelEvent * ev)
830 // Wheel rotation by one notch results in a delta() of 120 (see
831 // documentation of QWheelEvent)
832 int const delta = ev->delta() / 120;
833 if (ev->modifiers() & Qt::ControlModifier) {
834 docstring arg = convert<docstring>(5 * delta);
835 lyx::dispatch(FuncRequest(LFUN_BUFFER_ZOOM_IN, arg));
839 // Take into account the desktop wide settings.
840 int const lines = qApp->wheelScrollLines();
841 int const page_step = verticalScrollBar()->pageStep();
842 // Test if the wheel mouse is set to one screen at a time.
843 int scroll_value = lines > page_step
844 ? page_step : lines * verticalScrollBar()->singleStep();
846 // Take into account the rotation.
847 scroll_value *= delta;
849 // Take into account user preference.
850 scroll_value = int(scroll_value * lyxrc.mouse_wheel_speed);
851 LYXERR(Debug::SCROLLING, "wheelScrollLines = " << lines
852 << " delta = " << delta << " scroll_value = " << scroll_value
853 << " page_step = " << page_step);
855 verticalScrollBar()->setValue(verticalScrollBar()->value() - scroll_value);
861 void GuiWorkArea::generateSyntheticMouseEvent()
863 // Set things off to generate the _next_ 'pseudo' event.
864 if (synthetic_mouse_event_.restart_timeout)
865 synthetic_mouse_event_.timeout.start();
867 // Has anything changed on-screen since the last timeout signal
869 int const min_scrollbar = verticalScrollBar()->minimum();
870 int const max_scrollbar = verticalScrollBar()->maximum();
871 if (min_scrollbar == synthetic_mouse_event_.min_scrollbar_old
872 && max_scrollbar == synthetic_mouse_event_.max_scrollbar_old) {
875 // Yes it has. Store the params used to check this.
876 synthetic_mouse_event_.min_scrollbar_old = min_scrollbar;
877 synthetic_mouse_event_.max_scrollbar_old = max_scrollbar;
878 // ... and dispatch the event to the LyX core.
879 dispatch(synthetic_mouse_event_.cmd);
883 void GuiWorkArea::keyPressEvent(QKeyEvent * ev)
885 // Do not process here some keys if dialog_mode_ is set
887 && (ev->modifiers() == Qt::NoModifier
888 || ev->modifiers() == Qt::ShiftModifier)
889 && (ev->key() == Qt::Key_Escape
890 || ev->key() == Qt::Key_Enter
891 || ev->key() == Qt::Key_Return)
897 // intercept some keys if completion popup is visible
898 if (completer_->popupVisible()) {
902 completer_->activate();
908 // do nothing if there are other events
909 // (the auto repeated events come too fast)
910 // \todo FIXME: remove hard coded Qt keys, process the key binding
912 if (XEventsQueued(QX11Info::display(), 0) > 1 && ev->isAutoRepeat()
913 && (Qt::Key_PageDown || Qt::Key_PageUp)) {
914 LYXERR(Debug::KEY, "system is busy: scroll key event ignored");
920 LYXERR(Debug::KEY, " count: " << ev->count() << " text: " << ev->text()
921 << " isAutoRepeat: " << ev->isAutoRepeat() << " key: " << ev->key());
924 setKeySymbol(&sym, ev);
926 processKeySym(sym, q_key_state(ev->modifiers()));
934 void GuiWorkArea::doubleClickTimeout()
936 dc_event_.active = false;
940 void GuiWorkArea::mouseDoubleClickEvent(QMouseEvent * ev)
942 dc_event_ = DoubleClick(ev);
943 QTimer::singleShot(QApplication::doubleClickInterval(), this,
944 SLOT(doubleClickTimeout()));
945 FuncRequest cmd(LFUN_MOUSE_DOUBLE,
947 q_button_state(ev->button()));
953 void GuiWorkArea::resizeEvent(QResizeEvent * ev)
955 QAbstractScrollArea::resizeEvent(ev);
961 void GuiWorkArea::update(int x, int y, int w, int h)
963 viewport()->repaint(x, y, w, h);
967 void GuiWorkArea::paintEvent(QPaintEvent * ev)
969 QRect const rc = ev->rect();
970 // LYXERR(Debug::PAINTING, "paintEvent begin: x: " << rc.x()
971 // << " y: " << rc.y() << " w: " << rc.width() << " h: " << rc.height());
974 screen_ = QPixmap(viewport()->width(), viewport()->height());
976 if (cursor_visible_) {
982 QPainter pain(viewport());
983 pain.drawPixmap(rc, screen_, rc);
989 void GuiWorkArea::updateScreen()
991 GuiPainter pain(&screen_);
992 buffer_view_->draw(pain);
996 void GuiWorkArea::showCursor(int x, int y, int h,
997 bool l_shape, bool rtl, bool completable)
999 if (schedule_redraw_) {
1000 // This happens when a graphic conversion is finished. As we don't know
1001 // the size of the new graphics, it's better the update everything.
1002 // We can't use redraw() here because this would trigger a infinite
1003 // recursive loop with showCursor().
1004 buffer_view_->resize(viewport()->width(), viewport()->height());
1007 viewport()->update(QRect(0, 0, viewport()->width(), viewport()->height()));
1008 schedule_redraw_ = false;
1009 // Show the cursor immediately after the update.
1015 cursor_->update(x, y, h, l_shape, rtl, completable);
1017 viewport()->update(cursor_->rect());
1021 void GuiWorkArea::removeCursor()
1024 //if (!qApp->focusWidget())
1025 viewport()->update(cursor_->rect());
1029 void GuiWorkArea::inputMethodEvent(QInputMethodEvent * e)
1031 QString const & commit_string = e->commitString();
1032 docstring const & preedit_string
1033 = qstring_to_ucs4(e->preeditString());
1035 if (!commit_string.isEmpty()) {
1037 LYXERR(Debug::KEY, "preeditString: " << e->preeditString()
1038 << " commitString: " << e->commitString());
1042 // FIXME Iwami 04/01/07: we should take care also of UTF16 surrogates here.
1043 for (int i = 0; i != commit_string.size(); ++i) {
1044 QKeyEvent ev(QEvent::KeyPress, key, Qt::NoModifier, commit_string[i]);
1049 // Hide the cursor during the kana-kanji transformation.
1050 if (preedit_string.empty())
1051 startBlinkingCursor();
1053 stopBlinkingCursor();
1055 // last_width : for checking if last preedit string was/wasn't empty.
1056 static bool last_width = false;
1057 if (!last_width && preedit_string.empty()) {
1058 // if last_width is last length of preedit string.
1063 GuiPainter pain(&screen_);
1064 buffer_view_->updateMetrics();
1065 buffer_view_->draw(pain);
1066 FontInfo font = buffer_view_->cursor().getFont().fontInfo();
1067 FontMetrics const & fm = theFontMetrics(font);
1068 int height = fm.maxHeight();
1069 int cur_x = cursor_->rect().left();
1070 int cur_y = cursor_->rect().bottom();
1072 // redraw area of preedit string.
1073 update(0, cur_y - height, viewport()->width(),
1074 (height + 1) * preedit_lines_);
1076 if (preedit_string.empty()) {
1084 // att : stores an IM attribute.
1085 QList<QInputMethodEvent::Attribute> const & att = e->attributes();
1087 // get attributes of input method cursor.
1088 // cursor_pos : cursor position in preedit string.
1089 size_t cursor_pos = 0;
1090 bool cursor_is_visible = false;
1091 for (int i = 0; i != att.size(); ++i) {
1092 if (att.at(i).type == QInputMethodEvent::Cursor) {
1093 cursor_pos = att.at(i).start;
1094 cursor_is_visible = att.at(i).length != 0;
1099 size_t preedit_length = preedit_string.length();
1101 // get position of selection in input method.
1102 // FIXME: isn't there a way to do this simplier?
1103 // rStart : cursor position in selected string in IM.
1105 // rLength : selected string length in IM.
1107 if (cursor_pos < preedit_length) {
1108 for (int i = 0; i != att.size(); ++i) {
1109 if (att.at(i).type == QInputMethodEvent::TextFormat) {
1110 if (att.at(i).start <= int(cursor_pos)
1111 && int(cursor_pos) < att.at(i).start + att.at(i).length) {
1112 rStart = att.at(i).start;
1113 rLength = att.at(i).length;
1114 if (!cursor_is_visible)
1115 cursor_pos += rLength;
1122 rStart = cursor_pos;
1126 int const right_margin = buffer_view_->rightMargin();
1127 Painter::preedit_style ps;
1128 // Most often there would be only one line:
1130 for (size_t pos = 0; pos != preedit_length; ++pos) {
1131 char_type const typed_char = preedit_string[pos];
1132 // reset preedit string style
1133 ps = Painter::preedit_default;
1135 // if we reached the right extremity of the screen, go to next line.
1136 if (cur_x + fm.width(typed_char) > viewport()->width() - right_margin) {
1137 cur_x = right_margin;
1138 cur_y += height + 1;
1141 // preedit strings are displayed with dashed underline
1142 // and partial strings are displayed white on black indicating
1143 // that we are in selecting mode in the input method.
1144 // FIXME: rLength == preedit_length is not a changing condition
1145 // FIXME: should be put out of the loop.
1147 && pos < rStart + rLength
1148 && !(cursor_pos < rLength && rLength == preedit_length))
1149 ps = Painter::preedit_selecting;
1151 if (pos == cursor_pos
1152 && (cursor_pos < rLength && rLength == preedit_length))
1153 ps = Painter::preedit_cursor;
1155 // draw one character and update cur_x.
1156 cur_x += pain.preeditText(cur_x, cur_y, typed_char, font, ps);
1159 // update the preedit string screen area.
1160 update(0, cur_y - preedit_lines_*height, viewport()->width(),
1161 (height + 1) * preedit_lines_);
1163 // Don't forget to accept the event!
1168 QVariant GuiWorkArea::inputMethodQuery(Qt::InputMethodQuery query) const
1170 QRect cur_r(0, 0, 0, 0);
1172 // this is the CJK-specific composition window position and
1173 // the context menu position when the menu key is pressed.
1174 case Qt::ImMicroFocus:
1175 cur_r = cursor_->rect();
1176 if (preedit_lines_ != 1)
1178 cur_r.moveBottom(cur_r.bottom()
1179 + cur_r.height() * (preedit_lines_ - 1));
1180 // return lower right of cursor in LyX.
1183 return QWidget::inputMethodQuery(query);
1188 void GuiWorkArea::updateWindowTitle()
1190 docstring maximize_title;
1191 docstring minimize_title;
1193 Buffer & buf = buffer_view_->buffer();
1194 FileName const fileName = buf.fileName();
1195 if (!fileName.empty()) {
1196 maximize_title = fileName.displayName(30);
1197 minimize_title = from_utf8(fileName.onlyFileName());
1198 if (buf.lyxvc().inUse()) {
1199 if (buf.lyxvc().locker().empty())
1200 maximize_title += _(" (version control)");
1202 maximize_title += _(" (version control, locking)");
1204 if (!buf.isClean()) {
1205 maximize_title += _(" (changed)");
1206 minimize_title += char_type('*');
1208 if (buf.isReadonly())
1209 maximize_title += _(" (read only)");
1212 QString title = windowTitle();
1213 QString new_title = toqstr(maximize_title);
1214 if (title == new_title)
1217 QWidget::setWindowTitle(new_title);
1218 QWidget::setWindowIconText(toqstr(minimize_title));
1223 void GuiWorkArea::setReadOnly(bool)
1225 updateWindowTitle();
1226 if (this == lyx_view_->currentWorkArea())
1227 lyx_view_->updateDialogs();
1231 bool GuiWorkArea::isFullScreen()
1233 return lyx_view_ && lyx_view_->isFullScreen();
1237 ////////////////////////////////////////////////////////////////////
1241 ////////////////////////////////////////////////////////////////////
1244 EmbeddedWorkArea::EmbeddedWorkArea(QWidget * w): GuiWorkArea(w)
1246 buffer_ = theBufferList().newBuffer(
1247 support::FileName::tempName().absFilename() + "_embedded.internal");
1248 buffer_->setUnnamed(true);
1249 buffer_->setFullyLoaded(true);
1250 setBuffer(*buffer_);
1251 setDialogMode(true);
1255 EmbeddedWorkArea::~EmbeddedWorkArea()
1257 // No need to destroy buffer and bufferview here, because it is done
1258 // in theBuffeerList() destruction loop at application exit
1262 void EmbeddedWorkArea::closeEvent(QCloseEvent * ev)
1265 GuiWorkArea::closeEvent(ev);
1269 void EmbeddedWorkArea::hideEvent(QHideEvent * ev)
1272 GuiWorkArea::hideEvent(ev);
1276 void EmbeddedWorkArea::disable()
1278 stopBlinkingCursor();
1279 if (view().currentWorkArea() != this)
1281 // No problem if currentMainWorkArea() is 0 (setCurrentWorkArea()
1282 // tolerates it and shows the background logo), what happens if
1283 // an EmbeddedWorkArea is closed after closing all document WAs
1284 view().setCurrentWorkArea(view().currentMainWorkArea());
1287 ////////////////////////////////////////////////////////////////////
1291 ////////////////////////////////////////////////////////////////////
1294 class NoTabFrameMacStyle : public QMacStyle {
1297 QRect subElementRect(SubElement element, const QStyleOption * option,
1298 const QWidget * widget = 0) const
1300 QRect rect = QMacStyle::subElementRect(element, option, widget);
1301 bool noBar = static_cast<QTabWidget const *>(widget)->count() <= 1;
1303 // The Qt Mac style puts the contents into a 3 pixel wide box
1304 // which looks very ugly and not like other Mac applications.
1305 // Hence we remove this here, and moreover the 16 pixel round
1306 // frame above if the tab bar is hidden.
1307 if (element == QStyle::SE_TabWidgetTabContents) {
1308 rect.adjust(- rect.left(), 0, rect.left(), 0);
1317 NoTabFrameMacStyle noTabFrameMacStyle;
1321 TabWorkArea::TabWorkArea(QWidget * parent)
1322 : QTabWidget(parent), clicked_tab_(-1)
1325 setStyle(&noTabFrameMacStyle);
1327 #if QT_VERSION < 0x040500
1328 lyxrc.single_close_tab_button = true;
1331 QPalette pal = palette();
1332 pal.setColor(QPalette::Active, QPalette::Button,
1333 pal.color(QPalette::Active, QPalette::Window));
1334 pal.setColor(QPalette::Disabled, QPalette::Button,
1335 pal.color(QPalette::Disabled, QPalette::Window));
1336 pal.setColor(QPalette::Inactive, QPalette::Button,
1337 pal.color(QPalette::Inactive, QPalette::Window));
1339 QObject::connect(this, SIGNAL(currentChanged(int)),
1340 this, SLOT(on_currentTabChanged(int)));
1342 closeBufferButton = new QToolButton(this);
1343 closeBufferButton->setPalette(pal);
1344 // FIXME: rename the icon to closebuffer.png
1345 closeBufferButton->setIcon(QIcon(getPixmap("images/", "closetab", "png")));
1346 closeBufferButton->setText("Close File");
1347 closeBufferButton->setAutoRaise(true);
1348 closeBufferButton->setCursor(Qt::ArrowCursor);
1349 closeBufferButton->setToolTip(qt_("Close File"));
1350 closeBufferButton->setEnabled(true);
1351 QObject::connect(closeBufferButton, SIGNAL(clicked()),
1352 this, SLOT(closeCurrentBuffer()));
1353 setCornerWidget(closeBufferButton, Qt::TopRightCorner);
1355 // setup drag'n'drop
1356 QTabBar* tb = new DragTabBar;
1357 connect(tb, SIGNAL(tabMoveRequested(int, int)),
1358 this, SLOT(moveTab(int, int)));
1359 tb->setElideMode(Qt::ElideNone);
1362 // make us responsible for the context menu of the tabbar
1363 tb->setContextMenuPolicy(Qt::CustomContextMenu);
1364 connect(tb, SIGNAL(customContextMenuRequested(const QPoint &)),
1365 this, SLOT(showContextMenu(const QPoint &)));
1366 #if QT_VERSION >= 0x040500
1367 connect(tb, SIGNAL(tabCloseRequested(int)),
1368 this, SLOT(closeTab(int)));
1371 setUsesScrollButtons(true);
1375 void TabWorkArea::setFullScreen(bool full_screen)
1377 for (int i = 0; i != count(); ++i) {
1378 if (GuiWorkArea * wa = dynamic_cast<GuiWorkArea *>(widget(i)))
1379 wa->setFullScreen(full_screen);
1382 if (lyxrc.full_screen_tabbar)
1383 showBar(!full_screen && count() > 1);
1387 void TabWorkArea::showBar(bool show)
1389 tabBar()->setEnabled(show);
1390 tabBar()->setVisible(show);
1391 closeBufferButton->setVisible(show && lyxrc.single_close_tab_button);
1392 #if QT_VERSION >= 0x040500
1393 setTabsClosable(!lyxrc.single_close_tab_button);
1398 GuiWorkArea * TabWorkArea::currentWorkArea()
1403 GuiWorkArea * wa = dynamic_cast<GuiWorkArea *>(currentWidget());
1409 GuiWorkArea * TabWorkArea::workArea(Buffer & buffer)
1411 for (int i = 0; i != count(); ++i) {
1412 GuiWorkArea * wa = dynamic_cast<GuiWorkArea *>(widget(i));
1413 LASSERT(wa, return 0);
1414 if (&wa->bufferView().buffer() == &buffer)
1421 void TabWorkArea::closeAll()
1424 GuiWorkArea * wa = dynamic_cast<GuiWorkArea *>(widget(0));
1432 bool TabWorkArea::setCurrentWorkArea(GuiWorkArea * work_area)
1434 LASSERT(work_area, /**/);
1435 int index = indexOf(work_area);
1439 if (index == currentIndex())
1440 // Make sure the work area is up to date.
1441 on_currentTabChanged(index);
1443 // Switch to the work area.
1444 setCurrentIndex(index);
1445 work_area->setFocus();
1451 GuiWorkArea * TabWorkArea::addWorkArea(Buffer & buffer, GuiView & view)
1453 GuiWorkArea * wa = new GuiWorkArea(buffer, view);
1454 wa->setUpdatesEnabled(false);
1455 // Hide tabbar if there's no tab (avoid a resize and a flashing tabbar
1456 // when hiding it again below).
1457 if (!(currentWorkArea() && currentWorkArea()->isFullScreen()))
1458 showBar(count() > 0);
1459 addTab(wa, wa->windowTitle());
1460 QObject::connect(wa, SIGNAL(titleChanged(GuiWorkArea *)),
1461 this, SLOT(updateTabTexts()));
1462 if (currentWorkArea() && currentWorkArea()->isFullScreen())
1463 setFullScreen(true);
1465 // Hide tabbar if there's only one tab.
1466 showBar(count() > 1);
1474 bool TabWorkArea::removeWorkArea(GuiWorkArea * work_area)
1476 LASSERT(work_area, return false);
1477 int index = indexOf(work_area);
1481 work_area->setUpdatesEnabled(false);
1486 // make sure the next work area is enabled.
1487 currentWidget()->setUpdatesEnabled(true);
1488 if (currentWorkArea() && currentWorkArea()->isFullScreen())
1489 setFullScreen(true);
1491 // Show tabbar only if there's more than one tab.
1492 showBar(count() > 1);
1494 lastWorkAreaRemoved();
1502 void TabWorkArea::on_currentTabChanged(int i)
1504 // returns e.g. on application destruction
1507 GuiWorkArea * wa = dynamic_cast<GuiWorkArea *>(widget(i));
1508 LASSERT(wa, return);
1509 wa->setUpdatesEnabled(true);
1513 currentWorkAreaChanged(wa);
1515 LYXERR(Debug::GUI, "currentTabChanged " << i
1516 << "File" << wa->bufferView().buffer().absFileName());
1520 void TabWorkArea::closeCurrentBuffer()
1523 if (clicked_tab_ == -1)
1524 wa = currentWorkArea();
1526 wa = dynamic_cast<GuiWorkArea *>(widget(clicked_tab_));
1529 wa->view().closeWorkArea(wa);
1533 void TabWorkArea::hideCurrentTab()
1536 if (clicked_tab_ == -1)
1537 wa = currentWorkArea();
1539 wa = dynamic_cast<GuiWorkArea *>(widget(clicked_tab_));
1542 wa->view().hideWorkArea(wa);
1546 void TabWorkArea::closeTab(int index)
1548 on_currentTabChanged(index);
1551 wa = currentWorkArea();
1553 wa = dynamic_cast<GuiWorkArea *>(widget(index));
1556 wa->view().closeWorkArea(wa);
1563 /// make vector happy
1566 DisplayPath(int tab, FileName const & filename)
1569 filename_ = (filename.extension() == "lyx") ?
1570 toqstr(filename.onlyFileNameWithoutExt())
1571 : toqstr(filename.onlyFileName());
1572 postfix_ = toqstr(filename.absoluteFilePath()).
1573 split("/", QString::SkipEmptyParts);
1574 postfix_.pop_back();
1575 abs_ = toqstr(filename.absoluteFilePath());
1576 dottedPrefix_ = false;
1579 /// Absolute path for debugging.
1584 /// Add the first segment from the postfix or three dots to the prefix.
1585 /// Merge multiple dot tripples. In fact dots are added lazily, i.e. only
1586 /// when really needed.
1587 void shiftPathSegment(bool dotted)
1589 if (postfix_.count() <= 0)
1593 if (dottedPrefix_ && !prefix_.isEmpty())
1595 prefix_ += postfix_.front() + "/";
1597 dottedPrefix_ = dotted && !prefix_.isEmpty();
1598 postfix_.pop_front();
1601 QString displayString() const
1603 if (prefix_.isEmpty())
1606 bool dots = dottedPrefix_ || !postfix_.isEmpty();
1607 return prefix_ + (dots ? ".../" : "") + filename_;
1610 QString forecastPathString() const
1612 if (postfix_.count() == 0)
1613 return displayString();
1616 + (dottedPrefix_ ? ".../" : "")
1617 + postfix_.front() + "/";
1620 bool final() const { return postfix_.empty(); }
1622 int tab() const { return tab_; }
1628 QStringList postfix_;
1641 bool operator<(DisplayPath const & a, DisplayPath const & b)
1643 return a.displayString() < b.displayString();
1647 bool operator==(DisplayPath const & a, DisplayPath const & b)
1649 return a.displayString() == b.displayString();
1653 void TabWorkArea::updateTabTexts()
1658 std::list<DisplayPath> paths;
1659 typedef std::list<DisplayPath>::iterator It;
1661 // collect full names first: path into postfix, empty prefix and
1662 // filename without extension
1663 for (size_t i = 0; i < n; ++i) {
1664 GuiWorkArea * i_wa = dynamic_cast<GuiWorkArea *>(widget(i));
1665 FileName const fn = i_wa->bufferView().buffer().fileName();
1666 paths.push_back(DisplayPath(i, fn));
1669 // go through path segments and see if it helps to make the path more unique
1670 bool somethingChanged = true;
1671 bool allFinal = false;
1672 while (somethingChanged && !allFinal) {
1673 // adding path segments changes order
1676 LYXERR(Debug::GUI, "updateTabTexts() iteration start");
1677 somethingChanged = false;
1680 // find segments which are not unique (i.e. non-atomic)
1681 It it = paths.begin();
1683 QString segString = it->displayString();
1684 for (; it != paths.end(); ++it) {
1685 // look to the next item
1690 allFinal = allFinal && it->final();
1692 LYXERR(Debug::GUI, "it = " << it->abs()
1693 << " => " << it->displayString());
1695 // still the same segment?
1697 if ((next != paths.end()
1698 && (nextString = next->displayString()) == segString))
1700 LYXERR(Debug::GUI, "segment ended");
1702 // only a trivial one with one element?
1703 if (it == segStart) {
1704 // start new segment
1706 segString = nextString;
1710 // we found a non-atomic segment segStart <= sit <= it < next.
1711 // Shift path segments and hope for the best
1712 // that it makes the path more unique.
1713 somethingChanged = true;
1715 QString dspString = sit->forecastPathString();
1716 LYXERR(Debug::GUI, "first forecast found for "
1717 << sit->abs() << " => " << dspString);
1719 bool moreUnique = false;
1720 for (; sit != next; ++sit) {
1721 if (sit->forecastPathString() != dspString) {
1722 LYXERR(Debug::GUI, "different forecast found for "
1723 << sit->abs() << " => " << sit->forecastPathString());
1727 LYXERR(Debug::GUI, "same forecast found for "
1728 << sit->abs() << " => " << dspString);
1731 // if the path segment helped, add it. Otherwise add dots
1732 bool dots = !moreUnique;
1733 LYXERR(Debug::GUI, "using dots = " << dots);
1734 for (sit = segStart; sit != next; ++sit) {
1735 sit->shiftPathSegment(dots);
1736 LYXERR(Debug::GUI, "shifting "
1737 << sit->abs() << " => " << sit->displayString());
1740 // start new segment
1742 segString = nextString;
1746 // set new tab titles
1747 for (It it = paths.begin(); it != paths.end(); ++it) {
1748 GuiWorkArea * i_wa = dynamic_cast<GuiWorkArea *>(widget(it->tab()));
1749 Buffer & buf = i_wa->bufferView().buffer();
1750 if (!buf.fileName().empty() && !buf.isClean())
1751 setTabText(it->tab(), it->displayString() + "*");
1753 setTabText(it->tab(), it->displayString());
1758 void TabWorkArea::showContextMenu(const QPoint & pos)
1761 clicked_tab_ = static_cast<DragTabBar *>(tabBar())->tabAt(pos);
1762 if (clicked_tab_ == -1)
1767 popup.addAction(QIcon(getPixmap("images/", "hidetab", "png")),
1768 qt_("Hide tab"), this, SLOT(hideCurrentTab()));
1769 popup.addAction(QIcon(getPixmap("images/", "closetab", "png")),
1770 qt_("Close tab"), this, SLOT(closeCurrentBuffer()));
1771 popup.exec(tabBar()->mapToGlobal(pos));
1777 void TabWorkArea::moveTab(int fromIndex, int toIndex)
1779 QWidget * w = widget(fromIndex);
1780 QIcon icon = tabIcon(fromIndex);
1781 QString text = tabText(fromIndex);
1783 setCurrentIndex(fromIndex);
1784 removeTab(fromIndex);
1785 insertTab(toIndex, w, icon, text);
1786 setCurrentIndex(toIndex);
1790 DragTabBar::DragTabBar(QWidget* parent)
1793 setAcceptDrops(true);
1794 #if QT_VERSION >= 0x040500
1795 setTabsClosable(!lyxrc.single_close_tab_button);
1800 #if QT_VERSION < 0x040300
1801 int DragTabBar::tabAt(QPoint const & position) const
1803 const int max = count();
1804 for (int i = 0; i < max; ++i) {
1805 if (tabRect(i).contains(position))
1813 void DragTabBar::mousePressEvent(QMouseEvent * event)
1815 if (event->button() == Qt::LeftButton)
1816 dragStartPos_ = event->pos();
1817 QTabBar::mousePressEvent(event);
1821 void DragTabBar::mouseMoveEvent(QMouseEvent * event)
1823 // If the left button isn't pressed anymore then return
1824 if (!(event->buttons() & Qt::LeftButton))
1827 // If the distance is too small then return
1828 if ((event->pos() - dragStartPos_).manhattanLength()
1829 < QApplication::startDragDistance())
1832 // did we hit something after all?
1833 int tab = tabAt(dragStartPos_);
1837 // simulate button release to remove highlight from button
1838 int i = currentIndex();
1839 QMouseEvent me(QEvent::MouseButtonRelease, dragStartPos_,
1840 event->button(), event->buttons(), 0);
1841 QTabBar::mouseReleaseEvent(&me);
1845 QDrag * drag = new QDrag(this);
1846 QMimeData * mimeData = new QMimeData;
1847 // a crude way to distinguish tab-reodering drops from other ones
1848 mimeData->setData("action", "tab-reordering") ;
1849 drag->setMimeData(mimeData);
1851 #if QT_VERSION >= 0x040300
1852 // get tab pixmap as cursor
1853 QRect r = tabRect(tab);
1854 QPixmap pixmap(r.size());
1855 render(&pixmap, - r.topLeft());
1856 drag->setPixmap(pixmap);
1859 drag->start(Qt::MoveAction);
1865 void DragTabBar::dragEnterEvent(QDragEnterEvent * event)
1867 // Only accept if it's an tab-reordering request
1868 QMimeData const * m = event->mimeData();
1869 QStringList formats = m->formats();
1870 if (formats.contains("action")
1871 && m->data("action") == "tab-reordering")
1872 event->acceptProposedAction();
1876 void DragTabBar::dropEvent(QDropEvent * event)
1878 int fromIndex = tabAt(dragStartPos_);
1879 int toIndex = tabAt(event->pos());
1881 // Tell interested objects that
1882 if (fromIndex != toIndex)
1883 tabMoveRequested(fromIndex, toIndex);
1884 event->acceptProposedAction();
1888 } // namespace frontend
1891 #include "moc_GuiWorkArea.cpp"