2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 06:35:14 +00:00

Make tabbed selector working in scheduled section.

This commit is contained in:
John Preston
2019-08-16 15:44:20 +03:00
parent 385a7eb00d
commit 3e895d0e85
27 changed files with 341 additions and 250 deletions

View File

@@ -1574,6 +1574,8 @@ int StickersListWidget::megagroupSetInfoLeft() const {
}
void StickersListWidget::paintMegagroupEmptySet(Painter &p, int y, bool buttonSelected) {
p.setPen(st::emojiPanHeaderFg);
auto infoLeft = megagroupSetInfoLeft();
_megagroupSetAbout.drawLeft(p, infoLeft, y, width() - infoLeft, width());

View File

@@ -26,20 +26,27 @@ constexpr auto kDelayedHideTimeoutMs = 3000;
TabbedPanel::TabbedPanel(
QWidget *parent,
not_null<Window::SessionController*> controller)
: TabbedPanel(
parent,
controller,
object_ptr<TabbedSelector>(nullptr, controller)) {
not_null<Window::SessionController*> controller,
not_null<TabbedSelector*> selector)
: TabbedPanel(parent, controller, { nullptr }, selector) {
}
TabbedPanel::TabbedPanel(
QWidget *parent,
not_null<Window::SessionController*> controller,
object_ptr<TabbedSelector> selector)
: TabbedPanel(parent, controller, std::move(selector), nullptr) {
}
TabbedPanel::TabbedPanel(
QWidget *parent,
not_null<Window::SessionController*> controller,
object_ptr<TabbedSelector> ownedSelector,
TabbedSelector *nonOwnedSelector)
: RpWidget(parent)
, _controller(controller)
, _selector(std::move(selector))
, _ownedSelector(std::move(ownedSelector))
, _selector(nonOwnedSelector ? nonOwnedSelector : _ownedSelector.data())
, _heightRatio(st::emojiPanHeightRatio)
, _minContentHeight(st::emojiPanMinHeight)
, _maxContentHeight(st::emojiPanMaxHeight) {
@@ -106,6 +113,14 @@ TabbedPanel::TabbedPanel(
hide();
}
not_null<TabbedSelector*> TabbedPanel::selector() const {
return _selector;
}
bool TabbedPanel::isSelectorStolen() const {
return (_selector->parent() != this);
}
void TabbedPanel::moveBottomRight(int bottom, int right) {
const auto isNew = (_bottom != bottom || _right != right);
_bottom = bottom;
@@ -366,17 +381,6 @@ void TabbedPanel::toggleAnimated() {
}
}
object_ptr<TabbedSelector> TabbedPanel::takeSelector() {
if (!isHidden() && !_hiding) {
startOpacityAnimation(true);
}
return std::move(_selector);
}
QPointer<TabbedSelector> TabbedPanel::getSelector() const {
return _selector.data();
}
void TabbedPanel::hideFinished() {
hide();
_a_show.stop();
@@ -450,6 +454,10 @@ bool TabbedPanel::overlaps(const QRect &globalRect) const {
|| inner.marginsRemoved(QMargins(0, st::buttonRadius, 0, st::buttonRadius)).contains(testRect);
}
TabbedPanel::~TabbedPanel() = default;
TabbedPanel::~TabbedPanel() {
if (!_ownedSelector) {
_controller->takeTabbedSelectorOwnershipFrom(this);
}
}
} // namespace ChatHelpers

View File

@@ -27,14 +27,16 @@ class TabbedPanel : public Ui::RpWidget {
public:
TabbedPanel(
QWidget *parent,
not_null<Window::SessionController*> controller);
not_null<Window::SessionController*> controller,
not_null<TabbedSelector*> selector);
TabbedPanel(
QWidget *parent,
not_null<Window::SessionController*> controller,
object_ptr<TabbedSelector> selector);
object_ptr<TabbedSelector> takeSelector();
QPointer<TabbedSelector> getSelector() const;
[[nodiscard]] bool isSelectorStolen() const;
[[nodiscard]] not_null<TabbedSelector*> selector() const;
void moveBottomRight(int bottom, int right);
void setDesiredHeightValues(
float64 ratio,
@@ -64,6 +66,12 @@ protected:
bool eventFilter(QObject *obj, QEvent *e) override;
private:
TabbedPanel(
QWidget *parent,
not_null<Window::SessionController*> controller,
object_ptr<TabbedSelector> ownedSelector,
TabbedSelector *nonOwnedSelector);
void hideByTimerOrLeave();
void moveByBottom();
bool isDestroying() const {
@@ -89,8 +97,9 @@ private:
bool preventAutoHide() const;
void updateContentHeight();
not_null<Window::SessionController*> _controller;
object_ptr<TabbedSelector> _selector;
const not_null<Window::SessionController*> _controller;
const object_ptr<TabbedSelector> _ownedSelector = { nullptr };
const not_null<TabbedSelector*> _selector;
int _contentMaxHeight = 0;
int _contentHeight = 0;

View File

@@ -7,56 +7,27 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "chat_helpers/tabbed_section.h"
#include "styles/style_chat_helpers.h"
#include "chat_helpers/tabbed_selector.h"
#include "window/window_session_controller.h"
#include "styles/style_chat_helpers.h"
namespace ChatHelpers {
TabbedMemento::TabbedMemento(
object_ptr<TabbedSelector> selector,
Fn<void(object_ptr<TabbedSelector>)> returnMethod)
: _selector(std::move(selector))
, _returnMethod(std::move(returnMethod)) {
}
object_ptr<Window::SectionWidget> TabbedMemento::createWidget(
QWidget *parent,
not_null<Window::SessionController*> controller,
Window::Column column,
const QRect &geometry) {
auto result = object_ptr<TabbedSection>(
parent,
controller,
std::move(_selector),
std::move(_returnMethod));
auto result = object_ptr<TabbedSection>(parent, controller);
result->setGeometry(geometry);
return std::move(result);
}
TabbedMemento::~TabbedMemento() {
if (_returnMethod && _selector) {
_returnMethod(std::move(_selector));
}
}
TabbedSection::TabbedSection(
QWidget *parent,
not_null<Window::SessionController*> controller)
: TabbedSection(
parent,
controller,
object_ptr<TabbedSelector>(this, controller),
Fn<void(object_ptr<TabbedSelector>)>()) {
}
TabbedSection::TabbedSection(
QWidget *parent,
not_null<Window::SessionController*> controller,
object_ptr<TabbedSelector> selector,
Fn<void(object_ptr<TabbedSelector>)> returnMethod)
: Window::SectionWidget(parent, controller)
, _selector(std::move(selector))
, _returnMethod(std::move(returnMethod)) {
, _selector(controller->tabbedSelector()) {
_selector->setParent(this);
_selector->setRoundRadius(0);
_selector->setGeometry(rect());
@@ -80,14 +51,6 @@ void TabbedSection::resizeEvent(QResizeEvent *e) {
_selector->setGeometry(rect());
}
object_ptr<TabbedSelector> TabbedSection::takeSelector() {
_selector->beforeHiding();
return std::move(_selector);
}
QPointer<TabbedSelector> TabbedSection::getSelector() const {
return _selector.data();
}
bool TabbedSection::showInternal(
not_null<Window::SectionMemento*> memento,
const Window::SectionShow &params) {
@@ -104,9 +67,7 @@ QRect TabbedSection::rectForFloatPlayer() const {
TabbedSection::~TabbedSection() {
beforeHiding();
if (_returnMethod) {
_returnMethod(takeSelector());
}
controller()->takeTabbedSelectorOwnershipFrom(this);
}
} // namespace ChatHelpers

View File

@@ -16,9 +16,7 @@ class TabbedSelector;
class TabbedMemento : public Window::SectionMemento {
public:
TabbedMemento(
object_ptr<TabbedSelector> selector,
Fn<void(object_ptr<TabbedSelector>)> returnMethod);
TabbedMemento() = default;
TabbedMemento(TabbedMemento &&other) = default;
TabbedMemento &operator=(TabbedMemento &&other) = default;
@@ -28,12 +26,6 @@ public:
Window::Column column,
const QRect &geometry) override;
~TabbedMemento();
private:
object_ptr<TabbedSelector> _selector;
Fn<void(object_ptr<TabbedSelector>)> _returnMethod;
};
class TabbedSection : public Window::SectionWidget {
@@ -41,18 +33,10 @@ public:
TabbedSection(
QWidget *parent,
not_null<Window::SessionController*> controller);
TabbedSection(
QWidget *parent,
not_null<Window::SessionController*> controller,
object_ptr<TabbedSelector> selector,
Fn<void(object_ptr<TabbedSelector>)> returnMethod);
void beforeHiding();
void afterShown();
object_ptr<TabbedSelector> takeSelector();
QPointer<TabbedSelector> getSelector() const;
bool showInternal(
not_null<Window::SectionMemento*> memento,
const Window::SectionShow &params) override;
@@ -73,8 +57,7 @@ protected:
}
private:
object_ptr<TabbedSelector> _selector;
Fn<void(object_ptr<TabbedSelector>)> _returnMethod;
const not_null<TabbedSelector*> _selector;
};

View File

@@ -11,7 +11,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "chat_helpers/stickers_list_widget.h"
#include "chat_helpers/gifs_list_widget.h"
#include "chat_helpers/stickers.h"
#include "styles/style_chat_helpers.h"
#include "ui/widgets/buttons.h"
#include "ui/widgets/labels.h"
#include "ui/widgets/shadow.h"
@@ -21,10 +20,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "window/window_session_controller.h"
#include "storage/localstorage.h"
#include "data/data_channel.h"
#include "data/data_session.h"
#include "lang/lang_keys.h"
#include "mainwindow.h"
#include "observer_peer.h"
#include "apiwrap.h"
#include "styles/style_chat_helpers.h"
namespace ChatHelpers {
@@ -291,8 +292,8 @@ TabbedSelector::TabbedSelector(
createTab(SelectorTab::Gifs),
} }
, _currentTabType(full()
? session().settings().selectorTab()
: SelectorTab::Emoji) {
? session().settings().selectorTab()
: SelectorTab::Emoji) {
resize(st::emojiPanWidth, st::emojiPanMaxHeight);
for (auto &tab : _tabs) {
@@ -364,10 +365,16 @@ TabbedSelector::TabbedSelector(
stickers()->showStickerSet(setId);
_showRequests.fire({});
}, lifetime());
session().data().stickersUpdated(
) | rpl::start_with_next([=] {
refreshStickers();
}, lifetime());
}
//setAttribute(Qt::WA_AcceptTouchEvents);
setAttribute(Qt::WA_OpaquePaintEvent, false);
showAll();
hide();
}
TabbedSelector::~TabbedSelector() = default;
@@ -651,13 +658,6 @@ void TabbedSelector::afterShown() {
}
}
void TabbedSelector::showMegagroupSet(ChannelData *megagroup) {
if (!full()) {
return;
}
stickers()->showMegagroupSet(megagroup);
}
void TabbedSelector::setCurrentPeer(PeerData *peer) {
if (!full()) {
return;
@@ -665,6 +665,7 @@ void TabbedSelector::setCurrentPeer(PeerData *peer) {
gifs()->setInlineQueryPeer(peer);
_currentPeer = peer;
checkRestrictedPeer();
stickers()->showMegagroupSet(peer ? peer->asMegagroup() : nullptr);
}
void TabbedSelector::checkRestrictedPeer() {

View File

@@ -70,7 +70,6 @@ public:
void setRoundRadius(int radius);
void refreshStickers();
void showMegagroupSet(ChannelData *megagroup);
void setCurrentPeer(PeerData *peer);
void hideFinished();