#include <qapplication.h>

#include "imagewindow.h"
#include <iostream>
#include <qregexp.h>
#include <qscrollview.h>

using namespace std;

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    bool silent=false;
    QString xmlFileName;
    QString scrDesFileName;

    QRegExp regex_silent("^--silent");
    QRegExp regex_xml("^--xml=(.+)");
    QRegExp regex_scrDes("^--screenshotDescription=(.+)");
    int pos;
    for(int i =0 ; i< argc ;++i){
      QString argValue(argv[i]);
      pos=regex_silent.search(argValue);
      if(pos>-1){
         silent=true;
         cerr<<"silent:"<<silent<<endl;
      }

      pos=regex_xml.search(argValue);
      if(pos>-1){
         if(regex_xml.numCaptures()==1)
            xmlFileName=regex_xml.cap(1);
            cerr<<"xml:"<<xmlFileName<<endl;
            continue;
      }

      pos=regex_scrDes.search(argValue);
      if(pos>-1){
         if(regex_scrDes.numCaptures()==1)
            scrDesFileName=regex_scrDes.cap(1);
            cerr<<"screenshotDescription:"<<scrDesFileName<<endl;
            continue;
      }
      
            
    }
    //silent mode of operation
    if(silent){
      ImageWindow imageWin(0,0,true);
      imageWin.setXMLFile(xmlFileName);
      
      app.setMainWidget(&imageWin);

      if(!scrDesFileName.isEmpty())
         imageWin.setScreenshotDescriptionFileName(scrDesFileName);
               
      imageWin.startSimulation();
      
      return app.exec();
    }

/*    QScrollView scrollView;
    app.setMainWidget(&scrollView);
    ImageWindow * imageWindow=new ImageWindow();
    scrollView.addChild(imageWindow);
    scrollView.show();
    return app.exec();*/
    
    ImageWindow imageWin;
    app.setMainWidget(&imageWin);
    imageWin.resize(1200, 600);
    imageWin.show();
    return app.exec();
}
