master
Denes Matetelki 14 years ago
parent 790bd6a964
commit 03042f5906

@ -137,6 +137,11 @@ void GraphWidget::newFile()
addFirstNode();
this->show();
m_parent->enableCloseFile(true);
m_parent->enableSave(false);
m_parent->enableSaveAs(true);
m_parent->setTitle("untitled");
}
void GraphWidget::closeFile()
@ -189,21 +194,31 @@ void GraphWidget::closeFile()
removeAllNodes();
this->hide();
}
}
void GraphWidget::saveFile()
{
m_parent->enableCloseFile(false);
m_parent->enableSave(false);
m_parent->enableSaveAs(false);
m_parent->setTitle("");
}
void GraphWidget::saveFileAs()
{
QString fileName = QFileDialog::getSaveFileName(
this,
tr("Save File"),
QDir::homePath(),
tr("QtMindMap (*.qmm)"));
QFileDialog dialog(this,
tr("Save MindMap as"),
QDir::homePath(),
tr("QtMindMap (*.qmm)"));
dialog.setAcceptMode(QFileDialog::AcceptSave);
dialog.setDefaultSuffix("qmm");
if (dialog.exec())
{
m_fileName = dialog.selectedFiles().first();
saveFile();
}
}
void GraphWidget::saveFile()
{
QDomDocument doc("QtMindMap");
QDomElement root = doc.createElement("qtmindmap");
@ -233,7 +248,7 @@ void GraphWidget::saveFileAs()
edges_root.appendChild(cn);
}
QFile file(fileName);
QFile file(m_fileName);
if (!file.open(QIODevice::WriteOnly))
{
dynamic_cast<MainWindow *>(m_parent)->getStatusBar()->showMessage(
@ -249,13 +264,95 @@ void GraphWidget::saveFileAs()
dynamic_cast<MainWindow *>(m_parent)->getStatusBar()->showMessage(
tr("Saved."),
3000); // millisec
m_parent->enableCloseFile(true);
m_parent->enableSave(true);
m_parent->enableSaveAs(true);
m_parent->setTitle(m_fileName);
}
void GraphWidget::openFile()
{
qDebug() << __PRETTY_FUNCTION__;
QFileDialog dialog(this,
tr("Open MindMap"),
QDir::homePath(),
tr("QtMindMap (*.qmm)"));
dialog.setAcceptMode(QFileDialog::AcceptOpen);
dialog.setDefaultSuffix("qmm");
if (dialog.exec())
{
m_fileName = dialog.selectedFiles().first();
openFile(m_fileName);
}
}
void GraphWidget::openFile(const QString &fileName)
{
m_fileName = fileName;
m_parent->enableCloseFile(true);
m_parent->enableSave(true);
m_parent->enableSaveAs(true);
m_parent->setTitle(fileName);
QDomDocument doc("QtMindMap");
QFile file(fileName);
if (!file.open(QIODevice::ReadOnly))
{
qDebug() << "faszom cannot read file";
return;
}
if (!doc.setContent(&file))
{
qDebug() << "cannot parse file";
file.close();
return;
}
file.close();
removeAllNodes();
QDomElement docElem = doc.documentElement();
QDomNodeList nodes = docElem.childNodes().item(0).childNodes();
for (unsigned int i = 0; i < nodes.length(); i++)
{
QDomElement e = nodes.item(i).toElement();
if(!e.isNull())
{
Node *node = new Node(this);
node->setHtml(e.attribute("htmlContent"));
m_scene->addItem(node);
node->setPos(e.attribute("x").toFloat(),
e.attribute("y").toFloat());
m_nodeList.append(node);
}
}
QDomNodeList edges = docElem.childNodes().item(1).childNodes();
for (unsigned int i = 0; i < edges.length(); i++)
{
QDomElement e = edges.item(i).toElement();
if(!e.isNull())
{
m_scene->addItem(new Edge(m_nodeList[e.attribute("source").toInt()],
m_nodeList[e.attribute("destination").toInt()]));
}
}
m_activeNode = m_nodeList.first();
m_activeNode->setActive();
this->show();
}
QGraphicsScene *GraphWidget::getScene()
{
return m_scene;

@ -32,6 +32,7 @@ public slots:
void closeFile();
void saveFile();
void saveFileAs();
void openFile(const QString &fileName);
void openFile();
protected:
@ -66,6 +67,7 @@ private:
bool m_edgeAdding;
bool m_edgeDeleting;
bool m_contentChanged;
QString m_fileName;
};
#endif // GRAPHWIDGET_H

@ -59,7 +59,7 @@ int main(int argc, char *argv[])
}
if (!argParser.filePath().isEmpty())
w.setFileName(argParser.filePath());
w.openFile(argParser.filePath());
if (!argParser.isShowMinimized()) w.show();
return a.exec();

@ -68,7 +68,7 @@ void MainWindow::exportScene()
{
QFileDialog dialog(this,
tr("Export MindMap to image"),
"/home/cs0rbagomba",
QDir::homePath(),
tr("PNG image file (*.png)"));
dialog.setAcceptMode(QFileDialog::AcceptSave);
dialog.setDefaultSuffix("png");
@ -117,3 +117,45 @@ QStatusBar * MainWindow::getStatusBar()
{
return m_ui->statusBar;
}
void MainWindow::openFile(QString fileName)
{
m_fileName = fileName;
m_graphicsView->openFile(m_fileName);
}
void MainWindow::enableSave(const bool &enable)
{
m_ui->actionSave->setEnabled(enable);
}
void MainWindow::enableSaveAs(const bool &enable)
{
m_ui->actionSaveAs->setEnabled(enable);
}
void MainWindow::enableCloseFile(const bool &enable)
{
m_ui->actionClose->setEnabled(enable);
}
void MainWindow::setTitle(const QString &title)
{
if (title.isEmpty())
{
setWindowTitle("QtMindMap");
}
else
{
QString t(title);
t.append(" - QtMindMap");
setWindowTitle(t);
}
}
//void MainWindow::setModifiedTitle(const bool &modified)
//{
// modified ?
// setWindowTitle(windowTitle().remove(0,2)) :
// setWindowTitle(windowTitle().prepend("* "));
//}

@ -19,7 +19,12 @@ public:
~MainWindow();
QStatusBar * getStatusBar();
QString getFileName() { return m_fileName; }
void setFileName(QString fileName) { m_fileName = fileName; }
void openFile(QString fileName);
void enableSave(const bool &enable = true);
void enableSaveAs(const bool &enable = true);
void enableCloseFile(const bool &enable = true);
void setTitle(const QString &title);
// void setModifiedTitle(const bool &modified = true);
public slots:

@ -79,7 +79,7 @@
</action>
<action name="actionSave">
<property name="enabled">
<bool>true</bool>
<bool>false</bool>
</property>
<property name="text">
<string>&amp;Save</string>
@ -103,7 +103,7 @@
</action>
<action name="actionClose">
<property name="enabled">
<bool>true</bool>
<bool>false</bool>
</property>
<property name="text">
<string>&amp;Close</string>
@ -124,6 +124,9 @@
</property>
</action>
<action name="actionSaveAs">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Save&amp;As</string>
</property>

Loading…
Cancel
Save