argumentparser is now a new class. node cannot be moved from scene (temp fix)

master
Denes Matetelki 14 years ago
parent da0ebc6180
commit 28528963a8

@ -0,0 +1,106 @@
#include "argumentparser.h"
#include <QApplication>
#include <QStringList>
#include <QFileInfo>
#include <QDebug>
#include <iostream>
ArgumentParser::ArgumentParser(QObject *parent) :
QObject(parent),
m_isSystemTray(false),
m_isShowMinimized(false),
m_filePath()
{
qDebug() << __PRETTY_FUNCTION__;
}
void ArgumentParser::printUsage()
{
qDebug() << __PRETTY_FUNCTION__;
std::cout << tr("Usage: ").toStdString() << "qtmindmap [OPTION][FILE]" << std::endl
<< tr("Mindmap program in QT").toStdString() << std::endl
<< std::endl
<< tr("Options:").toStdString() << std::endl
<< "-h, --help\t\t" << tr("Prints this help.").toStdString() << std::endl
<< "-t, --tray\t\t" << tr("Starts application in system tray.").toStdString() << std::endl
<< "-s, --show-minimized\t" << tr("Hide main window, just show systray icon.").toStdString() << std::endl
<< std::endl
<< tr("Report bugs to: ").toStdString() << "denes.matetelki@gmail.com" << std::endl;
}
bool ArgumentParser::parseCmdLineArgs(bool &successful)
{
qDebug() << __PRETTY_FUNCTION__;
QStringList cmdlineArgs = QCoreApplication::arguments();
cmdlineArgs.removeFirst();
QRegExp help("^-(h|-help)$");
if (!cmdlineArgs.filter(help).isEmpty())
{
printUsage();
successful = true;
return false;
}
QRegExp tray("^-(t|-tray)$");
if (!cmdlineArgs.filter(tray).isEmpty()) m_isSystemTray = true;
QRegExp minimized("^-(s|-show-minimized)$");
if (!cmdlineArgs.filter(minimized).isEmpty()) m_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)
{
std::cerr << tr("Unkown options: ").toStdString() << others.join(" ").toStdString() << std::endl;
printUsage();
successful = false;
return false;
}
if (others.size()==1)
{
if (others.first().at(0)=='-')
{
successful = false;
return false;
}
/// @note filecheck shall be done elsewhere?
m_filePath = others.first();
QFileInfo fileInfo(m_filePath);
if (!fileInfo.exists())
{
std::cerr << tr("File: ").toStdString() << m_filePath.toStdString() << tr(" does not exists.").toStdString() << std::endl;
successful = false;
return false;
}
if (!fileInfo.isFile())
{
std::cerr << tr("File: ").toStdString() << m_filePath.toStdString() << tr(" is not a file.").toStdString() << std::endl;
successful = false;
return false;
}
if (!fileInfo.isReadable())
{
std::cerr << tr("File: ").toStdString() << m_filePath.toStdString() << tr(" is not readable.").toStdString() << std::endl;
successful = false;
return false;
}
if (!fileInfo.isWritable())
{
std::cout << tr("File: ").toStdString() << m_filePath.toStdString() << tr(" is not writeable.").toStdString() << std::endl;
}
}
return true;
}

@ -0,0 +1,34 @@
#ifndef ARGUMENTPARSER_H
#define ARGUMENTPARSER_H
#include <QObject>
class ArgumentParser : public QObject
{
Q_OBJECT
public:
explicit ArgumentParser(QObject *parent = 0);
/***
* @param successful is true is the program needs to stop but its not an error.
* @return true is program can continue
*/
bool parseCmdLineArgs(bool &successful);
bool isSystemTray() { return m_isSystemTray; }
bool isShowMinimized() { return m_isShowMinimized; }
QString filePath() { return m_filePath; }
private:
void printUsage();
bool m_isSystemTray;
bool m_isShowMinimized;
QString m_filePath;
};
#endif // ARGUMENTPARSER_H

@ -59,22 +59,14 @@ void Edge::adjust()
if (!m_sourceNode || !m_destNode) if (!m_sourceNode || !m_destNode)
return; return;
prepareGeometryChange(); prepareGeometryChange();
QLineF line(mapFromItem(m_sourceNode, 0, 0) + m_sourceNode->boundingRect().center(), QLineF line(mapFromItem(m_sourceNode, 0, 0) + m_sourceNode->boundingRect().center(),
mapFromItem(m_destNode, 0, 0) + m_destNode->boundingRect().center()); mapFromItem(m_destNode, 0, 0) + m_destNode->boundingRect().center());
qreal length = line.length();
if (length > qreal(20.)) {
QPointF sourceOffset(firstNotContainedPoint(line,m_sourceNode->sceneBoundingRect()));
QPointF destOffset(firstNotContainedPoint(line,m_destNode->sceneBoundingRect(),true));
m_sourcePoint = sourceOffset; if (line.length() > qreal(20.)) {
m_destPoint = destOffset; m_sourcePoint = firstNotContainedPoint(line,m_sourceNode->sceneBoundingRect());
m_destPoint = firstNotContainedPoint(line,m_destNode->sceneBoundingRect(),true);
} else { } else {
m_sourcePoint = m_destPoint = line.p1(); m_sourcePoint = m_destPoint = line.p1();
} }

