add pkgconfig, improve Qt example

This commit is contained in:
Syping 2021-08-27 21:48:33 +02:00
parent 33c3dcb512
commit dd47087afd
5 changed files with 43 additions and 23 deletions

View file

@ -17,10 +17,18 @@ set(QTVIEWER_SOURCES
src/main.cpp
)
if(TARGET ragephoto)
add_executable(ragephoto-qtviewer ${QTVIEWER_SOURCES})
target_link_libraries(ragephoto-qtviewer Qt${QT_VERSION_MAJOR}::Widgets ragephoto)
target_include_directories(ragephoto-qtviewer PRIVATE ${RAGEPHOTO_INCLUDE_DIRS})
if (TARGET ragephoto)
set(RAGEPHOTO_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/src)
set(RAGEPHOTO_LIBRARIES ragephoto)
else()
message("ragephoto-qtviewer need to be build with libragephoto together")
find_package(PkgConfig REQUIRED)
pkg_check_modules(RAGEPHOTO REQUIRED ragephoto)
endif()
add_executable(ragephoto-qtviewer ${QTVIEWER_SOURCES})
target_compile_options(ragephoto-qtviewer PRIVATE ${RAGEPHOTO_CFLAGS})
target_link_libraries(ragephoto-qtviewer PRIVATE Qt${QT_VERSION_MAJOR}::Widgets ${RAGEPHOTO_LIBRARIES})
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.13.0")
target_link_directories(ragephoto-qtviewer PRIVATE ${RAGEPHOTO_LIBRARY_DIRS})
endif()
target_include_directories(ragephoto-qtviewer PRIVATE ${RAGEPHOTO_INCLUDE_DIRS})

View file

@ -89,6 +89,8 @@ int main(int argc, char *argv[])
QPushButton openButton("Open", &mainWindow);
QObject::connect(&openButton, &QPushButton::clicked, &mainWindow, [&](){
const QString filename = QFileDialog::getOpenFileName(&mainWindow, "Open Photo...", QString(), "GTA V Photo (PGTA5*)");
if (filename.isEmpty())
return;
if (readPhotoFile(filename, &mainWindow, &photoLabel)) {
QTimer::singleShot(0, &mainWindow, [&](){
mainWindow.setFixedSize(mainWindow.sizeHint());