Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
Signed-off-by: Vinayakjeet Singh Karki <[email protected]>
  • Loading branch information
vinayakjeet committed Apr 2, 2024
1 parent 6645452 commit f3c3d13
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 20 deletions.
79 changes: 60 additions & 19 deletions avogadro/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
#include <QtCore/QString>
#include <QtCore/QThread>
#include <QtCore/QTimer>

#include <QMouseEvent>
#include <QOpenGLFramebufferObject>
#include <QtGui/QClipboard>
#include <QtGui/QCloseEvent>
Expand Down Expand Up @@ -228,6 +228,7 @@ using VTK::vtkGLWidget;
#endif

MainWindow::MainWindow(const QStringList& fileNames, bool disableSettings)
: QMainWindow(/* parent */), dragStartPosition()
: m_molecule(nullptr)
, m_rwMolecule(nullptr)
, m_moleculeModel(nullptr)
Expand Down Expand Up @@ -357,6 +358,47 @@ MainWindow::~MainWindow()
delete m_viewFactory;
}

void MainWindow::mousePressEvent(QMouseEvent* event)
{
if (event->button() == Qt::LeftButton)
dragStartPosition = event->pos();
}

void MainWindow::mouseMoveEvent(QMouseEvent* event)
{
if (!(event->buttons() & Qt::LeftButton))
return;
if ((event->pos() - dragStartPosition).manhattanLength() < QApplication::startDragDistance())
return;

performDrag();
}

void MainWindow::performDrag()
{
// Assuming you have a method to get the currently selected molecule as a string in a specific format
QString moleculeData = /* method to get molecule data */;
if (moleculeData.isEmpty())
return;

auto* mimeData = new QMimeData;
mimeData->setText(moleculeData); // For demonstration, using plain text. Adjust based on actual data format.

// Create a drag object
auto* drag = new QDrag(this);
drag->setMimeData(mimeData);

// You can set an appropriate pixmap for the drag object if you like
// QPixmap pixmap(iconSize);
// QPainter painter(&pixmap);
// painter.drawPixmap(QPoint(), /* your pixmap here */);
// painter.end();
// drag->setPixmap(pixmap);

// Execute the drag operation
drag->exec(Qt::CopyAction | Qt::MoveAction);
}

void MainWindow::setupInterface()
{
// We take care of setting up the main interface here, along with any custom
Expand Down Expand Up @@ -524,30 +566,29 @@ void MainWindow::dragEnterEvent(QDragEnterEvent* event)
}
void MainWindow::dropEvent(QDropEvent* event)
{
const QMimeData* mimeData = event->mimeData();

if (mimeData->hasUrls()) {
QList<QUrl> urlList = mimeData->urls();
.
for (int i = 0; i < urlList.size() && i < 10; ++i) {
QString filePath = urlList.at(i).toLocalFile();
openFile(filePath);
if (event->mimeData()->hasUrls()) {
QList<QUrl> urls = event->mimeData()->urls();
for (const QUrl &url : urls) {
if (url.isLocalFile()) {
QString fileName = url.toLocalFile();
QFileInfo info(fileName);

// Distinguish Python scripts for special handling
if (info.suffix().compare("py", Qt::CaseInsensitive) == 0) {
addScript(fileName);
} else {

openFile(fileName);
}
}
}
event->acceptProposedAction();
}

else if (mimeData->hasText()) {

QString textData = mimeData->text();

event->acceptProposedAction();
}

else {
} else {
event->ignore();
}
}


void MainWindow::moleculeReady(int)
{
auto* extension = qobject_cast<ExtensionPlugin*>(sender());
Expand Down
8 changes: 7 additions & 1 deletion avogadro/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include <QtCore/QStringList>
#include <QtCore/QVariantMap>
#include <QtWidgets/QMainWindow>
#include <QMimeData>
#include <QDrag>

#ifdef QTTESTING
class pqTestUtility;
Expand Down Expand Up @@ -161,6 +163,9 @@ public slots:
void moleculeChanged(QtGui::Molecule* molecue);

protected:
void mousePressEvent(QMouseEvent* event) override;
void mouseMoveEvent(QMouseEvent* event) override;

void closeEvent(QCloseEvent* event);

// Handle drag and drop -- accept files dragged on the window
Expand Down Expand Up @@ -391,6 +396,7 @@ private slots:
void setProjectionPerspective();

private:
QPoint dragStartPosition; // To store the start position of a drag operation
QtGui::Molecule* m_molecule;
QtGui::RWMolecule* m_rwMolecule;
QtGui::MoleculeModel* m_moleculeModel;
Expand Down Expand Up @@ -478,7 +484,7 @@ private slots:
* Initialize the tool plugins.
*/
void buildTools();

void performDrag();
/**
* Convenience function that converts a file extension to a wildcard
* expression, e.g. "out" to "*.out". This method also checks for "extensions"
Expand Down

0 comments on commit f3c3d13

Please sign in to comment.