new/close file

master
Denes Matetelki 14 years ago
parent baf944f8de
commit 80321d75a2

@ -2,7 +2,8 @@
#include <QDebug> #include <QDebug>
#include <QStatusBar> #include <QStatusBar>
#include <QMessageBox>
#include <QFileDialog>
#include "node.h" #include "node.h"
#include "edge.h" #include "edge.h"
@ -10,7 +11,7 @@
#include "mainwindow.h" #include "mainwindow.h"
GraphWidget::GraphWidget(QWidget *parent) : GraphWidget::GraphWidget(MainWindow *parent) :
QGraphicsView(parent), QGraphicsView(parent),
m_parent(parent), m_parent(parent),
m_activeNode(0), m_activeNode(0),
@ -18,7 +19,8 @@ GraphWidget::GraphWidget(QWidget *parent) :
m_hintNode(0), m_hintNode(0),
m_editingNode(false), m_editingNode(false),
m_edgeAdding(false), m_edgeAdding(false),
m_edgeDeleting(false) m_edgeDeleting(false),
m_contentChanged(false)
{ {
m_scene = new QGraphicsScene(this); m_scene = new QGraphicsScene(this);
m_scene->setItemIndexMethod(QGraphicsScene::NoIndex); m_scene->setItemIndexMethod(QGraphicsScene::NoIndex);
@ -30,13 +32,14 @@ GraphWidget::GraphWidget(QWidget *parent) :
setTransformationAnchor(AnchorUnderMouse); setTransformationAnchor(AnchorUnderMouse);
setMinimumSize(400, 400); setMinimumSize(400, 400);
Node *node1 = new Node(this); // Node *node1 = new Node(this);
node1->setHtml(QString("<img src=:/heart.svg width=40 height=40></img>")); // node1->setHtml(QString("<img src=:/heart.svg width=40 height=40></img>"));
m_scene->addItem(node1); // m_scene->addItem(node1);
node1->setPos(-10, -10); // node1->setPos(-10, -10);
node1->setBorder(false); // node1->setBorder(false);
m_nodeList.append(node1); // m_nodeList.append(node1);
/*
Node *node2 = new Node(this); Node *node2 = new Node(this);
node2->setHtml(QString("work: <a href=www.hup.hu>hup.hu</a>")); node2->setHtml(QString("work: <a href=www.hup.hu>hup.hu</a>"));
m_scene->addItem(node2); m_scene->addItem(node2);
@ -116,10 +119,90 @@ GraphWidget::GraphWidget(QWidget *parent) :
m_scene->addItem(new Edge(node5, node7)); m_scene->addItem(new Edge(node5, node7));
m_scene->addItem(new Edge(node2, node8)); m_scene->addItem(new Edge(node2, node8));
m_scene->addItem(new Edge(node2, node9)); 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() QGraphicsScene *GraphWidget::getScene()
@ -510,3 +593,24 @@ void GraphWidget::showNodeNumbers()
showingNodeNumbersBeginWithNumber(m_hintNumber.toInt(), true); 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("<img src=:/heart.svg width=40 height=40></img>"));
m_scene->addItem(node1);
node1->setPos(-10, -10);
node1->setBorder(false);
m_nodeList.append(node1);
m_activeNode = m_nodeList.first();
m_activeNode->setActive();
}

@ -6,22 +6,32 @@
#include <QKeyEvent> #include <QKeyEvent>
#include <QMovie> #include <QMovie>
//#include "mainwindow.h"
#include "node.h" #include "node.h"
class MainWindow;
class GraphWidget : public QGraphicsView class GraphWidget : public QGraphicsView
{ {
Q_OBJECT Q_OBJECT
public: public:
GraphWidget(QWidget *parent = 0); GraphWidget(MainWindow *parent = 0);
QGraphicsScene *getScene(); QGraphicsScene *getScene();
void setActiveNode(Node *node); void setActiveNode(Node *node);
void insertNode(); void insertNode();
void setActiveNodeEditable(); void setActiveNodeEditable();
void nodeSelected(Node *node); void nodeSelected(Node *node);
public slots:
void newFile();
void closeFile();
void saveFile();
void saveFileAs();
void openFile();
protected: protected:
void keyPressEvent(QKeyEvent *event); void keyPressEvent(QKeyEvent *event);
@ -40,9 +50,11 @@ private:
qreal calculateBiggestAngle(Node *node); qreal calculateBiggestAngle(Node *node);
void addEdge(Node *source, Node *destination); void addEdge(Node *source, Node *destination);
void removeEdge(Node* source, Node *destination); void removeEdge(Node* source, Node *destination);
void removeAllNodes();
void addFirstNode();
QList<Node *> m_nodeList; QList<Node *> m_nodeList;
QWidget *m_parent; MainWindow *m_parent;
Node *m_activeNode; Node *m_activeNode;
QGraphicsScene *m_scene; QGraphicsScene *m_scene;
bool m_showingNodeNumbers; bool m_showingNodeNumbers;
@ -51,6 +63,7 @@ private:
bool m_editingNode; bool m_editingNode;
bool m_edgeAdding; bool m_edgeAdding;
bool m_edgeDeleting; bool m_edgeDeleting;
bool m_contentChanged;
}; };
#endif // GRAPHWIDGET_H #endif // GRAPHWIDGET_H

@ -22,7 +22,7 @@ int main(int argc, char *argv[])
// translation // translation
QString locale = QLocale::system().name(); QString locale = QLocale::system().name();
QTranslator translator; QTranslator translator;
if (!translator.load(QString("qtmindmap_") + locale)) if (locale != "C" && !translator.load(QString("qtmindmap_") + locale))
{ {
std::cerr << "No translation file for locale: " std::cerr << "No translation file for locale: "
<< locale.toStdString() << locale.toStdString()
@ -58,6 +58,9 @@ int main(int argc, char *argv[])
systemtray.show(); systemtray.show();
} }
if (!argParser.filePath().isEmpty())
w.setFileName(argParser.filePath());
if (!argParser.isShowMinimized()) w.show(); if (!argParser.isShowMinimized()) w.show();
return a.exec(); return a.exec();
} }

@ -35,19 +35,22 @@ MainWindow::MainWindow(QWidget *parent) :
m_ui(new Ui::MainWindow), m_ui(new Ui::MainWindow),
m_aboutDialog(0) m_aboutDialog(0)
{ {
m_graphicsView = new GraphWidget(this);
m_ui->setupUi(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->actionOpen, SIGNAL(activated()), this, SLOT(klakk()));
connect(m_ui->actionSave, 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->actionExport, SIGNAL(activated()), this, SLOT(exportScene()));
connect(m_ui->actionQuit, SIGNAL(activated()), QApplication::instance(), connect(m_ui->actionQuit, SIGNAL(activated()), QApplication::instance(),
SLOT(quit())); SLOT(quit()));
connect(m_ui->actionAbout_QtMindMap, SIGNAL(activated()), this, connect(m_ui->actionAbout_QtMindMap, SIGNAL(activated()), this,
SLOT(about())); SLOT(about()));
m_graphicsView = new GraphWidget(this);
setCentralWidget(m_graphicsView); setCentralWidget(m_graphicsView);
m_graphicsView->hide();
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()

@ -19,6 +19,8 @@ public:
explicit MainWindow(QWidget *parent = 0); explicit MainWindow(QWidget *parent = 0);
~MainWindow(); ~MainWindow();
QStatusBar * getStatusBar(); QStatusBar * getStatusBar();
QString getFileName() { return m_fileName; }
void setFileName(QString fileName) { m_fileName = fileName; }
public slots: public slots:
void klakk(); void klakk();
@ -31,6 +33,7 @@ private:
Ui::MainWindow *m_ui; Ui::MainWindow *m_ui;
AboutDialog *m_aboutDialog; AboutDialog *m_aboutDialog;
GraphWidget *m_graphicsView; GraphWidget *m_graphicsView;
QString m_fileName;
}; };

@ -56,7 +56,7 @@
<widget class="QStatusBar" name="statusBar"/> <widget class="QStatusBar" name="statusBar"/>
<action name="actionNew"> <action name="actionNew">
<property name="enabled"> <property name="enabled">
<bool>false</bool> <bool>true</bool>
</property> </property>
<property name="text"> <property name="text">
<string>&amp;New</string> <string>&amp;New</string>
@ -102,7 +102,7 @@
</action> </action>
<action name="actionClose"> <action name="actionClose">
<property name="enabled"> <property name="enabled">
<bool>false</bool> <bool>true</bool>
</property> </property>
<property name="text"> <property name="text">
<string>&amp;Close</string> <string>&amp;Close</string>

Loading…
Cancel
Save