~ubuntu-branches/ubuntu/precise/ipe/precise

« back to all changes in this revision

Viewing changes to src/ipeqtcanvas/ipeqtcanvas.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Steve M. Robbins
  • Date: 2011-02-15 23:06:48 UTC
  • mfrom: (4.1.8 sid)
  • Revision ID: james.westby@ubuntu.com-20110215230648-ddivgj61o8k7et79
Tags: 7.0.14-1
* New upstream.  Update control, rules.

* libipe7.0.13.install:
* ipe.links: Remove.  Replace with explicit calls in rules using
  $(IPEVERS).  Fixes lua link.  Closes: #611560.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
/*
5
5
 
6
6
    This file is part of the extensible drawing editor Ipe.
7
 
    Copyright (C) 1993-2009  Otfried Cheong
 
7
    Copyright (C) 1993-2010  Otfried Cheong
8
8
 
9
9
    Ipe is free software; you can redistribute it and/or modify it
10
10
    under the terms of the GNU General Public License as published by
159
159
  iAutoSnap = false;
160
160
  iFifiVisible = false;
161
161
 
 
162
  iAdditionalModifiers = 0;
 
163
 
162
164
  iStyle.paperColor = Color(1000,1000,1000);
163
165
  iStyle.pretty = false;
164
166
  iStyle.classicGrid = false;
165
167
  iStyle.thinLine = 0.2;
166
168
  iStyle.thickLine = 0.9;
 
169
  iStyle.thinStep = 1;
 
170
  iStyle.thickStep = 4;
 
171
  iStyle.paperClip = false;
 
172
  iStyle.numberPages = false;
167
173
 
168
174
  iSnap.iSnap = 0;
169
175
  iSnap.iGridVisible = false;
201
207
// --------------------------------------------------------------------
202
208
 
203
209
//! Set the page to be displayed.
204
 
/*! Doesn't take ownership of any argument. */
205
 
void Canvas::setPage(const Page *page, int view, const Cascade *sheet)
 
210
/*! Doesn't take ownership of any argument.
 
211
  The page number \a pno is only needed if page numbering is turned on.
 
212
*/
 
213
void Canvas::setPage(const Page *page, int pno, int view, const Cascade *sheet)
206
214
{
207
215
  iPage = page;
 
216
  iPageNumber = pno;
208
217
  iView = view;
209
218
  iCascade = sheet;
210
219
}
216
225
  iStyle = style;
217
226
}
218
227
 
219
 
//! Determine whether pretty display should be used.
220
 
/*! In pretty display, no dashed lines are drawn around text objects,
221
 
  and if Latex font data is not available, no text is drawn at all. */
222
 
void Canvas::setPretty(bool pretty)
223
 
{
224
 
  iStyle.pretty = pretty;
225
 
}
226
 
 
227
228
//! Set current pan position.
228
229
/*! The pan position is the user coordinate that is displayed at
229
230
  the very center of the canvas. */
252
253
  iDimmed = dimmed;
253
254
}
254
255
 
 
256
//! Set additional modifiers.
 
257
/*! These modifier bits are passed to the Tool when a key is pressed
 
258
    or a drawing action is performed in addition to the actual
 
259
    keyboard modifiers. */
 
260
void Canvas::setAdditionalModifiers(int mod)
 
261
{
 
262
  iAdditionalModifiers = mod;
 
263
}
 
264
 
