init
Some checks failed
Docker. / Ubuntu (push) Has been cancelled
User-agent updater. / User-agent (push) Failing after 15s
Lock Threads / lock (push) Failing after 10s
Waiting for answer. / waiting-for-answer (push) Failing after 22s
Close stale issues and PRs / stale (push) Successful in 13s
Needs user action. / needs-user-action (push) Failing after 8s
Can't reproduce. / cant-reproduce (push) Failing after 8s

This commit is contained in:
allhaileris
2026-02-16 15:50:16 +03:00
commit afb81b8278
13816 changed files with 3689732 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
// This file is part of Desktop App Toolkit,
// a set of libraries for developing nice desktop applications.
//
// For license and copyright information please follow this link:
// https://github.com/desktop-app/legal/blob/master/LEGAL
//
#pragma once
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
#include <QtGui/QInputDevice>
#else // Qt >= 6.0.0
#include <QtGui/QTouchDevice>
#endif // Qt < 6.0.0
namespace base {
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
using TouchDevice = QInputDevice::DeviceType;
#else // Qt >= 6.0.0
using TouchDevice = QTouchDevice;
#endif // Qt < 6.0.0
} // namespace base

View File

@@ -0,0 +1,112 @@
// This file is part of Desktop App Toolkit,
// a set of libraries for developing nice desktop applications.
//
// For license and copyright information please follow this link:
// https://github.com/desktop-app/legal/blob/master/LEGAL
//
#pragma once
#include <compare>
#include <variant>
#include <gsl/pointers>
#include <QString>
#if !defined(__apple_build_version__) || (__apple_build_version__ > 12000032)
template <typename P>
[[nodiscard]] inline std::strong_ordering operator<=>(
const gsl::not_null<P> &a,
const gsl::not_null<P> &b) noexcept {
return a.get() <=> b.get();
}
#if QT_VERSION < QT_VERSION_CHECK(6, 8, 0) || !defined __cpp_lib_three_way_comparison
[[nodiscard]] inline std::strong_ordering operator<=>(
const QString &a,
const QString &b) noexcept {
return a.compare(b) <=> 0;
}
#endif // Qt < 6.8.0 || !__cpp_lib_three_way_comparison
template <typename T>
[[nodiscard]] inline std::strong_ordering operator<=>(
const QVector<T> &a,
const QVector<T> &b) noexcept {
const auto as = a.size();
const auto bs = b.size();
const auto s = int(std::min(as, bs));
for (auto i = 0; i != s; ++i) {
const auto result = (a[i] <=> b[i]);
if (result != std::strong_ordering::equal
&& result != std::strong_ordering::equivalent) {
return result;
}
}
return (as <=> bs);
}
#ifndef _MSC_VER
namespace base::details {
template <typename T>
using compare_three_way_result_t = decltype(
(std::declval<const std::remove_reference_t<T>&>()
<=> std::declval<const std::remove_reference_t<T>&>()));
template <typename ...Types>
using variant_compare_result = std::common_comparison_category_t<
compare_three_way_result_t<Types>...>;
template <int Index, typename ...Types>
constexpr variant_compare_result<Types...> variant_comparator(
const std::variant<Types...> &a,
const std::variant<Types...> &b,
int index) {
if (index == Index) {
return *std::get_if<Index>(&a) <=> *std::get_if<Index>(&b);
} else if constexpr (Index + 1 < sizeof...(Types)) {
return variant_comparator<Index + 1>(a, b, index);
} else {
Unexpected("Index value in variant_comparator.");
}
}
} // namespace base::details
template <typename ...Types>
inline constexpr auto operator<=>(
const std::variant<Types...> &a,
const std::variant<Types...> &b)
-> base::details::variant_compare_result<Types...> {
const auto index = a.index();
if (const auto result = (index <=> b.index())
; result != std::strong_ordering::equal) {
return result;
}
return base::details::variant_comparator<0>(a, b, index);
}
template <typename Type, typename Result = decltype(std::declval<Type>() <=> std::declval<Type>())>
inline constexpr auto operator<=>(
const std::vector<Type> &a,
const std::vector<Type> &b) -> Result {
const auto asize = a.size();
const auto bsize = b.size();
const auto min = std::min(asize, bsize);
for (auto i = std::size_t(); i != min; ++i) {
const auto result = (a[i] <=> b[i]);
if (result != Result::equivalent) {
return result;
}
}
if (asize < bsize) {
return Result::less;
} else if (asize > bsize) {
return Result::greater;
}
return Result::equivalent;
}
#endif // _MSC_VER
#endif // __apple_build_version__

