summary refs log tree commit diff
path: root/third_party/SingleApplication-3.3.2/examples
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2021-12-15 15:20:04 +0100
committerNicolas Werner <nicolas.werner@hotmail.de>2021-12-15 15:20:04 +0100
commit57d1dffdbd453af572d1460495edd81427bc2b04 (patch)
tree8deb94ba6a52200c1ea7e44c8f095874e873b17a /third_party/SingleApplication-3.3.2/examples
parentUse icns on macOS (diff)
downloadnheko-57d1dffdbd453af572d1460495edd81427bc2b04.tar.xz
Update to SingleApplication 3.3.2 proper
Diffstat (limited to 'third_party/SingleApplication-3.3.2/examples')
-rw-r--r--third_party/SingleApplication-3.3.2/examples/basic/CMakeLists.txt12
-rwxr-xr-xthird_party/SingleApplication-3.3.2/examples/basic/basic.pro5
-rwxr-xr-xthird_party/SingleApplication-3.3.2/examples/basic/main.cpp10
-rw-r--r--third_party/SingleApplication-3.3.2/examples/calculator/CMakeLists.txt21
-rw-r--r--third_party/SingleApplication-3.3.2/examples/calculator/button.cpp73
-rw-r--r--third_party/SingleApplication-3.3.2/examples/calculator/button.h68
-rw-r--r--third_party/SingleApplication-3.3.2/examples/calculator/calculator.cpp406
-rw-r--r--third_party/SingleApplication-3.3.2/examples/calculator/calculator.h117
-rw-r--r--third_party/SingleApplication-3.3.2/examples/calculator/calculator.pro11
-rw-r--r--third_party/SingleApplication-3.3.2/examples/calculator/main.cpp71
-rw-r--r--third_party/SingleApplication-3.3.2/examples/sending_arguments/CMakeLists.txt20
-rwxr-xr-xthird_party/SingleApplication-3.3.2/examples/sending_arguments/main.cpp28
-rw-r--r--third_party/SingleApplication-3.3.2/examples/sending_arguments/messagereceiver.cpp12
-rw-r--r--third_party/SingleApplication-3.3.2/examples/sending_arguments/messagereceiver.h15
-rwxr-xr-xthird_party/SingleApplication-3.3.2/examples/sending_arguments/sending_arguments.pro9
15 files changed, 878 insertions, 0 deletions
diff --git a/third_party/SingleApplication-3.3.2/examples/basic/CMakeLists.txt b/third_party/SingleApplication-3.3.2/examples/basic/CMakeLists.txt
new file mode 100644

