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

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

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

revision 3520 by capela, Mon Jul 1 10:53:41 2019 UTC revision 4024 by capela, Sun Feb 6 10:50:27 2022 UTC
# Line 1  Line 1 
1  // qsampler.cpp  // qsampler.cpp
2  //  //
3  /****************************************************************************  /****************************************************************************
4     Copyright (C) 2004-2019, rncbc aka Rui Nuno Capela. All rights reserved.     Copyright (C) 2004-2022, rncbc aka Rui Nuno Capela. All rights reserved.
5     Copyright (C) 2007,2008,2015 Christian Schoenebeck     Copyright (C) 2007,2008,2015,2019 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 25  Line 25 
25  #include "qsamplerOptions.h"  #include "qsamplerOptions.h"
26  #include "qsamplerMainForm.h"  #include "qsamplerMainForm.h"
27    
28    #include "qsamplerPaletteForm.h"
29    
30    #include <QDir>
31    
32    #include <QStyleFactory>
33    
34  #include <QLibraryInfo>  #include <QLibraryInfo>
35  #include <QTranslator>  #include <QTranslator>
36  #include <QLocale>  #include <QLocale>
37    
38    #if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0)
39    #include <lscp/client.h>
40    #ifdef CONFIG_LIBGIG
41    #if defined(Q_CC_GNU) || defined(Q_CC_MINGW)
42    #pragma GCC diagnostic push
43    #pragma GCC diagnostic ignored "-Wunused-parameter"
44    #endif
45    #include <gig.h>
46    #if defined(Q_CC_GNU) || defined(Q_CC_MINGW)
47    #pragma GCC diagnostic pop
48    #endif
49    #endif
50    #endif
51    
52  #if defined(__APPLE__)  // Toshi Nagata 20080105  #if defined(__APPLE__)  // Toshi Nagata 20080105
53  #include <QDir>  #include <QDir>
54  #endif  #endif
# Line 37  Line 57 
57  #define CONFIG_PREFIX   "/usr/local"  #define CONFIG_PREFIX   "/usr/local"
58  #endif  #endif
59    
60    #ifndef CONFIG_BINDIR
61    #define CONFIG_BINDIR   CONFIG_PREFIX "/bin"
62    #endif
63    
64  #ifndef CONFIG_DATADIR  #ifndef CONFIG_DATADIR
65  #define CONFIG_DATADIR  CONFIG_PREFIX "/share"  #define CONFIG_DATADIR  CONFIG_PREFIX "/share"
66  #endif  #endif
67    
68    #ifndef CONFIG_LIBDIR
69    #if defined(__x86_64__)
70    #define CONFIG_LIBDIR  CONFIG_PREFIX "/lib64"
71    #else
72    #define CONFIG_LIBDIR  CONFIG_PREFIX "/lib"
73    #endif
74    #endif
75    
76    #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
77    #define CONFIG_PLUGINSDIR CONFIG_LIBDIR "/qt4/plugins"
78    #elif QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
79    #define CONFIG_PLUGINSDIR CONFIG_LIBDIR "/qt5/plugins"
80    #else
81    #define CONFIG_PLUGINSDIR CONFIG_LIBDIR "/qt6/plugins"
82    #endif
83    
84  #if defined(__WIN32__) || defined(_WIN32) || defined(WIN32)  #if defined(__WIN32__) || defined(_WIN32) || defined(WIN32)
85  #define RELATIVE_LOCALE_DIR "/share/locale"  #define RELATIVE_LOCALE_DIR "/share/locale"
86  #elif defined(__APPLE__)  #elif defined(__APPLE__)
# Line 78  Line 118 
118  // Constructor.  // Constructor.
119  qsamplerApplication::qsamplerApplication ( int& argc, char **argv )  qsamplerApplication::qsamplerApplication ( int& argc, char **argv )
120          : QApplication(argc, argv),          : QApplication(argc, argv),
121                  m_pQtTranslator(NULL), m_pMyTranslator(NULL), m_pWidget(NULL)                  m_pQtTranslator(nullptr), m_pMyTranslator(nullptr), m_pWidget(nullptr)
122  {  {
123    #if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0)
124            QApplication::setApplicationName(QSAMPLER_TITLE);
125            QApplication::setApplicationDisplayName(QSAMPLER_TITLE);
126            //      QSAMPLER_TITLE " - " + QObject::tr(QSAMPLER_SUBTITLE));
127            QString sVersion(CONFIG_BUILD_VERSION);
128            sVersion += '\n';
129            sVersion += QString("Qt: %1").arg(qVersion());
130    #if defined(QT_STATIC)
131            sVersion += "-static";
132    #endif
133            sVersion += '\n';
134    #ifdef CONFIG_LIBGIG
135            sVersion += QString("%1: %2")
136                    .arg(gig::libraryName().c_str())
137                    .arg(gig::libraryVersion().c_str());
138            sVersion += '\n';
139    #endif
140            sVersion += QString("%1: %2")
141                    .arg(::lscp_client_package())
142                    .arg(::lscp_client_version());
143            QApplication::setApplicationVersion(sVersion);
144    #endif
145          // Load translation support.          // Load translation support.
146          QLocale loc;          QLocale loc;
147          if (loc.language() != QLocale::C) {          if (loc.language() != QLocale::C) {
148                  // Try own Qt translation...                  // Try own Qt translation...
149                  m_pQtTranslator = new QTranslator(this);                  m_pQtTranslator = new QTranslator(this);
150                  QString sLocName = "qt_" + loc.name();                  QString sLocName = "qt_" + loc.name();
151            #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
152                    QString sLocPath = QLibraryInfo::path(QLibraryInfo::TranslationsPath);
153            #else
154                  QString sLocPath = QLibraryInfo::location(QLibraryInfo::TranslationsPath);                  QString sLocPath = QLibraryInfo::location(QLibraryInfo::TranslationsPath);
155            #endif
156                  if (m_pQtTranslator->load(sLocName, sLocPath)) {                  if (m_pQtTranslator->load(sLocName, sLocPath)) {
157                          QApplication::installTranslator(m_pQtTranslator);                          QApplication::installTranslator(m_pQtTranslator);
158                  } else {                  } else {
159                            sLocPath = QApplication::applicationDirPath();
160                  #ifdef RELATIVE_LOCALE_DIR                  #ifdef RELATIVE_LOCALE_DIR
161                          sLocPath = QApplication::applicationDirPath() + RELATIVE_LOCALE_DIR;                          sLocPath.append(RELATIVE_LOCALE_DIR);
162                    #else
163                            sLocPath.remove(CONFIG_BINDIR);
164                            sLocPath.append(CONFIG_DATADIR "/qsampler/translations");
165                    #endif
166                          if (m_pQtTranslator->load(sLocName, sLocPath)) {                          if (m_pQtTranslator->load(sLocName, sLocPath)) {
167                                  QApplication::installTranslator(m_pQtTranslator);                                  QApplication::installTranslator(m_pQtTranslator);
168                          } else {                          } else {
169                  #endif                                  delete m_pQtTranslator;
170                          delete m_pQtTranslator;                                  m_pQtTranslator = nullptr;
171                          m_pQtTranslator = 0;                          #ifdef CONFIG_DEBUG
172                  #ifdef CONFIG_DEBUG                                  qWarning("Warning: no translation found for '%s' locale: %s/%s.qm",
173                          qWarning("Warning: no translation found for '%s' locale: %s/%s.qm",                                          loc.name().toUtf8().constData(),
174                                  loc.name().toUtf8().constData(),                                          sLocPath.toUtf8().constData(),
175                                  sLocPath.toUtf8().constData(),                                          sLocName.toUtf8().constData());
176                                  sLocName.toUtf8().constData());                          #endif
                 #endif  
                 #ifdef RELATIVE_LOCALE_DIR  
177                          }                          }
                 #endif  
178                  }                  }
179                  // Try own application translation...                  // Try own application translation...
180                  m_pMyTranslator = new QTranslator(this);                  m_pMyTranslator = new QTranslator(this);
# Line 123  qsamplerApplication::qsamplerApplication Line 191  qsamplerApplication::qsamplerApplication
191                                  QApplication::installTranslator(m_pMyTranslator);                                  QApplication::installTranslator(m_pMyTranslator);
192                          } else {                          } else {
193                                  delete m_pMyTranslator;                                  delete m_pMyTranslator;
194                                  m_pMyTranslator = 0;                                  m_pMyTranslator = nullptr;
195                          #ifdef CONFIG_DEBUG                          #ifdef CONFIG_DEBUG
196                                  qWarning("Warning: no translation found for '%s' locale: %s/%s.qm",                                  qWarning("Warning: no translation found for '%s' locale: %s/%s.qm",
197                                          loc.name().toUtf8().constData(),                                          loc.name().toUtf8().constData(),
# Line 136  qsamplerApplication::qsamplerApplication Line 204  qsamplerApplication::qsamplerApplication
204  #ifdef CONFIG_XUNIQUE  #ifdef CONFIG_XUNIQUE
205  #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)  #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
206  #ifdef CONFIG_X11  #ifdef CONFIG_X11
207          m_pDisplay = NULL;          m_pDisplay = nullptr;
208          m_aUnique = 0;          m_aUnique = 0;
209          m_wOwner = 0;          m_wOwner = 0;
210  #endif  // CONFIG_X11  #endif  // CONFIG_X11
211  #else  #else
212          m_pMemory = NULL;          m_pMemory = nullptr;
213          m_pServer = NULL;          m_pServer = nullptr;
214  #endif  #endif
215  #endif  // CONFIG_XUNIQUE  #endif  // CONFIG_XUNIQUE
216  }  }
# Line 156  qsamplerApplication::~qsamplerApplicatio Line 224  qsamplerApplication::~qsamplerApplicatio
224          if (m_pServer) {          if (m_pServer) {
225                  m_pServer->close();                  m_pServer->close();
226                  delete m_pServer;                  delete m_pServer;
227                  m_pServer = NULL;                  m_pServer = nullptr;
228          }          }
229          if (m_pMemory) {          if (m_pMemory) {
230                  delete m_pMemory;                  delete m_pMemory;
231                  m_pMemory = NULL;                  m_pMemory = nullptr;
232  }  }
233  #endif  #endif
234  #endif  // CONFIG_XUNIQUE  #endif  // CONFIG_XUNIQUE
# Line 370  void qsamplerApplication::readyReadSlot Line 438  void qsamplerApplication::readyReadSlot
438          if (pSocket) {          if (pSocket) {
439                  const qint64 nread = pSocket->bytesAvailable();                  const qint64 nread = pSocket->bytesAvailable();
440                  if (nread > 0) {                  if (nread > 0) {
441                          QByteArray data = pSocket->read(nread);                          const QByteArray data = pSocket->read(nread);
442                          // Just make it always shows up fine...                          // Just make it always shows up fine...
443                          m_pWidget->hide();                          m_pWidget->hide();
444                          m_pWidget->show();                          m_pWidget->show();
# Line 421  void stacktrace ( int signo ) Line 489  void stacktrace ( int signo )
489    
490          // Fork child...          // Fork child...
491          if (pid == 0) {          if (pid == 0) {
492                  execl(shell, shell, "-c", cmd, NULL);                  execl(shell, shell, "-c", cmd, nullptr);
493                  _exit(1);                  _exit(1);
494                  return;                  return;
495          }          }
# Line 458  int main ( int argc, char **argv ) Line 526  int main ( int argc, char **argv )
526          ::signal(SIGBUS,  stacktrace);          ::signal(SIGBUS,  stacktrace);
527  #endif  #endif
528  #endif  #endif
529          qsamplerApplication app(argc, argv);  #if defined(Q_OS_LINUX)
530            ::setenv("QT_QPA_PLATFORM", "xcb", 0);
531    #endif
532  #if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)  #if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
533          app.setAttribute(Qt::AA_EnableHighDpiScaling);  #if QT_VERSION <  QT_VERSION_CHECK(6, 0, 0)
534            QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
535  #endif  #endif
536    #endif
537            qsamplerApplication app(argc, argv);
538    
539          #if defined(__APPLE__)  //  Toshi Nagata 20080105          #if defined(__APPLE__)  //  Toshi Nagata 20080105
540          {          {
541                  //  Set the plugin path to @exetutable_path/../plugins                  //  Set the plugin path to @exetutable_path/../plugins
# Line 491  int main ( int argc, char **argv ) Line 565  int main ( int argc, char **argv )
565                  return 2;                  return 2;
566          }          }
567    
568          // Dark themes grayed/disabled color group fix...          // Special custom styles...
569            if (QDir(CONFIG_PLUGINSDIR).exists())
570                    app.addLibraryPath(CONFIG_PLUGINSDIR);
571            if (!options.sCustomStyleTheme.isEmpty())
572                    app.setStyle(QStyleFactory::create(options.sCustomStyleTheme));
573    
574            // Custom color theme (eg. "KXStudio")...
575          QPalette pal(app.palette());          QPalette pal(app.palette());
576          if (pal.base().color().value() < 0x7f) {          if (QSampler::PaletteForm::namedPalette(
577          #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)                          &options.settings(), options.sCustomColorTheme, pal))
                 const QColor& color = pal.window().color();  
                 const int iGroups = int(QPalette::Active | QPalette::Inactive) + 1;  
                 for (int i = 0; i < iGroups; ++i) {  
                         const QPalette::ColorGroup group = QPalette::ColorGroup(i);  
                         pal.setBrush(group, QPalette::Light,    color.lighter(150));  
                         pal.setBrush(group, QPalette::Midlight, color.lighter(120));  
                         pal.setBrush(group, QPalette::Dark,     color.darker(150));  
                         pal.setBrush(group, QPalette::Mid,      color.darker(120));  
                         pal.setBrush(group, QPalette::Shadow,   color.darker(200));  
                 }  
         //      pal.setColor(QPalette::Disabled, QPalette::ButtonText, pal.mid().color());  
         #endif  
                 pal.setColorGroup(QPalette::Disabled,  
                         pal.windowText().color().darker(),  
                         pal.button(),  
                         pal.light(),  
                         pal.dark(),  
                         pal.mid(),  
                         pal.text().color().darker(),  
                         pal.text().color().lighter(),  
                         pal.base(),  
                         pal.window());  
578                  app.setPalette(pal);                  app.setPalette(pal);
         }  
579    
580          // Set default base font...          // Set default base font...
581          if (options.iBaseFontSize > 0)          if (options.iBaseFontSize > 0)

Legend:
Removed from v.3520  
changed lines
  Added in v.4024

  ViewVC Help
Powered by ViewVC