Beispiel #1
0
void CustomFilter::initialize()
{
    connect(GraphicsView::instance(), SIGNAL(newImage(QImage)), SLOT(onNewImage(QImage)),Qt::DirectConnection);
}
Beispiel #2
0
Image loadImageaspgm(const char *filename)
{
	Image img;
	FILE *in;
	int i, j, k, xres, yres, maxgrey;
	char line[100];
	int mode, c;
	guchar *row;

	in = fopen(filename, "r");
	if(!in)
	{
		fprintf(stderr, "loadImageaspgm: File not found: %s\n",
			filename);
		return 0;
	}
	if(readpgmline(in, line, filename)) return 0;
	if(line[0] != 'P' || (line[1] != '5' && line[1] != '6'))
	{
		fprintf(stderr, "Unsupported file: %s\n", filename);
		fclose(in);
		return 0;
	}
	if(line[1] == '5') mode = 0;
	else mode = 1;
	if(readpgmline(in, line, filename)) return 0;
	sscanf(line, "%d%d", &xres, &yres);
	if(xres <= 0 || yres <= 0)
	{
		fprintf(stderr, "loadImageaspgm: Bad file: %s\n", filename);
		fclose(in);
		return 0;
	}
	if(readpgmline(in, line, filename)) return 0;
	sscanf(line, "%d", &maxgrey);

	img = newImage(xres, yres);
	if(mode == 0) 
	{
		for(j = 0; j < yres; j++) 
		{
			if(fread(img->data[j], sizeof(unsigned char), xres, in)
				!= xres)
			{
				fprintf(stderr, "Warning: loadImageaspgm: "
					"File Short: %s\n", filename);
				break;
			}
		}
	}
	else 
	{
		row = g_new(guchar, 3*xres);
		for(j = 0; j < yres; j++)
		{
			if(fread(row, sizeof(unsigned char), 3*xres,in) 
				!= 3*xres)
			{
				fprintf(stderr, "Warning: loadImageaspgm:"
					" File Short: %s\n", filename);
				break;
			}
			k = 0;
			for(i = 0; i < xres; i++)
			{
				c = 71*row[k++];
				c += 150*row[k++];
				c += 28*row[k++];
				img->data[j][i] = c>>8;
			}
		}
		g_free(row);
	}

	fclose(in);

	return img;
}
Beispiel #3
0
  // compute the scs-lbp code image
  void SCSLBP::lbpcompute(const cv::Mat &input1, cv::Mat &LBPImage)
  {
    int neighbors_ = 2 * neighbors;

    float y, x, yd, xd, v;
    int fy, fx, cy, cx, ry, rx;
    int fyd, fxd, cyd, cxd, ryd, rxd;
    float miny = 999, minx = 999;
    float maxy = 0, maxx = 0;
    int mapping = 0;
    float spoints[2][2 * 4];

    // angle step
    float a = 2 * CV_PI / neighbors_;
    for (int i = 0; i < neighbors_; i++)
    {
      spoints[0][i] = -(float)radius * sin(i*a);
      spoints[1][i] = (float)radius * cos(i*a);

      if (spoints[0][i] < miny)
        miny = spoints[0][i];

      if (spoints[0][i] > maxy)
        maxy = spoints[0][i];

      if (spoints[1][i] < minx)
        minx = spoints[1][i];

      if (spoints[1][i] > maxx)
        maxx = spoints[1][i];

    }

    // block size, each LBP code is computed within a block of size bsizey*bsizex
    int bsizey = ceil(std::max(maxy, (float)0.0)) - floor(std::min(miny, (float)0.0)) + 1;
    int bsizex = ceil(std::max(maxx, (float)0.0)) - floor(std::min(minx, (float)0.0)) + 1;

    // coordinates of origin (0,0) in the block
    int origy = 1 - floor(std::min(miny, (float)0.0)) - 1;
    int origx = 1 - floor(std::min(minx, (float)0.0)) - 1;

    // minimum allowed size for the input image depends on the radius of the used LBP operator
    if (input1.cols < bsizex || input1.rows < bsizey)
      std::cout << "Too small input image. Should be at least " << (2 * radius + 1) * (2 * radius + 1) << std::endl;

    // calculate dx and dy
    int dx = input1.cols - bsizex + 1;
    int dy = input1.rows - bsizey + 1;

    cv::Mat comImage, comImageCen;
    cv::Rect roi = cv::Rect(origx, origy, dx, dy); // because of transalation of coord from matlab
    input1(roi).copyTo(comImage);

    comImageCen = comImage.clone();

    cv::Mat result(dy, dx, CV_8UC1, cv::Scalar(0));        // sign LBP computing image
    cv::Mat D(comImage.rows, comImage.cols, CV_8UC1);
    cv::Mat Diff(comImage.rows, comImage.cols, CV_8UC1);

    cv::Mat newImage(comImage.rows, comImage.cols, CV_32FC1);
    cv::Mat newImageD(comImage.rows, comImage.cols, CV_32FC1);
    cv::Mat inputFloat(input1.rows, input1.cols, CV_32FC1);
    input1.convertTo(inputFloat, CV_32F);

    float* newImageData = (float*)newImage.data;
    float* newImageDData = (float*)newImageD.data;

    for (int i = 0; i < neighbors_ / 2; i++)
    {
      y = spoints[0][i] + origy;
      x = spoints[1][i] + origx;

      // calculate floors, ceils and rounds for the x and y.
      fy = floor(y); cy = ceil(y); ry = roundLocal(y);
      fx = floor(x); cx = ceil(x); rx = roundLocal(x);

      yd = spoints[0][i + neighbors_ / 2] + origy;
      xd = spoints[1][i + neighbors_ / 2] + origx;

      fyd = floor(yd); cyd = ceil(yd); ryd = roundLocal(yd);
      fxd = floor(xd); cxd = ceil(xd); rxd = roundLocal(xd);

      int a = abs(x - rx);
      int b = abs(y - ry);

      // check if interpolation is needed
      if ((abs(x - rx) < 1 / 100000.0) && (abs(y - ry) < 1 / 100000.0))
      {
        // --- interpolation is not needed, use original datatypes ---
        inputFloat(cv::Rect(rx, ry, dx, dy)).copyTo(newImage);
        inputFloat(cv::Rect(rxd, ryd, dx, dy)).copyTo(newImageD);

        // compute difference between newImage and newImageD
        for (int iRow = 0; iRow < newImage.rows; iRow++)
          for (int iCol = 0; iCol < newImage.cols; iCol++)
          {
            if (newImageData[iCol + newImage.cols * iRow] - newImageDData[iCol + newImageD.cols * iRow] >= 0)
              D.data[iCol + D.cols * iRow] = 1;
            else
              D.data[iCol + D.cols * iRow] = 0;
          }
      }
      else
      {
        // --- interpolation needed, use double type images ---
        float ty = y - fy;
        float tx = x - fx;

        // calculate the interpolation weights
        float w1 = (1 - tx) * (1 - ty);
        float w2 = tx  * (1 - ty);
        float w3 = (1 - tx) *      ty;
        float w4 = tx  *      ty;

        // compute interpolated pixel values
        cv::Mat dImage1, dImage2, dImage3, dImage4;
        inputFloat(cv::Rect(fx, fy, dx, dy)).copyTo(dImage1);
        inputFloat(cv::Rect(cx, fy, dx, dy)).copyTo(dImage2);
        inputFloat(cv::Rect(fx, cy, dx, dy)).copyTo(dImage3);
        inputFloat(cv::Rect(cx, cy, dx, dy)).copyTo(dImage4);

        newImage = w1*dImage1 + w2*dImage2 + w3*dImage3 + w4*dImage4;

        /////////////////////////////////////////
        float tyd = yd - fyd;
        float txd = xd - fxd;

        float w1d = (1 - txd) * (1 - tyd);
        float w2d = txd  * (1 - tyd);
        float w3d = (1 - txd) *      tyd;
        float w4d = txd  *      tyd;

        inputFloat(cv::Rect(fxd, fyd, dx, dy)).copyTo(dImage1);
        inputFloat(cv::Rect(cxd, fyd, dx, dy)).copyTo(dImage2);
        inputFloat(cv::Rect(fxd, cyd, dx, dy)).copyTo(dImage3);
        inputFloat(cv::Rect(cxd, cyd, dx, dy)).copyTo(dImage4);

        newImageD = w1d*dImage1 + w2d*dImage2 + w3d*dImage3 + w4d*dImage4;

        // compute difference between newImage and newImageD
        for (int iRow = 0; iRow < newImage.rows; iRow++)
          for (int iCol = 0; iCol < newImage.cols; iCol++)
          {
            if (newImageData[iCol + newImage.cols * iRow] - newImageDData[iCol + newImageD.cols * iRow] >= 0)
              D.data[iCol + D.cols * iRow] = 1;
            else
              D.data[iCol + D.cols * iRow] = 0;
          }
      }

      // update the result matrix
      v = std::pow(2.0, i);
      result = result + (int)v*D;
    }

    // save results taking into account margins
    result.copyTo(LBPImage(cv::Rect(origx, origy, dx, dy)));
  }
