remove QApplication dependencies in gui/image

This commit is contained in:
Lars Knoll 2011-05-03 15:00:21 +02:00
parent 2ce57e22d0
commit f1f5a80cfe
9 changed files with 49 additions and 62 deletions

View File

@ -45,7 +45,6 @@
#include "qiconengineplugin.h"
#include "private/qfactoryloader_p.h"
#include "private/qiconloader_p.h"
#include "qapplication.h"
#include "qstyleoption.h"
#include "qpainter.h"
#include "qfileinfo.h"
@ -263,37 +262,38 @@ 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);
QString key = QLatin1Literal("qt_")
% HexString<quint64>(pm.cacheKey())
% HexString<uint>(pe->mode)
% HexString<quint64>(QApplication::palette().cacheKey())
% HexString<uint>(actualSize.width())
% HexString<uint>(actualSize.height());
// #### Qt5 no idea what this really does, but we need to remove the QApp and style references
// QString key = QLatin1Literal("qt_")
// % HexString<quint64>(pm.cacheKey())
// % HexString<uint>(pe->mode)
// % HexString<quint64>(QApplication::palette().cacheKey())
// % HexString<uint>(actualSize.width())
// % HexString<uint>(actualSize.height());
if (mode == QIcon::Active) {
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);
if (pm.cacheKey() == active.cacheKey())
return pm;
}
}
// if (mode == QIcon::Active) {
// 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);
// if (pm.cacheKey() == active.cacheKey())
// return pm;
// }
// }
if (!QPixmapCache::find(key % HexString<uint>(mode), pm)) {
// if (!QPixmapCache::find(key % HexString<uint>(mode), pm)) {
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);
if (!generated.isNull())
pm = generated;
}
QPixmapCache::insert(key % HexString<uint>(mode), pm);
}
// if (pe->mode != mode && mode != QIcon::Normal) {
// QStyleOption opt(0);
// opt.palette = QApplication::palette();
// QPixmap generated = QApplication::style()->generatedIconPixmap(mode, pm, &opt);
// if (!generated.isNull())
// pm = generated;
// }
// QPixmapCache::insert(key % HexString<uint>(mode), pm);
// }
return pm;
}

View File

@ -41,7 +41,7 @@
#ifndef QT_NO_ICON
#include <private/qiconloader_p.h>
#include <private/qapplication_p.h>
#include <private/qguiapplication_qpa_p.h>
#include <private/qicon_p.h>
#include <private/qguiplatformplugin_p.h>

View File

@ -45,7 +45,7 @@
#include "private/qpaintengine_raster_p.h"
#include "private/qapplication_p.h"
#include "private/qguiapplication_qpa_p.h"
#if defined(Q_WS_X11) && !defined(QT_NO_MITSHM)
#include <qx11info_x11.h>
@ -301,11 +301,7 @@ QNativeImage::~QNativeImage()
QImage::Format QNativeImage::systemFormat()
{
#ifdef Q_WS_QPA
return QApplicationPrivate::platformIntegration()->screens().at(0)->format();
#else
return QImage::Format_RGB32;
#endif
return QGuiApplicationPrivate::platformIntegration()->screens().at(0)->format();
}
#endif // platforms

View File

@ -1217,7 +1217,6 @@ QDataStream &operator>>(QDataStream &s, QPicture &r)
QT_BEGIN_INCLUDE_NAMESPACE
#include "qregexp.h"
#include "qapplication.h"
#include "qpictureformatplugin.h"
QT_END_INCLUDE_NAMESPACE

View File