@ -15,8 +15,8 @@ public:
void adjust(); void adjust();
enum { Type = UserType + 2 }; // enum { Type = UserType + 2 };
int type() const { return Type; } // int type() const { return Type; }
protected: protected:
QRectF boundingRect() const; QRectF boundingRect() const;

@ -8,50 +8,10 @@
#include "mainwindow.h" #include "mainwindow.h"
#include "systemtray.h" #include "systemtray.h"
#include "argumentparser.h"
void printUsage()
{
std::cout << "Usage: qtmindmap [OPTION][FILE]" << std::endl
<< "Mindmap program in QT" << std::endl
<< std::endl
<< "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,
bool &isShowMinimized,
QString &filePath)
{
QStringList cmdlineArgs = QCoreApplication::arguments();
cmdlineArgs.removeFirst();
QRegExp help("^-(h|-help)$");
if (!cmdlineArgs.filter(help).isEmpty()) return false;
QRegExp tray("^-(t|-tray)$");
if (!cmdlineArgs.filter(tray).isEmpty()) isSystemTray = true;
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;
if (others.size()==1) filePath = others.first();
return true;
}
int main(int argc, char *argv[]) int main(int argc, char *argv[])
@ -65,7 +25,7 @@ int main(int argc, char *argv[])
QTranslator translator; QTranslator translator;
if (!translator.load(QString("qtmindmap_") + locale)) if (!translator.load(QString("qtmindmap_") + locale))
{ {
std::cout << "No translation file for locale: " << locale.toStdString() << std::endl; std::cerr << "No translation file for locale: " << locale.toStdString() << std::endl;
} }
else else
{ {
@ -73,19 +33,17 @@ int main(int argc, char *argv[])
} }
// parse args // parse args
bool isSystemTray(false); ArgumentParser argParser;
bool isShowMinimized(false); bool success;
QString filePath; if (!argParser.parseCmdLineArgs(success))
if (!parseCmdLineArgs(isSystemTray,isShowMinimized,filePath))
{ {
printUsage(); return success ? EXIT_SUCCESS : EXIT_FAILURE;
return EXIT_FAILURE;
} }
// system tray? // system tray?
MainWindow w; MainWindow w;
SystemTray systemtray(&w); SystemTray systemtray(&w);
if (isSystemTray or isShowMinimized) if (argParser.isSystemTray() or argParser.isShowMinimized())
{ {
if (!QSystemTrayIcon::isSystemTrayAvailable()) if (!QSystemTrayIcon::isSystemTrayAvailable())
{ {
@ -95,11 +53,10 @@ int main(int argc, char *argv[])
return EXIT_FAILURE; return EXIT_FAILURE;
} }
QApplication::setQuitOnLastWindowClosed(false); QApplication::setQuitOnLastWindowClosed(false);
// w.showSysTray();
systemtray.setup(); systemtray.setup();
systemtray.show(); systemtray.show();
} }
if (!isShowMinimized) w.show(); if (!argParser.isShowMinimized()) w.show();
return a.exec(); return a.exec();
} }

@ -107,7 +107,7 @@
<string>Export</string> <string>Export</string>
</property> </property>
<property name="shortcut"> <property name="shortcut">
<string>Ctrl+X</string> <string notr="true">Ctrl+X</string>
</property> </property>
</action> </action>
</widget> </widget>