255
265
//! Enable automatic angular snapping with this origin.
256
266
void Canvas::setAutoOrigin(const Vector &v)
257
267
{
327
337
 
328
338
void Canvas::drawGrid(cairo_t *cc)
329
339
{
330
 
  int step = iSnap.iGridSize;
 
340
  int step = iSnap.iGridSize * iStyle.thinStep;
331
341
  double pixstep = step * iZoom;
332
342
  if (pixstep < 3.0)
333
343
    return;
334
344
 
335
 
  int vfactor = 1;
336
 
  int vstep = step * vfactor;
337
 
 
338
 
  Rect paper = iCascade->findLayout()->paper();
339
 
  Vector ll = paper.bottomLeft();
340
 
  Vector ur = paper.topRight();
 
345
  // Rect paper = iCascade->findLayout()->paper();
 
346
  // Vector ll = paper.bottomLeft();
 
347
  // Vector ur = paper.topRight();
 
348
  Vector ll = Vector::ZERO;
 
349
  Vector ur = iCascade->findLayout()->iFrameSize;
341
350
 
342
351
  int left = step * int(ll.x / step);
343
352
  if (left < ll.x)
356
365
  if (iStyle.classicGrid) {
357
366
    double lw = iStyle.thinLine / iZoom;
358
367
    cairo_set_line_width(cc, lw);
359
 
    for (int y = bottom; y < ur.y; y += vstep) {
 
368
    for (int y = bottom; y < ur.y; y += step) {
360
369
      if (screenLR.y <= y && y <= screenUL.y) {
361
 
        for (int x = left; x < ur.x; x += vstep) {
 
370
        for (int x = left; x < ur.x; x += step) {
362
371
          if (screenUL.x <= x && x <= screenLR.x) {
363
372
            cairo_move_to(cc, x, y - 0.5 * lw);
364
373
            cairo_line_to(cc, x, y + 0.5 * lw);
370
379
  } else {
371
380
    double thinLine = iStyle.thinLine / iZoom;
372
381
    double thickLine = iStyle.thickLine / iZoom;
373
 
    int thickStep = 4 * step;
 
382
    int thickStep = iStyle.thickStep * step;
374
383
 
375
384
    // draw horizontal lines
376
 
    for (int y = bottom; y < ur.y; y += vstep) {
 
385
    for (int y = bottom; y < ur.y; y += step) {
377
386
      if (screenLR.y <= y && y <= screenUL.y) {
378
387
        cairo_set_line_width(cc, (y % thickStep) ? thinLine : thickLine);
379
388
        cairo_move_to(cc, ll.x, y);
383
392
    }
384
393
 
385
394
    // draw vertical lines
386
 
    for (int x = left; x < ur.x; x += vstep) {
 
395
    for (int x = left; x < ur.x; x += step) {
387
396
      if (screenUL.x <= x && x <= screenLR.x) {
388
397
        cairo_set_line_width(cc, (x % thickStep) ? thinLine : thickLine);
389
398
        cairo_move_to(cc, x, ll.y);
429
438
  if (!iPage)
430
439
    return;
431
440
 
 
441
  if (iStyle.paperClip) {
 
442
    const Layout *l = iCascade->findLayout();
 
443
    cairo_rectangle(cc, -l->iOrigin.x, -l->iOrigin.y,
 
444
                    l->iPaperSize.x, l->iPaperSize.y);
 
445
    cairo_clip(cc);
 
446
  }
 
447
 
432
448
  CairoPainter painter(iCascade, iFonts, cc, iZoom, iStyle.pretty);
433
449
  painter.setDimmed(iDimmed);
434
450
  // painter.Transform(CanvasTfm());
439
455
  if (background && iPage->findLayer("BACKGROUND") < 0)
440
456
    background->iObject->draw(painter);
441
457
 
 
458
  if (iStyle.numberPages) {
 
459
    const StyleSheet::PageNumberStyle *pns =
 
460
      iCascade->findPageNumberStyle();
 
461
    cairo_save(cc);
 
462
    cairo_set_source_rgb(cc, pns->iColor.iRed.toDouble(),
 
463
                         pns->iColor.iGreen.toDouble(),
 
464
                         pns->iColor.iBlue.toDouble());
 
465
    cairo_select_font_face(cc, "sans-serif",
 
466
                           CAIRO_FONT_SLANT_NORMAL,
 
467
                           CAIRO_FONT_WEIGHT_NORMAL);
 
468
    cairo_set_font_size(cc, pns->iFontSize);
 
469
    cairo_move_to(cc, pns->iPos.x, pns->iPos.y);
 
470
    cairo_scale(cc, 1.0, -1.0);
 
471
    char buf[20];
 
472
    if (iPage->countViews() > 0)
 
473
      sprintf(buf, "%d-%d", iPageNumber + 1, iView + 1);
 
474
    else
 
475
      sprintf(buf, "%d", iPageNumber + 1);
 
476
    cairo_show_text(cc, buf);
 
477
    cairo_restore(cc);
 
478
  }
 
479
 
442
480
  const Text *title = iPage->titleText();
443
481
  if (title)
444
482
    title->draw(painter);
602
640
void Canvas::keyPressEvent(QKeyEvent *ev)
603
641
{
604
642
  String s = IpeQ(ev->text());
605
 
  if (iTool && iTool->key(ev->key(), ev->modifiers(), s))
 
643
  if (iTool && iTool->key(ev->key(), ev->modifiers()|iAdditionalModifiers, s))
606
644
    ev->accept();
607
645
  else
608
646
    ev->ignore();
613
651
  iGlobalPos = Vector(ev->globalPos().x(), ev->globalPos().y());
614
652
  computeFifi(ev->x(), ev->y());
615
653
  if (iTool)
616
 
    iTool->mouseButton(ev->button() | ev->modifiers(), true);
 
654
    iTool->mouseButton(ev->button() | ev->modifiers() | iAdditionalModifiers,
 
655
                       true);
617
656
  else
618
 
    emit mouseAction(ev->button() | ev->modifiers());
 
657
    emit mouseAction(ev->button() | ev->modifiers() | iAdditionalModifiers);
619
658
}
620
659
 
621
660
void Canvas::mouseReleaseEvent(QMouseEvent *ev)
642
681
 
643
682
  switch (ev->type()) {
644
683
  case QEvent::TabletPress:
 
684
    iGlobalPos = globalPos;
 
685
    computeFifi(hiPos.x(), hiPos.y());
645
686
    if (ev->pointerType() == QTabletEvent::Eraser)
646
 
      return; // not yet implemented
647
 
    iGlobalPos = globalPos;
648
 
    computeFifi(hiPos.x(), hiPos.y());
649
 
    if (iTool)
650
 
      iTool->mouseButton(Qt::LeftButton, true);
 
687
      emit mouseAction(Qt::MidButton | iAdditionalModifiers);
 
688
    else if (iTool)
 
689
      iTool->mouseButton(Qt::LeftButton | iAdditionalModifiers, true);
651
690
    else
652
 
      emit mouseAction(Qt::LeftButton);
 
691
      emit mouseAction(Qt::LeftButton | iAdditionalModifiers);
653
692
    break;
654
693
  case QEvent::TabletMove:
655
694
    if (ev->pressure() > 0.01) {
712
751
        drawFrame(cc);
713
752
      if (iSnap.iGridVisible)
714
753
        drawGrid(cc);
 
754
      drawObjects(cc);
715
755
      if (iSnap.iWithAxes)
716
756
        drawAxes(cc);
717
 
      drawObjects(cc);
718
757
    }
719
758
    cairo_surface_flush(iSurface);
720
759
    cairo_destroy(cc);