/[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 2839 by capela, Tue Aug 25 18:36:55 2015 UTC revision 3648 by capela, Tue Dec 10 10:34:06 2019 UTC
# Line 1  Line 1 
1  // qsampler.cpp  // qsampler.cpp
2  //  //
3  /****************************************************************************  /****************************************************************************
4     Copyright (C) 2004-2015, rncbc aka Rui Nuno Capela. All rights reserved.     Copyright (C) 2004-2019, rncbc aka Rui Nuno Capela. All rights reserved.
5     Copyright (C) 2007, 2008 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 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>
# Line 33  Line 39 
39  #include <QDir>  #include <QDir>
40  #endif  #endif
41    
42  #define CONFIG_QUOTE1(x) #x  #ifndef CONFIG_PREFIX
43  #define CONFIG_QUOTED(x) CONFIG_QUOTE1(x)  #define CONFIG_PREFIX   "/usr/local"
44    #endif
45    
46    #ifndef CONFIG_DATADIR
47    #define CONFIG_DATADIR  CONFIG_PREFIX "/share"
48    #endif
49    
50  #if defined(DATADIR)  #ifndef CONFIG_LIBDIR
51  #define CONFIG_DATADIR CONFIG_QUOTED(DATADIR)  #if defined(__x86_64__)
52    #define CONFIG_LIBDIR  CONFIG_PREFIX "/lib64"
53  #else  #else
54  #define CONFIG_DATADIR CONFIG_PREFIX "/share"  #define CONFIG_LIBDIR  CONFIG_PREFIX "/lib"
55    #endif
56  #endif  #endif
57    
58  #if WIN32  #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)
65  #define RELATIVE_LOCALE_DIR "/share/locale"  #define RELATIVE_LOCALE_DIR "/share/locale"
66  #elif defined(__APPLE__)  #elif defined(__APPLE__)
67  #define RELATIVE_LOCALE_DIR "/../Resources"  #define RELATIVE_LOCALE_DIR "/../Resources"
# Line 53  Line 72 
72  // Singleton application instance stuff (Qt/X11 only atm.)  // Singleton application instance stuff (Qt/X11 only atm.)
73  //  //
74    
75  #if QT_VERSION < 0x050000  #ifdef CONFIG_XUNIQUE
 #if defined(Q_WS_X11)  
 #define CONFIG_X11  
 #endif  
 #else  
 #if defined(QT_X11EXTRAS_LIB)  
 #define CONFIG_X11  
 #endif  
 #endif  
76    
77    #define QSAMPLER_XUNIQUE "qsamplerApplication"
78    
79    #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
80  #ifdef CONFIG_X11  #ifdef CONFIG_X11
 #ifdef CONFIG_XUNIQUE  
81    
82  #include <QX11Info>  #include <unistd.h> /* for gethostname() */
83    
84  #include <X11/Xatom.h>  #include <X11/Xatom.h>
85  #include <X11/Xlib.h>  #include <X11/Xlib.h>
86    
87  #define QSAMPLER_XUNIQUE "qsamplerApplication"  #endif  // CONFIG_X11
88    #else
89  #if QT_VERSION >= 0x050100  #include <QSharedMemory>
90    #include <QLocalServer>
91  #include <xcb/xcb.h>  #include <QLocalSocket>
92  #include <xcb/xproto.h>  #include <QHostInfo>
   
 #include <QAbstractNativeEventFilter>  
   
 class qsamplerApplication;  
   
 class qsamplerXcbEventFilter : public QAbstractNativeEventFilter  
 {  
 public:  
   
         // Constructor.  
         qsamplerXcbEventFilter(qsamplerApplication *pApp)  
                 : QAbstractNativeEventFilter(), m_pApp(pApp) {}  
   
         // XCB event filter (virtual processor).  
         bool nativeEventFilter(const QByteArray& eventType, void *message, long *);  
   
 private:  
   
         // Instance variable.  
         qsamplerApplication *m_pApp;  
 };  
   
93  #endif  #endif
94    
95  #endif  // CONFIG_XUNIQUE  #endif  // CONFIG_XUNIQUE
 #endif  // CONFIG_X11  
96    
97    
98  class qsamplerApplication : public QApplication  // Constructor.
99    qsamplerApplication::qsamplerApplication ( int& argc, char **argv )
100            : QApplication(argc, argv),
101                    m_pQtTranslator(nullptr), m_pMyTranslator(nullptr), m_pWidget(nullptr)
102  {  {
103  public:  #if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0)
104            QApplication::setApplicationName(QSAMPLER_TITLE);
105          // Constructor.          QApplication::setApplicationDisplayName(QSAMPLER_TITLE);
106          qsamplerApplication(int& argc, char **argv) : QApplication(argc, argv),          //      QSAMPLER_TITLE " - " + QObject::tr(QSAMPLER_SUBTITLE));
107                  m_pQtTranslator(0), m_pMyTranslator(0), m_pWidget(0)  #endif
108          {          // Load translation support.
109                  // Load translation support.          QLocale loc;
110                  QLocale loc;          if (loc.language() != QLocale::C) {
111                  if (loc.language() != QLocale::C) {                  // Try own Qt translation...
112                          // Try own Qt translation...                  m_pQtTranslator = new QTranslator(this);
113                          m_pQtTranslator = new QTranslator(this);                  QString sLocName = "qt_" + loc.name();
114                          QString sLocName = "qt_" + loc.name();                  QString sLocPath = QLibraryInfo::location(QLibraryInfo::TranslationsPath);
115                          QString sLocPath = QLibraryInfo::location(QLibraryInfo::TranslationsPath);                  if (m_pQtTranslator->load(sLocName, sLocPath)) {
116                            QApplication::installTranslator(m_pQtTranslator);
117                    } else {
118                    #ifdef RELATIVE_LOCALE_DIR
119                            sLocPath = QApplication::applicationDirPath() + RELATIVE_LOCALE_DIR;
120                          if (m_pQtTranslator->load(sLocName, sLocPath)) {                          if (m_pQtTranslator->load(sLocName, sLocPath)) {
121                                  QApplication::installTranslator(m_pQtTranslator);                                  QApplication::installTranslator(m_pQtTranslator);
122                          } else {                          } else {
123                          #ifdef RELATIVE_LOCALE_DIR                  #endif
124                                  sLocPath = QApplication::applicationDirPath() + RELATIVE_LOCALE_DIR;                          delete m_pQtTranslator;
125                                  if (m_pQtTranslator->load(sLocName, sLocPath)) {                          m_pQtTranslator = 0;
126                                          QApplication::installTranslator(m_pQtTranslator);                  #ifdef CONFIG_DEBUG
127                                  } else {                          qWarning("Warning: no translation found for '%s' locale: %s/%s.qm",
128                          #endif                                  loc.name().toUtf8().constData(),
129                                  delete m_pQtTranslator;                                  sLocPath.toUtf8().constData(),
130                                  m_pQtTranslator = 0;                                  sLocName.toUtf8().constData());
131                    #endif
132                    #ifdef RELATIVE_LOCALE_DIR
133                            }
134                    #endif
135                    }
136                    // Try own application translation...
137                    m_pMyTranslator = new QTranslator(this);
138                    sLocName = "qsampler_" + loc.name();
139                    if (m_pMyTranslator->load(sLocName, sLocPath)) {
140                            QApplication::installTranslator(m_pMyTranslator);
141                    } else {
142                    #ifdef RELATIVE_LOCALE_DIR
143                            sLocPath = QApplication::applicationDirPath() + RELATIVE_LOCALE_DIR;
144                    #else
145                            sLocPath = CONFIG_DATADIR "/qsampler/translations";
146                    #endif
147                            if (m_pMyTranslator->load(sLocName, sLocPath)) {
148                                    QApplication::installTranslator(m_pMyTranslator);
149                            } else {
150                                    delete m_pMyTranslator;
151                                    m_pMyTranslator = 0;
152                          #ifdef CONFIG_DEBUG                          #ifdef CONFIG_DEBUG
153                                  qWarning("Warning: no translation found for '%s' locale: %s/%s.qm",                                  qWarning("Warning: no translation found for '%s' locale: %s/%s.qm",
154                                          loc.name().toUtf8().constData(),                                          loc.name().toUtf8().constData(),
155                                          sLocPath.toUtf8().constData(),                                          sLocPath.toUtf8().constData(),
156                                          sLocName.toUtf8().constData());                                          sLocName.toUtf8().constData());
157                          #endif                          #endif
                         #ifdef RELATIVE_LOCALE_DIR  
                                 }  
                         #endif  
                         }  
                         // Try own application translation...  
                         m_pMyTranslator = new QTranslator(this);  
                         sLocName = "qsampler_" + loc.name();  
                         if (m_pMyTranslator->load(sLocName, sLocPath)) {  
                                 QApplication::installTranslator(m_pMyTranslator);  
                         } else {  
                         #ifdef RELATIVE_LOCALE_DIR  
                                 sLocPath = QApplication::applicationDirPath() + RELATIVE_LOCALE_DIR;  
                         #else  
                                 sLocPath = CONFIG_DATADIR "/qsampler/translations";  
                         #endif  
                                 if (m_pMyTranslator->load(sLocName, sLocPath)) {  
                                         QApplication::installTranslator(m_pMyTranslator);  
                                 } else {  
                                         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  
                                 }  
158                          }                          }
159                  }                  }
         #ifdef CONFIG_X11  
         #ifdef CONFIG_XUNIQUE  
                 // Instance uniqueness initialization...  
                 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);  
         #if QT_VERSION >= 0x050100  
                 m_pXcbEventFilter = new qsamplerXcbEventFilter(this);  
                 installNativeEventFilter(m_pXcbEventFilter);  
         #endif  
         #endif  // CONFIG_XUNIQUE  
         #endif  // CONFIG_X11  
160          }          }
161    #ifdef CONFIG_XUNIQUE
162    #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
163    #ifdef CONFIG_X11
164            m_pDisplay = nullptr;
165            m_aUnique = 0;
166            m_wOwner = 0;
167    #endif  // CONFIG_X11
168    #else
169            m_pMemory = nullptr;
170            m_pServer = nullptr;
171    #endif
172    #endif  // CONFIG_XUNIQUE
173    }
174    
         // Destructor.  
         ~qsamplerApplication()  
         {  
         #ifdef CONFIG_X11  
         #ifdef CONFIG_XUNIQUE  
         #if QT_VERSION >= 0x050100  
                 removeNativeEventFilter(m_pXcbEventFilter);  
                 delete m_pXcbEventFilter;  
         #endif  
         #endif  // CONFIG_XUNIQUE  
         #endif  // CONFIG_X11  
                 if (m_pMyTranslator) delete m_pMyTranslator;  
                 if (m_pQtTranslator) delete m_pQtTranslator;  
         }  
175    
176          // Main application widget accessors.  // Destructor.
177          void setMainWidget(QWidget *pWidget)  qsamplerApplication::~qsamplerApplication (void)
178          {  {
179                  m_pWidget = pWidget;  #ifdef CONFIG_XUNIQUE
180          #ifdef CONFIG_X11  #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
181          #ifdef CONFIG_XUNIQUE          if (m_pServer) {
182                    m_pServer->close();
183                    delete m_pServer;
184                    m_pServer = nullptr;
185            }
186            if (m_pMemory) {
187                    delete m_pMemory;
188                    m_pMemory = nullptr;
189    }
190    #endif
191    #endif  // CONFIG_XUNIQUE
192            if (m_pMyTranslator) delete m_pMyTranslator;
193            if (m_pQtTranslator) delete m_pQtTranslator;
194    }
195    
196    
197    // Main application widget accessors.
198    void qsamplerApplication::setMainWidget ( QWidget *pWidget )
199    {
200            m_pWidget = pWidget;
201    #ifdef CONFIG_XUNIQUE
202    #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
203    #ifdef CONFIG_X11
204            m_wOwner = m_pWidget->winId();
205            if (m_pDisplay && m_wOwner) {
206                  XGrabServer(m_pDisplay);                  XGrabServer(m_pDisplay);
                 m_wOwner = m_pWidget->winId();  
207                  XSetSelectionOwner(m_pDisplay, m_aUnique, m_wOwner, CurrentTime);                  XSetSelectionOwner(m_pDisplay, m_aUnique, m_wOwner, CurrentTime);
208                  XUngrabServer(m_pDisplay);                  XUngrabServer(m_pDisplay);
         #endif  // CONFIG_XUNIQUE  
         #endif  // CONFIG_X11  
209          }          }
210    #endif  // CONFIG_X11
211    #endif
212    #endif  // CONFIG_XUNIQUE
213    }
214    
         QWidget *mainWidget() const { return m_pWidget; }  