@ -3,6 +3,7 @@
#include <QPainter> #include <QPainter>
#include <QStyleOption> #include <QStyleOption>
#include <QDebug> #include <QDebug>
#include <QGraphicsSceneMouseEvent>
Node::Node(GraphWidget *parent) : m_graph(parent) Node::Node(GraphWidget *parent) : m_graph(parent)
{ {
@ -35,8 +36,6 @@ QVariant Node::itemChange(GraphicsItemChange change, const QVariant &value)
switch (change) { switch (change) {
case ItemPositionHasChanged: case ItemPositionHasChanged:
// if ()
foreach (Edge *edge, m_edgeList) edge->adjust(); foreach (Edge *edge, m_edgeList) edge->adjust();
break; break;
default: default:
@ -50,6 +49,8 @@ void Node::mousePressEvent(QGraphicsSceneMouseEvent *event)
{ {
qDebug() << __PRETTY_FUNCTION__; qDebug() << __PRETTY_FUNCTION__;
prevpt = event->pos();
update(); update();
QGraphicsTextItem::mousePressEvent(event); QGraphicsTextItem::mousePressEvent(event);
} }
@ -58,10 +59,21 @@ void Node::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{ {
qDebug() << __PRETTY_FUNCTION__; qDebug() << __PRETTY_FUNCTION__;
if (!scene()->sceneRect().contains(sceneBoundingRect()))
{
setPos(prevpt);
}
update(); update();
QGraphicsTextItem::mouseReleaseEvent(event); QGraphicsTextItem::mouseReleaseEvent(event);
} }
void Node::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
qDebug() << __PRETTY_FUNCTION__;
QGraphicsTextItem::mouseMoveEvent(event);
}
void Node::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *w) void Node::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *w)
{ {
@ -73,4 +85,6 @@ void Node::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWid
painter->drawRect(QRect(boundingRect().topLeft().toPoint(), painter->drawRect(QRect(boundingRect().topLeft().toPoint(),
boundingRect().bottomRight().toPoint() - boundingRect().bottomRight().toPoint() -
QPoint(1,1))); QPoint(1,1)));
prevpt = pos();
} }

@ -20,12 +20,14 @@ protected:
QVariant itemChange(GraphicsItemChange change, const QVariant &value); QVariant itemChange(GraphicsItemChange change, const QVariant &value);
void mousePressEvent(QGraphicsSceneMouseEvent *event); void mousePressEvent(QGraphicsSceneMouseEvent *event);
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
private: private:
QList<Edge *> m_edgeList; QList<Edge *> m_edgeList;
GraphWidget *m_graph; GraphWidget *m_graph;
QPointF prevpt;
}; };
#endif // NODE_H #endif // NODE_H

@ -16,14 +16,16 @@ SOURCES += main.cpp\
graphwidget.cpp \ graphwidget.cpp \
node.cpp \ node.cpp \
edge.cpp \ edge.cpp \
systemtray.cpp systemtray.cpp \
argumentparser.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 systemtray.h \
argumentparser.h
FORMS += mainwindow.ui \ FORMS += mainwindow.ui \
aboutdialog.ui aboutdialog.ui

@ -182,7 +182,7 @@
<value key="Qt4ProjectManager.Qt4RunConfiguration.CommandLineArguments" type="QString"></value> <value key="Qt4ProjectManager.Qt4RunConfiguration.CommandLineArguments" type="QString"></value>
<value key="Qt4ProjectManager.Qt4RunConfiguration.ProFile" type="QString">qtmindmap.pro</value> <value key="Qt4ProjectManager.Qt4RunConfiguration.ProFile" type="QString">qtmindmap.pro</value>
<value key="Qt4ProjectManager.Qt4RunConfiguration.UseDyldImageSuffix" type="bool">false</value> <value key="Qt4ProjectManager.Qt4RunConfiguration.UseDyldImageSuffix" type="bool">false</value>
<value key="Qt4ProjectManager.Qt4RunConfiguration.UseTerminal" type="bool">false</value> <value key="Qt4ProjectManager.Qt4RunConfiguration.UseTerminal" type="bool">true</value>
<valuelist key="Qt4ProjectManager.Qt4RunConfiguration.UserEnvironmentChanges" type="QVariantList"/> <valuelist key="Qt4ProjectManager.Qt4RunConfiguration.UserEnvironmentChanges" type="QVariantList"/>
<value key="Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory" type="QString"></value> <value key="Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory" type="QString"></value>
<value key="RunConfiguration.QmlDebugServerPort" type="uint">3768</value> <value key="RunConfiguration.QmlDebugServerPort" type="uint">3768</value>

