From 6cab47bfae065ae9119906d045c9d6bcbf161e92 Mon Sep 17 00:00:00 2001 From: Denes Matetelki Date: Fri, 10 Jun 2011 23:53:53 +0200 Subject: [PATCH] shorter lines, less qDebug(), Node::calculateBiggestAngle() works --- .gitignore | 1 + algorithmtests.cpp | 84 ++++++++++++++++ algorithmtests.h | 18 ++++ argumentparser.cpp | 52 ++++++---- argumentparser.h | 2 +- edge.cpp | 17 ++-- edge.h | 3 +- graphwidget.cpp | 38 +++---- graphwidget.h | 3 +- main.cpp | 5 +- mainwindow.cpp | 9 -- node.cpp | 74 +++++--------- node.h | 18 ++-- qtmindmap.pro.user | 244 --------------------------------------------- qtmindmap_test.pro | 26 +++++ systemtray.cpp | 19 ++-- 16 files changed, 229 insertions(+), 384 deletions(-) create mode 100644 algorithmtests.cpp create mode 100644 algorithmtests.h delete mode 100644 qtmindmap.pro.user create mode 100644 qtmindmap_test.pro diff --git a/.gitignore b/.gitignore index d01fc5b..ee52a96 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ Makefile moc_* qrc_* qtmindmap +*.pro.user diff --git a/algorithmtests.cpp b/algorithmtests.cpp new file mode 100644 index 0000000..da51fa6 --- /dev/null +++ b/algorithmtests.cpp @@ -0,0 +1,84 @@ +#define private public + +#include "algorithmtests.h" + +#include + +#include "node.h" + +#include "edge.h" + +static const double Pi = 3.14159265358979323846264338327950288419717; + +AlgorithmTests::AlgorithmTests(QObject *parent) : + QObject(parent) +{ +} + +/** edge->paint() calculates the m_angle of th edge, + * but it is skipped so it must be done manually + */ +double angleOfPoints(const QPointF &a, const QPointF &b) +{ + QLineF line(a, b); + double angle = ::acos(line.dx() / line.length()); + if (line.dy() >= 0) + angle = 2 * Pi - angle; + + return angle; +} + +void AlgorithmTests::calculateBiggestAngle() +{ + // no edges + Node *node1 = new Node(); + node1->setPos(0,0); + QCOMPARE(node1->calculateBiggestAngle(), Pi * 1.5); + + // one egde + // 1 + Node *node2 = new Node(); + node2->setPos(30,0); + + Edge *edge1 = new Edge(node1, node2); + edge1->m_angle = angleOfPoints(node1->pos(), node2->pos()); + + QCOMPARE(edge1->getAngle(), 2 * Pi); + QCOMPARE(node1->calculateBiggestAngle(), - Pi); + QCOMPARE(node2->calculateBiggestAngle(), double(0)); + + // 2 + node2->setPos(30,30); + edge1->m_angle = angleOfPoints(node1->pos(), node2->pos()); // 45 + + QCOMPARE(edge1->getAngle(), 1.75 * Pi); + QCOMPARE(node1->calculateBiggestAngle(), - 0.75 * Pi); + QCOMPARE(node2->calculateBiggestAngle(), 0.25 * Pi); + + + // more edges + node2->setPos(30,0); + edge1->m_angle = angleOfPoints(node1->pos(), node2->pos()); + + Node *node3 = new Node(); + node3->setPos(-30,0); + Edge *edge2 = new Edge(node1, node3); + edge2->m_angle = angleOfPoints(node1->pos(), node3->pos()); + + Node *node4 = new Node(); + node4->setPos(0, -30); + Edge *edge3 = new Edge(node1, node4); + edge3->m_angle = angleOfPoints(node1->pos(), node4->pos()); + + QCOMPARE(edge1->getAngle(), 2 * Pi); + QCOMPARE(edge2->getAngle(), Pi); + QCOMPARE(edge3->getAngle(), 0.5 * Pi); + QCOMPARE(node1->calculateBiggestAngle(), 0.5 * Pi); + + delete node1; + delete node2; + delete node3; +} + + +QTEST_MAIN(AlgorithmTests) diff --git a/algorithmtests.h b/algorithmtests.h new file mode 100644 index 0000000..4c94c04 --- /dev/null +++ b/algorithmtests.h @@ -0,0 +1,18 @@ +#ifndef ALGORITHMTESTS_H +#define ALGORITHMTESTS_H + +#include + +class AlgorithmTests : public QObject +{ + Q_OBJECT + +public: + explicit AlgorithmTests(QObject *parent = 0); + +private slots: + void calculateBiggestAngle(); + +}; + +#endif // ALGORITHMTESTS_H diff --git a/argumentparser.cpp b/argumentparser.cpp index b961009..c59abc7 100644 --- a/argumentparser.cpp +++ b/argumentparser.cpp @@ -3,7 +3,6 @@ #include #include #include -#include #include @@ -13,30 +12,31 @@ ArgumentParser::ArgumentParser(QObject *parent) : m_isShowMinimized(false), m_filePath() { - qDebug() << __PRETTY_FUNCTION__; } void ArgumentParser::printUsage() { - qDebug() << __PRETTY_FUNCTION__; - - std::cout << tr("Usage: ").toStdString() << "qtmindmap [OPTION][FILE]" << std::endl + std::cout << tr("Usage: ").toStdString() << "qtmindmap [OPTION][FILE]" + << std::endl << tr("Mindmap program in QT").toStdString() << std::endl << std::endl << tr("Options:").toStdString() << std::endl - << "-h, --help\t\t" << tr("Prints this help.").toStdString() << std::endl - << "-t, --tray\t\t" << tr("Starts application in system tray.").toStdString() << std::endl - << "-s, --show-minimized\t" << tr("Hide main window, just show systray icon.").toStdString() << std::endl + << "-h, --help\t\t" << tr("Prints this help.").toStdString() + << std::endl + << "-t, --tray\t\t" + << tr("Starts application in system tray.").toStdString() << std::endl - << tr("Report bugs to: ").toStdString() << "denes.matetelki@gmail.com" << std::endl; + << "-s, --show-minimized\t" + << tr("Hide main window, just show systray icon.").toStdString() + << std::endl << std::endl + << tr("Report bugs to: ").toStdString() + << "denes.matetelki@gmail.com" << std::endl; } bool ArgumentParser::parseCmdLineArgs(bool &successful) { - qDebug() << __PRETTY_FUNCTION__; - QStringList cmdlineArgs = QCoreApplication::arguments(); cmdlineArgs.removeFirst(); @@ -49,20 +49,26 @@ bool ArgumentParser::parseCmdLineArgs(bool &successful) } QRegExp tray("^-(t|-tray)$"); - if (!cmdlineArgs.filter(tray).isEmpty()) m_isSystemTray = true; + if (!cmdlineArgs.filter(tray).isEmpty()) + m_isSystemTray = true; QRegExp minimized("^-(s|-show-minimized)$"); - if (!cmdlineArgs.filter(minimized).isEmpty()) m_isShowMinimized = true; + if (!cmdlineArgs.filter(minimized).isEmpty()) + m_isShowMinimized = true; /// @note It is an error? Shall it be handled? // if (isSystemTray && isShowMinimized) return false; QRegExp all("^-(t|-tray|h|-help|s|-show-minimized)$"); QStringList others; - foreach (QString arg, cmdlineArgs) if (all.indexIn(arg)==-1) others.append(arg); + foreach (QString arg, cmdlineArgs) + if (all.indexIn(arg)==-1) + others.append(arg); + if (others.size() > 1) { - std::cerr << tr("Unkown options: ").toStdString() << others.join(" ").toStdString() << std::endl; + std::cerr << tr("Unkown options: ").toStdString() + << others.join(" ").toStdString() << std::endl; printUsage(); successful = false; return false; @@ -81,25 +87,33 @@ bool ArgumentParser::parseCmdLineArgs(bool &successful) QFileInfo fileInfo(m_filePath); if (!fileInfo.exists()) { - std::cerr << tr("File: ").toStdString() << m_filePath.toStdString() << tr(" does not exists.").toStdString() << std::endl; + std::cerr << tr("File: ").toStdString() << + m_filePath.toStdString() << + tr(" does not exists.").toStdString() << std::endl; successful = false; return false; } if (!fileInfo.isFile()) { - std::cerr << tr("File: ").toStdString() << m_filePath.toStdString() << tr(" is not a file.").toStdString() << std::endl; + std::cerr << tr("File: ").toStdString() << + m_filePath.toStdString() << + tr(" is not a file.").toStdString() << std::endl; successful = false; return false; } if (!fileInfo.isReadable()) { - std::cerr << tr("File: ").toStdString() << m_filePath.toStdString() << tr(" is not readable.").toStdString() << std::endl; + std::cerr << tr("File: ").toStdString() << + m_filePath.toStdString() << + tr(" is not readable.").toStdString() << std::endl; successful = false; return false; } if (!fileInfo.isWritable()) { - std::cout << tr("File: ").toStdString() << m_filePath.toStdString() << tr(" is not writeable.").toStdString() << std::endl; + std::cout << tr("File: ").toStdString() << + m_filePath.toStdString() << + tr(" is not writeable.").toStdString() << std::endl; } } return true; diff --git a/argumentparser.h b/argumentparser.h index 81daabe..96c44bf 100644 --- a/argumentparser.h +++ b/argumentparser.h @@ -12,7 +12,7 @@ public: explicit ArgumentParser(QObject *parent = 0); /*** - * @param successful is true is the program needs to stop but its not an error. + * @param successful is true if the program needs to stop but its not error * @return true is program can continue */ bool parseCmdLineArgs(bool &successful); diff --git a/edge.cpp b/edge.cpp index 6ee60c1..5e585f0 100644 --- a/edge.cpp +++ b/edge.cpp @@ -11,7 +11,8 @@ static const double Pi = 3.14159265358979323846264338327950288419717; static double TwoPi = 2.0 * Pi; Edge::Edge(Node *sourceNode, Node *destNode) - : m_arrowSize(7) + : m_arrowSize(7), + m_angle(-1) { setAcceptedMouseButtons(0); m_sourceNode = sourceNode; @@ -102,6 +103,10 @@ void Edge::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) QLineF line(m_sourcePoint, m_destPoint); + m_angle = ::acos(line.dx() / line.length()); + if (line.dy() >= 0) + m_angle = TwoPi - m_angle; + if (sourceNode()->collidesWithItem(destNode())) return; @@ -113,12 +118,6 @@ void Edge::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) return; // Draw the arrows - m_angle = ::acos(line.dx() / line.length()); - if (line.dy() >= 0) - m_angle = TwoPi - m_angle; - - qDebug() << m_angle; - QPointF destArrowP1 = m_destPoint + QPointF(sin(m_angle - Pi / 3) * m_arrowSize, cos(m_angle - Pi / 3) * m_arrowSize); QPointF destArrowP2 = m_destPoint + QPointF(sin(m_angle - Pi + Pi / 3) * m_arrowSize, @@ -130,9 +129,5 @@ void Edge::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) double Edge::getAngle() const { - qDebug() << __PRETTY_FUNCTION__; - - qDebug() << m_angle; - return m_angle; } diff --git a/edge.h b/edge.h index 8d5de87..be8c564 100644 --- a/edge.h +++ b/edge.h @@ -21,7 +21,8 @@ public: protected: QRectF boundingRect() const; - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, + QWidget *widget); private: diff --git a/graphwidget.cpp b/graphwidget.cpp index 8af8ddf..9531364 100644 --- a/graphwidget.cpp +++ b/graphwidget.cpp @@ -17,8 +17,6 @@ GraphWidget::GraphWidget(QWidget *parent) : m_showingNodeNumbers(false), m_followNode(0) { - qDebug() << __PRETTY_FUNCTION__; - m_scene = new QGraphicsScene(this); m_scene->setItemIndexMethod(QGraphicsScene::NoIndex); m_scene->setSceneRect(-400, -400, 800, 800); @@ -127,9 +125,6 @@ QGraphicsScene *GraphWidget::getScene() void GraphWidget::keyPressEvent(QKeyEvent *event) { - qDebug() << __PRETTY_FUNCTION__; - qDebug() << event->key(); - switch (event->key()) { case Qt::Key_Up: if (m_activeNode) @@ -224,8 +219,6 @@ void GraphWidget::keyPressEvent(QKeyEvent *event) case Qt::Key_Enter: if (m_followNode && m_showingNodeNumbers) { - qDebug() << m_activeNode; - qDebug() << m_followNode; showingAllNodeNumbers(false); if (m_activeNode) m_activeNode->setActive(false); @@ -289,7 +282,8 @@ void GraphWidget::drawBackground(QPainter *painter, const QRectF &rect) void GraphWidget::scaleView(qreal scaleFactor) { - qreal factor = transform().scale(scaleFactor, scaleFactor).mapRect(QRectF(0, 0, 1, 1)).width(); + qreal factor = transform().scale(scaleFactor, scaleFactor). + mapRect(QRectF(0, 0, 1, 1)).width(); if (factor < 0.2 || factor > 10) return; scale(scaleFactor, scaleFactor); @@ -297,8 +291,6 @@ void GraphWidget::scaleView(qreal scaleFactor) void GraphWidget::setActiveNode(Node *node) { - qDebug() << __PRETTY_FUNCTION__; - if (m_activeNode!=0) m_activeNode->setActive(false); @@ -308,26 +300,21 @@ void GraphWidget::setActiveNode(Node *node) void GraphWidget::insertNode() { - qDebug() << __PRETTY_FUNCTION__; - double angle(m_activeNode->calculateBiggestAngle()); - qreal length(100); + qDebug() << "got angle: " << angle; - qDebug() << "angle: "; - qDebug() << angle; + qreal length(100); QPointF pos(length * cos(angle), length * sin(angle)); - - qDebug() << pos; - Node *node = new Node(this); node->setHtml(QString("new node")); m_scene->addItem(node); - node->setPos(m_activeNode->pos() + -// m_activeNode->boundingRect().center() + - pos); + node->setPos(m_activeNode->sceneBoundingRect().center() + + pos - + node->boundingRect().center() + ); m_nodeList.append(node); m_scene->addItem(new Edge(m_activeNode, node)); @@ -336,15 +323,18 @@ void GraphWidget::insertNode() void GraphWidget::showingAllNodeNumbers(const bool &show) { int i =0; - for (QList::const_iterator it = m_nodeList.begin(); it != m_nodeList.end(); it++, i++) + for (QList::const_iterator it = m_nodeList.begin(); + it != m_nodeList.end(); it++, i++) dynamic_cast(*it)->showNumber(i,show); } -void GraphWidget::showingNodeNumbersBeginWithNumber(const int &number, const bool &show) +void GraphWidget::showingNodeNumbersBeginWithNumber(const int &number, + const bool &show) { int i(0); int hit(0); - for (QList::const_iterator it = m_nodeList.begin(); it != m_nodeList.end(); it++, i++) + for (QList::const_iterator it = m_nodeList.begin(); + it != m_nodeList.end(); it++, i++) { if (i == number) { diff --git a/graphwidget.h b/graphwidget.h index c2ef248..7bc3a2b 100644 --- a/graphwidget.h +++ b/graphwidget.h @@ -31,7 +31,8 @@ protected: private: void showingAllNodeNumbers(const bool &show = true); - void showingNodeNumbersBeginWithNumber(const int &number, const bool &show = true); + void showingNodeNumbersBeginWithNumber(const int &number, + const bool &show = true); bool numberStartsWithNumber(const int &number, const int &prefix); qreal calculateBiggestAngle(Node *node); diff --git a/main.cpp b/main.cpp index 935fd10..fc6e1c6 100644 --- a/main.cpp +++ b/main.cpp @@ -2,7 +2,6 @@ #include // cout #include -#include #include #include @@ -25,7 +24,9 @@ int main(int argc, char *argv[]) QTranslator translator; if (!translator.load(QString("qtmindmap_") + locale)) { - std::cerr << "No translation file for locale: " << locale.toStdString() << std::endl; + std::cerr << "No translation file for locale: " + << locale.toStdString() + << std::endl; } else { diff --git a/mainwindow.cpp b/mainwindow.cpp index 45a29c3..1ab60e0 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -35,7 +35,6 @@ MainWindow::MainWindow(QWidget *parent) : m_ui(new Ui::MainWindow), m_aboutDialog(0) { - qDebug() << __PRETTY_FUNCTION__; m_ui->setupUi(this); connect(m_ui->actionNew, SIGNAL(activated()), this, SLOT(klakk())); connect(m_ui->actionOpen, SIGNAL(activated()), this, SLOT(klakk())); @@ -53,7 +52,6 @@ MainWindow::MainWindow(QWidget *parent) : MainWindow::~MainWindow() { - qDebug() << __PRETTY_FUNCTION__; delete m_ui; if (m_aboutDialog) delete m_aboutDialog; } @@ -65,8 +63,6 @@ void MainWindow::klakk() void MainWindow::exportScene() { - qDebug() << __PRETTY_FUNCTION__; - QFileDialog dialog(this, tr("Export MindMap to image"), "/home/cs0rbagomba", @@ -105,8 +101,6 @@ void MainWindow::exportScene() void MainWindow::about() { - qDebug() << __PRETTY_FUNCTION__; - setDisabled(true); if (m_aboutDialog == 0) m_aboutDialog = new AboutDialog(this); m_aboutDialog->setEnabled(true); // children inherits enabled status @@ -115,10 +109,7 @@ void MainWindow::about() void MainWindow::aboutDestroyed() { - qDebug() << __PRETTY_FUNCTION__; - qDebug() << m_aboutDialog; setEnabled(true); - } QStatusBar * MainWindow::getStatusBar() diff --git a/node.cpp b/node.cpp index 2f24dcf..67eb4c4 100644 --- a/node.cpp +++ b/node.cpp @@ -14,11 +14,9 @@ Node::Node(GraphWidget *parent) : m_hasBorder(true), m_numberIsSpecial(false) { - qDebug() << __PRETTY_FUNCTION__; - setFlag(ItemIsMovable); setFlag(ItemSendsGeometryChanges); - setTextInteractionFlags(Qt::TextBrowserInteraction); +// setTextInteractionFlags(Qt::TextBrowserInteraction); // setTextInteractionFlags(Qt::LinksAccessibleByMouse | Qt::LinksAccessibleByKeyboard); setCacheMode(DeviceCoordinateCache); @@ -33,34 +31,30 @@ Node::Node(GraphWidget *parent) : Node::~Node() { - qDebug() << __PRETTY_FUNCTION__; foreach (EdgeElement element, m_edgeList) delete element.edge; } void Node::addEdge(Edge *edge, bool startsFromThisNode) { - qDebug() << __PRETTY_FUNCTION__; - m_edgeList.push_back(EdgeElement(edge, startsFromThisNode)); edge->adjust(); } void Node::removeEdge(Edge *edge) { - qDebug() << __PRETTY_FUNCTION__; - - for(QList::iterator it = m_edgeList.begin(); it != m_edgeList.end(); it++) + for(QList::iterator it = m_edgeList.begin(); + it != m_edgeList.end(); it++) + { if (it->edge == edge) { m_edgeList.erase(it); return; } + } } QVariant Node::itemChange(GraphicsItemChange change, const QVariant &value) { -// qDebug() << __PRETTY_FUNCTION__; - switch (change) { case ItemPositionChange: @@ -95,8 +89,6 @@ QVariant Node::itemChange(GraphicsItemChange change, const QVariant &value) void Node::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *w) { -// qDebug() << __PRETTY_FUNCTION__; - if (m_number != -1) { painter->setBackground(m_numberIsSpecial ? Qt::green : Qt::yellow); @@ -117,14 +109,13 @@ void Node::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWid painter->setPen(Qt::white); painter->setBackground(Qt::red); painter->setBackgroundMode(Qt::OpaqueMode); - painter->drawText(boundingRect().topLeft()+QPointF(0,11), QString("%1").arg(m_number)); + painter->drawText(boundingRect().topLeft()+QPointF(0,11), + QString("%1").arg(m_number)); } } void Node::setActive(const bool &active) { - qDebug() << __PRETTY_FUNCTION__; - m_isActive = active; update(); } @@ -133,8 +124,6 @@ void Node::setActive(const bool &active) /// @note who shall set active: press or release? void Node::mousePressEvent(QGraphicsSceneMouseEvent *event) { - qDebug() << __PRETTY_FUNCTION__; - m_graph->setActiveNode(this); QGraphicsItem::mousePressEvent(event); @@ -142,8 +131,6 @@ void Node::mousePressEvent(QGraphicsSceneMouseEvent *event) void Node::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) { - qDebug() << __PRETTY_FUNCTION__; - m_graph->insertNode(); QGraphicsItem::mouseDoubleClickEvent(event); @@ -151,22 +138,18 @@ void Node::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) void Node::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { - qDebug() << __PRETTY_FUNCTION__; - QGraphicsItem::mouseReleaseEvent(event); } void Node::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { -// qDebug() << __PRETTY_FUNCTION__; - QGraphicsItem::mouseMoveEvent(event); } -void Node::showNumber(const int &number, const bool& show, const bool &numberIsSpecial) +void Node::showNumber(const int &number, + const bool& show, + const bool &numberIsSpecial) { -// qDebug() << __PRETTY_FUNCTION__; - m_number = show ? number : -1; m_numberIsSpecial = numberIsSpecial; update(); @@ -180,8 +163,6 @@ void Node::setBorder(const bool &hasBorder) double Node::calculateBiggestAngle() { - qDebug() << __PRETTY_FUNCTION__; - if (m_edgeList.empty()) return 1.5 * Pi; @@ -198,30 +179,23 @@ double Node::calculateBiggestAngle() } QList tmp; - for(QList::iterator it = m_edgeList.begin(); it != m_edgeList.end(); it++) + for(QList::iterator it = m_edgeList.begin(); + it != m_edgeList.end(); it++) { - if (it->startsFromThisNode) - { - tmp.push_back(Pi - it->edge->getAngle()); - } - else - { - tmp.push_back(2 * Pi - it->edge->getAngle()); - } + tmp.push_back(it->startsFromThisNode ? + it->edge->getAngle() : + doubleModulo(Pi + it->edge->getAngle(), 2 * Pi)); } qSort(tmp.begin(), tmp.end()); - qDebug() << tmp; - - double prev(tmp.last()); + double prev(tmp.first()); double max_prev(tmp.last()); - double max(0); + double max(2 * Pi - tmp.last() + tmp.first()); - /// @bug algorith is baaad - for(QList::const_iterator it = tmp.begin(); it!=tmp.end(); it++) + for(QList::const_iterator it = ++tmp.begin(); it!=tmp.end(); it++) { - if (abs(*it - prev) > abs(max) ) + if (*it - prev > max ) { max = *it - prev; max_prev = prev; @@ -229,10 +203,7 @@ double Node::calculateBiggestAngle() prev = *it; } - qDebug() << max; - qDebug() << max_prev; - - return max_prev + max / 2 ; + return 2 * Pi - doubleModulo(max_prev + max / 2, 2 * Pi); } void Node::linkActivated(const QString &link) @@ -241,3 +212,8 @@ void Node::linkActivated(const QString &link) qDebug() << link; } + +double Node::doubleModulo(const double &devided, const double &devisor) +{ + return devided - static_cast(devisor * static_cast(devided / devisor)); +} diff --git a/node.h b/node.h index 631dfd8..13a43c0 100644 --- a/node.h +++ b/node.h @@ -17,15 +17,16 @@ public: void addEdge(Edge *edge, bool startsFromThisNode); void removeEdge(Edge *edge); -// QList edges() const; void setBorder(const bool &hasBorder); void setActive(const bool &active = true); - void showNumber(const int &number, const bool& show = true, const bool &numberIsSpecial = false); + void showNumber(const int &number, const bool& show = true, + const bool &numberIsSpecial = false); double calculateBiggestAngle(); protected: - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, + QWidget *widget); QVariant itemChange(GraphicsItemChange change, const QVariant &value); void mousePressEvent(QGraphicsSceneMouseEvent *event); void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event); @@ -35,25 +36,18 @@ protected: private: + double doubleModulo(const double &devided, const double &devisor); + struct EdgeElement { Edge *edge; bool startsFromThisNode; EdgeElement(Edge *e, bool s) : edge(e), startsFromThisNode(s) {} }; -// class EdgeList : public QList -// { -// public: -// int compareItems(QCollection::Item a, QCollection::Item b) -// { -// return (EdgeElement)a.edge = (EdgeElement)b.edge; -// } -// }; QList m_edgeList; GraphWidget *m_graph; bool m_isActive; -// Edge *m_activeEdge; int m_number; bool m_hasBorder; bool m_numberIsSpecial; diff --git a/qtmindmap.pro.user b/qtmindmap.pro.user deleted file mode 100644 index a2bd180..0000000 --- a/qtmindmap.pro.user +++ /dev/null @@ -1,244 +0,0 @@ - - - - ProjectExplorer.Project.ActiveTarget - 0 - - - ProjectExplorer.Project.EditorSettings - - true - false - System - false - false - 4 - true - 1 - true - false - true - 0 - 8 - true - 1 - true - true - true - false - - - - ProjectExplorer.Project.Target.0 - - Desktop - Desktop - Qt4ProjectManager.Target.DesktopTarget - 1 - 0 - 0 - - ProjectExplorer.ToolChain.Gcc:/usr/bin/g++.x86-linux-generic-elf-64bit. - - - qmake - - QtProjectManager.QMakeBuildStep - false - - false - - - Make - - Qt4ProjectManager.MakeStep - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - Make - - Qt4ProjectManager.MakeStep - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Qt in PATH Release - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - /home/cs0rbagomba/projects/qtmindmap-build-desktop - 2 - ProjectExplorer.ToolChain.Gcc:/usr/bin/g++.x86-linux-generic-elf-64bit. - true - - - ProjectExplorer.ToolChain.Gcc:/usr/bin/g++.x86-linux-generic-elf-64bit. - - - qmake - - QtProjectManager.QMakeBuildStep - false - - false - - - Make - - Qt4ProjectManager.MakeStep - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - Make - - Qt4ProjectManager.MakeStep - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Qt in PATH Debug - - Qt4ProjectManager.Qt4BuildConfiguration - 2 - - 2 - ProjectExplorer.ToolChain.Gcc:/usr/bin/g++.x86-linux-generic-elf-64bit. - true - - 2 - - - 0 - Deploy - - ProjectExplorer.BuildSteps.Deploy - - 1 - No deployment - - ProjectExplorer.DefaultDeployConfiguration - - 1 - - - true - 25 - - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - qtmindmap - - Qt4ProjectManager.Qt4RunConfiguration - 2 - - qtmindmap.pro - false - true - - - 3768 - true - false - - - - true - 25 - - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - -q --tool=memcheck --leak-check=full --leak-resolution=low --suppressions=../qtmindmap/Qt47supp.txt ./qtmindmap - 2 - valgrind - false - - /home/cs0rbagomba/projects/qtmindmap-build-desktop - Run valgrind - - ProjectExplorer.CustomExecutableRunConfiguration - 3768 - true - false - - 2 - - - - ProjectExplorer.Project.TargetCount - 1 - - - ProjectExplorer.Project.Updater.EnvironmentId - {75e4e232-a182-46a5-bb12-10bf44c99a73} - - - ProjectExplorer.Project.Updater.FileVersion - 9 - - diff --git a/qtmindmap_test.pro b/qtmindmap_test.pro new file mode 100644 index 0000000..bf072cc --- /dev/null +++ b/qtmindmap_test.pro @@ -0,0 +1,26 @@ +QT += core gui svg + +CONFIG += qtestlib + +TARGET = qtmindmap_test + +SOURCES += mainwindow.cpp \ + aboutdialog.cpp \ + graphwidget.cpp \ + node.cpp \ + edge.cpp \ + systemtray.cpp \ + argumentparser.cpp \ + algorithmtests.cpp + +HEADERS += mainwindow.h \ + aboutdialog.h \ + graphwidget.h \ + node.h \ + edge.h \ + systemtray.h \ + argumentparser.h \ + algorithmtests.h + +FORMS += mainwindow.ui \ + aboutdialog.ui diff --git a/systemtray.cpp b/systemtray.cpp index bfd33c3..1e24787 100644 --- a/systemtray.cpp +++ b/systemtray.cpp @@ -1,26 +1,26 @@ #include "systemtray.h" #include -#include - void SystemTray::setup() { - qDebug() << __PRETTY_FUNCTION__; - m_systemTrayIcon = new QSystemTrayIcon(0); m_minimizeAction = new QAction(tr("Mi&nimize"), m_systemTrayIcon); - connect(m_minimizeAction, SIGNAL(triggered()), m_mainWindow, SLOT(hide())); + connect(m_minimizeAction, SIGNAL(triggered()), m_mainWindow, + SLOT(hide())); m_maximizeAction = new QAction(tr("Ma&ximize"), m_systemTrayIcon); - connect(m_maximizeAction, SIGNAL(triggered()), m_mainWindow, SLOT(showMaximized())); + connect(m_maximizeAction, SIGNAL(triggered()), m_mainWindow, + SLOT(showMaximized())); m_restoreAction = new QAction(tr("&Restore"), m_systemTrayIcon); - connect(m_restoreAction, SIGNAL(triggered()), m_mainWindow, SLOT(showNormal())); + connect(m_restoreAction, SIGNAL(triggered()), m_mainWindow, + SLOT(showNormal())); m_quitAction = new QAction(tr("&Quit"), m_systemTrayIcon); - connect(m_quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); + connect(m_quitAction, SIGNAL(triggered()), qApp, + SLOT(quit())); m_trayIconMenu = new QMenu(this); m_trayIconMenu->addAction(m_minimizeAction); @@ -39,13 +39,10 @@ SystemTray::SystemTray(MainWindow *mainWindow, QWidget *parent) : QWidget(parent), m_mainWindow(mainWindow) { - qDebug() << __PRETTY_FUNCTION__; } void SystemTray::show() { - qDebug() << __PRETTY_FUNCTION__; - m_systemTrayIcon->show(); }