implement drag-n-drop for files
This commit is contained in:
@ -3,7 +3,6 @@ LAMMPS-GUI TODO list:
|
|||||||
# Short term goals
|
# Short term goals
|
||||||
|
|
||||||
- add indicator for when the file in editor is modified (-> status bar?)
|
- add indicator for when the file in editor is modified (-> status bar?)
|
||||||
- add support for drag-n-drop of files into the editor
|
|
||||||
- add "Help" entry to menu bar. Should open a popup window with a one page description of how to use it. Use HTML or Markdown text.
|
- add "Help" entry to menu bar. Should open a popup window with a one page description of how to use it. Use HTML or Markdown text.
|
||||||
- add dialog when exiting asking if file should be saved when it is modified, similar dialog when opening a new file
|
- add dialog when exiting asking if file should be saved when it is modified, similar dialog when opening a new file
|
||||||
- add CTRL-q hotkey to log windows so you can exit the entire application (add do you really want to? dialog to this)
|
- add CTRL-q hotkey to log windows so you can exit the entire application (add do you really want to? dialog to this)
|
||||||
|
|||||||
@ -13,7 +13,11 @@
|
|||||||
|
|
||||||
#include "codeeditor.h"
|
#include "codeeditor.h"
|
||||||
#include "linenumberarea.h"
|
#include "linenumberarea.h"
|
||||||
|
#include "lammpsgui.h"
|
||||||
|
|
||||||
|
#include <QDragEnterEvent>
|
||||||
|
#include <QDropEvent>
|
||||||
|
#include <QMimeData>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QTextBlock>
|
#include <QTextBlock>
|
||||||
|
|
||||||
@ -58,6 +62,29 @@ void CodeEditor::updateLineNumberArea(const QRect &rect, int dy)
|
|||||||
if (rect.contains(viewport()->rect())) updateLineNumberAreaWidth(0);
|
if (rect.contains(viewport()->rect())) updateLineNumberAreaWidth(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CodeEditor::dragEnterEvent(QDragEnterEvent *event)
|
||||||
|
{
|
||||||
|
event->acceptProposedAction();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CodeEditor::canInsertFromMimeData(const QMimeData *source) const
|
||||||
|
{
|
||||||
|
return source->hasUrls(); // || source->hasText();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CodeEditor::dropEvent(QDropEvent *event)
|
||||||
|
{
|
||||||
|
event->acceptProposedAction();
|
||||||
|
if (event->mimeData()->hasUrls()) {
|
||||||
|
auto file = event->mimeData()->urls()[0].url().remove("file://");
|
||||||
|
auto gui = dynamic_cast<LammpsGui *>(parent());
|
||||||
|
if (gui) gui->open_file(file);
|
||||||
|
} else if (event->mimeData()->hasText()) {
|
||||||
|
fprintf(stderr, "Drag - Drop for text block not yet implemented: text=%s\n",
|
||||||
|
event->mimeData()->text().toStdString().c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CodeEditor::resizeEvent(QResizeEvent *e)
|
void CodeEditor::resizeEvent(QResizeEvent *e)
|
||||||
{
|
{
|
||||||
QPlainTextEdit::resizeEvent(e);
|
QPlainTextEdit::resizeEvent(e);
|
||||||
|
|||||||
@ -27,6 +27,9 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
void resizeEvent(QResizeEvent *event) override;
|
void resizeEvent(QResizeEvent *event) override;
|
||||||
|
void dragEnterEvent(QDragEnterEvent *event) override;
|
||||||
|
bool canInsertFromMimeData(const QMimeData *source) const override;
|
||||||
|
void dropEvent(QDropEvent *event) override;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void updateLineNumberAreaWidth(int newBlockCount);
|
void updateLineNumberAreaWidth(int newBlockCount);
|
||||||
|
|||||||
@ -79,7 +79,8 @@ LammpsGui::LammpsGui(QWidget *parent, const char *filename) :
|
|||||||
|
|
||||||
#if defined(LAMMPS_GUI_USE_PLUGIN)
|
#if defined(LAMMPS_GUI_USE_PLUGIN)
|
||||||
liblammpsplugin_t *lammps = nullptr;
|
liblammpsplugin_t *lammps = nullptr;
|
||||||
for (const auto libfile : {"liblammps.so", "./liblammps.so", "liblammps.dylib", "./liblammps.dylib", "liblammps.dll"}) {
|
for (const auto libfile : {"liblammps.so", "./liblammps.so", "liblammps.dylib",
|
||||||
|
"./liblammps.dylib", "liblammps.dll"}) {
|
||||||
if (!lammps) lammps = liblammpsplugin_load(libfile);
|
if (!lammps) lammps = liblammpsplugin_load(libfile);
|
||||||
if (lammps) {
|
if (lammps) {
|
||||||
plugin_path = libfile;
|
plugin_path = libfile;
|
||||||
@ -106,7 +107,6 @@ LammpsGui::LammpsGui(QWidget *parent, const char *filename) :
|
|||||||
progress->setRange(0, 1000);
|
progress->setRange(0, 1000);
|
||||||
progress->setFixedWidth(500);
|
progress->setFixedWidth(500);
|
||||||
ui->statusbar->addWidget(progress);
|
ui->statusbar->addWidget(progress);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LammpsGui::~LammpsGui()
|
LammpsGui::~LammpsGui()
|
||||||
@ -141,7 +141,6 @@ void LammpsGui::open()
|
|||||||
// open file and switch CWD to path of file
|
// open file and switch CWD to path of file
|
||||||
void LammpsGui::open_file(const QString &fileName)
|
void LammpsGui::open_file(const QString &fileName)
|
||||||
{
|
{
|
||||||
|
|
||||||
QFileInfo path(fileName);
|
QFileInfo path(fileName);
|
||||||
current_file = path.fileName();
|
current_file = path.fileName();
|
||||||
current_dir = path.absolutePath();
|
current_dir = path.absolutePath();
|
||||||
@ -393,7 +392,7 @@ void LammpsGui::about()
|
|||||||
#else
|
#else
|
||||||
version += " - LAMMPS linked statically";
|
version += " - LAMMPS linked statically";
|
||||||
#endif
|
#endif
|
||||||
std::string info = "LAMMPS is currently running. LAMMPS config info not available.";
|
std::string info = "LAMMPS is currently running. LAMMPS config info not available.";
|
||||||
|
|
||||||
// LAMMPS is not re-entrant, so we can only query LAMMPS when it is not running
|
// LAMMPS is not re-entrant, so we can only query LAMMPS when it is not running
|
||||||
if (!is_running) {
|
if (!is_running) {
|
||||||
|
|||||||
@ -36,9 +36,10 @@ class StdCapture;
|
|||||||
class LammpsGui : public QMainWindow {
|
class LammpsGui : public QMainWindow {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
friend class CodeEditor;
|
||||||
public:
|
public:
|
||||||
LammpsGui(QWidget *parent = nullptr, const char *filename = nullptr);
|
LammpsGui(QWidget *parent = nullptr, const char *filename = nullptr);
|
||||||
~LammpsGui();
|
~LammpsGui() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void open_file(const QString &filename);
|
void open_file(const QString &filename);
|
||||||
|
|||||||
@ -25,7 +25,11 @@
|
|||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
<item>
|
<item>
|
||||||
<widget class="CodeEditor" name="textEdit" native="true"/>
|
<widget class="CodeEditor" name="textEdit" native="true">
|
||||||
|
<property name="acceptDrops">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
@ -303,7 +307,7 @@
|
|||||||
<customwidgets>
|
<customwidgets>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
<class>CodeEditor</class>
|
<class>CodeEditor</class>
|
||||||
<extends>QWidget</extends>
|
<extends>QPlainTextEdit</extends>
|
||||||
<header>codeeditor.h</header>
|
<header>codeeditor.h</header>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
</customwidgets>
|
</customwidgets>
|
||||||
|
|||||||
Reference in New Issue
Block a user