mirror of
https://github.com/jkriege2/JKQtPlotter.git
synced 2024-12-24 17:41:39 +08:00
added Code+CMake facilities to auto-generate screenshots
This commit is contained in:
parent
7030475568
commit
02fbabff5c
@ -57,3 +57,38 @@ if(JKQtPlotter_BUILD_TOOLS)
|
||||
|
||||
add_dependencies(JKQTMathText_GenerateDocImages JKQTMathText_GenerateDocImages_listsymbols)
|
||||
endif()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if(JKQtPlotter_BUILD_EXAMPLES)
|
||||
|
||||
# custom target that generates the images for the JKQTMathText documentation
|
||||
set(JKQTPlotter_GenerateDocScreenshots_DefaultOptions --screenshotdir="${CMAKE_CURRENT_LIST_DIR}/../screenshots/" --screenshot --smallscreenshotplot)
|
||||
set(JKQTPlotter_GenerateDocScreenshots_From
|
||||
)
|
||||
|
||||
add_custom_target(JKQTPlotter_GenerateDocScreenshots
|
||||
COMMENT "Building JKQTPlotter Documentation Screenshots ..."
|
||||
)
|
||||
|
||||
foreach(example ${JKQTPlotter_GenerateDocScreenshots_From})
|
||||
set(loc_target_name JKQTPlotter_GenerateDocScreenshots_${example})
|
||||
set(dep_name jkqtptest_${example})
|
||||
add_custom_target(${loc_target_name}
|
||||
COMMENT "Building JKQTPlotter Documentation Screenshot: ${loc_name_upper}"
|
||||
COMMAND $<TARGET_FILE:${dep_name}> ${JKQTPlotter_GenerateDocScreenshots_DefaultOptions} --screenshotbasename=${example}
|
||||
WORKING_DIRECTORY ${JKQtPlotter_QT_BINDIR}
|
||||
DEPENDS ${dep_name}
|
||||
)
|
||||
|
||||
add_dependencies(JKQTPlotter_GenerateDocScreenshots ${loc_target_name})
|
||||
|
||||
unset(loc_target_name)
|
||||
unset(dep_name)
|
||||
endforeach()
|
||||
|
||||
endif()
|
||||
|
@ -25,6 +25,11 @@ message( STATUS "...............................................................
|
||||
|
||||
|
||||
|
||||
# examples for libexampletools
|
||||
message( STATUS ".. BUILDING EXAMPLE TOOLS LIB:" )
|
||||
add_subdirectory(libexampletools)
|
||||
|
||||
|
||||
# examples for JKQtFastPlotter
|
||||
message( STATUS ".. BUILDING EXAMPLES FOR JKQTFASTPLOTTER:" )
|
||||
add_subdirectory(jkqtfastplotter_test)
|
||||
|
55
examples/libexampletools/CMakeLists.txt
Normal file
55
examples/libexampletools/CMakeLists.txt
Normal file
@ -0,0 +1,55 @@
|
||||
cmake_minimum_required(VERSION 3.15)
|
||||
|
||||
set(libBasename JKQTPExampleTools)
|
||||
|
||||
set(lib_name ${libBasename}Lib)
|
||||
message( STATUS "-- Building ${lib_name}" )
|
||||
|
||||
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
|
||||
|
||||
# Set up source files
|
||||
set(SOURCES
|
||||
${CMAKE_CURRENT_LIST_DIR}/jkqtpexampleapplication.cpp
|
||||
)
|
||||
|
||||
set(HEADERS
|
||||
${CMAKE_CURRENT_LIST_DIR}/jkqtpexampleapplication.h
|
||||
)
|
||||
|
||||
|
||||
include(CMakePackageConfigHelpers)
|
||||
|
||||
function(jkqtpexampletools_setDefaultLibOptions TARGETNAME)
|
||||
set_property(TARGET ${TARGETNAME} PROPERTY VERSION "${PROJECT_VERSION}")
|
||||
target_link_libraries(${TARGETNAME} PUBLIC Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Gui Qt${QT_VERSION_MAJOR}::Widgets)
|
||||
set_property(TARGET ${TARGETNAME} PROPERTY CXX_STANDARD ${JKQtPlotter_QT_CXX_STANDARD})
|
||||
set_property(TARGET ${TARGETNAME} PROPERTY CXX_STANDARD_REQUIRED ${JKQtPlotter_QT_CXX_STANDARD_REQUIRED})
|
||||
target_compile_features(${TARGETNAME} PUBLIC ${JKQtPlotter_QT_CXX_COMPILE_FEATURE})
|
||||
|
||||
if(MINGW)
|
||||
# COMPILER-SETTINGS FOR MINGW
|
||||
target_compile_options(${TARGETNAME} PUBLIC -fexceptions)
|
||||
elseif(MSVC)
|
||||
# COMPILER-SETTINGS FOR MS VISUAL C++
|
||||
target_compile_options(${TARGETNAME} PUBLIC /EHsc)
|
||||
target_compile_definitions(${TARGETNAME} PUBLIC NOMINMAX)
|
||||
endif()
|
||||
target_include_directories(${TARGETNAME} PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}/../
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
endfunction()
|
||||
|
||||
|
||||
add_library(${lib_name} STATIC ${SOURCES} ${RESOURCES} ${HEADERS})
|
||||
jkqtpexampletools_setDefaultLibOptions(${lib_name})
|
||||
if(JKQtPlotter_BUILD_STATIC_LIBS)
|
||||
target_link_libraries(${lib_name} PUBLIC JKQTPlotterLib)
|
||||
elseif(JKQtPlotter_BUILD_SHARED_LIBS)
|
||||
target_link_libraries(${lib_name} PUBLIC JKQTPlotterSharedLib)
|
||||
endif()
|
||||
write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/${lib_name}Version.cmake
|
||||
VERSION ${PROJECT_VERSION}
|
||||
COMPATIBILITY AnyNewerVersion )
|
||||
|
||||
|
138
examples/libexampletools/jkqtpexampleapplication.cpp
Normal file
138
examples/libexampletools/jkqtpexampleapplication.cpp
Normal file
@ -0,0 +1,138 @@
|
||||
#include "jkqtpexampleapplication.h"
|
||||
#include <QElapsedTimer>
|
||||
#include <QCommandLineParser>
|
||||
#include <QCommandLineOption>
|
||||
#include <QWindow>
|
||||
#include <QWidget>
|
||||
#include "jkqtplotter/jkqtplotter.h"
|
||||
|
||||
|
||||
JKQTPExampleApplication::JKQTPExampleApplication(int &argc, char **argv):
|
||||
QApplication(argc, argv),
|
||||
saveScreenshot(false),
|
||||
saveSmallScreenshot(false),
|
||||
saveScreenshotPlot(false),
|
||||
saveSmallScreenshotPlot(false),
|
||||
screenshotBasename("screenshot")
|
||||
{
|
||||
screenshotDir=QDir::current();
|
||||
|
||||
}
|
||||
|
||||
JKQTPExampleApplication::~JKQTPExampleApplication()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void JKQTPExampleApplication::readCmdLine() {
|
||||
QCommandLineParser parser;
|
||||
parser.setApplicationDescription(QString("JKQTPlotter example program '%1'").arg(applicationName()));
|
||||
parser.addHelpOption();
|
||||
parser.addVersionOption();
|
||||
QCommandLineOption outputDirectoryOption("screenshotdir", "write results into this directory.", "outputdir", applicationDirPath());
|
||||
parser.addOption(outputDirectoryOption);
|
||||
QCommandLineOption basenameOption("screenshotbasename", "basename for screenshots.", "basename", QFileInfo(applicationFilePath()).baseName());
|
||||
parser.addOption(basenameOption);
|
||||
QCommandLineOption screenshotOption(QStringList()<<"screenshot", "save screenshot(s) of the window(s).");
|
||||
parser.addOption(screenshotOption);
|
||||
QCommandLineOption smallscreenshotOption(QStringList()<<"smallscreenshot", "save small screenshot(s) of the window(s).");
|
||||
parser.addOption(smallscreenshotOption);
|
||||
QCommandLineOption screenshotPlotOption(QStringList()<<"screenshotplot", "save screenshot(s) of the plot(s).");
|
||||
parser.addOption(screenshotPlotOption);
|
||||
QCommandLineOption smallscreenshotPlotOption(QStringList()<<"smallscreenshotplot", "save screenshot(s) of the plot(s).");
|
||||
parser.addOption(smallscreenshotPlotOption);
|
||||
|
||||
parser.process(*this);
|
||||
|
||||
screenshotDir=QDir(parser.value(outputDirectoryOption));
|
||||
screenshotBasename=parser.value(basenameOption);
|
||||
saveScreenshot = parser.isSet(screenshotOption);
|
||||
saveSmallScreenshot = parser.isSet(smallscreenshotOption);
|
||||
saveScreenshotPlot = parser.isSet(screenshotPlotOption);
|
||||
saveSmallScreenshotPlot = parser.isSet(smallscreenshotPlotOption);
|
||||
}
|
||||
|
||||
QRect JKQTPExampleApplication::getBoundsWithoutColor(QImage qImage, const QColor &exclusionColor)
|
||||
{
|
||||
QRect ofTheKing;
|
||||
|
||||
int maxX = 0; int minX = qImage.width();
|
||||
int maxY = 0; int minY = qImage.height();
|
||||
|
||||
for(int x=0; x < qImage.width(); x++)
|
||||
for(int y=0; y < qImage.height(); y++)
|
||||
if (QColor::fromRgb(qImage.pixel(x, y)) != exclusionColor)
|
||||
{
|
||||
if(x < minX) minX = x;
|
||||
if(x > maxX) maxX = x;
|
||||
if(y < minY) minY = y;
|
||||
if(y > maxY) maxY = y;
|
||||
}
|
||||
|
||||
if (minX > maxX || minY > maxY)
|
||||
ofTheKing=QRect();
|
||||
else
|
||||
ofTheKing.setCoords(minX, minY, maxX+1, maxY+1);
|
||||
|
||||
return ofTheKing;
|
||||
}
|
||||
|
||||
int JKQTPExampleApplication::exec()
|
||||
{
|
||||
readCmdLine();
|
||||
if (saveScreenshot||saveSmallScreenshot) {
|
||||
QElapsedTimer timer;
|
||||
timer.start();
|
||||
while(timer.elapsed()<150) {
|
||||
QApplication::processEvents();
|
||||
}
|
||||
QWidgetList widgets=topLevelWidgets();
|
||||
int iVisible=0;
|
||||
for (int i=0; i<widgets.size(); i++) {
|
||||
QWidget* w=widgets[i];
|
||||
if (w->isVisible()) {
|
||||
JKQTPlotter* plot=dynamic_cast<JKQTPlotter*>(w);
|
||||
QString bn=screenshotBasename;
|
||||
if (iVisible>0) {
|
||||
bn+=QString("_win%1").arg(iVisible, 2, 10, QLatin1Char('0'));
|
||||
}
|
||||
if (w) {
|
||||
QPixmap pix_win=w->grab();
|
||||
/*QPixmap pix;
|
||||
if (screenshotIncludeWindowTitle) {
|
||||
pix=w->screen()->grabWindow(0, w->frameGeometry().x(), w->frameGeometry().y(), w->frameGeometry().width(), w->frameGeometry().height());
|
||||
} else {
|
||||
pix=pix_win;
|
||||
}*/
|
||||
if (saveScreenshot) {
|
||||
pix_win.save(screenshotDir.absoluteFilePath(bn+".png"));
|
||||
}
|
||||
if (saveSmallScreenshot) {
|
||||
QPixmap img=pix_win.scaledToWidth(150, Qt::SmoothTransformation);
|
||||
img.save(screenshotDir.absoluteFilePath(bn+"_small.png"));
|
||||
}
|
||||
}
|
||||
if (plot) {
|
||||
QString bnp=bn+"_plot";
|
||||
QImage gr=plot->grabPixelImage();
|
||||
|
||||
if (saveScreenshotPlot) {
|
||||
QString fn=bn+"_small.png";
|
||||
if (saveScreenshot) fn=bnp+"_small.png";
|
||||
gr.save(screenshotDir.absoluteFilePath(fn));
|
||||
}
|
||||
if (saveSmallScreenshotPlot) {
|
||||
QString fn=bn+"_small.png";
|
||||
if (saveSmallScreenshot) fn=bnp+"_small.png";
|
||||
QImage img=gr.scaledToWidth(150, Qt::SmoothTransformation);
|
||||
img.save(screenshotDir.absoluteFilePath(fn));
|
||||
}
|
||||
}
|
||||
iVisible++;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
} else {
|
||||
return QApplication::exec();
|
||||
}
|
||||
}
|
26
examples/libexampletools/jkqtpexampleapplication.h
Normal file
26
examples/libexampletools/jkqtpexampleapplication.h
Normal file
@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
#include <QApplication>
|
||||
#include "jkqtplotter/jkqtplotter.h"
|
||||
#include <QDir>
|
||||
|
||||
|
||||
|
||||
class JKQTPExampleApplication: public QApplication {
|
||||
Q_OBJECT
|
||||
public:
|
||||
JKQTPExampleApplication(int &argc, char **argv);
|
||||
|
||||
virtual ~JKQTPExampleApplication();
|
||||
|
||||
int exec();
|
||||
|
||||
protected:
|
||||
QDir screenshotDir;
|
||||
bool saveScreenshot;
|
||||
bool saveSmallScreenshot;
|
||||
bool saveScreenshotPlot;
|
||||
bool saveSmallScreenshotPlot;
|
||||
QString screenshotBasename;
|
||||
void readCmdLine();
|
||||
QRect getBoundsWithoutColor(QImage qImage, const QColor &exclusionColor = Qt::white);
|
||||
};
|
14
examples/libexampletools/libexampletools.pri
Normal file
14
examples/libexampletools/libexampletools.pri
Normal file
@ -0,0 +1,14 @@
|
||||
|
||||
isEmpty(JKQTP_LIBEXAMPLETOOLS_PRI_INCLUDED) {
|
||||
JKQTP_LIBEXAMPLETOOLS_PRI_INCLUDED = 1
|
||||
|
||||
INCLUDEPATH += $PWD
|
||||
|
||||
|
||||
HEADERS += $$PWD/jkqtpexampleapplication.h
|
||||
|
||||
|
||||
SOURCES += $$PWD/jkqtpexampleapplication.cpp
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user