From 6a7d28d1b5564db6c45460de680282e45751d11a Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Wed, 16 Jun 2021 22:30:45 +0200 Subject: [PATCH] update SingleApplication --- CMakeLists.txt | 2 +- .../.github/FUNDING.yml | 1 + .../.github/workflows/build-cmake.yml | 56 +++ .../.gitignore | 0 .../CHANGELOG.md | 6 + .../CMakeLists.txt | 0 .../LICENSE | 0 .../README.md | 0 .../SingleApplication | 0 .../Windows.md | 0 .../examples/basic/CMakeLists.txt | 12 + .../examples/basic/basic.pro | 5 + .../examples/basic/main.cpp | 10 + .../examples/calculator/CMakeLists.txt | 21 + .../examples/calculator/button.cpp | 73 ++++ .../examples/calculator/button.h | 68 +++ .../examples/calculator/calculator.cpp | 406 ++++++++++++++++++ .../examples/calculator/calculator.h | 117 +++++ .../examples/calculator/calculator.pro | 11 + .../examples/calculator/main.cpp | 71 +++ .../examples/sending_arguments/CMakeLists.txt | 20 + .../examples/sending_arguments/main.cpp | 28 ++ .../sending_arguments/messagereceiver.cpp | 12 + .../sending_arguments/messagereceiver.h | 15 + .../sending_arguments/sending_arguments.pro | 9 + .../singleapplication.cpp | 33 +- .../singleapplication.h | 16 +- .../singleapplication.pri | 0 .../singleapplication_p.cpp | 110 +++-- .../singleapplication_p.h | 13 +- 30 files changed, 1051 insertions(+), 64 deletions(-) create mode 100644 third_party/SingleApplication-3.3.0/.github/FUNDING.yml create mode 100644 third_party/SingleApplication-3.3.0/.github/workflows/build-cmake.yml rename third_party/{SingleApplication-3.2.0-dc8042b => SingleApplication-3.3.0}/.gitignore (100%) rename third_party/{SingleApplication-3.2.0-dc8042b => SingleApplication-3.3.0}/CHANGELOG.md (98%) rename third_party/{SingleApplication-3.2.0-dc8042b => SingleApplication-3.3.0}/CMakeLists.txt (100%) rename third_party/{SingleApplication-3.2.0-dc8042b => SingleApplication-3.3.0}/LICENSE (100%) rename third_party/{SingleApplication-3.2.0-dc8042b => SingleApplication-3.3.0}/README.md (100%) rename third_party/{SingleApplication-3.2.0-dc8042b => SingleApplication-3.3.0}/SingleApplication (100%) rename third_party/{SingleApplication-3.2.0-dc8042b => SingleApplication-3.3.0}/Windows.md (100%) create mode 100644 third_party/SingleApplication-3.3.0/examples/basic/CMakeLists.txt create mode 100755 third_party/SingleApplication-3.3.0/examples/basic/basic.pro create mode 100755 third_party/SingleApplication-3.3.0/examples/basic/main.cpp create mode 100644 third_party/SingleApplication-3.3.0/examples/calculator/CMakeLists.txt create mode 100644 third_party/SingleApplication-3.3.0/examples/calculator/button.cpp create mode 100644 third_party/SingleApplication-3.3.0/examples/calculator/button.h create mode 100644 third_party/SingleApplication-3.3.0/examples/calculator/calculator.cpp create mode 100644 third_party/SingleApplication-3.3.0/examples/calculator/calculator.h create mode 100644 third_party/SingleApplication-3.3.0/examples/calculator/calculator.pro create mode 100644 third_party/SingleApplication-3.3.0/examples/calculator/main.cpp create mode 100644 third_party/SingleApplication-3.3.0/examples/sending_arguments/CMakeLists.txt create mode 100755 third_party/SingleApplication-3.3.0/examples/sending_arguments/main.cpp create mode 100644 third_party/SingleApplication-3.3.0/examples/sending_arguments/messagereceiver.cpp create mode 100644 third_party/SingleApplication-3.3.0/examples/sending_arguments/messagereceiver.h create mode 100755 third_party/SingleApplication-3.3.0/examples/sending_arguments/sending_arguments.pro rename third_party/{SingleApplication-3.2.0-dc8042b => SingleApplication-3.3.0}/singleapplication.cpp (92%) rename third_party/{SingleApplication-3.2.0-dc8042b => SingleApplication-3.3.0}/singleapplication.h (95%) rename third_party/{SingleApplication-3.2.0-dc8042b => SingleApplication-3.3.0}/singleapplication.pri (100%) rename third_party/{SingleApplication-3.2.0-dc8042b => SingleApplication-3.3.0}/singleapplication_p.cpp (85%) rename third_party/{SingleApplication-3.2.0-dc8042b => SingleApplication-3.3.0}/singleapplication_p.h (88%) diff --git a/CMakeLists.txt b/CMakeLists.txt index fb104807..2893bde4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -458,7 +458,7 @@ endif() # single instance functionality set(QAPPLICATION_CLASS QApplication CACHE STRING "Inheritance class for SingleApplication") -add_subdirectory(third_party/SingleApplication-3.2.0-dc8042b/) +add_subdirectory(third_party/SingleApplication-3.3.0/) feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/third_party/SingleApplication-3.3.0/.github/FUNDING.yml b/third_party/SingleApplication-3.3.0/.github/FUNDING.yml new file mode 100644 index 00000000..3ca4d97a --- /dev/null +++ b/third_party/SingleApplication-3.3.0/.github/FUNDING.yml @@ -0,0 +1 @@ +github: itay-grudev diff --git a/third_party/SingleApplication-3.3.0/.github/workflows/build-cmake.yml b/third_party/SingleApplication-3.3.0/.github/workflows/build-cmake.yml new file mode 100644 index 00000000..6344b504 --- /dev/null +++ b/third_party/SingleApplication-3.3.0/.github/workflows/build-cmake.yml @@ -0,0 +1,56 @@ +name: "CI: Build Test" + +on: [push, pull_request] + +jobs: + build: + + strategy: + matrix: + qt_version: [5.12.6, 5.13.2, 5.14.0, 5.15.0, 6.0.0] + platform: [ubuntu-20.04, windows-latest, macos-latest] + include: + - qt_version: 6.0.0 + additional_arguments: -D QT_DEFAULT_MAJOR_VERSION=6 + - platform: ubuntu-20.04 + CXXFLAGS: -Wall -Wextra -pedantic -Werror + - platform: macos-latest + CXXFLAGS: -Wall -Wextra -pedantic -Werror + - platform: windows-latest + CXXFLAGS: /W4 /WX + + runs-on: ${{ matrix.platform }} + env: + CXXFLAGS: ${{ matrix.CXXFLAGS }} + + steps: + - uses: actions/checkout@v2.3.4 + + - name: Install Qt + uses: jurplel/install-qt-action@v2.11.1 + with: + version: ${{ matrix.qt_version }} + + - name: cmake + run: cmake . ${{ matrix.additional_arguments }} + + - name: cmake build + run: cmake --build . + + - name: Build example - basic (cmake) + working-directory: examples/basic/ + run: | + cmake . ${{ matrix.additional_arguments }} + cmake --build . + + - name: Build example - calculator (cmake) + working-directory: examples/calculator/ + run: | + cmake . ${{ matrix.additional_arguments }} + cmake --build . + + - name: Build example - sending_arguments (cmake) + working-directory: examples/sending_arguments/ + run: | + cmake . ${{ matrix.additional_arguments }} + cmake --build . diff --git a/third_party/SingleApplication-3.2.0-dc8042b/.gitignore b/third_party/SingleApplication-3.3.0/.gitignore similarity index 100% rename from third_party/SingleApplication-3.2.0-dc8042b/.gitignore rename to third_party/SingleApplication-3.3.0/.gitignore diff --git a/third_party/SingleApplication-3.2.0-dc8042b/CHANGELOG.md b/third_party/SingleApplication-3.3.0/CHANGELOG.md similarity index 98% rename from third_party/SingleApplication-3.2.0-dc8042b/CHANGELOG.md rename to third_party/SingleApplication-3.3.0/CHANGELOG.md index e2ba290e..51669b90 100644 --- a/third_party/SingleApplication-3.2.0-dc8042b/CHANGELOG.md +++ b/third_party/SingleApplication-3.3.0/CHANGELOG.md @@ -3,6 +3,12 @@ Changelog If by accident I have forgotten to credit someone in the CHANGELOG, email me and I will fix it. + +__3.3.0__ +--------- + +* Fixed message fragmentation issue causing crashes and incorrectly and inconsistently received messages. - _Nils Jeisecke_ + __3.2.0__ --------- diff --git a/third_party/SingleApplication-3.2.0-dc8042b/CMakeLists.txt b/third_party/SingleApplication-3.3.0/CMakeLists.txt similarity index 100% rename from third_party/SingleApplication-3.2.0-dc8042b/CMakeLists.txt rename to third_party/SingleApplication-3.3.0/CMakeLists.txt diff --git a/third_party/SingleApplication-3.2.0-dc8042b/LICENSE b/third_party/SingleApplication-3.3.0/LICENSE similarity index 100% rename from third_party/SingleApplication-3.2.0-dc8042b/LICENSE rename to third_party/SingleApplication-3.3.0/LICENSE diff --git a/third_party/SingleApplication-3.2.0-dc8042b/README.md b/third_party/SingleApplication-3.3.0/README.md similarity index 100% rename from third_party/SingleApplication-3.2.0-dc8042b/README.md rename to third_party/SingleApplication-3.3.0/README.md diff --git a/third_party/SingleApplication-3.2.0-dc8042b/SingleApplication b/third_party/SingleApplication-3.3.0/SingleApplication similarity index 100% rename from third_party/SingleApplication-3.2.0-dc8042b/SingleApplication rename to third_party/SingleApplication-3.3.0/SingleApplication diff --git a/third_party/SingleApplication-3.2.0-dc8042b/Windows.md b/third_party/SingleApplication-3.3.0/Windows.md similarity index 100% rename from third_party/SingleApplication-3.2.0-dc8042b/Windows.md rename to third_party/SingleApplication-3.3.0/Windows.md diff --git a/third_party/SingleApplication-3.3.0/examples/basic/CMakeLists.txt b/third_party/SingleApplication-3.3.0/examples/basic/CMakeLists.txt new file mode 100644 index 00000000..c1429230 --- /dev/null +++ b/third_party/SingleApplication-3.3.0/examples/basic/CMakeLists.txt @@ -0,0 +1,12 @@ +cmake_minimum_required(VERSION 3.7.0) + +project(basic LANGUAGES CXX) + +# SingleApplication base class +set(QAPPLICATION_CLASS QCoreApplication) +add_subdirectory(../.. SingleApplication) + +add_executable(basic main.cpp) + +target_link_libraries(${PROJECT_NAME} SingleApplication::SingleApplication) + diff --git a/third_party/SingleApplication-3.3.0/examples/basic/basic.pro b/third_party/SingleApplication-3.3.0/examples/basic/basic.pro new file mode 100755 index 00000000..b7af16cf --- /dev/null +++ b/third_party/SingleApplication-3.3.0/examples/basic/basic.pro @@ -0,0 +1,5 @@ +# Single Application implementation +include(../../singleapplication.pri) +DEFINES += QAPPLICATION_CLASS=QCoreApplication + +SOURCES += main.cpp diff --git a/third_party/SingleApplication-3.3.0/examples/basic/main.cpp b/third_party/SingleApplication-3.3.0/examples/basic/main.cpp new file mode 100755 index 00000000..b2092c6d --- /dev/null +++ b/third_party/SingleApplication-3.3.0/examples/basic/main.cpp @@ -0,0 +1,10 @@ +#include + +int main(int argc, char *argv[]) +{ + SingleApplication app( argc, argv ); + + qWarning() << "Started a new instance"; + + return app.exec(); +} diff --git a/third_party/SingleApplication-3.3.0/examples/calculator/CMakeLists.txt b/third_party/SingleApplication-3.3.0/examples/calculator/CMakeLists.txt new file mode 100644 index 00000000..82305f04 --- /dev/null +++ b/third_party/SingleApplication-3.3.0/examples/calculator/CMakeLists.txt @@ -0,0 +1,21 @@ +cmake_minimum_required(VERSION 3.7.0) + +project(calculator LANGUAGES CXX) + +set(CMAKE_AUTOMOC ON) + +# SingleApplication base class +set(QAPPLICATION_CLASS QApplication) +add_subdirectory(../.. SingleApplication) + +find_package(Qt${QT_DEFAULT_MAJOR_VERSION} COMPONENTS Core REQUIRED) + +add_executable(${PROJECT_NAME} + button.h + calculator.h + button.cpp + calculator.cpp + main.cpp +) + +target_link_libraries(${PROJECT_NAME} SingleApplication::SingleApplication) diff --git a/third_party/SingleApplication-3.3.0/examples/calculator/button.cpp b/third_party/SingleApplication-3.3.0/examples/calculator/button.cpp new file mode 100644 index 00000000..d6cca0a0 --- /dev/null +++ b/third_party/SingleApplication-3.3.0/examples/calculator/button.cpp @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "button.h" + +//! [0] +Button::Button(const QString &text, QWidget *parent) + : QToolButton(parent) +{ + setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); + setText(text); +} +//! [0] + +//! [1] +QSize Button::sizeHint() const +//! [1] //! [2] +{ + QSize size = QToolButton::sizeHint(); + size.rheight() += 20; + size.rwidth() = qMax(size.width(), size.height()); + return size; +} +//! [2] diff --git a/third_party/SingleApplication-3.3.0/examples/calculator/button.h b/third_party/SingleApplication-3.3.0/examples/calculator/button.h new file mode 100644 index 00000000..2c014c7b --- /dev/null +++ b/third_party/SingleApplication-3.3.0/examples/calculator/button.h @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef BUTTON_H +#define BUTTON_H + +#include + +//! [0] +class Button : public QToolButton +{ + Q_OBJECT + +public: + explicit Button(const QString &text, QWidget *parent = 0); + + QSize sizeHint() const Q_DECL_OVERRIDE; +}; +//! [0] + +#endif diff --git a/third_party/SingleApplication-3.3.0/examples/calculator/calculator.cpp b/third_party/SingleApplication-3.3.0/examples/calculator/calculator.cpp new file mode 100644 index 00000000..3d34c2a7 --- /dev/null +++ b/third_party/SingleApplication-3.3.0/examples/calculator/calculator.cpp @@ -0,0 +1,406 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include + +#include "button.h" +#include "calculator.h" + +//! [0] +Calculator::Calculator(QWidget *parent) + : QWidget(parent) +{ + sumInMemory = 0.0; + sumSoFar = 0.0; + factorSoFar = 0.0; + waitingForOperand = true; +//! [0] + +//! [1] + display = new QLineEdit("0"); +//! [1] //! [2] + display->setReadOnly(true); + display->setAlignment(Qt::AlignRight); + display->setMaxLength(15); + + QFont font = display->font(); + font.setPointSize(font.pointSize() + 8); + display->setFont(font); +//! [2] + +//! [4] + for (int i = 0; i < NumDigitButtons; ++i) { + digitButtons[i] = createButton(QString::number(i), SLOT(digitClicked())); + } + + Button *pointButton = createButton(".", SLOT(pointClicked())); + Button *changeSignButton = createButton("\302\261", SLOT(changeSignClicked())); + + Button *backspaceButton = createButton("Backspace", SLOT(backspaceClicked())); + Button *clearButton = createButton("Clear", SLOT(clear())); + Button *clearAllButton = createButton("Clear All", SLOT(clearAll())); + + Button *clearMemoryButton = createButton("MC", SLOT(clearMemory())); + Button *readMemoryButton = createButton("MR", SLOT(readMemory())); + Button *setMemoryButton = createButton("MS", SLOT(setMemory())); + Button *addToMemoryButton = createButton("M+", SLOT(addToMemory())); + + Button *divisionButton = createButton("\303\267", SLOT(multiplicativeOperatorClicked())); + Button *timesButton = createButton("\303\227", SLOT(multiplicativeOperatorClicked())); + Button *minusButton = createButton("-", SLOT(additiveOperatorClicked())); + Button *plusButton = createButton("+", SLOT(additiveOperatorClicked())); + + Button *squareRootButton = createButton("Sqrt", SLOT(unaryOperatorClicked())); + Button *powerButton = createButton("x\302\262", SLOT(unaryOperatorClicked())); + Button *reciprocalButton = createButton("1/x", SLOT(unaryOperatorClicked())); + Button *equalButton = createButton("=", SLOT(equalClicked())); +//! [4] + +//! [5] + QGridLayout *mainLayout = new QGridLayout; +//! [5] //! [6] + mainLayout->setSizeConstraint(QLayout::SetFixedSize); + mainLayout->addWidget(display, 0, 0, 1, 6); + mainLayout->addWidget(backspaceButton, 1, 0, 1, 2); + mainLayout->addWidget(clearButton, 1, 2, 1, 2); + mainLayout->addWidget(clearAllButton, 1, 4, 1, 2); + + mainLayout->addWidget(clearMemoryButton, 2, 0); + mainLayout->addWidget(readMemoryButton, 3, 0); + mainLayout->addWidget(setMemoryButton, 4, 0); + mainLayout->addWidget(addToMemoryButton, 5, 0); + + for (int i = 1; i < NumDigitButtons; ++i) { + int row = ((9 - i) / 3) + 2; + int column = ((i - 1) % 3) + 1; + mainLayout->addWidget(digitButtons[i], row, column); + } + + mainLayout->addWidget(digitButtons[0], 5, 1); + mainLayout->addWidget(pointButton, 5, 2); + mainLayout->addWidget(changeSignButton, 5, 3); + + mainLayout->addWidget(divisionButton, 2, 4); + mainLayout->addWidget(timesButton, 3, 4); + mainLayout->addWidget(minusButton, 4, 4); + mainLayout->addWidget(plusButton, 5, 4); + + mainLayout->addWidget(squareRootButton, 2, 5); + mainLayout->addWidget(powerButton, 3, 5); + mainLayout->addWidget(reciprocalButton, 4, 5); + mainLayout->addWidget(equalButton, 5, 5); + setLayout(mainLayout); + + setWindowTitle("Calculator"); +} +//! [6] + +//! [7] +void Calculator::digitClicked() +{ + Button *clickedButton = qobject_cast