Newer
Older
/*
* Copyright (c) 2015 Tricoire Sebastien 3dsman@free.fr
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*
*/
#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++;
Loading full blame...