本文整理汇总了C++中QPixmap::cacheKey方法的典型用法代码示例。如果您正苦于以下问题:C++ QPixmap::cacheKey方法的具体用法?C++ QPixmap::cacheKey怎么用?C++ QPixmap::cacheKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QPixmap
的用法示例。
在下文中一共展示了QPixmap::cacheKey方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: pixmap
QPixmap QPixmapIconEngine::pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state)
{
QPixmap pm;
QPixmapIconEngineEntry *pe = bestMatch(size, mode, state, false);
if (pe)
pm = pe->pixmap;
if (pm.isNull()) {
int idx = pixmaps.count();
while (--idx >= 0) {
if (pe == &pixmaps[idx]) {
pixmaps.remove(idx);
break;
}
}
if (pixmaps.isEmpty())
return pm;
else
return pixmap(size, mode, state);
}
QSize actualSize = pm.size();
if (!actualSize.isNull() && (actualSize.width() > size.width() || actualSize.height() > size.height()))
actualSize.scale(size, Qt::KeepAspectRatio);
QString key = QLatin1String("$qt_icon_")
+ QString::number(pm.cacheKey())
+ QString::number(pe->mode)
+ QString::number(actualSize.width())
+ QLatin1Char('_')
+ QString::number(actualSize.height())
+ QLatin1Char('_');
if (mode == QIcon::Active) {
if (QPixmapCache::find(key + QString::number(mode), pm))
return pm; // horray
if (QPixmapCache::find(key + QString::number(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 + QString::number(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 + QString::number(mode), pm);
}
return pm;
}
示例2: pixmap
QPixmap QPixmapIconEngine::pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state)
{
QPixmap pm;
QPixmapIconEngineEntry *pe = bestMatch(size, mode, state, false);
if (pe)
pm = pe->pixmap;
if (pm.isNull()) {
int idx = pixmaps.count();
while (--idx >= 0) {
if (pe == &pixmaps[idx]) {
pixmaps.remove(idx);
break;
}
}
if (pixmaps.isEmpty())
return pm;
else
return pixmap(size, mode, state);
}
QSize actualSize = pm.size();
if (!actualSize.isNull() && (actualSize.width() > size.width() || actualSize.height() > size.height()))
actualSize.scale(size, Qt::KeepAspectRatio);
QString key = QLatin1String("qt_")
% HexString<quint64>(pm.cacheKey())
% HexString<uint>(pe->mode)
% HexString<quint64>(QGuiApplication::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)) {
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;
}
}
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) {
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;
}
QPixmapCache::insert(key % HexString<uint>(mode), pm);
}
return pm;
}
示例3: QPixmap
const QPixmap & CImgButton::scaleImage( const QString & name ) const
{
QPixmap * scaled = new QPixmap();
*scaled = m_picsOrig[ name ].scaled( size().width(),
size().height(),
Qt::IgnoreAspectRatio,
Qt::SmoothTransformation );
m_picsSz.insert( scaled->cacheKey(), scaled );
return *m_picsSz[ scaled->cacheKey() ];
}
示例4: testUnknownIconNotCached
void testUnknownIconNotCached()
{
// This is a test to ensure that "unknown" icons do not pin themselves
// in the icon loader. Or in other words, if an "unknown" icon is
// returned, but the appropriate icon is subsequently installed
// properly, the next request for that icon should return the new icon
// instead of the unknown icon.
// Since we'll need to create an icon we'll need a temporary directory,
// and we want that established before creating the icon loader.
QString tempRoot = QDir::tempPath() + QLatin1String("/kiconloader_unittest");
QString temporaryDir = tempRoot + QLatin1String("/hicolor/22x22/actions");
QVERIFY(QDir::root().mkpath(temporaryDir));
QVERIFY(KGlobal::dirs()->addResourceDir("icon", tempRoot, false));
KIconLoader iconLoader;
// First find an existing icon. The only ones installed for sure by
// kdelibs are the kimproxy ones.
QString loadedIconPath = iconLoader.iconPath(
QLatin1String("presence_online"),
KIconLoader::DefaultState,
false /* Ensure "unknown" icon can't be returned */
);
QVERIFY(!loadedIconPath.isEmpty());
QString nonExistingIconName = QLatin1String("fhqwhgads_homsar");
// Find a non-existent icon, allowing unknown icon to be returned
QPixmap nonExistingIcon = iconLoader.loadIcon(
nonExistingIconName, KIconLoader::Toolbar);
QCOMPARE(nonExistingIcon.isNull(), false);
// Install the existing icon by copying.
QFileInfo existingIconInfo(loadedIconPath);
QString newIconPath = temporaryDir + QLatin1String("/")
+ nonExistingIconName + QLatin1String(".png");
QVERIFY(QFile::copy(loadedIconPath, newIconPath));
// Verify the icon can now be found.
QPixmap nowExistingIcon = iconLoader.loadIcon(
nonExistingIconName, KIconLoader::Toolbar);
QVERIFY(nowExistingIcon.cacheKey() != nonExistingIcon.cacheKey());
QCOMPARE(iconLoader.iconPath(nonExistingIconName, KIconLoader::Toolbar),
newIconPath);
// Cleanup
QFile::remove(newIconPath);
QStringList entries(QDir(tempRoot).entryList(
QDir::Dirs | QDir::NoDotAndDotDot,
QDir::Name | QDir::Reversed));
Q_FOREACH(const QString &dirName, entries) {
QDir::root().rmdir(dirName);
}
示例5: adoptImageBackingStore
int64_t LayerTreeHostQt::adoptImageBackingStore(Image* image)
{
if (!image)
return InvalidWebLayerID;
QPixmap* pixmap = image->nativeImageForCurrentFrame();
if (!pixmap)
return InvalidWebLayerID;
int64_t key = pixmap->cacheKey();
HashMap<int64_t, int>::iterator it = m_directlyCompositedImageRefCounts.find(key);
if (it != m_directlyCompositedImageRefCounts.end()) {
++(it->second);
return key;
}
RefPtr<ShareableBitmap> bitmap = ShareableBitmap::createShareable(image->size(), image->currentFrameHasAlpha() ? ShareableBitmap::SupportsAlpha : 0);
{
OwnPtr<WebCore::GraphicsContext> graphicsContext = bitmap->createGraphicsContext();
graphicsContext->drawImage(image, ColorSpaceDeviceRGB, IntPoint::zero());
}
ShareableBitmap::Handle handle;
bitmap->createHandle(handle);
m_webPage->send(Messages::LayerTreeHostProxy::CreateDirectlyCompositedImage(key, handle));
m_directlyCompositedImageRefCounts.add(key, 1);
return key;
}
示例6: drawPixmap
void QPdfEngine::drawPixmap (const QRectF &rectangle, const QPixmap &pixmap, const QRectF &sr)
{
if (sr.isEmpty() || rectangle.isEmpty() || pixmap.isNull())
return;
Q_D(QPdfEngine);
QBrush b = d->brush;
QRect sourceRect = sr.toRect();
QPixmap pm = sourceRect != pixmap.rect() ? pixmap.copy(sourceRect) : pixmap;
QImage image = pm.toImage();
bool bitmap = true;
const int object = d->addImage(image, &bitmap, pm.cacheKey());
if (object < 0)
return;
*d->currentPage << "q\n/GSa gs\n";
*d->currentPage
<< QPdf::generateMatrix(QTransform(rectangle.width() / sr.width(), 0, 0, rectangle.height() / sr.height(),
rectangle.x(), rectangle.y()) * (d->simplePen ? QTransform() : d->stroker.matrix));
if (bitmap) {
// set current pen as d->brush
d->brush = d->pen.brush();
}
setBrush();
d->currentPage->streamImage(image.width(), image.height(), object);
*d->currentPage << "Q\n";
d->brush = b;
}
示例7: stlInstance
void
PixmapDelegateFader::setPixmap( const QPixmap& pixmap )
{
if ( pixmap.isNull() )
return;
m_defaultImage = false;
const qint64 newImageMd5 = pixmap.cacheKey();
if ( m_oldImageMd5 == newImageMd5 )
return;
m_oldImageMd5 = newImageMd5;
if ( m_connectedToStl )
{
m_pixmapQueue.enqueue( pixmap );
return;
}
m_oldReference = m_currentReference;
m_currentReference = pixmap;
stlInstance().data()->setUpdateInterval( 20 );
m_startFrame = stlInstance().data()->currentFrame();
m_connectedToStl = true;
m_fadePct = 0;
connect( stlInstance().data(), SIGNAL( frameChanged( int ) ), this, SLOT( onAnimationStep( int ) ) );
}
示例8: setPicture
void ComplexVideoWidget::setPicture(const QPixmap& pxmp)
{
//if (!d->pixmap || d->pixmap->cacheKey() != pixmap.cacheKey()) {
// d->clearContents();
// d->pixmap = new QPixmap(pixmap);
//}
//if (d->pixmap->depth() == 1 && !d->pixmap->mask())
// d->pixmap->setMask(*((QBitmap *)d->pixmap));
//d->updateLabel();
if(_noSignal)
_noSignal = false;
//static int k=0;
//k++;
//if(k > 50)
// return;
if(!_pPixmap || _pPixmap->cacheKey() != pxmp.cacheKey())
{
if(_pPixmap != NULL)
{
delete _pPixmap;
_pPixmap = NULL;
}
_pPixmap = new QPixmap(pxmp);
update(rect());
}
}
示例9: deleteBitmap
bool QWinThumbnailToolBarPrivate::IconicPixmapCache::setPixmap(const QPixmap &pixmap)
{
if (pixmap.cacheKey() == m_pixmap.cacheKey())
return false;
deleteBitmap();
m_pixmap = pixmap;
return true;
}
示例10: setPixmap
void QWindowsDragCursorWindow::setPixmap(const QPixmap &p)
{
if (p.cacheKey() == m_pixmap.cacheKey())
return;
const QSize oldSize = m_pixmap.size();
QSize newSize = p.size();
qCDebug(lcQpaMime) << __FUNCTION__ << p.cacheKey() << newSize;
m_pixmap = p;
if (oldSize != newSize) {
const qreal pixDevicePixelRatio = p.devicePixelRatio();
if (pixDevicePixelRatio > 1.0 && qFuzzyCompare(pixDevicePixelRatio, devicePixelRatio()))
newSize /= qRound(pixDevicePixelRatio);
resize(newSize);
}
if (isVisible())
update();
}
示例11: testEntryIcons
void TestGuiPixmaps::testEntryIcons()
{
Database* db = new Database();
Entry* entry = new Entry();
entry->setGroup(db->rootGroup());
QImage icon;
QImage image;
QPixmap pixmap;
QPixmap pixmapCached1;
QPixmap pixmapCached2;
icon = databaseIcons()->icon(10);
entry->setIcon(10);
image = entry->icon();
pixmap = entry->iconPixmap();
QCOMPARE(image, icon);
compareImages(pixmap, icon);
pixmapCached1 = entry->iconPixmap();
pixmapCached2 = databaseIcons()->iconPixmap(10);
compareImages(pixmapCached1, icon);
compareImages(pixmapCached2, icon);
QCOMPARE(pixmapCached1.cacheKey(), pixmap.cacheKey());
QCOMPARE(pixmapCached2.cacheKey(), pixmap.cacheKey());
Uuid iconUuid = Uuid::random();
icon = QImage(2, 1, QImage::Format_RGB32);
icon.setPixel(0, 0, qRgb(0, 0, 0));
icon.setPixel(1, 0, qRgb(0, 0, 50));
db->metadata()->addCustomIcon(iconUuid, icon);
entry->setIcon(iconUuid);
image = entry->icon();
pixmap = entry->iconPixmap();
QCOMPARE(image, icon);
compareImages(pixmap, icon);
pixmapCached1 = entry->iconPixmap();
compareImages(pixmapCached1, icon);
QCOMPARE(pixmapCached1.cacheKey(), pixmap.cacheKey());
delete db;
}
示例12: testDatabaseIcons
void TestGuiPixmaps::testDatabaseIcons()
{
QImage image;
QPixmap pixmap;
QPixmap pixmapCached;
image = databaseIcons()->icon(0);
pixmap = databaseIcons()->iconPixmap(0);
compareImages(pixmap, image);
// check if the cache works correctly
pixmapCached = databaseIcons()->iconPixmap(0);
compareImages(pixmapCached, image);
QCOMPARE(pixmapCached.cacheKey(), pixmap.cacheKey());
pixmap = databaseIcons()->iconPixmap(1);
image = databaseIcons()->icon(1);
compareImages(pixmap, image);
pixmapCached = databaseIcons()->iconPixmap(1);
compareImages(pixmapCached, image);
QCOMPARE(pixmapCached.cacheKey(), pixmap.cacheKey());
}
示例13: insertBlurTextureInfo
void QGLBlurTextureCache::insertBlurTextureInfo(const QPixmap &pixmap, QGLBlurTextureInfo *info)
{
static bool hookAdded = false;
if (!hookAdded) {
QImagePixmapCleanupHooks::instance()->addPixmapDataDestructionHook(pixmapDestroyed);
QImagePixmapCleanupHooks::instance()->addPixmapDataModificationHook(pixmapDestroyed);
hookAdded = true;
}
QImagePixmapCleanupHooks::enableCleanupHooks(pixmap);
cache.insert(pixmap.cacheKey(), info, pixmap.width() * pixmap.height());
if (timerId)
killTimer(timerId);
timerId = startTimer(8000);
}
示例14: insert
bool QPMCache::insert(const QString& key, const QPixmap &pixmap, int cost)
{
qint64 cacheKey = pixmap.cacheKey();
if (QCache<qint64, QDetachedPixmap>::object(cacheKey)) {
cacheKeys.insert(key, cacheKey);
return true;
}
bool success = QCache<qint64, QDetachedPixmap>::insert(cacheKey, new QDetachedPixmap(pixmap), cost);
if (success) {
cacheKeys.insert(key, cacheKey);
if (!id) {
id = startTimer(30000);
t = false;
}
}
return success;
}
示例15: bindTexture
GLuint QOpenGLTextureCache::bindTexture(QOpenGLContext *context, const QPixmap &pixmap, BindOptions options)
{
if (pixmap.isNull())
return 0;
QMutexLocker locker(&m_mutex);
qint64 key = pixmap.cacheKey();
// A QPainter is active on the image - take the safe route and replace the texture.
if (!pixmap.paintingActive()) {
QOpenGLCachedTexture *entry = m_cache.object(key);
if (entry && entry->options() == options) {
context->functions()->glBindTexture(GL_TEXTURE_2D, entry->id());
return entry->id();
}
}
GLuint id = bindTexture(context, key, pixmap.toImage(), options);
if (id > 0)
QImagePixmapCleanupHooks::enableCleanupHooks(pixmap);
return id;
}