tdesktop/Telegram/SourceFiles/ui/special_buttons.h

196 lines
4.7 KiB
C
Raw Normal View History

2016-05-19 17:18:23 +00:00
/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
2016-05-19 17:18:23 +00:00
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
2016-05-19 17:18:23 +00:00
*/
#pragma once
#include "ui/widgets/buttons.h"
#include "ui/widgets/tooltip.h"
2019-04-02 09:13:30 +00:00
#include "ui/effects/animations.h"
#include "ui/effects/cross_line.h"
#include "styles/style_window.h"
2016-10-27 14:10:28 +00:00
#include "styles/style_widgets.h"
2016-05-19 17:18:23 +00:00
class PeerData;
2020-05-28 14:32:10 +00:00
namespace Data {
class CloudImageView;
} // namespace Data
2018-05-04 16:57:50 +00:00
namespace Window {
class SessionController;
} // namespace Window
namespace Media {
namespace Streaming {
class Instance;
struct Update;
enum class Error;
struct Information;
} // namespace Streaming
} // namespace Media
2016-05-19 17:18:23 +00:00
namespace Ui {
class HistoryDownButton : public RippleButton {
2016-05-19 17:18:23 +00:00
public:
HistoryDownButton(QWidget *parent, const style::TwoIconButton &st);
2016-05-19 17:18:23 +00:00
void setUnreadCount(int unreadCount);
int unreadCount() const {
return _unreadCount;
}
2016-05-19 17:18:23 +00:00
protected:
void paintEvent(QPaintEvent *e) override;
QImage prepareRippleMask() const override;
QPoint prepareRippleStartPosition() const override;
2016-05-19 17:18:23 +00:00
private:
const style::TwoIconButton &_st;
int _unreadCount = 0;
2016-05-19 17:18:23 +00:00
};
class UserpicButton : public RippleButton {
public:
enum class Role {
ChangePhoto,
OpenPhoto,
OpenProfile,
Custom,
};
UserpicButton(
QWidget *parent,
2018-12-23 17:23:36 +00:00
const QString &cropTitle,
Role role,
const style::UserpicButton &st);
UserpicButton(
QWidget *parent,
not_null<Window::SessionController*> controller,
not_null<PeerData*> peer,
Role role,
const style::UserpicButton &st);
UserpicButton(
QWidget *parent,
not_null<PeerData*> peer,
Role role,
const style::UserpicButton &st);
void switchChangePhotoOverlay(bool enabled);
void showSavedMessagesOnSelf(bool enabled);
QImage takeResultImage() {
return std::move(_result);
2017-11-10 15:45:10 +00:00
}
protected:
void paintEvent(QPaintEvent *e) override;
void mouseMoveEvent(QMouseEvent *e) override;
void leaveEventHook(QEvent *e) override;
void onStateChanged(State was, StateChangeSource source) override;
QImage prepareRippleMask() const override;
QPoint prepareRippleStartPosition() const override;
private:
void prepare();
void setImage(QImage &&image);
void setupPeerViewers();
void startAnimation();
void processPeerPhoto();
void processNewPeerPhoto();
void startNewPhotoShowing();
void prepareUserpicPixmap();
QPoint countPhotoPosition() const;
void startChangeOverlayAnimation();
void updateCursorInChangeOverlay(QPoint localPos);
void setCursorInChangeOverlay(bool inOverlay);
void updateCursor();
void updateVideo();
bool showSavedMessages() const;
2020-09-11 15:33:26 +00:00
bool showRepliesMessages() const;
void checkStreamedIsStarted();
bool createStreamingObjects(not_null<PhotoData*> photo);
void clearStreaming();
void handleStreamingUpdate(Media::Streaming::Update &&update);
void handleStreamingError(Media::Streaming::Error &&error);
void streamingReady(Media::Streaming::Information &&info);
void paintUserpicFrame(Painter &p, QPoint photoPosition);
void grabOldUserpic();
void setClickHandlerByRole();
void openPeerPhoto();
void changePhotoLazy();
void uploadNewPeerPhoto();
const style::UserpicButton &_st;
Window::SessionController *_controller = nullptr;
PeerData *_peer = nullptr;
2020-05-28 14:32:10 +00:00
std::shared_ptr<Data::CloudImageView> _userpicView;
2018-12-23 17:23:36 +00:00
QString _cropTitle;
Role _role = Role::ChangePhoto;
bool _notShownYet = true;
bool _waiting = false;
QPixmap _userpic, _oldUserpic;
bool _userpicHasImage = false;
bool _userpicCustom = false;
InMemoryKey _userpicUniqueKey;
2019-04-02 09:13:30 +00:00
Ui::Animations::Simple _a_appearance;
QImage _result;
std::unique_ptr<Media::Streaming::Instance> _streamed;
PhotoData *_streamedPhoto = nullptr;
bool _showSavedMessagesOnSelf = false;
bool _canOpenPhoto = false;
bool _cursorInChangeOverlay = false;
bool _changeOverlayEnabled = false;
2019-04-02 09:13:30 +00:00
Ui::Animations::Simple _changeOverlayShown;
};
class SilentToggle
: public Ui::RippleButton
, public Ui::AbstractTooltipShower {
public:
SilentToggle(QWidget *parent, not_null<ChannelData*> channel);
void setChecked(bool checked);
bool checked() const {
return _checked;
}
// AbstractTooltipShower interface
QString tooltipText() const override;
QPoint tooltipPos() const override;
2019-09-16 11:14:06 +00:00
bool tooltipWindowActive() const override;
protected:
void mouseMoveEvent(QMouseEvent *e) override;
void mouseReleaseEvent(QMouseEvent *e) override;
void leaveEventHook(QEvent *e) override;
QImage prepareRippleMask() const override;
QPoint prepareRippleStartPosition() const override;
private:
const style::IconButton &_st;
const QColor &_colorOver;
not_null<ChannelData*> _channel;
bool _checked = false;
Ui::CrossLineAnimation _crossLine;
Ui::Animations::Simple _crossLineAnimation;
};
2016-05-19 17:18:23 +00:00
} // namespace Ui