/[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 2415 by capela, Thu Feb 14 14:57:43 2013 UTC revision 4030 by capela, Fri Mar 4 15:17:30 2022 UTC
# Line 1  Line 1 
1  // qsampler.cpp  // qsampler.cpp
2  //  //
3  /****************************************************************************  /****************************************************************************
4     Copyright (C) 2004-2013, 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 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 20  Line 20 
20    
21  *****************************************************************************/  *****************************************************************************/
22    
23  #include "qsamplerAbout.h"  #include "qsampler.h"
24    
25  #include "qsamplerOptions.h"  #include "qsamplerOptions.h"
26  #include "qsamplerMainForm.h"  #include "qsamplerMainForm.h"
27    
28  #include <QApplication>  #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
55    
56  #if QT_VERSION < 0x040300  #ifndef CONFIG_PREFIX
57  #define lighter(x)      light(x)  #define CONFIG_PREFIX   "/usr/local"
 #define darker(x)       dark(x)  
58  #endif  #endif
59    
60  #define CONFIG_QUOTE1(x) #x  #ifndef CONFIG_BINDIR
61  #define CONFIG_QUOTED(x) CONFIG_QUOTE1(x)  #define CONFIG_BINDIR   CONFIG_PREFIX "/bin"
62    #endif
63    
64  #if defined(DATADIR)  #ifndef CONFIG_DATADIR
65  #define CONFIG_DATADIR CONFIG_QUOTED(DATADIR)  #define CONFIG_DATADIR  CONFIG_PREFIX "/share"
66    #endif
67    
68    #ifndef CONFIG_LIBDIR
69    #if defined(__x86_64__)
70    #define CONFIG_LIBDIR  CONFIG_PREFIX "/lib64"
71  #else  #else
72  #define CONFIG_DATADIR CONFIG_PREFIX "/share"  #define CONFIG_LIBDIR  CONFIG_PREFIX "/lib"
73    #endif
74  #endif  #endif
75    
76  #if defined(LOCALEDIR)  #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
77  #define CONFIG_LOCALEDIR CONFIG_QUOTED(LOCALEDIR)  #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  #else
81  #define CONFIG_LOCALEDIR CONFIG_DATADIR "/locale"  #define CONFIG_PLUGINSDIR CONFIG_LIBDIR "/qt6/plugins"
82  #endif  #endif
83    
84  #if 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__)
87  #define RELATIVE_LOCALE_DIR "/../Resources"  #define RELATIVE_LOCALE_DIR "/../Resources"
# Line 63  Line 92 
92  // Singleton application instance stuff (Qt/X11 only atm.)  // Singleton application instance stuff (Qt/X11 only atm.)
93  //  //
94    
95  #if defined(Q_WS_X11)  #ifdef CONFIG_XUNIQUE
96    
97  #include <QX11Info>  #define QSAMPLER_XUNIQUE "qsamplerApplication"
98    
99    #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
100    #ifdef CONFIG_X11
101    
102    #include <unistd.h> /* for gethostname() */
103    
104  #include <X11/Xatom.h>  #include <X11/Xatom.h>
105  #include <X11/Xlib.h>  #include <X11/Xlib.h>
106    
107  #define QSAMPLER_XUNIQUE "qsamplerMainForm_xunique"  #endif  // CONFIG_X11
108    #else
109    #include <QSharedMemory>
110    #include <QLocalServer>
111    #include <QLocalSocket>
112    #include <QHostInfo>
113  #endif  #endif
114    
115  class qsamplerApplication : public QApplication  #endif  // CONFIG_XUNIQUE
 {  
 public:  
116    
117          // Constructor.  
118          qsamplerApplication(int& argc, char **argv) : QApplication(argc, argv),  // Constructor.
119                  m_pQtTranslator(0), m_pMyTranslator(0), m_pWidget(0)      qsamplerApplication::qsamplerApplication ( int& argc, char **argv )
120          {          : QApplication(argc, argv),
121                  // Load translation support.                  m_pQtTranslator(nullptr), m_pMyTranslator(nullptr), m_pWidget(nullptr)
122                  QLocale loc;  {
123                  if (loc.language() != QLocale::C) {  #if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0)
124                          // Try own Qt translation...          QApplication::setApplicationName(QSAMPLER_TITLE);
125                          m_pQtTranslator = new QTranslator(this);          QApplication::setApplicationDisplayName(QSAMPLER_TITLE);
126                          QString sLocName = "qt_" + loc.name();          //      QSAMPLER_TITLE " - " + QObject::tr(QSAMPLER_SUBTITLE));
127                          QString sLocPath = QLibraryInfo::location(QLibraryInfo::TranslationsPath);  #if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)
128            QApplication::setDesktopFileName(
129                    QString("org.rncbc.%1").arg(PACKAGE_TARNAME));
130    #endif
131            QString sVersion(CONFIG_BUILD_VERSION);
132            sVersion += '\n';
133            sVersion += QString("Qt: %1").arg(qVersion());
134    #if defined(QT_STATIC)
135            sVersion += "-static";
136    #endif
137            sVersion += '\n';
138    #ifdef CONFIG_LIBGIG
139            sVersion += QString("%1: %2")
140                    .arg(gig::libraryName().c_str())
141                    .arg(gig::libraryVersion().c_str());
142            sVersion += '\n';
143    #endif
144            sVersion += QString("%1: %2")
145                    .arg(::lscp_client_package())
146                    .arg(::lscp_client_version());
147            QApplication::setApplicationVersion(sVersion);
148    #endif
149            // Load translation support.
150            QLocale loc;
151            if (loc.language() != QLocale::C) {
152                    // Try own Qt translation...
153                    m_pQtTranslator = new QTranslator(this);
154                    QString sLocName = "qt_" + loc.name();
155            #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
156                    QString sLocPath = QLibraryInfo::path(QLibraryInfo::TranslationsPath);
157            #else
158                    QString sLocPath = QLibraryInfo::location(QLibraryInfo::TranslationsPath);
159            #endif
160                    if (m_pQtTranslator->load(sLocName, sLocPath)) {
161                            QApplication::installTranslator(m_pQtTranslator);
162                    } else {
163                            sLocPath = QApplication::applicationDirPath();
164                    #ifdef RELATIVE_LOCALE_DIR
165                            sLocPath.append(RELATIVE_LOCALE_DIR);
166                    #else
167                            sLocPath.remove(CONFIG_BINDIR);
168                            sLocPath.append(CONFIG_DATADIR "/qsampler/translations");
169                    #endif
170                          if (m_pQtTranslator->load(sLocName, sLocPath)) {                          if (m_pQtTranslator->load(sLocName, sLocPath)) {
171                                  QApplication::installTranslator(m_pQtTranslator);                                  QApplication::installTranslator(m_pQtTranslator);
172                          } else {                          } else {
                 #ifdef RELATIVE_LOCALE_DIR  
                                 sLocPath = QApplication::applicationDirPath() + RELATIVE_LOCALE_DIR;  
                                 if (m_pQtTranslator->load(sLocName, sLocPath)) {  
                                         QApplication::installTranslator(m_pQtTranslator);  
                                 } else {  
                 #endif  
173                                  delete m_pQtTranslator;                                  delete m_pQtTranslator;
174                                  m_pQtTranslator = 0;                                  m_pQtTranslator = nullptr;
175                  #ifdef CONFIG_DEBUG                          #ifdef CONFIG_DEBUG
176                                  qWarning("Warning: no translation found for '%s' locale: %s/%s.qm",                                  qWarning("Warning: no translation found for '%s' locale: %s/%s.qm",
177                                          loc.name().toUtf8().constData(),                                          loc.name().toUtf8().constData(),
178                                          sLocPath.toUtf8().constData(),                                          sLocPath.toUtf8().constData(),
179                                          sLocName.toUtf8().constData());                                          sLocName.toUtf8().constData());
180                  #endif                          #endif
181                            }
182                    }
183                    // Try own application translation...
184                    m_pMyTranslator = new QTranslator(this);
185                    sLocName = "qsampler_" + loc.name();
186                    if (m_pMyTranslator->load(sLocName, sLocPath)) {
187                            QApplication::installTranslator(m_pMyTranslator);
188                    } else {
189                  #ifdef RELATIVE_LOCALE_DIR                  #ifdef RELATIVE_LOCALE_DIR
190                                  }                          sLocPath = QApplication::applicationDirPath() + RELATIVE_LOCALE_DIR;
191                    #else
192                            sLocPath = CONFIG_DATADIR "/qsampler/translations";
193                  #endif                  #endif
                         }  
                         // Try own application translation...  
                         m_pMyTranslator = new QTranslator(this);  
                         sLocName = "qsampler_" + loc.name();  
194                          if (m_pMyTranslator->load(sLocName, sLocPath)) {                          if (m_pMyTranslator->load(sLocName, sLocPath)) {
195                                  QApplication::installTranslator(m_pMyTranslator);                                  QApplication::installTranslator(m_pMyTranslator);
196                          } else {                          } else {
197                  #ifdef RELATIVE_LOCALE_DIR                                  delete m_pMyTranslator;
198                                  sLocPath = QApplication::applicationDirPath() + RELATIVE_LOCALE_DIR;                                  m_pMyTranslator = nullptr;
199                  #else                          #ifdef CONFIG_DEBUG
200                                  sLocPath = CONFIG_LOCALEDIR;                                  qWarning("Warning: no translation found for '%s' locale: %s/%s.qm",
201                  #endif                                          loc.name().toUtf8().constData(),
202                                  if (m_pMyTranslator->load(sLocName, sLocPath)) {                                          sLocPath.toUtf8().constData(),
203                                          QApplication::installTranslator(m_pMyTranslator);                                          sLocName.toUtf8().constData());
204                                  } else {                          #endif
                                         delete m_pMyTranslator;  
                                         m_pMyTranslator = 0;  
                 #ifdef CONFIG_DEBUG  
                                         qWarning("Warning: no translation found for '%s' locale: %s/%s.qm",  
                                                 loc.name().toUtf8().constData(),  
                                                 sLocPath.toUtf8().constData(),  
                                                 sLocName.toUtf8().constData());  
                 #endif  
                                 }  
205                          }                          }
206                  }                  }
         #if defined(Q_WS_X11)  
                 m_pDisplay = QX11Info::display();  
                 m_aUnique  = XInternAtom(m_pDisplay, QSAMPLER_XUNIQUE, false);  
                 XGrabServer(m_pDisplay);  
                 m_wOwner = XGetSelectionOwner(m_pDisplay, m_aUnique);  
                 XUngrabServer(m_pDisplay);  
         #endif  
207          }          }
208    #ifdef CONFIG_XUNIQUE
209    #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
210    #ifdef CONFIG_X11
211            m_pDisplay = nullptr;
212            m_aUnique = 0;
213            m_wOwner = 0;
214    #endif  // CONFIG_X11
215    #else
216            m_pMemory = nullptr;
217            m_pServer = nullptr;
218    #endif
219    #endif  // CONFIG_XUNIQUE
220    }
221    
222          // Destructor.  
223          ~qsamplerApplication()  // Destructor.
224          {  qsamplerApplication::~qsamplerApplication (void)
225                  if (m_pMyTranslator) delete m_pMyTranslator;  {
226                  if (m_pQtTranslator) delete m_pQtTranslator;  #ifdef CONFIG_XUNIQUE
227    #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
228            if (m_pServer) {
229                    m_pServer->close();
230                    delete m_pServer;
231                    m_pServer = nullptr;
232          }          }
233            if (m_pMemory) {
234                    delete m_pMemory;
235                    m_pMemory = nullptr;
236    }
237    #endif
238    #endif  // CONFIG_XUNIQUE
239            if (m_pMyTranslator) delete m_pMyTranslator;
240            if (m_pQtTranslator) delete m_pQtTranslator;
241    }
242    
243          // Main application widget accessors.  
244          void setMainWidget(QWidget *pWidget)  // Main application widget accessors.
245          {  void qsamplerApplication::setMainWidget ( QWidget *pWidget )
246                  m_pWidget = pWidget;  {
247          #if defined(Q_WS_X11)          m_pWidget = pWidget;
248    #ifdef CONFIG_XUNIQUE
249    #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
250    #ifdef CONFIG_X11
251            m_wOwner = m_pWidget->winId();
252            if (m_pDisplay && m_wOwner) {
253                  XGrabServer(m_pDisplay);                  XGrabServer(m_pDisplay);
                 m_wOwner = m_pWidget->winId();  
254                  XSetSelectionOwner(m_pDisplay, m_aUnique, m_wOwner, CurrentTime);                  XSetSelectionOwner(m_pDisplay, m_aUnique, m_wOwner, CurrentTime);
255                  XUngrabServer(m_pDisplay);                  XUngrabServer(m_pDisplay);
         #endif  
256          }          }
257    #endif  // CONFIG_X11
258    #endif
259    #endif  // CONFIG_XUNIQUE
260    }
261    
         QWidget *mainWidget() const { return m_pWidget; }  
262    
263          // Check if another instance is running,  // Check if another instance is running,
264      // and raise its proper main widget...  // and raise its proper main widget...
265          bool setup()  bool qsamplerApplication::setup (void)
266          {  {
267          #if defined(Q_WS_X11)  #ifdef CONFIG_XUNIQUE
268    #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
269    #ifdef CONFIG_X11
270            m_pDisplay = QX11Info::display();
271            if (m_pDisplay) {
272                    QString sUnique = QSAMPLER_XUNIQUE;
273                    char szHostName[255];
274                    if (::gethostname(szHostName, sizeof(szHostName)) == 0) {
275                            sUnique += '@';
276                            sUnique += szHostName;
277                    }
278                    m_aUnique = XInternAtom(m_pDisplay, sUnique.toUtf8().constData(), false);
279                    XGrabServer(m_pDisplay);
280                    m_wOwner = XGetSelectionOwner(m_pDisplay, m_aUnique);
281                    XUngrabServer(m_pDisplay);
282                  if (m_wOwner != None) {                  if (m_wOwner != None) {
283                          // First, notify any freedesktop.org WM                          // First, notify any freedesktop.org WM
284                          // that we're about to show the main widget...                          // that we're about to show the main widget...
# Line 193  public: Line 302  public:
302                          XSync(m_pDisplay, false);                          XSync(m_pDisplay, false);
303                          XRaiseWindow(m_pDisplay, m_wOwner);                          XRaiseWindow(m_pDisplay, m_wOwner);
304                          // And then, let it get caught on destination                          // And then, let it get caught on destination
305                          // by QApplication::x11EventFilter...                          // by QApplication::native/x11EventFilter...
306                          QByteArray value = QSAMPLER_XUNIQUE;                          const QByteArray value = QSAMPLER_XUNIQUE;
307                          XChangeProperty(                          XChangeProperty(
308                                  m_pDisplay,                                  m_pDisplay,
309                                  m_wOwner,                                  m_wOwner,
# Line 206  public: Line 315  public:
315                          // Done.                          // Done.
316                          return true;                          return true;
317                  }                  }
         #endif  
                 return false;  
318          }          }
319    #endif  // CONFIG_X11
320  #if defined(Q_WS_X11)          return false;
321          bool x11EventFilter(XEvent *pEv)  #else
322          {          m_sUnique = QCoreApplication::applicationName();
323                  if (m_pWidget && m_wOwner != None          m_sUnique += '@';
324                          && pEv->type == PropertyNotify          m_sUnique += QHostInfo::localHostName();
325                          && pEv->xproperty.window == m_wOwner  #ifdef Q_OS_UNIX
326                          && pEv->xproperty.state == PropertyNewValue) {          m_pMemory = new QSharedMemory(m_sUnique);
327                          // Always check whether our property-flag is still around...          m_pMemory->attach();
328                          Atom aType;          delete m_pMemory;
329                          int iFormat = 0;  #endif
330                          unsigned long iItems = 0;          m_pMemory = new QSharedMemory(m_sUnique);
331                          unsigned long iAfter = 0;          bool bServer = false;
332                          unsigned char *pData = 0;          const qint64 pid = QCoreApplication::applicationPid();
333                          if (XGetWindowProperty(          struct Data { qint64 pid; };
334                                          m_pDisplay,          if (m_pMemory->create(sizeof(Data))) {
335                                          m_wOwner,                  m_pMemory->lock();
336                                          m_aUnique,                  Data *pData = static_cast<Data *> (m_pMemory->data());
337                                          0, 1024,                  if (pData) {
338                                          false,                          pData->pid = pid;
339                                          m_aUnique,                          bServer = true;
340                                          &aType,                  }
341                                          &iFormat,                  m_pMemory->unlock();
342                                          &iItems,          }
343                                          &iAfter,          else
344                                          &pData) == Success          if (m_pMemory->attach()) {
345                                  && aType == m_aUnique && iItems > 0 && iAfter == 0) {                  m_pMemory->lock(); // maybe not necessary?
346                                  // Avoid repeating it-self...                  Data *pData = static_cast<Data *> (m_pMemory->data());
347                                  XDeleteProperty(m_pDisplay, m_wOwner, m_aUnique);                  if (pData)
348                                  // Just make it always shows up fine...                          bServer = (pData->pid == pid);
349                                  m_pWidget->show();                  m_pMemory->unlock();
350                                  m_pWidget->raise();          }
351                                  m_pWidget->activateWindow();          if (bServer) {
352                          }                  QLocalServer::removeServer(m_sUnique);
353                          // Free any left-overs...                  m_pServer = new QLocalServer();
354                          if (iItems > 0 && pData)                  m_pServer->setSocketOptions(QLocalServer::UserAccessOption);
355                                  XFree(pData);                  m_pServer->listen(m_sUnique);
356                    QObject::connect(m_pServer,
357                            SIGNAL(newConnection()),
358                            SLOT(newConnectionSlot()));
359            } else {
360                    QLocalSocket socket;
361                    socket.connectToServer(m_sUnique);
362                    if (socket.state() == QLocalSocket::ConnectingState)
363                            socket.waitForConnected(200);
364                    if (socket.state() == QLocalSocket::ConnectedState) {
365                            socket.write(QCoreApplication::arguments().join(' ').toUtf8());
366                            socket.flush();
367                            socket.waitForBytesWritten(200);
368                  }                  }
                 return QApplication::x11EventFilter(pEv);  
369          }          }
370            return !bServer;
371  #endif  #endif
372            #else
373  private:          return false;
374    #endif  // !CONFIG_XUNIQUE
375    }
376    
         // Translation support.  
         QTranslator *m_pQtTranslator;  
         QTranslator *m_pMyTranslator;  
377    
378          // Instance variables.  #ifdef CONFIG_XUNIQUE
379          QWidget *m_pWidget;  #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
380    #ifdef CONFIG_X11
381    
382    void qsamplerApplication::x11PropertyNotify ( Window w )
383    {
384            if (m_pDisplay && m_pWidget && m_wOwner == w) {
385                    // Always check whether our property-flag is still around...
386                    Atom aType;
387                    int iFormat = 0;
388                    unsigned long iItems = 0;
389                    unsigned long iAfter = 0;
390                    unsigned char *pData = 0;
391                    if (XGetWindowProperty(
392                                    m_pDisplay,
393                                    m_wOwner,
394                                    m_aUnique,
395                                    0, 1024,
396                                    false,
397                                    m_aUnique,
398                                    &aType,
399                                    &iFormat,
400                                    &iItems,
401                                    &iAfter,
402                                    &pData) == Success
403                            && aType == m_aUnique && iItems > 0 && iAfter == 0) {
404                            // Avoid repeating it-self...
405                            XDeleteProperty(m_pDisplay, m_wOwner, m_aUnique);
406                            // Just make it always shows up fine...
407                            m_pWidget->show();
408                            m_pWidget->raise();
409                            m_pWidget->activateWindow();
410                    }
411                    // Free any left-overs...
412                    if (iItems > 0 && pData)
413                            XFree(pData);
414            }
415    }
416    
417    
418    bool qsamplerApplication::x11EventFilter ( XEvent *pEv )
419    {
420            if (pEv->type == PropertyNotify
421                    && pEv->xproperty.state == PropertyNewValue)
422                    x11PropertyNotify(pEv->xproperty.window);
423            return QApplication::x11EventFilter(pEv);
424    }
425    
426    #endif  // CONFIG_X11
427    #else
428    
429    // Local server conection slot.
430    void qsamplerApplication::newConnectionSlot (void)
431    {
432            QLocalSocket *pSocket = m_pServer->nextPendingConnection();
433            QObject::connect(pSocket,
434                    SIGNAL(readyRead()),
435                    SLOT(readyReadSlot()));
436    }
437    
438    // Local server data-ready slot.
439    void qsamplerApplication::readyReadSlot (void)
440    {
441            QLocalSocket *pSocket = qobject_cast<QLocalSocket *> (sender());
442            if (pSocket) {
443                    const qint64 nread = pSocket->bytesAvailable();
444                    if (nread > 0) {
445                            const QByteArray data = pSocket->read(nread);
446                            // Just make it always shows up fine...
447                            m_pWidget->hide();
448                            m_pWidget->show();
449                            m_pWidget->raise();
450                            m_pWidget->activateWindow();
451                    }
452            }
453    }
454    
 #if defined(Q_WS_X11)  
         Display *m_pDisplay;  
         Atom     m_aUnique;  
         Window   m_wOwner;  
455  #endif  #endif
456  };  #endif  // CONFIG_XUNIQUE
457    
458    
459  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
# Line 289  void stacktrace ( int signo ) Line 477  void stacktrace ( int signo )
477          char cmd[80];          char cmd[80];
478    
479          // Reinstall default handler; prevent race conditions...          // Reinstall default handler; prevent race conditions...
480          signal(signo, SIG_DFL);          ::signal(signo, SIG_DFL);
481    
482          static const char *shell  = "/bin/sh";          static const char *shell  = "/bin/sh";
483          static const char *format = "gdb -q --batch --pid=%d"          static const char *format = "gdb -q --batch --pid=%d"
# Line 305  void stacktrace ( int signo ) Line 493  void stacktrace ( int signo )
493    
494          // Fork child...          // Fork child...
495          if (pid == 0) {          if (pid == 0) {
496                  execl(shell, shell, "-c", cmd, NULL);                  execl(shell, shell, "-c", cmd, nullptr);
497                  _exit(1);                  _exit(1);
498                  return;                  return;
499          }          }
# Line 335  int main ( int argc, char **argv ) Line 523  int main ( int argc, char **argv )
523          Q_INIT_RESOURCE(qsampler);          Q_INIT_RESOURCE(qsampler);
524  #ifdef CONFIG_STACKTRACE  #ifdef CONFIG_STACKTRACE
525  #if defined(__GNUC__) && defined(Q_OS_LINUX)  #if defined(__GNUC__) && defined(Q_OS_LINUX)
526          signal(SIGILL,  stacktrace);          ::signal(SIGILL,  stacktrace);
527          signal(SIGFPE,  stacktrace);          ::signal(SIGFPE,  stacktrace);
528          signal(SIGSEGV, stacktrace);          ::signal(SIGSEGV, stacktrace);
529          signal(SIGABRT, stacktrace);          ::signal(SIGABRT, stacktrace);
530          signal(SIGBUS,  stacktrace);          ::signal(SIGBUS,  stacktrace);
531    #endif
532    #endif
533    #if defined(Q_OS_LINUX) && !defined(CONFIG_WAYLAND)
534            ::setenv("QT_QPA_PLATFORM", "xcb", 0);
535    #endif
536    #if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
537    #if QT_VERSION <  QT_VERSION_CHECK(6, 0, 0)
538            QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
539  #endif  #endif
540  #endif  #endif
541          qsamplerApplication app(argc, argv);          qsamplerApplication app(argc, argv);
# Line 373  int main ( int argc, char **argv ) Line 569  int main ( int argc, char **argv )
569                  return 2;                  return 2;
570          }          }
571    
572          // Dark themes grayed/disabled color group fix...          // Special custom styles...
573            if (QDir(CONFIG_PLUGINSDIR).exists())
574                    app.addLibraryPath(CONFIG_PLUGINSDIR);
575            if (!options.sCustomStyleTheme.isEmpty())
576                    app.setStyle(QStyleFactory::create(options.sCustomStyleTheme));
577    
578            // Custom color theme (eg. "KXStudio")...
579          QPalette pal(app.palette());          QPalette pal(app.palette());
580          if (pal.base().color().value() < 0x7f) {          if (QSampler::PaletteForm::namedPalette(
581          #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());  
582                  app.setPalette(pal);                  app.setPalette(pal);
         }  
583    
584          // Set default base font...          // Set default base font...
         int iBaseFontSize = app.font().pointSize();  
585          if (options.iBaseFontSize > 0)          if (options.iBaseFontSize > 0)
586                  iBaseFontSize = options.iBaseFontSize;                  app.setFont(QFont(app.font().family(), options.iBaseFontSize));
         app.setFont(QFont(app.font().family(), iBaseFontSize));  
587    
588          // Construct, setup and show the main form.          // Construct, setup and show the main form.
589          QSampler::MainForm w;          QSampler::MainForm w;
# Line 424  int main ( int argc, char **argv ) Line 601  int main ( int argc, char **argv )
601    
602    
603  // end of qsampler.cpp  // end of qsampler.cpp
604    

Legend:
Removed from v.2415  
changed lines
  Added in v.4030

  ViewVC Help
Powered by ViewVC