View File

@@ -0,0 +1,25 @@
// This file is part of Desktop App Toolkit,
// a set of libraries for developing nice desktop applications.
//
// For license and copyright information please follow this link:
// https://github.com/desktop-app/legal/blob/master/LEGAL
//
#pragma once
#include <QtGui/QGuiApplication>
namespace base {
[[nodiscard]] inline bool IsCtrlPressed() {
return (QGuiApplication::keyboardModifiers() == Qt::ControlModifier);
}
[[nodiscard]] inline bool IsAltPressed() {
return (QGuiApplication::keyboardModifiers() == Qt::AltModifier);
}
[[nodiscard]] inline bool IsShiftPressed() {
return (QGuiApplication::keyboardModifiers() == Qt::ShiftModifier);
}
} // namespace base

View File

@@ -0,0 +1,66 @@
// This file is part of Desktop App Toolkit,
// a set of libraries for developing nice desktop applications.
//
// For license and copyright information please follow this link:
// https://github.com/desktop-app/legal/blob/master/LEGAL
//
#pragma once
#include <QtCore/QString>
namespace base {
namespace details {
struct ContainerImplHelper {
enum CutResult { Null, Empty, Full, Subset };
static constexpr CutResult mid(
qsizetype originalLength,
qsizetype *_position,
qsizetype *_length) {
qsizetype &position = *_position;
qsizetype &length = *_length;
if (position > originalLength) {
position = 0;
length = 0;
return Null;
}
if (position < 0) {
if (length < 0 || length + position >= originalLength) {
position = 0;
length = originalLength;
return Full;
}
if (length + position <= 0) {
position = length = 0;
return Null;
}
length += position;
position = 0;
} else if (size_t(length) > size_t(originalLength - position)) {
length = originalLength - position;
}
if (position == 0 && length == originalLength)
return Full;
return length > 0 ? Subset : Empty;
}
};
} // namespace details
[[nodiscard]] inline QStringView StringViewMid(
QStringView view,
qsizetype pos,
qsizetype n = -1) {
const auto result = details::ContainerImplHelper::mid(
view.size(),
&pos,
&n);
return (result == details::ContainerImplHelper::Null)
? QStringView()
: view.mid(pos, n);
}
} // namespace base

View File

@@ -0,0 +1,51 @@
// This file is part of Desktop App Toolkit,
// a set of libraries for developing nice desktop applications.
//
// For license and copyright information please follow this link:
// https://github.com/desktop-app/legal/blob/master/LEGAL
//
#include "base/qt/qt_tab_key.h"
#include "base/event_filter.h"
#include <QApplication>
#include <QKeyEvent>
#include <QWidget>
namespace base {
bool FocusNextPrevChildBlocked(not_null<QWidget*> widget, bool next) {
const auto skip = [&](QWidget *w) {
return next ? w->nextInFocusChain() : w->previousInFocusChain();
};
const auto focused = QApplication::focusWidget();
const auto start = focused ? focused : widget.get();
auto w = skip(start);
while (w && w != start) {
if ((w->focusPolicy() & Qt::TabFocus) && widget->isAncestorOf(w)) {
break;
}
w = skip(w);
}
if (w && w != start) {
w->setFocus(next ? Qt::TabFocusReason : Qt::BacktabFocusReason);
}
return true;
}
void DisableTabKey(QWidget *widget) {
if (!widget) {
return;
}
install_event_filter(widget, [=](not_null<QEvent*> e) {
if (e->type() == QEvent::KeyPress) {
const auto key = static_cast<QKeyEvent*>(e.get())->key();
if ((key == Qt::Key_Tab) || (key == Qt::Key_Backtab)) {
return base::EventFilterResult::Cancel;
}
}
return base::EventFilterResult::Continue;
});
}
} // namespace base

View File

@@ -0,0 +1,17 @@
// This file is part of Desktop App Toolkit,
// a set of libraries for developing nice desktop applications.
//
// For license and copyright information please follow this link:
// https://github.com/desktop-app/legal/blob/master/LEGAL
//
#pragma once
class QWidget;
namespace base {
bool FocusNextPrevChildBlocked(not_null<QWidget*> widget, bool next);
void DisableTabKey(QWidget *widget);
} // namespace base