From kde-commits Wed Oct 31 23:13:56 2007 From: =?utf-8?q?Ga=C3=ABl=20de=20Chalendar?= Date: Wed, 31 Oct 2007 23:13:56 +0000 To: kde-commits Subject: extragear/graphics/kgraphviewer/src/part Message-Id: <1193872436.771428.14241.nullmailer () svn ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=119387244626459 SVN commit 731535 by kleag: Made edges selectable M +4 -3 KgvGlobal.cpp M +6 -2 KgvUnitWidgets.cpp M +1 -2 KgvUnitWidgets.h M +48 -3 canvasedge.cpp M +3 -0 canvasedge.h M +2 -1 graphelement.cpp M +4 -0 graphelement.h --- trunk/extragear/graphics/kgraphviewer/src/part/KgvGlobal.cpp #731534:731535 @@ -35,18 +35,19 @@ #include #include #include -#include +// #include #include #include KgvGlobal* KgvGlobal::s_global = 0L; -static K3StaticDeleter sdg; +// static K3StaticDeleter sdg; KgvGlobal* KgvGlobal::self() { if ( !s_global ) - sdg.setObject( s_global, new KgvGlobal ); + s_global = new KgvGlobal ; +// sdg.setObject( s_global, new KgvGlobal ); return s_global; } --- trunk/extragear/graphics/kgraphviewer/src/part/KgvUnitWidgets.cpp #731534:731535 @@ -158,6 +158,10 @@ setSingleStep(step); setValue(value); setDecimals(precision); + QDoubleSpinBox::setMinimum(lower); + QDoubleSpinBox::setMaximum(upper); + QDoubleSpinBox::setSingleStep(step); + QDoubleSpinBox::setValue(value); m_unit = KgvUnit::U_PT; m_validator = new KgvUnitDoubleValidator( this, this ); // QSpinBox::setValidator( m_validator ); @@ -225,8 +229,8 @@ void KgvUnitDoubleSpinBox::setMinMaxStep( double min, double max, double step ) { - setMinValue( min ); - setMaxValue( max ); + setMinimum( min ); + setMaximum( max ); setLineStepPt( step ); } --- trunk/extragear/graphics/kgraphviewer/src/part/KgvUnitWidgets.h #731534:731535 @@ -33,10 +33,9 @@ #include #include #include -//Added by qt3to4: #include +#include - // ---------------------------------------------------------------- // Support classes --- trunk/extragear/graphics/kgraphviewer/src/part/canvasedge.cpp #731534:731535 @@ -67,7 +67,6 @@ QRectF CanvasEdge::boundingRect() const { -// kDebug() << edge()->fromNode()->id() << "->" << edge()->toNode()->id() << m_boundingRect; return m_boundingRect; } @@ -102,12 +101,14 @@ } return; } + QList allPoints; DotRenderOpVec::const_iterator it, it_end; it = edge()->renderOperations().begin(); it_end = edge()->renderOperations().end(); for (; it != it_end; it++) { const DotRenderOp& dro = (*it); +// kDebug() << edge()->fromNode()->id() << "->" << edge()->toNode()->id() << "renderop" << (*it).renderop << "; selected:" << edge()->isSelected(); if ( (*it).renderop == "T" ) { const QString& str = (*it).str; @@ -152,6 +153,8 @@ (int(m_gh-(*it).integers[2*i+2])/*%m_hdvcf*/)*m_scaleY + m_yMargin ); polygon[i] = point; +// kDebug() << edge()->fromNode()->id() << "->" << edge()->toNode()->id() << point; + allPoints.append(point); } if ((*it).renderop == "P" ) { @@ -270,6 +273,8 @@ (m_gh-(*it).integers[2*i+2]/*%m_hdvcf*/)*m_scaleY + m_yMargin + diffY ); points[i] = p; +// kDebug() << edge()->fromNode()->id() << "->" << edge()->toNode()->id() << p; + allPoints.append(p); } // kDebug() << "Setting pen color to " << edge()->color(splineNum); pen.setColor(Dot2QtConsts::componentData().qtColor(edge()->color(splineNum))); @@ -287,8 +292,36 @@ p->drawPath(path); p->restore(); } - } + } } + if (edge()->isSelected()) + { +// kDebug() << "draw square"; +// p->drawRect(m_boundingRect); + qreal maxDist = 0; + QPair pointsPair; + foreach(const QPointF& point1, allPoints) + { + foreach(const QPointF& point2, allPoints) + { + if (distance(point1, point2) > maxDist) + { + maxDist = distance(point1, point2); + pointsPair = qMakePair(point1, point2); + } + } + } + if (maxDist>0) + { + p->save(); + // p->setBrush(Dot2QtConsts::componentData().qtColor(edge()->color(0))); + p->setBrush(Qt::black); + p->setPen(Qt::black); + p->drawRect(QRectF(pointsPair.first-QPointF(3,3),QSizeF(6,6))); + p->drawRect(QRectF(pointsPair.second-QPointF(3,3),QSizeF(6,6))); + p->restore(); + } + } } void CanvasEdge::modelChanged() @@ -327,7 +360,7 @@ for (; it != it_end; it++) { // kDebug() << (*it).renderop << ", "; - if ( (*it).renderop != "B" ) continue; + if ( ((*it).renderop != "B") && ((*it).renderop != "p") && ((*it).renderop != "P") ) continue; uint previousSize = points.size(); points.resize(previousSize+(*it).integers[0]); for (int i = 0; i < (*it).integers[0]; i++) @@ -357,3 +390,15 @@ } // kDebug() ;//<< edge()->fromNode()->id() << "->" << edge()->toNode()->id() << "New bounding rect is:" << m_boundingRect; } + +void CanvasEdge::mousePressEvent(QGraphicsSceneMouseEvent * event) +{ +// kDebug() << event; + edge()->setSelected(!edge()->isSelected()); + update(); +} + +qreal CanvasEdge::distance(const QPointF& point1, const QPointF& point2) +{ + return sqrt(pow(point1.x()-point2.x(),2)+pow(point1.y()-point2.y(),2)); +} --- trunk/extragear/graphics/kgraphviewer/src/part/canvasedge.h #731534:731535 @@ -77,8 +77,11 @@ void modelChanged(); protected: + virtual void mousePressEvent ( QGraphicsSceneMouseEvent * event ); private: + qreal distance(const QPointF& point1, const QPointF& point2); + qreal m_scaleX, m_scaleY; qreal m_xMargin, m_yMargin, m_gh, m_wdhcf, m_hdvcf; GraphEdge* m_edge; --- trunk/extragear/graphics/kgraphviewer/src/part/graphelement.cpp #731534:731535 @@ -32,7 +32,8 @@ m_originalAttributes(), m_ce(0), m_z(1.0), - m_renderOperations() + m_renderOperations(), + m_selected(false) { /* label(""); id(""); --- trunk/extragear/graphics/kgraphviewer/src/part/graphelement.h #731534:731535 @@ -93,6 +93,9 @@ inline CanvasElement* canvasElement() {return m_ce;} inline const CanvasElement* canvasElement() const {return m_ce;} inline void setCanvasElement(CanvasElement* ce) {m_ce = ce;} + + inline void setSelected(bool s) {m_selected=s;} + inline bool isSelected() {return m_selected;} Q_SIGNALS: void changed(); @@ -107,6 +110,7 @@ DotRenderOpVec m_renderOperations; + bool m_selected; };