Newer
Older
* This file is part of project OpenEmbroidery. It's copyrighted by
* the contributors recorded in the version control history of the file.
* Original project location https://code.electrolab.fr/openEmbroidery/openEmbroidery_software
*
* SPDX-License-Identifier: CECILL-2.1
* License-Filename: Licence_CeCILL_V2.1-en.txt
*/
#include "OE_display.h"
#include "OE_utils.h"
#include "OE_preferences.h"
#include <iostream>
#include <GL/gl.h>
#include <cstdlib>
#include <math.h>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <QMimeData>
#include <QTabWidget>
#include <iostream>
#include <sstream>
#include <string>
OE_display::OE_display(QWidget* parent, Qt::WindowFlags f) : QOpenGLWidget(parent, f), zoom(1.0), pan(false), width(0), height(0)
{
}
//DEBUG printf("MouseEvent pos %d, %d\n", event->pos().x(), event->pos().y()); fflush(stdout);
event->accept();
bool redraw = mouse_Pos(event->pos().x(), event->pos().y());
if (redraw)
update();
//TODO ? repaint();
void OE_display::mousePressEvent(QMouseEvent* event)
{
event->accept();
bool redraw = mouse_Button(event);
if (redraw)
update();
}
void OE_display::mouseReleaseEvent(QMouseEvent* event)
{
event->accept();
bool redraw = mouse_Button(event);
if (redraw)
update();
}
void OE_display::wheelEvent(QWheelEvent* event)
{
event->accept();
OE_display::scroll(0, event->delta());
update();
}
static bool endsWith(const std::string& str, const std::string& suffix)
{
return str.size() >= suffix.size() && 0 == str.compare(str.size()-suffix.size(), suffix.size(), suffix);
}
static std::vector<std::string> getAllowedFiles(QDropEvent *event)
{
std::vector<std::string> uris;
if (event->mimeData()->hasFormat("text/uri-list"))
{
for (const QUrl& qurl : event->mimeData()->urls())
if (!qurl.isLocalFile())
std::string url = qurl.toLocalFile().toStdString();
std::string urlLower = url;
std::transform(urlLower.begin(), urlLower.end(), urlLower.begin(), ::tolower);
if (!(endsWith(urlLower, ".oe") || endsWith(urlLower, ".svg") || endsWith(urlLower, ".pes")))
uris.push_back(url);
}
}
return uris;
}
void OE_display::dragEnterEvent(QDragEnterEvent *event)
{
std::vector<std::string> files = getAllowedFiles(event);
if (files.size() != 1)
{
event->ignore();
return;
}
event->setDropAction(Qt::MoveAction);
event->accept();
}
void OE_display::dropEvent(QDropEvent *event)
{
event->acceptProposedAction();
loadFile(getAllowedFiles(event).front());
}
void OE_display::loadFile(std::string file)
{
std::string fileLower = file;
std::transform(fileLower.begin(), fileLower.end(), fileLower.begin(), ::tolower);
OE_document* newDoc = nullptr;
printf("Importing file from %s\n", file.c_str());
newDoc = new OE_document();
if (!newDoc->loadFromFile(file))
}
if (newDoc)
{
OE_document* oldDoc = document;
document = newDoc;
if (oldDoc)
delete oldDoc;
if (controller)
{
controller->setDocument(newDoc);
controller->initNewDocument();
}
setDocument(newDoc);
showAll();
raoul
committed
QTabWidget* tabWidget = dynamic_cast<QTabWidget*>(this->parent()->parent()->parent());
int idx = tabWidget->indexOf(dynamic_cast<QWidget*>(this->parent()));
tabWidget->setTabText(idx, QString::fromStdString(file.substr(file.rfind('/')+1)));
tabWidget->setTabToolTip(idx, QString::fromStdString(file));
initializeOpenGLFunctions();
glEnable(GL_POINT_SMOOTH);
glEnable(GL_LINE_SMOOTH);
}
void OE_display::resizeGL(int w, int h)
{
resize(w, h);
update();
}
void OE_display::paintGL()
{
draw();
}
/** \brief draw the document on screen
*
* \return true if all is ok
*
*/
{
this->document = document;
std::list<OE_pointcurve*>::iterator curve = document->curves.begin();
while (curve != document->curves.end())
(*curve)->refresh(zoom/2);
curve++;
}*/
refreshAll();
return true;
}
bool OE_display::setController(OE_controller* controller)
this->controller = controller;
return true;
}
bool OE_display::setDisplayStyle(OE_displayStyle* style)
{
Loading full blame...