215    
216          // Check if another instance is running,  // Check if another instance is running,
217      // and raise its proper main widget...  // and raise its proper main widget...
218          bool setup()  bool qsamplerApplication::setup (void)
219          {  {
220          #ifdef CONFIG_X11  #ifdef CONFIG_XUNIQUE
221          #ifdef CONFIG_XUNIQUE  #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
222    #ifdef CONFIG_X11
223            m_pDisplay = QX11Info::display();
224            if (m_pDisplay) {
225                    QString sUnique = QSAMPLER_XUNIQUE;
226                    char szHostName[255];
227                    if (::gethostname(szHostName, sizeof(szHostName)) == 0) {
228                            sUnique += '@';
229                            sUnique += szHostName;
230                    }
231                    m_aUnique = XInternAtom(m_pDisplay, sUnique.toUtf8().constData(), false);
232                    XGrabServer(m_pDisplay);
233                    m_wOwner = XGetSelectionOwner(m_pDisplay, m_aUnique);
234                    XUngrabServer(m_pDisplay);
235                  if (m_wOwner != None) {                  if (m_wOwner != None) {
236                          // First, notify any freedesktop.org WM                          // First, notify any freedesktop.org WM
237                          // that we're about to show the main widget...                          // that we're about to show the main widget...
# Line 256  public: Line 268  public:
268                          // Done.                          // Done.
269                          return true;                          return true;
270                  }                  }
         #endif  // CONFIG_XUNIQUE  
         #endif  // CONFIG_X11  
                 return false;  
271          }          }
272    #endif  // CONFIG_X11
273  #ifdef CONFIG_X11          return false;
274  #ifdef CONFIG_XUNIQUE  #else
275          void x11PropertyNotify(Window w)          m_sUnique = QCoreApplication::applicationName();
276          {          m_sUnique += '@';
277                  if (m_pWidget && m_wOwner == w) {          m_sUnique += QHostInfo::localHostName();
278                          // Always check whether our property-flag is still around...  #ifdef Q_OS_UNIX
279                          Atom aType;          m_pMemory = new QSharedMemory(m_sUnique);
280                          int iFormat = 0;          m_pMemory->attach();
281                          unsigned long iItems = 0;          delete m_pMemory;
282                          unsigned long iAfter = 0;  #endif
283                          unsigned char *pData = 0;          m_pMemory = new QSharedMemory(m_sUnique);
284                          if (XGetWindowProperty(          bool bServer = false;
285                                          m_pDisplay,          const qint64 pid = QCoreApplication::applicationPid();
286                                          m_wOwner,          struct Data { qint64 pid; };
287                                          m_aUnique,          if (m_pMemory->create(sizeof(Data))) {
288                                          0, 1024,                  m_pMemory->lock();
289                                          false,                  Data *pData = static_cast<Data *> (m_pMemory->data());
290                                          m_aUnique,                  if (pData) {
291                                          &aType,                          pData->pid = pid;
292                                          &iFormat,                          bServer = true;
                                         &iItems,  
                                         &iAfter,  
                                         &pData) == Success  
                                 && aType == m_aUnique && iItems > 0 && iAfter == 0) {  
                                 // Avoid repeating it-self...  
                                 XDeleteProperty(m_pDisplay, m_wOwner, m_aUnique);  
                                 // Just make it always shows up fine...  
                                 m_pWidget->show();  
                                 m_pWidget->raise();  
                                 m_pWidget->activateWindow();  
                         }  
                         // Free any left-overs...  
                         if (iItems > 0 && pData)  
                                 XFree(pData);  
293                  }                  }
294                    m_pMemory->unlock();
295          }          }
296  #if QT_VERSION < 0x050000          else
297          bool x11EventFilter(XEvent *pEv)          if (m_pMemory->attach()) {
298          {                  m_pMemory->lock(); // maybe not necessary?
299                  if (pEv->type == PropertyNotify                  Data *pData = static_cast<Data *> (m_pMemory->data());
300                          && pEv->xproperty.state == PropertyNewValue)                  if (pData)
301                          x11PropertyNotify(pEv->xproperty.window);                          bServer = (pData->pid == pid);
302                  return QApplication::x11EventFilter(pEv);                  m_pMemory->unlock();
303            }
304            if (bServer) {
305                    QLocalServer::removeServer(m_sUnique);
306                    m_pServer = new QLocalServer();
307                    m_pServer->setSocketOptions(QLocalServer::UserAccessOption);
308                    m_pServer->listen(m_sUnique);
309                    QObject::connect(m_pServer,
310                            SIGNAL(newConnection()),
311                            SLOT(newConnectionSlot()));
312            } else {
313                    QLocalSocket socket;
314                    socket.connectToServer(m_sUnique);
315                    if (socket.state() == QLocalSocket::ConnectingState)
316                            socket.waitForConnected(200);
317                    if (socket.state() == QLocalSocket::ConnectedState) {
318                            socket.write(QCoreApplication::arguments().join(' ').toUtf8());
319                            socket.flush();
320                            socket.waitForBytesWritten(200);
321                    }
322          }          }
323            return !bServer;
324  #endif  #endif
325  #endif  // CONFIG_XUNIQUE  #else
326  #endif  // CONFIG_X11          return false;
327            #endif  // !CONFIG_XUNIQUE
328  private:  }
   
         // Translation support.  
         QTranslator *m_pQtTranslator;  
         QTranslator *m_pMyTranslator;  
