QGIS API Documentation  3.6.0-Noosa (5873452)
qgsproxystyle.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsproxystyle.cpp
3  -----------------
4  Date : March 2018
5  Copyright : (C) 2018 by Nyall Dawson
6  Email : nyall dot dawson at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #include "qgsproxystyle.h"
17 #include "qgsimageoperation.h"
18 #include <QStyleFactory>
19 #include <QStyle>
20 #include <QStyleOption>
21 #include <QApplication>
22 
23 QgsProxyStyle::QgsProxyStyle( QWidget *parent )
24  : QProxyStyle( nullptr ) // no base style yet - it transfers ownership, so we need a NEW QStyle object for the base style
25 {
26  // get application style
27  const QString appStyle = QApplication::style()->objectName();
28  if ( appStyle == QLatin1String( "QgsAppStyle" ) )
29  {
30  setBaseStyle( static_cast< QgsAppStyle * >( QApplication::style() )->clone() );
31  }
32  else if ( !appStyle.isEmpty() )
33  {
34  if ( QStyle *style = QStyleFactory::create( appStyle ) )
35  setBaseStyle( style );
36  }
37 
38  // set lifetime to match parent widget's
39  setParent( parent );
40 }
41 
43 
44 //
45 // QgsAppStyle
46 //
47 
48 QgsAppStyle::QgsAppStyle( const QString &base )
49  : QProxyStyle( nullptr ) // no base style yet - it transfers ownership, so we need a NEW QStyle object for the base style
50  , mBaseStyle( base )
51 {
52  if ( !mBaseStyle.isEmpty() )
53  {
54  if ( QStyle *style = QStyleFactory::create( mBaseStyle ) )
55  setBaseStyle( style );
56  }
57 
58  setObjectName( QStringLiteral( "QgsAppStyle" ) );
59 }
60 
61 QPixmap QgsAppStyle::generatedIconPixmap( QIcon::Mode iconMode, const QPixmap &pixmap, const QStyleOption *opt ) const
62 {
63  switch ( iconMode )
64  {
65  case QIcon::Disabled:
66  {
67  // override disabled icon style, with something which works better across different light/dark themes.
68  // the default Qt style here only works nicely for light themes.
69  QImage im = pixmap.toImage().convertToFormat( QImage::Format_ARGB32 );
72  return QPixmap::fromImage( im );
73  }
74 
75  case QIcon::Normal:
76  case QIcon::Active:
77  case QIcon::Selected:
78  break;
79 
80  }
81  return QProxyStyle::generatedIconPixmap( iconMode, pixmap, opt );
82 }
83 
84 QProxyStyle *QgsAppStyle::clone()
85 {
86  return new QgsAppStyle( mBaseStyle );
87 }
88 
static void multiplyOpacity(QImage &image, double factor)
Multiplies opacity of image pixel values by a factor.
QgsProxyStyle(QWidget *parent)
Constructor for QgsProxyStyle.
static void adjustHueSaturation(QImage &image, double saturation, const QColor &colorizeColor=QColor(), double colorizeStrength=1.0)
Alter the hue or saturation of a QImage.