Commit 75b70fcb authored by Tomaz  Canabrava's avatar Tomaz Canabrava
Browse files

Drag Drop files from konsole to other softwares

parent a66d2e23
......@@ -18,6 +18,8 @@
#include <QMouseEvent>
#include <QKeyEvent>
#include <QRegularExpression>
#include <QDrag>
#include <QMimeData>
#include <KIO/ApplicationLauncherJob>
#include <KIO/OpenUrlJob>
......@@ -28,6 +30,7 @@
#include <KMessageBox>
#include <KShell>
#include "konsoledebug.h"
#include "KonsoleSettings.h"
#include "profile/Profile.h"
......@@ -300,8 +303,33 @@ void FileFilterHotSpot::mouseLeaveEvent(TerminalDisplay *td, QMouseEvent *ev)
stopThumbnailGeneration();
}
void Konsole::FileFilterHotSpot::keyPressEvent(Konsole::TerminalDisplay* td, QKeyEvent* ev)
void FileFilterHotSpot::keyPressEvent(Konsole::TerminalDisplay* td, QKeyEvent* ev)
{
HotSpot::keyPressEvent(td, ev);
requestThumbnail(ev->modifiers(), QCursor::pos());
}
bool FileFilterHotSpot::hasDragOperation() const
{
return true;
}
void FileFilterHotSpot::startDrag()
{
auto *drag = new QDrag(this);
auto *mimeData = new QMimeData();
mimeData->setUrls({QUrl::fromLocalFile(_filePath)});
auto lowerFilePath = _filePath.toLower();
if (lowerFilePath.endsWith(QStringLiteral("png"))
|| lowerFilePath.endsWith(QStringLiteral("jpg"))
|| lowerFilePath.endsWith(QStringLiteral("jpeg"))) {
mimeData->setImageData(QImage(_filePath));
}
drag->setMimeData(mimeData);
Qt::DropAction result = drag->exec(Qt::CopyAction);
qDebug() << "result" << result;
}
......@@ -49,6 +49,9 @@ public:
void requestThumbnail(Qt::KeyboardModifiers modifiers, const QPoint &pos);
void thumbnailRequested();
bool hasDragOperation() const override;
void startDrag() override;
static void stopThumbnailGeneration();
void mouseEnterEvent(TerminalDisplay *td, QMouseEvent *ev) override;
......
......@@ -185,3 +185,13 @@ void HotSpot::debug() {
qDebug() << type();
qDebug() << _startLine << _endLine << _startColumn << _endColumn;
}
bool Konsole::HotSpot::hasDragOperation() const
{
return false;
}
void Konsole::HotSpot::startDrag()
{
}
......@@ -92,6 +92,9 @@ public:
*/
virtual QList<QAction *> actions();
virtual bool hasDragOperation() const;
virtual void startDrag();
/**
* Setups a menu with actions for the hotspot.
*/
......
......@@ -1165,6 +1165,11 @@ void TerminalDisplay::mousePressEvent(QMouseEvent* ev)
processFilters();
_filterChain->mouseMoveEvent(this, ev, charLine, charColumn);
auto hotSpotClick = _filterChain->hotSpotAt(charLine, charColumn);
if (hotSpotClick && hotSpotClick->hasDragOperation() && ev->modifiers() & Qt::Modifier::ALT) {
hotSpotClick->startDrag();
return;
}
if (ev->button() == Qt::LeftButton) {
// request the software keyboard, if any
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment