annotate panned.cpp @ 131:2550aaa09240

* Add connecting line to uncommitted item; turn Revert icon blue; cut down menus to things that actually work (well, mostly)
author Chris Cannam
date Tue, 30 Nov 2010 11:17:30 +0000
parents b0a90ac84b8b
children 16ceeee30e2a
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"
Chris@131 19 #include "debug.h"
cannam@45 20
cannam@45 21 #include <QScrollBar>
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 {
Chris@131 35 DEBUG << "Panned::resizeEvent()" << endl;
Chris@131 36
Chris@60 37 QPointF nearpt = mapToScene(0, 0);
Chris@60 38 QPointF farpt = mapToScene(width(), height());
Chris@60 39 QSizeF sz(farpt.x()-nearpt.x(), farpt.y()-nearpt.y());
Chris@60 40 QRectF pr(nearpt, sz);
cannam@45 41
cannam@45 42 if (pr != m_pannedRect) {
cannam@45 43 m_pannedRect = pr;
cannam@45 44 emit pannedRectChanged(pr);
cannam@45 45 }
cannam@45 46
cannam@45 47 QGraphicsView::resizeEvent(ev);
cannam@45 48 }
cannam@45 49
cannam@45 50 void
cannam@45 51 Panned::paintEvent(QPaintEvent *e)
cannam@45 52 {
cannam@45 53 QGraphicsView::paintEvent(e);
cannam@45 54 }
cannam@45 55
cannam@45 56 void
cannam@45 57 Panned::drawForeground(QPainter *paint, const QRectF &)
cannam@45 58 {
Chris@60 59 QPointF nearpt = mapToScene(0, 0);
Chris@60 60 QPointF farpt = mapToScene(width(), height());
Chris@60 61 QSizeF sz(farpt.x()-nearpt.x(), farpt.y()-nearpt.y());
Chris@60 62 QRectF pr(nearpt, sz);
cannam@45 63
cannam@45 64 if (pr != m_pannedRect) {
cannam@45 65 if (pr.x() != m_pannedRect.x()) emit pannedContentsScrolled();
cannam@45 66 m_pannedRect = pr;
cannam@45 67 emit pannedRectChanged(pr);
cannam@45 68 }
cannam@45 69 }
cannam@45 70
cannam@45 71 void
Chris@53 72 Panned::zoomIn()
Chris@53 73 {
Chris@53 74 QMatrix m = matrix();
Chris@53 75 m.scale(1.0 / 1.1, 1.0 / 1.1);
Chris@53 76 setMatrix(m);
Chris@53 77 }
Chris@53 78
Chris@53 79 void
Chris@53 80 Panned::zoomOut()
Chris@53 81 {
Chris@53 82 QMatrix m = matrix();
Chris@53 83 m.scale(1.1, 1.1);
Chris@53 84 setMatrix(m);
Chris@53 85 }
Chris@53 86
Chris@53 87 void
cannam@45 88 Panned::slotSetPannedRect(QRectF pr)
cannam@45 89 {
cannam@45 90 centerOn(pr.center());
cannam@45 91 // setSceneRect(pr);
cannam@45 92 // m_pannedRect = pr;
cannam@45 93 }
cannam@45 94
cannam@45 95 void
cannam@45 96 Panned::wheelEvent(QWheelEvent *ev)
cannam@45 97 {
Chris@53 98 if (ev->modifiers() & Qt::ControlModifier) {
Chris@53 99 int d = ev->delta();
Chris@53 100 if (d > 0) {
Chris@53 101 while (d > 0) {
Chris@53 102 zoomOut();
Chris@53 103 d -= 120;
Chris@53 104 }
Chris@53 105 } else {
Chris@53 106 while (d < 0) {
Chris@53 107 zoomIn();
Chris@53 108 d += 120;
Chris@53 109 }
Chris@53 110 }
Chris@53 111 } else {
Chris@53 112 emit wheelEventReceived(ev);
Chris@53 113 QGraphicsView::wheelEvent(ev);
Chris@53 114 }
cannam@45 115 }
cannam@45 116
cannam@45 117 void
cannam@45 118 Panned::slotEmulateWheelEvent(QWheelEvent *ev)
cannam@45 119 {
cannam@45 120 QGraphicsView::wheelEvent(ev);
cannam@45 121 }
cannam@45 122
cannam@45 123 void
cannam@45 124 Panned::leaveEvent(QEvent *)
cannam@45 125 {
cannam@45 126 emit mouseLeaves();
cannam@45 127 }