cannam@45: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ cannam@45: cannam@45: /* cannam@45: Rosegarden cannam@45: A MIDI and audio sequencer and musical notation editor. cannam@45: Copyright 2000-2010 the Rosegarden development team. cannam@45: cannam@45: Other copyrights also apply to some parts of this work. Please cannam@45: see the AUTHORS file and individual file headers for details. cannam@45: cannam@45: This program is free software; you can redistribute it and/or cannam@45: modify it under the terms of the GNU General Public License as cannam@45: published by the Free Software Foundation; either version 2 of the cannam@45: License, or (at your option) any later version. See the file cannam@45: COPYING included with this distribution for more information. cannam@45: */ cannam@45: cannam@45: #include "panned.h" cannam@45: cannam@45: #include Chris@46: #include Chris@53: #include cannam@45: cannam@45: #include cannam@45: cannam@45: Panned::Panned() cannam@45: { Chris@56: setRenderHints(QPainter::Antialiasing | Chris@56: QPainter::TextAntialiasing); cannam@45: } cannam@45: cannam@45: void cannam@45: Panned::resizeEvent(QResizeEvent *ev) cannam@45: { cannam@45: QPointF near = mapToScene(0, 0); cannam@45: QPointF far = mapToScene(width(), height()); cannam@45: QSizeF sz(far.x()-near.x(), far.y()-near.y()); cannam@45: QRectF pr(near, sz); cannam@45: cannam@45: if (pr != m_pannedRect) { cannam@45: m_pannedRect = pr; cannam@45: emit pannedRectChanged(pr); cannam@45: } cannam@45: cannam@45: QGraphicsView::resizeEvent(ev); cannam@45: } cannam@45: cannam@45: void cannam@45: Panned::paintEvent(QPaintEvent *e) cannam@45: { cannam@45: QGraphicsView::paintEvent(e); cannam@45: } cannam@45: cannam@45: void cannam@45: Panned::drawForeground(QPainter *paint, const QRectF &) cannam@45: { cannam@45: QPointF near = mapToScene(0, 0); cannam@45: QPointF far = mapToScene(width(), height()); cannam@45: QSizeF sz(far.x()-near.x(), far.y()-near.y()); cannam@45: QRectF pr(near, sz); cannam@45: cannam@45: if (pr != m_pannedRect) { cannam@45: if (pr.x() != m_pannedRect.x()) emit pannedContentsScrolled(); cannam@45: m_pannedRect = pr; cannam@45: emit pannedRectChanged(pr); cannam@45: } cannam@45: } cannam@45: cannam@45: void Chris@53: Panned::zoomIn() Chris@53: { Chris@53: QMatrix m = matrix(); Chris@53: m.scale(1.0 / 1.1, 1.0 / 1.1); Chris@53: setMatrix(m); Chris@53: } Chris@53: Chris@53: void Chris@53: Panned::zoomOut() Chris@53: { Chris@53: QMatrix m = matrix(); Chris@53: m.scale(1.1, 1.1); Chris@53: setMatrix(m); Chris@53: } Chris@53: Chris@53: void cannam@45: Panned::slotSetPannedRect(QRectF pr) cannam@45: { cannam@45: centerOn(pr.center()); cannam@45: // setSceneRect(pr); cannam@45: // m_pannedRect = pr; cannam@45: } cannam@45: cannam@45: void cannam@45: Panned::wheelEvent(QWheelEvent *ev) cannam@45: { Chris@53: if (ev->modifiers() & Qt::ControlModifier) { Chris@53: int d = ev->delta(); Chris@53: if (d > 0) { Chris@53: while (d > 0) { Chris@53: zoomOut(); Chris@53: d -= 120; Chris@53: } Chris@53: } else { Chris@53: while (d < 0) { Chris@53: zoomIn(); Chris@53: d += 120; Chris@53: } Chris@53: } Chris@53: } else { Chris@53: emit wheelEventReceived(ev); Chris@53: QGraphicsView::wheelEvent(ev); Chris@53: } cannam@45: } cannam@45: cannam@45: void cannam@45: Panned::slotEmulateWheelEvent(QWheelEvent *ev) cannam@45: { cannam@45: QGraphicsView::wheelEvent(ev); cannam@45: } cannam@45: cannam@45: void cannam@45: Panned::leaveEvent(QEvent *) cannam@45: { cannam@45: emit mouseLeaves(); cannam@45: }