Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
iamsergio committed Apr 9, 2024
0 parents commit d7074b2
Show file tree
Hide file tree
Showing 471 changed files with 294,851 additions and 0 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# SPDX-FileCopyrightText: 2023 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
#
# SPDX-License-Identifier: MIT

name: CI

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
os:
- ubuntu-latest
- windows-latest
- macos-latest

steps:
- name: Install Qt 6.6
uses: jurplel/install-qt-action@v3
with:
version: 6.6.3
cache: true

- name: Install ninja-build tool (must be after Qt due PATH changes)
uses: turtlesec-no/get-ninja@main

- name: Checkout sources
uses: actions/checkout@v4

- name: Make sure MSVC is found when Ninja generator is in use
if: ${{ runner.os == 'Windows' }}
uses: ilammy/msvc-dev-cmd@v1

- name: Configure project
run: cmake --preset dev

- name: Build Project
run: cmake --build build-dev
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
libQtDartBindings.so
*.o
mjb_rejected_*.log
/build
CMakeFiles
.ninja*
CMakeCache.txt
.dart_tool
.packages
build.ninja
cmake_install.cmake
CMakeLists.txt.user
.cmake
compile_commands.json
/build-dev
23 changes: 23 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# This file is part of dart-qtbindings
#
# SPDX-FileCopyrightText: 2022 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
# SPDX-License-Identifier: MIT

cmake_minimum_required(VERSION 3.10)

project(DartQt6Bindings LANGUAGES CXX)

# Uncomment once Qt bindings are exported too
# set(CMAKE_CXX_VISIBILITY_PRESET hidden)

set(ECM_MODULE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/cmake/ECM/modules/")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake" ${ECM_MODULE_DIR})

include(ECMEnableSanitizers)


find_package(Qt6Widgets)

add_subdirectory(generated/QtDartBindings/)

install(TARGETS QtDartBindings)
36 changes: 36 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"version": 2,
"configurePresets": [
{
"name": "dev",
"displayName": "dev",
"generator": "Ninja",
"binaryDir": "${sourceDir}/build-dev",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
"CMAKE_EXPORT_COMPILE_COMMANDS" : "ON"
}
},
{
"name": "dev-asan",
"displayName": "dev-san",
"generator": "Ninja",
"binaryDir": "${sourceDir}/build-dev-asan",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
"CMAKE_EXPORT_COMPILE_COMMANDS" : "ON",
"ECM_ENABLE_SANITIZERS" : "'address;undefined'"
}
},
{
"name": "release",
"displayName": "release",
"generator": "Ninja",
"binaryDir": "${sourceDir}/build-release",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release",
"CMAKE_EXPORT_COMPILE_COMMANDS" : "ON"
}
}
]
}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Sergio Martins

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:

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.
86 changes: 86 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# dart-qtbindings

This is a proof of concept of Qt bindings for Dart.

The goal is only to showcase the C++ binding generator for Dart, Dartagnan.<br>
There's no intention in creating production ready Qt bindings.

![dart-qtbindings](qtbindings.png)

# Build

```bash
cmake .
cmake --build .
```

You now have a Qt bindings library: `generated/QtDartBindings/libQtDartBindings.so`
These are the C wrappers produced by our dart generator.

# Run

`libQtDartBindings.so` needs to be in your library path, so edit PATH (Windows), LD_LIBRARY_PATH (Linux)
or DYLD_LIBRARY_PATH(macOS). On mac you'll need to disable system integrity protection though.

Or alternatively, edit:
```bash
generated/QtDartBindings/dart/lib/Bindings.dart: _dylib = ffi.DynamicLibrary.open('libQtDartBindings.so');
```

and use an hardcoded absolute path in the source.

On Linux, it's just:
```
export LD_LIBRARY_PATH=build-dev/generated/QtDartBindings/:$LD_LIBRARY_PATH
```

Now run:

```
cd app
dart pub get # Could this be done automatically ?
dart run bin/main.dart
```

# Regenerating the Bindings

Be sure to build and install `dartagnan` and put it in path.

Then run:

```
dart pub get
dart refresh_bindings.dart
```

# Repo Layout


`app/`
Our dart test app, which shows a Qt window.

`generated/`
Contains all the code generated by shiboken.
Includes the dart classes which users will use, and also the intermediate
C and C++ glue which calls the target C++ code.

`typesystem.xml`
Used by shiboken, at "binding generation time".
The file for configuring the shiboken generation. Lists all classes we want bindings.for

`bindings_global.h`
Used by shiboken, at "binding generation time". Includes all headers we want bindings for.

`shiboken_snippets/`
Sometimes shiboken needs a little help and we can provide some snippets for it, so we say
exactly what we want generated.