Beispiel #4
0
void TOSMWidget::paintEvent(QPaintEvent *)
{
    qDebug() << "Paint event";
    QImage newImage(QSize(rect().width(), rect().height()), QImage::Format_ARGB32);
    QPainter Painter(&newImage);
//    Painter.set
//    QPaintDevice t;

//    Painter.begin(&newImage);


    Painter.setPen(QPen(QColor(0, 0, 0)));

    midWayAttr = stWA.Median(drawProp);

    long long i = 0;
    for (TNWaysIter it = nways.begin(); it != nways.end(); it++)
    {
        TNWay *way = &it.value();
//        qDebug() << "F " << way->attrF << " R" << way->attrR << " / " << maxWayAttr;
//        bool deadEndF = MyNodes[way->nodes.last()].containedBy.size() == 1, deadEndR = MyNodes[way->nodes.first()].containedBy.size() == 1;



//        double v = way->Usage();

//        if ((way->usageF > 0) && (way->usageR > 0))
//        {
//            Painter.setPen(QPen(QColor(0, 255, 0)));
//            Painter.drawEllipse(w2s_p(MyNodes[way->nodes.first()].toPointF()), 25, 25);
//        }
//        else

//        if (v > midWayAttr)
//        {
//            Painter.setPen(QPen(QColor(255, 0, 0)));
//        }
//        else
//        {
//            Painter.setPen(QPen(QColor(0, 0, 255)));
//        }

//        / maxWayAttr;
//        Painter.setPen(QPen(QColor(long(v * 255) % 256, 0, 255 - long(v * 255) % 256)));

        bool first = true;
        QPointF prevP;
//        double dist1 = MyNodes[(*it).nodes.first()].attr,
//                dist2 = MyNodes[(*it).nodes.last()].attr,
//                wlen = (*it).Weight(),
//                wdist = 0.0;
        i++;
//        Painter.setPen(QPen(QColor((i*i)%200, ((i+11)*(i+11))%200, ((i+19)*(i+19))%200)));
        switch (way->roadClass())
        {
            case TOSMWidget::TNWay::EW_Trunk:
            case TOSMWidget::TNWay::EW_Motorway:
            case TOSMWidget::TNWay::EW_Raceway:
            case TOSMWidget::TNWay::EW_Primary: Painter.setPen(QPen(QColor(63, 200, 63))); break;
            case TOSMWidget::TNWay::EW_Tertiary:
            case TOSMWidget::TNWay::EW_Road:
            case TOSMWidget::TNWay::EW_Unclassified:
            case TOSMWidget::TNWay::EW_Secondary: Painter.setPen(QPen(QColor(100, 150, 63))); break;
            case TOSMWidget::TNWay::EW_LivingStreet:
            case TOSMWidget::TNWay::EW_Service: Painter.setPen(QPen(QColor(130, 100, 63))); break;
            case TOSMWidget::TNWay::EW_Residental: Painter.setPen(QPen(QColor(170, 90, 63))); break;
            case TOSMWidget::TNWay::EW_BusGuideway:
            case TOSMWidget::TNWay::EW_Track: Painter.setPen(QPen(QColor(200, 60, 63))); break;
            case TOSMWidget::TNWay::EW_Path:
            case TOSMWidget::TNWay::EW_Footway:
            case TOSMWidget::TNWay::EW_Steps:
            case TOSMWidget::TNWay::EW_Bridleway:
            case TOSMWidget::TNWay::EW_Construction:
            case TOSMWidget::TNWay::EW_Proposed:
            case TOSMWidget::TNWay::EW_Pedestrian: Painter.setPen(QPen(QColor(200, 200, 200))); break;
        default:
            Painter.setPen(QPen(QColor(0, 0, 0)));
        }

//        Painter.setPen(QPen(QColor((i*i)%200, ((i+11)*(i+11))%200, ((i+19)*(i+19))%200)));
        for (QList <TID> ::Iterator it_n = way->nodes.begin(); it_n != way->nodes.end(); it_n++)
        {
//            double dist = std::min(dist1 + wdist, dist2 + wlen - wdist);
//            Painter.setPen(QPen(QColor(long((dist*256/10)) % 256, 128, 128)));
            QPointF curP = nnodes[*it_n].toPointF();
            if ((nnodes[*it_n].metrica > 0.0) && (nnodes[*it_n].metrica < W_INF))
            {
                Painter.drawText(w2s_p(curP),QString::number(nnodes[*it_n].metrica));
            }
            if (!first)
            {
                drawLine(Painter, QLineF(prevP, curP));
//                wdist += fabs(distance(curP, prevP));
            }
            first = false;
            prevP = curP;
        }
    }

//    Painter.setPen(QPen(QColor(0, 0, 0)));
//    Painter.drawEllipse(w2s_p(MyNodes[*MyCrosses.begin()].toPointF()), 5, 5);

    Painter.setPen(QPen(QColor(0, 200, 0)));

    for (int i = 0; i < markers.size(); i++)
    {
//        qDebug() << "drawing marker " << markers[i];
//        QRect pieRect = QRect(
//                            w2s_x(markers[i].x())-20,
//                            w2s_y(markers[i].y())-20,
//                            w2s_x(markers[i].x())+20,
//                            w2s_y(markers[i].y())+20);
//        Painter.drawPie(pieRect, (90-10)*16, (90+10)*16);
        Painter.drawEllipse(w2s_p(markers[i]), 15, 15);
        Painter.drawEllipse(w2s_p(nnodes[nearestNode(markers[i])].toPointF()), 10, 10);
    }

    Painter.setPen(QPen(QColor(0, 255, 0)));
    QPointF p;
    bool first = true;
    for (QList <TID> ::Iterator it = path.nodes.begin(); it != path.nodes.end(); it++)
    {
        Painter.drawEllipse(w2s_p(nnodes[*it].toPointF()), 5, 5);
        first = false;
    }

//    for (QList <TWay> ::Iterator it = MyWays.begin(); it != MyWays.end(); it++)
//    {
//        TNWay *way = &(*it);
//        for (QList <TID> ::Iterator itn = way->nodes.begin(); itn != way->nodes.end(); itn++)
//        {

//        }
//    }

//    this->
//    Painter.drawImage();
//    Painter.end();

    QPainter newPainter(this);
    qDebug() << "rect " << this->rect();
    newPainter.drawRect(this->rect());
//    qDebug() << "rect " << this->rect();
//    newPainter.fillRect(this->Rect, QBrush(Qt::white));
    newPainter.drawImage(QPoint(0,0), newImage);

}
Beispiel #5
0
void LinkLabel::newImage(const QPixmap& upImg, const QPixmap& downImg, QString text) {
    _tooltip = text;
    newImage(upImg, downImg);
}
ptr<image> transformHighBit::allocateOutputImage(ptr<image> pInputImage, imbxUint32 width, imbxUint32 height)
{
	ptr<image> newImage(new image);
	newImage->create(width, height, pInputImage->getDepth(), pInputImage->getColorSpace(), pInputImage->getHighBit());
	return newImage;
}
Beispiel #7
0
static display_t draw()
{
#if COMPILE_ANIMATIONS
	static byte usbImagePos = FRAME_HEIGHT;
	static byte chargeImagePos = FRAME_HEIGHT;
#endif

	// Draw date
	drawDate();

	// Draw time animated
	display_t busy = ticker();

	// Draw battery icon
	drawBattery();

	byte fix = 20;

	// Draw USB icon
	image_s icon = newImage(fix, FRAME_HEIGHT - 9, usbIcon, 16, 8, WHITE, NOINVERT, 0);
	draw_bitmap_set(&icon);

#if COMPILE_ANIMATIONS
	if(animateIcon(USB_CONNECTED(), &usbImagePos))
	{
		icon.y = usbImagePos;
		draw_bitmap_s2(NULL);
		icon.x += 20;
	}
#else
	if(USB_CONNECTED())
	{
		draw_bitmap_s2(NULL);
		icon.x += 20;
	}
#endif
	
	// Draw charging icon
	icon.width = 8;
#if COMPILE_ANIMATIONS
	if(animateIcon(CHARGING(), &chargeImagePos))
	{
		icon.bitmap = chargeIcon;
		icon.y = chargeImagePos;
		draw_bitmap_s2(NULL);
		icon.x += 12;
	}	
#else
	if(CHARGING())
	{
		icon.bitmap = chargeIcon;
		draw_bitmap_s2(NULL);
		icon.x += 12;
	}
#endif

	icon.y = FRAME_HEIGHT - 8;

#if COMPILE_STOPWATCH
	// Stopwatch icon
	if(stopwatch_active())
	{
		icon.bitmap = stopwatch;
		draw_bitmap_s2(&icon);
		icon.x += 12;
	}
#endif	

	// Draw next alarm
	alarm_s nextAlarm;
	if(alarm_getNext(&nextAlarm))
	{
		time_s alarmTime;
		alarmTime.hour = nextAlarm.hour;
		alarmTime.mins = nextAlarm.min;
		alarmTime.ampm = CHAR_24;
		time_timeMode(&alarmTime, appConfig.timeMode);
		
		char buff[9];
		sprintf_P(buff, PSTR("%02hhu:%02hhu%c"), alarmTime.hour, alarmTime.mins, alarmTime.ampm);
		draw_string(buff, false, icon.x, FRAME_HEIGHT - 8);
		icon.x += (alarmTime.ampm == CHAR_24) ? 35 : 42;

		icon.bitmap = dowImg[alarm_getNextDay()];
		draw_bitmap_s2(&icon);

//		icon.x += 9;
	}

	return busy;
}
QConvoysWidget::QConvoysWidget(QWidget *parent)
    : QWidget(parent)
{
    newImage();
}
Beispiel #9
0
VideoObserver::VideoObserver(QObject *owner, const char *imageSlot):QObject(owner)
{
	myImage = new Mat;
	QObject::connect (this, SIGNAL(newImage()), owner, imageSlot, Qt::QueuedConnection);
}
Beispiel #10
0
static display_t ticker()
{
	static byte yPos;
	static byte yPos_secs;
	static bool moving = false;
	static bool moving2[5];

#if COMPILE_ANIMATIONS
	static byte hour2;
	static byte mins;
	static byte secs;

	if(appConfig.animations)
	{
		if(timeDate.time.secs != secs)
		{
			yPos = 0;
			yPos_secs = 0;
			moving = true;

			moving2[0] = div10(timeDate.time.hour) != div10(hour2);
			moving2[1] = mod10(timeDate.time.hour) != mod10(hour2);
			moving2[2] = div10(timeDate.time.mins) != div10(mins);
			moving2[3] = mod10(timeDate.time.mins) != mod10(mins);
			moving2[4] = div10(timeDate.time.secs) != div10(secs);
		
			//memcpy(&timeDateLast, &timeDate, sizeof(timeDate_s));
			hour2 = timeDate.time.hour;
			mins = timeDate.time.mins;
			secs = timeDate.time.secs;
		}

		if(moving)
		{
			if(yPos <= 3)
				yPos++;
			else if(yPos <= 6)
				yPos += 3;
			else if(yPos <= 16)
				yPos += 5;
			else if(yPos <= 22)
				yPos += 3;
			else if(yPos <= 24 + TICKER_GAP)
				yPos++;

			if(yPos >= MIDFONT_HEIGHT + TICKER_GAP)
				yPos = 255;

			if(yPos_secs <= 1)
				yPos_secs++;
			else if(yPos_secs <= 13)
				yPos_secs += 3;
			else if(yPos_secs <= 16 + TICKER_GAP)
				yPos_secs++;

			if(yPos_secs >= FONT_SMALL2_HEIGHT + TICKER_GAP)
				yPos_secs = 255;

			if(yPos_secs > FONT_SMALL2_HEIGHT + TICKER_GAP && yPos > MIDFONT_HEIGHT + TICKER_GAP)
			{
				yPos = 0;
				yPos_secs = 0;
				moving = false;
				memset(moving2, false, sizeof(moving2));
			}
		}
	}
	else
#endif
	{
		yPos = 0;
		yPos_secs = 0;
		moving = false;
		memset(moving2, false, sizeof(moving2));
	}

	// Set up image
	image_s img = newImage(104, 28, (const byte*)&small2Font, FONT_SMALL2_WIDTH, FONT_SMALL2_HEIGHT, WHITE, false, yPos_secs);
	draw_bitmap_set(&img);
	
	// Seconds
	drawTickerNum2(&img, div10(timeDate.time.secs), 5, moving2[4]);
	img.x = 116;
	drawTickerNum2(&img, mod10(timeDate.time.secs), 9, moving);
	
	// Set new font data for hours and minutes
	img.y = TIME_POS_Y;
	img.width = MIDFONT_WIDTH;
	img.height = MIDFONT_HEIGHT;
	img.bitmap = (const byte*)&midFont;
	img.offsetY = yPos;

	// Minutes
	img.x = 60;
	drawTickerNum2(&img, div10(timeDate.time.mins), 5, moving2[2]);
	img.x = 83;
	drawTickerNum2(&img, mod10(timeDate.time.mins), 9, moving2[3]);

	// Hours
	img.x = 1;
	drawTickerNum2(&img, div10(timeDate.time.hour), 5, moving2[0]);
	img.x = 24;
	drawTickerNum2(&img, mod10(timeDate.time.hour), 9, moving2[1]);
	
	// Draw colon for half a second
	if(RTC_HALFSEC())
	{
		img.x = TIME_POS_X + 46 + 2;
		img.bitmap = colon;
		img.width = FONT_COLON_WIDTH;
		img.height = FONT_COLON_HEIGHT;
		img.offsetY = 0;
		draw_bitmap_s2(NULL);
	}
	
	// Draw AM/PM character
	char tmp[2];
	tmp[0] = timeDate.time.ampm;
	tmp[1] = 0x00;
	draw_string(tmp, false, 104, 20);

//	char buff[12];
//	sprintf_P(buff, PSTR("%lu"), time_getTimestamp());
//	draw_string(buff, false, 30, 50);

	return (moving ? DISPLAY_BUSY : DISPLAY_DONE);
}
FramelessMainWindow::FramelessMainWindow( QWidget *parent ) :
   QMainWindow( parent ),
   m_scene( new QGraphicsScene( this ) ),
   m_browser( new GraphicsBrowser( m_scene, *this ) ),
   m_mouseFilter( *this, *qApp ),
   m_video( new EventfulVidgetVideo( this ) ),
   m_intro( new QGraphicsScene ),
   m_control( new VideoControl( this ) ),
   m_closeControl( new QFrame( this ) ),
   m_hostApp( new HostApp( m_browser->webView(), this ) )
{
    m_video->hide();
    m_control->hide();
    m_browser->webView()->page()->settings()->setAttribute( QWebSettings::JavascriptCanOpenWindows, true );

    m_control->setVolume( m_hostApp->getVolume() );

    m_closeControl->hide();
    m_closeControl->setStyleSheet( "QFrame{background-color:black; } "
                                   "QPushButton { background-image: url(':/close-styled'); width:31;} "
                                   "QWidget{border:none; padding:0; spacing:0; height:30;}" );
    QHBoxLayout *hl = new QHBoxLayout( m_closeControl );
    hl->setContentsMargins( QMargins() );
    hl->addSpacerItem( new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum ) );

    m_closeButton = new QPushButton();
    m_closeButton->setCursor( Qt::PointingHandCursor );
//  btn->setFlat( true );
    hl->addWidget( m_closeButton );
    connect( m_control, SIGNAL( uiShow() ), m_closeButton, SLOT( show() ) );
    connect( m_control, SIGNAL( uiHide() ), m_closeButton, SLOT( hide() ) );


    setWindowTitle( "Popcorn Time" );
    m_intro->addPixmap( QPixmap( ":/intro" ).scaled( DEFAULT_WIDTH, DEFAULT_HEIGHT, Qt::IgnoreAspectRatio ) );
    m_browser->setScene( m_intro );
    new QShortcut( QKeySequence( "Ctrl+M" ), this, SLOT( minimize() ) );

    QObject::connect( m_hostApp->thread(), SIGNAL( torrentUrlAvailable( QString ) ),
                      this, SLOT( playMedia( QString ) ) );
    QObject::connect( m_browser->webView(), SIGNAL( loadFinished( bool ) ),
                      this, SLOT( removeIntro() ) );
    QObject::connect( m_hostApp, SIGNAL( commandedClose() ),
                      this, SLOT( close() ) );
    QObject::connect( m_hostApp, SIGNAL( commandedMinimize() ),
                      this, SLOT( minimize() ) );
    QObject::connect( m_hostApp, SIGNAL( toggledMaximize() ),
                      this, SLOT( toggleMaximize() ) );
    QObject::connect( m_hostApp, SIGNAL( haveSubtitles( SubtitleItem ) ),
                      m_control, SLOT( addSubtitle( SubtitleItem ) ) );
    QObject::connect( m_hostApp, SIGNAL( downloadInfoChanged( DownloadInfo ) ),
                      m_control, SLOT( updateDownloadStatus( DownloadInfo ) ) );
    QObject::connect( m_control, SIGNAL( volumeChanged( int ) ),
                      m_hostApp, SLOT( setVolume( int ) ) );

    QObject::connect( m_control, SIGNAL( newImage( QString ) ),
                      m_video, SLOT( setImage( QString ) ) );

    QObject::connect( m_control->fullscreenButton(), SIGNAL( clicked() ),
                      this, SLOT( toggleMaximize() ) );
    QObject::connect( &m_mouseFilter, SIGNAL( enterPressed() ),
                      this, SLOT( toggleMaximize() ) );
    QObject::connect( &m_mouseFilter, SIGNAL( upPressed() ),
                      m_control, SLOT( volumeUp() ) );
    QObject::connect( &m_mouseFilter, SIGNAL( downPressed() ),
                      m_control, SLOT( volumeDown() ) );
    QObject::connect( &m_mouseFilter, SIGNAL( pausePressed() ),
                      m_control, SLOT( pauseToggleReq() ) );

    connect( m_video, SIGNAL( mouseEnter() ), m_control, SLOT( showForDefaultPeriod() ) );

    this->setWindowFlags( Qt::FramelessWindowHint | Qt::WindowMinimizeButtonHint );
