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

Move third column from HistoryWidget to MainWidget.

This commit is contained in:
John Preston
2017-09-16 19:53:41 +03:00
parent f162462111
commit 5e7aa4ff81
63 changed files with 1187 additions and 752 deletions

View File

@@ -304,7 +304,7 @@ void EmojiColorPicker::drawVariant(Painter &p, int variant) {
EmojiListWidget::EmojiListWidget(QWidget *parent, not_null<Window::Controller*> controller) : Inner(parent, controller)
, _picker(this) {
resize(st::emojiPanWidth - st::emojiScroll.width - st::buttonRadius, countHeight());
updateSize();
setMouseTracking(true);
setAttribute(Qt::WA_OpaquePaintEvent);
@@ -381,7 +381,7 @@ EmojiListWidget::SectionInfo EmojiListWidget::sectionInfoByOffset(int yOffset) c
return result;
}
int EmojiListWidget::countHeight() {
int EmojiListWidget::countDesiredHeight() {
return sectionInfo(kEmojiSectionCount - 1).rowsBottom + st::emojiPanPadding;
}
@@ -648,11 +648,7 @@ void EmojiListWidget::refreshRecent() {
clearSelection();
_emoji[0] = Ui::Emoji::GetSection(Section::Recent);
_counts[0] = _emoji[0].size();
auto h = countHeight();
if (h != height()) {
resize(width(), h);
update();
}
updateSize();
}
bool EmojiListWidget::event(QEvent *e) {

View File

@@ -126,7 +126,7 @@ protected:
TabbedSelector::InnerFooter *getFooter() const override;
void processHideFinished() override;
int countHeight() override;
int countDesiredHeight() override;
private:
class Footer;

View File

@@ -122,7 +122,7 @@ void GifsListWidget::Footer::processPanelHideFinished() {
GifsListWidget::GifsListWidget(QWidget *parent, not_null<Window::Controller*> controller) : Inner(parent, controller)
, _section(Section::Gifs) {
resize(st::emojiPanWidth - st::emojiScroll.width - st::buttonRadius, countHeight());
updateSize();
setMouseTracking(true);
setAttribute(Qt::WA_OpaquePaintEvent);
@@ -174,17 +174,12 @@ void GifsListWidget::checkLoadMore() {
}
}
int GifsListWidget::countHeight() {
auto visibleHeight = getVisibleBottom() - getVisibleTop();
if (visibleHeight <= 0) {
visibleHeight = st::emojiPanMaxHeight - st::emojiCategory.height;
}
auto minimalLastHeight = (visibleHeight - st::stickerPanPadding);
int GifsListWidget::countDesiredHeight() {
auto result = st::stickerPanPadding;
for (int i = 0, l = _rows.count(); i < l; ++i) {
result += _rows[i].height;
}
return qMax(minimalLastHeight, result) + st::stickerPanPadding;
return result + st::stickerPanPadding;
}
GifsListWidget::~GifsListWidget() {
@@ -475,11 +470,7 @@ void GifsListWidget::refreshSavedGifs() {
}
deleteUnusedGifLayouts();
auto newHeight = countHeight();
if (newHeight != height()) {
resize(width(), newHeight);
}
updateSize();
update();
}
@@ -642,8 +633,7 @@ int GifsListWidget::refreshInlineRows(const InlineCacheEntry *entry, bool result
inlineRowFinalize(row, sumWidth, true);
}
int32 h = countHeight();
if (h != height()) resize(width(), h);
updateSize();
update();
_lastMousePos = QCursor::pos();

View File

@@ -82,7 +82,7 @@ protected:
TabbedSelector::InnerFooter *getFooter() const override;
void processHideFinished() override;
void processPanelHideFinished() override;
int countHeight() override;
int countDesiredHeight() override;
private slots:
void onPreview();

View File

@@ -262,7 +262,7 @@ void SetIsFaved(not_null<DocumentData*> document, base::optional<std::vector<not
}
Local::writeFavedStickers();
Auth().data().stickersUpdated().notify(true);
App::main()->onStickersInstalled(FavedSetId);
Auth().api().stickerSetInstalled(FavedSetId);
}
void RequestSetToPushFaved(not_null<DocumentData*> document) {

View File

@@ -440,7 +440,7 @@ StickersListWidget::StickersListWidget(QWidget *parent, not_null<Window::Control
, _addText(lang(lng_stickers_featured_add).toUpper())
, _addWidth(st::stickersTrendingAdd.font->width(_addText))
, _settings(this, lang(lng_stickers_you_have)) {
resize(st::emojiPanWidth - st::emojiScroll.width - st::buttonRadius, countHeight());
updateSize();
setMouseTracking(true);
setAttribute(Qt::WA_OpaquePaintEvent);
@@ -559,11 +559,8 @@ StickersListWidget::SectionInfo StickersListWidget::sectionInfoByOffset(int yOff
return result;
}
int StickersListWidget::countHeight() {
auto visibleHeight = getVisibleBottom() - getVisibleTop();
if (visibleHeight <= 0) {
visibleHeight = st::emojiPanMaxHeight - st::emojiCategory.height;
}
int StickersListWidget::countDesiredHeight() {
auto visibleHeight = minimalHeight();
auto minimalLastHeight = (visibleHeight - st::stickerPanPadding);
auto countResult = [this, minimalLastHeight] {
if (_section == Section::Featured) {
@@ -1154,10 +1151,7 @@ void StickersListWidget::refreshStickers() {
appendSet(_featuredSets, setId, AppendSkip::Installed);
}
auto newHeight = countHeight();
if (newHeight != height()) {
resize(width(), newHeight);
}
updateSize();
if (_footer) {
_footer->refreshIcons(ValidateIconAnimations::None);
@@ -1283,12 +1277,7 @@ void StickersListWidget::refreshRecentStickers(bool performResize) {
}
if (performResize && (_section == Section::Stickers || _section == Section::Featured)) {
int32 h = countHeight();
if (h != height()) {
resize(width(), h);
update();
}
updateSize();
updateSelected();
}
}

View File

@@ -79,7 +79,7 @@ protected:
TabbedSelector::InnerFooter *getFooter() const override;
void processHideFinished() override;
void processPanelHideFinished() override;
int countHeight() override;
int countDesiredHeight() override;
private slots:
void onSettings();

View File

@@ -34,10 +34,20 @@ constexpr auto kDelayedHideTimeoutMs = 3000;
} // namespace
TabbedPanel::TabbedPanel(QWidget *parent, not_null<Window::Controller*> controller) : TabbedPanel(parent, controller, object_ptr<TabbedSelector>(nullptr, controller)) {
TabbedPanel::TabbedPanel(
QWidget *parent,
not_null<Window::Controller*> controller)
: TabbedPanel(
parent,
controller,
object_ptr<TabbedSelector>(nullptr, controller)) {
}
TabbedPanel::TabbedPanel(QWidget *parent, not_null<Window::Controller*> controller, object_ptr<TabbedSelector> selector) : TWidget(parent)
TabbedPanel::TabbedPanel(
QWidget *parent,
not_null<Window::Controller*> controller,
object_ptr<TabbedSelector> selector)
: RpWidget(parent)
, _controller(controller)
, _selector(std::move(selector)) {
_selector->setParent(this);
@@ -52,6 +62,9 @@ TabbedPanel::TabbedPanel(QWidget *parent, not_null<Window::Controller*> controll
_controller->disableGifPauseReason(Window::GifPauseReason::SavedGifs);
}
});
_selector->showRequests()
| rpl::on_next([this](auto&&) { showFromSelector(); })
| rpl::start(lifetime());
resize(QRect(0, 0, st::emojiPanWidth, st::emojiPanMaxHeight).marginsAdded(innerPadding()).size());
@@ -376,11 +389,7 @@ bool TabbedPanel::eventFilter(QObject *obj, QEvent *e) {
return false;
}
void TabbedPanel::stickersInstalled(uint64 setId) {
if (isDestroying()) {
return;
}
_selector->stickersInstalled(setId);
void TabbedPanel::showFromSelector() {
if (isHidden()) {
moveByBottom();
startShowAnimation();

View File

@@ -20,7 +20,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
*/
#pragma once
#include "ui/twidget.h"
#include "ui/rp_widget.h"
#include "base/timer.h"
namespace Window {
@@ -35,7 +35,7 @@ namespace ChatHelpers {
class TabbedSelector;
class TabbedPanel : public TWidget {
class TabbedPanel : public Ui::RpWidget{
Q_OBJECT
public:
@@ -51,8 +51,6 @@ public:
return _hiding || _hideTimer.isActive();
}
void stickersInstalled(uint64 setId);
bool overlaps(const QRect &globalRect) const;
void showAnimated();
@@ -79,6 +77,7 @@ private:
bool isDestroying() const {
return !_selector;
}
void showFromSelector();
style::margins innerPadding() const;

View File

@@ -25,11 +25,49 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
namespace ChatHelpers {
TabbedSection::TabbedSection(QWidget *parent, not_null<Window::Controller*> controller) : TabbedSection(parent, controller, object_ptr<TabbedSelector>(this, controller)) {
TabbedMemento::TabbedMemento(
object_ptr<TabbedSelector> selector,
base::lambda<void(object_ptr<TabbedSelector>)> returnMethod)
: _selector(std::move(selector))
, _returnMethod(std::move(returnMethod)) {
}
TabbedSection::TabbedSection(QWidget *parent, not_null<Window::Controller*> controller, object_ptr<TabbedSelector> selector) : Window::AbstractSectionWidget(parent, controller)
, _selector(std::move(selector)) {
object_ptr<Window::SectionWidget> TabbedMemento::createWidget(
QWidget *parent,
not_null<Window::Controller*> controller,
Window::Column column,
const QRect &geometry) {
return object_ptr<TabbedSection>(
parent,
controller,
std::move(_selector),
std::move(_returnMethod));
}
TabbedMemento::~TabbedMemento() {
if (_returnMethod && _selector) {
_returnMethod(std::move(_selector));
}
}
TabbedSection::TabbedSection(
QWidget *parent,
not_null<Window::Controller*> controller)
: TabbedSection(
parent,
controller,
object_ptr<TabbedSelector>(this, controller),
base::lambda<void(object_ptr<TabbedSelector>)>()) {
}
TabbedSection::TabbedSection(
QWidget *parent,
not_null<Window::Controller*> controller,
object_ptr<TabbedSelector> selector,
base::lambda<void(object_ptr<TabbedSelector>)> returnMethod)
: Window::SectionWidget(parent, controller)
, _selector(std::move(selector))
, _returnMethod(std::move(returnMethod)) {
resize(st::emojiPanWidth, st::emojiPanMaxHeight);
_selector->setParent(this);
@@ -68,17 +106,24 @@ object_ptr<TabbedSelector> TabbedSection::takeSelector() {
QPointer<TabbedSelector> TabbedSection::getSelector() const {
return _selector.data();
}
void TabbedSection::stickersInstalled(uint64 setId) {
_selector->stickersInstalled(setId);
bool TabbedSection::showInternal(
not_null<Window::SectionMemento*> memento) {
return false;
}
bool TabbedSection::wheelEventFromFloatPlayer(QEvent *e, Window::Column myColumn, Window::Column playerColumn) {
bool TabbedSection::wheelEventFromFloatPlayer(QEvent *e) {
return _selector->wheelEventFromFloatPlayer(e);
}
QRect TabbedSection::rectForFloatPlayer(Window::Column myColumn, Window::Column playerColumn) const {
QRect TabbedSection::rectForFloatPlayer() const {
return _selector->rectForFloatPlayer();
}
TabbedSection::~TabbedSection() {
beforeHiding();
if (_returnMethod) {
_returnMethod(takeSelector());
}
}
} // namespace ChatHelpers

View File

@@ -21,15 +21,42 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
#pragma once
#include "window/section_widget.h"
#include "window/section_memento.h"
namespace ChatHelpers {
class TabbedSelector;
class TabbedSection : public Window::AbstractSectionWidget {
class TabbedMemento : public Window::SectionMemento {
public:
TabbedSection(QWidget *parent, not_null<Window::Controller*> controller);
TabbedSection(QWidget *parent, not_null<Window::Controller*> controller, object_ptr<TabbedSelector> selector);
TabbedMemento(
object_ptr<TabbedSelector> selector,
base::lambda<void(object_ptr<TabbedSelector>)> returnMethod);
object_ptr<Window::SectionWidget> createWidget(
QWidget *parent,
not_null<Window::Controller*> controller,
Window::Column column,
const QRect &geometry) override;
~TabbedMemento();
private:
object_ptr<TabbedSelector> _selector;
base::lambda<void(object_ptr<TabbedSelector>)> _returnMethod;
};
class TabbedSection : public Window::SectionWidget {
public:
TabbedSection(
QWidget *parent,
not_null<Window::Controller*> controller);
TabbedSection(
QWidget *parent,
not_null<Window::Controller*> controller,
object_ptr<TabbedSelector> selector,
base::lambda<void(object_ptr<TabbedSelector>)> returnMethod);
void beforeHiding();
void afterShown();
@@ -40,18 +67,28 @@ public:
object_ptr<TabbedSelector> takeSelector();
QPointer<TabbedSelector> getSelector() const;
void stickersInstalled(uint64 setId);
bool showInternal(
not_null<Window::SectionMemento*> memento) override;
bool forceAnimateBack() const override {
return true;
}
// Float player interface.
bool wheelEventFromFloatPlayer(QEvent *e, Window::Column myColumn, Window::Column playerColumn) override;
QRect rectForFloatPlayer(Window::Column myColumn, Window::Column playerColumn) const override;
bool wheelEventFromFloatPlayer(QEvent *e) override;
QRect rectForFloatPlayer() const override;
~TabbedSection();
protected:
void resizeEvent(QResizeEvent *e) override;
void showFinishedHook() override {
afterShown();
}
private:
object_ptr<TabbedSelector> _selector;
base::lambda<void()> _cancelledCallback;
base::lambda<void(object_ptr<TabbedSelector>)> _returnMethod;
};

View File

@@ -346,6 +346,14 @@ TabbedSelector::TabbedSelector(QWidget *parent, not_null<Window::Controller*> co
}
}));
Auth().api().stickerSetInstalled()
| rpl::on_next([this](uint64 setId) {
_tabsSlider->setActiveSection(static_cast<int>(SelectorTab::Stickers));
stickers()->showStickerSet(setId);
_showRequests.fire({});
})
| rpl::start(lifetime());
// setAttribute(Qt::WA_AcceptTouchEvents);
setAttribute(Qt::WA_OpaquePaintEvent, false);
showAll();
@@ -356,9 +364,11 @@ void TabbedSelector::resizeEvent(QResizeEvent *e) {
if (e->oldSize().height() > height()) {
_scroll->resize(_scroll->width(), contentHeight);
auto scrollTop = _scroll->scrollTop();
currentTab()->widget()->setMinimalHeight(contentHeight);
currentTab()->widget()->setVisibleTopBottom(scrollTop, scrollTop + contentHeight);
} else {
auto scrollTop = _scroll->scrollTop();
currentTab()->widget()->setMinimalHeight(contentHeight);
currentTab()->widget()->setVisibleTopBottom(scrollTop, scrollTop + contentHeight);
_scroll->resize(_scroll->width(), contentHeight);
}
@@ -514,11 +524,6 @@ void TabbedSelector::afterShown() {
}
}
void TabbedSelector::stickersInstalled(uint64 setId) {
_tabsSlider->setActiveSection(static_cast<int>(SelectorTab::Stickers));
stickers()->showStickerSet(setId);
}
void TabbedSelector::showMegagroupSet(ChannelData *megagroup) {
stickers()->showMegagroupSet(megagroup);
}
@@ -702,15 +707,36 @@ TabbedSelector::Inner::Inner(QWidget *parent, not_null<Window::Controller*> cont
}
void TabbedSelector::Inner::visibleTopBottomUpdated(int visibleTop, int visibleBottom) {
auto oldVisibleHeight = getVisibleBottom() - getVisibleTop();
_visibleTop = visibleTop;
_visibleBottom = visibleBottom;
auto visibleHeight = getVisibleBottom() - getVisibleTop();
if (visibleHeight != oldVisibleHeight) {
resize(st::emojiPanWidth - st::emojiScroll.width - st::buttonRadius, countHeight());
}
void TabbedSelector::Inner::setMinimalHeight(int newMinimalHeight) {
if (_minimalHeight != newMinimalHeight) {
_minimalHeight = newMinimalHeight;
updateSize();
}
}
void TabbedSelector::Inner::updateSize() {
auto width = st::emojiPanWidth
- st::emojiScroll.width
- st::buttonRadius;
auto height = qMax(countDesiredHeight(), minimalHeight());
auto newSize = QSize(width, height);
if (size() != newSize) {
resize(newSize);
update();
}
}
int TabbedSelector::Inner::minimalHeight() const {
auto result = _minimalHeight;
return (_minimalHeight > 0)
? _minimalHeight
: (st::emojiPanMaxHeight - st::emojiCategory.height);
}
void TabbedSelector::Inner::hideFinished() {
processHideFinished();
if (auto footer = getFooter()) {

View File

@@ -60,7 +60,6 @@ public:
void setRoundRadius(int radius);
void refreshStickers();
void stickersInstalled(uint64 setId);
void showMegagroupSet(ChannelData *megagroup);
void setCurrentPeer(PeerData *peer);
@@ -88,6 +87,10 @@ public:
bool wheelEventFromFloatPlayer(QEvent *e);
QRect rectForFloatPlayer() const;
rpl::producer<> showRequests() const {
return _showRequests.events();
}
~TabbedSelector();
class Inner;
@@ -199,6 +202,8 @@ private:
base::lambda<void(SelectorTab)> _afterShownCallback;
base::lambda<void(SelectorTab)> _beforeHidingCallback;
rpl::event_stream<> _showRequests;
};
class TabbedSelector::Inner : public TWidget {
@@ -213,6 +218,7 @@ public:
int getVisibleBottom() const {
return _visibleBottom;
}
void setMinimalHeight(int newMinimalHeight);
virtual void refreshRecent() = 0;
virtual void preloadImages() {
@@ -236,12 +242,14 @@ protected:
void visibleTopBottomUpdated(
int visibleTop,
int visibleBottom) override;
void updateSize();
int minimalHeight() const;
not_null<Window::Controller*> controller() const {
return _controller;
}
virtual int countHeight() = 0;
virtual int countDesiredHeight() = 0;
virtual InnerFooter *getFooter() const = 0;
virtual void processHideFinished() {
}
@@ -253,6 +261,7 @@ private:
int _visibleTop = 0;
int _visibleBottom = 0;
int _minimalHeight = 0;
};