/[svn]/qsampler/trunk/src/qsamplerOptions.cpp
ViewVC logotype

Diff of /qsampler/trunk/src/qsamplerOptions.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2718 by capela, Thu Jan 22 19:01:32 2015 UTC revision 3796 by capela, Mon Jun 29 08:52:33 2020 UTC
# Line 1  Line 1 
1  // qsamplerOptions.cpp  // qsamplerOptions.cpp
2  //  //
3  /****************************************************************************  /****************************************************************************
4     Copyright (C) 2004-2015, rncbc aka Rui Nuno Capela. All rights reserved.     Copyright (C) 2004-2020, rncbc aka Rui Nuno Capela. All rights reserved.
5     Copyright (C) 2007,2015 Christian Schoenebeck     Copyright (C) 2007,2008,2015 Christian Schoenebeck
6    
7     This program is free software; you can redistribute it and/or     This program is free software; you can redistribute it and/or
8     modify it under the terms of the GNU General Public License     modify it under the terms of the GNU General Public License
# Line 27  Line 27 
27  #include <QTextStream>  #include <QTextStream>
28  #include <QComboBox>  #include <QComboBox>
29    
30    #include <QApplication>
31    
32    #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
33    #include <QDesktopWidget>
34    #endif
35    
36  #include <lscp/client.h>  #include <lscp/client.h>
37    
38  #ifdef CONFIG_LIBGIG  #ifdef CONFIG_LIBGIG
# Line 97  void Options::loadOptions (void) Line 103  void Options::loadOptions (void)
103          bMessagesLimit   = m_settings.value("/MessagesLimit", true).toBool();          bMessagesLimit   = m_settings.value("/MessagesLimit", true).toBool();
104          iMessagesLimitLines = m_settings.value("/MessagesLimitLines", 1000).toInt();          iMessagesLimitLines = m_settings.value("/MessagesLimitLines", 1000).toInt();
105          bConfirmRemove   = m_settings.value("/ConfirmRemove", true).toBool();          bConfirmRemove   = m_settings.value("/ConfirmRemove", true).toBool();
106            bConfirmReset    = m_settings.value("/ConfirmReset", true).toBool();
107            bConfirmRestart  = m_settings.value("/ConfirmRestart", true).toBool();
108            bConfirmError    = m_settings.value("/ConfirmError", true).toBool();
109          bKeepOnTop       = m_settings.value("/KeepOnTop", true).toBool();          bKeepOnTop       = m_settings.value("/KeepOnTop", true).toBool();
110          bStdoutCapture   = m_settings.value("/StdoutCapture", true).toBool();          bStdoutCapture   = m_settings.value("/StdoutCapture", true).toBool();
111          bCompletePath    = m_settings.value("/CompletePath", true).toBool();          bCompletePath    = m_settings.value("/CompletePath", true).toBool();
# Line 111  void Options::loadOptions (void) Line 120  void Options::loadOptions (void)
120  #endif  #endif
121          m_settings.endGroup();          m_settings.endGroup();
122    
123            // Load custom options...
124            m_settings.beginGroup("/Custom");
125            sCustomColorTheme = m_settings.value("/ColorTheme").toString();
126            sCustomStyleTheme = m_settings.value("/StyleTheme").toString();
127            m_settings.endGroup();
128    
129          // And go into view options group.          // And go into view options group.
130          m_settings.beginGroup("/View");          m_settings.beginGroup("/View");
131          bMenubar     = m_settings.value("/Menubar", true).toBool();          bMenubar     = m_settings.value("/Menubar", true).toBool();
# Line 159  void Options::saveOptions (void) Line 174  void Options::saveOptions (void)
174  {  {
175          // Make program version available in the future.          // Make program version available in the future.
176          m_settings.beginGroup("/Program");          m_settings.beginGroup("/Program");
177          m_settings.setValue("/Version", QSAMPLER_VERSION);          m_settings.setValue("/Version", CONFIG_BUILD_VERSION);
178          m_settings.endGroup();          m_settings.endGroup();
179    
180          // And go into general options group.          // And go into general options group.
# Line 192  void Options::saveOptions (void) Line 207  void Options::saveOptions (void)
207          m_settings.setValue("/MessagesLimit", bMessagesLimit);          m_settings.setValue("/MessagesLimit", bMessagesLimit);
208          m_settings.setValue("/MessagesLimitLines", iMessagesLimitLines);          m_settings.setValue("/MessagesLimitLines", iMessagesLimitLines);
209          m_settings.setValue("/ConfirmRemove", bConfirmRemove);          m_settings.setValue("/ConfirmRemove", bConfirmRemove);
210            m_settings.setValue("/ConfirmReset", bConfirmReset);
211            m_settings.setValue("/ConfirmRestart", bConfirmRestart);
212            m_settings.setValue("/ConfirmError", bConfirmError);
213          m_settings.setValue("/KeepOnTop", bKeepOnTop);          m_settings.setValue("/KeepOnTop", bKeepOnTop);
214          m_settings.setValue("/StdoutCapture", bStdoutCapture);          m_settings.setValue("/StdoutCapture", bStdoutCapture);
215          m_settings.setValue("/CompletePath", bCompletePath);          m_settings.setValue("/CompletePath", bCompletePath);
# Line 200  void Options::saveOptions (void) Line 218  void Options::saveOptions (void)
218          m_settings.setValue("/InstrumentNames", bInstrumentNames);          m_settings.setValue("/InstrumentNames", bInstrumentNames);
219          m_settings.endGroup();          m_settings.endGroup();
220    
221            // Save custom options...
222            m_settings.beginGroup("/Custom");
223            m_settings.setValue("/ColorTheme", sCustomColorTheme);
224            m_settings.setValue("/StyleTheme", sCustomStyleTheme);
225            m_settings.endGroup();
226    
227          // View options group.          // View options group.
228          m_settings.beginGroup("/View");          m_settings.beginGroup("/View");
229          m_settings.setValue("/Menubar", bMenubar);          m_settings.setValue("/Menubar", bMenubar);
# Line 280  bool Options::parse_args ( const QString Line 304  bool Options::parse_args ( const QString
304  {  {
305          QTextStream out(stderr);          QTextStream out(stderr);
306          const QString sEol = "\n\n";          const QString sEol = "\n\n";
         int iCmdArgs = 0;  
307          const int argc = args.count();          const int argc = args.count();
308            int iCmdArgs = 0;
309    
310          for (int i = 1; i < argc; i++) {          for (int i = 1; i < argc; ++i) {
311    
312                  if (iCmdArgs > 0) {                  if (iCmdArgs > 0) {
313                          sSessionFile += " ";                          sSessionFile += " ";
314                          sSessionFile += args.at(i);                          sSessionFile += args.at(i);
315                          iCmdArgs++;                          ++iCmdArgs;
316                          continue;                          continue;
317                  }                  }
318    
319                  QString sArg = args.at(i);                  QString sArg = args.at(i);
320                  QString sVal = QString::null;                  QString sVal;
321                  const int iEqual = sArg.indexOf("=");                  const int iEqual = sArg.indexOf("=");
322                  if (iEqual >= 0) {                  if (iEqual >= 0) {
323                          sVal = sArg.right(sArg.length() - iEqual - 1);                          sVal = sArg.right(sArg.length() - iEqual - 1);
# Line 315  bool Options::parse_args ( const QString Line 339  bool Options::parse_args ( const QString
339                          }                          }
340                          sServerHost = sVal;                          sServerHost = sVal;
341                          if (iEqual < 0)                          if (iEqual < 0)
342                                  i++;                                  ++i;
343                  }                  }
344                  else if (sArg == "-p" || sArg == "--port") {                  else if (sArg == "-p" || sArg == "--port") {
345                          if (sVal.isNull()) {                          if (sVal.isNull()) {
# Line 324  bool Options::parse_args ( const QString Line 348  bool Options::parse_args ( const QString
348                          }                          }
349                          iServerPort = sVal.toInt();                          iServerPort = sVal.toInt();
350                          if (iEqual < 0)                          if (iEqual < 0)
351                                  i++;                                  ++i;
352                  }                  }
353                  else if (sArg == "-?" || sArg == "--help") {                  else if (sArg == "-?" || sArg == "--help") {
354                          print_usage(args.at(0));                          print_usage(args.at(0));
355                          return false;                          return false;
356                  }                  }
357                  else if (sArg == "-v" || sArg == "--version") {                  else if (sArg == "-v" || sArg == "--version") {
358                          out << QObject::tr("Qt: %1\n").arg(qVersion());                          out << QString("Qt: %1\n")
359                                    .arg(qVersion());
360                            out << QString("%1: %2\n")
361                                    .arg(QSAMPLER_TITLE)
362                                    .arg(CONFIG_BUILD_VERSION);
363                  #ifdef CONFIG_LIBGIG                  #ifdef CONFIG_LIBGIG
364                          out << QString("%1: %2\n")                          out << QString("%1: %2\n")
365                                  .arg(gig::libraryName().c_str())                                  .arg(gig::libraryName().c_str())
# Line 340  bool Options::parse_args ( const QString Line 368  bool Options::parse_args ( const QString
368                          out << QString("%1: %2\n")                          out << QString("%1: %2\n")
369                                  .arg(::lscp_client_package())                                  .arg(::lscp_client_package())
370                                  .arg(::lscp_client_version());                                  .arg(::lscp_client_version());
                         out << QObject::tr(QSAMPLER_TITLE ": %1\n").arg(QSAMPLER_VERSION);  
371                          return false;                          return false;
372                  }                  }
373                  else {                  else {
374                          // If we don't have one by now,                          // If we don't have one by now,
375                          // this will be the startup sesion file...                          // this will be the startup sesion file...
376                          sSessionFile += sArg;                          sSessionFile += sArg;
377                          iCmdArgs++;                          ++iCmdArgs;
378                  }                  }
379          }          }
380    
# Line 363  void Options::loadWidgetGeometry ( QWidg Line 390  void Options::loadWidgetGeometry ( QWidg
390  {  {
391          // Try to restore old form window positioning.          // Try to restore old form window positioning.
392          if (pWidget) {          if (pWidget) {
393            //      if (bVisible) pWidget->show(); -- force initial exposure?
394                    m_settings.beginGroup("/Geometry/" + pWidget->objectName());
395            #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
396                    const QByteArray& geometry
397                            = m_settings.value("/geometry").toByteArray();
398                    if (geometry.isEmpty()) {
399                            QWidget *pParent = pWidget->parentWidget();
400                            if (pParent)
401                                    pParent = pParent->window();
402                    #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
403                            if (pParent == nullptr)
404                                    pParent = QApplication::desktop();
405                    #endif
406                            if (pParent) {
407                                    QRect wrect(pWidget->geometry());
408                                    wrect.moveCenter(pParent->geometry().center());
409                                    pWidget->move(wrect.topLeft());
410                            }
411                    } else {
412                            pWidget->restoreGeometry(geometry);
413                    }
414            #else//--LOAD_OLD_GEOMETRY
415                  QPoint wpos;                  QPoint wpos;
416                  QSize  wsize;                  QSize  wsize;
                 m_settings.beginGroup("/Geometry/" + pWidget->objectName());  
417                  wpos.setX(m_settings.value("/x", -1).toInt());                  wpos.setX(m_settings.value("/x", -1).toInt());
418                  wpos.setY(m_settings.value("/y", -1).toInt());                  wpos.setY(m_settings.value("/y", -1).toInt());
419                  wsize.setWidth(m_settings.value("/width", -1).toInt());                  wsize.setWidth(m_settings.value("/width", -1).toInt());
420                  wsize.setHeight(m_settings.value("/height", -1).toInt());                  wsize.setHeight(m_settings.value("/height", -1).toInt());
                 if (!bVisible) bVisible = m_settings.value("/visible", false).toBool();  
                 m_settings.endGroup();  
421                  if (wpos.x() > 0 && wpos.y() > 0)                  if (wpos.x() > 0 && wpos.y() > 0)
422                          pWidget->move(wpos);                          pWidget->move(wpos);
423                  if (wsize.width() > 0 && wsize.height() > 0)                  if (wsize.width() > 0 && wsize.height() > 0)
424                          pWidget->resize(wsize);                          pWidget->resize(wsize);
425            #endif
426          //      else          //      else
427          //              pWidget->adjustSize();          //      pWidget->adjustSize();
428                    if (!bVisible)
429                            bVisible = m_settings.value("/visible", false).toBool();
430                  if (bVisible)                  if (bVisible)
431                          pWidget->show();                          pWidget->show();
432          //      else                  else
433          //              pWidget->hide();                          pWidget->hide();
434                    m_settings.endGroup();
435          }          }
436  }  }
437    
# Line 393  void Options::saveWidgetGeometry ( QWidg Line 443  void Options::saveWidgetGeometry ( QWidg
443          // only save the form geometry while its up and visible)          // only save the form geometry while its up and visible)
444          if (pWidget) {          if (pWidget) {
445                  m_settings.beginGroup("/Geometry/" + pWidget->objectName());                  m_settings.beginGroup("/Geometry/" + pWidget->objectName());
446            #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
447                    m_settings.setValue("/geometry", pWidget->saveGeometry());
448            #else//--SAVE_OLD_GEOMETRY
449                  const QPoint& wpos  = pWidget->pos();                  const QPoint& wpos  = pWidget->pos();
450                  const QSize&  wsize = pWidget->size();                  const QSize&  wsize = pWidget->size();
                 if (!bVisible) bVisible = pWidget->isVisible();  
451                  m_settings.setValue("/x", wpos.x());                  m_settings.setValue("/x", wpos.x());
452                  m_settings.setValue("/y", wpos.y());                  m_settings.setValue("/y", wpos.y());
453                  m_settings.setValue("/width", wsize.width());                  m_settings.setValue("/width", wsize.width());
454                  m_settings.setValue("/height", wsize.height());                  m_settings.setValue("/height", wsize.height());
455            #endif
456                    if (!bVisible) bVisible = pWidget->isVisible();
457                  m_settings.setValue("/visible", bVisible);                  m_settings.setValue("/visible", bVisible);
458                  m_settings.endGroup();                  m_settings.endGroup();
459          }          }
# Line 411  void Options::saveWidgetGeometry ( QWidg Line 465  void Options::saveWidgetGeometry ( QWidg
465    
466  void Options::loadComboBoxHistory ( QComboBox *pComboBox, int iLimit )  void Options::loadComboBoxHistory ( QComboBox *pComboBox, int iLimit )
467  {  {
468            const bool bBlockSignals = pComboBox->blockSignals(true);
469    
470          // Load combobox list from configuration settings file...          // Load combobox list from configuration settings file...
471          m_settings.beginGroup("/History/" + pComboBox->objectName());          m_settings.beginGroup("/History/" + pComboBox->objectName());
472    
# Line 418  void Options::loadComboBoxHistory ( QCom Line 474  void Options::loadComboBoxHistory ( QCom
474                  pComboBox->setUpdatesEnabled(false);                  pComboBox->setUpdatesEnabled(false);
475                  pComboBox->setDuplicatesEnabled(false);                  pComboBox->setDuplicatesEnabled(false);
476                  pComboBox->clear();                  pComboBox->clear();
477                  for (int i = 0; i < iLimit; i++) {                  for (int i = 0; i < iLimit; ++i) {
478                          const QString& sText = m_settings.value(                          const QString& sText = m_settings.value(
479                                  "/Item" + QString::number(i + 1)).toString();                                  "/Item" + QString::number(i + 1)).toString();
480                          if (sText.isEmpty())                          if (sText.isEmpty())
# Line 429  void Options::loadComboBoxHistory ( QCom Line 485  void Options::loadComboBoxHistory ( QCom
485          }          }
486    
487          m_settings.endGroup();          m_settings.endGroup();
488    
489            pComboBox->blockSignals(bBlockSignals);
490  }  }
491    
492    
493  void Options::saveComboBoxHistory ( QComboBox *pComboBox, int iLimit )  void Options::saveComboBoxHistory ( QComboBox *pComboBox, int iLimit )
494  {  {
495            const bool bBlockSignals = pComboBox->blockSignals(true);
496    
497          // Add current text as latest item...          // Add current text as latest item...
498          const QString& sCurrentText = pComboBox->currentText();          const QString sCurrentText = pComboBox->currentText();
499          int iCount = pComboBox->count();          int iCount = pComboBox->count();
500          for (int i = 0; i < iCount; i++) {          for (int i = 0; i < iCount; i++) {
501                  const QString& sText = pComboBox->itemText(i);                  const QString& sText = pComboBox->itemText(i);
502                  if (sText == sCurrentText) {                  if (sText == sCurrentText) {
503                          pComboBox->removeItem(i);                          pComboBox->removeItem(i);
504                          iCount--;                          --iCount;
505                          break;                          break;
506                  }                  }
507          }          }
508          while (iCount >= iLimit)          while (iCount >= iLimit)
509                  pComboBox->removeItem(--iCount);                  pComboBox->removeItem(--iCount);
510          pComboBox->insertItem(0, sCurrentText);          pComboBox->insertItem(0, sCurrentText);
511          iCount++;          pComboBox->setCurrentIndex(0);
512            ++iCount;
513    
514          // Save combobox list to configuration settings file...          // Save combobox list to configuration settings file...
515          m_settings.beginGroup("/History/" + pComboBox->objectName());          m_settings.beginGroup("/History/" + pComboBox->objectName());
516          for (int i = 0; i < iCount; i++) {          for (int i = 0; i < iCount; ++i) {
517                  const QString& sText = pComboBox->itemText(i);                  const QString& sText = pComboBox->itemText(i);
518                  if (sText.isEmpty())                  if (sText.isEmpty())
519                          break;                          break;
520                  m_settings.setValue("/Item" + QString::number(i + 1), sText);                  m_settings.setValue("/Item" + QString::number(i + 1), sText);
521          }          }
522          m_settings.endGroup();          m_settings.endGroup();
523    
524            pComboBox->blockSignals(bBlockSignals);
525  }  }
526    
527    
528  int Options::getMaxVoices() {  int Options::getMaxVoices() {
529  #ifndef CONFIG_MAX_VOICES  #ifndef CONFIG_MAX_VOICES
530          return -1;          return -1;
# Line 558  void Options::sendFineTuningSettings() { Line 622  void Options::sendFineTuningSettings() {
622    
623    
624  // end of qsamplerOptions.cpp  // end of qsamplerOptions.cpp
625    

Legend:
Removed from v.2718  
changed lines
  Added in v.3796

  ViewVC Help
Powered by ViewVC