This commit is contained in:
Gary Wang 2019-09-29 23:53:29 +08:00
parent a4d8376c20
commit d106d9beee
13 changed files with 477 additions and 56 deletions

View File

@ -1,45 +1,48 @@
#------------------------------------------------- #-------------------------------------------------
# #
# Project created by QtCreator 2019-09-26T23:36:07 # Project created by QtCreator 2019-09-26T23:36:07
# #
#------------------------------------------------- #-------------------------------------------------
QT += core gui QT += core gui svg
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = PineapplePictures TARGET = PineapplePictures
TEMPLATE = app TEMPLATE = app
# The following define makes your compiler emit warnings if you use # The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings # any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the # depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it. # deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs. # You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line. # In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt. # You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
CONFIG += c++11 CONFIG += c++11
SOURCES += \ SOURCES += \
main.cpp \ main.cpp \
mainwindow.cpp \ mainwindow.cpp \
graphicsview.cpp \ graphicsview.cpp \
bottombuttongroup.cpp \ bottombuttongroup.cpp \
graphicsscene.cpp graphicsscene.cpp
HEADERS += \ HEADERS += \
mainwindow.h \ mainwindow.h \
graphicsview.h \ graphicsview.h \
bottombuttongroup.h \ bottombuttongroup.h \
graphicsscene.h graphicsscene.h
FORMS += FORMS +=
# Default rules for deployment. # Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target !isEmpty(target.path): INSTALLS += target
RESOURCES += \
resources.qrc

View File

@ -24,15 +24,16 @@ BottomButtonGroup::BottomButtonGroup(QWidget *parent)
"}"); "}");
auto newBtn = [](QString text) -> QPushButton * { auto newBtn = [](QString text) -> QPushButton * {
QPushButton * btn = new QPushButton(text); QPushButton * btn = new QPushButton(QIcon(QStringLiteral(":/icons/") + text), "");
btn->setIconSize(QSize(40, 40));
btn->setFixedSize(40, 40); btn->setFixedSize(40, 40);
return btn; return btn;
}; };
addButton(newBtn("1:1")); addButton(newBtn("zoom-original"));
addButton(newBtn("Full")); addButton(newBtn("view-fullscreen"));
addButton(newBtn("Zoom+")); addButton(newBtn("zoom-in"));
addButton(newBtn("Zoom-")); addButton(newBtn("zoom-out"));
addButton(newBtn("Rorate")); addButton(newBtn("object-rorate-right"));
} }
void BottomButtonGroup::addButton(QAbstractButton *button) void BottomButtonGroup::addButton(QAbstractButton *button)

View File

@ -5,6 +5,7 @@
#include <QDebug> #include <QDebug>
#include <QGraphicsItem> #include <QGraphicsItem>
#include <QUrl> #include <QUrl>
#include <QGraphicsSvgItem>
GraphicsScene::GraphicsScene(QObject *parent) GraphicsScene::GraphicsScene(QObject *parent)
: QGraphicsScene(parent) : QGraphicsScene(parent)
@ -32,3 +33,12 @@ void GraphicsScene::showText(const QString &text)
m_theThing = textItem; m_theThing = textItem;
this->setSceneRect(m_theThing->boundingRect()); this->setSceneRect(m_theThing->boundingRect());
} }
void GraphicsScene::showSvg(const QString &filepath)
{
this->clear();
QGraphicsSvgItem * svgItem = new QGraphicsSvgItem(filepath);
this->addItem(svgItem);
m_theThing = svgItem;
this->setSceneRect(m_theThing->boundingRect());
}

View File

@ -12,6 +12,7 @@ public:
void showImage(const QPixmap &pixmap); void showImage(const QPixmap &pixmap);
void showText(const QString &text); void showText(const QString &text);
void showSvg(const QString &filepath);
private: private:
QGraphicsItem * m_theThing; QGraphicsItem * m_theThing;

View File

