~ubuntu-branches/ubuntu/saucy/texmacs/saucy-proposed

« back to all changes in this revision

Viewing changes to src/Plugins/Qt/QTMWidget.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Atsuhito KOHDA
  • Date: 2011-04-04 13:58:09 UTC
  • mfrom: (4.1.13 sid)
  • Revision ID: james.westby@ubuntu.com-20110404135809-6f6jvotefb694vgp
Tags: 1:1.0.7.10-1
* New Upstream Release.
* Added gostscript to Build-Depends.  (Closes: #582228)

Show diffs side-by-side

added added

removed removed

Lines of Context:
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);
162
162
}
163
163
 
168
168
 
169
169
void 
170
170
QTMWidget::invalidate_rect (int x1, int y1, int x2, int y2) {
171
 
  // larger rectangle is needed to avoid artifacts during cursor movements
172
 
  // see bug #28664
173
 
  rectangle r = rectangle (x1-3, y1-1, x2+4, y2+1);
 
171
#ifdef Q_WS_MAC
 
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);
 
176
#else
 
177
  rectangle r = rectangle (x1, y1, x2, y2);
 
178
#endif
174
179
  // cout << "invalidating " << r << LF;
175
180
  invalid_regions = invalid_regions | rectangles (r);
176
181
}
177
182
 
178
183
void 
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 
231
237
 
232
238
  // update backing store origin wrt. TeXmacs document
233
 
  if ( backing_pos != origin ) {
 
239
  if ( backing_pos != origin() ) {
234
240
 
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();
238
244
    
239
245
    QPixmap newBackingPixmap (backingPixmap.size());
240
246
    QPainter p (&newBackingPixmap);
279
285
    qrgn += QRect(QPoint(0,0),sz);
280
286
  }
281
287
  
 
288
  
282
289
  // update backing store size
283
290
  {
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);
291
 
      //p.end();
 
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);
 
302
      }
 
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);
 
306
      }
 
307
      p.end();
292
308
      backingPixmap = newBackingPixmap;
293
 
      invalidate_all();
294
 
      the_gui -> process_resize(tm_widget(), 0, 0); // FIXME
295
309
    }
296
310
  }
297
311
  
340
354
  }
341
355
 
342
356
  // propagate immediatly the changes to the screen  
343
 
  QAbstractScrollArea::viewport()->repaint(qrgn);
 
357
  surface()->repaint(qrgn);
344
358
  
345
359
}
346
360
 
347
361
void 
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
351
 
  // of the widget.
352
 
  needs_update(); 
 
364
 
 
365
  force_update();
 
366
  // we force an update of the internal state to be in sync with the moving
 
367
  // scrollbars
353
368
}
354
369
 
355
370
void 
356
371
QTMWidget::resizeEvent( QResizeEvent* event ) {
 
372
  (void) event;
 
373
  
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
361
 
  // of the widget.
362
 
  needs_update(); 
 
376
  
 
377
  the_gui -> process_resize(tm_widget(), 0, 0); // FIXME
 
378
 
 
379
  // force_update();
 
380
 
 
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. 
 
385
  //
 
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.
363
388
}
364
389
 
 
390
 
 
391
 
 
392
 
365
393
void
366
394
QTMWidget::paintEvent (QPaintEvent* event) {
367
395
  // In the current implementation repainting take place during the call to
380
408
  }
381
409
    
382
410
  {    
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);
388
416
    }
389
 
  }
 
417
  } 
390
418
  
391
419
}
392
420
 
661
689
#endif
662
690
  }
663
691
  
664
 
  if (!preedit_string.isEmpty()) {
665
 
    if (DEBUG_QT)
666
 
      cout << "IM preediting :" << preedit_string.toUtf8().data() << LF;
667
 
 
668
 
    
669
 
    string r = "pre-edit:" * from_qstring(preedit_string);
670
 
    simple_widget_rep *wid =  tm_widget();
671
 
    if (wid)
672
 
      the_gui -> process_keypress (wid, r, texmacs_time());
 
692
  if (DEBUG_QT)
 
693
    cout << "IM preediting :" << preedit_string.toUtf8().data() << LF;
 
694
  
 
695
  string r = "pre-edit:";
 
696
  if (!preedit_string.isEmpty())
 
697
  {
 
698
    
 
699
    // find cursor position in the preedit string
 
700
    QList<QInputMethodEvent::Attribute>  const & attrs = event->attributes();
 
701
    //    int pos = preedit_string.count();
 
702
    int pos = 0;
 
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);
 
708
      }
 
709
    
 
710
    // find selection in the preedit string
 
711
    int sel_start = 0;
 
712
    int sel_length = 0;
 
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;
 
720
        }
 
721
    } else {
 
722
      sel_start = pos;
 
723
      sel_length = 0;
 
724
    }
 
725
    
 
726
    r = r * as_string(pos) * ":" 
 
727
    * from_qstring(preedit_string);
673
728
  }
 
729
  simple_widget_rep *wid =  tm_widget();
 
730
  if (wid)
 
731
    the_gui -> process_keypress (wid, r, texmacs_time());
674
732
  event->accept();
675
733
}  
676
734
 
678
736
QTMWidget::inputMethodQuery ( Qt::InputMethodQuery query ) const {
679
737
  switch (query) {
680
738
    case Qt::ImMicroFocus :
681
 
      return QVariant(QRect(cursor_pos ,QSize(5,5)));
 
739
      return QVariant (QRect (cursor_pos, QSize (5,5)));
682
740
    default:
683
 
      return QVariant();
 
741
      return QWidget::inputMethodQuery (query);
684
742
  }
685
743
}
686
744
 
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();
697
755
  scale (point);
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();
713
771
  scale (point);
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();
729
787
  scale (point);
730
788
  unsigned int mstate= mouse_state (event, false);
731
789
  string s= "move";
744
802
    QKeyEvent *ke = static_cast<QKeyEvent*> (event);
745
803
    keyPressEvent (ke);
746
804
    return true;
747
 
  }
 
805
  } 
748
806
  return QTMScrollView::event (event);
749
807
}
750
808