Selaa lähdekoodia

Move base64HTMLImageTagSrc into ctkWidgetsUtils

Julien Finet 14 vuotta sitten
vanhempi
commit
b27b582463

+ 1 - 0
Libs/Visualization/VTK/Widgets/Testing/Cpp/ctkVTKScalarsToColorsUtilsTest1.cpp

@@ -25,6 +25,7 @@
 #include <QTimer>
 
 // CTK includes
+#include "ctkWidgetsUtils.h"
 #include "ctkVTKScalarsToColorsUtils.h"
 
 // VTK includes

+ 0 - 11
Libs/Visualization/VTK/Widgets/ctkVTKScalarsToColorsUtils.cpp

@@ -79,14 +79,3 @@ QImage ctk::scalarsToColorsImage(vtkScalarsToColors* scalarsToColors, const QSiz
 
   return transferFunctionImage;
 }
-
-//----------------------------------------------------------------------------
-QString ctk::base64HTMLImageTagSrc(const QImage& image)
-{
-  QByteArray byteArray;
-  QBuffer buffer(&byteArray);
-  buffer.open(QIODevice::WriteOnly);
-  image.save(&buffer, "PNG");
-  return QString("data:image/png;base64,%1")
-    .arg(QString(buffer.data().toBase64()));
-}

+ 0 - 6
Libs/Visualization/VTK/Widgets/ctkVTKScalarsToColorsUtils.h

@@ -34,12 +34,6 @@ namespace ctk {
 /// If size is empty, it will use the large icon size of the application style
 QImage CTK_VISUALIZATION_VTK_WIDGETS_EXPORT scalarsToColorsImage(vtkScalarsToColors* scalarsToColors, const QSize& size = QSize());
 
-///
-/// \ingroup vtkWidgets
-/// Create a base 64 image tag. Can be used that way:
-/// QString("<img src=\"%1\">").arg(base64HTMLImageTagSrc(myImage);
-QString CTK_VISUALIZATION_VTK_WIDGETS_EXPORT base64HTMLImageTagSrc(const QImage& image);
-
 }
 
 #endif

+ 2 - 0
Libs/Widgets/CMakeLists.txt

@@ -119,6 +119,8 @@ SET(KIT_SRCS
   ctkTransferFunctionView.h
   ctkTreeComboBox.cpp
   ctkTreeComboBox.h
+  ctkWidgetsUtils.cpp
+  ctkWidgetsUtils.h
   ctkWorkflowAbstractPagedWidget.cpp
   ctkWorkflowAbstractPagedWidget.h
   ctkWorkflowButtonBoxWidget.cpp

+ 37 - 0
Libs/Widgets/ctkWidgetsUtils.cpp

@@ -0,0 +1,37 @@
+/*=========================================================================
+
+  Library:   CTK
+
+  Copyright (c) Kitware Inc.
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.commontk.org/LICENSE
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=========================================================================*/
+
+// Qt includes
+#include <QBuffer>
+#include <QImage>
+
+// ctkWidgets includes
+#include "ctkWidgetsUtils.h"
+
+//----------------------------------------------------------------------------
+QString ctk::base64HTMLImageTagSrc(const QImage& image)
+{
+  QByteArray byteArray;
+  QBuffer buffer(&byteArray);
+  buffer.open(QIODevice::WriteOnly);
+  image.save(&buffer, "PNG");
+  return QString("data:image/png;base64,%1")
+    .arg(QString(buffer.data().toBase64()));
+}

+ 39 - 0
Libs/Widgets/ctkWidgetsUtils.h

@@ -0,0 +1,39 @@
+/*=========================================================================
+
+  Library:   CTK
+
+  Copyright (c) Kitware Inc.
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.commontk.org/LICENSE
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=========================================================================*/
+
+#ifndef __ctkWidgetsUtils_h
+#define __ctkWidgetsUtils_h
+
+// Qt includes
+#include <QString>
+class QImage;
+
+#include "ctkWidgetsExport.h"
+
+namespace ctk {
+///
+/// \ingroup Widgets
+/// Create a base 64 image tag. Can be used that way:
+/// QString("<img src=\"%1\">").arg(base64HTMLImageTagSrc(myImage);
+QString CTK_WIDGETS_EXPORT base64HTMLImageTagSrc(const QImage& image);
+
+}
+
+#endif