Skip to content

Commit

Permalink
Add basic window example
Browse files Browse the repository at this point in the history
Change-Id: I5b729a1903aae656a483785d62ba6b43514b6949
Reviewed-on: https://codereview.kdab.com/c/kdab/kdutils/+/135718
Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Tested-by: Continuous Integration <build@kdab.com>
  • Loading branch information
MiKom committed Jan 3, 2024
1 parent 582f8b9 commit beaf7ab
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 1 deletion.
8 changes: 7 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file is part of KDUtils.
#
# SPDX-FileCopyrightText: 2021-2023 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
# SPDX-FileCopyrightText: 2021-2024 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
# Author: Paul Lemire <paul.lemire@kdab.com>
#
# SPDX-License-Identifier: MIT
Expand Down Expand Up @@ -40,6 +40,8 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
cmake_policy(SET CMP0090 NEW) # Stop export(PACKAGE) from modifying the system-wide cmake package system
cmake_policy(SET CMP0117 NEW) # Do not add /GR to CMAKE_CXX_FLAGS

option(KDUTILS_BUILD_EXAMPLES "Build examples" ON)

include(FeatureSummary)
include(CMakeDependentOption)
include(cmake/dependencies.cmake)
Expand All @@ -59,6 +61,10 @@ add_subdirectory(src/KDUtils)
add_subdirectory(src/KDFoundation)
add_subdirectory(src/KDGui)

if(KDUTILS_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()

if(KDUTILS_BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
Expand Down
9 changes: 9 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# This file is part of KDUtils.
#
# SPDX-FileCopyrightText: 2022-2024 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
#
# SPDX-License-Identifier: MIT
#
# Contact KDAB at <info@kdab.com> for commercial licensing options.

add_subdirectory(gui_window)
18 changes: 18 additions & 0 deletions examples/gui_window/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# This file is part of KDUtils.
#
# SPDX-FileCopyrightText: 2022-2024 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
#
# SPDX-License-Identifier: MIT
#
# Contact KDAB at <info@kdab.com> for commercial licensing options.

project(gui_window_example LANGUAGES CXX)

add_executable(
${PROJECT_NAME}
gui_window.cpp
)

target_link_libraries(
${PROJECT_NAME} KDGui
)
78 changes: 78 additions & 0 deletions examples/gui_window/gui_window.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
This file is part of KDUtils.
SPDX-FileCopyrightText: 2018-2024 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
Author: Miłosz Kosobucki <milosz.kosobucki@kdab.com>
SPDX-License-Identifier: MIT
Contact KDAB at <info@kdab.com> for commercial licensing options.
*/
#include <KDGui/gui_application.h>
#include <KDGui/window.h>
#include <KDGui/gui_events.h>

class ExampleWindow : public KDGui::Window
{
void mouseMoveEvent(KDGui::MouseMoveEvent *ev) override
{
spdlog::info("{}() buttons = {} at pos = ({}, {})",
__FUNCTION__,
ev->buttons(),
ev->xPos(),
ev->yPos());
}

void mousePressEvent(KDGui::MousePressEvent *ev) override
{
spdlog::info("{}() buttons = {} at pos = ({}, {})",
__FUNCTION__,
ev->buttons(),
ev->xPos(),
ev->yPos());
}

void mouseReleaseEvent(KDGui::MouseReleaseEvent *ev) override
{
spdlog::info("{}() buttons = {} at pos = ({}, {})",
__FUNCTION__,
ev->buttons(),
ev->xPos(),
ev->yPos());
}

void mouseWheelEvent(KDGui::MouseWheelEvent *ev) override
{
spdlog::info("{}() xDelta = {} yDelta = {}",
__FUNCTION__,
ev->xDelta(),
ev->yDelta());
}

void keyPressEvent(KDGui::KeyPressEvent *ev) override
{
spdlog::info("{}() key = {}", __FUNCTION__, ev->key());
}

void keyReleaseEvent(KDGui::KeyReleaseEvent *ev) override
{
spdlog::info("{}() key = {}", __FUNCTION__, ev->key());
}
};

int main()
{
KDGui::GuiApplication app;

ExampleWindow w;
w.title = "KDGui window example";
w.visible = true;

w.visible.valueChanged().connect([&app](bool visible) {
if (!visible) {
app.quit();
}
});

app.exec();
}

0 comments on commit beaf7ab

Please sign in to comment.