@ -52,8 +52,7 @@
#include "qpainter.h"
#include "qdatastream.h"
#include "qbuffer.h"
#include "qapplication.h"
#include <private/qapplication_p.h>
#include <private/qguiapplication_qpa_p.h>
#include <private/qwidget_p.h>
#include "qevent.h"
#include "qfile.h"
@ -64,6 +63,7 @@
#include "qimagewriter.h"
#include "qpaintengine.h"
#include "qthread.h"
#include "qdebug.h"
#ifdef Q_WS_MAC
# include "private/qt_mac_p.h"
@ -97,25 +97,17 @@ Q_GUI_EXPORT qint64 qt_pixmap_id(const QPixmap &pixmap)
static bool qt_pixmap_thread_test()
{
if (!qApp) {
if (!QCoreApplication::instance()) {
qFatal("QPixmap: Must construct a QApplication before a QPaintDevice");
return false;
}
if (qApp->thread() != QThread::currentThread()) {
bool fail = false;
#if defined (Q_WS_X11)
if (!QApplication::testAttribute(Qt::AA_X11InitThreads))
fail = true;
#elif defined (Q_WS_QPA)
if (!QApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::ThreadedPixmaps)) {
if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::ThreadedPixmaps)) {
printf("Lighthouse plugin does not support threaded pixmaps!\n");
fail = true;
}
#else
if (QApplicationPrivate::graphics_system_name != QLatin1String("raster"))
fail = true;
#endif
if (fail) {
qWarning("QPixmap: It is not safe to use pixmaps outside the GUI thread");
return false;
@ -129,16 +121,8 @@ void QPixmap::init(int w, int h, Type type)
init(w, h, int(type));
}
extern QApplication::Type qt_appType;
void QPixmap::init(int w, int h, int type)
{
if (qt_appType == QApplication::Tty) {
qWarning("QPixmap: Cannot create a QPixmap when no GUI is being used");
data = 0;
return;
}
if ((w > 0 && h > 0) || type == QPixmapData::BitmapType)
data = QPixmapData::create(w, h, (QPixmapData::PixelType) type);
else
@ -985,7 +969,7 @@ bool QPixmap::doImageIO(QImageWriter *writer, int quality) const
return writer->write(toImage());
}
// #### Qt5: needs fixing
// The implementation (and documentation) of
// QPixmap::fill(const QWidget *, const QPoint &)
// is in qwidget.cpp
@ -1071,6 +1055,7 @@ qint64 QPixmap::cacheKey() const
return data->cacheKey();
}
#if 0
static void sendResizeEvents(QWidget *target)
{
QResizeEvent e(target->size(), QSize());
@ -1083,6 +1068,7 @@ static void sendResizeEvents(QWidget *target)
sendResizeEvents(child);
}
}
#endif
/*!
\fn QPixmap QPixmap::grabWidget(QWidget * widget, const QRect &rectangle)
@ -1116,6 +1102,11 @@ static void sendResizeEvents(QWidget *target)
QPixmap QPixmap::grabWidget(QWidget * widget, const QRect &rect)
{
// ### Qt5: should we keep or remove this method?
// SC solution would be to install a callback form QtWidgets, but ugly.
qWarning() << "QPixmap::grabWidget is deprecated, use QWidget::render() instead";
return QPixmap();
#if 0
if (!widget)
return QPixmap();
@ -1141,6 +1132,7 @@ QPixmap QPixmap::grabWidget(QWidget * widget, const QRect &rect)
widget->d_func()->render(&res, QPoint(), r, QWidget::DrawWindowBackground
| QWidget::DrawChildren | QWidget::IgnoreMask, true);
return res;
#endif
}
/*!

View File

@ -44,7 +44,7 @@
#include <qpainter.h>
#include <qimage.h>
#include <private/qapplication_p.h>
#include <private/qguiapplication_qpa_p.h>
#include <private/qblittable_p.h>
#include <private/qdrawhelper_p.h>
@ -98,7 +98,7 @@ void QBlittablePixmapData::resize(int width, int height)
delete m_engine;
m_engine = 0;
#ifdef Q_WS_QPA
d = QApplicationPrivate::platformIntegration()->screens().at(0)->depth();
d = QGuiApplicationPrivate::platformIntegration()->screens().at(0)->depth();
#endif
w = width;
h = height;

View File

@ -43,7 +43,7 @@
#include <QtCore/qbuffer.h>
#include <QtGui/qbitmap.h>
#include <QtGui/qimagereader.h>
#include <private/qapplication_p.h>
#include <private/qguiapplication_qpa_p.h>
#include <private/qimagepixmapcleanuphooks_p.h>
QT_BEGIN_NAMESPACE

View File

@ -60,7 +60,7 @@
# include <private/qpixmap_s60_p.h>
#endif
#include "private/qapplication_p.h"
#include "private/qguiapplication_qpa_p.h"
QT_BEGIN_NAMESPACE

View File

@ -48,7 +48,7 @@
#include "qpixmapfilter_p.h"
#include "qvarlengtharray.h"
#include "private/qapplication_p.h"
#include "private/qguiapplication_qpa_p.h"
#include "private/qpaintengineex_p.h"
#include "private/qpaintengine_raster_p.h"
#include "qmath.h"