Changeset c41ce0


Ignore:
Timestamp:
Aug 11, 2025, 5:43:56 PM (2 months ago)
Author:
Frederik Heber <frederik.heber@…>
Branches:
Candidate_v1.7.0, stable
Children:
641550
Parents:
6294b6
git-author:
Frederik Heber <frederik.heber@…> (05/03/24 15:25:52)
git-committer:
Frederik Heber <frederik.heber@…> (08/11/25 17:43:56)
Message:

Adds qt_size and qt_position arguments to control Qt window size.

  • override is only temporary and is not stored in QSettings.
  • this allows using these parameters in scripts to take screenshots in a reliable manner but retain the actual window size for other usages.
Location:
src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/UIElements/Qt4/QtMainWindow.cpp

    r6294b6 rc41ce0  
    158158  QSettings settings;
    159159  settings.beginGroup("MainWindow");
    160   resize(settings.value("size", QSize(400, 400)).toSize());
    161   move(settings.value("position", QPoint(200, 200)).toPoint());
     160  settingsSize = settings.value("size", QSize(400, 400)).toSize();
     161  settingsPosition = settings.value("position", QPoint(200, 200)).toPoint();
     162
     163  const QStringList args = QCoreApplication::arguments();
     164  LOG(2, "DEBUG: QApp's seen arguments are " << args.join(",").toStdString());
     165
     166  const int indexSize = args.indexOf(QString("--qt_size"));
     167  const int indexPosition = args.indexOf(QString("--qt_position"));
     168
     169  if ((indexSize == -1) || (indexPosition == -1)) {
     170    resize(settingsSize);
     171    move(settingsPosition);
     172  } else {
     173    // Take size and position from command-line values instead
     174    // NOTE: Qt 4.8's toInt() caps the second argument when it's below 1000 (yes, really!). Hence, we're using stoi()
     175    const QSize cmdlineSize = QSize(stoi(args[indexSize + 1].split(",")[0].toStdString()), stoi(args[indexSize + 1].split(",")[1].toStdString()));
     176    const QPoint cmdlinePosition = QPoint(stoi(args[indexPosition + 1].split(",")[0].toStdString()), stoi(args[indexPosition + 1].split(",")[1].toStdString()));
     177    LOG(2, "DEBUG: Using size and position from the command line: (" << cmdlineSize.width() << "," << cmdlineSize.height()
     178        << "), (" << cmdlinePosition.x() << "," << cmdlinePosition.y() << ")");
     179    resize(cmdlineSize);
     180    move(cmdlinePosition);
     181  }
    162182  if (settings.value("maximized", false).toBool())
    163183    showMaximized();
    164184  settings.endGroup();
     185  LOG(1, "INFO: Size and position is (" << size().width() << "," << size().height() << "), (" << pos().x() << "," << pos().y() << ")");
    165186
    166187  connect(glWorldView,SIGNAL(hoverChanged(const atomId_t)), infoBox,SLOT(atomHover(const atomId_t)));
     
    174195QtMainWindow::~QtMainWindow()
    175196{
     197  const QStringList args = QCoreApplication::arguments();
     198  const bool containsSize = args.contains(QString("--qt_size"));
     199  const bool containsPosition = args.contains(QString("--qt_position"));
     200
    176201  QSettings settings;
    177202  settings.beginGroup("MainWindow");
    178   settings.setValue("size", size());
    179   settings.setValue("position", pos());
     203  if (!containsSize || !containsPosition) {
     204    settings.setValue("size", size());
     205    settings.setValue("position", pos());
     206  } else {
     207    settings.setValue("size", settingsSize);
     208    settings.setValue("position", settingsPosition);
     209  }
    180210  settings.setValue("maximized", isMaximized());
    181211  settings.endGroup();
  • src/UIElements/Qt4/QtMainWindow.hpp

    r6294b6 rc41ce0  
    3939class QtToolBar;
    4040class QCloseEvent;
     41class QSize;
     42class QPoint;
    4143
    4244class QtObservedInstanceBoard;
     
    7375  QtLogBox *logBox;
    7476  QtLogBox *errorlogBox;
     77  //!> Used to store old settings value for window size on exit when overridden from command line
     78  QSize settingsSize;
     79  //!> Used to store old settings value for window position on exit when overridden from command line
     80  QPoint settingsPosition;
    7581
    7682  QtObservedInstanceBoard *InstanceBoard;
  • src/UIElements/Qt4/QtUIFactory.cpp

    r6294b6 rc41ce0  
    6060
    6161QtUIFactory::QtUIFactory(int _argc, char **_argv) :
    62     argc(1),
    63     argv(new char*[1]),
     62    argc(0),
     63    argv(NULL),
    6464    testlauncher_Interrupted(false),
    6565    testlauncher_thread(NULL)
     
    7878#ifdef HAVE_BOOST_THREAD_HPP
    7979    std::vector<std::string> scripts;
    80     scripts.reserve(_argc-1);
    81     for (int i=2;i<_argc;++i)
    82       scripts.push_back(std::string(_argv[i]));
     80    scripts.reserve(1);
     81    scripts.push_back(std::string(_argv[2]));
    8382
    8483    // check for line-by-line execution
     
    9291    std::cerr << "Boost::thread support missing! Cannot launch test scripts.\n";
    9392#endif
    94     // use fake commands to not pass test stuff
    95     const int length = strlen(_argv[0]);
    96     argv[0] = new char[length];
    97     strncpy(argv[0],_argv[0], length);
     93    // remove test options from command line arguments
     94    argc = _argc-2;
     95    argv = new char*[argc];
     96    int j = 0;
     97    for (int i=0;i<_argc;++i) {
     98      if ((i >= 1) && (i<3))
     99        continue;
     100      const int length = strlen(_argv[i]);
     101      argv[j] = new char[length];
     102      strncpy(argv[j],_argv[i], length);
     103      ++j;
     104    }
    98105    app = new QApplication(argc,argv);
    99106  } else {
    100     const int length = strlen(_argv[0]);
    101     argv[0] = new char[length];
    102     strncpy(argv[0],_argv[0], length);
     107    argc = _argc;
     108    argv = new char*[argc];
     109    for (int i=0;i<_argc;++i) {
     110      const int length = strlen(_argv[i]);
     111      argv[i] = new char[length];
     112      strncpy(argv[i],_argv[i], length);
     113    }
    103114    app = new QApplication(argc,argv);
    104115  }
     
    146157{
    147158  return (strncmp(_argument,"--test", 6) == 0);
     159}
     160
     161bool QtUIFactory::isGuiMode(const char *_argument)
     162{
     163  return (strncmp(_argument,"--qt_size", 9) == 0) || (strncmp(_argument,"--qt_position", 13) == 0);
    148164}
    149165
  • src/UIElements/Qt4/QtUIFactory.hpp

    r6294b6 rc41ce0  
    4646
    4747  static bool isTestMode(const char *_argument);
     48  static bool isGuiMode(const char *_argument);
    4849
    4950protected:
  • src/builder_init.cpp

    r6294b6 rc41ce0  
    140140#ifdef USE_GUI_QT
    141141      && !QtUIFactory::isTestMode(argv[1])
     142      && !QtUIFactory::isGuiMode(argv[1])
    142143#endif
    143144  ) {
Note: See TracChangeset for help on using the changeset viewer.