Skip to content

Commit

Permalink
cxx-qt-lib-extras: add QPushButton
Browse files Browse the repository at this point in the history
  • Loading branch information
ahayzen-kdab committed Oct 8, 2024
1 parent 7d57542 commit 0c481d0
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 0 deletions.
2 changes: 2 additions & 0 deletions crates/cxx-qt-lib-extras/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ fn main() {
"core/qcommandlineoption",
"core/qcommandlineparser",
"gui/qapplication",
"gui/qpushbutton",
];

for rust_source in &rust_bridges {
Expand All @@ -68,6 +69,7 @@ fn main() {
"core/qcommandlineoption",
"core/qcommandlineparser",
"gui/qapplication",
"gui/qpushbutton",
];

builder = builder.cc_builder(move |cc| {
Expand Down
10 changes: 10 additions & 0 deletions crates/cxx-qt-lib-extras/include/gui/qpushbutton.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// clang-format off
// SPDX-FileCopyrightText: 2023 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
// clang-format on
// SPDX-FileContributor: Andrew Hayzen <[email protected]>
//
// SPDX-License-Identifier: MIT OR Apache-2.0

#pragma once

#include <QtWidgets/QPushButton>
3 changes: 3 additions & 0 deletions crates/cxx-qt-lib-extras/src/gui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@

mod qapplication;
pub use qapplication::QApplication;

mod qpushbutton;
pub use qpushbutton::QPushButton;
8 changes: 8 additions & 0 deletions crates/cxx-qt-lib-extras/src/gui/qpushbutton.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// clang-format off
// SPDX-FileCopyrightText: 2024 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
// clang-format on
// SPDX-FileContributor: Andrew Hayzen <[email protected]>
//
// SPDX-License-Identifier: MIT OR Apache-2.0

#include "cxx-qt-lib-extras/qpushbutton.h"
50 changes: 50 additions & 0 deletions crates/cxx-qt-lib-extras/src/gui/qpushbutton.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// SPDX-FileCopyrightText: 2024 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
// SPDX-FileContributor: Andrew Hayzen <[email protected]>
//
// SPDX-License-Identifier: MIT OR Apache-2.0

#[cxx_qt::bridge]
mod ffi {
unsafe extern "C++" {
include!("cxx-qt-lib/qstring.h");
type QString = cxx_qt_lib::QString;
}

unsafe extern "C++Qt" {
include!("cxx-qt-lib-extras/qpushbutton.h");

#[qobject]
type QPushButton;

// TODO: we should use upcasting methods here and implement QAbstractButton and QWidget
// so that we don't need to duplicate all of the methods

/// This signal is emitted when the button is activated (i.e., pressed down then released while the mouse cursor is inside the button)
#[qsignal]
fn clicked(self: Pin<&mut QPushButton>, checked: bool);

/// Set the text shown on the button
#[rust_name = "set_text"]
fn setText(self: Pin<&mut QPushButton>, text: &QString);

/// Shows the widget and its child widgets.
fn show(self: Pin<&mut QPushButton>);
}

#[namespace = "rust::cxxqtlib1"]
unsafe extern "C++Qt" {
include!("cxx-qt-lib/common.h");

#[doc(hidden)]
#[rust_name = "qpushbutton_init_default"]
fn make_unique() -> UniquePtr<QPushButton>;
}
}

impl ffi::QPushButton {
pub fn new() -> cxx::UniquePtr<Self> {
ffi::qpushbutton_init_default()
}
}

pub use ffi::QPushButton;

0 comments on commit 0c481d0

Please sign in to comment.