2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 14:45:14 +00:00

Add files from clipboard to composed album.

Fixes #4243.
This commit is contained in:
John Preston
2017-12-29 20:02:23 +03:00
parent 0171a4e874
commit 2a409e3734
8 changed files with 189 additions and 30 deletions

View File

@@ -2467,6 +2467,24 @@ void InputArea::Inner::contextMenuEvent(QContextMenuEvent *e) {
}
}
bool InputArea::Inner::canInsertFromMimeData(const QMimeData *source) const {
if (source
&& f()->_mimeDataHook
&& f()->_mimeDataHook(source, MimeAction::Check)) {
return true;
}
return QTextEdit::canInsertFromMimeData(source);
}
void InputArea::Inner::insertFromMimeData(const QMimeData *source) {
if (source
&& f()->_mimeDataHook
&& f()->_mimeDataHook(source, MimeAction::Insert)) {
return;
}
return QTextEdit::insertFromMimeData(source);
}
void InputArea::resizeEvent(QResizeEvent *e) {
refreshPlaceholder();
_inner->setGeometry(rect().marginsRemoved(_st.textMargins));

View File

@@ -387,6 +387,17 @@ public:
_inner->clearFocus();
}
enum class MimeAction {
Check,
Insert,
};
using MimeDataHook = base::lambda<bool(
not_null<const QMimeData*> data,
MimeAction action)>;
void setMimeDataHook(MimeDataHook hook) {
_mimeDataHook = std::move(hook);
}
private slots:
void onTouchTimer();
@@ -441,6 +452,8 @@ private:
void keyPressEvent(QKeyEvent *e) override;
void contextMenuEvent(QContextMenuEvent *e) override;
bool canInsertFromMimeData(const QMimeData *source) const override;
void insertFromMimeData(const QMimeData *source) override;
QMimeData *createMimeDataFromSelection() const override;
private:
@@ -504,6 +517,7 @@ private:
QPoint _touchStart;
bool _correcting = false;
MimeDataHook _mimeDataHook;
};