commit bb62992ed451c4075c7b2cbe53dd8a7a4ba11656 Author: Xevion Date: Thu Sep 21 11:24:33 2023 -0500 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b7fbbbc --- /dev/null +++ b/.gitignore @@ -0,0 +1,59 @@ +.vscode/ + +# qt +.qt/ +.rcc/ +calculatorbuilder_autogen/ + +### C++ ### +# Prerequisites +*.d + +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod +*.smod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app + +### CMake ### +CMakeLists.txt.user +CMakeCache.txt +CMakeFiles +CMakeScripts +Testing +Makefile +cmake_install.cmake +install_manifest.txt +compile_commands.json +CTestTestfile.cmake +_deps + +### CMake Patch ### +# External projects +*-prefix/ + +# End of https://www.toptal.com/developers/gitignore/api/c++,cmake diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..21047c9 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,52 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +cmake_minimum_required(VERSION 3.16) +project(calculatorbuilder LANGUAGES CXX) + +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTOUIC ON) + +if(NOT DEFINED INSTALL_EXAMPLESDIR) + set(INSTALL_EXAMPLESDIR "examples") +endif() + +set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/designer/calculatorbuilder") + +find_package(Qt6 REQUIRED COMPONENTS Core Gui UiTools Widgets) + +qt_add_executable(calculatorbuilder main.cpp) + +set_target_properties(calculatorbuilder PROPERTIES + WIN32_EXECUTABLE TRUE + MACOSX_BUNDLE TRUE +) + +#! [0] +target_link_libraries(calculatorbuilder PUBLIC + Qt::Core + Qt::Gui + Qt::UiTools + Qt::Widgets +) +#! [0] + +# Resources: +#! [1]x +set(calculatorbuilder_resource_files + "calculatorform.ui" +) +#! [1] + +qt6_add_resources(calculatorbuilder "calculatorbuilder" + PREFIX + "/forms" + FILES + ${calculatorbuilder_resource_files} +) + +install(TARGETS calculatorbuilder + RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" + BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" + LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" +) diff --git a/calculatorbuilder b/calculatorbuilder new file mode 100755 index 0000000..76f6de7 Binary files /dev/null and b/calculatorbuilder differ diff --git a/calculatorform.ui b/calculatorform.ui new file mode 100644 index 0000000..e7cd7b6 --- /dev/null +++ b/calculatorform.ui @@ -0,0 +1,303 @@ + + + + + CalculatorForm + + + CalculatorForm + + + + 0 + 0 + 276 + 98 + + + + + 5 + 5 + 0 + 0 + + + + Calculator Builder + + + + + + + 9 + + + 6 + + + + + + + + 1 + + + 6 + + + + + + + + 1 + + + 6 + + + + + label + + + + 1 + 1 + 45 + 19 + + + + Input 1 + + + + + + + inputSpinBox1 + + + + 1 + 26 + 45 + 25 + + + + true + + + + + + + + + label_3 + + + + 54 + 1 + 7 + 52 + + + + + + + + Qt::AlignCenter + + + + + + + + + + 1 + + + 6 + + + + + label_2 + + + + 1 + 1 + 45 + 19 + + + + Input 2 + + + + + + + inputSpinBox2 + + + + 1 + 26 + 45 + 25 + + + + true + + + + + + + + + label_3_2 + + + + 120 + 1 + 7 + 52 + + + + = + + + Qt::AlignCenter + + + + + + + + + + 1 + + + 6 + + + + + label_2_2_2 + + + + 1 + 1 + 37 + 17 + + + + Output + + + + + + + outputWidget + + + + 1 + 24 + 37 + 27 + + + + QFrame::Box + + + QFrame::Sunken + + + 0 + + + Qt::AlignAbsolute|Qt::AlignBottom|Qt::AlignCenter|Qt::AlignHCenter|Qt::AlignHorizontal_Mask|Qt::AlignJustify|Qt::AlignLeading|Qt::AlignLeft|Qt::AlignRight|Qt::AlignTop|Qt::AlignTrailing|Qt::AlignVCenter|Qt::AlignVertical_Mask + + + + + + + + + + + verticalSpacer + + + + 85 + 69 + 20 + 20 + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + horizontalSpacer + + + + 188 + 26 + 79 + 20 + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + \ No newline at end of file diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..78d071e --- /dev/null +++ b/main.cpp @@ -0,0 +1,67 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +//! [0] +#include +//! [0] + +#include +#include +#include +#include + +#include + +#include + +using namespace Qt::StringLiterals; + +//! [1] +static QWidget *loadCalculatorForm(QWidget *parent = nullptr) +{ + QUiLoader loader; + + QFile file(u":/forms/calculatorform.ui"_s); + if (!file.open(QFile::ReadOnly)) + return nullptr; + QWidget *formWidget = loader.load(&file, parent); + file.close(); + if (formWidget == nullptr) + return nullptr; +//! [1] + +//! [2] + auto *inputSpinBox1 = formWidget->findChild(u"inputSpinBox1"_s); + auto *inputSpinBox2 = formWidget->findChild(u"inputSpinBox2"_s); + auto *outputWidget = formWidget->findChild(u"outputWidget"_s); +//! [2] + +//! [3] + auto updateResult = [inputSpinBox1, inputSpinBox2, outputWidget]() + { + const int sum = inputSpinBox1->value() + inputSpinBox2->value(); + outputWidget->setText(QString::number(sum)); + }; + QObject::connect(inputSpinBox1, &QSpinBox::valueChanged, formWidget, updateResult); + QObject::connect(inputSpinBox2, &QSpinBox::valueChanged, formWidget, updateResult); +//! [3] + + return formWidget; +} + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + QWidget w; + auto *formWidget = loadCalculatorForm(&w); + if (formWidget == nullptr) + return -1; + //! [4] + auto *layout = new QVBoxLayout(&w); + layout->addWidget(formWidget); + w.setWindowTitle(QCoreApplication::translate("CalculatorForm", + "Calculator Builder")); + //! [4] + w.show(); + return app.exec(); +}