added SVGPixmap
This commit is contained in:
parent
aaac66e4a7
commit
833ae63cd4
34
inc/hgl/qt/SVGPixmap.h
Normal file
34
inc/hgl/qt/SVGPixmap.h
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include<QPixmap>
|
||||||
|
#include<QString>
|
||||||
|
#include<QSvgRenderer>
|
||||||
|
|
||||||
|
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
|
@ -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)
|
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})
|
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)
|
69
src/image/SVGPixmap.cpp
Normal file
69
src/image/SVGPixmap.cpp
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
#include<hgl/qt/SVGPixmap.h>
|
||||||
|
#include<QFile>
|
||||||
|
#include<QtXml/QDomDocument>
|
||||||
|
#include<QPainter>
|
||||||
|
|
||||||
|
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
|
Loading…
x
Reference in New Issue
Block a user