/[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 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-2013, 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>
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  #else  #else
61  #define CONFIG_LOCALEDIR CONFIG_DATADIR "/locale"  #define CONFIG_PLUGINSDIR CONFIG_LIBDIR "/qt5/plugins"
62  #endif  #endif
63    
64  #if WIN32  #if defined(__WIN32__) || defined(_WIN32) || defined(WIN32)
65  #define RELATIVE_LOCALE_DIR "/share/locale"  #define RELATIVE_LOCALE_DIR "/share/locale"
66  #elif defined(__APPLE__)  #elif defined(__APPLE__)
67  #define RELATIVE_LOCALE_DIR "/../Resources"  #define RELATIVE_LOCALE_DIR "/../Resources"
# Line 63  Line 72 
72  // Singleton application instance stuff (Qt/X11 only atm.)  // Singleton application instance stuff (Qt/X11 only atm.)
73  //  //
74    
75  #if defined(Q_WS_X11)  #ifdef CONFIG_XUNIQUE
76    
77    #define QSAMPLER_XUNIQUE "qsamplerApplication"
78    
79    #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
80    #ifdef CONFIG_X11
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 "qsamplerMainForm_xunique"  #endif  // CONFIG_X11
88    #else
89    #include <QSharedMemory>
90    #include <QLocalServer>
91    #include <QLocalSocket>
92    #include <QHostInfo>
93  #endif  #endif
94    
95  class qsamplerApplication : public QApplication  #endif  // CONFIG_XUNIQUE
 {  
 public:  
96    
97          // Constructor.  
98          qsamplerApplication(int& argc, char **argv) : QApplication(argc, argv),  // Constructor.
99                  m_pQtTranslator(0), m_pMyTranslator(0), m_pWidget(0)      qsamplerApplication::qsamplerApplication ( int& argc, char **argv )
100          {          : QApplication(argc, argv),
101                  // Load translation support.                  m_pQtTranslator(nullptr), m_pMyTranslator(nullptr), m_pWidget(nullptr)
102                  QLocale loc;  {
103                  if (loc.language() != QLocale::C) {  #if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0)
104                          // Try own Qt translation...          QApplication::setApplicationName(QSAMPLER_TITLE);
105                          m_pQtTranslator = new QTranslator(this);          QApplication::setApplicationDisplayName(QSAMPLER_TITLE);
106                          QString sLocName = "qt_" + loc.name();          //      QSAMPLER_TITLE " - " + QObject::tr(QSAMPLER_SUBTITLE));
107                          QString sLocPath = QLibraryInfo::location(QLibraryInfo::TranslationsPath);  #endif
108            // Load translation support.
109            QLocale loc;
110            if (loc.language() != QLocale::C) {
111                    // Try own Qt translation...
112                    m_pQtTranslator = new QTranslator(this);
113                    QString sLocName = "qt_" + loc.name();
114                    QString sLocPath = QLibraryInfo::location(QLibraryInfo::TranslationsPath);
115                    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 {
                 #ifdef RELATIVE_LOCALE_DIR  
                                 sLocPath = QApplication::applicationDirPath() + RELATIVE_LOCALE_DIR;  
                                 if (m_pQtTranslator->load(sLocName, sLocPath)) {  
                                         QApplication::installTranslator(m_pQtTranslator);  
                                 } else {  
123                  #endif                  #endif
124                                  delete m_pQtTranslator;                          delete m_pQtTranslator;
125                                  m_pQtTranslator = 0;                          m_pQtTranslator = 0;
126                  #ifdef CONFIG_DEBUG                  #ifdef CONFIG_DEBUG
127                                  qWarning("Warning: no translation found for '%s' locale: %s/%s.qm",                          qWarning("Warning: no translation found for '%s' locale: %s/%s.qm",
128                                          loc.name().toUtf8().constData(),                                  loc.name().toUtf8().constData(),
129                                          sLocPath.toUtf8().constData(),                                  sLocPath.toUtf8().constData(),
130                                          sLocName.toUtf8().constData());                                  sLocName.toUtf8().constData());
131                  #endif                  #endif
132                  #ifdef RELATIVE_LOCALE_DIR                  #ifdef RELATIVE_LOCALE_DIR
                                 }  
                 #endif  
133                          }                          }
134                          // Try own application translation...                  #endif
135                          m_pMyTranslator = new QTranslator(this);                  }
136                          sLocName = "qsampler_" + loc.name();                  // Try own application translation...
137                          if (m_pMyTranslator->load(sLocName, sLocPath)) {                  m_pMyTranslator = new QTranslator(this);
138                                  QApplication::installTranslator(m_pMyTranslator);                  sLocName = "qsampler_" + loc.name();
139                          } else {                  if (m_pMyTranslator->load(sLocName, sLocPath)) {
140                            QApplication::installTranslator(m_pMyTranslator);
141                    } else {
142                  #ifdef RELATIVE_LOCALE_DIR                  #ifdef RELATIVE_LOCALE_DIR
143                                  sLocPath = QApplication::applicationDirPath() + RELATIVE_LOCALE_DIR;                          sLocPath = QApplication::applicationDirPath() + RELATIVE_LOCALE_DIR;
144                  #else                  #else
145                                  sLocPath = CONFIG_LOCALEDIR;                          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());  
146                  #endif                  #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
153                                    qWarning("Warning: no translation found for '%s' locale: %s/%s.qm",
154                                            loc.name().toUtf8().constData(),
155                                            sLocPath.toUtf8().constData(),
156                                            sLocName.toUtf8().constData());
157                            #endif
158                          }                          }
159                  }                  }
         #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  
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    
175          // Destructor.  
176          ~qsamplerApplication()  // Destructor.
177          {  qsamplerApplication::~qsamplerApplication (void)
178                  if (m_pMyTranslator) delete m_pMyTranslator;  {
179                  if (m_pQtTranslator) delete m_pQtTranslator;  #ifdef CONFIG_XUNIQUE
180    #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
181            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          // Main application widget accessors.  
197          void setMainWidget(QWidget *pWidget)  // Main application widget accessors.
198          {  void qsamplerApplication::setMainWidget ( QWidget *pWidget )
199                  m_pWidget = pWidget;  {
200          #if defined(Q_WS_X11)          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  
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          #if defined(Q_WS_X11)  #ifdef CONFIG_XUNIQUE
221    #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 193  public: Line 255  public:
255                          XSync(m_pDisplay, false);                          XSync(m_pDisplay, false);
256                          XRaiseWindow(m_pDisplay, m_wOwner);                          XRaiseWindow(m_pDisplay, m_wOwner);
257                          // And then, let it get caught on destination                          // And then, let it get caught on destination
258                          // by QApplication::x11EventFilter...                          // by QApplication::native/x11EventFilter...
259                          QByteArray value = QSAMPLER_XUNIQUE;                          const QByteArray value = QSAMPLER_XUNIQUE;
260                          XChangeProperty(                          XChangeProperty(
261                                  m_pDisplay,                                  m_pDisplay,
262                                  m_wOwner,                                  m_wOwner,
# Line 206  public: Line 268  public:
268                          // Done.                          // Done.
269                          return true;                          return true;
270                  }                  }
         #endif  
                 return false;  
271          }          }
272    #endif  // CONFIG_X11
273  #if defined(Q_WS_X11)          return false;
274          bool x11EventFilter(XEvent *pEv)  #else
275          {          m_sUnique = QCoreApplication::applicationName();
276                  if (m_pWidget && m_wOwner != None          m_sUnique += '@';
277                          && pEv->type == PropertyNotify          m_sUnique += QHostInfo::localHostName();
278                          && pEv->xproperty.window == m_wOwner  #ifdef Q_OS_UNIX
279                          && pEv->xproperty.state == PropertyNewValue) {          m_pMemory = new QSharedMemory(m_sUnique);
280                          // Always check whether our property-flag is still around...          m_pMemory->attach();
281                          Atom aType;          delete m_pMemory;
282                          int iFormat = 0;  #endif
283                          unsigned long iItems = 0;          m_pMemory = new QSharedMemory(m_sUnique);
284                          unsigned long iAfter = 0;          bool bServer = false;
285                          unsigned char *pData = 0;          const qint64 pid = QCoreApplication::applicationPid();
286                          if (XGetWindowProperty(          struct Data { qint64 pid; };
287                                          m_pDisplay,          if (m_pMemory->create(sizeof(Data))) {
288                                          m_wOwner,                  m_pMemory->lock();
289                                          m_aUnique,                  Data *pData = static_cast<Data *> (m_pMemory->data());
290                                          0, 1024,                  if (pData) {
291                                          false,                          pData->pid = pid;
292                                          m_aUnique,                          bServer = true;
293                                          &aType,                  }
294                                          &iFormat,                  m_pMemory->unlock();
295                                          &iItems,          }
296                                          &iAfter,          else
297                                          &pData) == Success          if (m_pMemory->attach()) {
298                                  && aType == m_aUnique && iItems > 0 && iAfter == 0) {                  m_pMemory->lock(); // maybe not necessary?
299                                  // Avoid repeating it-self...                  Data *pData = static_cast<Data *> (m_pMemory->data());
300                                  XDeleteProperty(m_pDisplay, m_wOwner, m_aUnique);                  if (pData)
301                                  // Just make it always shows up fine...                          bServer = (pData->pid == pid);
302                                  m_pWidget->show();                  m_pMemory->unlock();
303                                  m_pWidget->raise();          }
304                                  m_pWidget->activateWindow();          if (bServer) {
305                          }                  QLocalServer::removeServer(m_sUnique);
306                          // Free any left-overs...                  m_pServer = new QLocalServer();
307                          if (iItems > 0 && pData)                  m_pServer->setSocketOptions(QLocalServer::UserAccessOption);
308                                  XFree(pData);                  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                  }                  }
                 return QApplication::x11EventFilter(pEv);  
322          }          }
323            return !bServer;
324  #endif  #endif
325            #else
326  private:          return false;
327    #endif  // !CONFIG_XUNIQUE
328    }
329    
330    
331    #ifdef CONFIG_XUNIQUE
332    #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
333    #ifdef CONFIG_X11
334    
335    void qsamplerApplication::x11PropertyNotify ( Window w )
336    {
337            if (m_pDisplay && m_pWidget && m_wOwner == w) {
338                    // 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    
         // Translation support.  
         QTranslator *m_pQtTranslator;  
         QTranslator *m_pMyTranslator;  
370    
371          // Instance variables.  bool qsamplerApplication::x11EventFilter ( XEvent *pEv )
372          QWidget *m_pWidget;  {
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
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    // Local server data-ready slot.
392    void qsamplerApplication::readyReadSlot (void)
393    {
394            QLocalSocket *pSocket = qobject_cast<QLocalSocket *> (sender());
395            if (pSocket) {
396                    const qint64 nread = pSocket->bytesAvailable();
397                    if (nread > 0) {
398                            const QByteArray data = pSocket->read(nread);
399                            // 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            }
406    }
407    
 #if defined(Q_WS_X11)  
         Display *m_pDisplay;  
         Atom     m_aUnique;  
         Window   m_wOwner;  
408  #endif  #endif
409  };  #endif  // CONFIG_XUNIQUE
410    
411    
412  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
# Line 289  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 305  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 335  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 373  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...
         int iBaseFontSize = app.font().pointSize();  
533          if (options.iBaseFontSize > 0)          if (options.iBaseFontSize > 0)
534                  iBaseFontSize = options.iBaseFontSize;                  app.setFont(QFont(app.font().family(), options.iBaseFontSize));
         app.setFont(QFont(app.font().family(), iBaseFontSize));  
535    
536          // Construct, setup and show the main form.          // Construct, setup and show the main form.
537          QSampler::MainForm w;          QSampler::MainForm w;
# Line 424  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.2415  
changed lines
  Added in v.3648

  ViewVC Help
Powered by ViewVC