export as png, translation

master
Denes Matetelki 14 years ago
parent d57ec2a21f
commit 6018bc6436

@ -1,7 +1,6 @@
#include "aboutdialog.h" #include "aboutdialog.h"
#include "ui_aboutdialog.h" #include "ui_aboutdialog.h"
//#include <QLayout>
AboutDialog::AboutDialog(QWidget *parent) : AboutDialog::AboutDialog(QWidget *parent) :
QDialog(parent), QDialog(parent),

@ -59,6 +59,10 @@ GraphWidget::GraphWidget(QWidget *parent)
activeNode->setFocus(); activeNode->setFocus();
} }
QGraphicsScene *GraphWidget::getScene()
{
return scene;
}
void GraphWidget::keyPressEvent(QKeyEvent *event) void GraphWidget::keyPressEvent(QKeyEvent *event)
{ {

@ -7,7 +7,6 @@
#include "node.h" #include "node.h"
//class Node;
class GraphWidget : public QGraphicsView class GraphWidget : public QGraphicsView
{ {
@ -16,9 +15,9 @@ class GraphWidget : public QGraphicsView
public: public:
GraphWidget(QWidget *parent = 0); GraphWidget(QWidget *parent = 0);
QGraphicsScene *getScene();
protected: protected:
// void drawBackground(QPainter *painter, const QRectF &rect);
void keyPressEvent(QKeyEvent *event); void keyPressEvent(QKeyEvent *event);
void wheelEvent(QWheelEvent *event); void wheelEvent(QWheelEvent *event);
void scaleView(qreal scaleFactor); void scaleView(qreal scaleFactor);

@ -2,12 +2,11 @@
#include <iostream> // cout #include <iostream> // cout
#include <QtGui> #include <QtGui>
//#include <QtGui/QApplication>
#include <QDebug> #include <QDebug>
#include <QRegExp> #include <QRegExp>
#include <QTranslator>
#include "mainwindow.h" #include "mainwindow.h"
#include "systemtray.h"
void printUsage() void printUsage()
@ -18,12 +17,15 @@ void printUsage()
<< "Options:" << std::endl << "Options:" << std::endl
<< "-h, --help\tPrints this help." << std::endl << "-h, --help\tPrints this help." << std::endl
<< "-t, --tray\tStarts application in system tray." << 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 << std::endl
<< "Report bugs to: denes.matetelki@gmail.com" << 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(); QStringList cmdlineArgs = QCoreApplication::arguments();
cmdlineArgs.removeFirst(); cmdlineArgs.removeFirst();
@ -34,7 +36,13 @@ bool parseCmdLineArgs(bool &isSystemTray, QString &filePath)
QRegExp tray("^-(t|-tray)$"); QRegExp tray("^-(t|-tray)$");
if (!cmdlineArgs.filter(tray).isEmpty()) isSystemTray = true; 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; QStringList others;
foreach (QString arg, cmdlineArgs) if (all.indexIn(arg)==-1) others.append(arg); foreach (QString arg, cmdlineArgs) if (all.indexIn(arg)==-1) others.append(arg);
if (others.size() > 1) return false; if (others.size() > 1) return false;
@ -51,32 +59,43 @@ int main(int argc, char *argv[])
QApplication a(argc, 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 isSystemTray(false);
bool isShowMinimized(false);
QString filePath; QString filePath;
if (!parseCmdLineArgs(isSystemTray,filePath)) if (!parseCmdLineArgs(isSystemTray,isShowMinimized,filePath))
{ {
printUsage(); printUsage();
return EXIT_FAILURE; return EXIT_FAILURE;
} }
MainWindow w; // system tray?
SystemTray *systemTray; MainWindow w(isSystemTray or isShowMinimized);
isSystemTray = true; if (isSystemTray or isShowMinimized)
if (isSystemTray)
{ {
if (!QSystemTrayIcon::isSystemTrayAvailable()) if (!QSystemTrayIcon::isSystemTrayAvailable())
{ {
QMessageBox::critical(0, QMessageBox::critical(0,
QObject::tr("Systray"), QObject::tr("QtMindMap Error"),
QObject::tr("I couldn't detect any system tray on this system.")); QObject::tr("I couldn't detect any system tray on this system."));
return EXIT_FAILURE; return EXIT_FAILURE;
} }
QApplication::setQuitOnLastWindowClosed(false); QApplication::setQuitOnLastWindowClosed(false);
systemTray = new SystemTray(&w); w.showSysTray();
systemTray->show();
} }
if (!isShowMinimized) w.show();
w.show();
return a.exec(); return a.exec();
} }

@ -4,8 +4,10 @@
#include <QDebug> #include <QDebug>
//#include <QLayout> //#include <QLayout>
#include <QFileDialog>
MainWindow::MainWindow(QWidget *parent) :
MainWindow::MainWindow(bool isSystemtray, QWidget *parent) :
QMainWindow(parent), QMainWindow(parent),
ui(new Ui::MainWindow), ui(new Ui::MainWindow),
aboutDialog(0) aboutDialog(0)
@ -16,14 +18,16 @@ MainWindow::MainWindow(QWidget *parent) :
connect(ui->actionOpen, SIGNAL(activated()), this, SLOT(klakk())); connect(ui->actionOpen, SIGNAL(activated()), this, SLOT(klakk()));
connect(ui->actionSave, SIGNAL(activated()), this, SLOT(klakk())); connect(ui->actionSave, SIGNAL(activated()), this, SLOT(klakk()));
connect(ui->actionClose, 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(), connect(ui->actionQuit, SIGNAL(activated()), QApplication::instance(),
SLOT(closeAllWindows())); SLOT(quit()));
connect(ui->actionAbout_QtMindMap, SIGNAL(activated()), this, connect(ui->actionAbout_QtMindMap, SIGNAL(activated()), this,
SLOT(about())); SLOT(about()));
graphicsView = new GraphWidget(ui->centralWidget); graphicsView = new GraphWidget(ui->centralWidget);
setCentralWidget(graphicsView); setCentralWidget(graphicsView);
if (isSystemtray) setupSystemTray();
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()
@ -38,6 +42,66 @@ void MainWindow::klakk()
qDebug() << __PRETTY_FUNCTION__; 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() void MainWindow::about()
{ {
qDebug() << __PRETTY_FUNCTION__; qDebug() << __PRETTY_FUNCTION__;
@ -57,4 +121,7 @@ void MainWindow::aboutDestroyed()
} }
void MainWindow::showSysTray()
{
systemTrayIcon->show();
}

@ -2,7 +2,7 @@
#define MAINWINDOW_H #define MAINWINDOW_H
#include <QMainWindow> #include <QMainWindow>
//#include <QPointer> #include <QSystemTrayIcon>
#include "aboutdialog.h" #include "aboutdialog.h"
#include "graphwidget.h" #include "graphwidget.h"
@ -16,19 +16,32 @@ class MainWindow : public QMainWindow
Q_OBJECT Q_OBJECT
public: public:
explicit MainWindow(QWidget *parent = 0); explicit MainWindow(bool isSystemTray = false, QWidget *parent = 0);
~MainWindow(); ~MainWindow();
void showSysTray();
public slots: public slots:
void klakk(void); void klakk();
void exportScene();
void about(); void about();
void aboutDestroyed(); void aboutDestroyed();
private: private:
void setupSystemTray();
Ui::MainWindow *ui; Ui::MainWindow *ui;
AboutDialog* aboutDialog; AboutDialog* aboutDialog;
// QPointer<AboutDialog> aboutDialog;
GraphWidget *graphicsView; GraphWidget *graphicsView;
QSystemTrayIcon *systemTrayIcon;
MainWindow *mainWindow;
QMenu *trayIconMenu;
QAction *minimizeAction;
QAction *maximizeAction;
QAction *restoreAction;
QAction *quitAction;
QIcon *icon;
}; };
#endif // MAINWINDOW_H #endif // MAINWINDOW_H

@ -32,6 +32,8 @@
<addaction name="actionSave"/> <addaction name="actionSave"/>
<addaction name="actionClose"/> <addaction name="actionClose"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="actionExport"/>
<addaction name="separator"/>
<addaction name="actionQuit"/> <addaction name="actionQuit"/>
</widget> </widget>
<widget class="QMenu" name="menuHelp"> <widget class="QMenu" name="menuHelp">
@ -57,7 +59,7 @@
<string>&amp;New</string> <string>&amp;New</string>
</property> </property>
<property name="shortcut"> <property name="shortcut">
<string>Ctrl+N</string> <string notr="true">Ctrl+N</string>
</property> </property>
</action> </action>
<action name="actionOpen"> <action name="actionOpen">
@ -65,7 +67,7 @@
<string>&amp;Open</string> <string>&amp;Open</string>
</property> </property>
<property name="shortcut"> <property name="shortcut">
<string>Ctrl+O</string> <string notr="true">Ctrl+O</string>
</property> </property>
</action> </action>
<action name="actionSave"> <action name="actionSave">
@ -73,7 +75,7 @@
<string>&amp;Save</string> <string>&amp;Save</string>
</property> </property>
<property name="shortcut"> <property name="shortcut">
<string>Ctrl+S</string> <string notr="true">Ctrl+S</string>
</property> </property>
</action> </action>
<action name="actionQuit"> <action name="actionQuit">
@ -81,7 +83,7 @@
<string>&amp;Quit</string> <string>&amp;Quit</string>
</property> </property>
<property name="shortcut"> <property name="shortcut">
<string>Ctrl+Q</string> <string notr="true">Ctrl+Q</string>
</property> </property>
</action> </action>
<action name="actionAbout_QtMindMap"> <action name="actionAbout_QtMindMap">
@ -94,7 +96,18 @@
<string>&amp;Close</string> <string>&amp;Close</string>
</property> </property>
<property name="shortcut"> <property name="shortcut">
<string>Ctrl+W</string> <string notr="true">Ctrl+W</string>
</property>
</action>
<action name="actionExport">
<property name="text">
<string>E&amp;xport</string>
</property>
<property name="toolTip">
<string>Export</string>
</property>
<property name="shortcut">
<string>Ctrl+X</string>
</property> </property>
</action> </action>
</widget> </widget>

@ -15,17 +15,19 @@ SOURCES += main.cpp\
aboutdialog.cpp \ aboutdialog.cpp \
graphwidget.cpp \ graphwidget.cpp \
node.cpp \ node.cpp \
edge.cpp \ edge.cpp
systemtray.cpp
HEADERS += mainwindow.h \ HEADERS += mainwindow.h \
aboutdialog.h \ aboutdialog.h \
graphwidget.h \ graphwidget.h \
node.h \ node.h \
edge.h \ edge.h
systemtray.h
FORMS += mainwindow.ui \ FORMS += mainwindow.ui \
aboutdialog.ui aboutdialog.ui
RESOURCES = qtmindmap.qrc RESOURCES = qtmindmap.qrc
TRANSLATIONS = qtmindmap_hu.ts
CODECFORTR = UTF-8

@ -0,0 +1,128 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.0" language="hu_HU">
<defaultcodec>UTF-8</defaultcodec>
<context>
<name>AboutDialog</name>
<message>
<location filename="aboutdialog.ui" line="23"/>
<source>About QtMindMap</source>
<translation type="unfinished">A QtMindMap-rol</translation>
</message>
<message>
<location filename="aboutdialog.ui" line="54"/>
<source>QtMindMap 0.1</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="aboutdialog.ui" line="67"/>
<source>Mindmap software in QT</source>
<translation type="unfinished">Agyterkep szoftver Qt-ben irva</translation>
</message>
<message>
<location filename="aboutdialog.ui" line="80"/>
<source>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:&apos;Sans Serif&apos;; font-size:9pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Denes Matetelki &lt;a href=&quot;mailto:denes.matetelki@gmail.com&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#508ed8;&quot;&gt;denes.matetelki@gmail.com&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>MainWindow</name>
<message>
<location filename="mainwindow.ui" line="14"/>
<source>QtMindMap</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="mainwindow.ui" line="28"/>
<source>&amp;File</source>
<translation type="unfinished">Fajl</translation>
</message>
<message>
<location filename="mainwindow.ui" line="39"/>
<source>&amp;Help</source>
<translation type="unfinished">Segitseg</translation>
</message>
<message>
<location filename="mainwindow.ui" line="57"/>
<source>&amp;New</source>
<translation type="unfinished">Uj</translation>
</message>
<message>
<location filename="mainwindow.ui" line="65"/>
<source>&amp;Open</source>
<translation type="unfinished">Megnyitas</translation>
</message>
<message>
<location filename="mainwindow.ui" line="73"/>
<source>&amp;Save</source>
<translation type="unfinished">Mentes</translation>
</message>
<message>
<location filename="mainwindow.ui" line="81"/>
<location filename="mainwindow.cpp" line="40"/>
<source>&amp;Quit</source>
<translation type="unfinished">Kilepes</translation>
</message>
<message>
<location filename="mainwindow.ui" line="89"/>
<source>&amp;About QtMindMap</source>
<translation type="unfinished">A QtMindMap-rol</translation>
</message>
<message>
<location filename="mainwindow.ui" line="94"/>
<source>&amp;Close</source>
<translation type="unfinished">Bezaras</translation>
</message>
<message>
<location filename="mainwindow.cpp" line="31"/>
<source>Mi&amp;nimize</source>
<translation type="unfinished">&amp;Talcara</translation>
</message>
<message>
<location filename="mainwindow.cpp" line="34"/>
<source>Ma&amp;ximize</source>
<translation type="unfinished">Teljes &amp;meret</translation>
</message>
<message>
<location filename="mainwindow.cpp" line="37"/>
<source>&amp;Restore</source>
<translation type="unfinished">&amp;Visszaallita</translation>
</message>
</context>
<context>
<name>QObject</name>
<message>
<location filename="main.cpp" line="95"/>
<source>QtMindMap Error</source>
<translation type="unfinished">QtMindMap hiba</translation>
</message>
<message>
<location filename="main.cpp" line="96"/>
<source>I couldn&apos;t detect any system tray on this system.</source>
<translation type="unfinished">Nem talalhato talca a jelenlegi rendszerben.</translation>
</message>
</context>
<context>
<name>SystemTray</name>
<message>
<source>Mi&amp;nimize</source>
<translation type="obsolete">&amp;Talcara</translation>
</message>
<message>
<source>Ma&amp;ximize</source>
<translation type="obsolete">Teljes &amp;meret</translation>
</message>
<message>
<source>&amp;Restore</source>
<translation type="obsolete">&amp;Visszaallita</translation>
</message>
<message>
<source>&amp;Quit</source>
<translation type="obsolete">&amp;Kilepes</translation>
</message>
</context>
</TS>

@ -1,41 +0,0 @@
#include "systemtray.h"
#include <QtGui>
//#include <QAction>
//#include <QMenu>
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"));
}

@ -1,24 +0,0 @@
#ifndef SYSTEMTRAY_H
#define SYSTEMTRAY_H
#include <QSystemTrayIcon>
#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

@ -1,21 +0,0 @@
<ui version="4.0">
<author/>
<comment/>
<exportmacro/>
<class>SystemTray</class>
<widget class="QWidget" name="SystemTray">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
</widget>
<pixmapfunction/>
<connections/>
</ui>
Loading…
Cancel
Save