1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- #include "mainwidget.h"
- #include <QApplication>
- #include <QDebug>
-
- int usage()
- {
- qDebug() << "Usage: " << QFile(qApp->arguments().at(0)).fileName().toStdString().c_str()
- << " ([--position=X-Y] [--size=WIDTH-HEIGHT] [--onLostFocus=(quit|ignore)]) | (--help|-h)";
- qDebug() << "--size: WIDTH >= 300 && HEIGHT >= 210";
- return 64;
- }
-
- int main(int argc, char *argv[])
- {
- QApplication a(argc, argv);
- MainWidget w;
- QStringList args = qApp->arguments();
- QRegExp reg_geo("--(position|size)=([0-9]+)\\-([0-9]+)");
- QRegExp reg_focus("--onLostFocus=(quit|ignore)");
- for (int i = 1; i < args.size(); ++i)
- {
- QString arg = args.at(i);
- if (arg.contains(reg_geo))
- {
- int x = reg_geo.cap(2).toInt();
- int y = reg_geo.cap(3).toInt();
- if (reg_geo.cap(1) == "position")
- {
- qDebug() << "Moving to" << x << y;
- w.move(x, y);
- }
- else
- {
- if (x < 300)
- {
- qDebug() << "WIDTH < 300:" << x;
- return usage();
- }
- if (y < 210)
- {
- qDebug() << "HEIGHT < 210:" << y;
- return usage();
- }
- qDebug() << "Resizing to" << x << y;
- w.resize(x, y);
- }
- }
- else if (arg.contains(reg_focus))
- w.setExitOnLostFocus(reg_focus.cap(1) == "quit");
- else if (arg == "--help" || arg == "-h")
- return usage();
- else
- {
- qWarning() << "Invalid argument:" << arg;
- return usage();
- }
- }
- qDebug() << "Geometry:" << w.geometry();
- w.show();
-
- return a.exec();
- }
|