mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-15 21:57:10 +02:00
Added ability to set controls type for single previews.
This commit is contained in:
parent
5431541694
commit
7cf5e6d94f
12 changed files with 59 additions and 26 deletions
|
@ -16,13 +16,24 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
|
||||
namespace Ui {
|
||||
|
||||
AbstractSingleFilePreview::AbstractSingleFilePreview(QWidget *parent)
|
||||
AbstractSingleFilePreview::AbstractSingleFilePreview(
|
||||
QWidget *parent,
|
||||
AttachControls::Type type)
|
||||
: AbstractSinglePreview(parent)
|
||||
, _type(type)
|
||||
, _editMedia(this, st::sendBoxAlbumGroupButtonFile)
|
||||
, _deleteMedia(this, st::sendBoxAlbumGroupButtonFile) {
|
||||
|
||||
_editMedia->setIconOverride(&st::sendBoxAlbumGroupEditButtonIconFile);
|
||||
_deleteMedia->setIconOverride(&st::sendBoxAlbumGroupDeleteButtonIconFile);
|
||||
|
||||
if (type == AttachControls::Type::Full) {
|
||||
_deleteMedia->show();
|
||||
_editMedia->show();
|
||||
} else if (type == AttachControls::Type::EditOnly) {
|
||||
_deleteMedia->hide();
|
||||
_editMedia->show();
|
||||
}
|
||||
}
|
||||
|
||||
AbstractSingleFilePreview::~AbstractSingleFilePreview() = default;
|
||||
|
@ -136,8 +147,10 @@ void AbstractSingleFilePreview::resizeEvent(QResizeEvent *e) {
|
|||
const auto x = (width() - w) / 2;
|
||||
const auto top = st::sendBoxFileGroupSkipTop;
|
||||
auto right = st::sendBoxFileGroupSkipRight + x;
|
||||
_deleteMedia->moveToRight(right, top);
|
||||
right += st::sendBoxFileGroupEditInternalSkip + _deleteMedia->width();
|
||||
if (_type != AttachControls::Type::EditOnly) {
|
||||
_deleteMedia->moveToRight(right, top);
|
||||
right += st::sendBoxFileGroupEditInternalSkip + _deleteMedia->width();
|
||||
}
|
||||
_editMedia->moveToRight(right, top);
|
||||
}
|
||||
|
||||
|
@ -152,12 +165,17 @@ void AbstractSingleFilePreview::updateTextWidthFor(Data &data) {
|
|||
const auto nameleft = st.thumbSize + st.padding.right();
|
||||
const auto nametop = st.nameTop;
|
||||
const auto statustop = st.statusTop;
|
||||
const auto buttonsCount = (_type == AttachControls::Type::EditOnly)
|
||||
? 1
|
||||
: (_type == AttachControls::Type::Full)
|
||||
? 2
|
||||
: 0;
|
||||
const auto availableFileWidth = st::sendMediaPreviewSize
|
||||
- st.thumbSize
|
||||
- st.padding.right()
|
||||
// Right buttons.
|
||||
- st::sendBoxAlbumGroupButtonFile.width * 2
|
||||
- st::sendBoxAlbumGroupEditInternalSkip * 2
|
||||
- st::sendBoxAlbumGroupButtonFile.width * buttonsCount
|
||||
- st::sendBoxAlbumGroupEditInternalSkip * buttonsCount
|
||||
- st::sendBoxAlbumGroupSkipRight;
|
||||
data.nameWidth = st::semiboldFont->width(data.name);
|
||||
if (data.nameWidth > availableFileWidth) {
|
||||
|
|
|
@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#pragma once
|
||||
|
||||
#include "ui/chat/attach/attach_abstract_single_preview.h"
|
||||
#include "ui/chat/attach/attach_controls.h"
|
||||
#include "base/object_ptr.h"
|
||||
|
||||
namespace Ui {
|
||||
|
@ -16,7 +17,7 @@ class IconButton;
|
|||
|
||||
class AbstractSingleFilePreview : public AbstractSinglePreview {
|
||||
public:
|
||||
AbstractSingleFilePreview(QWidget *parent);
|
||||
AbstractSingleFilePreview(QWidget *parent, AttachControls::Type type);
|
||||
~AbstractSingleFilePreview();
|
||||
|
||||
[[nodiscard]] rpl::producer<> deleteRequests() const override;
|
||||
|
@ -45,6 +46,8 @@ private:
|
|||
|
||||
void updateTextWidthFor(Data &data);
|
||||
|
||||
const AttachControls::Type _type;
|
||||
|
||||
Data _data;
|
||||
|
||||
object_ptr<IconButton> _editMedia = { nullptr };
|
||||
|
|
|
@ -22,12 +22,14 @@ constexpr auto kMinPreviewWidth = 20;
|
|||
|
||||
} // namespace
|
||||
|
||||
AbstractSingleMediaPreview::AbstractSingleMediaPreview(QWidget *parent)
|
||||
AbstractSingleMediaPreview::AbstractSingleMediaPreview(
|
||||
QWidget *parent,
|
||||
AttachControls::Type type)
|
||||
: AbstractSinglePreview(parent)
|
||||
, _minThumbH(st::sendBoxAlbumGroupSize.height()
|
||||
+ st::sendBoxAlbumGroupSkipTop * 2)
|
||||
, _photoEditorButton(base::make_unique_q<AbstractButton>(this))
|
||||
, _controls(base::make_unique_q<AttachControlsWidget>(this)) {
|
||||
, _controls(base::make_unique_q<AttachControlsWidget>(this, type)) {
|
||||
}
|
||||
|
||||
AbstractSingleMediaPreview::~AbstractSingleMediaPreview() = default;
|
||||
|
|
|
@ -8,15 +8,14 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#pragma once
|
||||
|
||||
#include "ui/chat/attach/attach_abstract_single_preview.h"
|
||||
#include "ui/chat/attach/attach_controls.h"
|
||||
#include "ui/abstract_button.h"
|
||||
|
||||
namespace Ui {
|
||||
|
||||
class AttachControlsWidget;
|
||||
|
||||
class AbstractSingleMediaPreview : public AbstractSinglePreview {
|
||||
public:
|
||||
AbstractSingleMediaPreview(QWidget *parent);
|
||||
AbstractSingleMediaPreview(QWidget *parent, AttachControls::Type type);
|
||||
~AbstractSingleMediaPreview();
|
||||
|
||||
[[nodiscard]] rpl::producer<> deleteRequests() const override;
|
||||
|
|
|
@ -23,8 +23,9 @@ namespace Ui {
|
|||
|
||||
ItemSingleFilePreview::ItemSingleFilePreview(
|
||||
QWidget *parent,
|
||||
not_null<HistoryItem*> item)
|
||||
: AbstractSingleFilePreview(parent) {
|
||||
not_null<HistoryItem*> item,
|
||||
AttachControls::Type type)
|
||||
: AbstractSingleFilePreview(parent, type) {
|
||||
const auto media = item->media();
|
||||
Assert(media != nullptr);
|
||||
const auto document = media->document();
|
||||
|
|
|
@ -25,7 +25,8 @@ class ItemSingleFilePreview final : public AbstractSingleFilePreview {
|
|||
public:
|
||||
ItemSingleFilePreview(
|
||||
QWidget *parent,
|
||||
not_null<HistoryItem*> item);
|
||||
not_null<HistoryItem*> item,
|
||||
AttachControls::Type type);
|
||||
|
||||
private:
|
||||
void preparePreview(not_null<DocumentData*> document);
|
||||
|
|
|
@ -32,8 +32,9 @@ using namespace ::Media::Streaming;
|
|||
ItemSingleMediaPreview::ItemSingleMediaPreview(
|
||||
QWidget *parent,
|
||||
Fn<bool()> gifPaused,
|
||||
not_null<HistoryItem*> item)
|
||||
: AbstractSingleMediaPreview(parent)
|
||||
not_null<HistoryItem*> item,
|
||||
AttachControls::Type type)
|
||||
: AbstractSingleMediaPreview(parent, type)
|
||||
, _gifPaused(std::move(gifPaused))
|
||||
, _fullId(item->fullId()) {
|
||||
const auto media = item->media();
|
||||
|
|
|
@ -33,7 +33,8 @@ public:
|
|||
ItemSingleMediaPreview(
|
||||
QWidget *parent,
|
||||
Fn<bool()> gifPaused,
|
||||
not_null<HistoryItem*> item);
|
||||
not_null<HistoryItem*> item,
|
||||
AttachControls::Type type);
|
||||
|
||||
std::shared_ptr<::Data::PhotoMedia> sharedPhotoMedia() const;
|
||||
|
||||
|
|
|
@ -19,8 +19,9 @@ namespace Ui {
|
|||
|
||||
SingleFilePreview::SingleFilePreview(
|
||||
QWidget *parent,
|
||||
const PreparedFile &file)
|
||||
: AbstractSingleFilePreview(parent) {
|
||||
const PreparedFile &file,
|
||||
AttachControls::Type type)
|
||||
: AbstractSingleFilePreview(parent, type) {
|
||||
preparePreview(file);
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,8 @@ class SingleFilePreview final : public AbstractSingleFilePreview {
|
|||
public:
|
||||
SingleFilePreview(
|
||||
QWidget *parent,
|
||||
const PreparedFile &file);
|
||||
const PreparedFile &file,
|
||||
AttachControls::Type type = AttachControls::Type::Full);
|
||||
|
||||
private:
|
||||
void preparePreview(const PreparedFile &file);
|
||||
|
|
|
@ -17,7 +17,8 @@ namespace Ui {
|
|||
SingleMediaPreview *SingleMediaPreview::Create(
|
||||
QWidget *parent,
|
||||
Fn<bool()> gifPaused,
|
||||
const PreparedFile &file) {
|
||||
const PreparedFile &file,
|
||||
AttachControls::Type type) {
|
||||
auto preview = QImage();
|
||||
bool animated = false;
|
||||
bool animationPreview = false;
|
||||
|
@ -44,7 +45,8 @@ SingleMediaPreview *SingleMediaPreview::Create(
|
|||
preview,
|
||||
animated,
|
||||
Core::IsMimeSticker(file.information->filemime),
|
||||
animationPreview ? file.path : QString());
|
||||
animationPreview ? file.path : QString(),
|
||||
type);
|
||||
}
|
||||
|
||||
SingleMediaPreview::SingleMediaPreview(
|
||||
|
@ -53,8 +55,9 @@ SingleMediaPreview::SingleMediaPreview(
|
|||
QImage preview,
|
||||
bool animated,
|
||||
bool sticker,
|
||||
const QString &animatedPreviewPath)
|
||||
: AbstractSingleMediaPreview(parent)
|
||||
const QString &animatedPreviewPath,
|
||||
AttachControls::Type type)
|
||||
: AbstractSingleMediaPreview(parent, type)
|
||||
, _gifPaused(std::move(gifPaused))
|
||||
, _sticker(sticker) {
|
||||
Expects(!preview.isNull());
|
||||
|
|
|
@ -23,7 +23,8 @@ public:
|
|||
static SingleMediaPreview *Create(
|
||||
QWidget *parent,
|
||||
Fn<bool()> gifPaused,
|
||||
const PreparedFile &file);
|
||||
const PreparedFile &file,
|
||||
AttachControls::Type type = AttachControls::Type::Full);
|
||||
|
||||
SingleMediaPreview(
|
||||
QWidget *parent,
|
||||
|
@ -31,7 +32,8 @@ public:
|
|||
QImage preview,
|
||||
bool animated,
|
||||
bool sticker,
|
||||
const QString &animatedPreviewPath);
|
||||
const QString &animatedPreviewPath,
|
||||
AttachControls::Type type);
|
||||
|
||||
protected:
|
||||
bool drawBackground() const override;
|
||||
|
|
Loading…
Add table
Reference in a new issue