mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-24 03:10:52 +01:00
Update SingleApplication to v3.5.1 version
This commit is contained in:
0
SingleApplication/examples/basic/basic.pro
Normal file → Executable file
0
SingleApplication/examples/basic/basic.pro
Normal file → Executable file
23
SingleApplication/examples/basic/main.cpp
Normal file → Executable file
23
SingleApplication/examples/basic/main.cpp
Normal file → Executable file
@@ -1,3 +1,26 @@
|
||||
// Copyright (c) Itay Grudev 2015 - 2023
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// Permission is not granted to use this software or any of the associated files
|
||||
// as sample data for the purposes of building machine learning models.
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
#include <singleapplication.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
|
||||
23
SingleApplication/examples/sending_arguments/main.cpp
Normal file → Executable file
23
SingleApplication/examples/sending_arguments/main.cpp
Normal file → Executable file
@@ -1,3 +1,26 @@
|
||||
// Copyright (c) Itay Grudev 2015 - 2023
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// Permission is not granted to use this software or any of the associated files
|
||||
// as sample data for the purposes of building machine learning models.
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
#include <singleapplication.h>
|
||||
#include "messagereceiver.h"
|
||||
|
||||
|
||||
@@ -1,3 +1,26 @@
|
||||
// Copyright (c) Itay Grudev 2015 - 2023
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// Permission is not granted to use this software or any of the associated files
|
||||
// as sample data for the purposes of building machine learning models.
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
#include <QDebug>
|
||||
#include "messagereceiver.h"
|
||||
|
||||
|
||||
@@ -1,3 +1,26 @@
|
||||
// Copyright (c) Itay Grudev 2015 - 2023
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// Permission is not granted to use this software or any of the associated files
|
||||
// as sample data for the purposes of building machine learning models.
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
#ifndef MESSAGERECEIVER_H
|
||||
#define MESSAGERECEIVER_H
|
||||
|
||||
|
||||
0
SingleApplication/examples/sending_arguments/sending_arguments.pro
Normal file → Executable file
0
SingleApplication/examples/sending_arguments/sending_arguments.pro
Normal file → Executable file
@@ -0,0 +1,16 @@
|
||||
cmake_minimum_required(VERSION 3.7.0)
|
||||
|
||||
project(windows_raise_widget LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
set(CMAKE_WIN32_EXECUTABLE TRUE)
|
||||
|
||||
# SingleApplication base class
|
||||
set(QAPPLICATION_CLASS QApplication)
|
||||
add_subdirectory(../.. SingleApplication)
|
||||
|
||||
find_package(Qt${QT_DEFAULT_MAJOR_VERSION} COMPONENTS Core Widgets REQUIRED)
|
||||
|
||||
add_executable(${PROJECT_NAME} main.cpp)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} SingleApplication::SingleApplication)
|
||||
59
SingleApplication/examples/windows_raise_widget/main.cpp
Normal file
59
SingleApplication/examples/windows_raise_widget/main.cpp
Normal file
@@ -0,0 +1,59 @@
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
#include "singleapplication.h"
|
||||
|
||||
#ifdef Q_OS_WINDOWS
|
||||
#include <Windows.h>
|
||||
#endif
|
||||
|
||||
void raiseWidget(QWidget* widget);
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
#ifdef Q_OS_WINDOWS
|
||||
SingleApplication app(argc, argv, true);
|
||||
|
||||
if (app.isSecondary()) {
|
||||
|
||||
AllowSetForegroundWindow( DWORD( app.primaryPid() ) );
|
||||
|
||||
app.sendMessage("RAISE_WIDGET");
|
||||
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
SingleApplication app(argc, argv);
|
||||
#endif
|
||||
|
||||
QWidget* widget = new QWidget;
|
||||
|
||||
#ifdef Q_OS_WINDOWS
|
||||
QObject::connect(&app, &SingleApplication::receivedMessage,
|
||||
widget, [widget] () { raiseWidget(widget); } );
|
||||
#else
|
||||
QObject::connect(&app, &SingleApplication::instanceStarted,
|
||||
widget, [widget] () { raiseWidget(widget); } );
|
||||
#endif
|
||||
|
||||
widget->show();
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
|
||||
void raiseWidget(QWidget* widget) {
|
||||
#ifdef Q_OS_WINDOWS
|
||||
HWND hwnd = (HWND)widget->winId();
|
||||
|
||||
// check if widget is minimized to Windows task bar
|
||||
if (::IsIconic(hwnd)) {
|
||||
::ShowWindow(hwnd, SW_RESTORE);
|
||||
}
|
||||
|
||||
::SetForegroundWindow(hwnd);
|
||||
#else
|
||||
widget->show();
|
||||
widget->raise();
|
||||
widget->activateWindow();
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
# Single Application implementation
|
||||
include(../../singleapplication.pri)
|
||||
DEFINES += QAPPLICATION_CLASS=QApplication
|
||||
|
||||
QT += widgets
|
||||
SOURCES += main.cpp
|
||||
|
||||
win32{
|
||||
LIBS += User32.lib
|
||||
}
|
||||
Reference in New Issue
Block a user