@ -12,7 +12,7 @@
<message> <message>
<location filename="aboutdialog.ui" line="54"/> <location filename="aboutdialog.ui" line="54"/>
<source>QtMindMap 0.1</source> <source>QtMindMap 0.1</source>
<translation type="unfinished"></translation> <translation type="unfinished">QtMindMap 0.1</translation>
</message> </message>
<message> <message>
<location filename="aboutdialog.ui" line="67"/> <location filename="aboutdialog.ui" line="67"/>
@ -29,12 +29,83 @@ p, li { white-space: pre-wrap; }
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
</context> </context>
<context>
<name>ArgumentParser</name>
<message>
<location filename="argumentparser.cpp" line="24"/>
<source>Usage: </source>
<translation type="unfinished">Hasznalat: </translation>
</message>
<message>
<location filename="argumentparser.cpp" line="25"/>
<source>Mindmap program in QT</source>
<translation type="unfinished">Agyterkep program QT-ben irva</translation>
</message>
<message>
<location filename="argumentparser.cpp" line="27"/>
<source>Options:</source>
<translation type="unfinished">Opciok:</translation>
</message>
<message>
<location filename="argumentparser.cpp" line="28"/>
<source>Prints this help.</source>
<translation type="unfinished">Kiirja ezt a szoveget.</translation>
</message>
<message>
<location filename="argumentparser.cpp" line="29"/>
<source>Starts application in system tray.</source>
<translation type="unfinished">A programot blablabla-ban inditja.</translation>
</message>
<message>
<location filename="argumentparser.cpp" line="30"/>
<source>Hide main window, just show systray icon.</source>
<translation type="unfinished">Nem mutatja a foablakot, csak a balbalba-t.</translation>
</message>
<message>
<location filename="argumentparser.cpp" line="32"/>
<source>Report bugs to: </source>
<translation type="unfinished">Ide jelentsd a bugokat: </translation>
</message>
<message>
<location filename="argumentparser.cpp" line="65"/>
<source>Unkown options: </source>
<translation type="unfinished">Ismeretlen opciok:</translation>
</message>
<message>
<location filename="argumentparser.cpp" line="84"/>
<location filename="argumentparser.cpp" line="90"/>
<location filename="argumentparser.cpp" line="96"/>
<location filename="argumentparser.cpp" line="102"/>
<source>File: </source>
<translation type="unfinished">Fajl: </translation>
</message>
<message>
<location filename="argumentparser.cpp" line="84"/>
<source> does not exists.</source>
<translation type="unfinished"> nem letezik.</translation>
</message>
<message>
<location filename="argumentparser.cpp" line="90"/>
<source> is not a file.</source>
<translation type="unfinished"> nem egy fajl.</translation>
</message>
<message>
<location filename="argumentparser.cpp" line="96"/>
<source> is not readable.</source>
<translation type="unfinished"> nem olvashato.</translation>
</message>
<message>
<location filename="argumentparser.cpp" line="102"/>
<source> is not writeable.</source>
<translation type="unfinished"> nem irhato.</translation>
</message>
</context>
<context> <context>
<name>MainWindow</name> <name>MainWindow</name>
<message> <message>
<location filename="mainwindow.ui" line="14"/> <location filename="mainwindow.ui" line="14"/>
<source>QtMindMap</source> <source>QtMindMap</source>
<translation type="unfinished"></translation> <translation type="unfinished">QtMindMap</translation>
</message> </message>
<message> <message>
<location filename="mainwindow.ui" line="28"/> <location filename="mainwindow.ui" line="28"/>
@ -79,43 +150,38 @@ p, li { white-space: pre-wrap; }
<message> <message>
<location filename="mainwindow.ui" line="104"/> <location filename="mainwindow.ui" line="104"/>
<source>E&amp;xport</source> <source>E&amp;xport</source>
<translation type="unfinished"></translation> <translation type="unfinished">E&amp;xportalas</translation>
</message> </message>
<message> <message>
<location filename="mainwindow.ui" line="107"/> <location filename="mainwindow.ui" line="107"/>
<source>Export</source> <source>Export</source>
<translation type="unfinished"></translation> <translation type="unfinished">Exportalas</translation>
</message>
<message>
<location filename="mainwindow.ui" line="110"/>
<source>Ctrl+X</source>
<translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="71"/> <location filename="mainwindow.cpp" line="71"/>
<source>Export MindMap to image</source> <source>Export MindMap to image</source>
<translation type="unfinished"></translation> <translation type="unfinished">Az agyterkep kepkent exportalasa</translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="73"/> <location filename="mainwindow.cpp" line="73"/>
<source>PNG image file (*.png)</source> <source>PNG image file (*.png)</source>
<translation type="unfinished"></translation> <translation type="unfinished">PNG kep file (*.png)</translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="99"/> <location filename="mainwindow.cpp" line="99"/>
<source>MindMap exported as </source> <source>MindMap exported as </source>
<translation type="unfinished"></translation> <translation type="unfinished">Az agyterkep exportalva lett, mint</translation>
</message> </message>
</context> </context>
<context> <context>
<name>QObject</name> <name>QObject</name>
<message> <message>
<location filename="main.cpp" line="93"/> <location filename="main.cpp" line="51"/>
<source>QtMindMap Error</source> <source>QtMindMap Error</source>
<translation type="unfinished">QtMindMap hiba</translation> <translation type="unfinished">QtMindMap hiba</translation>
</message> </message>
<message> <message>
<location filename="main.cpp" line="94"/> <location filename="main.cpp" line="52"/>
<source>I couldn&apos;t detect any system tray on this system.</source> <source>I couldn&apos;t detect any system tray on this system.</source>
<translation type="unfinished">Nem talalhato talca a jelenlegi rendszerben.</translation> <translation type="unfinished">Nem talalhato talca a jelenlegi rendszerben.</translation>
</message> </message>

Loading…
Cancel
Save