Skip to content

Commit

Permalink
can now pan and zoom in preview window, added automatic detection of …
Browse files Browse the repository at this point in the history
…best KLD settings
  • Loading branch information
Theverat committed Oct 25, 2014
1 parent 3f518ac commit a430793
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 5 deletions.
23 changes: 23 additions & 0 deletions graphicsview.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "graphicsview.h"
#include <QMimeData>
#include <QDropEvent>
#include <iostream>

GraphicsView::GraphicsView(QGraphicsScene *scene, QWidget *parent) : QGraphicsView(scene, parent)
{
Expand Down Expand Up @@ -31,3 +32,25 @@ void GraphicsView::dropEvent(QDropEvent* event) {
}
}
}

void GraphicsView::mouseReleaseEvent(QMouseEvent *event) {
QGraphicsView::mouseReleaseEvent(event);

if(event->button() == Qt::RightButton) {
//rightclick -> reset image scale to 1:1
emit rightClick();
}
else if(event->button() == Qt::MiddleButton) {
//middle click -> fit image to view
emit middleClick();
}
}

void GraphicsView::wheelEvent(QWheelEvent *event) {
if(event->delta() > 0) {
emit zoomIn();
}
else {
emit zoomOut();
}
}
8 changes: 7 additions & 1 deletion graphicsview.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,17 @@ class GraphicsView : public QGraphicsView
void dragEnterEvent(QDragEnterEvent* event);
void dragMoveEvent(QDragMoveEvent* event);
void dropEvent(QDropEvent* event);

void mouseReleaseEvent(QMouseEvent* event);
void wheelEvent(QWheelEvent *event);

signals:
void singleImageDropped(QUrl url);
void multipleImagesDropped(QList<QUrl> urls);
void folderDropped(QUrl url);
void rightClick();
void middleClick();
void zoomIn();
void zoomOut();
};

#endif // GRAPHICSVIEW_H
32 changes: 30 additions & 2 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ MainWindow::MainWindow(QWidget *parent) :
GraphicsScene *scene = new GraphicsScene();
ui->graphicsView->setScene(scene);
scene->setBackgroundBrush(QBrush(Qt::darkGray));
ui->graphicsView->setDragMode(QGraphicsView::ScrollHandDrag);
scene->addText("Start by dragging images here.");
ui->graphicsView->setRenderHints(QPainter::HighQualityAntialiasing | QPainter::SmoothPixmapTransform);
ui->graphicsView->setAcceptDrops(true);
Expand Down Expand Up @@ -116,7 +117,21 @@ bool MainWindow::load(QUrl url) {
ui->checkBox_displayChannelIntensity->setEnabled(true);
ui->spinBox_normalmapSize->setEnabled(true);
enableAutoupdate(true);
//TODO: algorithm to find best settings for KeepLargeDetail

//algorithm to find best settings for KeepLargeDetail
int imageSize = std::max(input.width(), input.height());

int largeDetailScale = -0.037 * imageSize + 100;
ui->checkBox_keepLargeDetail->setChecked(true);

if(imageSize < 300) {
ui->checkBox_keepLargeDetail->setChecked(false);
}
else if(imageSize > 2300) {
largeDetailScale = 20;
}

ui->spinBox_largeDetailScale->setValue(largeDetailScale);

//switch active tab to input
ui->tabWidget->setCurrentIndex(0);
Expand All @@ -132,6 +147,13 @@ bool MainWindow::load(QUrl url) {
displayChannelIntensity();
else
preview(0);

//image smaller than graphicsview: fitInView, then resetZoom (this way it is centered)
//image larger than graphicsview: just fitInView
fitInView();
if(input.width() < ui->graphicsView->width() || input.height() < ui->graphicsView->height()) {
resetZoom();
}

ui->statusBar->clearMessage();

Expand Down Expand Up @@ -455,7 +477,8 @@ void MainWindow::preview(int tab) {
pixmap->setTransformationMode(Qt::SmoothTransformation);
}
else {
ui->graphicsView->scene()->addPixmap(QPixmap::fromImage(input));
QGraphicsPixmapItem *pixmap = ui->graphicsView->scene()->addPixmap(QPixmap::fromImage(input));
pixmap->setTransformationMode(Qt::SmoothTransformation);
}
break;
}
Expand Down Expand Up @@ -710,6 +733,11 @@ void MainWindow::connectSignalSlots() {
//graphicsview drag and drop
connect(ui->graphicsView, SIGNAL(singleImageDropped(QUrl)), this, SLOT(loadSingleDropped(QUrl)));
connect(ui->graphicsView, SIGNAL(multipleImagesDropped(QList<QUrl>)), this, SLOT(loadMultipleDropped(QList<QUrl>)));
//graphicsview rightclick/middleclick/zoom
connect(ui->graphicsView, SIGNAL(rightClick()), this, SLOT(resetZoom()));
connect(ui->graphicsView, SIGNAL(middleClick()), this, SLOT(fitInView()));
connect(ui->graphicsView, SIGNAL(zoomIn()), this, SLOT(zoomIn()));
connect(ui->graphicsView, SIGNAL(zoomOut()), this, SLOT(zoomOut()));
//queue (item widget)
connect(ui->pushButton_removeImagesFromQueue, SIGNAL(clicked()), this, SLOT(removeImagesFromQueue()));
connect(ui->pushButton_processQueue, SIGNAL(clicked()), this, SLOT(processQueue()));
Expand Down
11 changes: 9 additions & 2 deletions mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,9 @@
<property name="text">
<string>Keep Large Detail</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>true</bool>
</property>
Expand Down Expand Up @@ -1081,7 +1084,11 @@
</widget>
</item>
<item>
<widget class="GraphicsView" name="graphicsView"/>
<widget class="GraphicsView" name="graphicsView">
<property name="dragMode">
<enum>QGraphicsView::NoDrag</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
Expand Down Expand Up @@ -1326,7 +1333,7 @@
</connection>
</connections>
<buttongroups>
<buttongroup name="buttonGroup_exportFolder"/>
<buttongroup name="buttonGroup_displayChannelIntensity"/>
<buttongroup name="buttonGroup_exportFolder"/>
</buttongroups>
</ui>

0 comments on commit a430793

Please sign in to comment.