329    
         // Instance variables.  
         QWidget *m_pWidget;  
330    
 #ifdef CONFIG_X11  
331  #ifdef CONFIG_XUNIQUE  #ifdef CONFIG_XUNIQUE
332          Display *m_pDisplay;  #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
333          Atom     m_aUnique;  #ifdef CONFIG_X11
334          Window   m_wOwner;  
335  #if QT_VERSION >= 0x050100  void qsamplerApplication::x11PropertyNotify ( Window w )
336          qsamplerXcbEventFilter *m_pXcbEventFilter;  {
337  #endif          if (m_pDisplay && m_pWidget && m_wOwner == w) {
338  #endif  // CONFIG_XUNIQUE                  // Always check whether our property-flag is still around...
339                    Atom aType;
340                    int iFormat = 0;
341                    unsigned long iItems = 0;
342                    unsigned long iAfter = 0;
343                    unsigned char *pData = 0;
344                    if (XGetWindowProperty(
345                                    m_pDisplay,
346                                    m_wOwner,
347                                    m_aUnique,
348                                    0, 1024,
349                                    false,
350                                    m_aUnique,
351                                    &aType,
352                                    &iFormat,
353                                    &iItems,
354                                    &iAfter,
355                                    &pData) == Success
356                            && aType == m_aUnique && iItems > 0 && iAfter == 0) {
357                            // Avoid repeating it-self...
358                            XDeleteProperty(m_pDisplay, m_wOwner, m_aUnique);
359                            // Just make it always shows up fine...
360                            m_pWidget->show();
361                            m_pWidget->raise();
362                            m_pWidget->activateWindow();
363                    }
364                    // Free any left-overs...
365                    if (iItems > 0 && pData)
366                            XFree(pData);
367            }
368    }
369    
370    
371    bool qsamplerApplication::x11EventFilter ( XEvent *pEv )
372    {
373            if (pEv->type == PropertyNotify
374                    && pEv->xproperty.state == PropertyNewValue)
375                    x11PropertyNotify(pEv->xproperty.window);
376            return QApplication::x11EventFilter(pEv);
377    }
378    
379  #endif  // CONFIG_X11  #endif  // CONFIG_X11
380  };  #else
381    
382    // Local server conection slot.
383    void qsamplerApplication::newConnectionSlot (void)
384    {
385            QLocalSocket *pSocket = m_pServer->nextPendingConnection();
386            QObject::connect(pSocket,
387                    SIGNAL(readyRead()),
388                    SLOT(readyReadSlot()));
389    }
390    
391  #ifdef CONFIG_X11  // Local server data-ready slot.
392  #ifdef CONFIG_XUNIQUE  void qsamplerApplication::readyReadSlot (void)
 #if QT_VERSION >= 0x050100  
 // XCB Event filter (virtual processor).  
 bool qsamplerXcbEventFilter::nativeEventFilter (  
         const QByteArray& eventType, void *message, long * )  
