You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

main.cpp 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include "mainwidget.h"
  2. #include <QApplication>
  3. #include <QDebug>
  4. int usage()
  5. {
  6. qDebug() << "Usage: " << QFile(qApp->arguments().at(0)).fileName().toStdString().c_str()
  7. << " ([--position=X-Y] [--size=WIDTH-HEIGHT] [--onLostFocus=(quit|ignore)]) | (--help|-h)";
  8. qDebug() << "--size: WIDTH >= 300 && HEIGHT >= 210";
  9. return 64;
  10. }
  11. int main(int argc, char *argv[])
  12. {
  13. QApplication a(argc, argv);
  14. MainWidget w;
  15. QStringList args = qApp->arguments();
  16. QRegExp reg_geo("--(position|size)=([0-9]+)\\-([0-9]+)");
  17. QRegExp reg_focus("--onLostFocus=(quit|ignore)");
  18. for (int i = 1; i < args.size(); ++i)
  19. {
  20. QString arg = args.at(i);
  21. if (arg.contains(reg_geo))
  22. {
  23. int x = reg_geo.cap(2).toInt();
  24. int y = reg_geo.cap(3).toInt();
  25. if (reg_geo.cap(1) == "position")
  26. {
  27. qDebug() << "Moving to" << x << y;
  28. w.move(x, y);
  29. }
  30. else
  31. {
  32. if (x < 300)
  33. {
  34. qDebug() << "WIDTH < 300:" << x;
  35. return usage();
  36. }
  37. if (y < 210)
  38. {
  39. qDebug() << "HEIGHT < 210:" << y;
  40. return usage();
  41. }
  42. qDebug() << "Resizing to" << x << y;
  43. w.resize(x, y);
  44. }
  45. }
  46. else if (arg.contains(reg_focus))
  47. w.setExitOnLostFocus(reg_focus.cap(1) == "quit");
  48. else if (arg == "--help" || arg == "-h")
  49. return usage();
  50. else
  51. {
  52. qWarning() << "Invalid argument:" << arg;
  53. return usage();
  54. }
  55. }
  56. qDebug() << "Geometry:" << w.geometry();
  57. w.exec();
  58. return 0;
  59. }