diff --git a/inc/hgl/qt/SVGPixmap.h b/inc/hgl/qt/SVGPixmap.h new file mode 100644 index 0000000..35da030 --- /dev/null +++ b/inc/hgl/qt/SVGPixmap.h @@ -0,0 +1,34 @@ +#pragma once + +#include +#include +#include + +namespace hgl +{ + namespace qt + { + class SVGPixmap + { + QSvgRenderer *svg; + + public: + + const QSize size()const + { + return svg?svg->defaultSize():QSize(0,0); + } + + public: + + SVGPixmap(){svg=nullptr;} + ~SVGPixmap(){if(svg)delete svg;} + + bool Load(const QString &); + + QPixmap bitmap(const uint size); + };//class SVGPixmap + + QPixmap LoadSVG(const QString &filename,const uint size); + }//namespace qt +}//namespace hgl \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2edcd80..988459b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,4 +1,4 @@ -find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS Gui Widgets) +find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS Gui Widgets Svg Xml) SET(CMQT_INCLUDE_PATH ${CMQT_ROOT_INCLUDE_PATH}/hgl/qt) @@ -16,7 +16,10 @@ SET(CMQT_DIALOG_FILES ${CMQT_DIALOG_INCLUDE_PATH}/NameEdit.h SOURCE_GROUP("Dialog" FILES ${CMQT_DIALOG_FILES}) -add_cm_library(CMQT "CM" ${CMQT_DIALOG_FILES}) +SET(CMQT_IMAGE_FILES image/SVGPixmap.cpp) -target_link_libraries(CMQT PUBLIC Qt5::Core Qt5::Gui Qt5::Widgets) +SOURCE_GROUP("Image" FILES ${CMQT_IMAGE_FILES}) +add_cm_library(CMQT "CM" ${CMQT_DIALOG_FILES} ${CMQT_IMAGE_FILES}) + +target_link_libraries(CMQT PUBLIC Qt5::Core Qt5::Gui Qt5::Widgets Qt5::Svg Qt5::Xml) \ No newline at end of file diff --git a/src/image/SVGPixmap.cpp b/src/image/SVGPixmap.cpp new file mode 100644 index 0000000..2e238cf --- /dev/null +++ b/src/image/SVGPixmap.cpp @@ -0,0 +1,69 @@ +#include +#include +#include +#include + +namespace hgl +{ + namespace qt + { + bool SVGPixmap::Load(const QString &filename) + { + QFile file(filename); + + if(!file.open(QIODevice::ReadOnly)) + return(false); + + QByteArray baData = file.readAll(); + + QDomDocument doc; + doc.setContent(baData); + + if(svg)delete svg; + + svg=new QSvgRenderer(doc.toByteArray()); + + return(true); + } + + QPixmap SVGPixmap::bitmap(const uint size) + { + if(!svg||size==0) + return QPixmap(0,0); + + QPixmap pix(size,size); + + pix.fill(Qt::transparent); + + QPainter pixPainter(&pix); + + svg->render(&pixPainter); + + return pix; + } + + QPixmap LoadSVG(const QString &filename,const uint size) + { + QFile file(filename); + + if(!file.open(QIODevice::ReadOnly)) + return(QPixmap(size,size)); + + QByteArray baData = file.readAll(); + + QDomDocument doc; + doc.setContent(baData); + + QSvgRenderer svg(doc.toByteArray()); + QPixmap pix(size,size); + + pix.fill(Qt::transparent); + + QPainter pixPainter(&pix); + + svg.render(&pixPainter); + + return pix; + } + }//namespace qt +}//namespace hgl \ No newline at end of file