diff --git a/graphwidget.cpp b/graphwidget.cpp index b2565e4..558a6b4 100644 --- a/graphwidget.cpp +++ b/graphwidget.cpp @@ -2,7 +2,8 @@ #include #include - +#include +#include #include "node.h" #include "edge.h" @@ -10,7 +11,7 @@ #include "mainwindow.h" -GraphWidget::GraphWidget(QWidget *parent) : +GraphWidget::GraphWidget(MainWindow *parent) : QGraphicsView(parent), m_parent(parent), m_activeNode(0), @@ -18,7 +19,8 @@ GraphWidget::GraphWidget(QWidget *parent) : m_hintNode(0), m_editingNode(false), m_edgeAdding(false), - m_edgeDeleting(false) + m_edgeDeleting(false), + m_contentChanged(false) { m_scene = new QGraphicsScene(this); m_scene->setItemIndexMethod(QGraphicsScene::NoIndex); @@ -30,13 +32,14 @@ GraphWidget::GraphWidget(QWidget *parent) : setTransformationAnchor(AnchorUnderMouse); setMinimumSize(400, 400); - Node *node1 = new Node(this); - node1->setHtml(QString("")); - m_scene->addItem(node1); - node1->setPos(-10, -10); - node1->setBorder(false); - m_nodeList.append(node1); +// Node *node1 = new Node(this); +// node1->setHtml(QString("")); +// m_scene->addItem(node1); +// node1->setPos(-10, -10); +// node1->setBorder(false); +// m_nodeList.append(node1); + /* Node *node2 = new Node(this); node2->setHtml(QString("work: hup.hu")); m_scene->addItem(node2); @@ -116,10 +119,90 @@ GraphWidget::GraphWidget(QWidget *parent) : m_scene->addItem(new Edge(node5, node7)); m_scene->addItem(new Edge(node2, node8)); m_scene->addItem(new Edge(node2, node9)); + */ +// m_activeNode = m_nodeList.first(); +// m_activeNode->setActive(); + + //addFirstNode(); + + /// @todo open file somewhere +} + +void GraphWidget::newFile() +{ + removeAllNodes(); + + addFirstNode(); + + this->show(); +} + +void GraphWidget::closeFile() +{ + m_contentChanged = true; + + if (m_contentChanged) + { + + int ret = QMessageBox::warning( + this, + tr("QtMindMap - The document has been modified"), + m_parent->getFileName(). + append("\n\n"). + append(tr("Do you want to save your changes?")), + QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, + QMessageBox::Save); + + switch (ret) { + case QMessageBox::Save: + // Save was clicked + { + QString fileName = QFileDialog::getSaveFileName( + this, + tr("Save File"), + QDir::homePath(), + tr("Images (*.png *.xpm *.jpg)")); + + qDebug() << fileName; + + /// @todo save content to file + + break; + } + case QMessageBox::Discard: + // Don't Save was clicked + removeAllNodes(); + this->hide(); + break; + case QMessageBox::Cancel: + // Cancel was clicked + return; + default: + // should never be reached + break; + } + } + else + { + removeAllNodes(); + this->hide(); + } +} + +void GraphWidget::saveFile() +{ + +} + +void GraphWidget::saveFileAs() +{ + +} + +void GraphWidget::openFile() +{ - m_activeNode = m_nodeList.first(); - m_activeNode->setActive(); } QGraphicsScene *GraphWidget::getScene() @@ -510,3 +593,24 @@ void GraphWidget::showNodeNumbers() showingNodeNumbersBeginWithNumber(m_hintNumber.toInt(), true); } } + +void GraphWidget::removeAllNodes() +{ + foreach(Node *node, m_nodeList) delete node; + m_nodeList.clear(); + m_activeNode = 0; + m_hintNode = 0; +} + +void GraphWidget::addFirstNode() +{ + Node *node1 = new Node(this); + node1->setHtml(QString("")); + m_scene->addItem(node1); + node1->setPos(-10, -10); + node1->setBorder(false); + m_nodeList.append(node1); + + m_activeNode = m_nodeList.first(); + m_activeNode->setActive(); +} diff --git a/graphwidget.h b/graphwidget.h index 5102542..641c367 100644 --- a/graphwidget.h +++ b/graphwidget.h @@ -6,22 +6,32 @@ #include #include +//#include "mainwindow.h" #include "node.h" +class MainWindow; class GraphWidget : public QGraphicsView { Q_OBJECT - public: - GraphWidget(QWidget *parent = 0); + GraphWidget(MainWindow *parent = 0); + QGraphicsScene *getScene(); void setActiveNode(Node *node); void insertNode(); void setActiveNodeEditable(); void nodeSelected(Node *node); +public slots: + + void newFile(); + void closeFile(); + void saveFile(); + void saveFileAs(); + void openFile(); + protected: void keyPressEvent(QKeyEvent *event); @@ -40,9 +50,11 @@ private: qreal calculateBiggestAngle(Node *node); void addEdge(Node *source, Node *destination); void removeEdge(Node* source, Node *destination); + void removeAllNodes(); + void addFirstNode(); QList m_nodeList; - QWidget *m_parent; + MainWindow *m_parent; Node *m_activeNode; QGraphicsScene *m_scene; bool m_showingNodeNumbers; @@ -51,6 +63,7 @@ private: bool m_editingNode; bool m_edgeAdding; bool m_edgeDeleting; + bool m_contentChanged; }; #endif // GRAPHWIDGET_H diff --git a/main.cpp b/main.cpp index fc6e1c6..33b9e09 100644 --- a/main.cpp +++ b/main.cpp @@ -22,7 +22,7 @@ int main(int argc, char *argv[]) // translation QString locale = QLocale::system().name(); QTranslator translator; - if (!translator.load(QString("qtmindmap_") + locale)) + if (locale != "C" && !translator.load(QString("qtmindmap_") + locale)) { std::cerr << "No translation file for locale: " << locale.toStdString() @@ -58,6 +58,9 @@ int main(int argc, char *argv[]) systemtray.show(); } + if (!argParser.filePath().isEmpty()) + w.setFileName(argParser.filePath()); + if (!argParser.isShowMinimized()) w.show(); return a.exec(); } diff --git a/mainwindow.cpp b/mainwindow.cpp index 1ab60e0..b922232 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -35,19 +35,22 @@ MainWindow::MainWindow(QWidget *parent) : m_ui(new Ui::MainWindow), m_aboutDialog(0) { + m_graphicsView = new GraphWidget(this); + m_ui->setupUi(this); - connect(m_ui->actionNew, SIGNAL(activated()), this, SLOT(klakk())); + connect(m_ui->actionNew, SIGNAL(activated()), m_graphicsView, SLOT(newFile())); connect(m_ui->actionOpen, SIGNAL(activated()), this, SLOT(klakk())); connect(m_ui->actionSave, SIGNAL(activated()), this, SLOT(klakk())); - connect(m_ui->actionClose, SIGNAL(activated()), this, SLOT(klakk())); + connect(m_ui->actionClose, SIGNAL(activated()), m_graphicsView, SLOT(closeFile())); connect(m_ui->actionExport, SIGNAL(activated()), this, SLOT(exportScene())); connect(m_ui->actionQuit, SIGNAL(activated()), QApplication::instance(), SLOT(quit())); connect(m_ui->actionAbout_QtMindMap, SIGNAL(activated()), this, SLOT(about())); - m_graphicsView = new GraphWidget(this); + setCentralWidget(m_graphicsView); + m_graphicsView->hide(); } MainWindow::~MainWindow() diff --git a/mainwindow.h b/mainwindow.h index cd54171..3f80555 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -19,6 +19,8 @@ public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); QStatusBar * getStatusBar(); + QString getFileName() { return m_fileName; } + void setFileName(QString fileName) { m_fileName = fileName; } public slots: void klakk(); @@ -31,6 +33,7 @@ private: Ui::MainWindow *m_ui; AboutDialog *m_aboutDialog; GraphWidget *m_graphicsView; + QString m_fileName; }; diff --git a/mainwindow.ui b/mainwindow.ui index 029f7d3..386e820 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -56,7 +56,7 @@ - false + true &New @@ -102,7 +102,7 @@ - false + true &Close