Commits

opampg  committed a9d94eb

QMLに描画方法を変更中

  • Participants
  • Parent commits 76a5db0
  • Branches dev

Comments (0)

Files changed (9)

File CMakeLists.txt

 
 SET(LIBWEBP_PREFIX "" CACHE PATH "path to libwebp prefix.")
 
-INCLUDE_DIRECTORIES(/usr/include /usr/local/include ${LIBWEBP_PREFIX}/include)
+INCLUDE_DIRECTORIES(/usr/include /usr/local/include ${LIBWEBP_PREFIX}/include ${QT_QTDECLARATIVE_INCLUDE_DIR})
 LINK_DIRECTORIES(/usr/lib /usr/local/lib ${LIBWEBP_PREFIX}/lib)
 
 INCLUDE(${PROJECT_SOURCE_DIR}/src/CMakeLists.txt)

File src/CMakeLists.txt

 	${SRC_DIR}/MainWindow.hpp
 	${SRC_DIR}/decoder.hpp
 	${SRC_DIR}/QImageViewer.hpp
+	${SRC_DIR}/ColorImageProvider.hpp 
 	)
 
 QT4_WRAP_CPP(HMOD ${MHED})
 ELSEIF(UNIX AND NOT APPLE)
 	ADD_EXECUTABLE(${EXECUTABLE_FILE_NAME} ${SRCS})
 ENDIF()
-TARGET_LINK_LIBRARIES(${EXECUTABLE_FILE_NAME} ${QT_LIBRARIES} utils webp) # Link 
+TARGET_LINK_LIBRARIES(${EXECUTABLE_FILE_NAME} ${QT_LIBRARIES} ${QT_QTDECLARATIVE_LIBRARY} utils webp) # Link
 
 IF(UNIX AND NOT APPLE)
 	INSTALL(TARGETS ${EXECUTABLE_FILE_NAME} RUNTIME DESTINATION bin)

File src/ColorImageProvider.hpp

+#pragma onece
+#include<QDeclarativeImageProvider>
+#include"decoder.hpp"
+
+class ColorImageProvider : public QDeclarativeImageProvider
+{
+public:
+	ColorImageProvider()
+		:QDeclarativeImageProvider(QDeclarativeImageProvider::Image){}
+
+	QImage requestImage(const QString &id, QSize *size, const QSize &requestedSize)
+	{
+		decoder d;
+		d.setFileName(QString("/Users/opamp/Desktop/test.webp"));
+		d.init();
+		QImage img = *d.getQImage();
+		return img;
+	}
+};

File src/MainWindow.cpp

 #include"MainWindow.hpp"
+#include<iostream>
 
-#include<iostream>
 
 MainWindow::MainWindow()
 {
+/*
     w = new QImageViewer();
     decoder d;
     d.setFileName(QString("/Users/opamp/Desktop/test.webp"));
     d.init();
     w->setQImage(d.getQImage());
-
+*/
+    w = new QDeclarativeView();
+//    w->engine()->addImageProvider(QLatin1String("colors"), new ColorPixmapProvider());
+    w->setSource(QUrl("qrc:qml/resources/qmls/WebPViewer.qml"));
+    w->show();
     setCentralWidget(w);
     setWindowTitle(tr("WebPViewer test"));
 }

File src/MainWindow.hpp

 #pragma onece
 #include<QMainWindow>
-
-#include"QImageViewer.hpp"
-#include"decoder.hpp"
+#include<QtDeclarative/QDeclarativeView>
+#include"ColorImageProvider.hpp"
+//#include"QImageViewer.hpp"
 
 class MainWindow : public QMainWindow
 {
     MainWindow();
 
 private:
-    QImageViewer* w;
+//   QImageViewer* w;
+    QDeclarativeView *w;
 };

File src/QImageViewer.cpp

     }
 }
 
-void QImageViewer::draw(QPainter* p)
-{
-
-}
 
 void QImageViewer::paintEvent(QPaintEvent *event)
 {

File src/QImageViewer.hpp

     QRect pixelRect(int i,int j);
 
 private:
-    void draw(QPainter*);
-
     QImage* img;
     int zoom;
 };

File src/main.qrc

     <qresource prefix="/text">
         <file>resources/text/MIT_LICENSE</file>
     </qresource>
+    <qresource prefix="/qml">
+        <file>resources/qmls/WebPViewer.qml</file>
+    </qresource>
 </RCC>

File src/resources/qmls/WebPViewer.qml

+import QtQuick 1.0
+
+Rectangle{
+    Text {
+        id: text1
+        x: -80
+        y: -60
+        width: 23
+        height: 0
+        text: qsTr("text")
+        font.pixelSize: 12
+    }
+
+    Image {
+        id: image1
+        x: -93
+        y: -45
+        width: 100
+        height: 100
+        source: "q"
+    }
+
+}