Implement Qml drag and drop
This commit is contained in:
parent
0eb8d4126b
commit
c74077a41f
@ -257,22 +257,23 @@ set(SRC_FILES
|
|||||||
src/ui/Avatar.cpp
|
src/ui/Avatar.cpp
|
||||||
src/ui/Badge.cpp
|
src/ui/Badge.cpp
|
||||||
src/ui/DropShadow.cpp
|
src/ui/DropShadow.cpp
|
||||||
src/ui/LoadingIndicator.cpp
|
|
||||||
src/ui/InfoMessage.cpp
|
|
||||||
src/ui/FlatButton.cpp
|
src/ui/FlatButton.cpp
|
||||||
src/ui/FloatingButton.cpp
|
src/ui/FloatingButton.cpp
|
||||||
|
src/ui/InfoMessage.cpp
|
||||||
src/ui/Label.cpp
|
src/ui/Label.cpp
|
||||||
|
src/ui/LoadingIndicator.cpp
|
||||||
|
src/ui/NhekoDropArea.cpp
|
||||||
src/ui/OverlayModal.cpp
|
src/ui/OverlayModal.cpp
|
||||||
src/ui/SnackBar.cpp
|
src/ui/OverlayWidget.cpp
|
||||||
src/ui/RaisedButton.cpp
|
src/ui/RaisedButton.cpp
|
||||||
src/ui/Ripple.cpp
|
src/ui/Ripple.cpp
|
||||||
src/ui/RippleOverlay.cpp
|
src/ui/RippleOverlay.cpp
|
||||||
src/ui/OverlayWidget.cpp
|
src/ui/SnackBar.cpp
|
||||||
src/ui/TextField.cpp
|
src/ui/TextField.cpp
|
||||||
src/ui/TextLabel.cpp
|
src/ui/TextLabel.cpp
|
||||||
src/ui/ToggleButton.cpp
|
|
||||||
src/ui/Theme.cpp
|
src/ui/Theme.cpp
|
||||||
src/ui/ThemeManager.cpp
|
src/ui/ThemeManager.cpp
|
||||||
|
src/ui/ToggleButton.cpp
|
||||||
src/ui/UserProfile.cpp
|
src/ui/UserProfile.cpp
|
||||||
|
|
||||||
src/AvatarProvider.cpp
|
src/AvatarProvider.cpp
|
||||||
@ -471,6 +472,7 @@ qt5_wrap_cpp(MOC_HEADERS
|
|||||||
src/ui/Label.h
|
src/ui/Label.h
|
||||||
src/ui/FloatingButton.h
|
src/ui/FloatingButton.h
|
||||||
src/ui/Menu.h
|
src/ui/Menu.h
|
||||||
|
src/ui/NhekoDropArea.h
|
||||||
src/ui/OverlayWidget.h
|
src/ui/OverlayWidget.h
|
||||||
src/ui/SnackBar.h
|
src/ui/SnackBar.h
|
||||||
src/ui/RaisedButton.h
|
src/ui/RaisedButton.h
|
||||||
|
@ -178,6 +178,11 @@ Rectangle {
|
|||||||
onClicked: TimelineManager.timeline.input.paste(true)
|
onClicked: TimelineManager.timeline.input.paste(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NhekoDropArea {
|
||||||
|
anchors.fill: parent
|
||||||
|
roomid: TimelineManager.timeline.roomId()
|
||||||
|
}
|
||||||
|
|
||||||
background: Rectangle {
|
background: Rectangle {
|
||||||
color: colors.window
|
color: colors.window
|
||||||
}
|
}
|
||||||
|
@ -88,6 +88,7 @@ public:
|
|||||||
|
|
||||||
QSharedPointer<UserSettings> userSettings() { return userSettings_; }
|
QSharedPointer<UserSettings> userSettings() { return userSettings_; }
|
||||||
CallManager *callManager() { return callManager_; }
|
CallManager *callManager() { return callManager_; }
|
||||||
|
TimelineViewManager *timelineManager() { return view_manager_; }
|
||||||
void deleteConfigs();
|
void deleteConfigs();
|
||||||
|
|
||||||
CommunitiesList *communitiesList() { return communitiesList_; }
|
CommunitiesList *communitiesList() { return communitiesList_; }
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include "InputBar.h"
|
#include "InputBar.h"
|
||||||
|
|
||||||
#include <QClipboard>
|
#include <QClipboard>
|
||||||
|
#include <QDropEvent>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QGuiApplication>
|
#include <QGuiApplication>
|
||||||
#include <QMimeData>
|
#include <QMimeData>
|
||||||
@ -44,6 +45,13 @@ InputBar::paste(bool fromMouse)
|
|||||||
md = QGuiApplication::clipboard()->mimeData(QClipboard::Clipboard);
|
md = QGuiApplication::clipboard()->mimeData(QClipboard::Clipboard);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (md)
|
||||||
|
insertMimeData(md);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
InputBar::insertMimeData(const QMimeData *md)
|
||||||
|
{
|
||||||
if (!md)
|
if (!md)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
class TimelineModel;
|
class TimelineModel;
|
||||||
class QMimeData;
|
class QMimeData;
|
||||||
|
class QDropEvent;
|
||||||
class QStringList;
|
class QStringList;
|
||||||
|
|
||||||
class InputBar : public QObject
|
class InputBar : public QObject
|
||||||
@ -36,6 +37,7 @@ public slots:
|
|||||||
|
|
||||||
void send();
|
void send();
|
||||||
void paste(bool fromMouse);
|
void paste(bool fromMouse);
|
||||||
|
void insertMimeData(const QMimeData *data);
|
||||||
void updateState(int selectionStart, int selectionEnd, int cursorPosition, QString text);
|
void updateState(int selectionStart, int selectionEnd, int cursorPosition, QString text);
|
||||||
void openFileSelection();
|
void openFileSelection();
|
||||||
bool uploading() const { return uploading_; }
|
bool uploading() const { return uploading_; }
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include "TimelineViewManager.h"
|
#include "TimelineViewManager.h"
|
||||||
|
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
|
#include <QDropEvent>
|
||||||
#include <QMetaType>
|
#include <QMetaType>
|
||||||
#include <QPalette>
|
#include <QPalette>
|
||||||
#include <QQmlContext>
|
#include <QQmlContext>
|
||||||
@ -20,6 +21,7 @@
|
|||||||
#include "dialogs/ImageOverlay.h"
|
#include "dialogs/ImageOverlay.h"
|
||||||
#include "emoji/EmojiModel.h"
|
#include "emoji/EmojiModel.h"
|
||||||
#include "emoji/Provider.h"
|
#include "emoji/Provider.h"
|
||||||
|
#include "ui/NhekoDropArea.h"
|
||||||
|
|
||||||
#include <iostream> //only for debugging
|
#include <iostream> //only for debugging
|
||||||
|
|
||||||
@ -115,6 +117,7 @@ TimelineViewManager::TimelineViewManager(CallManager *callManager, ChatPage *par
|
|||||||
|
|
||||||
qmlRegisterType<DelegateChoice>("im.nheko", 1, 0, "DelegateChoice");
|
qmlRegisterType<DelegateChoice>("im.nheko", 1, 0, "DelegateChoice");
|
||||||
qmlRegisterType<DelegateChooser>("im.nheko", 1, 0, "DelegateChooser");
|
qmlRegisterType<DelegateChooser>("im.nheko", 1, 0, "DelegateChooser");
|
||||||
|
qmlRegisterType<NhekoDropArea>("im.nheko", 1, 0, "NhekoDropArea");
|
||||||
qmlRegisterUncreatableType<DeviceVerificationFlow>(
|
qmlRegisterUncreatableType<DeviceVerificationFlow>(
|
||||||
"im.nheko", 1, 0, "DeviceVerificationFlow", "Can't create verification flow from QML!");
|
"im.nheko", 1, 0, "DeviceVerificationFlow", "Can't create verification flow from QML!");
|
||||||
qmlRegisterUncreatableType<UserProfile>(
|
qmlRegisterUncreatableType<UserProfile>(
|
||||||
|
@ -105,6 +105,15 @@ public slots:
|
|||||||
void initWithMessages(const std::vector<QString> &roomIds);
|
void initWithMessages(const std::vector<QString> &roomIds);
|
||||||
|
|
||||||
void setHistoryView(const QString &room_id);
|
void setHistoryView(const QString &room_id);
|
||||||
|
TimelineModel *getHistoryView(const QString &room_id)
|
||||||
|
{
|
||||||
|
auto room = models.find(room_id);
|
||||||
|
if (room != models.end())
|
||||||
|
return room.value().data();
|
||||||
|
else
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
void updateColorPalette();
|
void updateColorPalette();
|
||||||
void queueReactionMessage(const QString &reactedEvent, const QString &reactionKey);
|
void queueReactionMessage(const QString &reactedEvent, const QString &reactionKey);
|
||||||
void queueCallMessage(const QString &roomid, const mtx::events::msg::CallInvite &);
|
void queueCallMessage(const QString &roomid, const mtx::events::msg::CallInvite &);
|
||||||
|
39
src/ui/NhekoDropArea.cpp
Normal file
39
src/ui/NhekoDropArea.cpp
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
#include "NhekoDropArea.h"
|
||||||
|
|
||||||
|
#include <QMimeData>
|
||||||
|
|
||||||
|
#include "ChatPage.h"
|
||||||
|
#include "timeline/InputBar.h"
|
||||||
|
#include "timeline/TimelineModel.h"
|
||||||
|
#include "timeline/TimelineViewManager.h"
|
||||||
|
|
||||||
|
#include "Logging.h"
|
||||||
|
|
||||||
|
NhekoDropArea::NhekoDropArea(QQuickItem *parent)
|
||||||
|
: QQuickItem(parent)
|
||||||
|
{
|
||||||
|
setFlags(ItemAcceptsDrops);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
NhekoDropArea::dragEnterEvent(QDragEnterEvent *event)
|
||||||
|
{
|
||||||
|
event->acceptProposedAction();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
NhekoDropArea::dragMoveEvent(QDragMoveEvent *event)
|
||||||
|
{
|
||||||
|
event->acceptProposedAction();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
NhekoDropArea::dropEvent(QDropEvent *event)
|
||||||
|
{
|
||||||
|
if (event) {
|
||||||
|
auto model = ChatPage::instance()->timelineManager()->getHistoryView(roomid_);
|
||||||
|
if (model) {
|
||||||
|
model->input()->insertMimeData(event->mimeData());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
30
src/ui/NhekoDropArea.h
Normal file
30
src/ui/NhekoDropArea.h
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#include <QQuickItem>
|
||||||
|
|
||||||
|
class NhekoDropArea : public QQuickItem
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(QString roomid READ roomid WRITE setRoomid NOTIFY roomidChanged)
|
||||||
|
public:
|
||||||
|
NhekoDropArea(QQuickItem *parent = nullptr);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void roomidChanged(QString roomid);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void setRoomid(QString roomid)
|
||||||
|
{
|
||||||
|
if (roomid_ != roomid) {
|
||||||
|
roomid_ = roomid;
|
||||||
|
emit roomidChanged(roomid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
QString roomid() const { return roomid_; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void dragEnterEvent(QDragEnterEvent *event) override;
|
||||||
|
void dragMoveEvent(QDragMoveEvent *event) override;
|
||||||
|
void dropEvent(QDropEvent *event) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString roomid_;
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user