annotate panned.cpp @ 57:f583e44d9d31

* Update copyrights; add debug header
author Chris Cannam
date Tue, 16 Nov 2010 13:57:30 +0000
parents 1394c8cbf991
children 73073f34a5ee
rev   line source
Chris@57 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
cannam@45 2
cannam@45 3 /*
Chris@57 4 EasyMercurial
cannam@45 5
Chris@57 6 Based on HgExplorer by Jari Korhonen
Chris@57 7 Copyright (c) 2010 Jari Korhonen
Chris@57 8 Copyright (c) 2010 Chris Cannam
Chris@57 9 Copyright (c) 2010 Queen Mary, University of London
Chris@57 10
cannam@45 11 This program is free software; you can redistribute it and/or
cannam@45 12 modify it under the terms of the GNU General Public License as
cannam@45 13 published by the Free Software Foundation; either version 2 of the
cannam@45 14 License, or (at your option) any later version. See the file
cannam@45 15 COPYING included with this distribution for more information.
cannam@45 16 */
cannam@45 17
cannam@45 18 #include "panned.h"
cannam@45 19
cannam@45 20 #include <QScrollBar>
Chris@46 21 #include <QGLWidget>
Chris@53 22 #include <QWheelEvent>
cannam@45 23
cannam@45 24 #include <iostream>
cannam@45 25
cannam@45 26 Panned::Panned()
cannam@45 27 {
Chris@56 28 setRenderHints(QPainter::Antialiasing |
Chris@56 29 QPainter::TextAntialiasing);
cannam@45 30 }
cannam@45 31
cannam@45 32 void
cannam@45 33 Panned::resizeEvent(QResizeEvent *ev)
cannam@45 34 {
cannam@45 35 QPointF near = mapToScene(0, 0);
cannam@45 36 QPointF far = mapToScene(width(), height());
cannam@45 37 QSizeF sz(far.x()-near.x(), far.y()-near.y());
cannam@45 38 QRectF pr(near, sz);
cannam@45 39
cannam@45 40 if (pr != m_pannedRect) {
cannam@45 41 m_pannedRect = pr;
cannam@45 42 emit pannedRectChanged(pr);
cannam@45 43 }
cannam@45 44
cannam@45 45 QGraphicsView::resizeEvent(ev);
cannam@45 46 }
cannam@45 47
cannam@45 48 void
cannam@45 49 Panned::paintEvent(QPaintEvent *e)
cannam@45 50 {
cannam@45 51 QGraphicsView::paintEvent(e);
cannam@45 52 }
cannam@45 53
cannam@45 54 void
cannam@45 55 Panned::drawForeground(QPainter *paint, const QRectF &)
cannam@45 56 {
cannam@45 57 QPointF near = mapToScene(0, 0);
cannam@45 58 QPointF far = mapToScene(width(), height());
cannam@45 59 QSizeF sz(far.x()-near.x(), far.y()-near.y());
cannam@45 60 QRectF pr(near, sz);
cannam@45 61
cannam@45 62 if (pr != m_pannedRect) {
cannam@45 63 if (pr.x() != m_pannedRect.x()) emit pannedContentsScrolled();
cannam@45 64 m_pannedRect = pr;
cannam@45 65 emit pannedRectChanged(pr);
cannam@45 66 }
cannam@45 67 }
cannam@45 68
cannam@45 69 void
Chris@53 70 Panned::zoomIn()
Chris@53 71 {
Chris@53 72 QMatrix m = matrix();
Chris@53 73 m.scale(1.0 / 1.1, 1.0 / 1.1);
Chris@53 74 setMatrix(m);
Chris@53 75 }
Chris@53 76
Chris@53 77 void
Chris@53 78 Panned::zoomOut()
Chris@53 79 {
Chris@53 80 QMatrix m = matrix();
Chris@53 81 m.scale(1.1, 1.1);
Chris@53 82 setMatrix(m);
Chris@53 83 }
Chris@53 84
Chris@53 85 void
cannam@45 86 Panned::slotSetPannedRect(QRectF pr)
cannam@45 87 {
cannam@45 88 centerOn(pr.center());
cannam@45 89 // setSceneRect(pr);
cannam@45 90 // m_pannedRect = pr;
cannam@45 91 }
cannam@45 92
cannam@45 93 void
cannam@45 94 Panned::wheelEvent(QWheelEvent *ev)
cannam@45 95 {
Chris@53 96 if (ev->modifiers() & Qt::ControlModifier) {
Chris@53 97 int d = ev->delta();
Chris@53 98 if (d > 0) {
Chris@53 99 while (d > 0) {
Chris@53 100 zoomOut();
Chris@53 101 d -= 120;
Chris@53 102 }
Chris@53 103 } else {
Chris@53 104 while (d < 0) {
Chris@53 105 zoomIn();
Chris@53 106 d += 120;
Chris@53 107 }
Chris@53 108 }
Chris@53 109 } else {
Chris@53 110 emit wheelEventReceived(ev);
Chris@53 111 QGraphicsView::wheelEvent(ev);
Chris@53 112 }
cannam@45 113 }
cannam@45 114
cannam@45 115 void
cannam@45 116 Panned::slotEmulateWheelEvent(QWheelEvent *ev)
cannam@45 117 {
cannam@45 118 QGraphicsView::wheelEvent(ev);
cannam@45 119 }
cannam@45 120
cannam@45 121 void
cannam@45 122 Panned::leaveEvent(QEvent *)
cannam@45 123 {
cannam@45 124 emit mouseLeaves();
cannam@45 125 }