mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2026-07-25 06:54:43 +00:00
Added menu action with dynamic image thumbnail.
This commit is contained in:
@@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
This file is part of Telegram Desktop,
|
||||||
|
the official desktop application for the Telegram messaging service.
|
||||||
|
|
||||||
|
For license and copyright information please follow this link:
|
||||||
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
|
*/
|
||||||
|
#include "menu/menu_action_with_thumbnail.h"
|
||||||
|
|
||||||
|
#include "ui/dynamic_image.h"
|
||||||
|
#include "ui/painter.h"
|
||||||
|
|
||||||
|
namespace Menu {
|
||||||
|
|
||||||
|
ActionWithThumbnail::ActionWithThumbnail(
|
||||||
|
not_null<Ui::Menu::Menu*> parent,
|
||||||
|
const style::Menu &st,
|
||||||
|
not_null<QAction*> action,
|
||||||
|
std::shared_ptr<Ui::DynamicImage> thumbnail,
|
||||||
|
int thumbnailSize)
|
||||||
|
: Ui::Menu::Action(parent, st, action, nullptr, nullptr)
|
||||||
|
, _thumbnail(std::move(thumbnail))
|
||||||
|
, _thumbnailSize(thumbnailSize) {
|
||||||
|
if (_thumbnail) {
|
||||||
|
_thumbnail->subscribeToUpdates([=] { update(); });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ActionWithThumbnail::~ActionWithThumbnail() {
|
||||||
|
if (_thumbnail) {
|
||||||
|
_thumbnail->subscribeToUpdates(nullptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ActionWithThumbnail::paintEvent(QPaintEvent *e) {
|
||||||
|
Ui::Menu::Action::paintEvent(e);
|
||||||
|
if (!_thumbnail) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
auto p = QPainter(this);
|
||||||
|
const auto pos = st().itemIconPosition;
|
||||||
|
p.drawImage(
|
||||||
|
QRect(pos.x(), pos.y(), _thumbnailSize, _thumbnailSize),
|
||||||
|
_thumbnail->image(_thumbnailSize));
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Menu
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
This file is part of Telegram Desktop,
|
||||||
|
the official desktop application for the Telegram messaging service.
|
||||||
|
|
||||||
|
For license and copyright information please follow this link:
|
||||||
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "ui/widgets/menu/menu_action.h"
|
||||||
|
|
||||||
|
namespace Ui {
|
||||||
|
class DynamicImage;
|
||||||
|
} // namespace Ui
|
||||||
|
|
||||||
|
namespace Menu {
|
||||||
|
|
||||||
|
class ActionWithThumbnail final : public Ui::Menu::Action {
|
||||||
|
public:
|
||||||
|
ActionWithThumbnail(
|
||||||
|
not_null<Ui::Menu::Menu*> parent,
|
||||||
|
const style::Menu &st,
|
||||||
|
not_null<QAction*> action,
|
||||||
|
std::shared_ptr<Ui::DynamicImage> thumbnail,
|
||||||
|
int thumbnailSize);
|
||||||
|
~ActionWithThumbnail();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void paintEvent(QPaintEvent *e) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::shared_ptr<Ui::DynamicImage> _thumbnail;
|
||||||
|
int _thumbnailSize = 0;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Menu
|
||||||
@@ -223,6 +223,8 @@ PRIVATE
|
|||||||
|
|
||||||
menu/gift_resale_filter.cpp
|
menu/gift_resale_filter.cpp
|
||||||
menu/gift_resale_filter.h
|
menu/gift_resale_filter.h
|
||||||
|
menu/menu_action_with_thumbnail.cpp
|
||||||
|
menu/menu_action_with_thumbnail.h
|
||||||
menu/menu_checked_action.cpp
|
menu/menu_checked_action.cpp
|
||||||
menu/menu_checked_action.h
|
menu/menu_checked_action.h
|
||||||
menu/menu_check_item.cpp
|
menu/menu_check_item.cpp
|
||||||
|
|||||||
Reference in New Issue
Block a user