LogWidget::LogWidget(QWidget* parent)
  : QTextEdit(parent)
{
    m_action_clear_all = new QAction("Clear All", this);
    m_action_clear_all->setShortcut(QKeySequence("Ctrl+K"));
    connect(m_action_clear_all, SIGNAL(triggered()), this, SLOT(slot_clear_all()));
    addAction(m_action_clear_all);
}
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    // load and set style from resources
    QFile styleFile(":/styles/default.style");
    styleFile.open(QFile::ReadOnly | QFile::Text);
    QString style(styleFile.readAll());
    styleFile.close();

    qDebug() << style;
    qApp->setStyleSheet(style);

    // init values fo images
    QColor c(255, 255, 255, 0);
    QSize s = ui->image1_scrollArea->viewport()->size();
    image1 = new ImageWrapper(s, c);
    image2 = new ImageWrapper(s, c);
    imager = new ImageWrapper(":/images/images/monkey.png");
    image1t2 = 0;
    image2t1 = 0;

    image1_ready = image2_ready = false;

    image1_widget = new ImageHighlight(ui->image1_scrollArea, image1);
    image1_widget->setHighlight(false);

    image2_widget = new ImageHighlight(ui->image2_scrollArea, image2);
    image2_widget->setHighlight(false);

    ui->image1_scrollArea->setWidget(image1_widget);
    ui->image1_scrollArea->setWidgetResizable(false);

    ui->image2_scrollArea->setWidget(image2_widget);
    ui->image2_scrollArea->setWidgetResizable(false);

    // signals connect
    connect(imager, SIGNAL(update()), this, SLOT(slot_imager_redraw()) );
    connect( ui->actionClear_all, SIGNAL(triggered()), this, SLOT(slot_clear_all()) );

    connect( image1, SIGNAL(newSegment(QPair<QPointF,QPointF>&)), this, SLOT(slot_image1_newSegment(QPair<QPointF,QPointF>&)) );
    connect( image2, SIGNAL(newSegment(QPair<QPointF,QPointF>&)), this, SLOT(slot_image2_newSegment(QPair<QPointF,QPointF>&)) );

    connect( image1, SIGNAL(update()), this, SLOT(slot_image1_update()) );
    connect( image2, SIGNAL(update()), this, SLOT(slot_image2_update()) );

    slot_imager_redraw();

    progress = new QProgressBar(this);
    progress->setMaximum(100);
    progress->setValue(0);
    progress->setVisible(false);
    ui->statusBar->addWidget(progress, 1);

    play_timer = new QTimer();
    connect( play_timer, SIGNAL(timeout()), this, SLOT(slot_play_timer_timeout()) );

    isRecording = false;
    isRepeating = false;
    this->rec_output = 0;

    this->outside_color = QColor(255,255,255);
    ui->outside_color_button->setStyleSheet("background-color: #fff;");

}