Allow custom click handlers in toasts.
This commit is contained in:
parent
2cb10e1d13
commit
6d26132685
3 changed files with 13 additions and 3 deletions
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
#include "ui/effects/animations.h"
|
#include "ui/effects/animations.h"
|
||||||
#include "ui/text/text_entity.h"
|
#include "ui/text/text_entity.h"
|
||||||
|
#include "ui/click_handler.h"
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
namespace Toast {
|
namespace Toast {
|
||||||
|
|
@ -17,6 +18,8 @@ class Manager;
|
||||||
class Widget;
|
class Widget;
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
|
|
||||||
|
using ClickHandlerFilter = Fn<bool(const ClickHandlerPtr&, Qt::MouseButton)>;
|
||||||
|
|
||||||
inline constexpr auto kDefaultDuration = crl::time(1500);
|
inline constexpr auto kDefaultDuration = crl::time(1500);
|
||||||
struct Config {
|
struct Config {
|
||||||
TextWithEntities text;
|
TextWithEntities text;
|
||||||
|
|
@ -26,6 +29,7 @@ struct Config {
|
||||||
int maxWidth = 0;
|
int maxWidth = 0;
|
||||||
int maxLines = 16;
|
int maxLines = 16;
|
||||||
bool multiline = false;
|
bool multiline = false;
|
||||||
|
ClickHandlerFilter filter;
|
||||||
};
|
};
|
||||||
void SetDefaultParent(not_null<QWidget*> parent);
|
void SetDefaultParent(not_null<QWidget*> parent);
|
||||||
void Show(not_null<QWidget*> parent, const Config &config);
|
void Show(not_null<QWidget*> parent, const Config &config);
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,8 @@ Widget::Widget(QWidget *parent, const Config &config)
|
||||||
, _maxTextWidth(widthWithoutPadding(_maxWidth))
|
, _maxTextWidth(widthWithoutPadding(_maxWidth))
|
||||||
, _maxTextHeight(
|
, _maxTextHeight(
|
||||||
st::toastTextStyle.font->height * (_multiline ? config.maxLines : 1))
|
st::toastTextStyle.font->height * (_multiline ? config.maxLines : 1))
|
||||||
, _text(_multiline ? widthWithoutPadding(config.minWidth) : QFIXED_MAX) {
|
, _text(_multiline ? widthWithoutPadding(config.minWidth) : QFIXED_MAX)
|
||||||
|
, _clickHandlerFilter(config.filter) {
|
||||||
const auto toastOptions = TextParseOptions{
|
const auto toastOptions = TextParseOptions{
|
||||||
TextParseMultiline,
|
TextParseMultiline,
|
||||||
_maxTextWidth,
|
_maxTextWidth,
|
||||||
|
|
@ -116,11 +117,14 @@ void Widget::mouseReleaseEvent(QMouseEvent *e) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (const auto handler = ClickHandler::unpressed()) {
|
if (const auto handler = ClickHandler::unpressed()) {
|
||||||
handler->onClick({ e->button() });
|
const auto button = e->button();
|
||||||
|
if (!_clickHandlerFilter
|
||||||
|
|| _clickHandlerFilter(handler, button)) {
|
||||||
|
ActivateClickHandler(this, handler, button);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
} // namespace Toast
|
} // namespace Toast
|
||||||
} // namespace Ui
|
} // namespace Ui
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,8 @@ private:
|
||||||
int _textWidth = 0;
|
int _textWidth = 0;
|
||||||
Text::String _text;
|
Text::String _text;
|
||||||
|
|
||||||
|
ClickHandlerFilter _clickHandlerFilter;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue