QIcon: move back to QtGui

-  Move the files and tests
git mv src/widgets/kernel/qicon* qrc/gui/image/
git mv tests/auto/widgets/kernel/qicon/ tests/auto/gui/image/

 - update the include of QIcon
git grep -O"sed -i s,QtWidgets/qicon,QtGui/qicon," "QtWidgets/qicon"
git grep -O"sed -i s,QtWidgets/QIcon,QtGui/QIcon," "QtWidgets/QIcon"

 - Adapt QIcon \ingroup documentation
sed -i s/QtWidgets/QtGui/ src/gui/images/qicon*

 - Adapt export macro
sed -i s/Q_WIDGETS_EXPORT/Q_GUI_EXPORT/g src/gui/image/qicon*

 - Update .pri and .pro files

 - Remove the use of QStyle::alignedRect by copying its content (and
   adapt slightly

 - Use QGuiApplication::palette() instead of QApplication::palette()

 - Add a hook in QGuiApplicationPrivate to call the
   QStyle::generatedIconPixmap() from QtWidgets

Another commit follows to adjust QMetaType::Icon and move the QVariant
and QMetaType icon handler back in QtGui

Change-Id: I1b63759f892ebc02dfc30f41bb6e76e0b7451182
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Reviewed-by: Girish Ramakrishnan <girish.1.ramakrishnan@nokia.com>
This commit is contained in:
Olivier Goffart 2012-05-14 18:02:16 +02:00 committed by Qt by Nokia
parent 83645377e9
commit 6c06e14a49
50 changed files with 92 additions and 65 deletions

View File

@ -23,6 +23,11 @@ HEADERS += \
image/qpixmapcache_p.h \
image/qplatformpixmap.h \
image/qimagepixmapcleanuphooks_p.h \
image/qicon.h \
image/qicon_p.h \
image/qiconloader_p.h \
image/qiconengine.h \
image/qiconengineplugin.h \
SOURCES += \
image/qbitmap.cpp \
@ -40,7 +45,12 @@ SOURCES += \
image/qpixmap_raster.cpp \
image/qpixmap_blitter.cpp \
image/qnativeimage.cpp \
image/qimagepixmapcleanuphooks.cpp
image/qimagepixmapcleanuphooks.cpp \
image/qicon.cpp \
image/qiconloader.cpp \
image/qiconengine.cpp \
image/qiconengineplugin.cpp \
win32: SOURCES += image/qpixmap_win.cpp

View File

@ -45,15 +45,13 @@
#include "qiconengineplugin.h"
#include "private/qfactoryloader_p.h"
#include "private/qiconloader_p.h"
#include "qstyleoption.h"
#include "qpainter.h"
#include "qfileinfo.h"
#include "qstyle.h"
#include "qpixmapcache.h"
#include "qvariant.h"
#include "qcache.h"
#include "qdebug.h"
#include "qapplication.h"
#include "qpalette.h"
#ifdef Q_WS_MAC
#include <private/qt_mac_p.h>
@ -61,6 +59,7 @@
#endif
#include "private/qhexstring_p.h"
#include "private/qguiapplication_p.h"
#ifndef QT_NO_ICON
QT_BEGIN_NAMESPACE
@ -265,11 +264,10 @@ QPixmap QPixmapIconEngine::pixmap(const QSize &size, QIcon::Mode mode, QIcon::St
if (!actualSize.isNull() && (actualSize.width() > size.width() || actualSize.height() > size.height()))
actualSize.scale(size, Qt::KeepAspectRatio);
// #### Qt5 no idea what this really does, but we need to remove the QApp and style references
QString key = QLatin1String("qt_")
% HexString<quint64>(pm.cacheKey())
% HexString<uint>(pe->mode)
% HexString<quint64>(QApplication::palette().cacheKey())
% HexString<quint64>(QGuiApplication::palette().cacheKey())
% HexString<uint>(actualSize.width())
% HexString<uint>(actualSize.height());
@ -277,9 +275,9 @@ QPixmap QPixmapIconEngine::pixmap(const QSize &size, QIcon::Mode mode, QIcon::St
if (QPixmapCache::find(key % HexString<uint>(mode), pm))
return pm; // horray
if (QPixmapCache::find(key % HexString<uint>(QIcon::Normal), pm)) {
QStyleOption opt(0);
opt.palette = QApplication::palette();
QPixmap active = QApplication::style()->generatedIconPixmap(QIcon::Active, pm, &opt);
QPixmap active = pm;
if (QGuiApplication *guiApp = qobject_cast<QGuiApplication *>(qApp))
active = static_cast<QGuiApplicationPrivate*>(QObjectPrivate::get(guiApp))->applyQIconStyleHelper(QIcon::Active, pm);
if (pm.cacheKey() == active.cacheKey())
return pm;
}
@ -289,9 +287,9 @@ QPixmap QPixmapIconEngine::pixmap(const QSize &size, QIcon::Mode mode, QIcon::St
if (pm.size() != actualSize)
pm = pm.scaled(actualSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
if (pe->mode != mode && mode != QIcon::Normal) {
QStyleOption opt(0);
opt.palette = QApplication::palette();
QPixmap generated = QApplication::style()->generatedIconPixmap(mode, pm, &opt);
QPixmap generated = pm;
if (QGuiApplication *guiApp = qobject_cast<QGuiApplication *>(qApp))
generated = static_cast<QGuiApplicationPrivate*>(QObjectPrivate::get(guiApp))->applyQIconStyleHelper(mode, pm);
if (!generated.isNull())
pm = generated;
}
@ -457,7 +455,7 @@ Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader,
\ingroup painting
\ingroup shared
\inmodule QtWidgets
\inmodule QtGui
A QIcon can generate smaller, larger, active, and disabled pixmaps
from the set of pixmaps it is given. Such pixmaps are used by Qt
@ -710,7 +708,24 @@ void QIcon::paint(QPainter *painter, const QRect &rect, Qt::Alignment alignment,
{
if (!d || !painter)
return;
QRect alignedRect = QStyle::alignedRect(painter->layoutDirection(), alignment, d->engine->actualSize(rect.size(), mode, state), rect);
// Copy of QStyle::alignedRect
const QSize size = d->engine->actualSize(rect.size(), mode, state);
alignment = QGuiApplicationPrivate::visualAlignment(painter->layoutDirection(), alignment);
int x = rect.x();
int y = rect.y();
int w = size.width();
int h = size.height();
if ((alignment & Qt::AlignVCenter) == Qt::AlignVCenter)
y += rect.size().height()/2 - h/2;
else if ((alignment & Qt::AlignBottom) == Qt::AlignBottom)
y += rect.size().height() - h;
if ((alignment & Qt::AlignRight) == Qt::AlignRight)
x += rect.size().width() - w;
else if ((alignment & Qt::AlignHCenter) == Qt::AlignHCenter)
x += rect.size().width()/2 - w/2;
QRect alignedRect(x, y, w, h);
d->engine->paint(painter, alignedRect, mode, state);
}

View File

@ -55,7 +55,7 @@ QT_BEGIN_NAMESPACE
class QIconPrivate;
class QIconEngine;
class Q_WIDGETS_EXPORT QIcon
class Q_GUI_EXPORT QIcon
{
public:
enum Mode { Normal, Disabled, Active, Selected };
@ -118,8 +118,8 @@ public:
private:
QIconPrivate *d;
#if !defined(QT_NO_DATASTREAM)
friend Q_WIDGETS_EXPORT QDataStream &operator<<(QDataStream &, const QIcon &);
friend Q_WIDGETS_EXPORT QDataStream &operator>>(QDataStream &, QIcon &);
friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QIcon &);
friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QIcon &);
#endif
public:
@ -131,12 +131,12 @@ Q_DECLARE_SHARED(QIcon)
Q_DECLARE_TYPEINFO(QIcon, Q_MOVABLE_TYPE);
#if !defined(QT_NO_DATASTREAM)
Q_WIDGETS_EXPORT QDataStream &operator<<(QDataStream &, const QIcon &);
Q_WIDGETS_EXPORT QDataStream &operator>>(QDataStream &, QIcon &);
Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QIcon &);
Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QIcon &);
#endif
#ifndef QT_NO_DEBUG_STREAM
Q_WIDGETS_EXPORT QDebug operator<<(QDebug dbg, const QIcon &);
Q_GUI_EXPORT QDebug operator<<(QDebug dbg, const QIcon &);
#endif
QT_END_NAMESPACE

View File

@ -57,8 +57,8 @@
#include <QtCore/qsize.h>
#include <QtCore/qlist.h>
#include <QtGui/qpixmap.h>
#include <QtWidgets/qicon.h>
#include <QtWidgets/qiconengine.h>
#include <QtGui/qicon.h>
#include <QtGui/qiconengine.h>
#ifndef QT_NO_ICON
QT_BEGIN_NAMESPACE

View File

@ -50,7 +50,7 @@ QT_BEGIN_NAMESPACE
\brief The QIconEngine class provides an abstract base class for QIcon renderers.
\ingroup painting
\inmodule QtWidgets
\inmodule QtGui
An icon engine provides the rendering functions for a QIcon. Each icon has a
corresponding icon engine that is responsible for drawing the icon with a
@ -158,7 +158,7 @@ void QIconEngine::addFile(const QString &/*fileName*/, const QSize &/*size*/, QI
\class QIconEngine::AvailableSizesArgument
\since 4.5
\inmodule QtWidgets
\inmodule QtGui
This struct represents arguments to virtual_hook() function when
\a id parameter is QIconEngine::AvailableSizesHook.

View File

@ -44,14 +44,14 @@
#include <QtCore/qglobal.h>
#include <QtCore/qlist.h>
#include <QtWidgets/qicon.h>
#include <QtGui/qicon.h>
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
class Q_WIDGETS_EXPORT QIconEngine
class Q_GUI_EXPORT QIconEngine
{
public:
virtual ~QIconEngine();

View File

@ -49,7 +49,7 @@ QT_BEGIN_NAMESPACE
\brief The QIconEnginePlugin class provides an abstract base for custom QIconEngine plugins.
\ingroup plugins
\inmodule QtWidgets
\inmodule QtGui
\b {Use QIconEnginePluginV2 instead.}

View File

@ -52,7 +52,7 @@ QT_BEGIN_NAMESPACE
class QIconEngine;
struct Q_WIDGETS_EXPORT QIconEngineFactoryInterface : public QFactoryInterface
struct Q_GUI_EXPORT QIconEngineFactoryInterface : public QFactoryInterface
{
virtual QIconEngine *create(const QString &filename = QString()) = 0;
};
@ -61,7 +61,7 @@ struct Q_WIDGETS_EXPORT QIconEngineFactoryInterface : public QFactoryInterface
"org.qt-project.Qt.QIconEngineFactoryInterface"
Q_DECLARE_INTERFACE(QIconEngineFactoryInterface, QIconEngineFactoryInterface_iid)
class Q_WIDGETS_EXPORT QIconEnginePlugin : public QObject, public QIconEngineFactoryInterface
class Q_GUI_EXPORT QIconEnginePlugin : public QObject, public QIconEngineFactoryInterface
{
Q_OBJECT
Q_INTERFACES(QIconEngineFactoryInterface:QFactoryInterface)

View File

@ -43,14 +43,12 @@
#include <private/qguiapplication_p.h>
#include <private/qicon_p.h>
#include <private/qguiapplication_p.h>
#include <QtWidgets/QApplication>
#include <QtWidgets/QIconEnginePlugin>
#include <QtGui/QIconEnginePlugin>
#include <QtGui/QPixmapCache>
#include <qpa/qplatformtheme.h>
#include <QtWidgets/QIconEngine>
#include <QtWidgets/QStyleOption>
#include <QtGui/QIconEngine>
#include <QtGui/QPalette>
#include <QtCore/QList>
#include <QtCore/QHash>
#include <QtCore/QDir>
@ -510,16 +508,16 @@ QPixmap PixmapEntry::pixmap(const QSize &size, QIcon::Mode mode, QIcon::State st
QString key = QLatin1String("$qt_theme_")
% HexString<qint64>(basePixmap.cacheKey())
% HexString<int>(mode)
% HexString<qint64>(qApp->palette().cacheKey())
% HexString<qint64>(QGuiApplication::palette().cacheKey())
% HexString<int>(actualSize);
QPixmap cachedPixmap;
if (QPixmapCache::find(key, &cachedPixmap)) {
return cachedPixmap;
} else {
QStyleOption opt(0);
opt.palette = qApp->palette();
cachedPixmap = qApp->style()->generatedIconPixmap(mode, basePixmap, &opt);
cachedPixmap = basePixmap;
if (QGuiApplication *guiApp = qobject_cast<QGuiApplication *>(qApp))
cachedPixmap = static_cast<QGuiApplicationPrivate*>(QObjectPrivate::get(guiApp))->applyQIconStyleHelper(mode, basePixmap);
QPixmapCache::insert(key, cachedPixmap);
}
return cachedPixmap;

View File

@ -54,8 +54,8 @@
// We mean it.
//
#include <QtWidgets/QIcon>
#include <QtWidgets/QIconEngine>
#include <QtGui/QIcon>
#include <QtGui/QIconEngine>
#include <QtGui/QPixmapCache>
#include <private/qicon_p.h>
#include <private/qfactoryloader_p.h>
@ -153,7 +153,7 @@ private:
bool m_valid;
};
class QIconLoader : public QObject
class Q_GUI_EXPORT QIconLoader : public QObject
{
public:
QIconLoader();

View File

@ -52,6 +52,7 @@
#include <QWindowSystemInterface>
#include "private/qwindowsysteminterface_qpa_p.h"
#include "private/qshortcutmap_p.h"
#include <qicon.h>
QT_BEGIN_HEADER
@ -213,6 +214,9 @@ public:
const QDrawHelperGammaTables *gammaTables();
// hook reimplemented in QApplication to apply the QStyle function on the QIcon
virtual QPixmap applyQIconStyleHelper(QIcon::Mode, const QPixmap &basePixmap) const { return basePixmap; }
protected:
virtual void notifyThemeChanged();

View File

@ -61,7 +61,7 @@
#include <QtGui/qimage.h>
#ifdef QT_WIDGETS_LIB
#include <QtWidgets/qicon.h>
#include <QtGui/qicon.h>
#endif
#if 0

View File

@ -45,7 +45,7 @@
#include <QtCore/qabstractitemmodel.h>
#include <QtCore/qpair.h>
#include <QtCore/qdir.h>
#include <QtWidgets/qicon.h>
#include <QtGui/qicon.h>
#include <QtCore/qdiriterator.h>
QT_BEGIN_HEADER

View File

@ -54,7 +54,7 @@
#include <QtWidgets/qdesktopwidget.h>
#include <QtWidgets/qpushbutton.h>
#include <QtGui/qaccessible.h>
#include <QtWidgets/qicon.h>
#include <QtGui/qicon.h>
#include <QtGui/qtextdocument.h>
#include <QtWidgets/qapplication.h>
#include <QtWidgets/qtextedit.h>

View File

@ -44,7 +44,7 @@
#include <QtCore/qfileinfo.h>
#include <QtCore/qscopedpointer.h>
#include <QtWidgets/qicon.h>
#include <QtGui/qicon.h>
QT_BEGIN_HEADER

View File

@ -45,7 +45,7 @@
#include <QtCore/qabstractitemmodel.h>
#include <QtGui/qbrush.h>
#include <QtGui/qfont.h>
#include <QtWidgets/qicon.h>
#include <QtGui/qicon.h>
#ifndef QT_NO_DATASTREAM
#include <QtCore/qdatastream.h>
#endif

View File

@ -15,11 +15,6 @@ HEADERS += \
kernel/qdesktopwidget.h \
kernel/qformlayout.h \
kernel/qgridlayout.h \
kernel/qicon.h \
kernel/qicon_p.h \
kernel/qiconloader_p.h \
kernel/qiconengine.h \
kernel/qiconengineplugin.h \
kernel/qlayout.h \
kernel/qlayout_p.h \
kernel/qlayoutengine_p.h \
@ -52,10 +47,6 @@ SOURCES += \
kernel/qboxlayout.cpp \
kernel/qformlayout.cpp \
kernel/qgridlayout.cpp \
kernel/qicon.cpp \
kernel/qiconloader.cpp \
kernel/qiconengine.cpp \
kernel/qiconengineplugin.cpp \
kernel/qlayout.cpp \
kernel/qlayoutengine.cpp \
kernel/qlayoutitem.cpp \

View File

@ -46,7 +46,7 @@
#include <QtCore/qstring.h>
#include <QtWidgets/qwidget.h>
#include <QtCore/qvariant.h>
#include <QtWidgets/qicon.h>
#include <QtGui/qicon.h>
QT_BEGIN_HEADER

View File

@ -4510,6 +4510,14 @@ QGestureManager* QGestureManager::instance()
}
#endif // QT_NO_GESTURES
QPixmap QApplicationPrivate::applyQIconStyleHelper(QIcon::Mode mode, const QPixmap& base) const
{
Q_Q(const QApplication);
QStyleOption opt(0);
opt.palette = q->palette();
return q->style()->generatedIconPixmap(mode, base, &opt);
}
QT_END_NAMESPACE
#include "moc_qapplication.cpp"

View File

@ -374,6 +374,7 @@ public:
ulong timestamp);
static void translateTouchCancel(QTouchDevice *device, ulong timestamp);
QPixmap applyQIconStyleHelper(QIcon::Mode mode, const QPixmap& base) const;
private:
#ifdef Q_WS_QWS
QHash<const QScreen*, QRect> maxWindowRects;

View File

@ -45,7 +45,7 @@
#include <QtCore/qobject.h>
#include <QtCore/qrect.h>
#include <QtCore/qsize.h>
#include <QtWidgets/qicon.h>
#include <QtGui/qicon.h>
#include <QtGui/qpixmap.h>
#include <QtGui/qpalette.h>
#include <QtWidgets/qsizepolicy.h>

View File

@ -44,7 +44,7 @@
#include <QtCore/qvariant.h>
#include <QtWidgets/qabstractspinbox.h>
#include <QtWidgets/qicon.h>
#include <QtGui/qicon.h>
#include <QtGui/qmatrix.h>
#include <QtWidgets/qslider.h>
#include <QtWidgets/qstyle.h>

View File

@ -46,7 +46,7 @@
#ifndef QT_NO_SYSTEMTRAYICON
#include <QtWidgets/qicon.h>
#include <QtGui/qicon.h>
QT_BEGIN_HEADER

View File

@ -47,7 +47,7 @@
#include "qundogroup.h"
#include <QtCore/qabstractitemmodel.h>
#include <QtCore/qpointer.h>
#include <QtWidgets/qicon.h>
#include <QtGui/qicon.h>
#include <private/qlistview_p.h>
QT_BEGIN_NAMESPACE

View File

@ -42,7 +42,7 @@
#ifndef QABSTRACTBUTTON_H
#define QABSTRACTBUTTON_H
#include <QtWidgets/qicon.h>
#include <QtGui/qicon.h>
#include <QtGui/qkeysequence.h>
#include <QtWidgets/qwidget.h>

View File

@ -44,7 +44,7 @@
#include <QtWidgets/qwidget.h>
#include <QtCore/qstring.h>
#include <QtWidgets/qicon.h>
#include <QtGui/qicon.h>
#include <QtWidgets/qaction.h>
#ifdef Q_OS_WINCE

View File

@ -43,7 +43,7 @@
#define QTABWIDGET_H
#include <QtWidgets/qwidget.h>
#include <QtWidgets/qicon.h>
#include <QtGui/qicon.h>
QT_BEGIN_HEADER

View File

@ -43,7 +43,7 @@
#define QTOOLBOX_H
#include <QtWidgets/qframe.h>
#include <QtWidgets/qicon.h>
#include <QtGui/qicon.h>
QT_BEGIN_HEADER

View File

@ -9,6 +9,7 @@ SUBDIRS=\
qimagewriter \
qmovie \
qpicture \
qicon \
!contains(QT_CONFIG, private_tests): SUBDIRS -= \
qpixmapcache \

View File

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

View File

Before

Width:  |  Height:  |  Size: 175 B

After

Width:  |  Height:  |  Size: 175 B

View File

@ -13,7 +13,6 @@ SUBDIRS=\
qwidget \
qwidget_window \
qwidgetaction \
qicon \
qshortcut \
SUBDIRS -= qsound