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

@ -0,0 +1,18 @@
/*
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 "base/basic_types.h"
// Methods that must be implemented outside lib_base.
namespace base {
void EnterFromEventLoop(FnMut<void()> &&method);
} // namespace

View File

@ -7,9 +7,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once
#include "core/sandbox.h"
#include "base/base_integration.h"
namespace Core {
namespace base {
// This method allows to create an rpl::producer from a Qt object
// and a signal with none or one reported value.
@ -20,28 +20,28 @@ namespace Core {
// 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);
auto qt_signal_producer(Object *object, Signal signal);
namespace details {
template <typename Signal>
struct QtSignalArgument;
struct qt_signal_argument;
template <typename Class, typename Return, typename Value>
struct QtSignalArgument<Return(Class::*)(Value)> {
struct qt_signal_argument<Return(Class::*)(Value)> {
using type = Value;
};
template <typename Class, typename Return>
struct QtSignalArgument<Return(Class::*)()> {
struct qt_signal_argument<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;
auto qt_signal_producer(Object *object, Signal signal) {
using Value = typename details::qt_signal_argument<Signal>::type;
static constexpr auto NoArgument = std::is_same_v<Value, void>;
using Produced = std::conditional_t<
NoArgument,
@ -67,7 +67,7 @@ auto QtSignalProducer(Object *object, Signal signal) {
});
};
auto put = [=](const Produced &value) {
Sandbox::Instance().customEnterFromEventLoop([&] {
EnterFromEventLoop([&] {
consumer.put_next_copy(value);
});
};
@ -79,4 +79,4 @@ auto QtSignalProducer(Object *object, Signal signal) {
});
}
} // namespace Core
} // namespace base

View File

@ -14,7 +14,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "window/window_session_controller.h"
#include "mainwindow.h"
#include "core/application.h"
#include "core/qt_signal_producer.h"
#include "app.h"
#include "styles/style_chat_helpers.h"

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

@ -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

View File

@ -121,7 +121,7 @@ InnerWidget::InnerWidget(
? Global::DialogsMode()
: Dialogs::Mode::All;
connect(_addContactLnk, SIGNAL(clicked()), App::wnd(), SLOT(onShowAddContact()));
_addContactLnk->addClickHandler([] { App::wnd()->onShowAddContact(); });
_cancelSearchInChat->setClickedCallback([=] { cancelSearchInChat(); });
_cancelSearchInChat->hide();
_cancelSearchFromUser->setClickedCallback([=] {

View File

@ -12,7 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/ui_utility.h"
#include "lang/lang_keys.h"
#include "core/event_filter.h"
#include "core/qt_signal_producer.h"
#include "base/qt_signal_producer.h"
#include "history/history.h"
#include "chat_helpers/tabbed_panel.h"
#include "chat_helpers/tabbed_section.h"
@ -94,7 +94,7 @@ rpl::producer<> ComposeControls::cancelRequests() const {
rpl::producer<> ComposeControls::sendRequests() const {
auto toEmpty = rpl::map([] { return rpl::empty_value(); });
auto submits = Core::QtSignalProducer(
auto submits = base::qt_signal_producer(
_field.get(),
&Ui::InputField::submitted);
return rpl::merge(

View File

@ -447,7 +447,7 @@ void Inner::refreshSwitchPmButton(const CacheEntry *entry) {
_switchPmButton.create(this, nullptr, st::switchPmButton);
_switchPmButton->show();
_switchPmButton->setTextTransform(Ui::RoundButton::TextTransform::NoTransform);
connect(_switchPmButton, SIGNAL(clicked()), this, SLOT(onSwitchPm()));
_switchPmButton->addClickHandler([=] { onSwitchPm(); });
}
_switchPmButton->setText(rpl::single(entry->switchPmText));
_switchPmStartToken = entry->switchPmStartToken;

View File

@ -91,7 +91,7 @@ CodeWidget::CodeWidget(
connect(_code, SIGNAL(changed()), this, SLOT(onInputChange()));
connect(_callTimer, SIGNAL(timeout()), this, SLOT(onSendCall()));
connect(_checkRequest, SIGNAL(timeout()), this, SLOT(onCheckRequest()));
connect(_noTelegramCode, SIGNAL(clicked()), this, SLOT(onNoTelegramCode()));
_noTelegramCode->addClickHandler([=] { onNoTelegramCode(); });
_code->setDigitsCountMax(getData()->codeLength);
setErrorBelowLink(true);

View File

@ -41,8 +41,8 @@ PwdCheckWidget::PwdCheckWidget(
subscribe(Lang::Current().updated(), [this] { refreshLang(); });
connect(_checkRequest, SIGNAL(timeout()), this, SLOT(onCheckRequest()));
connect(_toRecover, SIGNAL(clicked()), this, SLOT(onToRecover()));
connect(_toPassword, SIGNAL(clicked()), this, SLOT(onToPassword()));
_toRecover->addClickHandler([=] { onToRecover(); });
_toPassword->addClickHandler([=] { onToPassword(); });
connect(_pwdField, SIGNAL(changed()), this, SLOT(onInputChange()));
connect(_codeField, SIGNAL(changed()), this, SLOT(onInputChange()));

View File

@ -313,9 +313,9 @@ OverlayWidget::OverlayWidget()
_controlsHideTimer.setSingleShot(true);
connect(&_controlsHideTimer, SIGNAL(timeout()), this, SLOT(onHideControls()));
connect(_docDownload, SIGNAL(clicked()), this, SLOT(onDownload()));
connect(_docSaveAs, SIGNAL(clicked()), this, SLOT(onSaveAs()));
connect(_docCancel, SIGNAL(clicked()), this, SLOT(onSaveCancel()));
_docDownload->addClickHandler([=] { onDownload(); });
_docSaveAs->addClickHandler([=] { onSaveAs(); });
_docCancel->addClickHandler([=] { onSaveCancel(); });
_dropdown->setHiddenCallback([this] { dropdownHidden(); });
_dropdownShowTimer->setSingleShot(true);

View File

@ -13,36 +13,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace MTP {
namespace internal {
bool paused();
[[nodiscard]] bool paused();
void pause();
void unpause();
} // namespace internal
class PauseHolder {
public:
PauseHolder() {
restart();
}
void restart() {
if (!std::exchange(_paused, true)) {
internal::pause();
}
}
void release() {
if (std::exchange(_paused, false)) {
internal::unpause();
}
}
~PauseHolder() {
release();
}
private:
bool _paused = false;
};
// send(MTPhelp_GetConfig(), MTP::configDcId(dc)) - for dc enumeration
constexpr ShiftedDcId configDcId(DcId dcId) {
return ShiftDcId(dcId, kConfigDcShift);

View File

@ -46,7 +46,7 @@ void BackButton::paintEvent(QPaintEvent *e) {
void BackButton::onStateChanged(State was, StateChangeSource source) {
if (isDown() && !(was & StateFlag::Down)) {
emit clicked();
clicked(Qt::KeyboardModifiers(), Qt::LeftButton);
}
}

View File

@ -38,9 +38,7 @@ protected:
int resizeGetHeight(int newWidth) override = 0;
void contentSizeUpdated() {
auto oldHeight = height();
resizeToWidth(width());
emit heightUpdated();
}
PeerData *peer() const {

View File

@ -7,8 +7,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "ui/abstract_button.h"
#include "core/application.h"
#include "ui/ui_utility.h"
#include "ui/ui_integration.h"
#include <QtGui/QtEvents>
#include <rpl/filter.h>
#include <rpl/mappers.h>
@ -71,28 +73,33 @@ void AbstractButton::mouseReleaseEvent(QMouseEvent *e) {
const auto was = _state;
_state &= ~State(StateFlag::Down);
auto weak = MakeWeak(this);
const auto weak = MakeWeak(this);
onStateChanged(was, StateChangeSource::ByPress);
if (!weak) {
return;
}
if (was & StateFlag::Over) {
_modifiers = e->modifiers();
if (const auto callback = _clickedCallback) {
callback();
} else {
emit clicked();
}
if (weak) {
_clicks.fire(e->button());
}
clicked(e->modifiers(), e->button());
} else {
setOver(false, StateChangeSource::ByHover);
}
}
}
void AbstractButton::clicked(
Qt::KeyboardModifiers modifiers,
Qt::MouseButton button) {
_modifiers = modifiers;
const auto weak = MakeWeak(this);
if (const auto callback = _clickedCallback) {
callback();
}
if (weak) {
_clicks.fire_copy(button);
}
}
void AbstractButton::setPointerCursor(bool enablePointerCursor) {
if (_enablePointerCursor != enablePointerCursor) {
_enablePointerCursor = enablePointerCursor;
@ -104,12 +111,12 @@ void AbstractButton::setOver(bool over, StateChangeSource source) {
if (over && !(_state & StateFlag::Over)) {
auto was = _state;
_state |= StateFlag::Over;
Core::App().registerLeaveSubscription(this);
RegisterLeaveSubscription(this);
onStateChanged(was, source);
} else if (!over && (_state & StateFlag::Over)) {
auto was = _state;
_state &= ~State(StateFlag::Over);
Core::App().unregisterLeaveSubscription(this);
UnregisterLeaveSubscription(this);
onStateChanged(was, source);
}
updateCursor();

View File

@ -14,8 +14,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace Ui {
class AbstractButton : public RpWidget {
Q_OBJECT
public:
AbstractButton(QWidget *parent);
@ -61,9 +59,6 @@ protected:
void mouseMoveEvent(QMouseEvent *e) override;
void mouseReleaseEvent(QMouseEvent *e) override;
signals:
void clicked();
protected:
enum class StateFlag {
None = 0,
@ -88,6 +83,8 @@ protected:
virtual void onStateChanged(State was, StateChangeSource source) {
}
void clicked(Qt::KeyboardModifiers modifiers, Qt::MouseButton button);
private:
void updateCursor();
void checkIfOver(QPoint localPos);

View File

@ -7,6 +7,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "ui/effects/animation_value.h"
#include "ui/painter.h"
#include <QtCore/QtMath> // M_PI
namespace anim {
namespace {

View File

@ -7,6 +7,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once
#include "base/basic_types.h"
#include "ui/style/style_core.h"
namespace anim {
enum class type {

View File

@ -8,7 +8,16 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/effects/animations.h"
#include "ui/ui_utility.h"
#include "core/application.h"
#include "base/invoke_queued.h"
#include <QtCore/QPointer>
#include <crl/crl_on_main.h>
#include <crl/crl.h>
#include <rpl/filter.h>
#include <range/v3/algorithm/remove_if.hpp>
#include <range/v3/algorithm/remove.hpp>
#include <range/v3/algorithm/find.hpp>
namespace Ui {
namespace Animations {
@ -17,19 +26,25 @@ namespace {
constexpr auto kAnimationTick = crl::time(1000) / 120;
constexpr auto kIgnoreUpdatesTimeout = crl::time(4);
Manager *ManagerInstance = nullptr;
} // namespace
void Basic::start() {
Expects(ManagerInstance != nullptr);
if (animating()) {
restart();
} else {
Core::App().animationManager().start(this);
ManagerInstance->start(this);
}
}
void Basic::stop() {
Expects(ManagerInstance != nullptr);
if (animating()) {
Core::App().animationManager().stop(this);
ManagerInstance->stop(this);
}
}
@ -56,6 +71,10 @@ void Basic::markStopped() {
}
Manager::Manager() {
Expects(ManagerInstance == nullptr);
ManagerInstance = this;
crl::on_main_update_requests(
) | rpl::filter([=] {
return (_lastUpdateTime + kIgnoreUpdatesTimeout < crl::now());
@ -64,6 +83,14 @@ Manager::Manager() {
}, _lifetime);
}
Manager::~Manager() {
Expects(ManagerInstance == this);
Expects(_active.empty());
Expects(_starting.empty());
ManagerInstance = nullptr;
}
void Manager::start(not_null<Basic*> animation) {
_forceImmediateUpdate = true;
if (_updating) {

View File

@ -9,6 +9,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/effects/animation_value.h"
#include <crl/crl_time.h>
#include <rpl/lifetime.h>
namespace Ui {
namespace Animations {
@ -69,6 +72,32 @@ public:
[[nodiscard]] float64 value(float64 final) const;
private:
class ShortTracker {
public:
ShortTracker() {
restart();
}
ShortTracker(const ShortTracker &other) = delete;
ShortTracker &operator=(const ShortTracker &other) = delete;
~ShortTracker() {
release();
}
void restart() {
if (!std::exchange(_paused, true)) {
style::internal::StartShortAnimation();
}
}
void release() {
if (std::exchange(_paused, false)) {
style::internal::StopShortAnimation();
}
}
private:
bool _paused = false;
};
struct Data {
explicit Data(float64 initial) : value(initial) {
}
@ -85,7 +114,7 @@ private:
float64 value = 0.;
float64 duration = 0.;
bool *markOnDelete = nullptr;
MTP::PauseHolder pause;
ShortTracker tracker;
};
template <typename Callback>
@ -106,6 +135,7 @@ private:
class Manager final : private QObject {
public:
Manager();
~Manager();
void update();
@ -326,7 +356,7 @@ inline void Simple::start(
if (!deleted) {
that->markOnDelete = nullptr;
if (!result) {
that->pause.release();
that->tracker.release();
}
}
return result;
@ -349,10 +379,10 @@ inline void Simple::prepare(float64 from, crl::time duration) {
if (!_data) {
_data = std::make_unique<Data>(from);
} else if (!isLong) {
_data->pause.restart();
_data->tracker.restart();
}
if (isLong) {
_data->pause.release();
_data->tracker.release();
}
}

View File

@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/effects/cross_animation.h"
#include "ui/effects/animation_value.h"
#include "ui/painter.h"
namespace Ui {
namespace {

View File

@ -9,6 +9,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "styles/style_widgets.h"
class Painter;
namespace Ui {
class CrossAnimation {

View File

@ -9,6 +9,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "styles/style_widgets.h"
#include <deque>
namespace Ui {
class RippleAnimation {

View File

@ -7,9 +7,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "ui/rp_widget.h"
#include "core/qt_signal_producer.h"
#include "base/qt_signal_producer.h"
#include <QtGui/QWindow>
#include <QtGui/QtEvents>
namespace Ui {
@ -89,7 +90,7 @@ rpl::producer<> RpWidgetMethods::windowDeactivateEvents() const {
const auto window = callGetWidget()->window()->windowHandle();
Assert(window != nullptr);
return Core::QtSignalProducer(
return base::qt_signal_producer(
window,
&QWindow::activeChanged
) | rpl::filter([=] {

View File

@ -15,6 +15,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include <rpl/map.h>
#include <rpl/distinct_until_changed.h>
#include <QtWidgets/QWidget>
#include <QtCore/QPointer>
class TWidget;
template <typename Base>
@ -49,13 +52,13 @@ public:
auto margins = getMargins();
x -= margins.left();
y -= margins.top();
Base::move(rtl() ? ((outerw > 0 ? outerw : Base::parentWidget()->width()) - x - Base::width()) : x, y);
Base::move(style::RightToLeft() ? ((outerw > 0 ? outerw : Base::parentWidget()->width()) - x - Base::width()) : x, y);
}
void moveToRight(int x, int y, int outerw = 0) {
auto margins = getMargins();
x -= margins.right();
y -= margins.top();
Base::move(rtl() ? x : ((outerw > 0 ? outerw : Base::parentWidget()->width()) - x - Base::width()), y);
Base::move(style::RightToLeft() ? x : ((outerw > 0 ? outerw : Base::parentWidget()->width()) - x - Base::width()), y);
}
void setGeometryToLeft(int x, int y, int w, int h, int outerw = 0) {
auto margins = getMargins();
@ -63,7 +66,7 @@ public:
y -= margins.top();
w -= margins.left() - margins.right();
h -= margins.top() - margins.bottom();
Base::setGeometry(rtl() ? ((outerw > 0 ? outerw : Base::parentWidget()->width()) - x - w) : x, y, w, h);
Base::setGeometry(style::RightToLeft() ? ((outerw > 0 ? outerw : Base::parentWidget()->width()) - x - w) : x, y, w, h);
}
void setGeometryToRight(int x, int y, int w, int h, int outerw = 0) {
auto margins = getMargins();
@ -71,7 +74,7 @@ public:
y -= margins.top();
w -= margins.left() - margins.right();
h -= margins.top() - margins.bottom();
Base::setGeometry(rtl() ? x : ((outerw > 0 ? outerw : Base::parentWidget()->width()) - x - w), y, w, h);
Base::setGeometry(style::RightToLeft() ? x : ((outerw > 0 ? outerw : Base::parentWidget()->width()) - x - w), y, w, h);
}
QPoint myrtlpoint(int x, int y) const {
return style::rtlpoint(x, y, Base::width());
@ -204,14 +207,10 @@ public:
void setVisibleTopBottom(int visibleTop, int visibleBottom) {
auto max = height();
visibleTopBottomUpdated(
snap(visibleTop, 0, max),
snap(visibleBottom, 0, max));
std::clamp(visibleTop, 0, max),
std::clamp(visibleBottom, 0, max));
}
signals:
// Child widget is responsible for emitting this signal.
void heightUpdated();
protected:
void setChildVisibleTopBottom(
TWidget *child,

View File

@ -14,6 +14,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include <QtGui/QPainter>
#include <rpl/event_stream.h>
#include <rpl/variable.h>
namespace style {
namespace internal {
namespace {
@ -22,8 +25,9 @@ constexpr auto kMinContrastAlpha = 64;
constexpr auto kMinContrastDistance = 64 * 64 * 4;
constexpr auto kContrastDeltaL = 64;
int DevicePixelRatioValue = 1;
bool RightToLeftValue = false;
auto PaletteChanges = rpl::event_stream<>();
auto ShortAnimationRunning = rpl::variable<bool>(false);
auto RunningShortAnimations = 0;
std::vector<internal::ModuleBase*> &StyleModules() {
static auto result = std::vector<internal::ModuleBase*>();
@ -42,14 +46,30 @@ void registerModule(ModuleBase *module) {
StyleModules().push_back(module);
}
} // namespace internal
bool RightToLeft() {
return internal::RightToLeftValue;
void StartShortAnimation() {
if (++RunningShortAnimations == 1) {
ShortAnimationRunning = true;
}
}
void SetRightToLeft(bool rtl) {
internal::RightToLeftValue = rtl;
void StopShortAnimation() {
if (--RunningShortAnimations == 0) {
ShortAnimationRunning = false;
}
}
} // namespace internal
rpl::producer<> PaletteChanged() {
return internal::PaletteChanges.events();
}
void NotifyPaletteChanged() {
internal::PaletteChanges.fire({});
}
rpl::producer<bool> ShortAnimationPlaying() {
return internal::ShortAnimationRunning.value();
}
void startManager(int scale) {

View File

@ -11,6 +11,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/style/style_core_types.h"
#include "ui/style/style_core_direction.h"
#include <rpl/producer.h>
namespace style {
namespace internal {
@ -26,17 +28,22 @@ public:
void registerModule(ModuleBase *module);
// This method is implemented in palette.cpp (codegen).
bool setPaletteColor(QLatin1String name, uchar r, uchar g, uchar b, uchar a);
[[nodiscard]] QColor EnsureContrast(const QColor &over, const QColor &under);
void EnsureContrast(ColorData &over, const ColorData &under);
void StartShortAnimation();
void StopShortAnimation();
} // namespace internal
void startManager(int scale);
void stopManager();
[[nodiscard]] rpl::producer<> PaletteChanged();
void NotifyPaletteChanged();
[[nodiscard]] rpl::producer<bool> ShortAnimationPlaying();
// *outResult must be r.width() x r.height(), ARGB32_Premultiplied.
// QRect(0, 0, src.width(), src.height()) must contain r.
void colorizeImage(const QImage &src, QColor c, QImage *outResult, QRect srcRect = QRect(), QPoint dstPoint = QPoint(0, 0));

View File

@ -0,0 +1,25 @@
/*
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
*/
#include "ui/style/style_core_direction.h"
namespace style {
namespace {
bool RightToLeftValue = false;
} // namespace
bool RightToLeft() {
return RightToLeftValue;
}
void SetRightToLeft(bool rtl) {
RightToLeftValue = rtl;
}
} // namespace style

