149
149
// map (Qt::Key_ModeSwitchFunctionKey, "modeswitch" );
153
QTMWidget::postponedUpdate () {
155
//FIXME: the call below to update is ignored sometimes (usually in long documents).
156
// It is a confirmed Qt/Mac bug (#251792). See
157
// http://www.qtsoftware.com/developer/task-tracker/index_html?method=entry&id=251792
158
//FIXME: This is a workaround for the update(rect) bug. Mac specific.
160
cout << "postponedUpdate (ALL)\n";
163
delayed_rects= list<QRect>();
165
while (!is_nil (delayed_rects)) {
166
QRect rect = delayed_rects->item;
168
cout << "postponedUpdate (" << rect.x()
170
<< "," << rect.width()
171
<< "," << rect.height() << ")\n" ;
174
delayed_rects= delayed_rects->next;
180
void QTMWidget::resizeEvent( QResizeEvent* event )
182
//cout << "QTMWidget::resizeEvent (" << event->size().width() << "," << event->size().height() << ")" << LF;
183
QWidget::resizeEvent (event);
184
#if defined(Q_WS_X11) && defined(USE_CAIRO)
185
backingPixmap = QPixmap(width(),height());
190
QTMWidget::paintEvent (QPaintEvent* event) {
191
//cout << "paint"<< LF;
192
QRect rect = event->rect ();
193
bool partial_redraw = false;
197
QBrush brush (QColor ("red"));
198
p.fillRect (rect, brush);
201
cout << "paintEvent ("<< rect.x()
203
<< "," << rect.width()
204
<< "," << rect.height() << ")\n" ;
208
if (!qt_update_flag) {
209
//time_t start= texmacs_time ();
210
basic_renderer_rep *r;
154
QTMWidget::QTMWidget (simple_widget_rep *_wid)
155
: QTMScrollView (), backingPixmap() {
156
setObjectName("A QTMWidget");
157
setProperty ("texmacs_widget", QVariant::fromValue ((void*) _wid));
158
QAbstractScrollArea::viewport()->setMouseTracking (true);
159
QAbstractScrollArea::viewport()->setFocusPolicy (Qt::StrongFocus);
160
backing_pos = origin;
164
QTMWidget::~QTMWidget () {
165
if (DEBUG_QT) cout << "destroying " << this << LF;
169
QTMWidget::invalidate_rect (int x1, int y1, int x2, int y2) {
170
rectangle r = rectangle (x1, y1, x2, y2);
171
// cout << "invalidating " << r << LF;
172
invalid_regions = invalid_regions | rectangles (r);
176
QTMWidget::invalidate_all () {
177
QSize sz = QAbstractScrollArea::viewport()->size();
178
//cout << "invalidate all " << LF;
179
invalid_regions = rectangles();
180
invalidate_rect (0, 0, sz.width(), sz.height());
185
QTMWidget::getRenderer() {
213
r = the_cairo_renderer ();
214
cairo_surface_t *surf;
187
cairo_renderer_rep *ren = the_cairo_renderer ();
188
cairo_surface_t *surf;
216
//const QX11Info & info = x11Info();//qt_x11Info(this);
217
// Display *dpy = x11Info().display();
218
//backingPixmap = QPixmap(width(),height());
219
//cout << backingPixmap.width() << LF;
220
Display *dpy = QX11Info::display();
221
Drawable drawable = backingPixmap.handle();
222
Visual *visual = (Visual*)(backingPixmap.x11Info().visual());
223
surf = tm_cairo_xlib_surface_create (dpy, drawable, visual, backingPixmap.width (), backingPixmap.height ());
190
//const QX11Info & info = x11Info();//qt_x11Info(this);
191
// Display *dpy = x11Info().display();
192
//backingPixmap = QPixmap(width(),height());
193
//cout << backingPixmap.width() << LF;
194
Display *dpy = QX11Info::display();
195
Drawable drawable = backingPixmap.handle();
196
Visual *visual = (Visual*)(backingPixmap.x11Info().visual());
197
surf = tm_cairo_xlib_surface_create (dpy, drawable, visual,
198
backingPixmap.width (), backingPixmap.height ());
224
199
#elif defined(Q_WS_MAC)
225
surf = tm_cairo_quartz_surface_create_for_cg_context ((CGContextRef)(this->macCGHandle()), width(), height());
200
surf = tm_cairo_quartz_surface_create_for_cg_context (
201
(CGContextRef)(this->macCGHandle()), width(), height());
227
cairo_t *ct = tm_cairo_create (surf);
229
tm_cairo_surface_destroy (surf);
230
tm_cairo_destroy (ct);
203
cairo_t *ct = tm_cairo_create (surf);
205
tm_cairo_surface_destroy (surf);
206
tm_cairo_destroy (ct);
232
r = the_qt_renderer();
233
r->begin (static_cast<QPaintDevice*>(this));
236
tm_widget()->set_current_renderer(r);
241
(rect.x()*PIXEL, -(rect.y()+rect.height())*PIXEL,
242
(rect.x()+rect.width())*PIXEL, -rect.y()*PIXEL);
243
tm_widget()->handle_repaint
244
(rect.x()*PIXEL, -(rect.y()+rect.height())*PIXEL,
245
(rect.x()+rect.width())*PIXEL, -rect.y()*PIXEL);
247
if (r->interrupted()) {
249
cout << "Interrupted\n";
250
qt_update_flag= true;
251
partial_redraw = true;
256
tm_widget()->set_current_renderer(NULL);
257
//time_t end= texmacs_time ();
258
//if (end > start) cout << "Repaint " << end - start << "\n";
262
#if defined(Q_WS_X11) && defined(USE_CAIRO)
264
// copy pixmap to screen
265
QPainter painter (this);
266
painter.drawPixmap (0,0,backingPixmap);
274
cout << "Postponed redrawing\n";
275
delayed_rects= list<QRect> (rect, delayed_rects);
276
QTimer::singleShot (1, this, SLOT (postponedUpdate ()));
208
qt_renderer_rep * ren = the_qt_renderer();
209
ren->begin(&backingPixmap);
215
QTMWidget::repaint_invalid_regions () {
217
// this function is called by the qt_gui::update method to keep the backing
218
// store in sync and propagate the changes to the surface on screen.
219
// first we check that the backing store geometry is right and then we
220
// request to the texmacs canvas widget to repaint the regions which were
221
// marked invalid. Subsequently, for each succesfully repainted region, we
222
// propagate its contents from the backing store to the onscreen surface.
223
// If repaint has been interrupted we do not propagate the changes and proceed
224
// to mark the region invalid again.
227
// qrgn is to keep track of the area on the sceen which needs to be updated
229
// update backing store origin wrt. TeXmacs document
230
if ( backing_pos != origin ) {
232
int dx = origin.x() - backing_pos.x();
233
int dy = origin.y() - backing_pos.y();
234
backing_pos = origin;
236
QPixmap newBackingPixmap (backingPixmap.size());
237
QPainter p (&newBackingPixmap);
238
//newBackingPixmap.fill(Qt::black);
239
p.drawPixmap(-dx,-dy,backingPixmap);
241
backingPixmap = newBackingPixmap;
242
//cout << "SCROLL CONTENTS BY " << dx << " " << dy << LF;
244
QSize sz = backingPixmap.size();
247
while (!is_nil(invalid_regions)) {
248
rectangle r = invalid_regions->item ;
249
// rectangle q = rectangle(r->x1+dx,r->y1-dy,r->x2+dx,r->y2-dy);
250
rectangle q = rectangle(r->x1-dx,r->y1-dy,r->x2-dx,r->y2-dy);
251
invalid = rectangles (q, invalid);
252
//cout << r << " ---> " << q << LF;
253
invalid_regions = invalid_regions->next;
255
invalid_regions= invalid &
256
rectangles(rectangle(0,0,
257
sz.width(),sz.height())) ;
260
invalidate_rect(0,0,sz.width(),min(sz.height(),-dy));
262
invalidate_rect(0,max(0,sz.height()-dy),sz.width(),sz.height());
265
invalidate_rect(0,0,min(-dx,sz.width()),sz.height());
267
invalidate_rect(max(0,sz.width()-dx),0,sz.width(),sz.height());
269
// we cal update now to allow repainint of invalid regions
270
// this cannot be done directly since interpose handler needs
271
// to be run at least once in some situations
272
// (for example when scrolling is initiated by TeXmacs itself)
274
// QAbstractScrollArea::viewport()->scroll(-dx,-dy);
275
// QAbstractScrollArea::viewport()->update();
276
qrgn += QRect(QPoint(0,0),sz);
279
// update backing store size
281
QSize _oldSize = backingPixmap.size();
282
QSize _newSize = QAbstractScrollArea::viewport()->size();
283
if (_newSize != _oldSize) {
284
// cout << "RESIZING BITMAP"<< LF;
285
QPixmap newBackingPixmap (_newSize);
286
//QPainter p (&newBackingPixmap);
287
//p.drawPixmap(0,0,backingPixmap);
289
backingPixmap = newBackingPixmap;
291
the_gui -> process_resize(tm_widget(), 0, 0); // FIXME
295
// repaint invalid rectangles
297
rectangles new_regions;
298
if (!is_nil (invalid_regions)) {
299
rectangle lub= least_upper_bound (invalid_regions);
300
if (area (lub) < 1.2 * area (invalid_regions))
301
invalid_regions= rectangles (lub);
303
basic_renderer_rep* ren = getRenderer();
304
tm_widget()->set_current_renderer(ren);
306
SI ox = -backing_pos.x()*PIXEL;
307
SI oy = backing_pos.y()*PIXEL;
309
rectangles rects = invalid_regions;
310
invalid_regions = rectangles();
312
while (!is_nil (rects)) {
313
rectangle r = copy (rects->item);
314
rectangle r0 = rects->item;
315
QRect qr = QRect(r0->x1, r0->y1, r0->x2 - r0->x1, r0->y2 - r0->y1);
316
//cout << "repainting " << r0 << "\n";
317
ren->set_origin(ox,oy);
318
ren->encode (r->x1, r->y1);
319
ren->encode (r->x2, r->y2);
320
ren->set_clipping (r->x1, r->y2, r->x2, r->y1);
321
tm_widget()->handle_repaint (r->x1, r->y2, r->x2, r->y1);
322
if (ren->interrupted ()) {
323
//cout << "interrupted repainting of " << r0 << "\n";
324
//ren->set_color(green);
325
//ren->line(r->x1, r->y1, r->x2, r->y2);
326
//ren->line(r->x1, r->y2, r->x2, r->y1);
327
invalidate_rect (r0->x1, r0->y1, r0->x2, r0->y2);
333
tm_widget()->set_current_renderer(NULL);
335
} // !is_nil(invalid_regions)
339
// propagate immediatly the changes to the screen
340
QAbstractScrollArea::viewport()->repaint(qrgn);
345
QTMWidget::scrollContentsBy ( int dx, int dy ) {
346
QTMScrollView::scrollContentsBy (dx,dy);
347
// the_gui::update needs to be run as soon as possible to refresh the status
353
QTMWidget::resizeEvent( QResizeEvent* event ) {
354
// cout << "QTMWidget::resizeEvent (" << event->size().width()
355
// << "," << event->size().height() << ")" << LF;
356
QTMScrollView::resizeEvent (event);
357
// the_gui::update needs to be run as soon as possible to refresh the status
363
QTMWidget::paintEvent (QPaintEvent* event) {
364
// In the current implementation repainting take place during the call to
365
// the widget's repaint_invalid_regions method in the_gui::update. All
366
// we have to do is to take the backing store and put it on screen according
367
// to the QRegion marked invalid.
368
// CHECK: Maybe just put onscreen all the region bounding rectangle could not
374
QRect rect = event->rect ();
375
cout << "paintEvent ("<< rect.x() << "," << rect.y()
376
<< "," << rect.width() << "," << rect.height() << ")" << LF ;
380
QPainter p (QAbstractScrollArea::viewport());
381
QVector<QRect> rects = event->region().rects();
382
for (int i=0; i< rects.count(); i++) {
383
QRect qr = rects.at(i);
384
p.drawPixmap(qr,backingPixmap,qr);
282
392
QTMWidget::keyPressEvent (QKeyEvent* event) {
284
timeout_time= texmacs_time () + time_credit;
285
393
static bool fInit = false;