コード例 #1
0
ファイル: RegionMask.cpp プロジェクト: lopespt/PhD-Thesis
QPolygon &RegionMask::Mask2QPolygon(const cv::Mat &img, QPolygon &poly, QList<QPolygon> &holes) {
    poly.clear();
    vector<vector<cv::Point> > contours;
    vector<cv::Vec4i> hierarchy;
    cv::findContours(img.clone(), contours, hierarchy, CV_RETR_CCOMP, CV_CHAIN_APPROX_TC89_KCOS, cv::Point(0, 0));

    //assert(contours.size() > 0);

    if (contours.size() > 0) {
        for (unsigned int i = 0; i < contours[0].size(); i++) {
            poly.append(QPoint(contours[0][i].x, contours[0][i].y));
        }

        int idHole = hierarchy[0][2];
        for (; idHole != -1; idHole = hierarchy[idHole][0]) {
            QPolygon pnew;
            for (unsigned int i = 0; i < contours[idHole].size(); i++) {
                pnew.append(QPoint(contours[idHole][i].x, contours[idHole][i].y));
            }
            holes.append(pnew);
        }
    }

    return poly;
}
コード例 #2
0
ファイル: mapmatrix.cpp プロジェクト: Exadios/Cumulus
// The new function using fixed point multiplication
QPolygon MapMatrix::map(const QPolygon &a) const
{
  int size = a.size();
  int64_t fx;
  int64_t fy;
  int32_t curx;
  int32_t cury;
  int32_t lastx = 0;
  int32_t lasty = 0;

  QPolygon p;

  for( int i = 0; i < size; i++ )
    {
      a.point(i, &curx, &cury);
      fx = itofp24p8( curx );
      fy = itofp24p8( cury );
      // some cheating involved; multiplication with the "wrong" macro
      // after "left shifting" the "m" value in createMatrix
      curx = fp24p8toi( mulfp8p24(m11,fx) + mulfp8p24(m21,fy) + dx);
      cury = fp24p8toi( mulfp8p24(m22,fy) + mulfp8p24(m12,fx) + dy);

      if ( (i==0) | ( ((curx - lastx) | (cury - lasty)) != 0) )
        {
          p.append(QPoint(curx, cury));
          lastx = curx;
          lasty = cury;
        }
    }

  return p;
}
コード例 #3
0
ファイル: qt4plot.cpp プロジェクト: syntheticpp/scigraphics
QPolygon drawerQt::polygonQt( const std::vector<scigraphics::wpoint> &Points )
{
  QPolygon Polygon;
  for ( unsigned i = 0; i < Points.size(); i++ )
    Polygon.append( pointQt( Points[i] ) );
  return Polygon;
}
コード例 #4
0
	void LineString::draw(QPainter* painter, const MapAdapter* mapadapter, const QRect &screensize, const QPoint offset)
	{
		if (!visible)
			return;
	
		QPolygon p = QPolygon();
	
		QPointF c;
		for (int i=0; i<vertices.size(); i++)
		{
			c = vertices[i]->coordinate();
			p.append(mapadapter->coordinateToDisplay(c));
		}
		if (mypen != 0)
		{
			painter->save();
			painter->setPen(*mypen);
		}
		painter->drawPolyline(p);
		if (mypen != 0)
		{
			painter->restore();
		}
		for (int i=0; i<vertices.size(); i++)
		{
			vertices[i]->draw(painter, mapadapter, screensize, offset);
		}
	}
コード例 #5
0
ファイル: area.cpp プロジェクト: SidneyTTW/ImageProcessor
Area Area::fromString(const QString& str)
{
  Area result;
  QStringList list = str.split(',', QString::SkipEmptyParts);
  if (list.isEmpty())
    return result;
  AreaTypeFlag type = (AreaTypeFlag) list.takeFirst().toInt();
  switch (type)
  {
  case TypeRectangle:
    if (list.size() != 4)
      break;
    {
      int values[4];
      values[0] = list.takeFirst().toInt();
      values[1] = list.takeFirst().toInt();
      values[2] = list.takeFirst().toInt();
      values[3] = list.takeFirst().toInt();
      result = Area(QRect(values[0],
                          values[1],
                          values[2],
                          values[3]));
    }
    break;
  case TypePolygon:
    {
      int size = list.takeFirst().toInt();
      if (list.size() != 2 * size)
        break;
      QPolygon poly;
      for (int i = 0;i < size;++i)
      {
        int values[2];
        values[0] = list.takeFirst().toInt();
        values[1] = list.takeFirst().toInt();
        poly.append(QPoint(values[0], values[1]));
      }
      result = Area(poly);
    }
    break;
  case TypeEllipse:
    if (list.size() != 4)
      break;
    {
      int values[4];
      values[0] = list.takeFirst().toInt();
      values[1] = list.takeFirst().toInt();
      values[2] = list.takeFirst().toInt();
      values[3] = list.takeFirst().toInt();
      result = Area(Ellipse(QPoint(values[0],
                                   values[1]),
                            values[2],
                            values[3]));
    }
    break;
  default:
    break;
  }
  return result;
}
コード例 #6
0
ファイル: qpolygon.cpp プロジェクト: fluxer/katie
QPolygon QPolygonF::toPolygon() const
{
    QPolygon a;
    a.reserve(size());
    for (int i=0; i<size(); ++i)
        a.append(at(i).toPoint());
    return a;
}
コード例 #7
0
void IntersectionTest::start() {
    QPolygon poly;
    poly.append(QPoint(0,0));
    poly.append(QPoint(0,100));
    poly.append(QPoint(100,100));
    poly.append(QPoint(100,0));
    cv::Mat mat(200,200, CV_8UC1);

    ShapeSignatureFeatureFactory factory(5, 5);
    //factory.CreateFromRegion();
    QImageCV image(mat.clone());
    Region r(&image, mat);
    Utils::QPolygon2Mask(mat, poly);
    cv::imshow("img", mat);
    cv::waitKey(0);


}
コード例 #8
0
	QPolygon PointListWidget::points() const
	{
		QPolygon back;

		for(int index = 0; index < ui->list->rowCount(); ++index)
			back.append(QPoint(ui->list->item(index, 0)->text().toInt(),
							   ui->list->item(index, 1)->text().toInt()));

		return back;
	}
