/[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 3996 by capela, Sun Sep 26 22:46:23 2021 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-2021, 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 defined(__APPLE__)  // Toshi Nagata 20080105  #if defined(__APPLE__)  // Toshi Nagata 20080105
39  #include <QDir>  #include <QDir>
40  #endif  #endif
41    
42  #if QT_VERSION < 0x040300  #ifndef CONFIG_PREFIX
43  #define lighter(x)      light(x)  #define CONFIG_PREFIX   "/usr/local"
 #define darker(x)       dark(x)  
44  #endif  #endif
45    
46  #define CONFIG_QUOTE1(x) #x  #ifndef CONFIG_DATADIR
47  #define CONFIG_QUOTED(x) CONFIG_QUOTE1(x)  #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 defined(LOCALEDIR)  #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
59  #define CONFIG_LOCALEDIR CONFIG_QUOTED(LOCALEDIR)  #define CONFIG_PLUGINSDIR CONFIG_LIBDIR "/qt4/plugins"
60    #elif QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
61    #define CONFIG_PLUGINSDIR CONFIG_LIBDIR "/qt5/plugins"
62  #else  #else
63  #define CONFIG_LOCALEDIR CONFIG_DATADIR "/locale"  #define CONFIG_PLUGINSDIR CONFIG_LIBDIR "/qt6/plugins"
64  #endif  #endif
65    
66  #if WIN32  #if defined(__WIN32__) || defined(_WIN32) || defined(WIN32)
67  #define RELATIVE_LOCALE_DIR "/share/locale"  #define RELATIVE_LOCALE_DIR "/share/locale"
68  #elif defined(__APPLE__)  #elif defined(__APPLE__)
69  #define RELATIVE_LOCALE_DIR "/../Resources"  #define RELATIVE_LOCALE_DIR "/../Resources"
# Line 63  Line 74 
74  // Singleton application instance stuff (Qt/X11 only atm.)  // Singleton application instance stuff (Qt/X11 only atm.)
75  //  //
76    
77  #if defined(Q_WS_X11)  #ifdef CONFIG_XUNIQUE
78    
79    #define QSAMPLER_XUNIQUE "qsamplerApplication"
80    
81    #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
82    #ifdef CONFIG_X11
83    
84  #include <QX11Info>  #include <unistd.h> /* for gethostname() */
85    
86  #include <X11/Xatom.h>  #include <X11/Xatom.h>
87  #include <X11/Xlib.h>  #include <X11/Xlib.h>
88    
89  #define QSAMPLER_XUNIQUE "qsamplerMainForm_xunique"  #endif  // CONFIG_X11
90    #else
91    #include <QSharedMemory>
92    #include <QLocalServer>
93    #include <QLocalSocket>
94    #include <QHostInfo>
95  #endif  #endif
96    
97  class qsamplerApplication : public QApplication  #endif  // CONFIG_XUNIQUE
 {  
 public:  
98    
99          // Constructor.  
100          qsamplerApplication(int& argc, char **argv) : QApplication(argc, argv),  // Constructor.
101                  m_pQtTranslator(0), m_pMyTranslator(0), m_pWidget(0)      qsamplerApplication::qsamplerApplication ( int& argc, char **argv )
102          {          : QApplication(argc, argv),
103                  // Load translation support.                  m_pQtTranslator(nullptr), m_pMyTranslator(nullptr), m_pWidget(nullptr)
104                  QLocale loc;  {
105                  if (loc.language() != QLocale::C) {  #if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0)
106                          // Try own Qt translation...          QApplication::setApplicationName(QSAMPLER_TITLE);
107                          m_pQtTranslator = new QTranslator(this);          QApplication::setApplicationDisplayName(QSAMPLER_TITLE);
108                          QString sLocName = "qt_" + loc.name();          //      QSAMPLER_TITLE " - " + QObject::tr(QSAMPLER_SUBTITLE));
109                          QString sLocPath = QLibraryInfo::location(QLibraryInfo::TranslationsPath);  #endif
110            // Load translation support.
111            QLocale loc;
112            if (loc.language() != QLocale::C) {
113                    // Try own Qt translation...
114                    m_pQtTranslator = new QTranslator(this);
115                    QString sLocName = "qt_" + loc.name();
116            #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
117                    QString sLocPath = QLibraryInfo::path(QLibraryInfo::TranslationsPath);
118            #else
119                    QString sLocPath = QLibraryInfo::location(QLibraryInfo::TranslationsPath);
120            #endif
121                    if (m_pQtTranslator->load(sLocName, sLocPath)) {
122                            QApplication::installTranslator(m_pQtTranslator);
123                    } else {
124                    #ifdef RELATIVE_LOCALE_DIR
125                            sLocPath = QApplication::applicationDirPath() + RELATIVE_LOCALE_DIR;
126                          if (m_pQtTranslator->load(sLocName, sLocPath)) {                          if (m_pQtTranslator->load(sLocName, sLocPath)) {
127                                  QApplication::installTranslator(m_pQtTranslator);                                  QApplication::installTranslator(m_pQtTranslator);
128                          } else {                          } else {
                 #ifdef RELATIVE_LOCALE_DIR  
                                 sLocPath = QApplication::applicationDirPath() + RELATIVE_LOCALE_DIR;  
                                 if (m_pQtTranslator->load(sLocName, sLocPath)) {  
                                         QApplication::installTranslator(m_pQtTranslator);  
                                 } else {  
129                  #endif                  #endif
130                                  delete m_pQtTranslator;                          delete m_pQtTranslator;
131                                  m_pQtTranslator = 0;                          m_pQtTranslator = nullptr;
132                  #ifdef CONFIG_DEBUG                  #ifdef CONFIG_DEBUG
133                                  qWarning("Warning: no translation found for '%s' locale: %s/%s.qm",                          qWarning("Warning: no translation found for '%s' locale: %s/%s.qm",
134                                          loc.name().toUtf8().constData(),                                  loc.name().toUtf8().constData(),
135                                          sLocPath.toUtf8().constData(),                                  sLocPath.toUtf8().constData(),
136                                          sLocName.toUtf8().constData());                                  sLocName.toUtf8().constData());
137                  #endif                  #endif
138                  #ifdef RELATIVE_LOCALE_DIR                  #ifdef RELATIVE_LOCALE_DIR
                                 }  
                 #endif  
139                          }                          }
140                          // Try own application translation...                  #endif
141                          m_pMyTranslator = new QTranslator(this);                  }
142                          sLocName = "qsampler_" + loc.name();                  // Try own application translation...
143                          if (m_pMyTranslator->load(sLocName, sLocPath)) {                  m_pMyTranslator = new QTranslator(this);
144                                  QApplication::installTranslator(m_pMyTranslator);                  sLocName = "qsampler_" + loc.name();
145                          } else {                  if (m_pMyTranslator->load(sLocName, sLocPath)) {
146                            QApplication::installTranslator(m_pMyTranslator);
147                    } else {
148                  #ifdef RELATIVE_LOCALE_DIR                  #ifdef RELATIVE_LOCALE_DIR
149                                  sLocPath = QApplication::applicationDirPath() + RELATIVE_LOCALE_DIR;                          sLocPath = QApplication::applicationDirPath() + RELATIVE_LOCALE_DIR;
150                  #else                  #else
151                                  sLocPath = CONFIG_LOCALEDIR;                          sLocPath = CONFIG_DATADIR "/qsampler/translations";
152                  #endif                  #endif
153                                  if (m_pMyTranslator->load(sLocName, sLocPath)) {                          if (m_pMyTranslator->load(sLocName, sLocPath)) {
154                                          QApplication::installTranslator(m_pMyTranslator);                                  QApplication::installTranslator(m_pMyTranslator);
155                                  } else {                          } else {
156                                          delete m_pMyTranslator;                                  delete m_pMyTranslator;
157                                          m_pMyTranslator = 0;                                  m_pMyTranslator = nullptr;
158                  #ifdef CONFIG_DEBUG                          #ifdef CONFIG_DEBUG
159                                          qWarning("Warning: no translation found for '%s' locale: %s/%s.qm",                                  qWarning("Warning: no translation found for '%s' locale: %s/%s.qm",
160                                                  loc.name().toUtf8().constData(),                                          loc.name().toUtf8().constData(),
161                                                  sLocPath.toUtf8().constData(),                                          sLocPath.toUtf8().constData(),
162                                                  sLocName.toUtf8().constData());                                          sLocName.toUtf8().constData());
163                  #endif                          #endif
                                 }  
164                          }                          }
165                  }                  }
         #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  
166          }          }
167    #ifdef CONFIG_XUNIQUE
168    #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
169    #ifdef CONFIG_X11
170            m_pDisplay = nullptr;
171            m_aUnique = 0;
172            m_wOwner = 0;
173    #endif  // CONFIG_X11
174    #else
175            m_pMemory = nullptr;
176            m_pServer = nullptr;
177    #endif
178    #endif  // CONFIG_XUNIQUE
179    }
180    
181          // Destructor.  
182          ~qsamplerApplication()  // Destructor.
183          {  qsamplerApplication::~qsamplerApplication (void)
184                  if (m_pMyTranslator) delete m_pMyTranslator;  {
185                  if (m_pQtTranslator) delete m_pQtTranslator;  #ifdef CONFIG_XUNIQUE
186    #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
187            if (m_pServer) {
188                    m_pServer->close();
189                    delete m_pServer;
190                    m_pServer = nullptr;
191          }          }
192            if (m_pMemory) {
193                    delete m_pMemory;
194                    m_pMemory = nullptr;
195    }
196    #endif
197    #endif  // CONFIG_XUNIQUE
198            if (m_pMyTranslator) delete m_pMyTranslator;
199            if (m_pQtTranslator) delete m_pQtTranslator;
200    }
201    
202          // Main application widget accessors.  
203          void setMainWidget(QWidget *pWidget)  // Main application widget accessors.
204          {  void qsamplerApplication::setMainWidget ( QWidget *pWidget )
205                  m_pWidget = pWidget;  {
206          #if defined(Q_WS_X11)          m_pWidget = pWidget;
207    #ifdef CONFIG_XUNIQUE
208    #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
209    #ifdef CONFIG_X11
210            m_wOwner = m_pWidget->winId();
211            if (m_pDisplay && m_wOwner) {
212                  XGrabServer(m_pDisplay);                  XGrabServer(m_pDisplay);
                 m_wOwner = m_pWidget->winId();  
213                  XSetSelectionOwner(m_pDisplay, m_aUnique, m_wOwner, CurrentTime);                  XSetSelectionOwner(m_pDisplay, m_aUnique, m_wOwner, CurrentTime);
214                  XUngrabServer(m_pDisplay);                  XUngrabServer(m_pDisplay);
         #endif  
215          }          }
216    #endif  // CONFIG_X11
217    #endif
218    #endif  // CONFIG_XUNIQUE
219    }
220    
         QWidget *mainWidget() const { return m_pWidget; }  
221    
222          // Check if another instance is running,  // Check if another instance is running,
223      // and raise its proper main widget...  // and raise its proper main widget...
224          bool setup()  bool qsamplerApplication::setup (void)
225          {  {
226          #if defined(Q_WS_X11)  #ifdef CONFIG_XUNIQUE
227    #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
228    #ifdef CONFIG_X11
229            m_pDisplay = QX11Info::display();
230            if (m_pDisplay) {
231                    QString sUnique = QSAMPLER_XUNIQUE;
232                    char szHostName[255];
233                    if (::gethostname(szHostName, sizeof(szHostName)) == 0) {
234                            sUnique += '@';
235                            sUnique += szHostName;
236                    }
237                    m_aUnique = XInternAtom(m_pDisplay, sUnique.toUtf8().constData(), false);
238                    XGrabServer(m_pDisplay);
239                    m_wOwner = XGetSelectionOwner(m_pDisplay, m_aUnique);
240                    XUngrabServer(m_pDisplay);
241                  if (m_wOwner != None) {                  if (m_wOwner != None) {
242                          // First, notify any freedesktop.org WM                          // First, notify any freedesktop.org WM
243                          // that we're about to show the main widget...                          // that we're about to show the main widget...
# Line 193  public: Line 261  public:
261                          XSync(m_pDisplay, false);                          XSync(m_pDisplay, false);
262                          XRaiseWindow(m_pDisplay, m_wOwner);                          XRaiseWindow(m_pDisplay, m_wOwner);
263                          // And then, let it get caught on destination                          // And then, let it get caught on destination
264                          // by QApplication::x11EventFilter...                          // by QApplication::native/x11EventFilter...
265                          QByteArray value = QSAMPLER_XUNIQUE;                          const QByteArray value = QSAMPLER_XUNIQUE;
266                          XChangeProperty(                          XChangeProperty(
267                                  m_pDisplay,                                  m_pDisplay,
268                                  m_wOwner,                                  m_wOwner,
# Line 206  public: Line 274  public:
274                          // Done.                          // Done.
275                          return true;                          return true;
276                  }                  }
         #endif  
                 return false;  
277          }          }
278    #endif  // CONFIG_X11
279  #if defined(Q_WS_X11)          return false;
280          bool x11EventFilter(XEvent *pEv)  #else
281          {          m_sUnique = QCoreApplication::applicationName();
282                  if (m_pWidget && m_wOwner != None          m_sUnique += '@';
283                          && pEv->type == PropertyNotify          m_sUnique += QHostInfo::localHostName();
284                          && pEv->xproperty.window == m_wOwner  #ifdef Q_OS_UNIX
285                          && pEv->xproperty.state == PropertyNewValue) {          m_pMemory = new QSharedMemory(m_sUnique);
286                          // Always check whether our property-flag is still around...          m_pMemory->attach();
287                          Atom aType;          delete m_pMemory;
288                          int iFormat = 0;  #endif
289                          unsigned long iItems = 0;          m_pMemory = new QSharedMemory(m_sUnique);
290                          unsigned long iAfter = 0;          bool bServer = false;
291                          unsigned char *pData = 0;          const qint64 pid = QCoreApplication::applicationPid();
292                          if (XGetWindowProperty(          struct Data { qint64 pid; };
293                                          m_pDisplay,          if (m_pMemory->create(sizeof(Data))) {
294                                          m_wOwner,                  m_pMemory->lock();
295                                          m_aUnique,                  Data *pData = static_cast<Data *> (m_pMemory->data());
296                                          0, 1024,                  if (pData) {
297                                          false,                          pData->pid = pid;
298                                          m_aUnique,                          bServer = true;
                                         &aType,  
                                         &iFormat,  
                                         &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);  
299                  }                  }
300                  return QApplication::x11EventFilter(pEv);                  m_pMemory->unlock();
301            }
302            else
303            if (m_pMemory->attach()) {
304                    m_pMemory->lock(); // maybe not necessary?
305                    Data *pData = static_cast<Data *> (m_pMemory->data());
306                    if (pData)
307                            bServer = (pData->pid == pid);
308                    m_pMemory->unlock();
309          }          }
310            if (bServer) {
311                    QLocalServer::removeServer(m_sUnique);
312                    m_pServer = new QLocalServer();
313                    m_pServer->setSocketOptions(QLocalServer::UserAccessOption);
314                    m_pServer->listen(m_sUnique);
315                    QObject::connect(m_pServer,
316                            SIGNAL(newConnection()),
317                            SLOT(newConnectionSlot()));
318            } else {
319                    QLocalSocket socket;
320                    socket.connectToServer(m_sUnique);
321                    if (socket.state() == QLocalSocket::ConnectingState)
322                            socket.waitForConnected(200);
323                    if (socket.state() == QLocalSocket::ConnectedState) {
324                            socket.write(QCoreApplication::arguments().join(' ').toUtf8());
325                            socket.flush();
326                            socket.waitForBytesWritten(200);
327                    }
328            }
329            return !bServer;
330  #endif  #endif
331            #else
332  private:          return false;
333    #endif  // !CONFIG_XUNIQUE
334    }
335    
         // Translation support.  
         QTranslator *m_pQtTranslator;  
         QTranslator *m_pMyTranslator;  
336    
337          // Instance variables.  #ifdef CONFIG_XUNIQUE
338          QWidget *m_pWidget;  #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
339    #ifdef CONFIG_X11
340    
341    void qsamplerApplication::x11PropertyNotify ( Window w )
342    {
343            if (m_pDisplay && m_pWidget && m_wOwner == w) {
344                    // Always check whether our property-flag is still around...
345                    Atom aType;
346                    int iFormat = 0;
347                    unsigned long iItems = 0;
348                    unsigned long iAfter = 0;
349                    unsigned char *pData = 0;
350                    if (XGetWindowProperty(
351                                    m_pDisplay,
352                                    m_wOwner,
353                                    m_aUnique,
354                                    0, 1024,
355                                    false,
356                                    m_aUnique,
357                                    &aType,
358                                    &iFormat,
359                                    &iItems,
360                                    &iAfter,
361                                    &pData) == Success
362                            && aType == m_aUnique && iItems > 0 && iAfter == 0) {
363                            // Avoid repeating it-self...
364                            XDeleteProperty(m_pDisplay, m_wOwner, m_aUnique);
365                            // Just make it always shows up fine...
366                            m_pWidget->show();
367                            m_pWidget->raise();
368                            m_pWidget->activateWindow();
369                    }
370                    // Free any left-overs...
371                    if (iItems > 0 && pData)
372                            XFree(pData);
373            }
374    }
375    
376    
377    bool qsamplerApplication::x11EventFilter ( XEvent *pEv )
378    {
379            if (pEv->type == PropertyNotify
380                    && pEv->xproperty.state == PropertyNewValue)
381                    x11PropertyNotify(pEv->xproperty.window);
382            return QApplication::x11EventFilter(pEv);
383    }
384    
385    #endif  // CONFIG_X11
386    #else
387    
388    // Local server conection slot.
389    void qsamplerApplication::newConnectionSlot (void)
390    {
391            QLocalSocket *pSocket = m_pServer->nextPendingConnection();
392            QObject::connect(pSocket,
393                    SIGNAL(readyRead()),
394                    SLOT(readyReadSlot()));
395    }
396    
397    // Local server data-ready slot.
398    void qsamplerApplication::readyReadSlot (void)
399    {
400            QLocalSocket *pSocket = qobject_cast<QLocalSocket *> (sender());
401            if (pSocket) {
402                    const qint64 nread = pSocket->bytesAvailable();
403                    if (nread > 0) {
404                            const QByteArray data = pSocket->read(nread);
405                            // Just make it always shows up fine...
406                            m_pWidget->hide();
407                            m_pWidget->show();
408                            m_pWidget->raise();
409                            m_pWidget->activateWindow();
410                    }
411            }
412    }
413    
 #if defined(Q_WS_X11)  
         Display *m_pDisplay;  
         Atom     m_aUnique;  
         Window   m_wOwner;  
414  #endif  #endif
415  };  #endif  // CONFIG_XUNIQUE
416    
417    
418  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
# Line 289  void stacktrace ( int signo ) Line 436  void stacktrace ( int signo )
436          char cmd[80];          char cmd[80];
437    
438          // Reinstall default handler; prevent race conditions...          // Reinstall default handler; prevent race conditions...
439          signal(signo, SIG_DFL);          ::signal(signo, SIG_DFL);
440    
441          static const char *shell  = "/bin/sh";          static const char *shell  = "/bin/sh";
442          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 452  void stacktrace ( int signo )
452    
453          // Fork child...          // Fork child...
454          if (pid == 0) {          if (pid == 0) {
455                  execl(shell, shell, "-c", cmd, NULL);                  execl(shell, shell, "-c", cmd, nullptr);
456                  _exit(1);                  _exit(1);
457                  return;                  return;
458          }          }
# Line 335  int main ( int argc, char **argv ) Line 482  int main ( int argc, char **argv )
482          Q_INIT_RESOURCE(qsampler);          Q_INIT_RESOURCE(qsampler);
483  #ifdef CONFIG_STACKTRACE  #ifdef CONFIG_STACKTRACE
484  #if defined(__GNUC__) && defined(Q_OS_LINUX)  #if defined(__GNUC__) && defined(Q_OS_LINUX)
485          signal(SIGILL,  stacktrace);          ::signal(SIGILL,  stacktrace);
486          signal(SIGFPE,  stacktrace);          ::signal(SIGFPE,  stacktrace);
487          signal(SIGSEGV, stacktrace);          ::signal(SIGSEGV, stacktrace);
488          signal(SIGABRT, stacktrace);          ::signal(SIGABRT, stacktrace);
489          signal(SIGBUS,  stacktrace);          ::signal(SIGBUS,  stacktrace);
490    #endif
491    #endif
492    #if defined(Q_OS_LINUX)
493            ::setenv("QT_QPA_PLATFORM", "xcb", 0);
494    #endif
495    #if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
496    #if QT_VERSION <  QT_VERSION_CHECK(6, 0, 0)
497            QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
498  #endif  #endif
499  #endif  #endif
500          qsamplerApplication app(argc, argv);          qsamplerApplication app(argc, argv);
# Line 373  int main ( int argc, char **argv ) Line 528  int main ( int argc, char **argv )
528                  return 2;                  return 2;
529          }          }
530    
531          // Dark themes grayed/disabled color group fix...          // Special custom styles...
532            if (QDir(CONFIG_PLUGINSDIR).exists())
533                    app.addLibraryPath(CONFIG_PLUGINSDIR);
534            if (!options.sCustomStyleTheme.isEmpty())
535                    app.setStyle(QStyleFactory::create(options.sCustomStyleTheme));
536    
537            // Custom color theme (eg. "KXStudio")...
538          QPalette pal(app.palette());          QPalette pal(app.palette());
539          if (pal.base().color().value() < 0x7f) {          if (QSampler::PaletteForm::namedPalette(
540          #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());  
541                  app.setPalette(pal);                  app.setPalette(pal);
         }  
542    
543          // Set default base font...          // Set default base font...
         int iBaseFontSize = app.font().pointSize();  
544          if (options.iBaseFontSize > 0)          if (options.iBaseFontSize > 0)
545                  iBaseFontSize = options.iBaseFontSize;                  app.setFont(QFont(app.font().family(), options.iBaseFontSize));
         app.setFont(QFont(app.font().family(), iBaseFontSize));  
546    
547          // Construct, setup and show the main form.          // Construct, setup and show the main form.
548          QSampler::MainForm w;          QSampler::MainForm w;
# Line 424  int main ( int argc, char **argv ) Line 560  int main ( int argc, char **argv )
560    
561    
562  // end of qsampler.cpp  // end of qsampler.cpp
563    

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

  ViewVC Help
Powered by ViewVC