# Known Issues

* macOS: "NSWindow drag regions should only be invalidated on the Main Thread!"
See https://github.com/dart-lang/sdk/issues/38315 , patches welcome


![Build Status](https://github.com/KDABLabs/dart-qtbindings/actions/workflows/build.yml/badge.svg
5 changes: 5 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
analyzer:
errors:
must_be_a_native_function_type: ignore
non_native_function_type_argument_to_pointer: ignore
implicit_dynamic_return: ignore
69 changes: 69 additions & 0 deletions app/bin/main.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/// This file is part of dart-qtbindings
///
/// SPDX-FileCopyrightText: 2022 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
/// SPDX-License-Identifier: MIT
import 'package:QtDartBindings/Bindings.dart';
import 'dart:async';

class MyButton extends QPushButton {
MyButton(String title) : super.ctor3(title, parent: null) {}

void mousePressEvent(QMouseEvent? e) {
if (e == null)
return; // Required check, otherwise null safety compile error

print("Mouse press! ${e.pos().x()},${e.pos().y()}");

final widgets = QApplication.topLevelWidgets();
final numWidgets = widgets.size();

for (int i = 0; i < numWidgets; ++i) {
final QRect geometry = widgets.at(i).frameGeometry();
print("Widget: ${geometry.width()}x${geometry.height()}");
}

super.mousePressEvent(e);
}
}

void runQtEventLoop() async {
// We can't simply call QApplication.exec(), as that would block dart's
// event loop. This will do for now.
QCoreApplication.processEvents();
Timer(Duration(milliseconds: 10), runQtEventLoop);
}

void main() {
var app = QApplication();
var widget = QWidget(parent: null);

var lay = QVBoxLayout(widget);
var helloButton = MyButton("Hello2");
helloButton.onClicked(() {
print("Button clicked!");
});

var maxButton = MyButton("Maximize");
var minButton = MyButton("Minimize");
maxButton.onClicked(widget.showMaximized);
minButton.onClicked(widget.showMinimized, context: widget);

lay.addWidget(helloButton);
lay.addWidget(maxButton);
lay.addWidget(minButton);

lay.addStretch();

widget.setWindowTitle("Dart!");
widget.resize_2(300, 1000);
widget.show();

QRect geo = widget.geometry();
print("Size= ${geo.width()}x${geo.height()}");

print("Window Title: " + widget.windowTitle().toDartString());

runQtEventLoop();
print("Dart event loop is not blocked!");
}
60 changes: 60 additions & 0 deletions app/pubspec.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
QtDartBindings:
dependency: "direct main"
description:
path: "../generated/QtDartBindings/dart"
relative: true
source: path
version: "0.0.0"
clock:
dependency: transitive
description:
name: clock
sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf
url: "https://pub.dev"
source: hosted
version: "1.1.1"
ffi:
dependency: transitive
description:
name: ffi
sha256: ed5337a5660c506388a9f012be0288fb38b49020ce2b45fe1f8b8323fe429f99
url: "https://pub.dev"
source: hosted
version: "2.0.2"
intl:
dependency: transitive
description:
name: intl
sha256: "3bc132a9dbce73a7e4a21a17d06e1878839ffbf975568bc875c60537824b0c4d"
url: "https://pub.dev"
source: hosted
version: "0.18.1"
meta:
dependency: transitive
description:
name: meta
sha256: "25dfcaf170a0190f47ca6355bdd4552cb8924b430512ff0cafb8db9bd41fe33b"
url: "https://pub.dev"
source: hosted
version: "1.14.0"
path:
dependency: transitive
description:
name: path
sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917"
url: "https://pub.dev"
source: hosted
version: "1.8.3"
pedantic:
dependency: "direct dev"
description:
name: pedantic
sha256: "67fc27ed9639506c856c840ccce7594d0bdcd91bc8d53d6e52359449a1d50602"
url: "https://pub.dev"
source: hosted
version: "1.11.1"
sdks:
dart: ">=2.17.0 <4.0.0"
15 changes: 15 additions & 0 deletions app/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: DartBindingsTest
description: A test app to test the dart bindings
# version: 1.0.0
# homepage: https://www.example.com

environment:
sdk: '>=2.12.0 <3.0.0'

dependencies:
QtDartBindings:
path: '../generated/QtDartBindings/dart/'

dev_dependencies:
pedantic: ^1.9.0

7 changes: 7 additions & 0 deletions bindings_global.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/// This file is part of dart-qtbindings
///
/// SPDX-FileCopyrightText: 2022 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
/// SPDX-License-Identifier: MIT

#include <QtWidgets/QtWidgets>
#include <QtGui/QtGui>
Loading

0 comments on commit d7074b2

Please sign in to comment.