Skip to content

Commit

Permalink
Timeline: accept dropped items
Browse files Browse the repository at this point in the history
Dropped files will be attached, dropped text will appear in the
input line.
  • Loading branch information
rpallai committed Jun 30, 2019
1 parent dbda393 commit f847494
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
14 changes: 14 additions & 0 deletions client/chatroomwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -798,3 +798,17 @@ bool ChatRoomWidget::pendingMarkRead() const
const auto rm = m_currentRoom->readMarker();
return rm != m_currentRoom->timelineEdge() && rm->index() < indexToMaybeRead;
}

void ChatRoomWidget::fileDrop(const QString& url)
{
attachedFileName = QUrl(url).path();
m_attachAction->setChecked(true);
m_chatEdit->setPlaceholderText(
tr("Add a message to the file or just push Enter"));
emit showStatusMessage(tr("Attaching %1").arg(attachedFileName));
}

void ChatRoomWidget::textDrop(const QString& text)
{
m_chatEdit->setText(text);
}
2 changes: 2 additions & 0 deletions client/chatroomwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ class ChatRoomWidget: public QWidget
void saveFileAs(QString eventId);
void quote(const QString& htmlText);
void showMenu(int index, const QString& hoveredLink, bool showingDetails);
void fileDrop(const QString& url);
void textDrop(const QString& text);

private slots:
void sendInput();
Expand Down
14 changes: 14 additions & 0 deletions client/qml/Timeline.qml
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,20 @@ Rectangle {
? Qt.ScrollBarAlwaysOff : Qt.ScrollBarAlwaysOn
style: ScrollViewStyle { transientScrollBars: true }

DropArea {
anchors.fill: parent
onEntered: if (!room) { drag.accepted = false }
onDropped: {
if (drop.hasUrls) {
controller.fileDrop(drop.urls)
drop.acceptProposedAction()
} else if (drop.hasText) {
controller.textDrop(drop.text)
drop.acceptProposedAction()
}
}
}

ListView {
id: chatView

Expand Down

0 comments on commit f847494

Please sign in to comment.