From 6bdf817793dcbcca23637fbd8f9b32d5d962c7ff Mon Sep 17 00:00:00 2001 From: Denes Matetelki Date: Thu, 23 Jun 2011 16:17:45 +0200 Subject: [PATCH] adding status icons --- graphwidget.cpp | 11 ++++++++++ graphwidget.h | 2 ++ mainwindow.cpp | 56 ++++++++++++++++++++++++++++++++++++++++++++++++- mainwindow.h | 3 +++ node.cpp | 16 ++++++++++++++ node.h | 1 + qtmindmap.pro | 3 +++ 7 files changed, 91 insertions(+), 1 deletion(-) diff --git a/graphwidget.cpp b/graphwidget.cpp index 15faf1b..b7718bc 100644 --- a/graphwidget.cpp +++ b/graphwidget.cpp @@ -207,6 +207,17 @@ void GraphWidget::writeContentToPngFile(const QString &fileName) m_parent->statusBarMsg(tr("MindMap exported as ") + fileName); } +void GraphWidget::insertPicture(const QString &picture) +{ + if (!m_activeNode) + { + m_parent->statusBarMsg(tr("No active node.")); + return; + } + + m_activeNode->insertPicture(picture); +} + void GraphWidget::keyPressEvent(QKeyEvent *event) { // esc leaves node editing mode diff --git a/graphwidget.h b/graphwidget.h index 60e0cb4..a814e81 100644 --- a/graphwidget.h +++ b/graphwidget.h @@ -32,6 +32,8 @@ public: void writeContentToXmlFile(const QString &fileName); void writeContentToPngFile(const QString &fileName); + void insertPicture(const QString &picture); + protected: void keyPressEvent(QKeyEvent *event); diff --git a/mainwindow.cpp b/mainwindow.cpp index b7efacb..9bec0ac 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -40,29 +40,42 @@ MainWindow::MainWindow(QWidget *parent) : // why can't I do this with qtcreator? /// @bug or a feature? no underline here + + /// @todo solve the shorcuts + m_doIt = new QAction(QIcon(":/user-trash-full.svg"), "&Do it", this); +// m_doIt->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_T)); + m_ui->mainToolBar->addAction(m_doIt); + connect(m_doIt, SIGNAL(activated()), this, SLOT(insertPicture())); + m_trash = new QAction(QIcon(":/user-trash-full.svg"), "&Trash it", this); m_trash->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_T)); m_ui->mainToolBar->addAction(m_trash); + connect(m_trash, SIGNAL(activated()), this, SLOT(insertPicture())); m_info = new QAction(QIcon(":/folder.svg"), "&Reference it", this); m_info->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_R)); m_ui->mainToolBar->addAction(m_info); + connect(m_info, SIGNAL(activated()), this, SLOT(insertPicture())); m_blocked = new QAction(QIcon(":/dialog-warning.svg"), tr("&Blocked"), this); m_blocked->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_B)); m_ui->mainToolBar->addAction(m_blocked); + connect(m_blocked, SIGNAL(activated()), this, SLOT(insertPicture())); - m_question = new QAction(QIcon(":/help-browser.svg"), tr("&What shall be done?"), this); + m_question = new QAction(QIcon(":/help-browser.svg"), tr("&What is it?"), this); // m_question->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q)); m_ui->mainToolBar->addAction(m_question); + connect(m_question, SIGNAL(activated()), this, SLOT(insertPicture())); m_postpone = new QAction(QIcon(":/x-office-calendar.svg"), tr("&Postpone it"), this); m_postpone->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_P)); m_ui->mainToolBar->addAction(m_postpone); + connect(m_postpone, SIGNAL(activated()), this, SLOT(insertPicture())); m_delegate = new QAction(QIcon(":/system-users.svg"), tr("&Delegate it"), this); m_delegate->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_D)); m_ui->mainToolBar->addAction(m_delegate); + connect(m_delegate, SIGNAL(activated()), this, SLOT(insertPicture())); m_ui->mainToolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); } @@ -317,6 +330,47 @@ void MainWindow::about() msgBox.exec(); } +void MainWindow::insertPicture() +{ + QAction *sender = dynamic_cast(QObject::sender()); + + /// @note Why QIcon does not store it's fileName? It would be easier: + // m_graphicsView->insertPicture( + // dynamic_cast(QObject::sender())->icon().name()); + if (sender == m_doIt) + { + m_graphicsView->insertPicture(":/user-trash-full.svg"); + } + else if (sender == m_trash) + { + m_graphicsView->insertPicture(":/user-trash-full.svg"); + } + else if (sender == m_info) + { + m_graphicsView->insertPicture(":/folder.svg"); + } + else if (sender == m_blocked) + { + m_graphicsView->insertPicture(":/dialog-warning.svg"); + } + else if (sender == m_question) + { + m_graphicsView->insertPicture(":/help-browser.svg"); + } + else if (sender == m_postpone) + { + m_graphicsView->insertPicture(":/x-office-calendar.svg"); + } + else if (sender == m_delegate) + { + m_graphicsView->insertPicture(":/system-users.svg"); + } + else + { + return; + } +} + void MainWindow::closeEvent(QCloseEvent * event) { m_contentChanged && !closeFile() ? event->ignore() : event->accept(); diff --git a/mainwindow.h b/mainwindow.h index 0debcdb..a27ffbd 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -34,6 +34,8 @@ public slots: void keys(); void about(); + void insertPicture(); + protected: void closeEvent(QCloseEvent * event); @@ -46,6 +48,7 @@ private: QString m_fileName; bool m_contentChanged; + QAction *m_doIt; QAction *m_trash; QAction *m_info; QAction *m_blocked; diff --git a/node.cpp b/node.cpp index 8b5b848..abccdc1 100644 --- a/node.cpp +++ b/node.cpp @@ -152,6 +152,22 @@ void Node::showNumber(const int &number, update(); } +void Node::insertPicture(const QString &picture, const int &pos) +{ + QTextCursor c = textCursor(); + + if (pos) + { + c.setPosition(pos); + } + + c.insertHtml(QString("")); + + m_graph->contentChanged(); + foreach (EdgeElement element, m_edgeList) element.edge->adjust(); +} + double Node::calculateBiggestAngle() { if (m_edgeList.empty()) diff --git a/node.h b/node.h index 9d83a0f..1375a58 100644 --- a/node.h +++ b/node.h @@ -33,6 +33,7 @@ public: void showNumber(const int &number, const bool& show = true, const bool &numberIsSpecial = false); + void insertPicture(const QString &picture, const int &pos = 0); double calculateBiggestAngle(); // changing visibility from prot to pub diff --git a/qtmindmap.pro b/qtmindmap.pro index 7d48db6..d8a2072 100644 --- a/qtmindmap.pro +++ b/qtmindmap.pro @@ -6,7 +6,10 @@ QT += core gui svg xml +CONFIG += warn_on + TARGET = qtmindmap + TEMPLATE = app