//load images using the file dialog
void MainWindow::loadUserFilePath() {
    QList<QUrl> urls = QFileDialog::getOpenFileUrls(this,
                                                     "Open Image File",
                                                     QDir::homePath(),
                                                     "Image Formats (*.png *.jpg *.jpeg *.tiff *.ppm *.bmp *.xpm *.tga)");
    loadMultipleDropped(urls);
}
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    //connect signals of GUI elements with slots of this class
    connectSignalSlots();

    //hide advanced settings and connect signals/slots to show them
    hideAdvancedSettings();

    //initialize graphicsview
    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);

    //initialize QImage objects to store the calculated maps
    input = QImage();
    channelIntensity = QImage();
    normalmap = QImage();
    specmap = QImage();
    displacementmap = QImage();
    ssaomap = QImage();

    //initialize calctimes
    lastCalctime_normal = 0;
    lastCalctime_specular = 0;
    lastCalctime_displace = 0;
    lastCalctime_ssao = 0;

    //initialize stopQueue flag
    stopQueue = false;

    //show default status message
    ui->statusBar->showMessage("Drag images into the empty preview window to load them.");

    //hide queue progressbar
    ui->progressBar_Queue->hide();

    //if the program was opened via "open with" by the OS, extract the image paths from the arguments
    //(args[0] is the name of the application)
    QStringList args = QCoreApplication::arguments();
    if(args.size() > 1) {
        QList<QUrl> imageUrls;

        for(int i = 1; i < args.size(); i++) {
            imageUrls.append(QUrl::fromLocalFile(args[i]));
        }

        loadMultipleDropped(imageUrls);
    }
}
Esempio n. 3
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow),
    lastCalctime_normal(0),
    lastCalctime_specular(0),
    lastCalctime_displace(0),
    lastCalctime_ssao(0),
    stopQueue(false)
{
    ui->setupUi(this);

    supportedImageformats << "*.png" << "*.jpg" << "*.jpeg" << "*.tiff"
                          << "*.tif" << "*.ppm" << "*.bmp"  << "*.xpm"
                          << "*.tga" << "*.gif";

    //connect signals of GUI elements with slots of this class
    connectSignalSlots();

    //hide advanced settings and connect signals/slots to show them
    hideAdvancedSettings();

    //initialize graphicsview
    GraphicsScene *scene = new GraphicsScene();
    ui->graphicsView->setScene(scene);
    ui->graphicsView->setDragMode(QGraphicsView::ScrollHandDrag);
    scene->addText("Start by dragging images here.");
    ui->graphicsView->setRenderHints(QPainter::HighQualityAntialiasing
                                     | QPainter::SmoothPixmapTransform);
    ui->graphicsView->setAcceptDrops(true);

    //show default status message
    ui->statusBar->showMessage("Drag images into the empty preview window to load them.");

    //hide queue progressbar
    ui->progressBar_Queue->hide();
    
    // SSAO map generator is not ready yet, remove it from the UI
    ui->tabWidget->removeTab(4);

    //default UI colors
    useCustomUiColors = false;
    uiColorMainDefault = QColor("#444");
    uiColorTextDefault = QColor("#eee");
    uiColorGraphicsViewDefault = QColor(Qt::darkGray);
    uiColorMain = uiColorMainDefault;
    uiColorText = uiColorTextDefault;
    uiColorGraphicsView = uiColorGraphicsViewDefault;

    //read last window position and color settings from registry
    readSettings();

    //set UI colors
    setUiColors();

    //if the program was opened via "open with" by the OS,
    //extract the image paths from the arguments
    QStringList args = QCoreApplication::arguments();
    if(args.size() > 1) {
        QList<QUrl> imageUrls;

        for(int i = 1; i < args.size(); i++) {
            imageUrls.append(QUrl::fromLocalFile(args[i]));
        }

        loadMultipleDropped(imageUrls);
    }
}
//connects gui buttons with Slots in this class
void MainWindow::connectSignalSlots() {
    //connect signals/slots
    //load/save/open export folder
    connect(ui->pushButton_load, SIGNAL(clicked()), this, SLOT(loadUserFilePath()));
    connect(ui->pushButton_save, SIGNAL(clicked()), this, SLOT(saveUserFilePath()));
    connect(ui->pushButton_openExportFolder, SIGNAL(clicked()), this, SLOT(openExportFolder()));
    //zoom
    connect(ui->pushButton_zoomIn, SIGNAL(clicked()), this, SLOT(zoomIn()));
    connect(ui->pushButton_zoomOut, SIGNAL(clicked()), this, SLOT(zoomOut()));
    connect(ui->pushButton_resetZoom, SIGNAL(clicked()), this, SLOT(resetZoom()));
    connect(ui->pushButton_fitInView, SIGNAL(clicked()), this, SLOT(fitInView()));
    //calculate
    connect(ui->pushButton_calcNormal, SIGNAL(clicked()), this, SLOT(calcNormalAndPreview()));
    connect(ui->pushButton_calcSpec, SIGNAL(clicked()), this, SLOT(calcSpecAndPreview()));
    connect(ui->pushButton_calcDisplace, SIGNAL(clicked()), this, SLOT(calcDisplaceAndPreview()));
    connect(ui->pushButton_calcSsao, SIGNAL(clicked()), this, SLOT(calcSsaoAndPreview()));
    //switch between tabs
    connect(ui->tabWidget, SIGNAL(tabBarClicked(int)), this, SLOT(preview(int)));
    //display channel intensity
    connect(ui->checkBox_displayChannelIntensity, SIGNAL(clicked(bool)), this, SLOT(preview()));
    connect(ui->checkBox_displayChannelIntensity, SIGNAL(clicked(bool)), ui->radioButton_displayRed, SLOT(setEnabled(bool)));
    connect(ui->checkBox_displayChannelIntensity, SIGNAL(clicked(bool)), ui->radioButton_displayGreen, SLOT(setEnabled(bool)));
    connect(ui->checkBox_displayChannelIntensity, SIGNAL(clicked(bool)), ui->radioButton_displayBlue, SLOT(setEnabled(bool)));
    connect(ui->checkBox_displayChannelIntensity, SIGNAL(clicked(bool)), ui->radioButton_displayAlpha, SLOT(setEnabled(bool)));

    connect(ui->radioButton_displayRed, SIGNAL(clicked()), this, SLOT(displayChannelIntensity()));
    connect(ui->radioButton_displayGreen, SIGNAL(clicked()), this, SLOT(displayChannelIntensity()));
    connect(ui->radioButton_displayBlue, SIGNAL(clicked()), this, SLOT(displayChannelIntensity()));
    connect(ui->radioButton_displayAlpha, SIGNAL(clicked()), this, SLOT(displayChannelIntensity()));
    connect(ui->checkBox_displayChannelIntensity, SIGNAL(clicked()), this, SLOT(displayChannelIntensity()));
    //autoupdate after changed values
    // spec autoupdate
    connect(ui->doubleSpinBox_spec_redMul, SIGNAL(valueChanged(double)), this, SLOT(autoUpdate()));
    connect(ui->doubleSpinBox_spec_greenMul, SIGNAL(valueChanged(double)), this, SLOT(autoUpdate()));
    connect(ui->doubleSpinBox_spec_blueMul, SIGNAL(valueChanged(double)), this, SLOT(autoUpdate()));
    connect(ui->doubleSpinBox_spec_alphaMul, SIGNAL(valueChanged(double)), this, SLOT(autoUpdate()));
    connect(ui->doubleSpinBox_spec_scale, SIGNAL(valueChanged(double)), this, SLOT(autoUpdate()));
    connect(ui->comboBox_mode_spec, SIGNAL(currentIndexChanged(int)), this, SLOT(autoUpdate()));
    connect(ui->doubleSpinBox_spec_contrast, SIGNAL(valueChanged(double)), this, SLOT(autoUpdate()));
    // normal autoupdate
    connect(ui->checkBox_useRed_normal, SIGNAL(clicked()), this, SLOT(autoUpdate()));
    connect(ui->checkBox_useGreen_normal, SIGNAL(clicked()), this, SLOT(autoUpdate()));
    connect(ui->checkBox_useBlue_normal, SIGNAL(clicked()), this, SLOT(autoUpdate()));
    connect(ui->checkBox_useAlpha_normal, SIGNAL(clicked()), this, SLOT(autoUpdate()));
    connect(ui->comboBox_mode_normal, SIGNAL(currentIndexChanged(int)), this, SLOT(autoUpdate()));
    connect(ui->comboBox_method, SIGNAL(currentIndexChanged(int)), this, SLOT(autoUpdate()));
    connect(ui->doubleSpinBox_strength, SIGNAL(valueChanged(double)), this, SLOT(autoUpdate()));
    connect(ui->checkBox_tileable, SIGNAL(clicked()), this, SLOT(autoUpdate()));
    connect(ui->checkBox_invertHeight, SIGNAL(clicked()), this, SLOT(autoUpdate()));
    connect(ui->spinBox_normalmapSize, SIGNAL(valueChanged(int)), this, SLOT(autoUpdate()));
    connect(ui->checkBox_keepLargeDetail, SIGNAL(clicked()), this, SLOT(autoUpdate()));
    connect(ui->spinBox_largeDetailScale, SIGNAL(valueChanged(int)), this, SLOT(autoUpdate()));
    connect(ui->doubleSpinBox_largeDetailHeight, SIGNAL(valueChanged(double)), this, SLOT(autoUpdate()));
    // displcacement autoupdate
    connect(ui->doubleSpinBox_displace_redMul, SIGNAL(valueChanged(double)), this, SLOT(autoUpdate()));
    connect(ui->doubleSpinBox_displace_greenMul, SIGNAL(valueChanged(double)), this, SLOT(autoUpdate()));
    connect(ui->doubleSpinBox_displace_blueMul, SIGNAL(valueChanged(double)), this, SLOT(autoUpdate()));
    connect(ui->doubleSpinBox_displace_scale, SIGNAL(valueChanged(double)), this, SLOT(autoUpdate()));
    connect(ui->comboBox_mode_displace, SIGNAL(currentIndexChanged(int)), this, SLOT(autoUpdate()));
    connect(ui->doubleSpinBox_displace_contrast, SIGNAL(valueChanged(double)), this, SLOT(autoUpdate()));
    // ssao autoupdate
    connect(ui->doubleSpinBox_ssao_size, SIGNAL(valueChanged(double)), this, SLOT(autoUpdate()));
    //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()));
    connect(ui->pushButton_stopProcessingQueue, SIGNAL(clicked()), this, SLOT(stopProcessingQueue()));
    connect(ui->pushButton_changeOutputPath_Queue, SIGNAL(clicked()), this, SLOT(changeOutputPathQueueDialog()));
    connect(ui->lineEdit_outputPath, SIGNAL(editingFinished()), this, SLOT(editOutputPathQueue()));
    connect(ui->listWidget_queue, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(queueItemDoubleClicked(QListWidgetItem*)));
    //queue drag and drop
    connect(ui->listWidget_queue, SIGNAL(singleImageDropped(QUrl)), this, SLOT(loadSingleDropped(QUrl)));
    connect(ui->listWidget_queue, SIGNAL(multipleImagesDropped(QList<QUrl>)), this, SLOT(loadMultipleDropped(QList<QUrl>)));
    //normalmap size preview text
    connect(ui->spinBox_normalmapSize, SIGNAL(valueChanged(int)), this, SLOT(normalmapSizeChanged()));
    //"About" button
    connect(ui->pushButton_about, SIGNAL(clicked()), this, SLOT(showAboutDialog()));
}