diff --git a/aboutdialog.cpp b/aboutdialog.cpp index 4371edf..09582fe 100644 --- a/aboutdialog.cpp +++ b/aboutdialog.cpp @@ -1,7 +1,6 @@ #include "aboutdialog.h" #include "ui_aboutdialog.h" -//#include AboutDialog::AboutDialog(QWidget *parent) : QDialog(parent), diff --git a/graphwidget.cpp b/graphwidget.cpp index 8769d4d..793a21c 100644 --- a/graphwidget.cpp +++ b/graphwidget.cpp @@ -59,6 +59,10 @@ GraphWidget::GraphWidget(QWidget *parent) activeNode->setFocus(); } +QGraphicsScene *GraphWidget::getScene() +{ + return scene; +} void GraphWidget::keyPressEvent(QKeyEvent *event) { diff --git a/graphwidget.h b/graphwidget.h index 1011792..0f578da 100644 --- a/graphwidget.h +++ b/graphwidget.h @@ -7,7 +7,6 @@ #include "node.h" -//class Node; class GraphWidget : public QGraphicsView { @@ -16,9 +15,9 @@ class GraphWidget : public QGraphicsView public: GraphWidget(QWidget *parent = 0); + QGraphicsScene *getScene(); protected: -// void drawBackground(QPainter *painter, const QRectF &rect); void keyPressEvent(QKeyEvent *event); void wheelEvent(QWheelEvent *event); void scaleView(qreal scaleFactor); diff --git a/main.cpp b/main.cpp index d0d02b7..8bd9a6f 100644 --- a/main.cpp +++ b/main.cpp @@ -2,12 +2,11 @@ #include // cout #include -//#include #include #include +#include #include "mainwindow.h" -#include "systemtray.h" void printUsage() @@ -18,12 +17,15 @@ void printUsage() << "Options:" << std::endl << "-h, --help\tPrints this help." << std::endl << "-t, --tray\tStarts application in system tray." << std::endl + << "-s, --show-minimized\tHide main window, just show systray icon." << std::endl << std::endl << "Report bugs to: denes.matetelki@gmail.com" << std::endl; } -bool parseCmdLineArgs(bool &isSystemTray, QString &filePath) +bool parseCmdLineArgs(bool &isSystemTray, + bool &isShowMinimized, + QString &filePath) { QStringList cmdlineArgs = QCoreApplication::arguments(); cmdlineArgs.removeFirst(); @@ -34,7 +36,13 @@ bool parseCmdLineArgs(bool &isSystemTray, QString &filePath) QRegExp tray("^-(t|-tray)$"); if (!cmdlineArgs.filter(tray).isEmpty()) isSystemTray = true; - QRegExp all("^-(t|-tray|h|-help)$"); + QRegExp minimized("^-(s|-show-minimized)$"); + if (!cmdlineArgs.filter(minimized).isEmpty()) 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); if (others.size() > 1) return false; @@ -51,32 +59,43 @@ int main(int argc, char *argv[]) QApplication a(argc, argv); + // translation + QString locale = QLocale::system().name(); + QTranslator translator; + if (!translator.load(QString("qtmindmap_") + locale)) + { + std::cout << "No translation file for locale: " << locale.toStdString() << std::endl; + } + else + { + a.installTranslator(&translator); + } + + // parse args bool isSystemTray(false); + bool isShowMinimized(false); QString filePath; - if (!parseCmdLineArgs(isSystemTray,filePath)) + if (!parseCmdLineArgs(isSystemTray,isShowMinimized,filePath)) { printUsage(); return EXIT_FAILURE; } - MainWindow w; - SystemTray *systemTray; - isSystemTray = true; - if (isSystemTray) + // system tray? + MainWindow w(isSystemTray or isShowMinimized); + if (isSystemTray or isShowMinimized) { if (!QSystemTrayIcon::isSystemTrayAvailable()) { QMessageBox::critical(0, - QObject::tr("Systray"), + QObject::tr("QtMindMap Error"), QObject::tr("I couldn't detect any system tray on this system.")); return EXIT_FAILURE; } QApplication::setQuitOnLastWindowClosed(false); - systemTray = new SystemTray(&w); - systemTray->show(); + w.showSysTray(); } - - w.show(); + if (!isShowMinimized) w.show(); return a.exec(); } diff --git a/mainwindow.cpp b/mainwindow.cpp index 88ac80a..e486a95 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -4,8 +4,10 @@ #include //#include +#include -MainWindow::MainWindow(QWidget *parent) : + +MainWindow::MainWindow(bool isSystemtray, QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), aboutDialog(0) @@ -16,14 +18,16 @@ MainWindow::MainWindow(QWidget *parent) : connect(ui->actionOpen, SIGNAL(activated()), this, SLOT(klakk())); connect(ui->actionSave, SIGNAL(activated()), this, SLOT(klakk())); connect(ui->actionClose, SIGNAL(activated()), this, SLOT(klakk())); + connect(ui->actionExport, SIGNAL(activated()), this, SLOT(exportScene())); connect(ui->actionQuit, SIGNAL(activated()), QApplication::instance(), - SLOT(closeAllWindows())); + SLOT(quit())); connect(ui->actionAbout_QtMindMap, SIGNAL(activated()), this, SLOT(about())); graphicsView = new GraphWidget(ui->centralWidget); setCentralWidget(graphicsView); + if (isSystemtray) setupSystemTray(); } MainWindow::~MainWindow() @@ -38,6 +42,66 @@ void MainWindow::klakk() qDebug() << __PRETTY_FUNCTION__; } +void MainWindow::exportScene() +{ + qDebug() << __PRETTY_FUNCTION__; + + QFileDialog dialog(this, + tr("Export MindMap to image"), + "/home/cs0rbagomba", + tr("PNG image file (*.png)")); + dialog.setAcceptMode(QFileDialog::AcceptSave); + dialog.setDefaultSuffix("png"); + + + if (dialog.exec()) + { + QStringList fileNames(dialog.selectedFiles()); + + // start export in a diff thread + QImage img(graphicsView->getScene()->sceneRect().width(), + graphicsView->getScene()->sceneRect().height(), + QImage::Format_ARGB32_Premultiplied); + QPainter painter(&img); + painter.setRenderHint(QPainter::Antialiasing); + graphicsView->getScene()->render(&painter); + painter.end(); + + img.save(fileNames.first()); + ui->statusBar->showMessage(tr("MindMap exported as ") + fileNames.first(), + 5000); + } +} + +void MainWindow::setupSystemTray() +{ + systemTrayIcon = new QSystemTrayIcon(0); + + minimizeAction = new QAction(tr("Mi&nimize"), systemTrayIcon); + connect(minimizeAction, SIGNAL(triggered()), this, SLOT(hide())); + + maximizeAction = new QAction(tr("Ma&ximize"), systemTrayIcon); + connect(maximizeAction, SIGNAL(triggered()), this, SLOT(showMaximized())); + + restoreAction = new QAction(tr("&Restore"), systemTrayIcon); + connect(restoreAction, SIGNAL(triggered()), this, SLOT(showNormal())); + + quitAction = new QAction(tr("&Quit"), systemTrayIcon); + connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); + + trayIconMenu = new QMenu(this); + trayIconMenu->addAction(minimizeAction); + trayIconMenu->addAction(maximizeAction); + trayIconMenu->addAction(restoreAction); + trayIconMenu->addSeparator(); + trayIconMenu->addAction(quitAction); + + systemTrayIcon->setContextMenu(trayIconMenu); + + icon = new QIcon(":/heart.svg"); + systemTrayIcon->setIcon(QIcon(":/heart.svg")); +} + void MainWindow::about() { qDebug() << __PRETTY_FUNCTION__; @@ -57,4 +121,7 @@ void MainWindow::aboutDestroyed() } - +void MainWindow::showSysTray() +{ + systemTrayIcon->show(); +} diff --git a/mainwindow.h b/mainwindow.h index 9261f37..95d67c7 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -2,7 +2,7 @@ #define MAINWINDOW_H #include -//#include +#include #include "aboutdialog.h" #include "graphwidget.h" @@ -16,19 +16,32 @@ class MainWindow : public QMainWindow Q_OBJECT public: - explicit MainWindow(QWidget *parent = 0); + explicit MainWindow(bool isSystemTray = false, QWidget *parent = 0); ~MainWindow(); + void showSysTray(); public slots: - void klakk(void); + void klakk(); + void exportScene(); void about(); void aboutDestroyed(); private: + + void setupSystemTray(); + Ui::MainWindow *ui; AboutDialog* aboutDialog; -// QPointer aboutDialog; GraphWidget *graphicsView; + + QSystemTrayIcon *systemTrayIcon; + MainWindow *mainWindow; + QMenu *trayIconMenu; + QAction *minimizeAction; + QAction *maximizeAction; + QAction *restoreAction; + QAction *quitAction; + QIcon *icon; }; #endif // MAINWINDOW_H diff --git a/mainwindow.ui b/mainwindow.ui index 6f99741..f7ad762 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -32,6 +32,8 @@ + + @@ -57,7 +59,7 @@ &New - Ctrl+N + Ctrl+N @@ -65,7 +67,7 @@ &Open - Ctrl+O + Ctrl+O @@ -73,7 +75,7 @@ &Save - Ctrl+S + Ctrl+S @@ -81,7 +83,7 @@ &Quit - Ctrl+Q + Ctrl+Q @@ -94,7 +96,18 @@ &Close - Ctrl+W + Ctrl+W + + + + + E&xport + + + Export + + + Ctrl+X diff --git a/qtmindmap.pro b/qtmindmap.pro index 90af67f..93926aa 100644 --- a/qtmindmap.pro +++ b/qtmindmap.pro @@ -15,17 +15,19 @@ SOURCES += main.cpp\ aboutdialog.cpp \ graphwidget.cpp \ node.cpp \ - edge.cpp \ - systemtray.cpp + edge.cpp HEADERS += mainwindow.h \ aboutdialog.h \ graphwidget.h \ node.h \ - edge.h \ - systemtray.h + edge.h FORMS += mainwindow.ui \ aboutdialog.ui RESOURCES = qtmindmap.qrc + +TRANSLATIONS = qtmindmap_hu.ts + +CODECFORTR = UTF-8 diff --git a/qtmindmap_hu.ts b/qtmindmap_hu.ts new file mode 100644 index 0000000..d5e87c9 --- /dev/null +++ b/qtmindmap_hu.ts @@ -0,0 +1,128 @@ + + + +UTF-8 + + AboutDialog + + + About QtMindMap + A QtMindMap-rol + + + + QtMindMap 0.1 + + + + + Mindmap software in QT + Agyterkep szoftver Qt-ben irva + + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Denes Matetelki <a href="mailto:denes.matetelki@gmail.com"><span style=" text-decoration: underline; color:#508ed8;">denes.matetelki@gmail.com</span></a></p></body></html> + + + + + MainWindow + + + QtMindMap + + + + + &File + Fajl + + + + &Help + Segitseg + + + + &New + Uj + + + + &Open + Megnyitas + + + + &Save + Mentes + + + + + &Quit + Kilepes + + + + &About QtMindMap + A QtMindMap-rol + + + + &Close + Bezaras + + + + Mi&nimize + &Talcara + + + + Ma&ximize + Teljes &meret + + + + &Restore + &Visszaallita + + + + QObject + + + QtMindMap Error + QtMindMap hiba + + + + I couldn't detect any system tray on this system. + Nem talalhato talca a jelenlegi rendszerben. + + + + SystemTray + + Mi&nimize + &Talcara + + + Ma&ximize + Teljes &meret + + + &Restore + &Visszaallita + + + &Quit + &Kilepes + + + diff --git a/systemtray.cpp b/systemtray.cpp deleted file mode 100644 index db48d98..0000000 --- a/systemtray.cpp +++ /dev/null @@ -1,41 +0,0 @@ -#include "systemtray.h" - - -#include -//#include -//#include - -SystemTray::SystemTray(MainWindow* parent) - : QSystemTrayIcon(parent), - mainWindow(parent) -{ - // QSystemTrayIcon *trayIcon; - - - minimizeAction = new QAction(tr("Mi&nimize"), this); - connect(minimizeAction, SIGNAL(triggered()), parent, SLOT(hide())); - - maximizeAction = new QAction(tr("Ma&ximize"), this); - connect(maximizeAction, SIGNAL(triggered()), parent, SLOT(showMaximized())); - - restoreAction = new QAction(tr("&Restore"), this); - connect(restoreAction, SIGNAL(triggered()), parent, SLOT(showNormal())); - - quitAction = new QAction(tr("&Quit"), this); - connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); - - /// @BUG shall pass this as parent - trayIconMenu = new QMenu(0); - trayIconMenu->addAction(minimizeAction); - trayIconMenu->addAction(maximizeAction); - trayIconMenu->addAction(restoreAction); - trayIconMenu->addSeparator(); - trayIconMenu->addAction(quitAction); - -// trayIcon = new QSystemTrayIcon(this); -// trayIcon->setContextMenu(trayIconMenu); - setContextMenu(trayIconMenu); - - icon = new QIcon(":/heart.svg"); - setIcon(QIcon(":/heart.svg")); -} diff --git a/systemtray.h b/systemtray.h deleted file mode 100644 index fe697fc..0000000 --- a/systemtray.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef SYSTEMTRAY_H -#define SYSTEMTRAY_H - -#include -#include "mainwindow.h" - -class SystemTray : public QSystemTrayIcon -{ -// Q_OBJECT - -public: - SystemTray(MainWindow *parent = 0); - -private: - MainWindow *mainWindow; - QMenu *trayIconMenu; - QAction *minimizeAction; - QAction *maximizeAction; - QAction *restoreAction; - QAction *quitAction; - QIcon *icon; -}; - -#endif // SYSTEMTRAY_H diff --git a/systemtray.ui b/systemtray.ui deleted file mode 100644 index 5e52dc7..0000000 --- a/systemtray.ui +++ /dev/null @@ -1,21 +0,0 @@ - - - - - SystemTray - - - - 0 - 0 - 400 - 300 - - - - Form - - - - -