index 00000000..c1429230 --- /dev/null +++ b/third_party/SingleApplication-3.3.2/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.2/examples/basic/basic.pro b/third_party/SingleApplication-3.3.2/examples/basic/basic.pro new file mode 100755
index 00000000..b7af16cf --- /dev/null +++ b/third_party/SingleApplication-3.3.2/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.2/examples/basic/main.cpp b/third_party/SingleApplication-3.3.2/examples/basic/main.cpp new file mode 100755
index 00000000..b2092c6d --- /dev/null +++ b/third_party/SingleApplication-3.3.2/examples/basic/main.cpp
@@ -0,0 +1,10 @@ +#include <singleapplication.h> + +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.2/examples/calculator/CMakeLists.txt b/third_party/SingleApplication-3.3.2/examples/calculator/CMakeLists.txt new file mode 100644
index 00000000..82305f04 --- /dev/null +++ b/third_party/SingleApplication-3.3.2/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.2/examples/calculator/button.cpp b/third_party/SingleApplication-3.3.2/examples/calculator/button.cpp new file mode 100644
index 00000000..d6cca0a0 --- /dev/null +++ b/third_party/SingleApplication-3.3.2/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 <QtWidgets> + +#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.2/examples/calculator/button.h b/third_party/SingleApplication-3.3.2/examples/calculator/button.h new file mode 100644
index 00000000..2c014c7b --- /dev/null +++ b/third_party/SingleApplication-3.3.2/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 <QToolButton> + +//! [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.2/examples/calculator/calculator.cpp b/third_party/SingleApplication-3.3.2/examples/calculator/calculator.cpp new file mode 100644
index 00000000..3d34c2a7 --- /dev/null +++ b/third_party/SingleApplication-3.3.2/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 <QtWidgets> + +#include <cmath> + +#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<Button *>(sender()); + int digitValue = clickedButton->text().toInt(); + if (display->text() == "0" && digitValue == 0.0) + return; + + if (waitingForOperand) { + display->clear(); + waitingForOperand = false; + } + display->setText(display->text() + QString::number(digitValue)); +} +//! [7] + +//! [8] +void Calculator::unaryOperatorClicked() +//! [8] //! [9] +{ + Button *clickedButton = qobject_cast<Button *>(sender()); + QString clickedOperator = clickedButton->text(); + double operand = display->text().toDouble(); + double result = 0.0; + + if (clickedOperator == "Sqrt") { + if (operand < 0.0) { + abortOperation(); + return; + } + result = std::sqrt(operand); + } else if (clickedOperator == "x\302\262") { + result = std::pow(operand, 2.0); + } else if (clickedOperator == "1/x") { + if (operand == 0.0) { + abortOperation(); + return; + } + result = 1.0 / operand; + } + display->setText(QString::number(result)); + waitingForOperand = true; +} +//! [9] + +//! [10] +void Calculator::additiveOperatorClicked() +//! [10] //! [11] +{ + Button *clickedButton = qobject_cast<Button *>(sender()); + QString clickedOperator = clickedButton->text(); + double operand = display->text().toDouble(); + +//! [11] //! [12] + if (!pendingMultiplicativeOperator.isEmpty()) { +//! [12] //! [13] + if (!calculate(operand, pendingMultiplicativeOperator)) { + abortOperation(); + return; + } + display->setText(QString::number(factorSoFar)); + operand = factorSoFar; + factorSoFar = 0.0; + pendingMultiplicativeOperator.clear(); + } + +//! [13] //! [14] + if (!pendingAdditiveOperator.isEmpty()) { +//! [14] //! [15] + if (!calculate(operand, pendingAdditiveOperator)) { + abortOperation(); + return; + } + display->setText(QString::number(sumSoFar)); + } else { + sumSoFar = operand; + } + +//! [15] //! [16] + pendingAdditiveOperator = clickedOperator; +//! [16] //! [17] + waitingForOperand = true; +} +//! [17] + +//! [18] +void Calculator::multiplicativeOperatorClicked() +{ + Button *clickedButton = qobject_cast<Button *>(sender()); + QString clickedOperator = clickedButton->text(); + double operand = display->text().toDouble(); + + if (!pendingMultiplicativeOperator.isEmpty()) { + if (!calculate(operand, pendingMultiplicativeOperator)) { + abortOperation(); + return; + } + display->setText(QString::number(factorSoFar)); + } else { + factorSoFar = operand; + } + + pendingMultiplicativeOperator = clickedOperator; + waitingForOperand = true; +} +//! [18] + +//! [20] +void Calculator::equalClicked() +{ + double operand = display->text().toDouble(); + + if (!pendingMultiplicativeOperator.isEmpty()) { + if (!calculate(operand, pendingMultiplicativeOperator)) { + abortOperation(); + return; + } + operand = factorSoFar; + factorSoFar = 0.0; + pendingMultiplicativeOperator.clear(); + } + if (!pendingAdditiveOperator.isEmpty()) { + if (!calculate(operand, pendingAdditiveOperator)) { + abortOperation(); + return; + } + pendingAdditiveOperator.clear(); + } else { + sumSoFar = operand; + } + + display->setText(QString::number(sumSoFar)); + sumSoFar = 0.0; + waitingForOperand = true; +} +//! [20] + +//! [22] +void Calculator::pointClicked() +{ + if (waitingForOperand) + display->setText("0"); + if (!display->text().contains('.')) + display->setText(display->text() + "."); + waitingForOperand = false; +} +//! [22] + +//! [24] +void Calculator::changeSignClicked() +{ + QString text = display->text(); + double value = text.toDouble(); + + if (value > 0.0) { + text.prepend("-"); + } else if (value < 0.0) { + text.remove(0, 1); + } + display->setText(text); +} +//! [24] + +//! [26] +void Calculator::backspaceClicked() +{ + if (waitingForOperand) + return; + + QString text = display->text(); + text.chop(1); + if (text.isEmpty()) { + text = "0"; + waitingForOperand = true; + } + display->setText(text); +} +//! [26] + +//! [28] +void Calculator::clear() +{ + if (waitingForOperand) + return; + + display->setText("0"); + waitingForOperand = true; +} +//! [28] + +//! [30] +void Calculator::clearAll() +{ + sumSoFar = 0.0; + factorSoFar = 0.0; + pendingAdditiveOperator.clear(); + pendingMultiplicativeOperator.clear(); + display->setText("0"); + waitingForOperand = true; +} +//! [30] + +//! [32] +void Calculator::clearMemory() +{ + sumInMemory = 0.0; +} + +void Calculator::readMemory() +{ + display->setText(QString::number(sumInMemory)); + waitingForOperand = true; +} + +void Calculator::setMemory() +{ + equalClicked(); + sumInMemory = display->text().toDouble(); +} + +void Calculator::addToMemory() +{ + equalClicked(); + sumInMemory += display->text().toDouble(); +} +//! [32] +//! [34] +Button *Calculator::createButton(const QString &text, const char *member) +{ + Button *button = new Button(text); + connect(button, SIGNAL(clicked()), this, member); + return button; +} +//! [34] + +//! [36] +void Calculator::abortOperation() +{ + clearAll(); + display->setText("####"); +} +//! [36] + +//! [38] +bool Calculator::calculate(double rightOperand, const QString &pendingOperator) +{ + if (pendingOperator == "+") { + sumSoFar += rightOperand; + } else if (pendingOperator == "-") { + sumSoFar -= rightOperand; + } else if (pendingOperator == "\303\227") { + factorSoFar *= rightOperand; + } else if (pendingOperator == "\303\267") { + if (rightOperand == 0.0) + return false; + factorSoFar /= rightOperand; + } + return true; +} +//! [38] diff --git a/third_party/SingleApplication-3.3.2/examples/calculator/calculator.h b/third_party/SingleApplication-3.3.2/examples/calculator/calculator.h new file mode 100644
index 00000000..250a2f3e --- /dev/null +++ b/third_party/SingleApplication-3.3.2/examples/calculator/calculator.h
@@ -0,0 +1,117 @@ +/**************************************************************************** +** +** 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 CALCULATOR_H +#define CALCULATOR_H + +#include <QWidget> + +QT_BEGIN_NAMESPACE +class QLineEdit; +QT_END_NAMESPACE +class Button; + +//! [0] +class Calculator : public QWidget +{ + Q_OBJECT + +public: + Calculator(QWidget *parent = 0); + +private slots: + void digitClicked(); + void unaryOperatorClicked(); + void additiveOperatorClicked(); + void multiplicativeOperatorClicked(); + void equalClicked(); + void pointClicked(); + void changeSignClicked(); + void backspaceClicked(); + void clear(); + void clearAll(); + void clearMemory(); + void readMemory(); + void setMemory(); + void addToMemory(); +//! [0] + +//! [1] +private: +//! [1] //! [2] + Button *createButton(const QString &text, const char *member); + void abortOperation(); + bool calculate(double rightOperand, const QString &pendingOperator); +//! [2] + +//! [3] + double sumInMemory; +//! [3] //! [4] + double sumSoFar; +//! [4] //! [5] + double factorSoFar; +//! [5] //! [6] + QString pendingAdditiveOperator; +//! [6] //! [7] + QString pendingMultiplicativeOperator; +//! [7] //! [8] + bool waitingForOperand; +//! [8] + +//! [9] + QLineEdit *display; +//! [9] //! [10] + + enum { NumDigitButtons = 10 }; + Button *digitButtons[NumDigitButtons]; +}; +//! [10] + +#endif diff --git a/third_party/SingleApplication-3.3.2/examples/calculator/calculator.pro b/third_party/SingleApplication-3.3.2/examples/calculator/calculator.pro new file mode 100644
index 00000000..8f132609 --- /dev/null +++ b/third_party/SingleApplication-3.3.2/examples/calculator/calculator.pro
@@ -0,0 +1,11 @@ +QT += widgets + +HEADERS = button.h \ + calculator.h +SOURCES = button.cpp \ + calculator.cpp \ + main.cpp + +# Single Application implementation +include(../../singleapplication.pri) +DEFINES += QAPPLICATION_CLASS=QApplication diff --git a/third_party/SingleApplication-3.3.2/examples/calculator/main.cpp b/third_party/SingleApplication-3.3.2/examples/calculator/main.cpp new file mode 100644
index 00000000..d45438f4 --- /dev/null +++ b/third_party/SingleApplication-3.3.2/examples/calculator/main.cpp
@@ -0,0 +1,71 @@ +/**************************************************************************** +** +** 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 <QApplication> + +#include <singleapplication.h> + +#include "calculator.h" + +int main(int argc, char *argv[]) +{ + SingleApplication app(argc, argv); + + Calculator calc; + + QObject::connect( &app, &SingleApplication::instanceStarted, [ &calc ]() { + calc.raise(); + calc.activateWindow(); + }); + + calc.show(); + + return app.exec(); +} diff --git a/third_party/SingleApplication-3.3.2/examples/sending_arguments/CMakeLists.txt b/third_party/SingleApplication-3.3.2/examples/sending_arguments/CMakeLists.txt new file mode 100644
index 00000000..2cc55975 --- /dev/null +++ b/third_party/SingleApplication-3.3.2/examples/sending_arguments/CMakeLists.txt
@@ -0,0 +1,20 @@ +cmake_minimum_required(VERSION 3.7.0) + +project(sending_arguments LANGUAGES CXX) + +set(CMAKE_AUTOMOC ON) + +# SingleApplication base class +set(QAPPLICATION_CLASS QCoreApplication) +add_subdirectory(../.. SingleApplication) + +find_package(Qt${QT_DEFAULT_MAJOR_VERSION} COMPONENTS Core REQUIRED) + +add_executable(${PROJECT_NAME} + main.cpp + messagereceiver.cpp + messagereceiver.h + main.cpp +) + +target_link_libraries(${PROJECT_NAME} SingleApplication::SingleApplication) diff --git a/third_party/SingleApplication-3.3.2/examples/sending_arguments/main.cpp b/third_party/SingleApplication-3.3.2/examples/sending_arguments/main.cpp new file mode 100755
index 00000000..a9d34dd9 --- /dev/null +++ b/third_party/SingleApplication-3.3.2/examples/sending_arguments/main.cpp
@@ -0,0 +1,28 @@ +#include <singleapplication.h> +#include "messagereceiver.h" + +int main(int argc, char *argv[]) +{ + // Allow secondary instances + SingleApplication app( argc, argv, true ); + + MessageReceiver msgReceiver; + + // If this is a secondary instance + if( app.isSecondary() ) { + app.sendMessage( app.arguments().join(' ').toUtf8() ); + qDebug() << "App already running."; + qDebug() << "Primary instance PID: " << app.primaryPid(); + qDebug() << "Primary instance user: " << app.primaryUser(); + return 0; + } else { + QObject::connect( + &app, + &SingleApplication::receivedMessage, + &msgReceiver, + &MessageReceiver::receivedMessage + ); + } + + return app.exec(); +} diff --git a/third_party/SingleApplication-3.3.2/examples/sending_arguments/messagereceiver.cpp b/third_party/SingleApplication-3.3.2/examples/sending_arguments/messagereceiver.cpp new file mode 100644
index 00000000..0560b072 --- /dev/null +++ b/third_party/SingleApplication-3.3.2/examples/sending_arguments/messagereceiver.cpp
@@ -0,0 +1,12 @@ +#include <QDebug> +#include "messagereceiver.h" + +MessageReceiver::MessageReceiver(QObject *parent) : QObject(parent) +{ +} + +void MessageReceiver::receivedMessage(int instanceId, QByteArray message) +{ + qDebug() << "Received message from instance: " << instanceId; + qDebug() << "Message Text: " << message; +} diff --git a/third_party/SingleApplication-3.3.2/examples/sending_arguments/messagereceiver.h b/third_party/SingleApplication-3.3.2/examples/sending_arguments/messagereceiver.h new file mode 100644
index 00000000..50a970c8 --- /dev/null +++ b/third_party/SingleApplication-3.3.2/examples/sending_arguments/messagereceiver.h
@@ -0,0 +1,15 @@ +#ifndef MESSAGERECEIVER_H +#define MESSAGERECEIVER_H + +#include <QObject> + +class MessageReceiver : public QObject +{ + Q_OBJECT +public: + explicit MessageReceiver(QObject *parent = 0); +public slots: + void receivedMessage( int instanceId, QByteArray message ); +}; + +#endif // MESSAGERECEIVER_H diff --git a/third_party/SingleApplication-3.3.2/examples/sending_arguments/sending_arguments.pro b/third_party/SingleApplication-3.3.2/examples/sending_arguments/sending_arguments.pro new file mode 100755
index 00000000..897636a9 --- /dev/null +++ b/third_party/SingleApplication-3.3.2/examples/sending_arguments/sending_arguments.pro
@@ -0,0 +1,9 @@ +# Single Application implementation +include(../../singleapplication.pri) +DEFINES += QAPPLICATION_CLASS=QCoreApplication + +SOURCES += main.cpp \ + messagereceiver.cpp + +HEADERS += \ + messagereceiver.h