Esempio n. 1
0
void PlayArea::repaintAll()
{
    QGraphicsView* canvas = scene->views().at(0);
    canvas->resetTransform();
    scaleX = canvas->width() / 1280.f;
    scaleY = canvas->height() / 720.f;
    qreal cscale = std::min(scaleX, scaleY);
    canvas->scale(cscale, cscale);
    qreal offsetX = (1280.f - 1280.f * cscale) / 2;
    qreal offsetY = (720.f - 720.f * cscale) / 2;
    if (offsetX > offsetY) {
        offsetY = 0;
    } else {
        offsetX = 0;
    }
    qDebug() << "scale" << cscale << "offsets" << offsetX << offsetY;
    field->setX(offsetX);
    field->setY(offsetY);
    Stack* zone;
    QString pstack, ostack;
    for (int i = 0; i < 12; i++) {
        pstack = PlayArea::stackNames[i];
        ostack = PlayArea::stackNames[11 - i];
        zone = getPlayerStack(pstack);
        repaint(zone);
        zone = getOpponentStack(ostack);
        repaint(zone);
    }
}
Esempio n. 2
0
int main(int argc, char *argv[]) {

    QApplication a(argc, argv);

	// define 4 points forming a square
	Point p(100.0, 100.0);
	Point q(500.0, 100.0);
	Point r(500.0, 500.0);
	Point s(100.0, 500.0);
	// Set up a Tour with those four points
	// The constructor should link p->q->r->s->p
	Tour squareTour(p, q, r, s);
	squareTour.show();

    string filename = "tsp10.txt";
    ifstream input;
    input.open(filename);

    // get dimensions
    int width;
    int height;
    input >> width;
    input >> height;

    // setup graphical window
    QGraphicsView *view = new QGraphicsView();
    QGraphicsScene *scene = new QGraphicsScene();
    view->setScene(scene);
    view->scale(1, -1); //screen y-axis is inverted
    view->setSceneRect(0, 0, width, height);
    view->show();

    // run insertion heuristic
    Tour tour;
    double x;
    double y;
    while (input >> x >> y) {
        Point p(x, y);
		//tour.insertNearest(p);
        tour.insertSmallest(p);
        //uncomment the 4 lines below to animate
		tour.draw(scene);
		std::chrono::milliseconds dura(50);
		std::this_thread::sleep_for(dura);
		a.processEvents();
	}
    input.close();

    // print tour to standard output
    cout << "Tour distance: " << std::fixed << std::setprecision(4)
         << std::showpoint << tour.distance() << endl;
    cout << "Number of points: " << tour.size() << endl;
	tour.show();

    // draw tour
    tour.draw(scene);
	return a.exec(); // start Qt event loop
}
Esempio n. 3
0
void TimeGraphContainer::addGraphScene(GraphScene * scene) {
	scene->setTimeControl(time_widget->getTimeControl());

	QGraphicsView * v = new QGraphicsView();
	v->scale(1.0,-1.0); 
	v->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
	v->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
	list.append(v);
	v->setScene(scene); 
	inner_layout->addWidget(v);
	
}
Esempio n. 4
0
SEXP
qt_qsetTransform_QGraphicsView(SEXP v,
			       SEXP xscale,
			       SEXP yscale,
			       SEXP rotate,
			       SEXP translate)
{
    QGraphicsView *view = unwrapQObject(v, QGraphicsView);
    // shear ( qreal sh, qreal sv )
    view->scale(REAL(xscale)[0], REAL(yscale)[0]);
    view->rotate(REAL(rotate)[0]);
    view->translate(REAL(translate)[0], REAL(translate)[1]);
    return R_NilValue;
}
Esempio n. 5
0
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QDir::setCurrent(QCoreApplication::applicationDirPath());
    QDir dir(QDir::current());

    // set the slide model.
    QFile xmlf(dir.absoluteFilePath("userdata/test.xml"));
    if (!xmlf.exists()) {
        QMessageBox::critical(0, "error", "no xml file...");
        return 0;
    }
    xmlf.open(QFile::ReadWrite);
    QSlideModel model(xmlf.readAll());
    xmlf.close();


    // set the slide scene
    QSlidePlayerScene *scene = new QSlidePlayerScene(0, &model);
    QPixmap pixmap(dir.absoluteFilePath("res/images/default-background.png"));
    scene->setBackgroundBrush(Qt::black);
    scene->setBackgroundPixmap(pixmap);

    //set slide view
    QGraphicsView *view = new QGraphicsView(scene);

    view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    view->setFrameShape(QFrame::NoFrame);
    // editing is not allowed.
    view->setInteractive(false);

    // scale
    double newScale = QApplication::desktop()->height() / scene->sceneRect().height();
    QMatrix oldMatrix = view->matrix();
    view->resetMatrix();
    view->translate(oldMatrix.dx(), oldMatrix.dy());
    view->scale(newScale, newScale);

    view->showFullScreen();

    QHidDevice * test = new QHidDevice(0x55, 0x32, &a);

    return a.exec();
}
Esempio n. 6
0
void MapperGLCanvas::wheelEvent(QWheelEvent *event)
{
  int deltaLevel = event->delta() / 120;
  qreal zoomFactor = qPow(MM::ZOOM_FACTOR, _zoomLevel);
  if (deltaLevel > 0)
  {
    // First check if we're already at max.
    while (deltaLevel && zoomFactor < MM::ZOOM_MAX) {
      _zoomLevel++;
      deltaLevel--;
      zoomFactor = qPow(MM::ZOOM_FACTOR, _zoomLevel);
    }
    zoomFactor = qMin(zoomFactor, MM::ZOOM_MAX);
  }
  else
  {
    // First check if we're already at min.
    while (deltaLevel && zoomFactor > MM::ZOOM_MIN) {
      _zoomLevel--;
      deltaLevel++;
      zoomFactor = qPow(MM::ZOOM_FACTOR, _zoomLevel);
    }
    zoomFactor = qMax(zoomFactor, MM::ZOOM_MIN);
  }

  // Re-bound zoom (for consistency).
  zoomFactor = getZoomFactor();

  // Apply zoom to view.
  QGraphicsView* view = scene()->views().first();
  view->resetMatrix();
  view->scale(zoomFactor, zoomFactor);
  view->update();

  // Accept wheel scrolling event.
  event->accept();
}
Esempio n. 7
0
int main(int argc, char *argv[]) {
    QApplication a(argc, argv);

    // open file
    string filename = "input12800.txt";
    ifstream input;
    input.open(filename);

    // the vector of points
    vector<Point> points;

    // read points from file
    int N;
    int x;
    int y;

    input >> N;

    for (int i = 0; i < N; ++i) {
        input >> x >> y;
        points.push_back(Point(x, y));
    }
    input.close();

    // setup graphical window
    QGraphicsView *view = new QGraphicsView();
    QGraphicsScene *scene = new QGraphicsScene(0, 0, SCENE_WIDTH, SCENE_HEIGHT);
    view->setScene(scene);
    // draw points to screen all at once
    render_points(scene, points);
    view->scale(1, -1); //screen y-axis is inverted
    view->resize(view->sizeHint());
    view->setWindowTitle("Brute Force Pattern Recognition");
    view->show();

    // sort points by natural order
    // makes finding endpoints of line segments easy
    sort(points.begin(), points.end());
    auto begin = chrono::high_resolution_clock::now();

    for(int i = 0; i < N-3;++i){
        Point p = points.at(i);
        // Skapar en ny lista som innehåller alla punkter som ligger efter p
        vector<Point> slopeList;
        for (int j = i+1; j < N;++j){
            slopeList.push_back(points.at(j));
        }
        // Sorterar den nya listan beorende på lutningen till p
        sort(slopeList.begin(),slopeList.end(),comparator(p));
        // De två senaste punkterna vi har kollat på
        Point sameSlope [2] = {
            slopeList.at(0),
            slopeList.at(1)
        };
        for(int j = 2;j < N-i-1;++j){
            // Kollar om båda punkterna i sameSlope och den nuvarande punkten har samma lutning mot p
            if(p.slopeTo(sameSlope[0]) == p.slopeTo(sameSlope[1]) && p.slopeTo(sameSlope[0]) == p.slopeTo(slopeList[j])){
                // Isåfall kollar vi vilken av de som har högst x-värde och ritar en linje från p till den
                Point largestX = sameSlope[0] > sameSlope[1] ? sameSlope[0] : sameSlope[1];
                largestX = largestX > slopeList.at(j) ? largestX : slopeList.at(j);
                render_line(scene,p,largestX);
                a.processEvents();
            }
            // Lägger in varannan punkt i slopeList[0] och varannan i slopeList[1]
            sameSlope[j%2] = slopeList[j];
        }
    }
    auto end = chrono::high_resolution_clock::now();
    cout << "Computing line segments took "
         << std::chrono::duration_cast<chrono::milliseconds>(end - begin).count()
         << " milliseconds." << endl;

    return a.exec(); // start Qt event loop
}
Esempio n. 8
0
void ULLineEditor::keyPressEvent ( QKeyEvent * event )
{
	if ( event->key() == Qt::Key_Return )
	{
		validateLine();
		return;
	}
	if ( event->key() == Qt::Key_G && event->modifiers().testFlag ( Qt::ControlModifier ))
	{
		pushLastGlyphAtFirstOfNextLine();
		return;
	}
	if ( event->key() == Qt::Key_P&& event->modifiers().testFlag ( Qt::ControlModifier ) )
	{
		insertAtLastFirstGlyphOfNextLine();
		return;
	}
	if ( event->key() == Qt::Key_G && event->modifiers().testFlag ( Qt::ShiftModifier ))
	{
		insertAtFirstLastGlyphFromPrevLine();
		pushLastGlyphAtFirstOfNextLine();
		return;
	}
	if ( event->key() == Qt::Key_P&& event->modifiers().testFlag ( Qt::ShiftModifier ) )
	{
		pushFirstGlyphAtLastOfPrevLine();
		insertAtLastFirstGlyphOfNextLine();
		return;
	}
	if ( event->key() == Qt::Key_G )
	{
		pushFirstGlyphAtLastOfPrevLine();
		return;
	}
	if ( event->key() == Qt::Key_P )
	{
		insertAtFirstLastGlyphFromPrevLine();
		return;
	}
	

	QList<QGraphicsItem*> it = selectedItems();
	if ( it.isEmpty() && event->modifiers().testFlag ( Qt::ControlModifier )  && event->modifiers().testFlag ( Qt::ShiftModifier ) )
	{
		switch ( event->key() )
		{
			case Qt::Key_Right : slotJustifyItsVeryBadInterletter ( 0.005 );
				break;
			case Qt::Key_Left : slotJustifyItsVeryBadInterletter ( -0.005 );
				break;
			default:break;
		}

	}
	else if ( it.isEmpty() && event->modifiers().testFlag ( Qt::ControlModifier ) )
	{
		switch ( event->key() )
		{
			case Qt::Key_Right : slotJustifyBlanks ( 0.01 );
				break;
			case Qt::Key_Left : slotJustifyBlanks ( -0.01 );
				break;
			default:break;
		}

	}
	else if ( it.isEmpty() )
	{
		QGraphicsView * v = views().first();
		switch ( event->key() )
		{
			case Qt::Key_Up: v->scale ( 1.2,1.2 );
				break;
			case Qt::Key_Down : v->scale ( 1.0/1.2,1.0/1.2 );
				break;
			case Qt::Key_Right : slotJustifyBlanks ( 0.1 );
				break;
			case Qt::Key_Left : slotJustifyBlanks ( -0.1 );
				break;
			default:break;
		}

	}
	else
	{
        if ( (event->key() == Qt::Key_Delete) || (event->key() == Qt::Key_Backslash) )
		{
			for ( uint i = 0; i < it.count();++i )
			{
				removeItem ( it[i] );
				glyphs.removeAll ( static_cast<ULGlyphItem*> ( it[i] ) );
			}
		}
		else if ( event->key() == Qt::Key_E )
		{
			wantEdit ( static_cast<ULGlyphItem*> ( it.first() ) );
		}

		else
		{
			for ( uint i = 0; i < it.count();++i )
				static_cast<ULGlyphItem*> ( it[i] )->keyForeign ( event );

		}
// 		previewLine();
	}
}
Esempio n. 9
0
int main(int argc, char *argv[]) {
    QApplication a(argc, argv);

    // open file
    string filename = "input100.txt";
    ifstream input;
    input.open(filename);

    // the vector of points
    vector<Point> points;

    // read points from file
    int N;
    int x;
    int y;

    input >> N;

    for (int i = 0; i < N; ++i) {
        input >> x >> y;
        points.push_back(Point(x, y));
    }
    input.close();

    // setup graphical window
    QGraphicsView *view = new QGraphicsView();
    QGraphicsScene *scene = new QGraphicsScene(0, 0, SCENE_WIDTH, SCENE_HEIGHT);
    view->setScene(scene);
    // draw points to screen all at once
    render_points(scene, points);
    view->scale(1, -1); //screen y-axis is inverted
    view->resize(view->sizeHint());
    view->setWindowTitle("Brute Force Pattern Recognition");
    view->show();

    // sort points by natural order
    // makes finding endpoints of line segments easy
    sort(points.begin(), points.end());
    auto begin = chrono::high_resolution_clock::now();

    //for each point int points
    for (unsigned int i=0;i<points.size();i++){
        //we create a map with the slope as key and a vector of points as value
        map<double,vector<Point>> point_map;

        //for each point that is "larger" than the point we takes its slopes to the current point i
        for (unsigned int j=i+1;j<points.size();++j){
            //and adds it to the maps in the vector with all other points with the same slope
            point_map[points.at(i).slopeTo(points.at(j))].push_back(points.at(j));
        }
        //after this we iterate through each key in the map
        for (map<double,vector<Point>>::iterator it=point_map.begin(); it!=point_map.end(); ++it){
            //and check if the vector has a size of of three or more
            if (it->second.size()>=3){
                //creates a line
                render_line(scene,points.at(i),*(it->second.end()-1));
                //process the event
                a.processEvents();
            }
        }


    }


    auto end = chrono::high_resolution_clock::now();
    cout << "Computing line segments took "
         << std::chrono::duration_cast<chrono::milliseconds>(end - begin).count()
         << " milliseconds." << endl;

    return a.exec(); // start Qt event loop
}
Esempio n. 10
0
int main(int argc, char *argv[]) {
    QApplication a(argc, argv);

    // open file
    string filename = "input12800.txt";
    ifstream input;
    input.open(filename);


    // read points from file
    int N;
    int x;
    int y;

    input >> N;

    // the vector of points
    vector<Point> points;
    // a vector of pointers to the points in points
    vector<Point*> pointPointers;

    for (int i = 0; i < N; ++i) {
        input >> x >> y;
        Point* p = new Point(x, y);
        points.push_back(*p);
        pointPointers.push_back(p);
    }
    input.close();

    // setup graphical window
    QGraphicsView *view = new QGraphicsView();
    QGraphicsScene *scene = new QGraphicsScene(0, 0, SCENE_WIDTH, SCENE_HEIGHT);
    view->setScene(scene);
    // draw points to screen all at once
    render_points(scene, points);
    view->scale(1, -1); //screen y-axis is inverted
    view->resize(view->sizeHint());
    view->setWindowTitle("Extra Fast Pattern Recognition");
    view->show();
    auto begin = chrono::high_resolution_clock::now();
    //do all of this using each point as starting point
    for (int startingPoint = 0; startingPoint < N; ++startingPoint) {
        vector<PointComparison> comparisons;
        //iterate over all except the starting point. Instead of
        //checking each point if it is a starting point, iterate first
        //over all points until the starting point, and then after.
        for (int i = 0; i < startingPoint; ++i) {
            //for every point that isn't the starting point, create a PointComparison of
            //the starting point pointer and the point pointer at index i.
            comparisons.push_back(PointComparison(pointPointers[startingPoint], pointPointers[i]));
        }
        for (int i = startingPoint + 1; i < N; ++i) {
            //do the same here.
            comparisons.push_back(PointComparison(pointPointers[startingPoint], pointPointers[i]));
        }
        //sort the comparisons by slope
        sort(comparisons.begin(), comparisons.end());

        //start finding collinear lines. Create an index variable.
        int i = 0;
        //since we are checking two points ahead, and checking every point except the starting point,
        //we check from i = 0 to N-1-2 = N-3.
        while (i < N - 3) {
            //get the slopes of this index and the one two indexes away
            double slope1 = comparisons[i].slope;
            double slope2 = comparisons[i + 2].slope;
            //if they are equal, that means we have found four aligned points (including the startingPoint)!
            //Lets see if we can find more...
            //EXTRATASK E8: Because of how the list is sorted, several equal slopes in a row will be sorted
            //lexicographically, which means that the last of these points will be the upmost right point.
            //This also means that the starting point is the downmost left point if and only if it follows
            //the order of the comparison list. That is, only if it is "less" than the first point with equal
            //slope. Since we only want to draw one single line segment between these lines, we include this
            //as a condition to draw the line.
            if (slope1 == slope2 && *comparisons[0].comparePoint < *comparisons[i].thisPoint) {
                int j = i + 3;
                while (slope1 == comparisons[j].slope && j < N - 1) {
                    //we found another aligned point!
                    j++;
                }
                //okay, so the compared point at comparisons[j] was not aligned, so we will
                //just draw a line from the starting point to the one at j-1 (since that was the
                //last aligned point). We use comparisons[0] to get the starting point but
                //we could just use any element in comparisons since they all have the same
                //pointer to the starting point.
                render_line(scene, *comparisons[0].comparePoint, *comparisons[j-1].thisPoint);
                a.processEvents(); // show rendered line
                //continue searching from where the last aligned point was found.
                i = j - 1;
            } else {
                //okay, we didn't find aligned points here, increment and continue.
                i++;
            }
        }
    }
    //And we're done! Pause the timer.
    auto end = chrono::high_resolution_clock::now();
    cout << "Computing line segments took "
         << std::chrono::duration_cast<chrono::milliseconds>(end - begin).count()
         << " milliseconds." << endl;
    return a.exec();
}