155
155
: QTMScrollView (), backingPixmap(), imwidget(NULL) {
156
156
setObjectName("A QTMWidget");
157
157
setProperty ("texmacs_widget", QVariant::fromValue ((void*) _wid));
158
QAbstractScrollArea::viewport()->setMouseTracking (true);
158
surface()->setMouseTracking (true);
159
159
setFocusPolicy (Qt::StrongFocus);
160
backing_pos = origin;
160
backing_pos = origin();
161
161
setAttribute(Qt::WA_InputMethodEnabled);
170
170
QTMWidget::invalidate_rect (int x1, int y1, int x2, int y2) {
171
// larger rectangle is needed to avoid artifacts during cursor movements
173
rectangle r = rectangle (x1-3, y1-1, x2+4, y2+1);
172
//HACK: for unknown reasons we need to enlarge the invalid rect to prevent
173
//artifacts while moving the cursor (for example at the end of a formula like
174
// $a+f$. These artifacts seems present only on 64 bit Macs.
175
rectangle r = rectangle (x1-10, y1-10, x2+10, y2+10);
177
rectangle r = rectangle (x1, y1, x2, y2);
174
179
// cout << "invalidating " << r << LF;
175
180
invalid_regions = invalid_regions | rectangles (r);
179
184
QTMWidget::invalidate_all () {
180
QSize sz = QAbstractScrollArea::viewport()->size();
185
QSize sz = surface()->size();
186
// QPoint pt = QAbstractScrollArea::viewport()->pos();
181
187
//cout << "invalidate all " << LF;
182
188
invalid_regions = rectangles();
183
189
invalidate_rect (0, 0, sz.width(), sz.height());
230
236
// qrgn is to keep track of the area on the sceen which needs to be updated
232
238
// update backing store origin wrt. TeXmacs document
233
if ( backing_pos != origin ) {
239
if ( backing_pos != origin() ) {
235
int dx = origin.x() - backing_pos.x();
236
int dy = origin.y() - backing_pos.y();
237
backing_pos = origin;
241
int dx = origin().x() - backing_pos.x();
242
int dy = origin().y() - backing_pos.y();
243
backing_pos = origin();
239
245
QPixmap newBackingPixmap (backingPixmap.size());
240
246
QPainter p (&newBackingPixmap);
279
285
qrgn += QRect(QPoint(0,0),sz);
282
289
// update backing store size
284
291
QSize _oldSize = backingPixmap.size();
285
QSize _newSize = QAbstractScrollArea::viewport()->size();
292
QSize _newSize = surface()->size();
286
293
if (_newSize != _oldSize) {
287
294
// cout << "RESIZING BITMAP"<< LF;
288
295
QPixmap newBackingPixmap (_newSize);
289
//QPainter p (&newBackingPixmap);
290
//p.drawPixmap(0,0,backingPixmap);
296
QPainter p (&newBackingPixmap);
297
p.drawPixmap(0,0,backingPixmap);
298
//p.fillRect(0, 0, _newSize.width(), _newSize.height(), Qt::red);
299
if (_newSize.width() >= _oldSize.width()) {
300
invalidate_rect(_oldSize.width(), 0, _newSize.width(), _newSize.height());
301
p.fillRect(QRect(_oldSize.width(), 0, _newSize.width()-_oldSize.width(), _newSize.height()), Qt::gray);
303
if (_newSize.height() >= _oldSize.height()) {
304
invalidate_rect(0,_oldSize.height(), _newSize.width(), _newSize.height());
305
p.fillRect(QRect(0,_oldSize.height(), _newSize.width(), _newSize.height()-_oldSize.height()), Qt::gray);
292
308
backingPixmap = newBackingPixmap;
294
the_gui -> process_resize(tm_widget(), 0, 0); // FIXME
342
356
// propagate immediatly the changes to the screen
343
QAbstractScrollArea::viewport()->repaint(qrgn);
357
surface()->repaint(qrgn);
348
362
QTMWidget::scrollContentsBy ( int dx, int dy ) {
349
363
QTMScrollView::scrollContentsBy (dx,dy);
350
// the_gui::update needs to be run as soon as possible to refresh the status
366
// we force an update of the internal state to be in sync with the moving
356
371
QTMWidget::resizeEvent( QResizeEvent* event ) {
357
374
// cout << "QTMWidget::resizeEvent (" << event->size().width()
358
375
// << "," << event->size().height() << ")" << LF;
359
QTMScrollView::resizeEvent (event);
360
// the_gui::update needs to be run as soon as possible to refresh the status
377
the_gui -> process_resize(tm_widget(), 0, 0); // FIXME
381
//FIXME: I would like to have a force_update here but this cause a failed
382
//assertion in TeXmacs since the at the boot not every internal structure is
383
//initialized at this point. It seems not too difficult to fix but I
384
//postpone this to discuss with Joris.
386
//Not having a force_update results in some lack of sync of the surface
387
//while the user is actively resizing with the mouse.
366
394
QTMWidget::paintEvent (QPaintEvent* event) {
367
395
// In the current implementation repainting take place during the call to
383
QPainter p (QAbstractScrollArea::viewport());
411
QPainter p (surface());
384
412
QVector<QRect> rects = event->region().rects();
385
413
for (int i=0; i< rects.count(); i++) {
386
414
QRect qr = rects.at(i);
387
415
p.drawPixmap(qr,backingPixmap,qr);
664
if (!preedit_string.isEmpty()) {
666
cout << "IM preediting :" << preedit_string.toUtf8().data() << LF;
669
string r = "pre-edit:" * from_qstring(preedit_string);
670
simple_widget_rep *wid = tm_widget();
672
the_gui -> process_keypress (wid, r, texmacs_time());
693
cout << "IM preediting :" << preedit_string.toUtf8().data() << LF;
695
string r = "pre-edit:";
696
if (!preedit_string.isEmpty())
699
// find cursor position in the preedit string
700
QList<QInputMethodEvent::Attribute> const & attrs = event->attributes();
701
// int pos = preedit_string.count();
703
bool visible_cur = false;
704
for(int i=0; i< attrs.count(); i++)
705
if (attrs[i].type == QInputMethodEvent::Cursor) {
706
pos = attrs[i].start;
707
visible_cur = (attrs[i].length != 0);
710
// find selection in the preedit string
713
if (pos < preedit_string.count()) {
714
for(int i=0; i< attrs.count(); i++)
715
if ((attrs[i].type == QInputMethodEvent::TextFormat) &&
716
(attrs[i].start <= pos) && (pos < attrs[i].start + attrs[i].length)) {
717
sel_start = attrs[i].start;
718
sel_length = attrs[i].length;
719
if (!visible_cur) pos += attrs[i].length;
726
r = r * as_string(pos) * ":"
727
* from_qstring(preedit_string);
729
simple_widget_rep *wid = tm_widget();
731
the_gui -> process_keypress (wid, r, texmacs_time());
678
736
QTMWidget::inputMethodQuery ( Qt::InputMethodQuery query ) const {
680
738
case Qt::ImMicroFocus :
681
return QVariant(QRect(cursor_pos ,QSize(5,5)));
739
return QVariant (QRect (cursor_pos, QSize (5,5)));
741
return QWidget::inputMethodQuery (query);
693
751
QTMWidget::mousePressEvent (QMouseEvent* event) {
694
752
simple_widget_rep *wid= tm_widget ();
695
753
if (!wid) return;
696
QPoint point = event->pos() + origin;
754
QPoint point = event->pos() + origin();
698
756
unsigned int mstate= mouse_state (event, false);
699
757
string s= "press-" * mouse_decode (mstate);
709
767
QTMWidget::mouseReleaseEvent (QMouseEvent* event) {
710
768
simple_widget_rep *wid = tm_widget();
711
769
if (!wid) return;
712
QPoint point = event->pos() + origin;;
770
QPoint point = event->pos() + origin();
714
772
unsigned int mstate= mouse_state (event, true);
715
773
string s= "release-" * mouse_decode (mstate);
725
783
QTMWidget::mouseMoveEvent (QMouseEvent* event) {
726
784
simple_widget_rep *wid = tm_widget();
727
785
if (!wid) return;
728
QPoint point = event->pos() + origin;
786
QPoint point = event->pos() + origin();
730
788
unsigned int mstate= mouse_state (event, false);
731
789
string s= "move";