Changeset View
Changeset View
Standalone View
Standalone View
dataengines/statusnotifieritem/statusnotifieritemsource.cpp
Show First 20 Lines • Show All 384 Lines • ▼ Show 20 Line(s) | |||||
385 | void StatusNotifierItemSource::contextMenuReady() | 385 | void StatusNotifierItemSource::contextMenuReady() | ||
386 | { | 386 | { | ||
387 | emit contextMenuReady(m_menuImporter->menu()); | 387 | emit contextMenuReady(m_menuImporter->menu()); | ||
388 | } | 388 | } | ||
389 | 389 | | |||
390 | QPixmap StatusNotifierItemSource::KDbusImageStructToPixmap(const KDbusImageStruct &image) const | 390 | QPixmap StatusNotifierItemSource::KDbusImageStructToPixmap(const KDbusImageStruct &image) const | ||
391 | { | 391 | { | ||
392 | //swap from network byte order if we are little endian | 392 | //swap from network byte order if we are little endian | ||
393 | if (QSysInfo::ByteOrder == QSysInfo::LittleEndian) { | 393 | if (QSysInfo::ByteOrder == QSysInfo::LittleEndian) { | ||
394 | uint *uintBuf = (uint *) image.data.data(); | 394 | uint *uintBuf = (uint *) image.data.data(); | ||
395 | for (uint i = 0; i < image.data.size()/sizeof(uint); ++i) { | 395 | for (uint i = 0; i < image.data.size()/sizeof(uint); ++i) { | ||
396 | *uintBuf = ntohl(*uintBuf); | 396 | *uintBuf = ntohl(*uintBuf); | ||
397 | ++uintBuf; | 397 | ++uintBuf; | ||
398 | } | 398 | } | ||
399 | } | 399 | } | ||
markg: Unrelated to your commit, i know.
Is there a reason why this is done at runtime?
```
#if… | |||||
400 | if (image.width == 0 || image.height == 0) { | 400 | if (image.width == 0 || image.height == 0) { | ||
401 | return QPixmap(); | 401 | return QPixmap(); | ||
402 | } | 402 | } | ||
403 | 403 | | |||
404 | QImage iconImage(image.width, image.height, QImage::Format_ARGB32 ); | 404 | //avoid a deep copy of the image data | ||
405 | memcpy(iconImage.bits(), (uchar*)image.data.data(), iconImage.byteCount()); | 405 | //we need to keep a reference to the image.data alive for the lifespan of the image, even if the image is copied | ||
406 | 406 | //we create a new QByteArray with a shallow copy of the original data on the heap, then delete this in the QImage cleanup | |||
407 | auto dataRef = new QByteArray(image.data); | ||||
408 | | ||||
409 | QImage iconImage(reinterpret_cast<const uchar*>(dataRef->data()), image.width, image.height, QImage::Format_ARGB32, | ||||
Very smart! I didn't even know that was possible. markg: Very smart! I didn't even know that was possible.
The cast should change to a C++ style cast… | |||||
410 | [](void* ptr) { | ||||
411 | delete static_cast<QByteArray*>(ptr); | ||||
412 | }, | ||||
413 | dataRef); | ||||
407 | return QPixmap::fromImage(iconImage); | 414 | return QPixmap::fromImage(iconImage); | ||
408 | } | 415 | } | ||
409 | 416 | | |||
410 | QIcon StatusNotifierItemSource::imageVectorToPixmap(const KDbusImageVector &vector) const | 417 | QIcon StatusNotifierItemSource::imageVectorToPixmap(const KDbusImageVector &vector) const | ||
411 | { | 418 | { | ||
412 | QIcon icon; | 419 | QIcon icon; | ||
413 | 420 | | |||
414 | for (int i = 0; i<vector.size(); ++i) { | 421 | for (int i = 0; i<vector.size(); ++i) { | ||
▲ Show 20 Lines • Show All 101 Lines • Show Last 20 Lines |
Unrelated to your commit, i know.
Is there a reason why this is done at runtime?
Just curious.