/[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 3496 by capela, Sun Mar 10 11:06:53 2019 UTC revision 3681 by capela, Thu Jan 2 14:39:02 2020 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-2020, 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>
# Line 41  Line 47 
47  #define CONFIG_DATADIR  CONFIG_PREFIX "/share"  #define CONFIG_DATADIR  CONFIG_PREFIX "/share"
48  #endif  #endif
49    
50    #ifndef CONFIG_LIBDIR
51    #if defined(__x86_64__)
52    #define CONFIG_LIBDIR  CONFIG_PREFIX "/lib64"
53    #else
54    #define CONFIG_LIBDIR  CONFIG_PREFIX "/lib"
55    #endif
56    #endif
57    
58    #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
59    #define CONFIG_PLUGINSDIR CONFIG_LIBDIR "/qt4/plugins"
60    #else
61    #define CONFIG_PLUGINSDIR CONFIG_LIBDIR "/qt5/plugins"
62    #endif
63    
64  #if defined(__WIN32__) || defined(_WIN32) || defined(WIN32)  #if defined(__WIN32__) || defined(_WIN32) || defined(WIN32)
65  #define RELATIVE_LOCALE_DIR "/share/locale"  #define RELATIVE_LOCALE_DIR "/share/locale"
66  #elif defined(__APPLE__)  #elif defined(__APPLE__)
# Line 56  Line 76 
76    
77  #define QSAMPLER_XUNIQUE "qsamplerApplication"  #define QSAMPLER_XUNIQUE "qsamplerApplication"
78    
79  #if QT_VERSION < 0x050000  #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
80  #ifdef CONFIG_X11  #ifdef CONFIG_X11
81    
82  #include <unistd.h> /* for gethostname() */  #include <unistd.h> /* for gethostname() */
# Line 78  Line 98 
98  // Constructor.  // Constructor.
99  qsamplerApplication::qsamplerApplication ( int& argc, char **argv )  qsamplerApplication::qsamplerApplication ( int& argc, char **argv )
100          : QApplication(argc, argv),          : QApplication(argc, argv),
101                  m_pQtTranslator(NULL), m_pMyTranslator(NULL), m_pWidget(NULL)                  m_pQtTranslator(nullptr), m_pMyTranslator(nullptr), m_pWidget(nullptr)
102  {  {
103    #if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0)
104            QApplication::setApplicationName(QSAMPLER_TITLE);
105            QApplication::setApplicationDisplayName(QSAMPLER_TITLE);
106            //      QSAMPLER_TITLE " - " + QObject::tr(QSAMPLER_SUBTITLE));
107    #endif
108          // Load translation support.          // Load translation support.
109          QLocale loc;          QLocale loc;
110          if (loc.language() != QLocale::C) {          if (loc.language() != QLocale::C) {
# Line 134  qsamplerApplication::qsamplerApplication Line 159  qsamplerApplication::qsamplerApplication
159                  }                  }
160          }          }
161  #ifdef CONFIG_XUNIQUE  #ifdef CONFIG_XUNIQUE
162  #if QT_VERSION < 0x050000  #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
163  #ifdef CONFIG_X11  #ifdef CONFIG_X11
164          m_pDisplay = NULL;          m_pDisplay = nullptr;
165          m_aUnique = 0;          m_aUnique = 0;
166          m_wOwner = 0;          m_wOwner = 0;
167  #endif  // CONFIG_X11  #endif  // CONFIG_X11
168  #else  #else
169          m_pMemory = NULL;          m_pMemory = nullptr;
170          m_pServer = NULL;          m_pServer = nullptr;
171  #endif  #endif
172  #endif  // CONFIG_XUNIQUE  #endif  // CONFIG_XUNIQUE
173  }  }
# Line 152  qsamplerApplication::qsamplerApplication Line 177  qsamplerApplication::qsamplerApplication
177  qsamplerApplication::~qsamplerApplication (void)  qsamplerApplication::~qsamplerApplication (void)
178  {  {
179  #ifdef CONFIG_XUNIQUE  #ifdef CONFIG_XUNIQUE
180  #if QT_VERSION >= 0x050000  #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
181          if (m_pServer) {          if (m_pServer) {
182                  m_pServer->close();                  m_pServer->close();
183                  delete m_pServer;                  delete m_pServer;
184                  m_pServer = NULL;                  m_pServer = nullptr;
185          }          }
186          if (m_pMemory) {          if (m_pMemory) {
187                  delete m_pMemory;                  delete m_pMemory;
188                  m_pMemory = NULL;                  m_pMemory = nullptr;
189  }  }
190  #endif  #endif
191  #endif  // CONFIG_XUNIQUE  #endif  // CONFIG_XUNIQUE
# Line 174  void qsamplerApplication::setMainWidget Line 199  void qsamplerApplication::setMainWidget
199  {  {
200          m_pWidget = pWidget;          m_pWidget = pWidget;
201  #ifdef CONFIG_XUNIQUE  #ifdef CONFIG_XUNIQUE
202  #if QT_VERSION < 0x050000  #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
203  #ifdef CONFIG_X11  #ifdef CONFIG_X11
204          m_wOwner = m_pWidget->winId();          m_wOwner = m_pWidget->winId();
205          if (m_pDisplay && m_wOwner) {          if (m_pDisplay && m_wOwner) {
# Line 193  void qsamplerApplication::setMainWidget Line 218  void qsamplerApplication::setMainWidget
218  bool qsamplerApplication::setup (void)  bool qsamplerApplication::setup (void)
219  {  {
220  #ifdef CONFIG_XUNIQUE  #ifdef CONFIG_XUNIQUE
221  #if QT_VERSION < 0x050000  #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
222  #ifdef CONFIG_X11  #ifdef CONFIG_X11
223          m_pDisplay = QX11Info::display();          m_pDisplay = QX11Info::display();
224          if (m_pDisplay) {          if (m_pDisplay) {
# Line 304  bool qsamplerApplication::setup (void) Line 329  bool qsamplerApplication::setup (void)
329    
330    
331  #ifdef CONFIG_XUNIQUE  #ifdef CONFIG_XUNIQUE
332  #if QT_VERSION < 0x050000  #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
333  #ifdef CONFIG_X11  #ifdef CONFIG_X11
334    
335  void qsamplerApplication::x11PropertyNotify ( Window w )  void qsamplerApplication::x11PropertyNotify ( Window w )
# Line 370  void qsamplerApplication::readyReadSlot Line 395  void qsamplerApplication::readyReadSlot
395          if (pSocket) {          if (pSocket) {
396                  const qint64 nread = pSocket->bytesAvailable();                  const qint64 nread = pSocket->bytesAvailable();
397                  if (nread > 0) {                  if (nread > 0) {
398                          QByteArray data = pSocket->read(nread);                          const QByteArray data = pSocket->read(nread);
399                          // Just make it always shows up fine...                          // Just make it always shows up fine...
400                          m_pWidget->hide();                          m_pWidget->hide();
401                          m_pWidget->show();                          m_pWidget->show();
# Line 405  void stacktrace ( int signo ) Line 430  void stacktrace ( int signo )
430          char cmd[80];          char cmd[80];
431    
432          // Reinstall default handler; prevent race conditions...          // Reinstall default handler; prevent race conditions...
433          signal(signo, SIG_DFL);          ::signal(signo, SIG_DFL);
434    
435          static const char *shell  = "/bin/sh";          static const char *shell  = "/bin/sh";
436          static const char *format = "gdb -q --batch --pid=%d"          static const char *format = "gdb -q --batch --pid=%d"
# Line 421  void stacktrace ( int signo ) Line 446  void stacktrace ( int signo )
446    
447          // Fork child...          // Fork child...
448          if (pid == 0) {          if (pid == 0) {
449                  execl(shell, shell, "-c", cmd, NULL);                  execl(shell, shell, "-c", cmd, nullptr);
450                  _exit(1);                  _exit(1);
451                  return;                  return;
452          }          }
# Line 451  int main ( int argc, char **argv ) Line 476  int main ( int argc, char **argv )
476          Q_INIT_RESOURCE(qsampler);          Q_INIT_RESOURCE(qsampler);
477  #ifdef CONFIG_STACKTRACE  #ifdef CONFIG_STACKTRACE
478  #if defined(__GNUC__) && defined(Q_OS_LINUX)  #if defined(__GNUC__) && defined(Q_OS_LINUX)
479          signal(SIGILL,  stacktrace);          ::signal(SIGILL,  stacktrace);
480          signal(SIGFPE,  stacktrace);          ::signal(SIGFPE,  stacktrace);
481          signal(SIGSEGV, stacktrace);          ::signal(SIGSEGV, stacktrace);
482          signal(SIGABRT, stacktrace);          ::signal(SIGABRT, stacktrace);
483          signal(SIGBUS,  stacktrace);          ::signal(SIGBUS,  stacktrace);
484  #endif  #endif
485  #endif  #endif
486          qsamplerApplication app(argc, argv);  #if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
487  #if QT_VERSION >= 0x050600          QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
         app.setAttribute(Qt::AA_EnableHighDpiScaling);  
488  #endif  #endif
489            qsamplerApplication app(argc, argv);
490    
491          #if defined(__APPLE__)  //  Toshi Nagata 20080105          #if defined(__APPLE__)  //  Toshi Nagata 20080105
492          {          {
493                  //  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 517  int main ( int argc, char **argv )
517                  return 2;                  return 2;
518          }          }
519    
520          // Dark themes grayed/disabled color group fix...          // Special custom styles...
521            if (QDir(CONFIG_PLUGINSDIR).exists())
522                    app.addLibraryPath(CONFIG_PLUGINSDIR);
523            if (!options.sCustomStyleTheme.isEmpty())
524                    app.setStyle(QStyleFactory::create(options.sCustomStyleTheme));
525    
526            // Custom color theme (eg. "KXStudio")...
527          QPalette pal(app.palette());          QPalette pal(app.palette());
528          if (pal.base().color().value() < 0x7f) {          if (QSampler::PaletteForm::namedPalette(
529          #if QT_VERSION >= 0x050000                          &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());  
530                  app.setPalette(pal);                  app.setPalette(pal);
         }  
531    
532          // Set default base font...          // Set default base font...
533          if (options.iBaseFontSize > 0)          if (options.iBaseFontSize > 0)

Legend:
Removed from v.3496  
changed lines
  Added in v.3681

  ViewVC Help
Powered by ViewVC