Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

main.cpp 1.7KB

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. if (x < 300)
  25. {
  26. qDebug() << "WIDTH < 300:" << x;
  27. return usage();
  28. }
  29. int y = reg_geo.cap(3).toInt();
  30. if (y < 210)
  31. {
  32. qDebug() << "HEIGHT < 210:" << y;
  33. return usage();
  34. }
  35. if (reg_geo.cap(1) == "position")
  36. {
  37. qDebug() << "Moving to" << x << y;
  38. w.move(x, y);
  39. }
  40. else
  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.show();
  58. return a.exec();
  59. }