#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <controlseleccio.h>
#include <QColorRampEditor.h>
#include <QtGui>
#include "ui_mainwindow.h"

#include "QColorRampEditor.h"
#include    <cstdlib>
#include    <ctime>
#include    <sys/timeb.h>
#include <texturewidget.h>
#include <color_dialog.hpp>
#include <arxiu.h>

namespace Ui {
    class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT
    
public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
    void iniescena();
protected:
     virtual void keyPressEvent(QKeyEvent *e);
public slots :
    void cambicolor(QColor);

private:

    ControlSeleccio* control;
    QColorRampEditor* ramph;

    void createActions();
    void createMenus();
    void initRcInteractiveComponents();
    void initUI();
    void canvioDeAtributos();
    void closeAllWindows();
    bool mask;
    bool onlymask;

    // Widgets i layouts
    Ui::MainWindow *ui;
    QWidget *centralWidget;
    QGridLayout *centralLayout;
    QStackedLayout *layoutStack;
    QStackedLayout *layoutStack2;
    QStackedLayout *layoutStack3;
    QWidget *window;
    QDialog *dialog;

    QSpinBox * integerSpinBox1;
    QSpinBox * integerSpinBox2;
    QSpinBox * integerSpinBox3;
    QComboBox * unsig;
    QDialogButtonBox *buttonBox;
    QSlider *umbralOpacitat;
    QSlider *umbralSaturacio;
    QSlider *cremQ;
    QSlider *umbralSampling;
    QSlider *umbralOpacitatGPU;
    QSlider *umbralSaturacioGPU;
    QSlider *umbralSamplingGPU;
    QSlider *umbralGammaMIDA;
    QSlider *umbralBlending; // K

    QLabel *opacitatLabel;
    QLabel *saturacioLabel;
    QLabel *samplingLabel;
    QLabel *cremLabel;
    QLabel *opacitatLabelGPU;
    QLabel *saturacioLabelGPU;
    QLabel *samplingLabelGPU;
    QLabel *cremLabelGPU;
    QLabel *gammaLabel;
    QLabel *Klabel;

    QLabel *samp;
    QLabel *op;
    QLabel *sat;
    QLabel *cre;
    QLabel *gama;
    QLabel *label2;
    QLabel *label3;
    QLabel *label4;

    QRadioButton *gsCheck;
    QRadioButton *lutCheck;
    QRadioButton *phongCheck;
    QCheckBox *oneStepCheck;
    QRadioButton *MipCheck;
    QRadioButton *MidaCheck;
    QCheckBox *RampCheck;

    QScrollArea *glWidgetArea;
    QScrollArea *glWidgetArea2;
    QScrollArea *glWidgetArea3;

    // Accions associades als menus
    QAction *exitAct;
    QAction *addVolumen;
    QAction *openDataSet;
    QAction *backgroundblack;
    QAction *menucontrol;
    QAction *maximizeGPU;
    QAction *maximizeCPU;

    // Qaction Raycasting GPU
    QAction *ArcgGS;
    QAction *ArcgLut;
    QAction *ArcgPB;
    QAction *ArcgMip;
    QAction *ArcgMida;
    QAction *ArcgMida2;

    // Qaction Raycasting CPU
    QAction *ArccGS;
    QAction *ArccLut;
    QAction *ArccPB;
    QAction *ArccMip;
    QAction *ArccMida;

    QAction *MaskAction;
    QAction *OnlyMaskAction;
    QAction *SelectColorMask;
    QAction *QAshowLut;

    // Menus principals
    QMenu *fileMenu;
    QMenu *rcMenu;
    QMenu *cmMenu;
    QMenu *maskMenu;

    //Raycasting values
    float opacitat, saturacio, sampling, opacitatGPU, samplingGPU;
    float crem, gamma, K;
    int saturacioGPU;

    // ELIMINAR
    static const int gsMode = 0;
    static const int lutMode = 1;
    static const int phongMode = 2;
    static const int mipMode = 3;
    static const int midaMode = 4;

    Color_Dialog *colordialog;
    vec4 *tamanyVolum;

     QGridLayout *slidersLayout2;
     QGridLayout *slidersLayout;

     QWidget* central2;
     QGridLayout* layoutcentral2;
     QGridLayout *sliders;
     QGridLayout* Widgets;


private slots:

    void setOpacitatGPU(int);
    void setSaturacioGPU(int);
    void setSamplingGPU(int);
    void setCremGPU(int);
    void setGammaMida(int);
    void onRampChanged();
    void activaMask();
    void onlyMask();
    void selectColorMask();
    void cargarVolumen();
    void showLut();
    void cambiarbackground();
    void Kblending(int);

    // Slots Raycasting GPU

    void rcgGS();
    void rcgLut();
    void rcgPB();
    void rcgMip();
    void rcgMida();
    void rcgMida2();

    // Slots Raycasting GPU

    void rccGS();
    void rccLut();
    void rccPB();
    void rccMip();
    void rccMida();

    void cambiartamanyglwidgetescena();
    void cambiartamanyglwidgettexture();
    void mostrarinterficie();
    void reescalar();

};

#endif // MAINWINDOW_H
