mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-19 18:40:13 -06:00
SqlTextEdit: Support opening files by drag and drop
When dropping a file on the editor widget try to open and read it.
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include <QScrollBar>
|
||||
#include <QPainter>
|
||||
#include <QTextBlock>
|
||||
#include <QUrl>
|
||||
|
||||
SqlTextEdit::SqlTextEdit(QWidget* parent) :
|
||||
QPlainTextEdit(parent), m_Completer(0), m_defaultCompleterModel(0)
|
||||
@@ -181,6 +182,22 @@ void SqlTextEdit::LineNumberArea::paintEvent(QPaintEvent* event)
|
||||
}
|
||||
}
|
||||
|
||||
void SqlTextEdit::dropEvent(QDropEvent* e)
|
||||
{
|
||||
QList<QUrl> urls = e->mimeData()->urls();
|
||||
if(urls.isEmpty())
|
||||
return QPlainTextEdit::dropEvent(e);
|
||||
|
||||
QString file = urls.first().toLocalFile();
|
||||
if(!QFile::exists(file))
|
||||
return;
|
||||
|
||||
QFile f(file);
|
||||
f.open(QIODevice::ReadOnly);
|
||||
setPlainText(f.readAll());
|
||||
f.close();
|
||||
}
|
||||
|
||||
QSize SqlTextEdit::LineNumberArea::sizeHint() const
|
||||
{
|
||||
return QSize(parent->lineNumberAreaWidth(), 0);
|
||||
|
||||
@@ -32,6 +32,7 @@ protected:
|
||||
void keyPressEvent(QKeyEvent *e);
|
||||
void focusInEvent(QFocusEvent *e);
|
||||
void resizeEvent(QResizeEvent* event);
|
||||
void dropEvent(QDropEvent* e);
|
||||
|
||||
void lineNumberAreaPaintEvent(QPaintEvent* event);
|
||||
int lineNumberAreaWidth();
|
||||
|
||||
Reference in New Issue
Block a user