View File

@ -0,0 +1,20 @@
/*
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 "base/basic_types.h"
// Methods that must be implemented outside lib_ui.
namespace Ui {
void PostponeCall(FnMut<void()> &&callable);
void RegisterLeaveSubscription(not_null<QWidget*> widget);
void UnregisterLeaveSubscription(not_null<QWidget*> widget);
} // namespace Ui

View File

@ -19,3 +19,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include <QtGui/QFontMetrics>
#include <QtWidgets/QWidget>
#include <rpl/rpl.h>
#include <range/v3/all.hpp>

View File

@ -8,6 +8,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#pragma once
#include "base/unique_qptr.h"
#include "ui/ui_integration.h"
#include <QtCore/QEvent>
template <typename Object>
class object_ptr;
@ -134,9 +137,6 @@ void RenderWidget(
void ForceFullRepaint(not_null<QWidget*> widget);
// Must be implemented outside lib_ui.
void PostponeCall(FnMut<void()> &&callable);
template <
typename Guard,
typename Callable,

View File

@ -11,9 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/effects/cross_animation.h"
#include "ui/effects/numbers_animation.h"
#include "ui/image/image_prepare.h"
#include "window/themes/window_theme.h"
#include "lang/lang_instance.h"
#include "app.h"
#include "ui/painter.h"
namespace Ui {
@ -91,13 +89,11 @@ void RippleButton::setForceRippled(
if (_forceRippled != rippled) {
_forceRippled = rippled;
if (_forceRippled) {
_forceRippledSubscription = base::ObservableViewer(
*Window::Theme::Background()
) | rpl::start_with_next([=](
const Window::Theme::BackgroundUpdate &update) {
if (update.paletteChanged() && _ripple) {
_ripple->forceRepaint();
}
_forceRippledSubscription = style::PaletteChanged(
) | rpl::filter([=] {
return _ripple != nullptr;
}) | rpl::start_with_next([=] {
_ripple->forceRepaint();
});
ensureRipple();
if (_ripple->empty()) {
@ -350,7 +346,12 @@ void RoundButton::paintEvent(QPaintEvent *e) {
p.setBrush(color);
p.drawRoundedRect(fill, radius, radius);
} else {
App::roundRect(p, fill, color, ImageRoundRadius::Small);
PainterHighQualityEnabler hq(p);
p.setPen(Qt::NoPen);
p.setBrush(color);
p.drawRoundedRect(fill, st::buttonRadius, st::buttonRadius);
// #TODO ui
//App::roundRect(p, fill, color, ImageRoundRadius::Small);
}
};
drawRect(_st.textBg);

View File

@ -101,7 +101,7 @@ private:
};
class RoundButton : public RippleButton, private base::Subscriber {
class RoundButton : public RippleButton {
public:
RoundButton(
QWidget *parent,

View File

@ -13,7 +13,7 @@ namespace Ui {
DropdownMenu::DropdownMenu(QWidget *parent, const style::DropdownMenu &st) : InnerDropdown(parent, st.wrap)
, _st(st) {
_menu = setOwnedWidget(object_ptr<Ui::Menu>(this, _st.menu));
_menu = setOwnedWidget(object_ptr<Menu>(this, _st.menu));
init();
}

View File

@ -52,10 +52,18 @@ InnerDropdown::InnerDropdown(
}, lifetime());
}
QPointer<TWidget> InnerDropdown::doSetOwnedWidget(object_ptr<TWidget> widget) {
auto result = QPointer<TWidget>(widget);
connect(widget, SIGNAL(heightUpdated()), this, SLOT(onWidgetHeightUpdated()));
auto container = _scroll->setOwnedWidget(object_ptr<Container>(_scroll, std::move(widget), _st));
QPointer<RpWidget> InnerDropdown::doSetOwnedWidget(
object_ptr<RpWidget> widget) {
auto result = QPointer<RpWidget>(widget);
widget->heightValue(
) | rpl::skip(1) | rpl::start_with_next([=] {
resizeToContent();
}, widget->lifetime());
auto container = _scroll->setOwnedWidget(
object_ptr<Container>(
_scroll,
std::move(widget),
_st));
container->resizeToWidth(_scroll->width());
container->moveToLeft(0, 0);
container->show();

View File

@ -86,12 +86,9 @@ private slots:
hideAnimated();
}
void onScroll();
void onWidgetHeightUpdated() {
resizeToContent();
}
private:
QPointer<TWidget> doSetOwnedWidget(object_ptr<TWidget> widget);
QPointer<RpWidget> doSetOwnedWidget(object_ptr<RpWidget> widget);
QImage grabForPanelAnimation();
void startShowAnimation();
void startOpacityAnimation(bool hiding);

View File

@ -24,14 +24,16 @@ struct Menu::ActionData {
bool hasSubmenu = false;
};
Menu::Menu(QWidget *parent, const style::Menu &st) : TWidget(parent)
Menu::Menu(QWidget *parent, const style::Menu &st)
: RpWidget(parent)
, _st(st)
, _itemHeight(_st.itemPadding.top() + _st.itemStyle.font->height + _st.itemPadding.bottom())
, _separatorHeight(_st.separatorPadding.top() + _st.separatorWidth + _st.separatorPadding.bottom()) {
init();
}
Menu::Menu(QWidget *parent, QMenu *menu, const style::Menu &st) : TWidget(parent)
Menu::Menu(QWidget *parent, QMenu *menu, const style::Menu &st)
: RpWidget(parent)
, _st(st)
, _wappedMenu(menu)
, _itemHeight(_st.itemPadding.top() + _st.itemStyle.font->height + _st.itemPadding.bottom())
@ -68,7 +70,9 @@ not_null<QAction*> Menu::addAction(const QString &text, Fn<void()> callback, con
}
not_null<QAction*> Menu::addAction(not_null<QAction*> action, const style::icon *icon, const style::icon *iconOver) {
connect(action, SIGNAL(changed()), this, SLOT(actionChanged()));
connect(action, &QAction::changed, this, [=] {
actionChanged();
});
_actions.emplace_back(action);
_actionsData.push_back([&] {
auto data = ActionData();

View File

@ -17,9 +17,7 @@ namespace Ui {
class ToggleView;
class RippleAnimation;
class Menu : public TWidget {
Q_OBJECT
class Menu : public RpWidget {
public:
Menu(QWidget *parent, const style::Menu &st = st::defaultMenu);
Menu(QWidget *parent, QMenu *menu, const style::Menu &st = st::defaultMenu);
@ -85,13 +83,11 @@ protected:
void enterEventHook(QEvent *e) override;
void leaveEventHook(QEvent *e) override;
private slots:
void actionChanged();
private:
struct ActionData;
void updateSelected(QPoint globalPosition);
void actionChanged();
void init();
// Returns the new width.

View File

@ -9,12 +9,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "mainwindow.h"
#include "platform/platform_specific.h"
#include "core/qt_signal_producer.h"
#include "ui/ui_utility.h"
#include "app.h"
#include "styles/style_widgets.h"
#include <QtCore/QCoreApplication>
#include <QtWidgets/QApplication>
#include <QtWidgets/QDesktopWidget>
namespace Ui {

View File

@ -519,6 +519,12 @@ ChatBackground::ChatBackground() : _adjustableColors({
st::historyScrollBarBg,
st::historyScrollBarBgOver }) {
saveAdjustableColors();
subscribe(this, [=](const BackgroundUpdate &update) {
if (update.paletteChanged()) {
style::NotifyPaletteChanged();
}
});
}
void ChatBackground::setThemeData(QImage &&themeImage, bool themeTile) {

View File

@ -20,7 +20,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "storage/localstorage.h"
#include "support/support_templates.h"
#include "settings/settings_common.h"
#include "core/qt_signal_producer.h"
#include "base/qt_signal_producer.h"
#include "boxes/about_box.h"
#include "boxes/peer_list_controllers.h"
#include "calls/calls_box_controller.h"
@ -469,7 +469,7 @@ void MainMenu::initResetScaleButton() {
rpl::single(
handle->screen()
) | rpl::then(
Core::QtSignalProducer(handle, &QWindow::screenChanged)
base::qt_signal_producer(handle, &QWindow::screenChanged)
) | rpl::filter([](QScreen *screen) {
return screen != nullptr;
}) | rpl::map([](QScreen * screen) {
@ -477,9 +477,9 @@ void MainMenu::initResetScaleButton() {
screen->availableGeometry()
) | rpl::then(
#ifdef OS_MAC_OLD
Core::QtSignalProducer(screen, &QScreen::virtualGeometryChanged)
base::qt_signal_producer(screen, &QScreen::virtualGeometryChanged)
#else // OS_MAC_OLD
Core::QtSignalProducer(screen, &QScreen::availableGeometryChanged)
base::qt_signal_producer(screen, &QScreen::availableGeometryChanged)
#endif // OS_MAC_OLD
);
}) | rpl::flatten_latest(

View File

@ -45,6 +45,7 @@
'sources': [
'<(src_loc)/base/algorithm.h',
'<(src_loc)/base/assertion.h',
'<(src_loc)/base/base_integration.h',
'<(src_loc)/base/basic_types.h',
'<(src_loc)/base/binary_guard.h',
'<(src_loc)/base/build_config.h',
@ -72,6 +73,7 @@
'<(src_loc)/base/qthelp_regex.h',
'<(src_loc)/base/qthelp_url.cpp',
'<(src_loc)/base/qthelp_url.h',
'<(src_loc)/base/qt_signal_producer.h',
'<(src_loc)/base/runtime_composer.cpp',
'<(src_loc)/base/runtime_composer.h',
'<(src_loc)/base/thread_safe_wrap.h',

View File

@ -15,7 +15,6 @@
'includes': [
'common.gypi',
'qt.gypi',
'qt_moc.gypi',
'codegen_styles_rule.gypi',
'codegen_rules_ui.gypi',
'pch.gypi',
@ -59,10 +58,16 @@
],
'sources': [
'<@(style_files)',
'<(src_loc)/ui/effects/animation_value.cpp',
'<(src_loc)/ui/effects/animation_value.h',
'<(src_loc)/ui/effects/animations.cpp',
'<(src_loc)/ui/effects/animations.h',
'<(src_loc)/ui/style/style_core.cpp',
'<(src_loc)/ui/style/style_core.h',
'<(src_loc)/ui/style/style_core_color.cpp',
'<(src_loc)/ui/style/style_core_color.h',
'<(src_loc)/ui/style/style_core_direction.cpp',
'<(src_loc)/ui/style/style_core_direction.h',
'<(src_loc)/ui/style/style_core_font.cpp',
'<(src_loc)/ui/style/style_core_font.h',
'<(src_loc)/ui/style/style_core_icon.cpp',
@ -71,7 +76,13 @@
'<(src_loc)/ui/style/style_core_scale.h',
'<(src_loc)/ui/style/style_core_types.cpp',
'<(src_loc)/ui/style/style_core_types.h',
'<(src_loc)/ui/widgets/buttons.cpp',
'<(src_loc)/ui/widgets/buttons.h',
'<(src_loc)/ui/abstract_button.cpp',
'<(src_loc)/ui/abstract_button.h',
'<(src_loc)/ui/painter.h',
'<(src_loc)/ui/ui_integration.h',
'<(src_loc)/ui/ui_utility.h',
'<(emoji_suggestions_loc)/emoji_suggestions.cpp',
'<(emoji_suggestions_loc)/emoji_suggestions.h',
],

View File

@ -164,7 +164,6 @@
<(src_loc)/core/media_active_cache.h
<(src_loc)/core/mime_type.cpp
<(src_loc)/core/mime_type.h
<(src_loc)/core/qt_signal_producer.h
<(src_loc)/core/sandbox.cpp
<(src_loc)/core/sandbox.h
<(src_loc)/core/shortcuts.cpp
@ -736,10 +735,6 @@
<(src_loc)/support/support_helper.h
<(src_loc)/support/support_templates.cpp
<(src_loc)/support/support_templates.h
<(src_loc)/ui/effects/animation_value.cpp
<(src_loc)/ui/effects/animation_value.h
<(src_loc)/ui/effects/animations.cpp
<(src_loc)/ui/effects/animations.h
<(src_loc)/ui/effects/cross_animation.cpp
<(src_loc)/ui/effects/cross_animation.h
<(src_loc)/ui/effects/fade_animation.cpp
@ -781,8 +776,6 @@
<(src_loc)/ui/toast/toast_manager.h
<(src_loc)/ui/toast/toast_widget.cpp
<(src_loc)/ui/toast/toast_widget.h
<(src_loc)/ui/widgets/buttons.cpp
<(src_loc)/ui/widgets/buttons.h
<(src_loc)/ui/widgets/checkbox.cpp
<(src_loc)/ui/widgets/checkbox.h
<(src_loc)/ui/widgets/continuous_sliders.cpp
@ -822,8 +815,6 @@
<(src_loc)/ui/wrap/vertical_layout.cpp
<(src_loc)/ui/wrap/vertical_layout.h
<(src_loc)/ui/wrap/wrap.h
<(src_loc)/ui/abstract_button.cpp
<(src_loc)/ui/abstract_button.h
<(src_loc)/ui/countryinput.cpp
<(src_loc)/ui/countryinput.h
<(src_loc)/ui/emoji_config.cpp