#ifdef Q_OS_MAC
    fixNativeWindow( this );
#endif
    this->setMinimumSize( 800, 330 );
    this->setMouseTracking( true );
    this->setCentralWidget( m_browser );
    qApp->installEventFilter( this );

    reconnectMediaPlayer();

    QObject::connect( VLC::VLCObject(), SIGNAL( mediaPlayerReplaced() ),
                      this, SLOT( reconnectMediaPlayer() ) );
}
Beispiel #12
0
void SBarInfo::ParseSBarInfoBlock(FScanner &sc, SBarInfoBlock &block)
{
	while(sc.CheckToken(TK_Identifier))
	{
		SBarInfoCommand cmd;

		switch(cmd.type = sc.MustMatchString(SBarInfoRoutineLevel))
		{
			case SBARINFO_DRAWSWITCHABLEIMAGE:
				sc.MustGetToken(TK_Identifier);
				if(sc.Compare("weaponslot"))
				{
					cmd.flags = DRAWIMAGE_WEAPONSLOT;
					sc.MustGetToken(TK_IntConst);
					cmd.value = sc.Number;
				}
				else if(sc.Compare("invulnerable"))
				{
					cmd.flags = DRAWIMAGE_INVULNERABILITY;
				}
				else if(sc.Compare("keyslot"))
				{
					cmd.flags = DRAWIMAGE_KEYSLOT;
					sc.MustGetToken(TK_IntConst);
					cmd.value = sc.Number;
				}
				else
				{
					cmd.setString(sc, sc.String, 0);
					const PClass* item = PClass::FindClass(sc.String);
					if(item == NULL || !PClass::FindClass("Inventory")->IsAncestorOf(item)) //must be a kind of Inventory
					{
						sc.ScriptError("'%s' is not a type of inventory item.", sc.String);
					}
				}
				if(sc.CheckToken(TK_AndAnd))
				{
					cmd.flags |= DRAWIMAGE_SWITCHABLE_AND;
					if(cmd.flags & DRAWIMAGE_KEYSLOT)
					{
						sc.MustGetToken(TK_IntConst);
						cmd.special4 = sc.Number;
					}
					else
					{
						sc.MustGetToken(TK_Identifier);
						cmd.setString(sc, sc.String, 1);
						const PClass* item = PClass::FindClass(sc.String);
						if(item == NULL || !PClass::FindClass("Inventory")->IsAncestorOf(item)) //must be a kind of Inventory
						{
							sc.ScriptError("'%s' is not a type of inventory item.", sc.String);
						}
					}
					sc.MustGetToken(',');
					sc.MustGetToken(TK_StringConst);
					cmd.special = newImage(sc.String);
					sc.MustGetToken(',');
					sc.MustGetToken(TK_StringConst);
					cmd.special2 = newImage(sc.String);
					sc.MustGetToken(',');
					sc.MustGetToken(TK_StringConst);
					cmd.special3 = newImage(sc.String);
					sc.MustGetToken(',');
				}
				else
				{
					sc.MustGetToken(',');
					sc.MustGetToken(TK_StringConst);
					cmd.special = newImage(sc.String);
					sc.MustGetToken(',');
				}
			case SBARINFO_DRAWIMAGE:
			{
				bool getImage = true;
				if(sc.CheckToken(TK_Identifier))
				{
					getImage = false;
					if(sc.Compare("playericon"))
						cmd.flags |= DRAWIMAGE_PLAYERICON;
					else if(sc.Compare("ammoicon1"))
						cmd.flags |= DRAWIMAGE_AMMO1;
					else if(sc.Compare("ammoicon2"))
						cmd.flags |= DRAWIMAGE_AMMO2;
					else if(sc.Compare("armoricon"))
						cmd.flags |= DRAWIMAGE_ARMOR;
					else if(sc.Compare("weaponicon"))
						cmd.flags |= DRAWIMAGE_WEAPONICON;
					else if(sc.Compare("sigil"))
						cmd.flags |= DRAWIMAGE_SIGIL;
					else if(sc.Compare("hexenarmor"))
					{
						cmd.flags = DRAWIMAGE_HEXENARMOR;
						sc.MustGetToken(TK_Identifier);
						if(sc.Compare("armor"))
							cmd.value = 0;
						else if(sc.Compare("shield"))
							cmd.value = 1;
						else if(sc.Compare("helm"))
							cmd.value = 2;
						else if(sc.Compare("amulet"))
							cmd.value = 3;
						else
							sc.ScriptError("Unkown armor type: '%s'", sc.String);
						sc.MustGetToken(',');
						getImage = true;
					}
					else if(sc.Compare("runeicon"))
						cmd.flags |= DRAWIMAGE_RUNEICON;
					else if(sc.Compare("translatable"))
					{
						cmd.flags |= DRAWIMAGE_TRANSLATABLE;
						getImage = true;
					}
					else
					{
						//sc.CheckToken(TK_Identifier);
						cmd.flags |= DRAWIMAGE_INVENTORYICON;
						const PClass* item = PClass::FindClass(sc.String);
						if(item == NULL || !PClass::FindClass("Inventory")->IsAncestorOf(item)) //must be a kind of Inventory
						{
							sc.ScriptError("'%s' is not a type of inventory item.", sc.String);
						}
						cmd.sprite_index = ((AInventory *)GetDefaultByType(item))->Icon;
						cmd.image_index = -1;
					}
				}
				if(getImage)
				{
					sc.MustGetToken(TK_StringConst);
					cmd.image_index = newImage(sc.String);
					cmd.sprite_index.SetInvalid();
				}
				sc.MustGetToken(',');
				this->getCoordinates(sc, block.fullScreenOffsets, cmd.x, cmd.y);
				if(sc.CheckToken(','))
				{
					sc.MustGetToken(TK_Identifier);
					if(sc.Compare("center"))
						cmd.flags |= DRAWIMAGE_OFFSET_CENTER;
					else if(sc.Compare("centerbottom"))
						cmd.flags |= DRAWIMAGE_OFFSET_CENTERBOTTOM;
					else
						sc.ScriptError("'%s' is not a valid alignment.", sc.String);
				}
				sc.MustGetToken(';');
				break;
			}
			case SBARINFO_DRAWNUMBER:
				cmd.special4 = cmd.special3 = -1;
				sc.MustGetToken(TK_IntConst);
				cmd.special = sc.Number;
				sc.MustGetToken(',');
				sc.MustGetToken(TK_Identifier);
				cmd.font = V_GetFont(sc.String);
				if(cmd.font == NULL)
					sc.ScriptError("Unknown font '%s'.", sc.String);
				sc.MustGetToken(',');
				sc.MustGetToken(TK_Identifier);
				cmd.translation = this->GetTranslation(sc, sc.String);
				sc.MustGetToken(',');
				if(sc.CheckToken(TK_IntConst))
				{
					cmd.value = sc.Number;
					sc.MustGetToken(',');
				}
				else
				{
					sc.MustGetToken(TK_Identifier);
					if(sc.Compare("health"))
						cmd.flags = DRAWNUMBER_HEALTH;
					else if(sc.Compare("armor"))
						cmd.flags = DRAWNUMBER_ARMOR;
					else if(sc.Compare("ammo1"))
						cmd.flags = DRAWNUMBER_AMMO1;
					else if(sc.Compare("ammo2"))
						cmd.flags = DRAWNUMBER_AMMO2;
					else if(sc.Compare("ammo")) //request the next string to be an ammo type
					{
						sc.MustGetToken(TK_Identifier);
						cmd.setString(sc, sc.String, 0);
						cmd.flags = DRAWNUMBER_AMMO;
						const PClass* ammo = PClass::FindClass(sc.String);
						if(ammo == NULL || !RUNTIME_CLASS(AAmmo)->IsAncestorOf(ammo)) //must be a kind of ammo
						{
							sc.ScriptError("'%s' is not a type of ammo.", sc.String);
						}
					}
					else if(sc.Compare("ammocapacity"))
					{
						sc.MustGetToken(TK_Identifier);
						cmd.setString(sc, sc.String, 0);
						cmd.flags = DRAWNUMBER_AMMOCAPACITY;
						const PClass* ammo = PClass::FindClass(sc.String);
						if(ammo == NULL || !RUNTIME_CLASS(AAmmo)->IsAncestorOf(ammo)) //must be a kind of ammo
						{
							sc.ScriptError("'%s' is not a type of ammo.", sc.String);
						}
					}
					else if(sc.Compare("frags"))
						cmd.flags = DRAWNUMBER_FRAGS;
					else if(sc.Compare("kills"))
						cmd.flags |= DRAWNUMBER_KILLS;
					else if(sc.Compare("monsters"))
						cmd.flags |= DRAWNUMBER_MONSTERS;
					else if(sc.Compare("items"))
						cmd.flags |= DRAWNUMBER_ITEMS;
					else if(sc.Compare("totalitems"))
						cmd.flags |= DRAWNUMBER_TOTALITEMS;
					else if(sc.Compare("secrets"))
						cmd.flags |= DRAWNUMBER_SECRETS;
					else if(sc.Compare("totalsecrets"))
						cmd.flags |= DRAWNUMBER_TOTALSECRETS;
					else if(sc.Compare("armorclass"))
						cmd.flags |= DRAWNUMBER_ARMORCLASS;
					else if(sc.Compare("globalvar"))
					{
						cmd.flags |= DRAWNUMBER_GLOBALVAR;
						sc.MustGetToken(TK_IntConst);
						if(sc.Number < 0 || sc.Number >= NUM_GLOBALVARS)
							sc.ScriptError("Global variable number out of range: %d", sc.Number);
						cmd.value = sc.Number;
					}
					else if(sc.Compare("globalarray")) //acts like variable[playernumber()]
					{
						cmd.flags |= DRAWNUMBER_GLOBALARRAY;
						sc.MustGetToken(TK_IntConst);
						if(sc.Number < 0 || sc.Number >= NUM_GLOBALVARS)
							sc.ScriptError("Global variable number out of range: %d", sc.Number);
						cmd.value = sc.Number;
					}
					else if(sc.Compare("poweruptime"))
					{
						cmd.flags |= DRAWNUMBER_POWERUPTIME;
						sc.MustGetToken(TK_Identifier);
						cmd.setString(sc, sc.String, 0);
						const PClass* item = PClass::FindClass(sc.String);
						if(item == NULL || !PClass::FindClass("PowerupGiver")->IsAncestorOf(item))
						{
							sc.ScriptError("'%s' is not a type of PowerupGiver.", sc.String);
						}
					}
					else if(sc.Compare("teamscore")) //Takes in a number for team
					{
						cmd.flags |= DRAWNUMBER_TEAMSCORE;
						sc.MustGetToken(TK_StringConst);
						int t = -1;
						for(unsigned int i = 0;i < teams.Size();i++)
						{
							if(teams[i].Name.CompareNoCase(sc.String) == 0)
							{
								t = (int) i;
								break;
							}
						}
						if(t == -1)
							sc.ScriptError("'%s' is not a valid team.", sc.String);
						cmd.value = t;
					}
					else
					{
						cmd.flags = DRAWNUMBER_INVENTORY;
						cmd.setString(sc, sc.String, 0);
						const PClass* item = PClass::FindClass(sc.String);
						if(item == NULL || !PClass::FindClass("Inventory")->IsAncestorOf(item)) //must be a kind of ammo
						{
							sc.ScriptError("'%s' is not a type of inventory item.", sc.String);
						}
					}
					sc.MustGetToken(',');
				}
				while(sc.CheckToken(TK_Identifier))
				{
					if(sc.Compare("fillzeros"))
						cmd.flags |= DRAWNUMBER_FILLZEROS;
					else if(sc.Compare("whennotzero"))
						cmd.flags |= DRAWNUMBER_WHENNOTZERO;
					else if(sc.Compare("drawshadow"))
						cmd.flags |= DRAWNUMBER_DRAWSHADOW;
					else
						sc.ScriptError("Unknown flag '%s'.", sc.String);
					if(!sc.CheckToken('|'))
						sc.MustGetToken(',');
				}
				this->getCoordinates(sc, block.fullScreenOffsets, cmd.x, cmd.y);
				if(sc.CheckToken(','))
				{
					bool needsComma = false;
					if(sc.CheckToken(TK_IntConst)) //font spacing
					{
						cmd.special2 = sc.Number;
						needsComma = true;
					}
					if(!needsComma || sc.CheckToken(',')) //2nd coloring for "low-on" value
					{
						sc.MustGetToken(TK_Identifier);
						cmd.translation2 = this->GetTranslation(sc, sc.String);
						sc.MustGetToken(',');
						sc.MustGetToken(TK_IntConst);
						cmd.special3 = sc.Number;
						if(sc.CheckToken(',')) //3rd coloring for "high-on" value
						{
							sc.MustGetToken(TK_Identifier);
							cmd.translation3 = this->GetTranslation(sc, sc.String);
							sc.MustGetToken(',');
							sc.MustGetToken(TK_IntConst);
							cmd.special4 = sc.Number;
						}
					}
				}
				sc.MustGetToken(';');
				break;
			case SBARINFO_DRAWMUGSHOT:
				if(sc.CheckToken(TK_StringConst))
				{
					cmd.setString(sc, sc.String, 0, 3, true);
					sc.MustGetToken(',');
				}
				sc.MustGetToken(TK_IntConst); //accuracy
				if(sc.Number < 1 || sc.Number > 9)
					sc.ScriptError("Expected a number between 1 and 9, got %d instead.", sc.Number);
				cmd.special = sc.Number;
				sc.MustGetToken(',');
				while(sc.CheckToken(TK_Identifier))
				{
					if(sc.Compare("xdeathface"))
						cmd.flags |= DRAWMUGSHOT_XDEATHFACE;
					else if(sc.Compare("animatedgodmode"))
						cmd.flags |= DRAWMUGSHOT_ANIMATEDGODMODE;
					else if(sc.Compare("disablegrin"))
						cmd.flags |= DRAWMUGSHOT_DISABLEGRIN;
					else if(sc.Compare("disableouch"))
						cmd.flags |= DRAWMUGSHOT_DISABLEOUCH;
					else if(sc.Compare("disablepain"))
						cmd.flags |= DRAWMUGSHOT_DISABLEPAIN;
					else if(sc.Compare("disablerampage"))
						cmd.flags |= DRAWMUGSHOT_DISABLERAMPAGE;
					else
						sc.ScriptError("Unknown flag '%s'.", sc.String);
					if(!sc.CheckToken('|'))
						sc.MustGetToken(',');
				}

				this->getCoordinates(sc, block.fullScreenOffsets, cmd.x, cmd.y);
				sc.MustGetToken(';');
				break;
			case SBARINFO_DRAWSELECTEDINVENTORY:
			{
				bool alternateonempty = false;
				while(true) //go until we get a font (non-flag)
				{
					sc.MustGetToken(TK_Identifier);
					if(sc.Compare("alternateonempty"))
					{
						alternateonempty = true;
						cmd.flags |= DRAWSELECTEDINVENTORY_ALTERNATEONEMPTY;
					}
					else if(sc.Compare("artiflash"))
					{
						cmd.flags |= DRAWSELECTEDINVENTORY_ARTIFLASH;
					}
					else if(sc.Compare("alwaysshowcounter"))
					{
						cmd.flags |= DRAWSELECTEDINVENTORY_ALWAYSSHOWCOUNTER;
					}
					else if(sc.Compare("center"))
					{
						cmd.flags |= DRAWSELECTEDINVENTORY_CENTER;
					}
					else if(sc.Compare("centerbottom"))
					{
						cmd.flags |= DRAWSELECTEDINVENTORY_CENTERBOTTOM;
					}
					else if(sc.Compare("drawshadow"))
					{
						cmd.flags |= DRAWSELECTEDINVENTORY_DRAWSHADOW;
					}
					else
					{
						cmd.font = V_GetFont(sc.String);
						if(cmd.font == NULL)
							sc.ScriptError("Unknown font '%s'.", sc.String);
						sc.MustGetToken(',');
						break;
					}
					if(!sc.CheckToken('|'))
						sc.MustGetToken(',');
				}
				this->getCoordinates(sc, block.fullScreenOffsets, cmd.x, cmd.y);
				cmd.special2 = *(cmd.x + 30);
				cmd.special3 = *(cmd.y + 24);
				cmd.translation = CR_GOLD;
				if(sc.CheckToken(',')) //more font information
				{
					this->getCoordinates(sc, block.fullScreenOffsets, cmd.special2, cmd.special3);
					if(sc.CheckToken(','))
					{
						sc.MustGetToken(TK_Identifier);
						cmd.translation = this->GetTranslation(sc, sc.String);
						if(sc.CheckToken(','))
						{
							sc.MustGetToken(TK_IntConst);
							cmd.special4 = sc.Number;
						}
					}
				}
				if(alternateonempty)
				{
					sc.MustGetToken('{');
					cmd.subBlock.fullScreenOffsets = block.fullScreenOffsets;
					this->ParseSBarInfoBlock(sc, cmd.subBlock);
				}
				else
				{
					sc.MustGetToken(';');
				}
				break;
			}
			case SBARINFO_DRAWINVENTORYBAR:
				sc.MustGetToken(TK_Identifier);
				if(sc.Compare("Doom"))
					cmd.special = GAME_Doom;
				else if(sc.Compare("Heretic"))
					cmd.special = GAME_Heretic;
				else if(sc.Compare("Hexen"))
					cmd.special = GAME_Hexen;
				else if(sc.Compare("Strife"))
					cmd.special = GAME_Strife;
				else
					sc.ScriptError("Unkown style '%s'.", sc.String);

				sc.MustGetToken(',');
				while(sc.CheckToken(TK_Identifier))
				{
					if(sc.Compare("alwaysshow"))
					{
						cmd.flags |= DRAWINVENTORYBAR_ALWAYSSHOW;
					}
					else if(sc.Compare("noartibox"))
					{
						cmd.flags |= DRAWINVENTORYBAR_NOARTIBOX;
					}
					else if(sc.Compare("noarrows"))
					{
						cmd.flags |= DRAWINVENTORYBAR_NOARROWS;
					}
					else if(sc.Compare("alwaysshowcounter"))
					{
						cmd.flags |= DRAWINVENTORYBAR_ALWAYSSHOWCOUNTER;
					}
					else if(sc.Compare("translucent"))
					{
						cmd.flags |= DRAWINVENTORYBAR_TRANSLUCENT;
					}
					else
					{
						sc.ScriptError("Unknown flag '%s'.", sc.String);
					}
					if(!sc.CheckToken('|'))
						sc.MustGetToken(',');
				}
				sc.MustGetToken(TK_IntConst);
				cmd.value = sc.Number;
				sc.MustGetToken(',');
				sc.MustGetToken(TK_Identifier);
				cmd.font = V_GetFont(sc.String);
				if(cmd.font == NULL)
					sc.ScriptError("Unknown font '%s'.", sc.String);

				sc.MustGetToken(',');
				this->getCoordinates(sc, block.fullScreenOffsets, cmd.x, cmd.y);
				cmd.special2 = *(cmd.x + 26);
				cmd.special3 = *(cmd.y + 22);
				cmd.translation = CR_GOLD;
				if(sc.CheckToken(',')) //more font information
				{
					this->getCoordinates(sc, block.fullScreenOffsets, cmd.special2, cmd.special3);
					if(sc.CheckToken(','))
					{
						sc.MustGetToken(TK_Identifier);
						cmd.translation = this->GetTranslation(sc, sc.String);
						if(sc.CheckToken(','))
						{
							sc.MustGetToken(TK_IntConst);
							cmd.special4 = sc.Number;
						}
					}
				}
				sc.MustGetToken(';');
				break;
			case SBARINFO_DRAWBAR:
				sc.MustGetToken(TK_StringConst);
				cmd.image_index = newImage(sc.String);
				cmd.sprite_index.SetInvalid();
				sc.MustGetToken(',');
				sc.MustGetToken(TK_StringConst);
				cmd.special = newImage(sc.String);
				sc.MustGetToken(',');
				sc.MustGetToken(TK_Identifier); //yeah, this is the same as drawnumber, there might be a better way to copy it...
				if(sc.Compare("health"))
				{
					cmd.flags = DRAWNUMBER_HEALTH;
					if(sc.CheckToken(TK_Identifier)) //comparing reference
					{
						cmd.setString(sc, sc.String, 0);
						const PClass* item = PClass::FindClass(sc.String);
						if(item == NULL || !PClass::FindClass("Inventory")->IsAncestorOf(item)) //must be a kind of inventory
						{
							sc.ScriptError("'%s' is not a type of inventory item.", sc.String);
						}
					}
					else
						cmd.special2 = DRAWBAR_COMPAREDEFAULTS;
				}
				else if(sc.Compare("armor"))
				{
					cmd.flags = DRAWNUMBER_ARMOR;
					if(sc.CheckToken(TK_Identifier))
					{
						cmd.setString(sc, sc.String, 0);
						const PClass* item = PClass::FindClass(sc.String);
						if(item == NULL || !PClass::FindClass("Inventory")->IsAncestorOf(item)) //must be a kind of inventory
						{
							sc.ScriptError("'%s' is not a type of inventory item.", sc.String);
						}
					}
					else
						cmd.special2 = DRAWBAR_COMPAREDEFAULTS;
				}
				else if(sc.Compare("ammo1"))
					cmd.flags = DRAWNUMBER_AMMO1;
				else if(sc.Compare("ammo2"))
					cmd.flags = DRAWNUMBER_AMMO2;
				else if(sc.Compare("ammo")) //request the next string to be an ammo type
				{
					sc.MustGetToken(TK_Identifier);
					cmd.setString(sc, sc.String, 0);
					cmd.flags = DRAWNUMBER_AMMO;
					const PClass* ammo = PClass::FindClass(sc.String);
					if(ammo == NULL || !RUNTIME_CLASS(AAmmo)->IsAncestorOf(ammo)) //must be a kind of ammo
					{
						sc.ScriptError("'%s' is not a type of ammo.", sc.String);
					}
				}
				else if(sc.Compare("frags"))
					cmd.flags = DRAWNUMBER_FRAGS;
				else if(sc.Compare("kills"))
					cmd.flags = DRAWNUMBER_KILLS;
				else if(sc.Compare("items"))
					cmd.flags = DRAWNUMBER_ITEMS;
				else if(sc.Compare("secrets"))
					cmd.flags = DRAWNUMBER_SECRETS;
				else if(sc.Compare("poweruptime"))
				{
					cmd.flags |= DRAWNUMBER_POWERUPTIME;
					sc.MustGetToken(TK_Identifier);
					cmd.setString(sc, sc.String, 0);
					const PClass* item = PClass::FindClass(sc.String);
					if(item == NULL || !PClass::FindClass("PowerupGiver")->IsAncestorOf(item))
					{
						sc.ScriptError("'%s' is not a type of PowerupGiver.", sc.String);
					}
				}
				else if(sc.Compare("teamscore")) //Takes in a number for team
				{
					cmd.flags |= DRAWNUMBER_TEAMSCORE;
					sc.MustGetToken(TK_StringConst);
					int t = -1;
					for(unsigned int i = 0;i < teams.Size();i++)
					{
						if(teams[i].Name.CompareNoCase(sc.String) == 0)
						{
							t = (int) i;
							break;
						}
					}
					if(t == -1)
						sc.ScriptError("'%s' is not a valid team.", sc.String);
					cmd.value = t;
				}
				else
				{
					cmd.flags = DRAWNUMBER_INVENTORY;
					cmd.setString(sc, sc.String, 0);
					const PClass* item = PClass::FindClass(sc.String);
					if(item == NULL || !RUNTIME_CLASS(AInventory)->IsAncestorOf(item))
					{
						sc.ScriptError("'%s' is not a type of inventory item.", sc.String);
					}
				}
				sc.MustGetToken(',');
				sc.MustGetToken(TK_Identifier);
				if(sc.Compare("horizontal"))
					cmd.special2 += DRAWBAR_HORIZONTAL;
				else if(!sc.Compare("vertical"))
					sc.ScriptError("Unknown direction '%s'.", sc.String);
				sc.MustGetToken(',');
				while(sc.CheckToken(TK_Identifier))
				{
					if(sc.Compare("reverse"))
						cmd.special2 += DRAWBAR_REVERSE;
					else
						sc.ScriptError("Unkown flag '%s'.", sc.String);
					if(!sc.CheckToken('|'))
						sc.MustGetToken(',');
				}
				this->getCoordinates(sc, block.fullScreenOffsets, cmd.x, cmd.y);
				if(sc.CheckToken(',')) //border
				{
					sc.MustGetToken(TK_IntConst);
					cmd.special3 = sc.Number;
				}
				sc.MustGetToken(';');
				break;
			case SBARINFO_DRAWGEM:
				while(sc.CheckToken(TK_Identifier))
				{
					if(sc.Compare("wiggle"))
						cmd.flags |= DRAWGEM_WIGGLE;
					else if(sc.Compare("translatable"))
						cmd.flags |= DRAWGEM_TRANSLATABLE;
					else if(sc.Compare("armor"))
						cmd.flags |= DRAWGEM_ARMOR;
					else if(sc.Compare("reverse"))
						cmd.flags |= DRAWGEM_REVERSE;
					else
						sc.ScriptError("Unknown drawgem flag '%s'.", sc.String);
					if(!sc.CheckToken('|'))
							sc.MustGetToken(',');
				}
				sc.MustGetToken(TK_StringConst); //chain
				cmd.special = newImage(sc.String);
				sc.MustGetToken(',');
				sc.MustGetToken(TK_StringConst); //gem
				cmd.image_index = newImage(sc.String);
				cmd.sprite_index.SetInvalid();
				sc.MustGetToken(',');
				cmd.special2 = this->getSignedInteger(sc);
				sc.MustGetToken(',');
				cmd.special3 = this->getSignedInteger(sc);
				sc.MustGetToken(',');
				sc.MustGetToken(TK_IntConst);
				if(sc.Number < 0)
					sc.ScriptError("Chain size must be a positive number.");
				cmd.special4 = sc.Number;
				sc.MustGetToken(',');
				this->getCoordinates(sc, block.fullScreenOffsets, cmd.x, cmd.y);
				sc.MustGetToken(';');
				break;
			case SBARINFO_DRAWSHADER:
				sc.MustGetToken(TK_IntConst);
				cmd.special = sc.Number;
				if(sc.Number < 1)
					sc.ScriptError("Width must be greater than 1.");
				sc.MustGetToken(',');
				sc.MustGetToken(TK_IntConst);
				cmd.special2 = sc.Number;
				if(sc.Number < 1)
					sc.ScriptError("Height must be greater than 1.");
				sc.MustGetToken(',');
				sc.MustGetToken(TK_Identifier);
				if(sc.Compare("vertical"))
					cmd.flags |= DRAWSHADER_VERTICAL;
				else if(!sc.Compare("horizontal"))
					sc.ScriptError("Unknown direction '%s'.", sc.String);
				sc.MustGetToken(',');
				if(sc.CheckToken(TK_Identifier))
				{
					if(!sc.Compare("reverse"))
					{
						sc.ScriptError("Exspected 'reverse', got '%s' instead.", sc.String);
					}
					cmd.flags |= DRAWSHADER_REVERSE;
					sc.MustGetToken(',');
				}
				this->getCoordinates(sc, block.fullScreenOffsets, cmd.x, cmd.y);
				sc.MustGetToken(';');
				break;
			case SBARINFO_DRAWSTRING:
				sc.MustGetToken(TK_Identifier);
				cmd.font = V_GetFont(sc.String);
				if(cmd.font == NULL)
					sc.ScriptError("Unknown font '%s'.", sc.String);
				sc.MustGetToken(',');
				sc.MustGetToken(TK_Identifier);
				cmd.translation = this->GetTranslation(sc, sc.String);
				sc.MustGetToken(',');
				sc.MustGetToken(TK_StringConst);
				cmd.setString(sc, sc.String, 0, -1, false);
				sc.MustGetToken(',');
				this->getCoordinates(sc, block.fullScreenOffsets, cmd.x, cmd.y);
				if(sc.CheckToken(',')) //spacing
				{
					sc.MustGetToken(TK_IntConst);
					cmd.special = sc.Number;
				}
				sc.MustGetToken(';');
				break;
			case SBARINFO_DRAWKEYBAR:
				sc.MustGetToken(TK_IntConst);
				cmd.value = sc.Number;
				sc.MustGetToken(',');
				sc.MustGetToken(TK_Identifier);
				if(sc.Compare("vertical"))
					cmd.flags |= DRAWKEYBAR_VERTICAL;
				else if(!sc.Compare("horizontal"))
					sc.ScriptError("Unknown direction '%s'.", sc.String);
				sc.MustGetToken(',');
				while(sc.CheckToken(TK_Identifier))
				{
					if(sc.Compare("reverserows"))
						cmd.flags |= DRAWKEYBAR_REVERSEROWS;
					else
						sc.ScriptError("Unknown flag '%s'.", sc.String);
					if(!sc.CheckToken('|'))
						sc.MustGetToken(',');
				}
				if(sc.CheckToken(TK_Auto))
					cmd.special = -1;
				else
				{
					sc.MustGetToken(TK_IntConst);
					cmd.special = sc.Number;
				}
				sc.MustGetToken(',');
				this->getCoordinates(sc, block.fullScreenOffsets, cmd.x, cmd.y);
				if(sc.CheckToken(','))
				{
					//key offset
					sc.MustGetToken(TK_IntConst);
					cmd.special2 = sc.Number;
					if(sc.CheckToken(','))
					{
						//max per row/column
						sc.MustGetToken(TK_IntConst);
						cmd.special3 = sc.Number;
						sc.MustGetToken(',');
						//row/column spacing (opposite of previous)
						if(sc.CheckToken(TK_Auto))
							cmd.special4 = -1;
						else
						{
							sc.MustGetToken(TK_IntConst);
							cmd.special4 = sc.Number;
						}
					}
				}
				sc.MustGetToken(';');
				break;
			case SBARINFO_GAMEMODE:
				while(sc.CheckToken(TK_Identifier))
				{
					if(sc.Compare("singleplayer"))
						cmd.flags |= GAMETYPE_SINGLEPLAYER;
					else if(sc.Compare("cooperative"))
						cmd.flags |= GAMETYPE_COOPERATIVE;
					else if(sc.Compare("deathmatch"))
						cmd.flags |= GAMETYPE_DEATHMATCH;
					else if(sc.Compare("teamgame"))
						cmd.flags |= GAMETYPE_TEAMGAME;
					else if(sc.Compare("ctf"))
						cmd.flags |= GAMETYPE_CTF;
					else if(sc.Compare("oneflagctf"))
						cmd.flags |= GAMETYPE_ONEFLAGCTF;
					else if(sc.Compare("skulltag"))
						cmd.flags |= GAMETYPE_SKULLTAG;
					else if(sc.Compare("invasion"))
						cmd.flags |= GAMETYPE_INVASION;
					else if(sc.Compare("possession"))
						cmd.flags |= GAMETYPE_POSSESSION;
					else if(sc.Compare("teampossession"))
						cmd.flags |= GAMETYPE_TEAMPOSSESSION;
					else if(sc.Compare("lastmanstanding"))
						cmd.flags |= GAMETYPE_LASTMANSTANDING;
					else if(sc.Compare("teamlms"))
						cmd.flags |= GAMETYPE_TEAMLMS;
					else if(sc.Compare("survival"))
						cmd.flags |= GAMETYPE_SURVIVAL;
					else if(sc.Compare("instagib"))
						cmd.flags |= GAMETYPE_INSTAGIB;
					else if(sc.Compare("buckshot"))
						cmd.flags |= GAMETYPE_BUCKSHOT;
					//else I'm removing this error to allow cross port compatiblity.  If it doesn't know what a gamemode is lets just ignore it.
					//	sc.ScriptError("Unknown gamemode: %s", sc.String);

					if(sc.CheckToken('{'))
						break;
					sc.MustGetToken(',');
				}
				cmd.subBlock.fullScreenOffsets = block.fullScreenOffsets;
				this->ParseSBarInfoBlock(sc, cmd.subBlock);
				break;
			case SBARINFO_PLAYERCLASS:
				cmd.special = cmd.special2 = cmd.special3 = -1;
				for(int i = 0;i < 3 && sc.CheckToken(TK_Identifier);i++) //up to 3 classes
				{
					bool foundClass = false;
					for(unsigned int c = 0;c < PlayerClasses.Size();c++)
					{
						if(stricmp(sc.String, PlayerClasses[c].Type->Meta.GetMetaString(APMETA_DisplayName)) == 0)
						{
							foundClass = true;
							if(i == 0)
								cmd.special = PlayerClasses[c].Type->ClassIndex;
							else if(i == 1)
								cmd.special2 = PlayerClasses[c].Type->ClassIndex;
							else //should be 2
								cmd.special3 = PlayerClasses[c].Type->ClassIndex;
							break;
						}
					}
					if(!foundClass)
						sc.ScriptError("Unkown PlayerClass '%s'.", sc.String);
					if(sc.CheckToken('{') || i == 2)
						goto FinishPlayerClass;
					sc.MustGetToken(',');
				}
			FinishPlayerClass:
				cmd.subBlock.fullScreenOffsets = block.fullScreenOffsets;
				this->ParseSBarInfoBlock(sc, cmd.subBlock);
				break;
			case SBARINFO_ASPECTRATIO:
				sc.MustGetToken(TK_StringConst);
				if(sc.Compare("4:3"))
					cmd.value = ASPECTRATIO_4_3;
				else if(sc.Compare("16:9"))
					cmd.value = ASPECTRATIO_16_9;
				else if(sc.Compare("16:10"))
					cmd.value = ASPECTRATIO_16_10;
				else if(sc.Compare("5:4"))
					cmd.value = ASPECTRATIO_5_4;
				else
					sc.ScriptError("Unkown aspect ratio: %s", sc.String);
				sc.MustGetToken('{');
				cmd.subBlock.fullScreenOffsets = block.fullScreenOffsets;
				this->ParseSBarInfoBlock(sc, cmd.subBlock);
				break;
			case SBARINFO_ISSELECTED:
				//Using StringConst instead of Identifieres is deperecated!
				if(sc.CheckToken(TK_Identifier))
				{
					if(sc.Compare("not"))
					{
						cmd.flags |= SBARINFOEVENT_NOT;
						if(!sc.CheckToken(TK_StringConst))
							sc.MustGetToken(TK_Identifier);
					}
				}
				else
					sc.MustGetToken(TK_StringConst);
				for(int i = 0;i < 2;i++)
				{
					cmd.setString(sc, sc.String, i);
					const PClass* item = PClass::FindClass(sc.String);
					if(item == NULL || !RUNTIME_CLASS(AWeapon)->IsAncestorOf(item))
					{
						sc.ScriptError("'%s' is not a type of weapon.", sc.String);
					}
					if(sc.CheckToken(','))
					{
						if(!sc.CheckToken(TK_StringConst))
							sc.MustGetToken(TK_Identifier);
					}
					else
						break;
				}
				sc.MustGetToken('{');
				cmd.subBlock.fullScreenOffsets = block.fullScreenOffsets;
				this->ParseSBarInfoBlock(sc, cmd.subBlock);
				break;
			case SBARINFO_USESSECONDARYAMMO:
			case SBARINFO_USESAMMO:
				if(sc.CheckToken(TK_Identifier))
				{
					if(sc.Compare("not"))
						cmd.flags |= SBARINFOEVENT_NOT;
					else
						sc.ScriptError("Expected 'not' got '%s' instead.", sc.String);
				}
				sc.MustGetToken('{');
				cmd.subBlock.fullScreenOffsets = block.fullScreenOffsets;
				this->ParseSBarInfoBlock(sc, cmd.subBlock);
				break;
			case SBARINFO_HASWEAPONPIECE:
			{
				sc.MustGetToken(TK_Identifier);
				const PClass* weapon = PClass::FindClass(sc.String);
				if(weapon == NULL || !RUNTIME_CLASS(AWeapon)->IsAncestorOf(weapon)) //must be a weapon
					sc.ScriptError("%s is not a kind of weapon.", sc.String);
				cmd.setString(sc, sc.String, 0);
				sc.MustGetToken(',');
				sc.MustGetToken(TK_IntConst);
				if(sc.Number < 1)
					sc.ScriptError("Weapon piece number can not be less than 1.");
				cmd.value = sc.Number;
				sc.MustGetToken('{');
				cmd.subBlock.fullScreenOffsets = block.fullScreenOffsets;
				this->ParseSBarInfoBlock(sc, cmd.subBlock);
				break;
			}
			case SBARINFO_INVENTORYBARNOTVISIBLE:
				sc.MustGetToken('{');
				cmd.subBlock.fullScreenOffsets = block.fullScreenOffsets;
				this->ParseSBarInfoBlock(sc, cmd.subBlock);
				break;
			case SBARINFO_WEAPONAMMO:
				sc.MustGetToken(TK_Identifier);
				if(sc.Compare("not"))
				{
					cmd.flags |= SBARINFOEVENT_NOT;
					sc.MustGetToken(TK_Identifier);
				}
				for(int i = 0;i < 2;i++)
				{
					cmd.setString(sc, sc.String, i);
					const PClass* ammo = PClass::FindClass(sc.String);
					if(ammo == NULL || !RUNTIME_CLASS(AAmmo)->IsAncestorOf(ammo)) //must be a kind of ammo
					{
						sc.ScriptError("'%s' is not a type of ammo.", sc.String);
					}
					if(sc.CheckToken(TK_OrOr))
					{
						cmd.flags |= SBARINFOEVENT_OR;
						sc.MustGetToken(TK_Identifier);
					}
					else if(sc.CheckToken(TK_AndAnd))
					{
						cmd.flags |= SBARINFOEVENT_AND;
						sc.MustGetToken(TK_Identifier);
					}
					else
						break;
				}
				sc.MustGetToken('{');
				cmd.subBlock.fullScreenOffsets = block.fullScreenOffsets;
				this->ParseSBarInfoBlock(sc, cmd.subBlock);
				break;
			case SBARINFO_ININVENTORY:
				cmd.special2 = cmd.special3 = 0;
				sc.MustGetToken(TK_Identifier);
				if(sc.Compare("not"))
				{
					cmd.flags |= SBARINFOEVENT_NOT;
					sc.MustGetToken(TK_Identifier);
				}
				for(int i = 0;i < 2;i++)
				{
					cmd.setString(sc, sc.String, i);
					const PClass* item = PClass::FindClass(sc.String);
					if(item == NULL || !RUNTIME_CLASS(AInventory)->IsAncestorOf(item))
					{
						sc.ScriptError("'%s' is not a type of inventory item.", sc.String);
					}
					if (sc.CheckToken(','))
					{
						sc.MustGetNumber();
						if (i == 0) cmd.special2 = sc.Number;
						else cmd.special3 = sc.Number;
					}

					if(sc.CheckToken(TK_OrOr))
					{
						cmd.flags |= SBARINFOEVENT_OR;
						sc.MustGetToken(TK_Identifier);
					}
					else if(sc.CheckToken(TK_AndAnd))
					{
						cmd.flags |= SBARINFOEVENT_AND;
						sc.MustGetToken(TK_Identifier);
					}
					else
						break;
				}
				sc.MustGetToken('{');
				cmd.subBlock.fullScreenOffsets = block.fullScreenOffsets;
				this->ParseSBarInfoBlock(sc, cmd.subBlock);
				break;
		}
		block.commands.Push(cmd);
	}
	sc.MustGetToken('}');
}
Beispiel #13
0
void enhanceImage(QImage &origin, const QString &pathToImage)
{
    QImage newImage(origin);
    int kernel[3][3] = { { 0, -3, 0 }, { -3, 50, -3 }, { 0, -3, 0 } };
    // int kernelSize = 3;
    constexpr int kernelDiv2 = 1;
    constexpr int sumKernel = 38;
    int r1, g1, b1, r2, g2, b2, r3, g3, b3, r4, g4, b4;
    QColor color;
    int N1 = (newImage.width() - kernelDiv2) / 4;
    int N2 = (newImage.height() - kernelDiv2) / 4;
    for (int x = kernelDiv2; x <= N1; ++x) {
        for (int y = kernelDiv2; y <= N2; ++y) {

            r1 = 0;
            g1 = 0;
            b1 = 0;

            for (int i = -kernelDiv2; i <= kernelDiv2; ++i) {
                for (int j = -kernelDiv2; j <= kernelDiv2; ++j) {
                    color = QColor(origin.pixel(x + i, y + j));
                    r1 += color.red() * kernel[kernelDiv2 + i][kernelDiv2 + j];
                    g1 +=
                        color.green() * kernel[kernelDiv2 + i][kernelDiv2 + j];
                    b1 += color.blue() * kernel[kernelDiv2 + i][kernelDiv2 + j];
                }
            }
            r1 = qBound(0, r1 / sumKernel, 255);
            g1 = qBound(0, g1 / sumKernel, 255);
            b1 = qBound(0, b1 / sumKernel, 255);

            newImage.setPixel(x, y, qRgb(r1, g1, b1));

            r2 = 0;
            g2 = 0;
            b2 = 0;

            for (int i = -kernelDiv2; i <= kernelDiv2; ++i) {
                for (int j = -kernelDiv2; j <= kernelDiv2; ++j) {
                    color = QColor(origin.pixel(x + N1 + i, y + N2 + j));
                    r2 += color.red() * kernel[kernelDiv2 + i][kernelDiv2 + j];
                    g2 +=
                        color.green() * kernel[kernelDiv2 + i][kernelDiv2 + j];
                    b2 += color.blue() * kernel[kernelDiv2 + i][kernelDiv2 + j];
                }
            }
            r2 = qBound(0, r2 / sumKernel, 255);
            g2 = qBound(0, g2 / sumKernel, 255);
            b2 = qBound(0, b2 / sumKernel, 255);

            newImage.setPixel(x + N1, y + N2, qRgb(r2, g2, b2));

            r3 = 0;
            g3 = 0;
            b3 = 0;

            for (int i = -kernelDiv2; i <= kernelDiv2; ++i) {
                for (int j = -kernelDiv2; j <= kernelDiv2; ++j) {
                    color =
                        QColor(origin.pixel(x + 2 * N1 + i, y + 2 * N2 + j));
                    r3 += color.red() * kernel[kernelDiv2 + i][kernelDiv2 + j];
                    g3 +=
                        color.green() * kernel[kernelDiv2 + i][kernelDiv2 + j];
                    b3 += color.blue() * kernel[kernelDiv2 + i][kernelDiv2 + j];
                }
            }
            r3 = qBound(0, r3 / sumKernel, 255);
            g3 = qBound(0, g3 / sumKernel, 255);
            b3 = qBound(0, b3 / sumKernel, 255);

            newImage.setPixel(x + 2 * N1, y + 2 * N2, qRgb(r3, g3, b3));

            r4 = 0;
            g4 = 0;
            b4 = 0;

            for (int i = -kernelDiv2; i <= kernelDiv2; ++i) {
                for (int j = -kernelDiv2; j <= kernelDiv2; ++j) {
                    color = QColor(
                        origin.pixel(x + 3 * N1 + i - 1, y + 3 * N2 + j - 1));
                    r4 += color.red() * kernel[kernelDiv2 + i][kernelDiv2 + j];
                    g4 +=
                        color.green() * kernel[kernelDiv2 + i][kernelDiv2 + j];
                    b4 += color.blue() * kernel[kernelDiv2 + i][kernelDiv2 + j];
                }
            }
            r4 = qBound(0, r4 / sumKernel, 255);
            g4 = qBound(0, g4 / sumKernel, 255);
            b4 = qBound(0, b4 / sumKernel, 255);

            newImage.setPixel(x + 3 * N1, y + 3 * N2, qRgb(r4, g4, b4));
        }
    }
    newImage.save(pathToImage);
}
int main(int argc,char *argv[])
{


    float beta;
    int* tab;
    int xmin;
    int xmax;
    int ymax;
    int ymin;

    // Loading image
    char* imagePath = argv[1];

    cimg_library::CImg<unsigned char> image(imagePath);
    // Patch size
    int w;
    cout << "Please enter size of Patch (must be odd and positive): ";
    cin >> w;
    bool odd = (w-(w/2)*2!=0);
    assert(odd);
    bool positive = (w>=0);
    assert(positive);
    // Minimum offset size
    int tau;
    cout << "Please enter minimum offset value (must be positive): ";
    cin >>tau;
    positive = (tau>=0);
    assert(positive);
    // Random search parameter
    float alpha;
    cout << "Please enter alpha (random search parameter) value (must be between 0 and 1): ";
    cin >> alpha;
    positive = (alpha>=0);
    assert(positive);
    bool inferior_one = (alpha<1);
    assert(inferior_one);
    // Number of vectors to keep
    int nb;
    cout << "Please enter the number of offsets to keep: ";
    cin >> nb;
    positive = (nb>=0);
    assert(positive);

    // Loading offset field

    int** offsetField = patchmatch(image,w,tau,alpha);
    int** tabVect = occurrenceOffsets(offsetField,image,w,nb);


    while(true){
    // Zone to complete
    tab = getXYImage(image);
    xmin = tab[0];
    ymin = tab[1];

if (tab[0]==-1){return 0;}

    tab = getXYImage(image);
    xmax = tab[0];
    ymax = tab[1];

if (tab[0]==-1){return 0;}

    cout << "Please enter Beta value: ";
    cin >> beta;

    int width = image.width();
    int height = image.height();
    cimg_library::CImg<unsigned char> newImage(width,height,1,3);
    newImage = graphcut(image,tabVect,xmin,xmax,ymin,ymax,w,beta,nb);
    displayImage(newImage);
    }

return 0;
}
Beispiel #15
0
void MjpegClient::processBlock()
{
	if(m_boundary.isEmpty())
	{
		// still waiting for boundary string defenition, check for content type in data block
		char * ctypeString = 0;
		if(m_dataBlock.contains("Content-Type:"))
		{
			ctypeString = "Content-Type:";
		}
		else
		if(m_dataBlock.contains("content-type:"))
		{
			// allow for buggy servers (some IP cameras - trendnet I'm looking at you!) sometimes dont use proper
			// case in their headers.
			ctypeString = "content-type:";
		}
		
		if(ctypeString)
		{
			int ctypeIdx = m_dataBlock.indexOf(ctypeString);
			if(ctypeIdx < 0)
			{
				qDebug() << "Error: Can't find content-type index in data block, exiting.";
				exit();
				return;
			}
			
			static QString boundaryMarker = "boundary=";
			int boundaryStartIdx = m_dataBlock.indexOf(boundaryMarker,ctypeIdx);
			if(boundaryStartIdx < 0)
			{
				qDebug() << "Error: Can't find boundary index after the first content-type index in data block, exiting.";
				exit();
				return;
			}
			
			int eolIdx = m_dataBlock.indexOf("\n",boundaryStartIdx);
			int pos = boundaryStartIdx + boundaryMarker.length();
			m_boundary = m_dataBlock.mid(pos, eolIdx - pos);
			m_boundary.replace("\r","");
// 			qDebug() << "processBlock(): m_boundary:"<<m_boundary<<", pos:"<<pos<<", eolIdx:"<<eolIdx;
		}
	}
	else
	{
		// we have the boundary string defenition, check for the boundary string in the data block.
		// If found, grab the data from the start of the block up to and including the boundary, leaving any data after the boundary in the block.
		// What we then have to process could look:
		// Content-Type.....\r\n(data)--(boundary)
		
		// If its the first block, we wait for the boundary, but discard it since the first block is the one that contains the server headers
		// like the boundary definition, Server:, Connection:, etc.
		int idx = m_dataBlock.indexOf(m_boundary);
		
		while(idx > 0)
		{
			QByteArray block = m_dataBlock.left(idx);
			
			int blockAndBoundaryLength = idx + m_boundary.length();
			m_dataBlock.remove(0,blockAndBoundaryLength);
			//qDebug() << "processBlock(): block length:"<<block.length()<<", blockAndBoundaryLength:"<<blockAndBoundaryLength;
			
			if(m_firstBlock)
			{
				QString string = block;
				//qDebug() << "processBlock(): Discarding block since first block flag is true. Dump of block:\n"<<string;
				m_firstBlock = false;
			}
			else
			{
				static const char * eol1 = "\n\n";
				static const char * eol2 = "\r\n\r\n";
				int headerLength = 0;
				if(block.contains(eol2))
					headerLength = block.indexOf(eol2,0) + 4;
				else
				if(block.contains(eol1))
					headerLength = block.indexOf(eol1,0) + 2;
				
				if(headerLength)
				{
					QString header = block.left(headerLength);
					
					block.remove(0,headerLength);
					
					// Block should now be just data
					//qDebug() << "processBlock(): block length:"<<block.length()<<", headerLength:"<<headerLength<<", header:"<<header;
					
					// TODO: do something with contents block - like write to a file, emit signal, whatever.
					if(block.length() > 0)
					{
					
						QImage frame = QImage::fromData(block);
						emit newImage(frame);
						
						#ifdef MJPEG_TEST
						QPixmap pix = QPixmap::fromImage(frame);
						m_label->setPixmap(pix);
						m_label->resize(pix.width(),pix.height());
						#endif
						
						
					
// 						static QString filename = "test.jpg";
// 						QFile file(filename);
// 						
// 						if(!file.open(QIODevice::WriteOnly))
// 						{
// 							qDebug() << "processBlock(): Unable to open "<<filename<<" for writing";
// 						}
// 						else
// 						{
// 							qint64 bytes = file.write(block);
// 							file.close();
// 							qDebug() << "processBlock(): Wrote"<<bytes<<" to "<<filename;
// 						}
					}
				}

			}
			
			// check for another boundary string in the data before exiting from processBlock()
			idx = m_dataBlock.indexOf(m_boundary);
		}
		
	}
	
// 	qDebug() << "processBlock(): End of processing, m_dataBlock.size() remaining:"<<m_dataBlock.size();
	
}
void ExpandCelCanvas::commit()
{
  ASSERT(!m_closed);
  ASSERT(!m_committed);

  if (!m_layer) {
    m_committed = true;
    return;
  }

  // Was the cel created in the start of the tool-loop?
  if (m_celCreated) {
    ASSERT(m_cel);
    ASSERT(!m_celImage);

    // Validate the whole m_dstImage (invalid areas are cleared, as we
    // don't have a m_celImage)
    validateDestCanvas(gfx::Region(m_bounds));

    // We can temporary remove the cel.
    if (m_layer->isImage()) {
      static_cast<LayerImage*>(m_layer)->removeCel(m_cel);

      // Add a copy of m_dstImage in the sprite's image stock
      gfx::Rect trimBounds = getTrimDstImageBounds();
      if (!trimBounds.isEmpty()) {
        ImageRef newImage(trimDstImage(trimBounds));
        ASSERT(newImage);

        m_cel->data()->setImage(newImage);
        m_cel->setPosition(m_cel->position() + trimBounds.origin());

        // And finally we add the cel again in the layer.
        m_transaction.execute(new cmd::AddCel(m_layer, m_cel));
      }
    }
    // We are selecting inside a layer group...
    else {
      // Just delete the created layer
      delete m_cel;
      m_cel = nullptr;
    }
  }
  else if (m_celImage) {
    // Restore cel position to its original position
    m_cel->setPosition(m_origCelPos);

    ASSERT(m_cel->image() == m_celImage.get());

    gfx::Region* regionToPatch = &m_validDstRegion;
    gfx::Region reduced;

    if (m_canCompareSrcVsDst) {
      ASSERT(gfx::Region().createSubtraction(m_validDstRegion, m_validSrcRegion).isEmpty());

      for (gfx::Rect rc : m_validDstRegion) {
        if (algorithm::shrink_bounds2(getSourceCanvas(),
                                      getDestCanvas(), rc, rc)) {
          reduced |= gfx::Region(rc);
        }
      }

      regionToPatch = &reduced;
    }

    if (m_layer->isBackground()) {
      m_transaction.execute(
        new cmd::CopyRegion(
          m_cel->image(),
          m_dstImage.get(),
          *regionToPatch,
          m_bounds.origin()));
    }
    else {
      m_transaction.execute(
        new cmd::PatchCel(
          m_cel,
          m_dstImage.get(),
          *regionToPatch,
          m_bounds.origin()));
    }
  }
  else {
    ASSERT(false);
  }

  m_committed = true;
}
bool QgsCompositionChecker::testComposition( QString &report, int page, int pixelDiff )
{
  if ( !mComposition )
  {
    return false;
  }

  setControlName( "expected_" + mTestName );

#if 0
  //fake mode to generate expected image
  //assume 96 dpi and size of the control image 1122 * 794
  QImage newImage( QSize( 1122, 794 ), QImage::Format_ARGB32 );
  mComposition->setPlotStyle( QgsComposition::Print );
  newImage.setDotsPerMeterX( 96 / 25.4 * 1000 );
  newImage.setDotsPerMeterY( 96 / 25.4 * 1000 );
  newImage.fill( 0 );
  QPainter expectedPainter( &newImage );
  //QRectF sourceArea( 0, 0, mComposition->paperWidth(), mComposition->paperHeight() );
  //QRectF targetArea( 0, 0, 3507, 2480 );
  mComposition->renderPage( &expectedPainter, page );
  expectedPainter.end();
  newImage.save( mExpectedImageFile, "PNG" );
  return true;
#endif //0

  //load expected image
  QImage expectedImage( mExpectedImageFile );

  //get width/height, create image and render the composition to it
  int width = expectedImage.width();
  int height = expectedImage.height();
  QImage outputImage( QSize( width, height ), QImage::Format_ARGB32 );

  mComposition->setPlotStyle( QgsComposition::Print );
  outputImage.setDotsPerMeterX( expectedImage.dotsPerMeterX() );
  outputImage.setDotsPerMeterY( expectedImage.dotsPerMeterX() );
  outputImage.fill( 0 );
  QPainter p( &outputImage );
  mComposition->renderPage( &p, page );
  p.end();

  QString renderedFilePath = QDir::tempPath() + QDir::separator() + QFileInfo( mTestName ).baseName() + "_rendered.png";
  outputImage.save( renderedFilePath, "PNG" );

  QString diffFilePath = QDir::tempPath() + QDir::separator() + QFileInfo( mTestName ).baseName() + "_result_diff.png";

  bool testResult = compareImages( mTestName, pixelDiff, renderedFilePath );

  QString myDashMessage = "<DartMeasurementFile name=\"Rendered Image " + mTestName + "\""
                          " type=\"image/png\">" + renderedFilePath +
                          "</DartMeasurementFile>"
                          "<DartMeasurementFile name=\"Expected Image " + mTestName + "\" type=\"image/png\">" +
                          mExpectedImageFile + "</DartMeasurementFile>"
                          "<DartMeasurementFile name=\"Difference Image " + mTestName + "\" type=\"image/png\">" +
                          diffFilePath + "</DartMeasurementFile>";
  qDebug( ) << myDashMessage;

  report += mReport;
  return testResult;
}
Beispiel #18
0
void ExpandCelCanvas::commit()
{
  ASSERT(!m_closed);
  ASSERT(!m_committed);

  // Was the cel created in the start of the tool-loop?
  if (m_celCreated) {
    ASSERT(m_cel);
    ASSERT(!m_celImage);

    // Validate the whole m_dstImage (invalid areas are cleared, as we
    // don't have a m_celImage)
    validateDestCanvas(gfx::Region(m_bounds));

    // We can temporary remove the cel.
    static_cast<LayerImage*>(m_layer)->removeCel(m_cel);

    // Add a copy of m_dstImage in the sprite's image stock
    ImageRef newImage(Image::createCopy(m_dstImage.get()));
    m_cel->data()->setImage(newImage);

    // And finally we add the cel again in the layer.
    m_transaction.execute(new cmd::AddCel(m_layer, m_cel));
  }
  else if (m_celImage) {
    // If the size of each image is the same, we can create an undo
    // with only the differences between both images.
    if (m_cel->position() == m_origCelPos &&
        m_bounds.origin() == m_origCelPos &&
        m_celImage->width() == m_dstImage->width() &&
        m_celImage->height() == m_dstImage->height()) {
      int dx = -m_bounds.x + m_origCelPos.x;
      int dy = -m_bounds.y + m_origCelPos.y;

      if ((m_flags & UseModifiedRegionAsUndoInfo) != UseModifiedRegionAsUndoInfo) {
        // TODO Reduce m_validDstRegion to modified areas between
        //      m_celImage and m_dstImage
      }

      // Copy the destination to the cel image.
      m_transaction.execute(new cmd::CopyRegion(
          m_celImage.get(), m_dstImage.get(), m_validDstRegion, dx, dy));
    }
    // If the size of both images are different, we have to
    // replace the entire image.
    else {
      if (m_cel->position() != m_origCelPos) {
        gfx::Point newPos = m_cel->position();
        m_cel->setPosition(m_origCelPos);
        m_transaction.execute(new cmd::SetCelPosition(m_cel, newPos.x, newPos.y));
      }

      // Validate the whole m_dstImage copying invalid areas from m_celImage
      validateDestCanvas(gfx::Region(m_bounds));

      // Replace the image in the stock. We need to create a copy of
      // image because m_dstImage's ImageBuffer cannot be shared.
      ImageRef newImage(Image::createCopy(m_dstImage.get()));
      m_transaction.execute(new cmd::ReplaceImage(
          m_sprite, m_celImage, newImage));
    }
  }
  else {
    ASSERT(false);
  }

  m_committed = true;
}
Beispiel #19
0
Images FrameData::startReadback( const Frame& frame,
                                 util::ObjectManager& glObjects,
                                 const DrawableConfig& config,
                                 const PixelViewports& regions )
{
    if( _impl->data.buffers == Frame::BUFFER_NONE )
        return Images();

    const Zoom& zoom = frame.getZoom();
    if( !zoom.isValid( ))
    {
        LBWARN << "Invalid zoom factor, skipping frame" << std::endl;
        return Images();
    }

    const eq::PixelViewport& framePVP = getPixelViewport();
    const PixelViewport      absPVP   = framePVP + frame.getOffset();
    if( !absPVP.isValid( ))
        return Images();

    Images images;

    // readback the whole screen when using textures
    if( getType() == eq::Frame::TYPE_TEXTURE )
    {
        Image* image = newImage( getType(), config );
        if( image->startReadback( getBuffers(), absPVP, zoom, glObjects ))
            images.push_back( image );
        image->setOffset( 0, 0 );
        return images;
    }
    //else read only required regions

#if 0
    // TODO: issue #85: move automatic ROI detection to eq::Channel
    PixelViewports regions;
    if( _impl->data.buffers & Frame::BUFFER_DEPTH && zoom == Zoom::NONE )
        regions = _impl->roiFinder->findRegions( _impl->data.buffers, absPVP,
                                                 zoom, frame.getAssemblyStage(),
                                                 frame.getFrameID(), glObjects);
    else
        regions.push_back( absPVP );
#endif

    LBASSERT( getType() == eq::Frame::TYPE_MEMORY );
    const eq::Pixel& pixel = getPixel();

    for( uint32_t i = 0; i < regions.size(); ++i )
    {
        PixelViewport pvp = regions[ i ] + frame.getOffset();
        pvp.intersect( absPVP );
        if( !pvp.hasArea( ))
            continue;

        Image* image = newImage( getType(), config );
        if( image->startReadback( getBuffers(), pvp, zoom, glObjects ))
            images.push_back( image );

        pvp -= frame.getOffset();
        pvp.apply( zoom );
        image->setOffset( (pvp.x - framePVP.x) * pixel.w,
                          (pvp.y - framePVP.y) * pixel.h );
    }
    return images;
}
Beispiel #20
0
void PaintArea::setImageSize(int width, int height)
{
    QImage newImage(width,height,QImage::Format_RGB32);
    image = newImage;
    update();
}
Beispiel #21
0
  //! Starts the socket thread
  void SocketThread::run() {
    std::string p_socketFile = ("/tmp/isis_qview_" + Application::UserName()).toAscii().data();
    struct sockaddr_un p_socketName;
    p_socketName.sun_family = AF_UNIX;
    strcpy(p_socketName.sun_path, p_socketFile.c_str());
    int p_socket;

    // Create a socket
    if((p_socket = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) {
      std::string msg = "Unable to create socket";
      std::cerr << msg << std::endl;
      remove(p_socketFile.c_str());
      return;
    }

    // Setting a timeout didn't work for Mac, so we're using a non-blocking mode
    //   instead.
    fcntl(p_socket, F_SETFL, O_NONBLOCK);

    // Bind the file to the socket
    int status =  bind(p_socket, (struct sockaddr *)&p_socketName, sizeof(p_socketName));
    if(status < 0) {
      std::string msg = "Unable to bind to socket [" + p_socketFile + "]";
      std::cerr << msg << std::endl;
      remove(p_socketFile.c_str());
      return;
    }

    // Set up to listen to the socket
    if(listen(p_socket, 5) < 0) {
      std::string msg = "Unable to listen to socket [" + p_socketFile + "]";
      std::cerr << msg << std::endl;
      remove(p_socketFile.c_str());
      return;
    }

    p_done = false;

    while(!p_done) {
      // Accept Socket
      socklen_t len = sizeof(&p_socketName);
      int childSocket = accept(p_socket, (struct sockaddr *)&p_socketName, &len);
      if (childSocket < 0)
        if (errno == EWOULDBLOCK) {
          msleep(100);
        continue; // probably timed out, we cant do anything about this anyways
      }

      // Receive Data
      int bytes;
      // This used to be char buf[1024*1024]; but when that line existed the
      //   mac OS's would crash unpredictably, even when the code on that
      //   line wasn't executed.
      QScopedPointer< char, QScopedPointerArrayDeleter<char> > buf(
          new char[1024*1024]);
      if((bytes = recv(childSocket, buf.data(), 1024 * 1024, 0)) < 0) {
        std::string msg = "Unable to read from socket [" + p_socketFile + "]";
        std::cerr << msg << std::endl;
        remove(p_socketFile.c_str());
        return;
      }

      // Push everything onto our string buffer
      IString buffer;
      for(int i = 0; i < bytes; i++) buffer += buf.data()[i];
      while(buffer.size() > 0) {
        IString token = buffer.Token(" ");
        if(token == "raise") {
          emit focusApp();
        }
        else emit newImage(token.c_str());
      }
    };
  }
Beispiel #22
0
void Map::convertToGrid()
{
	// Define variables.
	double MapResolutionCM = 2.5;
	double GridResolutionCM = 10;
	double GridResolutionPixels = GridResolutionCM / MapResolutionCM; // 4 pixels
	std::vector<unsigned char> newImage(((int)((width * height * 4) / GridResolutionPixels)));
	bool foundBlack;
	unsigned int newLocation;
	unsigned int newRow;
	unsigned int newCol;
	unsigned int location;
	gridWidth = (width - 2)/4;
	gridHeight = height/ 4;

	// Going on the given map rows.
	for (int row = 0; row < height * width * 4; row += width * GridResolutionPixels * 4)
	{
		// Going on the given map columns.
		for (int col = 0; col < (width - 2) * 4; col += GridResolutionPixels *4)
		{
			// Calculating the current cell (location).
			location = row + col;

			foundBlack = false;

			// Going on the square which will be equal to one cell on the Grid Map.
			// Going on the rows.
			for (int y = 0; y < GridResolutionPixels; y++)
			{
				// Going on the columns.
				for (int x = 0; x < GridResolutionPixels; x++)
				{
					// Calculating how many cells we should skip in order to get to the cell.
					int shifting = location + (x + (y * width)) * 4;
					unsigned int r = image[shifting];
					unsigned int g = image[shifting + 1];
					unsigned int b = image[shifting + 2];

					// It's enough to find one black pixel on the current square,
					// in order to set the whole cell as black on the Grid Map.
					if (r == 0 && g == 0 && b == 0)
					{
						foundBlack = true;
					}
				}
			}

			// Calculating the current row,column and cell eventually on the Grid.
			newRow = (row / (int)(width * GridResolutionPixels * 4)) *
						((width-2)/GridResolutionPixels) * 4;
			newCol = (col / GridResolutionPixels);
			newLocation = newRow + newCol;

			// Paint the cell.
			if (foundBlack)
			{
				newImage[newLocation] = 0;
				newImage[newLocation + 1] = 0;
				newImage[newLocation + 2] = 0;
				newImage[newLocation + 3] = 255;
			}
			else
			{
				newImage[newLocation] = 255;
				newImage[newLocation + 1] = 255;
				newImage[newLocation + 2] = 255;
				newImage[newLocation + 3] = 255;
			}
		}
	}

	grid = newImage;
	writePng("galvemoris.png", newImage, width / GridResolutionPixels, height / GridResolutionPixels);
}
Beispiel #23
0
Image::Image(int width, int height) {
	newImage(width, height);
}
Beispiel #24
0
Fenetre::Fenetre(QWidget *parent) : courant(0), QMainWindow(parent)
{
    //*************************
    courant = NULL;
    folder = NULL;
    resize(1200, 512);
    //*************************** Menu ***************************
    QMenu* mFile = menuBar()->addMenu("&File");
    QMenu* mEdit = menuBar()->addMenu("&Edit");
    QMenu* mView = menuBar()->addMenu("&View");


    QMenu* mNouveau = mFile->addMenu("New");
    QAction* mactionAnnuler = mEdit->addAction("Annuler");
    QAction* mactionRefaire = mEdit->addAction("Refaire");
    QAction* mactionSupprimer = mEdit->addAction("Supprimer");
    QMenu* mTag = mEdit->addMenu("Tags");
    QAction* mactionSupprimerTag = mTag->addAction("Supprimer");
    QMenu* mDocument = mEdit->addMenu("Documents");
    QAction* mactionUp = mDocument->addAction("Monter");
    QAction* mactionDown = mDocument->addAction("Descendre");
    QMenu* mExport = mEdit->addMenu("Exporter");
    QAction* mactionOuvrir = mFile->addAction("Ouvrir un espace de travail");
    QAction* mactionNew = mFile->addAction("Nouvel espace de travail");
    QAction* mactionSaveAs = mFile->addAction("Enregistrer sous...");
    QAction* mactionNewArticle = mNouveau->addAction("Article");
    QAction* mactionNewImage = mNouveau->addAction("Image");
    QAction* mactionNewAudio = mNouveau->addAction("Audio");
    QAction* mactionNewVideo = mNouveau->addAction("Video");
    QAction* mactionNewDocument = mNouveau->addAction("Document");

    QAction* mactionExportHTML = mExport->addAction("Html");
    QAction* mactionExportTex = mExport->addAction("Tex");
    QAction* mactionExportTexte = mExport->addAction("Texte");
    QAction* mactionOption=mEdit->addAction("Setting");

    QAction* mactionAddTag = mNouveau->addAction("Tag");

    QAction* mactionSave = mFile->addAction("Sauvegarder");
    mFile->addSeparator();
    QMenu* ouvrirCorbeille = mFile->addMenu("Corbeille");
    QAction* mactionRestaurer = ouvrirCorbeille->addAction("Restaurer");
    QAction* mactionVider = ouvrirCorbeille->addAction("Vider la Corbeille");

    mactionViewEdit = mView->addAction("Onglet Editeur");
    mactionViewHTML = mView->addAction("Onglet Html");
    mactionViewTex = mView->addAction("Onglet Tex");
    mactionViewTexte = mView->addAction("Onglet Texte");

    mFile->addSeparator();
    QAction* actionQuitter = mFile->addAction("&Quitter");
    actionQuitter->setIcon(QIcon("icon/quitter.png"));
    mactionNewArticle->setIcon(QIcon("icon/article.png"));
    mactionNewImage->setIcon(QIcon("icon/image.png"));
    mactionNewAudio->setIcon(QIcon("icon/audio.png"));
    mactionNewVideo->setIcon(QIcon("icon/video.png"));
    mNouveau->setIcon(QIcon("icon/plus.png"));
    mactionDown->setIcon(QIcon("icon/down.png"));
    mactionUp->setIcon(QIcon("icon/up.png"));
    mactionAddTag->setIcon(QIcon("icon/tag.png"));
    mactionSave->setIcon(QIcon("icon/save.png"));

    mactionExportHTML->setIcon(QIcon("icon/html.png"));
    mactionExportTex->setIcon(QIcon("icon/tex.png"));
    mactionExportTexte->setIcon(QIcon("icon/texte.png"));

    mactionAnnuler->setIcon(QIcon("icon/undo.png"));
    mactionRefaire->setIcon(QIcon("icon/redo.png"));
    mactionSupprimer->setIcon(QIcon("icon/cross.png"));
    mactionRestaurer->setIcon(QIcon("icon/corbeille.png"));
    mactionNewDocument->setIcon(QIcon("icon/document.png"));
    mactionOption->setIcon(QIcon("icon/setting.png"));


    mactionOuvrir->setShortcut(QKeySequence("Ctrl+O"));
    actionQuitter->setShortcut(QKeySequence("Ctrl+Q"));
    mactionSave->setShortcut(QKeySequence("Ctrl+S"));

    mactionAnnuler->setShortcut(QKeySequence("Ctrl+Z"));
    mactionRefaire->setShortcut(QKeySequence("Ctrl+Y"));
    mactionSupprimer->setShortcut(tr("Delete"));

    //** VIEW **//
    mactionViewEdit->setCheckable(true);
    mactionViewEdit->setChecked(true);
    mactionViewHTML->setCheckable(true);
    mactionViewTex->setCheckable(true);
    mactionViewTexte->setCheckable(true);


    //Bar de statue
    QStatusBar* statusBar = new QStatusBar;
    statusBar->addWidget(new QLabel("Projet Lo21 - Pauline Crouillère / Emilien Notarianni"));
    this->setStatusBar(statusBar);
    // Création de la barre d'outils
    QToolBar *toolBarFichier = addToolBar("Fichier");

    toolBarFichier->addAction(mactionNewArticle);
    toolBarFichier->addAction(mactionNewImage);
    toolBarFichier->addAction(mactionNewAudio);
    toolBarFichier->addAction(mactionNewVideo);
    toolBarFichier->addAction(mactionNewDocument);
    toolBarFichier->addSeparator();
    toolBarFichier->addAction(mactionAddTag);
    toolBarFichier->addSeparator();
    toolBarFichier->addAction(mactionUp);
    toolBarFichier->addAction(mactionDown);
    toolBarFichier->addSeparator();

    toolBarFichier->addAction(mactionExportHTML);
    toolBarFichier->addAction(mactionExportTex);
    toolBarFichier->addAction(mactionExportTexte);
    toolBarFichier->addSeparator();
    toolBarFichier->addAction(mactionRestaurer);
    toolBarFichier->addSeparator();
    toolBarFichier->addAction(mactionSupprimer);
    toolBarFichier->addSeparator();
    toolBarFichier->addAction(actionQuitter);

    /*************************************************************/
    couche = new QHBoxLayout();
    lw = new LeftWindows();
    ow = new OngletWindows();
    couche->addWidget(lw);
    couche->addWidget(ow);
    couche->setMargin(0);
    couche->setAlignment(Qt::AlignTop);
    centerWindows = new QWidget();
    centerWindows->setLayout(couche);
    setCentralWidget(centerWindows);

    //************************** CONNECT **************************/
    QObject::connect(mactionNewArticle, SIGNAL(triggered()), this, SLOT(newArticle()));
    QObject::connect(mactionNewDocument, SIGNAL(triggered()), this, SLOT(newDocument()));
    QObject::connect(mactionNewImage, SIGNAL(triggered()), this, SLOT(newImage()));
    QObject::connect(mactionNewAudio, SIGNAL(triggered()), this, SLOT(newAudio()));
    QObject::connect(mactionNewVideo, SIGNAL(triggered()), this, SLOT(newVideo()));
    QObject::connect(mactionAddTag, SIGNAL(triggered()), this, SLOT(newTag()));
    QObject::connect(mactionOuvrir,SIGNAL(triggered()),this, SLOT(ouvrirDialogue()));
    QObject::connect(actionQuitter,SIGNAL(triggered()),qApp, SLOT(quit()));

    QObject::connect(mactionUp,SIGNAL(triggered()),this, SLOT(docUp()));
    QObject::connect(mactionDown,SIGNAL(triggered()),this, SLOT(docDown()));

    QObject::connect(mactionRestaurer, SIGNAL(triggered()), this, SLOT(ouvrirCorbeille()));

    QObject::connect(mactionSave, SIGNAL(triggered()), this, SLOT(asave()));

    QObject::connect(mactionExportHTML, SIGNAL(triggered()), this, SLOT(exportHTML()));
    QObject::connect(mactionExportTex, SIGNAL(triggered()), this, SLOT(exportTex()));
    QObject::connect(mactionExportTexte, SIGNAL(triggered()), this, SLOT(exportTexte()));

    QObject::connect(mactionSupprimer, SIGNAL(triggered()), this, SLOT(deleteInCorbeille()));
    QObject::connect(mactionVider, SIGNAL(triggered()), this, SLOT(viderLaCorbeille()));
    //TODO
    QObject::connect(mactionAnnuler, SIGNAL(triggered()), qApp, SLOT(undo()));
    QObject::connect(mactionRefaire, SIGNAL(triggered()), qApp, SLOT(redo()));
    //
    QObject::connect(mactionSaveAs, SIGNAL(triggered()), this, SLOT(copieWorkSpace()));
    QObject::connect(mactionNew, SIGNAL(triggered()), this, SLOT(newWorkSpace()));
    QObject::connect(mactionOption, SIGNAL(triggered()), this, SLOT(setting()));



    QObject::connect(mactionViewEdit, SIGNAL(triggered()), this, SLOT(changeEdit()));
    QObject::connect(mactionViewHTML, SIGNAL(triggered()), this, SLOT(changeHtml()));
    QObject::connect(mactionViewTex,SIGNAL(triggered()),this, SLOT(changeTex()));
    QObject::connect(mactionViewTexte,SIGNAL(triggered()),this, SLOT(changeTexte()));
    QObject::connect(ow, SIGNAL(currentChanged(int)), this, SLOT(changeOnglet(int)));
    QObject::connect(mactionSupprimerTag, SIGNAL(triggered()), this, SLOT(supprimeTag()));

}
Beispiel #25
0
  //! Starts the socket thread
  void SocketThread::run() {
    std::string p_socketFile = "/tmp/isis_qview_" + Isis::Application::UserName(); 
    struct sockaddr_un p_socketName;
    p_socketName.sun_family = AF_UNIX;
    strcpy(p_socketName.sun_path,p_socketFile.c_str());
    int p_socket;

    // Create a socket
    if ((p_socket = socket(PF_UNIX,SOCK_STREAM,0)) < 0) {
      std::string msg = "Unable to create socket";
      std::cerr << msg << std::endl;
      return;
    }

    //const long unsigned int timeout = 1;
    timeval tv;
    tv.tv_sec = 0;
    tv.tv_usec = 100000;
    if(setsockopt(p_socket, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(struct timeval)) != 0) {
      std::string msg = "Unable set socket timeout";
      std::cerr << msg << std::endl;
      return;
    }

    // Bind the file to the socket
    int status =  bind(p_socket,(struct sockaddr *)&p_socketName, sizeof(p_socketName));
    if (status < 0) {
      std::string msg = "Unable to bind to socket [" + p_socketFile + "]";
      std::cerr << msg << std::endl;
      return;
    }

    // Set up to listen to the socket
    if (listen(p_socket,5) < 0) {
      std::string msg = "Unable to listen to socket [" + p_socketFile + "]";
      std::cerr << msg << std::endl;
      return;
    }

    p_done = false;
    
    while(!p_done) {  
      // Accept Socket
      socklen_t len;
      int childSocket = accept(p_socket, (struct sockaddr *)&p_socketName, &len);
      if (childSocket < 0) {
        continue; // probably timed out, we cant do anything about this anyways
      }

      // Receive Data
      int bytes;
      char buf[1024*1024];
      if ((bytes = recv(childSocket,&buf,1024*1024,0)) < 0) {
        std::string msg = "Unable to read from socket [" + p_socketFile + "]";
        std::cerr << msg << std::endl;
        return;
      }

      // Push everything onto our string buffer
      Isis::iString buffer;
      for (int i=0; i<bytes; i++) buffer += buf[i];
      while (buffer.size() > 0) {
        Isis::iString token = buffer.Token(" ");
        if (token == "raise") {
          emit focusApp();
        }
        else emit newImage(token.c_str());
      }

    };
  }