diff --git a/argumentparser.h b/argumentparser.h index 96c44bf..d93754d 100644 --- a/argumentparser.h +++ b/argumentparser.h @@ -11,10 +11,6 @@ public: explicit ArgumentParser(QObject *parent = 0); - /*** - * @param successful is true if the program needs to stop but its not error - * @return true is program can continue - */ bool parseCmdLineArgs(bool &successful); bool isSystemTray() { return m_isSystemTray; } diff --git a/edge.cpp b/edge.cpp index 663482c..6361dbe 100644 --- a/edge.cpp +++ b/edge.cpp @@ -81,19 +81,15 @@ void Edge::adjust() if (line.length() > qreal(20.)) { -// m_sourcePoint = m_sourceNode->intersect(line); m_destPoint = m_destNode->intersect(line,true); - - /// @bug seems not to be updated m_sourcePoint = m_sourceNode->sceneBoundingRect().center(); -// m_destPoint = m_destNode->sceneBoundingRect().center(); - - } else { + } + else + { m_sourcePoint = m_destPoint = line.p1(); } } -/// @bug not ok yet QRectF Edge::boundingRect() const { if (!m_sourceNode || !m_destNode) diff --git a/graphwidget.cpp b/graphwidget.cpp index 81cf562..cba3ebf 100644 --- a/graphwidget.cpp +++ b/graphwidget.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include "node.h" #include "edge.h" @@ -86,15 +87,13 @@ void GraphWidget::readContentFromXmlFile(const QString &fileName) m_scene->addItem(node); node->setPos(e.attribute("x").toFloat(), e.attribute("y").toFloat()); - node->setScale(e.attribute("scale").toFloat()); + node->setScale(e.attribute("scale").toFloat(),sceneRect()); node->setColor(QColor(e.attribute("bg_red").toFloat(), e.attribute("bg_green").toFloat(), - e.attribute("bg_blue").toFloat()/*, - e.attribute("bg_alpha").toFloat()*/)); + e.attribute("bg_blue").toFloat())); node->setTextColor(QColor(e.attribute("text_red").toFloat(), e.attribute("text_green").toFloat(), - e.attribute("text_blue").toFloat()/*, - e.attribute("text_alpha").toFloat()*/)); + e.attribute("text_blue").toFloat())); m_nodeList.append(node); } @@ -111,8 +110,7 @@ void GraphWidget::readContentFromXmlFile(const QString &fileName) m_nodeList[e.attribute("destination").toInt()]); edge->setColor(QColor(e.attribute("red").toFloat(), e.attribute("green").toFloat(), - e.attribute("blue").toFloat()/*, - e.attribute("alpha").toFloat()*/)); + e.attribute("blue").toFloat())); edge->setWidth(e.attribute("width").toFloat()); edge->setSecondary(e.attribute("secondary").toInt() ); @@ -146,15 +144,13 @@ void GraphWidget::writeContentToXmlFile(const QString &fileName) cn.setAttribute( "x", QString::number(node->pos().x())); cn.setAttribute( "y", QString::number(node->pos().y())); cn.setAttribute( "htmlContent", node->toHtml()); - cn.setAttribute( "scale", QString::number(dynamic_cast(node)->scale())); + cn.setAttribute( "scale", QString::number(node->scale())); cn.setAttribute( "bg_red", QString::number(node->color().red())); cn.setAttribute( "bg_green", QString::number(node->color().green())); cn.setAttribute( "bg_blue", QString::number(node->color().blue())); -// cn.setAttribute( "bg_alpha", QString::number(node->color().alpha())); cn.setAttribute( "text_red", QString::number(node->textColor().red())); cn.setAttribute( "text_green", QString::number(node->textColor().green())); cn.setAttribute( "text_blue", QString::number(node->textColor().blue())); -// cn.setAttribute( "text_alpha", QString::number(node->textColor().alpha())); nodes_root.appendChild(cn); } @@ -171,7 +167,6 @@ void GraphWidget::writeContentToXmlFile(const QString &fileName) cn.setAttribute( "red", QString::number(edge->color().red())); cn.setAttribute( "green", QString::number(edge->color().green())); cn.setAttribute( "blue", QString::number(edge->color().blue())); -// cn.setAttribute( "alpha", QString::number(edge->color().alpha())); cn.setAttribute( "width", QString::number(edge->width())); cn.setAttribute( "secondary", QString::number(edge->secondary())); @@ -237,7 +232,6 @@ void GraphWidget::keyPressEvent(QKeyEvent *event) event->key() == Qt::Key_D || // remove edge event->key() == Qt::Key_C || // node color event->key() == Qt::Key_T || // node text color -// event->key() == Qt::Key_K || // edge text color ( event->modifiers() & Qt::ControlModifier && // moving node ( event->key() == Qt::Key_Up || event->key() == Qt::Key_Down || @@ -265,11 +259,6 @@ void GraphWidget::keyPressEvent(QKeyEvent *event) m_edgeDeleting = false; m_parent->statusBarMsg(tr("Edge deleting cancelled.")); } -// else if (m_edgeColoring) -// { -// m_edgeColoring = false; -// m_parent->statusBarMsg(tr("Edge coloring cancelled.")); -// } else if(m_showingNodeNumbers) { m_hintNumber.clear(); @@ -302,7 +291,7 @@ void GraphWidget::keyPressEvent(QKeyEvent *event) case Qt::Key_Plus: if (event->modifiers() & Qt::ControlModifier) { - m_activeNode->scale(qreal(1.2)); + m_activeNode->setScale(qreal(1.2),sceneRect()); } else { @@ -312,7 +301,7 @@ void GraphWidget::keyPressEvent(QKeyEvent *event) case Qt::Key_Minus: if (event->modifiers() & Qt::ControlModifier) { - m_activeNode->scale(qreal(1 / 1.2)); + m_activeNode->setScale(qreal(1 / 1.2),sceneRect()); } else { @@ -388,11 +377,6 @@ void GraphWidget::keyPressEvent(QKeyEvent *event) // delete node case Qt::Key_Delete: -// if (m_nodeList.size()==1) -// { -// m_parent->statusBarMsg(tr("Last node cannot be deleted.")); -// break; -// } if (m_activeNode == m_nodeList.first()) { m_parent->statusBarMsg(tr("Base node cannot be deleted.")); @@ -428,7 +412,6 @@ void GraphWidget::keyPressEvent(QKeyEvent *event) { QColorDialog dialog(this); dialog.setWindowTitle(tr("Select node color")); -// dialog.setOption(QColorDialog::ShowAlphaChannel); dialog.setCurrentColor(m_activeNode->color()); if (dialog.exec()) { @@ -445,7 +428,6 @@ void GraphWidget::keyPressEvent(QKeyEvent *event) { QColorDialog dialog(this); dialog.setWindowTitle(tr("Select text color")); -// dialog.setOption(QColorDialog::ShowAlphaChannel); dialog.setCurrentColor(m_activeNode->textColor()); if (dialog.exec()) { @@ -456,13 +438,6 @@ void GraphWidget::keyPressEvent(QKeyEvent *event) break; } -// case Qt::Key_K: -// { -// m_parent->statusBarMsg(tr("Edge color: select other end-node.")); -// m_edgeColoring = true; -// break; -// } - default: QGraphicsView::keyPressEvent(event); } @@ -472,7 +447,23 @@ void GraphWidget::keyPressEvent(QKeyEvent *event) void GraphWidget::wheelEvent(QWheelEvent *event) { - scaleView(pow((double)2, -event->delta() / 240.0)); + if (QApplication::keyboardModifiers() == Qt::ControlModifier) + { + if (m_activeNode) + { + m_activeNode->setScale(pow((double)1.2, event->delta() / 120.0), + sceneRect()); + } + else + { + m_parent->statusBarMsg(tr("No active node.")); + return; + } + } + else + { + scaleView(pow((double)1.2, event->delta() / 240.0)); + } } void GraphWidget::drawBackground(QPainter *painter, const QRectF &rect) @@ -596,21 +587,6 @@ void GraphWidget::nodeSelected(Node *node) removeEdge(m_activeNode, node); m_edgeDeleting = false; } -// else if (m_edgeColoring) -// { -// QColorDialog dialog(this); -// dialog.setWindowTitle(tr("Select edge color")); -// dialog.setOption(QColorDialog::ShowAlphaChannel); -// if (dialog.exec()) -// { -// QColor color = dialog.selectedColor(); - -// Edge *edge = m_activeNode->edgeTo(node); -// if (edge) -// edge->setColor(color); -// } -// m_edgeColoring = false; -// } else { setActiveNode(node); @@ -642,7 +618,7 @@ void GraphWidget::addEdge(Node *source, Node *destination) } Edge *edge = new Edge(source, destination); edge->setColor(destination->color()); - edge->setWidth(dynamic_cast(destination)->scale()*2 + 1); + edge->setWidth(destination->scale()*2 + 1); edge->setSecondary(sec); m_scene->addItem(edge); @@ -699,7 +675,6 @@ void GraphWidget::addFirstNode() m_activeNode = m_nodeList.first(); m_activeNode->setActive(); -// m_scene->setFocusItem(m_activeNode); } QList GraphWidget::edges() const diff --git a/graphwidget.h b/graphwidget.h index 909b6f6..8824460 100644 --- a/graphwidget.h +++ b/graphwidget.h @@ -61,7 +61,6 @@ private: bool m_editingNode; bool m_edgeAdding; bool m_edgeDeleting; -// bool m_edgeColoring; bool m_contentChanged; QString m_fileName; diff --git a/node.cpp b/node.cpp index fe48356..b6e6498 100644 --- a/node.cpp +++ b/node.cpp @@ -111,23 +111,26 @@ void Node::setTextColor(const QColor &color) update(); } -void Node::scale(const qreal &factor) +void Node::setScale(const qreal &factor,const QRectF &sceneRect) { - if (factor * QGraphicsTextItem::scale() < 0.4 || - factor * QGraphicsTextItem::scale() > 4 ) + if (factor * scale() < 0.4 || + factor * scale() > 4 ) return; - // it would make stuff difficult, like limiting the pos. inside scene - // setTransformOriginPoint(boundingRect().center()); + if (!sceneRect.contains(pos() + + boundingRect().bottomRight() * scale() * factor)) + return; + + prepareGeometryChange(); - QGraphicsTextItem::setScale(factor * QGraphicsTextItem::scale()); + QGraphicsTextItem::setScale(factor * scale()); foreach(EdgeElement element, m_edgeList) + { if (!element.startsFromThisNode) - { element.edge->setWidth(element.edge->width() * factor ); - /// @bug seems not working - element.edge->adjust(); - } + + element.edge->adjust(); + } } void Node::showNumber(const int &number, @@ -364,7 +367,7 @@ QVariant Node::itemChange(GraphicsItemChange change, const QVariant &value) // the fence is reduced with the size of the node QRectF rect (scene()->sceneRect().topLeft(), scene()->sceneRect().bottomRight() - - boundingRect().bottomRight() * QGraphicsTextItem::scale() ); + boundingRect().bottomRight() * scale() ); if (!rect.contains(newPos)) { @@ -412,7 +415,6 @@ void Node::mouseMoveEvent(QGraphicsSceneMouseEvent *event) QGraphicsItem::mouseMoveEvent(event); } -/// @bug it seems sceneBoundingRect().contains doesn't care about path retval... QPainterPath Node::shape () const { QPainterPath path; diff --git a/node.h b/node.h index 6be4552..67274eb 100644 --- a/node.h +++ b/node.h @@ -28,7 +28,7 @@ public: QColor color() const { return m_color; } void setTextColor(const QColor &color); QColor textColor() const { return m_textColor; } - void scale(const qreal &factor); + void setScale(const qreal &factor, const QRectF &sceneRect); void showNumber(const int &number, const bool& show = true, const bool &numberIsSpecial = false);