2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 06:26:18 +00:00

Move standard buttons to lib_ui.

This commit is contained in:
John Preston
2019-09-13 19:45:48 +03:00
parent a16c6ca41a
commit c057f28425
45 changed files with 330 additions and 150 deletions

View File

@@ -184,6 +184,15 @@ void Application::run() {
Ui::Emoji::Init();
Media::Player::start(_audio.get());
style::ShortAnimationPlaying(
) | rpl::start_with_next([=](bool playing) {
if (playing) {
MTP::internal::pause();
} else {
MTP::internal::unpause();
}
}, _lifetime);
DEBUG_LOG(("Application Info: inited..."));
cChangeTimeFormat(QLocale::system().timeFormat(QLocale::ShortFormat));
@@ -732,7 +741,7 @@ QPoint Application::getPointForCallPanelCenter() const {
}
// macOS Qt bug workaround, sometimes no leaveEvent() gets to the nested widgets.
void Application::registerLeaveSubscription(QWidget *widget) {
void Application::registerLeaveSubscription(not_null<QWidget*> widget) {
#ifdef Q_OS_MAC
if (const auto topLevel = widget->window()) {
if (topLevel == _window->widget()) {
@@ -750,7 +759,7 @@ void Application::registerLeaveSubscription(QWidget *widget) {
#endif // Q_OS_MAC
}
void Application::unregisterLeaveSubscription(QWidget *widget) {
void Application::unregisterLeaveSubscription(not_null<QWidget*> widget) {
#ifdef Q_OS_MAC
_leaveSubscriptions = std::move(
_leaveSubscriptions
@@ -869,4 +878,12 @@ void PostponeCall(FnMut<void()> &&callable) {
Core::App().postponeCall(std::move(callable));
}
void RegisterLeaveSubscription(not_null<QWidget*> widget) {
Core::App().registerLeaveSubscription(widget);
}
void UnregisterLeaveSubscription(not_null<QWidget*> widget) {
Core::App().unregisterLeaveSubscription(widget);
}
} // namespace Ui

View File

@@ -199,8 +199,8 @@ public:
[[nodiscard]] crl::time lastNonIdleTime() const;
void updateNonIdle();
void registerLeaveSubscription(QWidget *widget);
void unregisterLeaveSubscription(QWidget *widget);
void registerLeaveSubscription(not_null<QWidget*> widget);
void unregisterLeaveSubscription(not_null<QWidget*> widget);
// Sandbox interface.
void postponeCall(FnMut<void()> &&callable);

View File

@@ -1,82 +0,0 @@
/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once
#include "core/sandbox.h"
namespace Core {
// This method allows to create an rpl::producer from a Qt object
// and a signal with none or one reported value.
//
// QtSignalProducer(qtWindow, &QWindow::activeChanged) | rpl::start_
//
// This producer values construct a custom event loop leave point.
// This means that all postponeCall's will be invoked right after
// the value processing by the current consumer finishes.
template <typename Object, typename Signal>
auto QtSignalProducer(Object *object, Signal signal);
namespace details {
template <typename Signal>
struct QtSignalArgument;
template <typename Class, typename Return, typename Value>
struct QtSignalArgument<Return(Class::*)(Value)> {
using type = Value;
};
template <typename Class, typename Return>
struct QtSignalArgument<Return(Class::*)()> {
using type = void;
};
} // namespace details
template <typename Object, typename Signal>
auto QtSignalProducer(Object *object, Signal signal) {
using Value = typename details::QtSignalArgument<Signal>::type;
static constexpr auto NoArgument = std::is_same_v<Value, void>;
using Produced = std::conditional_t<
NoArgument,
rpl::empty_value,
std::remove_const_t<std::decay_t<Value>>>;
const auto guarded = QPointer<Object>(object);
return rpl::make_producer<Produced>([=](auto consumer) {
if (!guarded) {
return rpl::lifetime();
}
const auto connect = [&](auto &&handler) {
const auto listener = new QObject(guarded.data());
QObject::connect(
guarded,
signal,
listener,
std::forward<decltype(handler)>(handler));
const auto weak = QPointer<QObject>(listener);
return rpl::lifetime([=] {
if (weak) {
delete weak;
}
});
};
auto put = [=](const Produced &value) {
Sandbox::Instance().customEnterFromEventLoop([&] {
consumer.put_next_copy(value);
});
};
if constexpr (NoArgument) {
return connect([put = std::move(put)] { put({}); });
} else {
return connect(std::move(put));
}
});
}
} // namespace Core

View File

@@ -613,3 +613,11 @@ rpl::producer<> on_main_update_requests() {
}
} // namespace crl
namespace base {
void EnterFromEventLoop(FnMut<void()> &&method) {
Core::Sandbox::Instance().customEnterFromEventLoop(std::move(method));
}
} // namespace base