File indexing completed on 2024-05-12 05:44:25
0001 /*************************************************************************** 0002 * Copyright (C) 2006-2009 by Rajko Albrecht * 0003 * ral@alwins-world.de * 0004 * * 0005 * This program is free software; you can redistribute it and/or modify * 0006 * it under the terms of the GNU General Public License as published by * 0007 * the Free Software Foundation; either version 2 of the License, or * 0008 * (at your option) any later version. * 0009 * * 0010 * This program is distributed in the hope that it will be useful, * 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0013 * GNU General Public License for more details. * 0014 * * 0015 * You should have received a copy of the GNU General Public License * 0016 * along with this program; if not, write to the * 0017 * Free Software Foundation, Inc., * 0018 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * 0019 ***************************************************************************/ 0020 #include "pannerview.h" 0021 #include "graphtree_defines.h" 0022 0023 #include <QGraphicsRectItem> 0024 #include <QMouseEvent> 0025 #include <QPainter> 0026 #include <QStyleOptionGraphicsItem> 0027 0028 class GraphPanMark : public QGraphicsRectItem 0029 { 0030 public: 0031 GraphPanMark(QGraphicsItem *p = nullptr); 0032 ~GraphPanMark() override; 0033 int type() const override; 0034 void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override; 0035 }; 0036 0037 GraphPanMark::GraphPanMark(QGraphicsItem *p) 0038 : QGraphicsRectItem(p) 0039 { 0040 setZValue(1.9); 0041 setPen(QPen(Qt::red)); 0042 QPen pe = pen(); 0043 pe.setWidthF(0.0); 0044 pe.setStyle(Qt::DashDotLine); 0045 setPen(pe); 0046 } 0047 0048 GraphPanMark::~GraphPanMark() 0049 { 0050 } 0051 0052 void GraphPanMark::paint(QPainter *p, const QStyleOptionGraphicsItem *option, QWidget *w) 0053 { 0054 if (option->levelOfDetail < .5) { 0055 QGraphicsRectItem::paint(p, option, w); 0056 } 0057 } 0058 0059 int GraphPanMark::type() const 0060 { 0061 return GRAPHTREE_PANMARK; 0062 } 0063 0064 PannerView::PannerView(QWidget *parent) 0065 : QGraphicsView(parent) // KDE4 check , /*Qt::WNoAutoErase |*/ Qt::WA_StaticContents/*WStaticContents*/ ) 0066 { 0067 m_Mark = nullptr; 0068 m_Moving = false; 0069 viewport()->setFocusPolicy(Qt::NoFocus); 0070 setFocusPolicy(Qt::NoFocus); 0071 } 0072 0073 PannerView::~PannerView() 0074 { 0075 if (scene() && m_Mark) { 0076 scene()->removeItem(m_Mark); 0077 delete m_Mark; 0078 } 0079 } 0080 0081 void PannerView::setScene(QGraphicsScene *sc) 0082 { 0083 if (!sc) { 0084 if (scene()) { 0085 scene()->removeItem(m_Mark); 0086 } 0087 } else { 0088 if (!m_Mark) { 0089 m_Mark = new GraphPanMark; 0090 } 0091 sc->addItem(m_Mark); 0092 } 0093 QGraphicsView::setScene(sc); 0094 } 0095 0096 void PannerView::setZoomRect(const QRectF &theValue) 0097 { 0098 m_ZoomRect = theValue; 0099 if (m_Mark) { 0100 m_Mark->setRect(m_ZoomRect); 0101 } 0102 } 0103 0104 /*! 0105 \fn PannerView::contentsMouseMoveEvent(QMouseEvent* e) 0106 */ 0107 void PannerView::mouseMoveEvent(QMouseEvent *e) 0108 { 0109 if (m_Moving) { 0110 QPointF sPos = mapToScene(e->pos()); 0111 emit zoomRectMoved(sPos.x() - m_ZoomRect.center().x(), sPos.y() - m_ZoomRect.center().y()); 0112 0113 m_LastPos = e->pos(); 0114 } 0115 } 0116 0117 /*! 0118 \fn PannerView::contentsMousePressEvent(QMouseEvent* e) 0119 */ 0120 void PannerView::mousePressEvent(QMouseEvent *e) 0121 { 0122 if (m_ZoomRect.isValid()) { 0123 QPointF sPos = mapToScene(e->pos()); 0124 if (!m_ZoomRect.contains(sPos)) { 0125 emit zoomRectMoved(sPos.x() - m_ZoomRect.center().x(), sPos.y() - m_ZoomRect.center().y()); 0126 } 0127 m_Moving = true; 0128 m_LastPos = e->pos(); 0129 } 0130 } 0131 0132 /*! 0133 \fn PannerView::contentsMouseReleaseEvent(QMouseEvent*) 0134 */ 0135 void PannerView::mouseReleaseEvent(QMouseEvent *) 0136 { 0137 m_Moving = false; 0138 emit zoomRectMoveFinished(); 0139 } 0140 0141 /*! 0142 \fn PannerView::updateCurrentRect() 0143 */ 0144 void PannerView::updateCurrentRect() 0145 { 0146 if (m_ZoomRect.isValid()) { } 0147 } 0148 0149 #include "moc_pannerview.cpp"