393  {  {
394          if (eventType == "xcb_generic_event_t") {          QLocalSocket *pSocket = qobject_cast<QLocalSocket *> (sender());
395                  xcb_property_notify_event_t *pEv          if (pSocket) {
396                          = static_cast<xcb_property_notify_event_t *> (message);                  const qint64 nread = pSocket->bytesAvailable();
397                  if ((pEv->response_type & ~0x80) == XCB_PROPERTY_NOTIFY                  if (nread > 0) {
398                          && pEv->state == XCB_PROPERTY_NEW_VALUE)                          const QByteArray data = pSocket->read(nread);
399                          m_pApp->x11PropertyNotify(pEv->window);                          // Just make it always shows up fine...
400                            m_pWidget->hide();
401                            m_pWidget->show();
402                            m_pWidget->raise();
403                            m_pWidget->activateWindow();
404                    }
405          }          }
         return false;  
406  }  }
407    
408  #endif  #endif
409  #endif  // CONFIG_XUNIQUE  #endif  // CONFIG_XUNIQUE
 #endif  // CONFIG_X11  
410    
411    
412  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
# Line 373  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 389  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 419  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    #if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
487            QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
488    #endif
489          qsamplerApplication app(argc, argv);          qsamplerApplication app(argc, argv);
490    
491          #if defined(__APPLE__)  //  Toshi Nagata 20080105          #if defined(__APPLE__)  //  Toshi Nagata 20080105
# Line 457  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)
# Line 506  int main ( int argc, char **argv ) Line 549  int main ( int argc, char **argv )
549    
550    
551  // end of qsampler.cpp  // end of qsampler.cpp
552    

Legend:
Removed from v.2839  
changed lines
  Added in v.3648

  ViewVC Help
Powered by ViewVC