forked from quickshell/quickshell
		
	core/icon: add icon image provider
This commit is contained in:
		
							parent
							
								
									8e530b6b77
								
							
						
					
					
						commit
						d47a7f2cff
					
				
					 5 changed files with 31 additions and 1 deletions
				
			
		| 
						 | 
					@ -22,6 +22,7 @@ qt_add_library(quickshell-core STATIC
 | 
				
			||||||
	incubator.cpp
 | 
						incubator.cpp
 | 
				
			||||||
	lazyloader.cpp
 | 
						lazyloader.cpp
 | 
				
			||||||
	easingcurve.cpp
 | 
						easingcurve.cpp
 | 
				
			||||||
 | 
						iconimageprovider.cpp
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
set_source_files_properties(main.cpp PROPERTIES COMPILE_DEFINITIONS GIT_REVISION="${GIT_REVISION}")
 | 
					set_source_files_properties(main.cpp PROPERTIES COMPILE_DEFINITIONS GIT_REVISION="${GIT_REVISION}")
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -14,6 +14,7 @@
 | 
				
			||||||
#include <qqmlincubator.h>
 | 
					#include <qqmlincubator.h>
 | 
				
			||||||
#include <qtimer.h>
 | 
					#include <qtimer.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "iconimageprovider.hpp"
 | 
				
			||||||
#include "incubator.hpp"
 | 
					#include "incubator.hpp"
 | 
				
			||||||
#include "plugin.hpp"
 | 
					#include "plugin.hpp"
 | 
				
			||||||
#include "qsintercept.hpp"
 | 
					#include "qsintercept.hpp"
 | 
				
			||||||
| 
						 | 
					@ -30,6 +31,8 @@ EngineGeneration::EngineGeneration(QmlScanner scanner)
 | 
				
			||||||
	this->engine.addUrlInterceptor(&this->urlInterceptor);
 | 
						this->engine.addUrlInterceptor(&this->urlInterceptor);
 | 
				
			||||||
	this->engine.setNetworkAccessManagerFactory(&this->interceptNetFactory);
 | 
						this->engine.setNetworkAccessManagerFactory(&this->interceptNetFactory);
 | 
				
			||||||
	this->engine.setIncubationController(&this->delayedIncubationController);
 | 
						this->engine.setIncubationController(&this->delayedIncubationController);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						this->engine.addImageProvider("icon", new IconImageProvider());
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
EngineGeneration::~EngineGeneration() {
 | 
					EngineGeneration::~EngineGeneration() {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										16
									
								
								src/core/iconimageprovider.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								src/core/iconimageprovider.cpp
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,16 @@
 | 
				
			||||||
 | 
					#include "iconimageprovider.hpp"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <qicon.h>
 | 
				
			||||||
 | 
					#include <qlogging.h>
 | 
				
			||||||
 | 
					#include <qpixmap.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					QPixmap
 | 
				
			||||||
 | 
					IconImageProvider::requestPixmap(const QString& id, QSize* size, const QSize& requestedSize) {
 | 
				
			||||||
 | 
						auto icon = QIcon::fromTheme(id);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						auto targetSize = requestedSize.isValid() ? requestedSize : QSize(100, 100);
 | 
				
			||||||
 | 
						auto pixmap = icon.pixmap(targetSize.width(), targetSize.height());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (size != nullptr) *size = pixmap.size();
 | 
				
			||||||
 | 
						return pixmap;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										11
									
								
								src/core/iconimageprovider.hpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								src/core/iconimageprovider.hpp
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,11 @@
 | 
				
			||||||
 | 
					#pragma once
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <qpixmap.h>
 | 
				
			||||||
 | 
					#include <qquickimageprovider.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class IconImageProvider: public QQuickImageProvider {
 | 
				
			||||||
 | 
					public:
 | 
				
			||||||
 | 
						explicit IconImageProvider(): QQuickImageProvider(QQuickImageProvider::Pixmap) {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						QPixmap requestPixmap(const QString& id, QSize* size, const QSize& requestedSize) override;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
| 
						 | 
					@ -1,6 +1,5 @@
 | 
				
			||||||
set_source_files_properties(org.freedesktop.DBus.Properties.xml PROPERTIES
 | 
					set_source_files_properties(org.freedesktop.DBus.Properties.xml PROPERTIES
 | 
				
			||||||
	CLASSNAME DBusPropertiesInterface
 | 
						CLASSNAME DBusPropertiesInterface
 | 
				
			||||||
	#INCLUDE dbus_properties_types.hpp
 | 
					 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
qt_add_dbus_interface(DBUS_INTERFACES
 | 
					qt_add_dbus_interface(DBUS_INTERFACES
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue