示例#1
0
void HelpBrowser::createActions()
{
    QAction * action;
    OverridingAction *ovrAction;

    mActions[GoHome] = action = new QAction(tr("Home"), this);
    connect( action, SIGNAL(triggered()), this, SLOT(goHome()) );

    mActions[ZoomIn] = ovrAction = new OverridingAction(tr("Zoom In"), this);
    connect(ovrAction, SIGNAL(triggered()), this, SLOT(zoomIn()));
    ovrAction->addToWidget(mWebView);

    mActions[ZoomOut] = ovrAction = new OverridingAction(tr("Zoom Out"), this);
    connect(ovrAction, SIGNAL(triggered()), this, SLOT(zoomOut()));
    ovrAction->addToWidget(mWebView);

    mActions[ResetZoom] = ovrAction = new OverridingAction(tr("Reset Zoom"), this);
    connect(ovrAction, SIGNAL(triggered()), this, SLOT(resetZoom()));
    ovrAction->addToWidget(mWebView);

    mActions[Evaluate] = ovrAction = new OverridingAction(tr("Evaluate as Code"), this);
    connect(ovrAction, SIGNAL(triggered()), this, SLOT(evaluateSelection()));
    ovrAction->addToWidget(mWebView);

    // For the sake of display:
    mWebView->pageAction(QWebPage::Copy)->setShortcut( QKeySequence::Copy );
    mWebView->pageAction(QWebPage::Paste)->setShortcut( QKeySequence::Paste );
}
示例#2
0
void WeatherChart::paintEvent(QPaintEvent *)
{
    resetPaintRect();

    QPainter p;
    p.begin(this);

    if (scaleRect.width() == 0 && scaleRect.height() == 0)
    {
        setMinMax();
        resetZoom();
    }

    p.setBrush(QColor(20,20,20));
    p.setPen(QColor(20,20,20));
    p.drawRect(0, 0, width(), height());

    drawAxes(&p);
    drawChart(&p);

    if (scaling)
        drawScaleRect(&p);

    p.end();
}
示例#3
0
void PreviewWidget::fitImage(bool fit){
	mFit = fit;
	ConfigManagerInterface::getInstance()->setOption("Preview/PreviewPanelFit", mFit);
	REQUIRE(preViewer->pixmap());
	if (fit) {
		// needs to be improved
		QSize m_size=size()-QSize(2,2);
		QSize m_labelSize=preViewer->size();
		qreal ratio=1.0*m_labelSize.height()/m_labelSize.width();
		qreal ratioPreviewer=1.0*m_size.height()/m_size.width();
		int h,w;
		if(ratioPreviewer>ratio){
			h=qRound(ratio*m_size.width());
			w=m_size.width();
			pvscaleFactor=1.0*w/preViewer->pixmap()->size().width();
		} else {
			h=m_size.height();
			w=qRound(m_size.height()/ratio);
			pvscaleFactor=1.0*h/preViewer->pixmap()->size().height();;
		}
		preViewer->resize(w,h);
		//setWidgetResizable(true);
	} else {
		resetZoom();
	}
}
示例#4
0
void Lineplot::setData(double* data, int n)
{
  if(numPoints_ != n)
  {
    numPoints_ = n;
    delete[] indexPoints_;
    delete[] dataPoints_;
    indexPoints_ = new double[numPoints_];
    dataPoints_ = new double[numPoints_];
    if(xMin_==xMax_)
    {
      for(int i=0;i<numPoints_;i++)
        indexPoints_[i] = i;
    }
    else
    {
      double step = (xMax_-xMin_)/numPoints_;
      double val = xMin_;
      for(int i=0;i<numPoints_;i++,val+=step)
        indexPoints_[i] = val;
    }
  }

  memcpy(dataPoints_, data, numPoints_*sizeof(double));
  //Need to setRawSamples again for autoscaling to work
  curve_->setRawSamples(indexPoints_, dataPoints_, numPoints_);
  resetZoom();
}
示例#5
0
void SessionPositionsChart::paintEvent(QPaintEvent *)
{
    resetPaintRect();

    if (scaleRect.width() == 0 && scaleRect.height() == 0)
    {
        resetZoom();
    }

    QPainter p;
    p.begin(this);

    p.setBrush(QColor(20,20,20));
    p.setPen(QColor(20,20,20));
    p.drawRect(0, 0, width(), height());
    drawChart(&p);

    if (scaling)
        drawScaleRect(&p);

//    drawLegend(&p, 35, 5);

    p.end();

    if (lapDataArray.isEmpty())
        clearLapDataCoordinates(0);
}
示例#6
0
void Modele::windowResized(int width, int height)
{
    for (it = vues.begin(); it != vues.end(); it++) {
        ((Vue*)(*it))->updateSize(width, height);
    }
    resetZoom();
}
示例#7
0
void SessionGapsChart::paintEvent(QPaintEvent *)
{
    resetPaintRect();

    if (scaleRect.width() == 0 && scaleRect.height() == 0)
    {
        resetZoom();
    }  

    if (!scaling && !repaintPopup)
    {
        chartImg = QImage(width(), height(), QImage::Format_ARGB32);
        drawIntoImage(chartImg);
    }


    QPainter p;
    p.begin(this);
    if (!scaling && !repaintPopup)
    {
        drawImage(&p);
        checkLapDataCoordinates(mousePosX, mousePosY);
        popupBox->paint(&p, mousePosX, mousePosY, paintRect);
    }
    if (scaling)
    {
        drawImage(&p);
        drawScaleRect(&p);
    }
    if (repaintPopup)
    {
        drawImage(&p);
        popupBox->paint(&p, mousePosX, mousePosY, paintRect);
    }


//    p.setBrush(QColor(20,20,20));
//    p.setPen(QColor(20,20,20));
//    p.drawRect(0, 0, width(), height());
//    drawChart(&p);

//    if (scaling)
//        drawScaleRect(&p);

//    else
//    {
//        if (!repaintPopup)
//            findLapDataXY(mousePosX, mousePosY);

//        drawLapDataXY(&p);
//    }

//    drawLegend(&p, 35, 5);

    p.end();

    if (lapDataArray.isEmpty())
        clearLapDataCoordinates(0);
}
示例#8
0
LightboxWidget::LightboxWidget(QWidget *parent,ImageGroup::Handle i,OverlayList::Handle ol, Cursor::Handle& c ) :  
  ImageWidget(parent,i,ol,c), m_image(i), m_zoom(1.0)
{
  TRACKER("LightboxWidget::LightboxWidget");
  m_sv = new QScrollView(this);
  
  setIcon( QPixmap(lightbox_xpm) );

  setCentralWidget(m_sv);
  
  m_sv->viewport()->setBackgroundColor(QColor(128, 128, 128));

  connect(m_sv->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(scrolled(int)));
  connect(m_sv->verticalScrollBar(), SIGNAL(sliderReleased()),  this, SLOT(repaintSlices()));

  connect(m_mainToolbarWidget, SIGNAL(zoomValueChanged(int)), this, SLOT(setZoom(int)));

  m_slices = SliceListHandle(new SliceList);

  for(int n = 0; n < m_image->inqZ(); ++n)
  {
    SliceWidget::Handle axial =
      SliceWidget::Handle(new AxialWidget(m_sv->viewport(), "axial", 
					  m_cursor, m_overlayList, m_drawSettings, m_undoList,
					  m_opts));
    
    m_sv->addChild(axial.get());
    m_slices->push_back(axial);

    connect(this, SIGNAL(crossHairModeChanged(bool)),     axial.get(), SLOT(crossHairMode(bool)));
    connect(this, SIGNAL(modeChanged(SliceWidget::Mode)), axial.get(), SLOT(setMode(SliceWidget::Mode)));
    connect(this, SIGNAL(crossHairModeChanged(bool)),     axial.get(), SLOT(crossHairMode(bool)));
    connect(this, SIGNAL(resetZoom()),                    axial.get(), SLOT(resetZoom()));
    connect(axial.get(), SIGNAL(message(const QString&, int )), SIGNAL(message(const QString&, int )));

//    m_mainToolbarWidget->setCursorMode();

    axial->setSlice(n,m_cursor->inqV());
    axial->setSliceIsFixed(true);
  }
  
  m_mainToolbarWidget->setCrossHairsMode(true);
}
示例#9
0
void QImageDrawer::paintEvent(QPaintEvent *event)
{
    QWidget::paintEvent(event);

    if (m_image.isNull())
        return;

    QPainter painter(this);
    painter.setRenderHint(QPainter::Antialiasing, false);
    if (firstTimeShow) {
        resetZoom();
        firstTimeShow = false;
    }
    qreal zoom = m_zoomer.getZoom();
    QSizeF pixSize = m_image.size() * zoom;
    /*
     * use QTransform instead of window-viewport conversion
     * beacause we can't retrieve a transform with scale from QPainter after setWindow and setViewport
     * don't know why would that happen. maybe that's a Qt bug?
     * anyway, just stick to QTransform for now.
     */
    ccSpace->setTransform(QTransform(zoom, 0, 0, 0, zoom, 0, (this->width() - pixSize.width()) / 2.0, (this->height() - pixSize.height()) / 2.0, 1.0));
    painter.setWorldTransform(ccSpace->getTransform());
    painter.drawImage(0, 0, m_image);

    //Draw
    QPen pen(m_penColour, 2, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
    painter.setPen(pen);

    //don't paint if user didn't draw
    if (ccSpace->qrect.width() < 2 && m_mousePressed.manhattanLength() < 2) {
        return;
    }

    if (m_drawMode == -3) {
        painter.drawLine(m_calibreLine);
        return;
    }
    else if (m_drawMode == -4)
    {
        painter.drawLine(m_gaugeLine);
        return;
    }

    painter.drawRect(ccSpace->qrect);
}
示例#10
0
void PreviewWidget::contextMenu(QPoint point) {
	if (!preViewer->pixmap()) return;
	QMenu menu;
	menu.addAction(tr("Zoom In"),this, SLOT(zoomIn()));
	menu.addAction(tr("Zoom Out"),this, SLOT(zoomOut()));
	menu.addAction(tr("Reset Zoom"),this, SLOT(resetZoom()));
	QAction *act = menu.addAction(tr("Fit"));
	act->setCheckable(true);
	act->setChecked(mFit);
	connect(act, SIGNAL(triggered(bool)), this, SLOT(fitImage(bool)));
	act = menu.addAction(tr("Center"));
	act->setCheckable(true);
	act->setChecked(mCenter);
	connect(act, SIGNAL(triggered(bool)), this, SLOT(centerImage(bool)));
	QWidget* menuParent = qobject_cast<QWidget*>(sender());
	Q_ASSERT(menuParent);
	if (!menuParent) menuParent = preViewer;
	menu.exec(menuParent->mapToGlobal(point));
}
示例#11
0
GraphicsScene::GraphicsScene(const char* raddr, unsigned rport, unsigned lport, QWidget* parent):
  QGraphicsView(parent),
  m_grid(true),
  m_fps(0),
  m_move(false),
  m_raddr(raddr),
  m_rport(rport),
  m_lport(lport),
  m_rotate(0)
{
  m_scene.addItem(&m_item);
  setScene(&m_scene);
  setFocusPolicy(Qt::StrongFocus);

  m_sock = new QUdpSocket();
  m_sock->bind(m_lport);

  m_zoom_tim = new QTimer(this);
  connect(m_zoom_tim, SIGNAL(timeout()), this, SLOT(resetZoom()));

  connect(m_sock, SIGNAL(readyRead()),
          this, SLOT(handleInputData()));

  m_vline = new QGraphicsLineItem;
  m_vline->setPen(QPen(Qt::DotLine));
  m_hline = new QGraphicsLineItem;
  m_hline->setPen(QPen(Qt::DotLine));

  m_fps_txt = new QGraphicsTextItem("FPS: 0");
  m_scene.addItem(m_fps_txt);
  m_fps_txt->setPos(5, 5);

  m_fps_tim = new QTimer(this);
  m_fps_tim->setInterval(1000);
  m_fps_tim->start(1000);
  connect(m_fps_tim, SIGNAL(timeout()), this, SLOT(computeFPS()));

  drawGrid();
}
示例#12
0
void PostWindow::createActions( Settings::Manager * settings )
{
    QAction * action;
    OverridingAction * ovrAction;

    QString postCategory(tr("Post Window"));

    mActions[Copy] = action = new QAction(tr("Copy"), this);
    action->setShortcut( QKeySequence::Copy );
    action->setShortcutContext( Qt::WidgetShortcut );
    action->setEnabled( false );
    connect(action, SIGNAL(triggered()), this, SLOT(copy()));
    connect( this, SIGNAL(copyAvailable(bool)), action, SLOT(setEnabled(bool)) );
    addAction(action);

    mActions[Clear] = action = new QAction(tr("Clear"), this);
    action->setStatusTip(tr("Clear post window"));
    action->setShortcutContext(Qt::ApplicationShortcut);
    action->setShortcut(tr("Ctrl+Shift+P", "Clear post window"));
    settings->addAction( action, "post-clear", postCategory );
    connect(action, SIGNAL(triggered()), this, SLOT(clear()));
    addAction(action);

    action = new QAction(this);
    action->setSeparator(true);
    addAction(action);

    mActions[DocClose] = ovrAction = new OverridingAction(tr("Close"), this);
    action->setStatusTip(tr("Close the current document"));
    connect( ovrAction, SIGNAL(triggered()), this, SLOT(closeDocument()) );
    ovrAction->addToWidget(this);

    mActions[ZoomIn] = ovrAction = new OverridingAction(tr("Enlarge Font"), this);
    ovrAction->setIconText("+");
    ovrAction->setStatusTip(tr("Enlarge post window font"));
    connect(ovrAction, SIGNAL(triggered()), this, SLOT(zoomIn()));
    ovrAction->addToWidget(this);

    mActions[ZoomOut] = ovrAction = new OverridingAction(tr("Shrink Font"), this);
    ovrAction->setIconText("-");
    ovrAction->setStatusTip(tr("Shrink post window font"));
    connect(ovrAction, SIGNAL(triggered()), this, SLOT(zoomOut()));
    ovrAction->addToWidget(this);

    mActions[ResetZoom] = ovrAction = new OverridingAction(tr("Reset Font Size"), this);
    connect(ovrAction, SIGNAL(triggered()), this, SLOT(resetZoom()));
    ovrAction->addToWidget(this);

    action = new QAction(this);
    action->setSeparator(true);
    addAction(action);

    mActions[LineWrap] = action = new QAction(tr("Wrap Text"), this);
    action->setStatusTip(tr("Wrap lines wider than the post window"));
    action->setCheckable(true);
    addAction(action);
    connect( action, SIGNAL(triggered(bool)), this, SLOT(setLineWrap(bool)) );
    settings->addAction( action, "post-line-wrap", postCategory );

    mActions[AutoScroll] = action = new QAction(tr("Auto Scroll"), this);
    action->setStatusTip(tr("Scroll to bottom on new posts"));
    action->setCheckable(true);
    action->setChecked(true);
    connect(action, SIGNAL(triggered(bool)), this, SLOT(onAutoScrollTriggered(bool)));
    addAction(action);
    settings->addAction( action, "post-auto-scroll", postCategory );
}
示例#13
0
/*!
*  Initialisation du module
*
*/
void CDataGraph::init(CApplication *application)
{
    CModule::init(application);
    setGUI(&m_ihm); // indique à  la classe de base l'IHM
    setNiveauTrace(MSG_TOUS);

    // Gère les actions sur clic droit sur le panel graphique du module
    m_ihm.setContextMenuPolicy(Qt::CustomContextMenu);
    connect(&m_ihm, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(onRightClicGUI(QPoint)));

    // Restore la taille de la fenêtre
    QVariant val;
    val = m_application->m_eeprom->read(getName(), "geometry", QRect(50, 50, 150, 150));
    m_ihm.setGeometry(val.toRect());
    // Restore le fait que la fenêtre est visible ou non
    val = m_application->m_eeprom->read(getName(), "visible", QVariant(true));
    if (val.toBool()) { m_ihm.show(); }
    else              { m_ihm.hide(); }
    // Restore le niveau d'affichage
    val = m_application->m_eeprom->read(getName(), "niveau_trace", QVariant(MSG_TOUS));
    setNiveauTrace(val.toUInt());
    // Restore la couleur de fond
    val = m_application->m_eeprom->read(getName(), "background_color", QVariant(DEFAULT_MODULE_COLOR));
    setBackgroundColor(val.value<QColor>());

    //labels pour le tableau de données
    QStringList QS_Labels;
    QS_Labels << "Variable" << "Valeur" << "Couleur" << "Curseur 1" << "Curseur 2";
    m_ihm.ui.table_variables_valeurs->setHorizontalHeaderLabels(QS_Labels);
    m_ihm.ui.table_variables_valeurs->horizontalHeader()->setVisible(true);
    m_ihm.ui.table_variables_valeurs->horizontalHeaderItem(3)->setTextColor(Qt::green);
    m_ihm.ui.table_variables_valeurs->horizontalHeaderItem(4)->setTextColor(Qt::red);

    // Restaure la zone minimale autour du curseur pour le sélectionner
    val = m_application->m_eeprom->read(getName(), "fineDistanceCursorSelection", QVariant(true));
    fineDistanceCursorSelection=val.toInt();

    //On cache les contrà´les agissant sur les courbes (réactivés lors de la pause des courbes)
    m_ihm.ui.label_deltaT->setVisible(false);
    m_ihm.ui.pb_resetZoom->setVisible(true);

    //de même on ne permet pas l'activation des curseurs
    m_ihm.ui.pb_cusor->setEnabled(false);
    m_ihm.ui.pb_cusor->setChecked(false);

    //ni de la pause
    m_ihm.ui.pb_resume->setEnabled(false);
    m_ihm.ui.pb_resume->setChecked(false);

    // le bouton refresh met à  jour la liste des variables disponibles
    connect(m_ihm.ui.PB_refresh_liste, SIGNAL(clicked()), this, SLOT(refreshListeVariables()));
    connect(m_ihm.ui.pb_play,SIGNAL(toggled(bool)),this,SLOT(activeGraph(bool)));
    connect(m_ihm.ui.pb_up, SIGNAL(clicked()), this, SLOT(upVariable()));
    connect(m_ihm.ui.pb_down, SIGNAL(clicked()), this, SLOT(downVariable()));
    connect(m_ihm.ui.liste_variables,SIGNAL(itemChanged(QListWidgetItem*)),this,SLOT(authorizePlay(QListWidgetItem*)));

    connect(&m_timer_lecture_variables, SIGNAL(timeout()), this, SLOT(refreshValeursVariables()));

    //récupération du pointeur du graphique et création des curseurs
    customPlot=m_ihm.findChild<QCustomPlot*>("customPlot");
    cursor1 = new QCPItemLine(customPlot);
    cursor1->setPen(QPen(Qt::green));
    cursor2 = new QCPItemLine(customPlot);
    cursor2->setPen(QPen(Qt::red));

    // à  inclure pour supprimer l'antialiasing pour de meilleures perfos
    /*
    customPlot->setNotAntialiasedElements(QCP::aeAll);
    QFont font;
    font.setStyleStrategy(QFont::NoAntialias);
    customPlot->xAxis->setTickLabelFont(font);
    customPlot->yAxis->setTickLabelFont(font);
    customPlot->legend->setFont(font);
    */
    //formattage des axes
    customPlot->xAxis->setTickLabelType(QCPAxis::ltDateTime);
    customPlot->xAxis->setDateTimeFormat("hh:mm:ss");
    customPlot->xAxis->setAutoTickStep(false);
    customPlot->xAxis->setTickStep(2);
    customPlot->axisRect()->setupFullAxesBox();
    //range du premier axe
    customPlot->yAxis->setRange(-300,300);
    val = m_application->m_eeprom->read(getName(), "initHighRange", QVariant());
    customPlot->yAxis->setRange(-fabs(val.toDouble()),fabs(val.toDouble()));
    //range du deuxième axe
    customPlot->yAxis2->setRange(-3.5,3.5);
    val = m_application->m_eeprom->read(getName(), "initLowRange", QVariant());
    customPlot->yAxis2->setRange(-fabs(val.toDouble()),fabs(val.toDouble()));
    customPlot->yAxis2->setAutoTickLabels(true);
    customPlot->yAxis2->setTickLabels(true);
    customPlot->yAxis2->setVisible(true);

    //uniformisation des ranges entre les axes dessus-dessous et gauche-droite
    connect(customPlot->xAxis, SIGNAL(rangeChanged(QCPRange)), customPlot->xAxis2, SLOT(setRange(QCPRange)));

    //gestion des ranges pour les différents zoom
    storedRange->lower=customPlot->yAxis->range().lower;
    storedRange->upper=customPlot->yAxis->range().upper;
    storedRangeAxe1->lower=customPlot->yAxis->range().lower;
    storedRangeAxe1->upper=customPlot->yAxis->range().upper;
    storedRangeAxe2->lower=customPlot->yAxis2->range().lower;
    storedRangeAxe2->upper=customPlot->yAxis2->range().upper;
    //par sécurité on normalise les ranges
    storedRange->normalize();storedRangeAxe1->normalize();storedRangeAxe2->normalize();
    QString str;
    m_ihm.ui.inputRangeAxe1->setText(str.setNum(storedRangeAxe1->upper));
    m_ihm.ui.inputRangeAxe2->setText(str.setNum(storedRangeAxe2->upper));

    //Interaction avec la souris: défilement de la courbe, zoom, sélection de lignes
    customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectItems);
    // zone minimale autour du curseur pour le sélectionner
    customPlot->setSelectionTolerance(fineDistanceCursorSelection);
    //pour l'init on désactive temporairement le drag and drop des courbes (réactive à  la mise en pause des courbes)
    customPlot->axisRect()->setRangeDrag(0);
    //pour l'init on désactive le zoom (réactive à  la mise en pause des courbes)
    customPlot->axisRect()->setRangeZoom(0);

    //mise à  jour des courbes
    customPlot->replot();    

    backupEnabled=false;

    //gestion des interactions des courbes
    connect(m_ihm.ui.pb_resume,SIGNAL(toggled(bool)),this,SLOT(resumeGraph(bool))); //pause des courbes
    connect(m_ihm.ui.table_variables_valeurs,SIGNAL(itemDoubleClicked(QTableWidgetItem*)),this, SLOT(itemRescaleGraph(QTableWidgetItem*))); //redimensionnement des axes
    connect(customPlot,SIGNAL(mousePress(QMouseEvent*)),this,SLOT(mousePress(QMouseEvent*))); //gestion des curseurs
    connect(customPlot,SIGNAL(mouseMove(QMouseEvent*)),this,SLOT(mouseMove(QMouseEvent*)));
    connect(customPlot,SIGNAL(mouseRelease(QMouseEvent*)),this,SLOT(mouseRelease(QMouseEvent*)));
    connect(m_ihm.ui.pb_resetZoom, SIGNAL(clicked()),this,SLOT(resetZoom())); //resetZoom (no comment)
    connect(m_ihm.ui.pb_cusor, SIGNAL(toggled(bool)),this, SLOT(enableCursor(bool)));
    connect(m_ihm.ui.pb_Range,SIGNAL(clicked()),this,SLOT(userRescaleGraph()));
    connect(m_ihm.ui.sliderZoom,SIGNAL(valueChanged(int)),this,SLOT(userZoomGraph(int)));
	//manage record data
    //connect(m_ihm.ui.pb_record,SIGNAL(toggled(bool)),this,SLOT(Slot_save(bool))); //pause des courbes
}
//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()));
}
//load the image specified in the url
bool MainWindow::load(QUrl url) {
    if(!url.isValid()) {
        throw "[load] invalid url!";
        return false;
    }

    ui->statusBar->showMessage("loading Image: " + url.fileName());

    //load the image
    input = QImage(url.toLocalFile());

    QFileInfo file(url.toLocalFile());

    if(input.isNull()) {
        QString errorMessage("Image not loaded!");

        if(file.suffix().toLower() == "tga") {
            errorMessage.append("\nOnly uncompressed TGA files are supported.");
        }
        else {
            errorMessage.append("\nMost likely the image format is not supported.");
        }

        ui->statusBar->showMessage("Error: Image " + url.fileName() + " NOT loaded!", 5000);
        QMessageBox::information(this, "Error while loading image", errorMessage);
        return false;
    }

    //store the path the image was loaded from (for saving later)
    if(exportPath.isEmpty())
        setExportPath(url.adjusted(QUrl::RemoveFilename));
    loadedImagePath = url;

    //enable ui buttons
    ui->pushButton_calcNormal->setEnabled(true);
    ui->pushButton_calcSpec->setEnabled(true);
    ui->pushButton_calcDisplace->setEnabled(true);
    ui->pushButton_calcSsao->setEnabled(true);
    ui->checkBox_displayChannelIntensity->setEnabled(true);
    ui->spinBox_normalmapSize->setEnabled(true);
    enableAutoupdate(true);
    
    //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);

    //clear all previously generated images
    channelIntensity = QImage();
    normalmap = QImage();
    specmap = QImage();
    displacementmap = QImage();
    ssaomap = QImage();

    //display single image channels if the option was already chosen
    if(ui->checkBox_displayChannelIntensity->isChecked())
        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();
    
    //enable button to save the maps
    ui->pushButton_save->setEnabled(true);

    return true;
}