KDeclarative

kiconprovider.cpp
1 /*
2  SPDX-FileCopyrightText: 2011 Artur Duque de Souza <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.1-or-later
5 */
6 
7 #include "kiconprovider_p.h"
8 
9 #include <QPixmap>
10 #include <QSize>
11 #include <QIcon>
12 #include <KIconLoader>
13 #include <KIconEffect>
14 
15 namespace KDeclarative {
16 
17 KIconProvider::KIconProvider()
19 {
20 }
21 
22 QPixmap KIconProvider::requestPixmap(const QString &id, QSize *size, const QSize &requestedSize)
23 {
24  // We need to handle QIcon::state
25  const QStringList source = id.split(QLatin1Char('/'));
26 
27  QPixmap pixmap;
28  if (requestedSize.isValid()) {
29  pixmap = QIcon::fromTheme(source.at(0)).pixmap(requestedSize);
30  } else if (size->isValid()) {
31  pixmap = QIcon::fromTheme(source.at(0)).pixmap(*size);
32  } else {
34  }
35 
36  if (source.size() == 2) {
38  const QString state(source.at(1));
39  int finalState = KIconLoader::DefaultState;
40 
41  if (state == QLatin1String("active")) {
42  finalState = KIconLoader::ActiveState;
43  } else if (state == QLatin1String("disabled")) {
44  finalState = KIconLoader::DisabledState;
45  } else if (state == QLatin1String("last")) {
46  finalState = KIconLoader::LastState;
47  }
48 
49  // apply the effect for state
50  pixmap = effect->apply(pixmap, KIconLoader::Desktop, finalState);
51  }
52 
53  if (!pixmap.isNull() && size) {
54  *size = pixmap.size();
55  }
56 
57  return pixmap;
58 }
59 
60 }
61 
QSize size() const const
bool isValid() const const
int currentSize(KIconLoader::Group group) const
const T & at(int i) const const
int size() const const
static KIconLoader * global()
KIconEffect * iconEffect() const
bool isNull() const const
QIcon fromTheme(const QString &name)
QImage apply(const QImage &src, int group, int state) const
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Jan 25 2021 22:44:28 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.