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