Moved SpoilerClickHandler to separated file.
This commit is contained in:
parent
af2cfca307
commit
2c1e6b458d
5 changed files with 69 additions and 27 deletions
|
|
@ -230,6 +230,8 @@ PRIVATE
|
|||
ui/rect_part.h
|
||||
ui/round_rect.cpp
|
||||
ui/round_rect.h
|
||||
ui/spoiler_click_handler.cpp
|
||||
ui/spoiler_click_handler.h
|
||||
ui/rp_widget.cpp
|
||||
ui/rp_widget.h
|
||||
ui/ui_utility.cpp
|
||||
|
|
|
|||
32
ui/spoiler_click_handler.cpp
Normal file
32
ui/spoiler_click_handler.cpp
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
// 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 "ui/spoiler_click_handler.h"
|
||||
|
||||
#include "ui/text/text_entity.h"
|
||||
|
||||
ClickHandler::TextEntity SpoilerClickHandler::getTextEntity() const {
|
||||
return { EntityType::Spoiler };
|
||||
}
|
||||
|
||||
void SpoilerClickHandler::onClick(ClickContext context) const {
|
||||
if (!_shown) {
|
||||
const auto nonconst = const_cast<SpoilerClickHandler*>(this);
|
||||
nonconst->_shown = true;
|
||||
}
|
||||
}
|
||||
|
||||
bool SpoilerClickHandler::shown() const {
|
||||
return _shown;
|
||||
}
|
||||
|
||||
crl::time SpoilerClickHandler::startMs() const {
|
||||
return _startMs;
|
||||
}
|
||||
|
||||
void SpoilerClickHandler::setStartMs(crl::time value) {
|
||||
_startMs = value;
|
||||
}
|
||||
29
ui/spoiler_click_handler.h
Normal file
29
ui/spoiler_click_handler.h
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
// 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 "ui/click_handler.h"
|
||||
|
||||
enum class EntityType : uchar;
|
||||
|
||||
class SpoilerClickHandler : public ClickHandler {
|
||||
public:
|
||||
SpoilerClickHandler() = default;
|
||||
|
||||
TextEntity getTextEntity() const override;
|
||||
|
||||
void onClick(ClickContext context) const override;
|
||||
|
||||
[[nodiscard]] bool shown() const;
|
||||
[[nodiscard]] crl::time startMs() const;
|
||||
void setStartMs(crl::time value);
|
||||
|
||||
private:
|
||||
bool _shown = false;
|
||||
crl::time _startMs = 0;
|
||||
|
||||
};
|
||||
|
|
@ -13,6 +13,7 @@
|
|||
#include "ui/integration.h"
|
||||
#include "ui/round_rect.h"
|
||||
#include "ui/image/image_prepare.h"
|
||||
#include "ui/spoiler_click_handler.h"
|
||||
#include "base/platform/base_platform_info.h"
|
||||
#include "base/qt_adapters.h"
|
||||
|
||||
|
|
@ -270,30 +271,6 @@ const TextParseOptions _textPlainOptions = {
|
|||
namespace Ui {
|
||||
namespace Text {
|
||||
|
||||
class String::SpoilerClickHandler final : public ClickHandler {
|
||||
public:
|
||||
SpoilerClickHandler() = default;
|
||||
|
||||
TextEntity getTextEntity() const override {
|
||||
return { EntityType::Spoiler };
|
||||
}
|
||||
|
||||
void onClick(ClickContext context) const override {
|
||||
if (!_shown) {
|
||||
const auto nonconst = const_cast<SpoilerClickHandler*>(this);
|
||||
nonconst->_shown = true;
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] bool shown() const {
|
||||
return _shown;
|
||||
}
|
||||
|
||||
private:
|
||||
bool _shown = false;
|
||||
|
||||
};
|
||||
|
||||
class Parser {
|
||||
public:
|
||||
Parser(
|
||||
|
|
@ -1024,9 +1001,9 @@ void Parser::finalize(const TextParseOptions &options) {
|
|||
if (spoilerIndex) {
|
||||
_t->_spoilers.resize(spoilerIndex);
|
||||
const auto handler = (options.flags & TextParseLinks)
|
||||
? std::make_shared<String::SpoilerClickHandler>()
|
||||
? std::make_shared<SpoilerClickHandler>()
|
||||
: nullptr;
|
||||
_t->_spoilers[spoilerIndex - 1] = std::move(handler);
|
||||
_t->setSpoiler(spoilerIndex, std::move(handler));
|
||||
}
|
||||
const auto shiftedIndex = block->lnkIndex();
|
||||
if (shiftedIndex <= kStringLinkIndexShift) {
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@
|
|||
#include <private/qfixed_p.h>
|
||||
#include <any>
|
||||
|
||||
class SpoilerClickHandler;
|
||||
|
||||
static const QChar TextCommand(0x0010);
|
||||
enum TextCommands {
|
||||
TextCommandBold = 0x01,
|
||||
|
|
@ -133,6 +135,7 @@ public:
|
|||
|
||||
void setLink(uint16 lnkIndex, const ClickHandlerPtr &lnk);
|
||||
bool hasLinks() const;
|
||||
void setSpoiler(uint16 lnkIndex, const std::shared_ptr<SpoilerClickHandler> &lnk);
|
||||
|
||||
bool hasSkipBlock() const;
|
||||
bool updateSkipBlock(int width, int height);
|
||||
|
|
@ -224,7 +227,6 @@ private:
|
|||
TextBlocks _blocks;
|
||||
TextLinks _links;
|
||||
|
||||
class SpoilerClickHandler;
|
||||
QVector<std::shared_ptr<SpoilerClickHandler>> _spoilers;
|
||||
|
||||
Qt::LayoutDirection _startDir = Qt::LayoutDirectionAuto;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue