Implement Qml drag and drop

pull/335/head
Nicolas Werner 4 years ago
parent 0eb8d4126b
commit c74077a41f
  1. 12
      CMakeLists.txt
  2. 5
      resources/qml/MessageInput.qml
  3. 1
      src/ChatPage.h
  4. 8
      src/timeline/InputBar.cpp
  5. 2
      src/timeline/InputBar.h
  6. 3
      src/timeline/TimelineViewManager.cpp
  7. 9
      src/timeline/TimelineViewManager.h
  8. 39
      src/ui/NhekoDropArea.cpp
  9. 30
      src/ui/NhekoDropArea.h

@ -257,22 +257,23 @@ set(SRC_FILES
src/ui/Avatar.cpp
src/ui/Badge.cpp
src/ui/DropShadow.cpp
src/ui/LoadingIndicator.cpp
src/ui/InfoMessage.cpp
src/ui/FlatButton.cpp
src/ui/FloatingButton.cpp
src/ui/InfoMessage.cpp
src/ui/Label.cpp
src/ui/LoadingIndicator.cpp
src/ui/NhekoDropArea.cpp
src/ui/OverlayModal.cpp
src/ui/SnackBar.cpp
src/ui/OverlayWidget.cpp
src/ui/RaisedButton.cpp
src/ui/Ripple.cpp
src/ui/RippleOverlay.cpp
src/ui/OverlayWidget.cpp
src/ui/SnackBar.cpp
src/ui/TextField.cpp
src/ui/TextLabel.cpp
src/ui/ToggleButton.cpp
src/ui/Theme.cpp
src/ui/ThemeManager.cpp
src/ui/ToggleButton.cpp
src/ui/UserProfile.cpp
src/AvatarProvider.cpp
@ -471,6 +472,7 @@ qt5_wrap_cpp(MOC_HEADERS
src/ui/Label.h
src/ui/FloatingButton.h
src/ui/Menu.h
src/ui/NhekoDropArea.h
src/ui/OverlayWidget.h
src/ui/SnackBar.h
src/ui/RaisedButton.h

@ -178,6 +178,11 @@ Rectangle {
onClicked: TimelineManager.timeline.input.paste(true)
}
NhekoDropArea {
anchors.fill: parent
roomid: TimelineManager.timeline.roomId()
}
background: Rectangle {
color: colors.window
}

@ -88,6 +88,7 @@ public:
QSharedPointer<UserSettings> userSettings() { return userSettings_; }
CallManager *callManager() { return callManager_; }
TimelineViewManager *timelineManager() { return view_manager_; }
void deleteConfigs();
CommunitiesList *communitiesList() { return communitiesList_; }

@ -1,6 +1,7 @@
#include "InputBar.h"
#include <QClipboard>
#include <QDropEvent>
#include <QFileDialog>
#include <QGuiApplication>
#include <QMimeData>
@ -44,6 +45,13 @@ InputBar::paste(bool fromMouse)
md = QGuiApplication::clipboard()->mimeData(QClipboard::Clipboard);
}
if (md)
insertMimeData(md);
}
void
InputBar::insertMimeData(const QMimeData *md)
{
if (!md)
return;

@ -9,6 +9,7 @@
class TimelineModel;
class QMimeData;
class QDropEvent;
class QStringList;
class InputBar : public QObject
@ -36,6 +37,7 @@ public slots:
void send();
void paste(bool fromMouse);
void insertMimeData(const QMimeData *data);
void updateState(int selectionStart, int selectionEnd, int cursorPosition, QString text);
void openFileSelection();
bool uploading() const { return uploading_; }

@ -1,6 +1,7 @@
#include "TimelineViewManager.h"
#include <QDesktopServices>
#include <QDropEvent>
#include <QMetaType>
#include <QPalette>
#include <QQmlContext>
@ -20,6 +21,7 @@
#include "dialogs/ImageOverlay.h"
#include "emoji/EmojiModel.h"
#include "emoji/Provider.h"
#include "ui/NhekoDropArea.h"
#include <iostream> //only for debugging
@ -115,6 +117,7 @@ TimelineViewManager::TimelineViewManager(CallManager *callManager, ChatPage *par
qmlRegisterType<DelegateChoice>("im.nheko", 1, 0, "DelegateChoice");
qmlRegisterType<DelegateChooser>("im.nheko", 1, 0, "DelegateChooser");
qmlRegisterType<NhekoDropArea>("im.nheko", 1, 0, "NhekoDropArea");
qmlRegisterUncreatableType<DeviceVerificationFlow>(
"im.nheko", 1, 0, "DeviceVerificationFlow", "Can't create verification flow from QML!");
qmlRegisterUncreatableType<UserProfile>(

@ -105,6 +105,15 @@ public slots:
void initWithMessages(const std::vector<QString> &roomIds);
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 queueReactionMessage(const QString &reactedEvent, const QString &reactionKey);
void queueCallMessage(const QString &roomid, const mtx::events::msg::CallInvite &);

@ -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());
}
}
}

@ -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…
Cancel
Save