コード例 #9
0
void GuiDomain::UpdatePosition()
{
    //LOG(LOG_VERBOSE, "Updating position of GUI domain %s", mDomain->GetDomainAddress().c_str());

    QPolygon tPolygon;
    GuiNode* tGuiNode;
    foreach(tGuiNode, mGuiNodes)
    {
        QPointF tPoint = mapFromItem(tGuiNode, 0, 0);
        tPoint.setX(tPoint.x() + tGuiNode->GetWidth() / 2);
        tPoint.setY(tPoint.y() + tGuiNode->GetHeight() / 2);
        tPolygon.append(tPoint.toPoint());
    }
コード例 #10
0
// public static
void kpPixmapFX::drawLine (QImage *image,
        int x1, int y1, int x2, int y2,
        const kpColor &color, int penWidth,
        const kpColor &stippleColor)
{
    QPolygon points;
    points.append (QPoint (x1, y1));
    points.append (QPoint (x2, y2));

    drawPolyline (image,
        points,
        color, penWidth,
        stippleColor);
}
コード例 #11
0
ファイル: WmfExport.cpp プロジェクト: TheTypoMaster/calligra
void WmfExport::paintShape(KoShape * shape)
{
    QList<QPolygonF> subpaths = shape->outline().toFillPolygons(shape->absoluteTransformation(0));

    if (! subpaths.count())
        return;

    QList<QPolygon> polygons;
    foreach(const QPolygonF & subpath, subpaths) {
        QPolygon p;
        uint pointCount = subpath.count();
        for (uint i = 0; i < pointCount; ++i)
            p.append(QPoint(coordX(subpath[i].x()), coordY(subpath[i].y())));

        polygons.append(p);
    }
コード例 #12
0
/*----------------------------------------------------------------------------*/
QPolygon ChannelEdit :: createPolygon(int x)
{
  QPolygon pol;
  const int w = 32;
  const int h = 32;
  pol.append(QPoint(x-w/2, 0));
  pol.append(QPoint(x+w/2, 0));
  pol.append(QPoint(x+w/2, h));
  pol.append(QPoint(x+3, rect().bottom() - 5));
  pol.append(QPoint(x+2, rect().bottom() - 3));
  pol.append(QPoint(x+1, rect().bottom() - 1));
  pol.append(QPoint(x, rect().bottom()));
  pol.append(QPoint(x-1, rect().bottom() - 1));
  pol.append(QPoint(x-2, rect().bottom() - 3));
  pol.append(QPoint(x-3, rect().bottom() - 5));
  pol.append(QPoint(x-w/2, h));
  return pol;
}
コード例 #13
0
ファイル: Obstacle.cpp プロジェクト: xammi/Curs_Fire
//-------------------------------------------------------------------------------------------------
void Obstacle::draw(QPainter & painter, const Projector & projector, const Plane3D & plane) {    

    QPoints Ps(8, QPoint(0, 0));
    for (int I = 0; I < tops.size(); ++I)
        Ps[I] = projector(tops[I]);

    int invisible = findInvisible(plane);
    for (Edge & edge : edges)
        if (! edge.isInvisible(invisible))
            painter.drawLine(Ps[edge.from], Ps[edge.to]);

    for (Facet & facet : facets)
        if (! facet.isInvisible(invisible)) {
            QPolygon polygon;

            for (int index : facet.tops)
                polygon.append(Ps[index]);

            painter.setBrush(QBrush(* texture));
            painter.drawPolygon(polygon);
        }
}
コード例 #14
0
QImage * GroundPlaneGenerator::generateGroundPlaneAux(const QString & boardSvg, QSizeF boardImageSize, const QString & svg, QSizeF copperImageSize, 
													QStringList & exceptions, QGraphicsItem * board, double res, double & bWidth, double & bHeight, double blurBy) 
{
	QByteArray boardByteArray;
    QString tempColor("#ffffff");
    if (!SvgFileSplitter::changeColors(boardSvg, tempColor, exceptions, boardByteArray)) {
		return NULL;
	}

	/*
	QFile file0("testGroundFillBoard.svg");
	file0.open(QIODevice::WriteOnly);
	QTextStream out0(&file0);
	out0 << boardByteArray;
	file0.close();
	*/


	QByteArray copperByteArray;
	if (!SvgFileSplitter::changeStrokeWidth(svg, 50, false, copperByteArray)) {
		return NULL;
	}

	/*
	QFile file1("testGroundFillCopper.svg");
	file1.open(QIODevice::WriteOnly);
	QTextStream out1(&file1);
	out1 << copperByteArray;
	file1.close();
	*/

	double svgWidth = res * qMax(boardImageSize.width(), copperImageSize.width()) / FSvgRenderer::printerScale();
	double svgHeight = res * qMax(boardImageSize.height(), copperImageSize.height()) / FSvgRenderer::printerScale();

	QRectF br =  board->sceneBoundingRect();
	bWidth = res * br.width() / FSvgRenderer::printerScale();
	bHeight = res * br.height() / FSvgRenderer::printerScale();
	QImage * image = new QImage(qMax(svgWidth, bWidth), qMax(svgHeight, bHeight), QImage::Format_Mono); //
	image->setDotsPerMeterX(res * GraphicsUtils::InchesPerMeter);
	image->setDotsPerMeterY(res * GraphicsUtils::InchesPerMeter);
	image->fill(0x0);

	QSvgRenderer renderer(boardByteArray);
	QPainter painter;
	painter.begin(image);
	painter.setRenderHint(QPainter::Antialiasing, false);
	renderer.render(&painter, QRectF(0, 0, res * boardImageSize.width() / FSvgRenderer::printerScale(), res * boardImageSize.height() / FSvgRenderer::printerScale()));
	painter.end();

#ifndef QT_NO_DEBUG
	image->save("testGroundFillBoard.png");
#endif

	for (double m = 0; m < .004; m += (1.0 / res)) {
		QList<QPoint> points;
		collectBorderPoints(*image, points);

#ifndef QT_NO_DEBUG
		// for debugging
		double pixelFactor = GraphicsUtils::StandardFritzingDPI / res;
		QPolygon polygon;
		foreach(QPoint p, points) {
			polygon.append(QPoint(p.x() * pixelFactor, p.y() * pixelFactor));
		}

		QList<QPolygon> polygons;
		polygons.append(polygon);
		QPointF offset;
		QString pSvg = makePolySvg(polygons, res, bWidth, bHeight, pixelFactor, "#ffffff", "debug", false,  NULL, QSizeF(0,0), 0, QPointF(0, 0));
#endif

		foreach (QPoint p, points) image->setPixel(p, 0);
	}
コード例 #15
0
QImage ImageProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize)
{
    QImage result;
    const QStringList idSegments = id.split(QLatin1Char('/'));
    if (requestedSize.width() < 1 || requestedSize.height() < 1) {
        qDebug() << Q_FUNC_INFO << " requestedSize is invalid!" << requestedSize << id;
        return QImage();
    }
    if (idSegments.count() < 2) {
        qDebug() << Q_FUNC_INFO << "Not enough parameters for the image provider: " << id;
        return QImage();
    }
    const QString &elementId = idSegments.at(1);
    if (idSegments.first() == QStringLiteral("background")) {
        return renderedSvgElement(elementId, designRenderer(), Qt::KeepAspectRatioByExpanding, size, requestedSize);
    } else if (idSegments.first() == QStringLiteral("title")) {
        if (elementId == QStringLiteral("textmask"))
            result = renderedSvgElement(idSegments.first(), designRenderer(), Qt::KeepAspectRatio, size, requestedSize);
        else
            result = spectrum(size, requestedSize);
    } else if (idSegments.first() == QStringLiteral("specialbutton")) {
        result = renderedSvgElement(elementId, designRenderer(), Qt::IgnoreAspectRatio, size, requestedSize);
    } else if (idSegments.first() == buttonString) {
        result = renderedDesignElement(DesignElementTypeButton, elementId.toInt(), size, requestedSize);
    } else if (idSegments.first() == frameString) {
        result = renderedDesignElement(DesignElementTypeFrame, 0, size, requestedSize);
    } else if (idSegments.first() == QStringLiteral("object")) {
        result = renderedSvgElement(elementId, objectRenderer(), Qt::KeepAspectRatio, size, requestedSize);
    } else if (idSegments.first() == QStringLiteral("clock")) {
        if (idSegments.count() != 4) {
            qDebug() << Q_FUNC_INFO << "Wrong number of parameters for clock images:" << id;
            return QImage();
        }
        result = clock(idSegments.at(1).toInt(), idSegments.at(2).toInt(), idSegments.at(3).toInt(), size, requestedSize);
    } else if (idSegments.first() == QStringLiteral("notes")) {
        result = notes(elementId.split(QLatin1Char(','), QString::SkipEmptyParts), size, requestedSize);
    } else if (idSegments.first() == QStringLiteral("quantity")) {
        if (idSegments.count() != 3) {
            qDebug() << Q_FUNC_INFO << "Wrong number of parameters for quantity images:" << id;
            return QImage();
        }
        result = quantity(idSegments.at(1).toInt(), idSegments.at(2), size, requestedSize);
    } else if (idSegments.first() == QStringLiteral("lessonicon")) {
        if (idSegments.count() != 3) {
            qDebug() << Q_FUNC_INFO << "Wrong number of parameters for lessonicon:" << id;
            return QImage();
        }
        result = renderedLessonIcon(idSegments.at(1), idSegments.at(2).toInt(), size, requestedSize);
    } else if (idSegments.first() == QStringLiteral("color")) {
        if (idSegments.count() != 3) {
            qDebug() << Q_FUNC_INFO << "Wrong number of parameters for color:" << id;
            return QImage();
        }
        const QColor color(idSegments.at(1));
        result = colorBlot(color, idSegments.at(2).toInt(), size, requestedSize);
    } else {
        qDebug() << Q_FUNC_INFO << "invalid image Id:" << id;
    }
#if 0
    if (idSegments.first() == QStringLiteral("object")) {
        QPainter p(&result);
        QPolygon points;
        for (int i = 0; i < result.width(); i += 2)
            for (int j = 0; j < result.height(); j += 2)
                points.append(QPoint(i, j));
        p.drawPoints(points);
        p.setPen(Qt::white);
        p.translate(1, 1);
        p.drawPoints(points);
    }
#endif
    return result;
}
コード例 #16
0
ファイル: datamanager.cpp プロジェクト: UFOID/UFO-Detector
bool DataManager::readDetectionAreaFile(bool clipToCamera) {
    QFile areaFile(m_config->detectionAreaFile());
    QDomDocument doc;
    QDomElement root;
    int x = 0;
    int y = 0;
    int cameraId = m_config->cameraIndex();
    int cameraWidth = m_config->cameraWidth();
    int cameraHeight = m_config->cameraHeight();
    QPolygon cameraRectangle;
    bool polygonsClipped = false;
    bool polygonWasClosed = false;

    if(!areaFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
        QString errorMsg = tr("Failed to open the detection area file %1. Please create it in Settings dialog or manually.").arg(areaFile.fileName());
        emit messageBroadcasted(errorMsg);
        return false;
    }

    if(!doc.setContent(&areaFile)) {
        QString errorMsg = tr("Error reading the detection area file %1").arg(areaFile.fileName());
        areaFile.close();
        emit messageBroadcasted(errorMsg);
        return false;
    }

    areaFile.close();
    root = doc.documentElement();
    if (root.nodeName() != "detectionarealist") {
        QString errorMsg = tr("Expected <detectionarealist> tag in detection area file but not found");
        emit messageBroadcasted(errorMsg);
        return false;
    }
    QDomNodeList areaList = root.childNodes();

    if (areaList.count() > 1) {
        QString errorMsg = tr("More than one detection areas defined, combining all together");
        emit messageBroadcasted(errorMsg);
    }

    for (int i = 0; i < areaList.count(); i++) {
        QDomNode area = areaList.at(i);
        QDomNodeList areaNodes = area.childNodes();

        if (area.nodeName() != "detectionarea") {
            QString errorMsg = tr("Expected <detectionarea> tag in detection area file but not found.");
            emit messageBroadcasted(errorMsg);
            return false;
        }

        QDomNodeList cameraList = area.toElement().elementsByTagName("camera");

        if (cameraList.count() != 1) {
            QString errorMsg = tr("Expected single <camera> tag in detection area. Assuming camera index 0.");
            emit messageBroadcasted(errorMsg);
        }
        for (int c = 0; c < cameraList.count(); c++) {
            QDomElement cameraElement = cameraList.at(c).toElement();
            cameraId = cameraElement.attribute("id").toInt();
            cameraWidth = cameraElement.attribute("width").toInt();
            cameraHeight = cameraElement.attribute("height").toInt();
            if (cameraId == m_config->cameraIndex()) {
                break;
            }
        }

        cameraRectangle << QPoint(0, 0) << QPoint(0, cameraHeight - 1)
                        << QPoint(cameraWidth - 1, cameraHeight - 1) << QPoint(cameraWidth - 1, 0);

        while (!m_detectionAreaPolygons.isEmpty()) {
            QPolygon* polygon = m_detectionAreaPolygons.takeLast();
            delete polygon;
        }

        for (int a = 0; a < areaNodes.count(); a++) {
            QDomNode areaSubNode = areaNodes.at(a);

            if (areaSubNode.nodeName() == "polygon") {
                QDomNodeList pointList = areaSubNode.childNodes();
                QPolygon* polygon = new QPolygon();

                for (int p = 0; p < pointList.count(); p++) {
                    QDomElement pointElement = pointList.at(p).toElement();
                    if (pointElement.nodeName() == "point") {
                        x = pointElement.attribute("x").toInt();
                        y = pointElement.attribute("y").toInt();
                        polygon->append(QPoint(x, y));
                    }
                }
                if (clipToCamera && polygon->size() &&
                    !cameraRectangle.boundingRect().contains(polygon->boundingRect()))
                {
                    if (polygon->first() == polygon->last()) {
                        polygonWasClosed = true;
                    }
                    *polygon = polygon->intersected(cameraRectangle);
                    polygonsClipped = true;
                    if (!polygonWasClosed) {
                        // intersected() treats polygon as implicitly closed
                        // so extra node is added: remove it
                        if (polygon->first() == polygon->last()) {
                            polygon->removeLast();
                        }
                    }
                }
                m_detectionAreaPolygons.append(polygon);
            }
        }
    }
    if (polygonsClipped) {
        QString warningMsg = tr("Detection area was clipped in order to fit the camera size.");
        emit messageBroadcasted(warningMsg);
    }
    return true;
}
コード例 #17
0
ファイル: BarDisplay.cpp プロジェクト: oswjk/prism
void BarDisplay::initShape()
{
    QPainter p(this);
    QPen pen(QColor(0, 0, 0, 255));
    QBrush brush(m_displayColor);

    p.setPen(Qt::NoPen);
    p.setBrush(brush);

    QPolygon one;
    one.append(QPoint(0, 0));
    one.append(QPoint(0, height() - 1));
    one.append(QPoint((160 / 3 * 1), height()));
    one.append(QPoint((160 / 3 * 1), 0));
    m_healthIndicators.append(one);

    QPolygon two;
    two.append(QPoint(0, 0));
    two.append(QPoint(0, height() - 1));
    two.append(QPoint((160 / 3 * 2), height()));
    two.append(QPoint((160 / 3 * 2), 0));
    m_healthIndicators.append(two);

    QPolygon three;
    three.append(QPoint(0, 0));
    three.append(QPoint(0, height() - 1));
    three.append(QPoint((160 / 3 * 3), height()));
    three.append(QPoint((160 / 3 * 3), 0));
    m_healthIndicators.append(three);

    QPolygon four;
    four.append(QPoint(0, 0));
    four.append(QPoint(0, height() - 1));
    four.append(QPoint(width() - 1, height()));
    four.append(QPoint(width() - 1, 0));
    m_healthIndicators.append(four);

    p.drawPolygon(three);

    p.setBrush(Qt::NoBrush);

    pen.setWidth(2);
    p.setPen(pen);
    // lefttside
    p.drawLine(0, 1, 20, 0);
    p.drawLine(1, 0, 0, height() - 1);
    p.drawLine(0, height() - 1, 20, height() - 1);

    // right side
    p.drawLine(width() - 1, 1, width() -1 - 20, 1);
    p.drawLine(width() - 1, 0, width() - 1, height() - 1);
    p.drawLine(width() - 1, height() - 1, width() - 1 - 20, height() - 1);

    pen.setWidth(2);
    p.setPen(pen);
    // the | -lines
    for (int i = 1; i < 4; i++)
        p.drawLine((160 / 3) * i, 4, (160 / 3) * i, height() - 1 - 5);
}
コード例 #18
0
/** Redefined. */
void AddressBarButton::paintEvent(QPaintEvent *)
{
	QStylePainter p(this);
	QRect r = rect().adjusted(0, 1, -1, -(1 + extra));
	static const int arrowWidth = r.height();

	QPalette palette = QApplication::palette();
	QLinearGradient g(rect().topLeft(), rect().bottomLeft());
	g.setColorAt(0, palette.base().color());
	g.setColorAt(1, palette.window().color());
	p.fillRect(r, g);

	// Compute size of rectangles to display text and right arrow
	if (_atLeastOneSubDir) {
		if (isLeftToRight()) {
			_arrowRect = QRect(r.width() - arrowWidth, r.y(), arrowWidth, r.height());
			_textRect = QRect(r.x(), r.y(), r.width() - arrowWidth, r.height());
		} else {
			_arrowRect = QRect(r.x(), r.y(), arrowWidth, r.height());
			_textRect = QRect(r.x() + arrowWidth, r.y(), r.width() - arrowWidth, r.height());
		}
	} else {
		_textRect = r.adjusted(0, 0, -5, 0);
	}

	// Highlight button if mouse is over
	QPoint pos = mapFromGlobal(QCursor::pos());
	p.save();
	QBrush brush;
	if (_addressBar->isDown()) {
		brush = palette.highlight().color().lighter();
	} else {
		brush = palette.highlight().color().lighter(lighterValue);
	}

	if (_highlighted) {
		p.setPen(palette.highlight().color());
		p.setBrush(brush);
		p.drawRect(_textRect);
		if (_atLeastOneSubDir) {
			p.drawRect(_arrowRect);
		}
	} else {
		if (_atLeastOneSubDir) {
			if (_textRect.contains(pos) || _arrowRect.contains(pos)) {
				p.setPen(palette.highlight().color());
				p.setBrush(brush);
				p.drawRect(_textRect);
				p.drawRect(_arrowRect);
			} else {
				p.setPen(Qt::NoPen);
				p.setBrush(Qt::NoBrush);
				p.drawRect(_textRect);
				p.drawRect(_arrowRect);
			}
		} else {
			if (_textRect.contains(pos)) {
				p.setPen(palette.highlight().color());
				p.setBrush(brush);
				p.drawRect(_textRect);
			}
		}
	}
	p.restore();

	// Draw folder's name
	QColor lighterBG = palette.highlight().color().lighter();
	QColor highlightedText = palette.highlightedText().color();

	if (rect().contains(pos) && SettingsPrivate::instance()->isCustomTextColorOverriden()) {
		p.setPen(palette.highlightedText().color());
	} else if (qAbs(lighterBG.value() - highlightedText.value()) > 128 && _highlighted) {
		p.setPen(highlightedText);
	} else {
		p.setPen(palette.text().color());
	}

	// Special case for root and drives
	bool root = false;
	if (_path.isRoot()) {
		QPixmap pixmap = QFileIconProvider().icon(QFileIconProvider::Computer).pixmap(20, 20);
		QString drive;
		if (_isAbsoluteRoot) {
			pixmap = QFileIconProvider().icon(QFileIconProvider::Computer).pixmap(20, 20);
			if (isLeftToRight()) {
				p.drawPixmap(2, 3, 20, 20, pixmap);
			} else {
				p.drawPixmap(18, 3, 20, 20, pixmap);
			}
		} else {
			drive = AddressBar::getVolumeInfo(_path.absolutePath());
			if (!_isAbsoluteRoot && !drive.isEmpty()) {
				// Add a small offset to simulate a pressed button
				if (_highlighted) {
					p.translate(1, 1);
				}
				p.drawText(_textRect.adjusted(5, 0, 0, 0), Qt::AlignCenter, drive);
			}
			pixmap = QFileIconProvider().icon(QFileIconProvider::Drive).pixmap(20, 20);
		}
	} else {
		if (!_path.dirName().isEmpty()) {
			// Add a small offset to simulate a pressed button
			if (_highlighted) {
				p.translate(1, 1);
			}
			p.drawText(_textRect.adjusted(0, 0, 0, 0), Qt::AlignCenter, _path.dirName());
		}
	}

	if (_atLeastOneSubDir) {
		QStyleOptionButton o;
		o.initFrom(this);
		p.save();
		p.setPen(Qt::NoPen);
		p.setBrush(o.palette.mid());
		if (root && _addressBar->hasHiddenFolders()) {
			/// Right To Left
			QPoint p1(o.rect.x() + 32, o.rect.y() + 11),
					p2(o.rect.x() + 29, o.rect.y() + 14),
					p2b(o.rect.x() + 29, o.rect.y() + 13),
					p3(o.rect.x() + 32, o.rect.y() + 16);
			p.save();
			p.setPen(Qt::black);
			p.setRenderHint(QPainter::Antialiasing);
			p.drawLine(p1, p2);
			p.drawLine(p2b, p3);
			p.translate(4, 0);
			p.drawLine(p1, p2);
			p.drawLine(p2b, p3);
			p.restore();
		} else {
			int w = _arrowRect.width() / 3;
			int h = this->rect().height() / 3;
			QRect indicatorArrow(_arrowRect.x() + w + 1, _arrowRect.y() + h, w, h);

			o.rect = indicatorArrow;
			p.setRenderHint(QPainter::Antialiasing);

			p.save();
			QPen pen(palette.mid().color());
			pen.setWidthF(1.5);
			pen.setJoinStyle(Qt::MiterJoin);
			p.setPen(pen);
			QPolygon pol;
			QPoint p1, p2, p3;
			if (_highlighted) {
				p.translate(0, -1);
				p1 = QPoint(o.rect.x(), o.rect.y() + o.rect.height() / 2);
				p2 = QPoint(o.rect.x() + o.rect.width(), o.rect.y() + o.rect.height() / 2);
				p3 = QPoint(o.rect.x() + o.rect.width() / 2, o.rect.y() + o.rect.height());
			} else if (isLeftToRight()) {
				p1 = QPoint(o.rect.x(), o.rect.y());
				p2 = QPoint(o.rect.x(), o.rect.y() + o.rect.height());
				p3 = QPoint(o.rect.x() + o.rect.width(), o.rect.y() + o.rect.height() / 2);
			} else {
				p1 = QPoint(o.rect.x() + o.rect.width(), o.rect.y());
				p2 = QPoint(o.rect.x() + o.rect.width(), o.rect.y() + o.rect.height());
				p3 = QPoint(o.rect.x(), o.rect.y() + o.rect.height() / 2);
			}
			pol.append(p1);
			pol.append(p2);
			pol.append(p3);
			p.drawPolygon(pol);
			p.restore();
			p.setRenderHint(QPainter::Antialiasing, false);
		}
		p.restore();
	}
}
コード例 #19
0
ファイル: altimeter.cpp プロジェクト: bertrandF/Altimeter
Altimeter::Altimeter(QWidget *parent) :
    QGraphicsView(parent),
    feets(0)
{
    QPolygon polygon; // helper

    this->setGeometry(0,0, WIDGETSIZE, WIDGETSIZE);

    // Style Setting
    backgroundBrush = QBrush(Qt::black);//QBrush(QColor(0x53, 0x54, 0x48));
    circlePen       = QPen(Qt::white);
    circlePen.setWidth(CIRCLEPENWIDTH);
    graduationPen   = QPen(Qt::white);
    graduationPen.setWidth(2);
    graduationFont  = QFont("lucida");
    graduationFont.setPointSize(12);
    graduationFont.setBold(true);
    handPenFront    = QPen(Qt::black);
    handPenFront.setWidth(2);
    handPenBack     = QPen(Qt::white);
    handPenBack.setWidth(2);
    handBrushBack   = QBrush(Qt::black);
    handBrushFront  = QBrush(Qt::white);

    // BACKGROUND PIXMAP
    backgroundPixmap = QPixmap(WIDGETSIZE,WIDGETSIZE);
    QPainter painter;
    painter.begin(&(this->backgroundPixmap));
    painter.setRenderHint(QPainter::Antialiasing);
    // Background
    painter.fillRect(QRect(0,0,WIDGETSIZE,WIDGETSIZE), backgroundBrush);
    // Circle
    painter.translate(WIDGETSIZE/2, WIDGETSIZE/2);
    painter.setBrush(Qt::NoBrush);
    painter.setPen(circlePen);
    painter.drawEllipse(QPoint(0,0),
                        (WIDGETSIZE/2-CIRCLEPENWIDTH),
                        (WIDGETSIZE/2-CIRCLEPENWIDTH)
                        );
    // Graduation
    painter.save();
    painter.setFont(graduationFont);
    for(int i=0 ; i<10 ; ++i)
    {
        graduationPen.setWidth(2);
        painter.setPen(graduationPen);
        painter.drawLine(QPoint(0, -(WIDGETSIZE/2-CIRCLEPENWIDTH)+5),
                         QPoint(0, -(WIDGETSIZE/2-CIRCLEPENWIDTH)+13));

        graduationPen.setWidth(1);
        painter.setPen(graduationPen);
        painter.drawText(
                    QPoint(-5, -(WIDGETSIZE/2-CIRCLEPENWIDTH)+28),
                    QString::number(i));
        for(int j=1 ; j<5 ; ++j)
        {
            painter.rotate(7.2);
            painter.drawLine(QPoint(0, -(WIDGETSIZE/2-CIRCLEPENWIDTH)+5),
                             QPoint(0, -(WIDGETSIZE/2-CIRCLEPENWIDTH)+10));
        }
        painter.rotate(7.2);
    }
    painter.restore();
    painter.end();


    // HAND, FEETS
    feetsHand = QPixmap(HANDWIDTH, HANDHEIGHT);
    painter.begin(&(this->feetsHand));
    painter.setRenderHint(QPainter::Antialiasing);
    painter.fillRect(feetsHand.rect(), backgroundBrush);
    // Hand front
    painter.setBrush(handBrushFront);
    painter.setPen(handPenFront);
    painter.drawRect(QRect(HANDCENTERX-2, CIRCLEPENWIDTH+5, 4, 16));
    painter.drawRect(QRect(
                         QPoint(HANDCENTERX-3, CIRCLEPENWIDTH+5+15),
                         QPoint(HANDCENTERX+3, HANDCENTERY))
                     );
    // Hand back
    painter.setBrush(handBrushBack);
    painter.setPen(handPenBack);
    painter.drawRect(HANDCENTERX-3, HANDCENTERY, 6, 25);
    painter.drawEllipse(QPoint(HANDCENTERX, HANDCENTERY+25), 6, 6);
    painter.end();
    // Mask
    feetsHand.setMask(feetsHand.createMaskFromColor(
                          backgroundBrush.color(),
                          Qt::MaskInColor)
                      );


    // HAND, TENTH of FEETS
    tenthHand = QPixmap(HANDWIDTH, HANDHEIGHT);
    painter.begin(&(this->tenthHand));
    painter.setRenderHint(QPainter::Antialiasing);
    painter.fillRect(tenthHand.rect(), backgroundBrush);
    // Hand front
    painter.setBrush(handBrushFront);
    painter.setPen(handPenFront);
    polygon.append(HANDCENTER);
    polygon.append(QPoint(HANDCENTERX-10, HANDCENTERY-25));
    polygon.append(QPoint(HANDCENTERX, HANDCENTERY-75));
    polygon.append(QPoint(HANDCENTERX+10, HANDCENTERY-25));
    painter.drawPolygon(polygon);
    // Hand back
    painter.setBrush(handBrushBack);
    painter.setPen(handPenBack);
    polygon.clear();
    polygon.append(HANDCENTER);
    polygon.append(QPoint(HANDCENTERX-10, HANDCENTERY+25));
    polygon.append(QPoint(HANDCENTERX+10, HANDCENTERY+25));
    painter.drawPolygon(polygon);
    painter.end();
    // Mask
    tenthHand.setMask(tenthHand.createMaskFromColor(
                          backgroundBrush.color(),
                          Qt::MaskInColor)
                      );


    // HAND, HUNDREDS of FEETS
    hundredsHand = QPixmap(HANDWIDTH, HANDHEIGHT);
    painter.begin(&(this->hundredsHand));
    painter.setRenderHint(QPainter::Antialiasing);
    painter.fillRect(hundredsHand.rect(), backgroundBrush);
    // Hand front
    painter.setBrush(handBrushFront);
    painter.setPen(handPenFront);
    painter.drawRect(QRect(
                         HANDCENTERX-2,
                         CIRCLEPENWIDTH+5,
                         4,
                         HANDCENTERY-CIRCLEPENWIDTH-5)
                     );
    polygon.clear();
    polygon.append(QPoint(HANDCENTERX-10, CIRCLEPENWIDTH+5));
    polygon.append(QPoint(HANDCENTERX+10, CIRCLEPENWIDTH+5));
    polygon.append(QPoint(HANDCENTERX, CIRCLEPENWIDTH+5+15));
    painter.drawPolygon(polygon);
    // Hand back
    painter.setBrush(handBrushBack);
    painter.setPen(handPenBack);
    painter.end();
    // Mask
    hundredsHand.setMask(hundredsHand.createMaskFromColor(
                             backgroundBrush.color(),
                             Qt::MaskInColor)
                         );

}
コード例 #20
0
ファイル: modetabbar.cpp プロジェクト: KittyIM/kitty.im
	void ModeTabBar::paintEvent(QPaintEvent *event)
	{
		QPainter p(this);
		IconManager *iconManager = IconManager::instance();

		QLinearGradient bgGrad(rect().topLeft(), rect().topRight());
		bgGrad.setColorAt(0.5, palette().color(QPalette::Window));
		bgGrad.setColorAt(1.0, palette().color(QPalette::Midlight));
		p.fillRect(rect(), bgGrad);

		p.setPen(palette().color(QPalette::Shadow));
		p.drawLine(width() - 1, 0, width() - 1, height());

		for(int i = 0; i < count(); ++i) {
			p.save();

			QFont labelFont = font();
			labelFont.setBold(true);
			p.setFont(labelFont);

			QRect rect = tabRect(i);

			int textHeight = p.fontMetrics().boundingRect(QRect(0, 0, width(), height()), 0, tabLabel(i)).height();
			QRect labelRect(QPoint(rect.left() + tabPadding, rect.bottom() - textHeight - tabPadding), QSize(rect.width() - (tabPadding * 2), textHeight));

			int iconSize = rect.height() - textHeight - (3 * tabPadding);
			QRect iconRect(QPoint((rect.width() - iconSize) / 2, rect.top() + tabPadding), QSize(iconSize, iconSize));

			bool isSelected = (i == m_currentIndex);
			bool isEnabled = isTabEnabled(i);
			bool isHovered = (i == m_hoverIndex);

			if(isHovered && isEnabled) {
				p.fillRect(rect.adjusted(0, 0, -1, 0), QColor(0, 0, 0, 24));
			}

			if(isSelected) {
				p.save();

				p.setPen(palette().color(QPalette::Shadow));
				p.drawLine(rect.topLeft(), rect.topRight());
				p.drawLine(rect.bottomLeft(), rect.bottomRight());

				p.fillRect(rect.adjusted(0, 0, -1, 0), QColor(0, 0, 0, 32));
				p.translate(rect.width() - 6, rect.top() + (rect.height() / 2) - 12);

				QPolygon arrowPoly;
				arrowPoly.append(QPoint(7, 0));
				arrowPoly.append(QPoint(7, 24));
				arrowPoly.append(QPoint(0, 12));

				p.translate(0, 1);
				p.setBrush(palette().color(QPalette::Shadow));
				p.setPen(palette().color(QPalette::Shadow));
				p.setRenderHint(QPainter::Antialiasing);
				p.drawPolygon(arrowPoly);

				p.translate(0, -1);
				p.setBrush(palette().color(QPalette::Light));
				p.drawPolygon(arrowPoly);

				p.restore();
			}

			if(!isEnabled)
				p.setOpacity(0.6);

			QIcon icon(iconManager->icon(tabIcon(i)));
			QPixmap pixmap = icon.pixmap(iconSize, iconSize, isEnabled ? QIcon::Normal : QIcon::Disabled);

			p.drawPixmap(iconRect, pixmap);

			p.setPen(palette().color(QPalette::Text));
			p.drawText(labelRect, Qt::AlignCenter, tabLabel(i));
			p.restore();
		}
	}