@ -35,6 +35,11 @@ void GraphicsView::showText(const QString &text)
scene()->showText(text); scene()->showText(text);
} }
void GraphicsView::showSvg(const QString &filepath)
{
scene()->showSvg(filepath);
}
GraphicsScene *GraphicsView::scene() const GraphicsScene *GraphicsView::scene() const
{ {
return qobject_cast<GraphicsScene*>(QGraphicsView::scene()); return qobject_cast<GraphicsScene*>(QGraphicsView::scene());
@ -129,12 +134,18 @@ void GraphicsView::dropEvent(QDropEvent *event)
if (mimeData->hasUrls()) { if (mimeData->hasUrls()) {
QUrl url(mimeData->urls().first()); QUrl url(mimeData->urls().first());
QImageReader imageReader(url.toLocalFile()); QString filePath(url.toLocalFile());
QImage::Format imageFormat = imageReader.imageFormat();
if (imageFormat == QImage::Format_Invalid) { if (filePath.endsWith(".svg")) {
showText("File is not a valid image"); showSvg(filePath);
} else { } else {
showImage(QPixmap::fromImageReader(&imageReader)); QImageReader imageReader(filePath);
QImage::Format imageFormat = imageReader.imageFormat();
if (imageFormat == QImage::Format_Invalid) {
showText("File is not a valid image");
} else {
showImage(QPixmap::fromImageReader(&imageReader));
}
} }
} else if (mimeData->hasImage()) { } else if (mimeData->hasImage()) {
QImage img = qvariant_cast<QImage>(mimeData->imageData()); QImage img = qvariant_cast<QImage>(mimeData->imageData());

View File

@ -11,6 +11,7 @@ public:
void showImage(const QPixmap &pixmap); void showImage(const QPixmap &pixmap);
void showText(const QString &text); void showText(const QString &text);
void showSvg(const QString &filepath);
GraphicsScene * scene() const; GraphicsScene * scene() const;
void setScene(GraphicsScene *scene); void setScene(GraphicsScene *scene);

View File

@ -0,0 +1,70 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="32"
height="32"
viewBox="0 0 8.4666665 8.4666669"
version="1.1"
id="svg8"
inkscape:version="0.92.4 (5da689c313, 2019-01-14)"
sodipodi:docname="object-rorate-right.svg">
<defs
id="defs2" />
<sodipodi:namedview
id="base"
pagecolor="#000000"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.69803922"
inkscape:pageshadow="2"
inkscape:zoom="22.4"
inkscape:cx="13.471207"
inkscape:cy="14.931415"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="false"
units="px"
inkscape:pagecheckerboard="true"
inkscape:window-width="1920"
inkscape:window-height="1001"
inkscape:window-x="-9"
inkscape:window-y="-9"
inkscape:window-maximized="1" />
<metadata
id="metadata5">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(0,-288.5333)">
<path
style="fill:none;stroke:#ffffff;stroke-width:0.26458332px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 6.2474252,294.57784 c -1.6704347,1.43657 -3.1237125,0.51783 -3.1237125,0.51783 -0.650925,-0.38244 -0.9769945,-1.03846 -1.0690781,-1.42823 -0.032148,-0.5952 -0.1092884,-1.34357 0.3591432,-1.95439 0.5186761,-0.51984 0.9614825,-0.84964 1.4783346,-0.9271 l 1.302939,-0.0167"
id="path21"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cccccc" />
<path
style="fill:none;stroke:#ffffff;stroke-width:0.26458332px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 4.5352297,289.82545 c 0.6598217,0.9438 0.6598217,0.9438 0.6598217,0.9438 l -0.626413,0.94379 -0.033409,0.0334"
id="path25"
inkscape:connector-curvature="0" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.5 KiB

86
icons/view-fullscreen.svg Normal file
View File

@ -0,0 +1,86 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="32"
height="32"
viewBox="0 0 8.4666665 8.4666669"
version="1.1"
id="svg8"
inkscape:version="0.92.4 (5da689c313, 2019-01-14)"
sodipodi:docname="view-fullscreen-a.svg">
<defs
id="defs2" />
<sodipodi:namedview
id="base"
pagecolor="#000000"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.69803922"
inkscape:pageshadow="2"
inkscape:zoom="22.4"
inkscape:cx="6.127457"
inkscape:cy="14.931415"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="false"
units="px"
inkscape:pagecheckerboard="true"
inkscape:window-width="1920"
inkscape:window-height="1001"
inkscape:window-x="-9"
inkscape:window-y="-9"
inkscape:window-maximized="1" />
<metadata
id="metadata5">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title />
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(0,-288.5333)">
<rect
style="fill:none;fill-opacity:1;stroke:#ffffff;stroke-width:0.37041667;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="rect835"
width="2.4214098"
height="1.8308237"
x="3.0710566"
y="291.59018" />
<path
style="fill:none;stroke:#ffffff;stroke-width:0.26458332px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 1.630022,292.00359 1.615848,290.14918 H 3.6380209"
id="path837"
inkscape:connector-curvature="0" />
<path
style="fill:none;stroke:#ffffff;stroke-width:0.26531255px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 6.9097992,291.96816 0.014252,-1.85441 -2.0333353,0"
id="path837-6"
inkscape:connector-curvature="0" />
<path
style="fill:none;stroke:#ffffff;stroke-width:0.26458332px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 6.9306311,293.21954 0.014174,1.85441 H 4.9226322"
id="path837-9"
inkscape:connector-curvature="0" />
<path
style="fill:none;stroke:#ffffff;stroke-width:0.26531255px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 1.6393869,293.16031 -0.014252,1.85441 h 2.0333353"
id="path837-6-4"
inkscape:connector-curvature="0" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.9 KiB

81
icons/zoom-in.svg Normal file
View File

@ -0,0 +1,81 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="32"
height="32"
viewBox="0 0 8.4666665 8.4666669"
version="1.1"
id="svg8"
inkscape:version="0.92.4 (5da689c313, 2019-01-14)"
sodipodi:docname="zoom-in-a.svg">
<defs
id="defs2" />
<sodipodi:namedview
id="base"
pagecolor="#000000"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.69803922"
inkscape:pageshadow="2"
inkscape:zoom="16"
inkscape:cx="17.492176"
inkscape:cy="13.486663"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="false"
units="px"
inkscape:pagecheckerboard="true"
inkscape:window-width="1920"
inkscape:window-height="1001"
inkscape:window-x="-9"
inkscape:window-y="-9"
inkscape:window-maximized="1" />
<metadata
id="metadata5">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title />
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(0,-288.5333)">
<circle
style="fill:none;stroke:#ffffff;stroke-width:0.26458332;stroke-opacity:1"
id="path825"
cx="3.8955173"
cy="292.02957"
r="1.9725631" />
<path
style="fill:none;stroke:#ffffff;stroke-width:0.26458332px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 2.8678944,292.07683 H 4.9703868"
id="path827"
inkscape:connector-curvature="0" />
<path
style="fill:none;stroke:#ffffff;stroke-width:0.26458332px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 3.9309524,290.90746 0.035435,2.29149"
id="path829"
inkscape:connector-curvature="0" />
<path
style="fill:none;stroke:#ffffff;stroke-width:0.5291667;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 5.2066218,293.63598 1.3465403,1.42922 v 0"
id="path831"
inkscape:connector-curvature="0"
sodipodi:nodetypes="ccc" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.6 KiB

71
icons/zoom-original.svg Normal file
View File

@ -0,0 +1,71 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="32"
height="32"
viewBox="0 0 8.4666665 8.4666669"
version="1.1"
id="svg8"
inkscape:version="0.92.4 (5da689c313, 2019-01-14)"
sodipodi:docname="zoom-original-a.svg">
<defs
id="defs2" />
<sodipodi:namedview
id="base"
pagecolor="#000000"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.69803922"
inkscape:pageshadow="2"
inkscape:zoom="15.839192"
inkscape:cx="22.610899"
inkscape:cy="17.020554"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="false"
units="px"
inkscape:pagecheckerboard="true"
inkscape:window-width="1920"
inkscape:window-height="1001"
inkscape:window-x="-9"
inkscape:window-y="-9"
inkscape:window-maximized="1" />
<metadata
id="metadata5">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title />
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(0,-288.5333)">
<text
xml:space="preserve"
style="font-style:normal;font-weight:normal;font-size:10.30979729px;line-height:6.44362354px;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:0.25774494;"
x="1.0365982"
y="259.85211"
id="text819"
transform="scale(0.88039913,1.1358485)"><tspan
sodipodi:role="line"
id="tspan817"
x="1.0365982"
y="259.85211"
style="font-size:5.84221935px;stroke-width:0.25774494;fill:#ffffff;fill-opacity:1;">1:1</tspan></text>
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.2 KiB

76
icons/zoom-out.svg Normal file
View File

@ -0,0 +1,76 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="32"
height="32"
viewBox="0 0 8.4666665 8.4666669"
version="1.1"
id="svg8"
inkscape:version="0.92.4 (5da689c313, 2019-01-14)"
sodipodi:docname="zoom-out-a.svg">
<defs
id="defs2" />
<sodipodi:namedview
id="base"
pagecolor="#000000"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.69803922"
inkscape:pageshadow="2"
inkscape:zoom="16"
inkscape:cx="17.492176"
inkscape:cy="13.486663"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="false"
units="px"
inkscape:pagecheckerboard="true"
inkscape:window-width="1920"
inkscape:window-height="1001"
inkscape:window-x="-9"
inkscape:window-y="-9"
inkscape:window-maximized="1" />
<metadata
id="metadata5">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(0,-288.5333)">
<circle
style="fill:none;stroke:#ffffff;stroke-width:0.26458332;stroke-opacity:1"
id="path825"
cx="3.8955173"
cy="292.02957"
r="1.9725631" />
<path
style="fill:none;stroke:#ffffff;stroke-width:0.26458332px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 2.8678944,292.07683 H 4.9703868"
id="path827"
inkscape:connector-curvature="0" />
<path
style="fill:none;stroke:#ffffff;stroke-width:0.5291667;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 5.2066218,293.63598 1.3465403,1.42922 v 0"
id="path831"
inkscape:connector-curvature="0"
sodipodi:nodetypes="ccc" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.4 KiB

View File

@ -4,6 +4,7 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QApplication a(argc, argv); QApplication a(argc, argv);
MainWindow w; MainWindow w;
w.show(); w.show();

9
resources.qrc Normal file
View File

@ -0,0 +1,9 @@
<RCC>
<qresource prefix="/">
<file>icons/zoom-in.svg</file>
<file>icons/zoom-out.svg</file>
<file>icons/view-fullscreen.svg</file>
<file>icons/zoom-original.svg</file>
<file>icons/object-rorate-right.svg</file>
</qresource>
</RCC>