diff options
author | Weblate <noreply@weblate.org> | 2018-03-10 15:09:31 +0000 |
---|---|---|
committer | Weblate <noreply@weblate.org> | 2018-03-10 15:09:31 +0000 |
commit | e823783499a7b2f8c3cbfb24ae428b39311bee5e (patch) | |
tree | 74138f1e34b8f090f62bd5412f38b8e185209302 /src-qt5/core/lumina-desktop-unified/src-desktop/QMLImageProvider.cpp | |
parent | Translated using Weblate (Italian) (diff) | |
parent | Add the beginnings of the new window frame (widgets-based) (diff) | |
download | lumina-e823783499a7b2f8c3cbfb24ae428b39311bee5e.tar.gz lumina-e823783499a7b2f8c3cbfb24ae428b39311bee5e.tar.bz2 lumina-e823783499a7b2f8c3cbfb24ae428b39311bee5e.zip |
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'src-qt5/core/lumina-desktop-unified/src-desktop/QMLImageProvider.cpp')
-rw-r--r-- | src-qt5/core/lumina-desktop-unified/src-desktop/QMLImageProvider.cpp | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src-qt5/core/lumina-desktop-unified/src-desktop/QMLImageProvider.cpp b/src-qt5/core/lumina-desktop-unified/src-desktop/QMLImageProvider.cpp new file mode 100644 index 00000000..a74d2585 --- /dev/null +++ b/src-qt5/core/lumina-desktop-unified/src-desktop/QMLImageProvider.cpp @@ -0,0 +1,65 @@ +//=========================================== +// Lumina-desktop source code +// Copyright (c) 2018, Ken Moore +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +#include <global-objects.h> +#include "QMLImageProvider.h" + +QMLImageProvider::QMLImageProvider(QQmlImageProviderBase::ImageType type) : QQuickImageProvider(type, 0){ + +} + +QMLImageProvider::~QMLImageProvider(){ + +} + +/*QMLImageProvider* QMLImageProvider::instance(){ + static QMLImageProvider *_prov = 0; + if(_prov==0){ _prov = new QMLImageProvider(); } + return _prov; +}*/ + +QImage QMLImageProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize){ + NativeWindowObject *win = Lumina::NWS->findWindow( id.section(":",1,1).toInt(), false); + if(win==0){ win = Lumina::NWS->findTrayWindow(id.section(":",1,1).toInt()); } + + if(!id.startsWith("image:")){ qDebug() << "Request Image:" << id << win << requestedSize; } + + QImage img(requestedSize,QImage::Format_RGB32); + if(win==0){ img.fill("black"); } //invalid window ID (should never happen) + else if(id.startsWith("image:")){ img = Lumina::NWS->GetWindowImage(win); } + else if(id.startsWith("icon:")){ + QIcon ico = win->property(NativeWindowObject::Icon).value<QIcon>(); + QList<QSize> sizes = ico.availableSizes(); + QSize sz(0,0); + //Just grab the largest size currently available + for(int i=0; i<sizes.length(); i++){ + if(sz.width()<sizes[i].width() && sz.height()<sizes[i].height()){ sz = sizes[i]; } + } + qDebug() << "Icon Sizes:" <<sizes; + img = ico.pixmap(sz).toImage(); + } + //qDebug() << "Got Window Image:" << img.size(); + if(img.size().isNull()){ + if(requestedSize.isValid()){ img = QImage(requestedSize,QImage::Format_RGB32); } + else{ img = QImage(QSize(64,64), QImage::Format_RGB32); } + img.fill("black"); + } + //qDebug() << "Final Window Image:" << img.size(); + if(size!=0){ + size->setHeight(img.height()); + size->setWidth( img.width() ); + } + if(requestedSize.isValid() && !requestedSize.isNull() && img.size()!=requestedSize){ + img = img.scaled(requestedSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); + } + return img; +} + +QPixmap QMLImageProvider::requestPixmap(const QString &id, QSize *size, const QSize &requestedSize){ + qDebug() << "Pixmap Requested:" << id; + QImage img = requestImage(id, size, requestedSize); + return QPixmap::fromImage(img); +} |