• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ qAbs函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中qAbs函数的典型用法代码示例。如果您正苦于以下问题:C++ qAbs函数的具体用法?C++ qAbs怎么用?C++ qAbs使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了qAbs函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: Q_ASSERT

Template* Template::loadTemplateConfiguration(QXmlStreamReader& xml, Map& map, bool& open)
{
	Q_ASSERT(xml.name() == "template");
	
	QXmlStreamAttributes attributes = xml.attributes();
	if (attributes.hasAttribute("open"))
		open = (attributes.value("open") == "true");
	
	QString path = attributes.value("path").toString();
	Template* temp = templateForFile(path, &map);
	temp->setTemplateRelativePath(attributes.value("relpath").toString());
	if (attributes.hasAttribute("name"))
		temp->template_file = attributes.value("name").toString();
	temp->is_georeferenced = (attributes.value("georef") == "true");
	if (!temp->is_georeferenced)
		temp->template_group = attributes.value("group").toString().toInt();
		
	while (xml.readNextStartElement())
	{
		if (!temp->is_georeferenced && xml.name() == "transformations")
		{
			temp->adjusted = (xml.attributes().value("adjusted") == "true");
			temp->adjustment_dirty = (xml.attributes().value("adjustment_dirty") == "true");
			int num_passpoints = xml.attributes().value("passpoints").toString().toInt();
Q_ASSERT(temp->passpoints.size() == 0);
			temp->passpoints.reserve(qMin(num_passpoints, 10)); // 10 is not a limit
			
			while (xml.readNextStartElement())
			{
				QStringRef role = xml.attributes().value("role");
				if (xml.name() == "transformation")
				{
					if (role == "active")
						temp->transform.load(xml);
					else if (xml.attributes().value("role") == "other")
						temp->other_transform.load(xml);
					else
					{
						qDebug() << xml.qualifiedName();
						xml.skipCurrentElement(); // unsupported
					}
				}
				else if (xml.name() == "passpoint")
				{
					temp->passpoints.push_back(PassPoint::load(xml));
				}
				else if (xml.name() == "matrix")
				{
					if (role == "map_to_template")
						temp->map_to_template.load(xml);
					else if (role == "template_to_map")
						temp->template_to_map.load(xml);
					else if (role == "template_to_map_other")
						temp->template_to_map_other.load(xml);
					else
					{
						qDebug() << xml.qualifiedName();
						xml.skipCurrentElement(); // unsupported
					}
				}
				else
				{
					qDebug() << xml.qualifiedName();
					xml.skipCurrentElement(); // unsupported
				}
			}
		}
		else if (!temp->loadTypeSpecificTemplateConfiguration(xml))
		{
			delete temp;
			return NULL;
		}
	}
	
	if (!temp->is_georeferenced)
	{
		// Fix template adjustment after moving objects during import (cf. #513)
		const auto offset = MapCoord::boundsOffset();
		if (!offset.isZero())
		{
			temp->template_to_map.set(0, 2, temp->template_to_map_other.get(0, 2) - offset.x / 1000.0);
			temp->template_to_map.set(1, 2, temp->template_to_map_other.get(1, 2) - offset.y / 1000.0);
			temp->template_to_map.invert(temp->map_to_template);
			temp->template_to_map_other.set(0, 2, temp->template_to_map_other.get(0, 2) - offset.x / 1000.0);
			temp->template_to_map_other.set(1, 2, temp->template_to_map_other.get(1, 2) - offset.y / 1000.0);
		}
		
		// Fix template alignment problems caused by grivation rounding since version 0.6
		const double correction = map.getGeoreferencing().getGrivationError();
		if (qAbs(correction) != 0.0 && temp->getTemplateType() == "TemplateTrack")
		{
			temp->setTemplateRotation(temp->getTemplateRotation() + Georeferencing::degToRad(correction));
		}
	}
	
	return temp;
}
开发者ID:kshji,项目名称:mapper,代码行数:97,代码来源:template.cpp


示例2: qAbs

void QgsDecorationScaleBar::render( QPainter * theQPainter )
{
  QgsMapCanvas* canvas = QgisApp::instance()->mapCanvas();

  int myBufferSize = 1; //softcode this later

  //Get canvas dimensions
  int myCanvasHeight = theQPainter->device()->height();
  int myCanvasWidth = theQPainter->device()->width();

  //Get map units per pixel. This can be negative at times (to do with
  //projections) and that just confuses the rest of the code in this
  //function, so force to a positive number.
  double myMapUnitsPerPixelDouble = qAbs( canvas->mapUnitsPerPixel() );
  double myActualSize = mPreferredSize;

  // Exit if the canvas width is 0 or layercount is 0 or QGIS will freeze
  int myLayerCount = canvas->layerCount();
  if ( !myLayerCount || !myCanvasWidth || !myMapUnitsPerPixelDouble )
    return;

  //Large if statement which determines whether to render the scale bar
  if ( enabled() )
  {
    // Hard coded sizes
    int myMajorTickSize = 8;
    int myTextOffsetX = 3;
    int myMargin = 20;

    QSettings settings;
    QGis::UnitType myPreferredUnits = QGis::fromLiteral( settings.value( "/qgis/measure/displayunits", QGis::toLiteral( QGis::Meters ) ).toString() );
    QGis::UnitType myMapUnits = canvas->mapUnits();

    // Adjust units meter/feet or vice versa
    if ( myMapUnits == QGis::Meters && myPreferredUnits == QGis::Feet )
    {
      // From meter to feet
      myMapUnits = QGis::Feet;
      myMapUnitsPerPixelDouble /= 0.3084;
    }
    else if ( myMapUnits == QGis::Feet && myPreferredUnits == QGis::Meters )
    {
      // From feet to meter
      myMapUnits = QGis::Meters;
      myMapUnitsPerPixelDouble *= 0.3084;
    }
    //Calculate size of scale bar for preferred number of map units
    double myScaleBarWidth = mPreferredSize / myMapUnitsPerPixelDouble;

    //If scale bar is very small reset to 1/4 of the canvas wide
    if ( myScaleBarWidth < 30 )
    {
      myScaleBarWidth = myCanvasWidth / 4; // pixels
      myActualSize = myScaleBarWidth * myMapUnitsPerPixelDouble; // map units
    };

    //if scale bar is more than half the canvas wide keep halving until not
    while ( myScaleBarWidth > myCanvasWidth / 3 )
    {
      myScaleBarWidth = myScaleBarWidth / 3;
    };
    myActualSize = myScaleBarWidth * myMapUnitsPerPixelDouble;

    // Work out the exponent for the number - e.g, 1234 will give 3,
    // and .001234 will give -3
    double myPowerOf10 = floor( log10( myActualSize ) );

    // snap to integer < 10 times power of 10
    if ( mSnapping )
    {
      double scaler = pow( 10.0, myPowerOf10 );
      myActualSize = qRound( myActualSize / scaler ) * scaler;
      myScaleBarWidth = myActualSize / myMapUnitsPerPixelDouble;
    }

    //Get type of map units and set scale bar unit label text
    QString myScaleBarUnitLabel;
    switch ( myMapUnits )
    {
      case QGis::Meters:
        if ( myActualSize > 1000.0 )
        {
          myScaleBarUnitLabel = tr( " km" );
          myActualSize = myActualSize / 1000;
        }
        else if ( myActualSize < 0.01 )
        {
          myScaleBarUnitLabel = tr( " mm" );
          myActualSize = myActualSize * 1000;
        }
        else if ( myActualSize < 0.1 )
        {
          myScaleBarUnitLabel = tr( " cm" );
          myActualSize = myActualSize * 100;
        }
        else
          myScaleBarUnitLabel = tr( " m" );
        break;
      case QGis::Feet:
        if ( myActualSize > 5280.0 ) //5280 feet to the mile
//.........这里部分代码省略.........
开发者ID:Adam-Brown,项目名称:Quantum-GIS,代码行数:101,代码来源:qgsdecorationscalebar.cpp


示例3: checkDifference

inline bool checkDifference(qreal a, qreal b, qreal portionTolerance)
{
    return qAbs(a) > 1e-10 ?
        qAbs(a - b) / qAbs(a) < portionTolerance :
        qAbs(a - b) < 1e-10;
}
开发者ID:IGLOU-EU,项目名称:krita,代码行数:6,代码来源:kis_dom_utils_test.cpp


示例4: qAbs

void ShapeResizeStrategy::resizeBy( const QPointF &center, qreal zoomX, qreal zoomY )
{
    QTransform matrix;
    matrix.translate(center.x(), center.y()); // translate to 
    matrix.scale(zoomX, zoomY);
    matrix.translate(-center.x(), -center.y()); // and back

    // that is the transformation we want to apply to the shapes
    matrix = m_unwindMatrix * matrix * m_windMatrix;

    // the resizing transformation without the mirroring part
    QTransform resizeMatrix;
    resizeMatrix.translate(center.x(), center.y()); // translate to 
    resizeMatrix.scale( qAbs(zoomX), qAbs(zoomY) );
    resizeMatrix.translate(-center.x(), -center.y()); // and back

    // the mirroring part of the resizing transformation
    QTransform mirrorMatrix;
    mirrorMatrix.translate(center.x(), center.y()); // translate to 
    mirrorMatrix.scale( zoomX < 0 ? -1 : 1, zoomY < 0 ? -1 : 1 );
    mirrorMatrix.translate(-center.x(), -center.y()); // and back

    int i = 0;
    foreach(KoShape *shape, m_selectedShapes)
    {
        shape->update();

        // this uses resize for the zooming part
        shape->applyAbsoluteTransformation( m_unwindMatrix );

        /*
         normally we would just apply the resizeMatrix now and be done with it, but
         we want to resize instead of scale, so we have to separate the scaling part
         of that transformation which can then be used to resize
        */

        // undo the last resize transformation
        shape->applyAbsoluteTransformation( m_transformations[i].inverted() );

        // save the shapes transformation matrix
        QTransform shapeMatrix = shape->absoluteTransformation(0);

        // calculate the matrix we would apply to the local shape matrix
        // that tells us the effective scale values we have to use for the resizing
        QTransform localMatrix = shapeMatrix * resizeMatrix * shapeMatrix.inverted();
        // save the effective scale values
        qreal scaleX = localMatrix.m11();
        qreal scaleY = localMatrix.m22();

        // calculate the scale matrix which is equivalent to our resizing above
        QTransform scaleMatrix = (QTransform().scale( scaleX, scaleY ));
        scaleMatrix =  shapeMatrix.inverted() * scaleMatrix * shapeMatrix;

        // calculate the new size of the shape, using the effective scale values
        QSizeF size( scaleX * m_startSizes[i].width(), scaleY * m_startSizes[i].height() );

        // apply the transformation
        shape->setSize( size );
        // apply the rest of the transformation without the resizing part
        shape->applyAbsoluteTransformation( scaleMatrix.inverted() * resizeMatrix );
        shape->applyAbsoluteTransformation( mirrorMatrix );

        // and remember the applied transformation later for later undoing
        m_transformations[i] = shapeMatrix.inverted() * shape->absoluteTransformation(0);

        shape->applyAbsoluteTransformation( m_windMatrix );

        shape->update();
        i++;
    }
开发者ID:KDE,项目名称:calligra-history,代码行数:70,代码来源:ShapeResizeStrategy.cpp


示例5: x

QGeometryData MgGeometriesData::cylinder(const QGLCylinder & cylinder,const QVector3D & orientation)
{
	QGeometryData my_geometry;

	qreal x(.0),y(.0);
	int n = cylinder.slices();
	qreal d_angle = 2.0 * M_PI/n;
	qreal angle=0;
	qreal z=cylinder.height();


	qreal scale_bottom,scale_top;
	QVector3D current_point;
	QQuaternion rotation = rotationFromZ(orientation);

	for(int i =0;i<n+1;++i)
	{
		x = cos(angle);
		y = sin(angle);
		if(z!=cylinder.height())
		{
			scale_bottom = cylinder.diameterTop();
			scale_top = cylinder.diameterBottom();
		}
		else
		{
			scale_bottom = cylinder.diameterBottom();
			scale_top = cylinder.diameterTop();
		}


		//bottom point;
		x = cos(angle) * scale_bottom;
		y = sin(angle) * scale_bottom;

		current_point = QVector3D(x,y,z);
		my_geometry.appendVertex(rotation.rotatedVector(current_point));
		my_geometry.appendNormal(rotation.rotatedVector(current_point));

		//top point
		x = scale_top * cos(angle);
		y = scale_top * sin(angle);
		z = qAbs(z-cylinder.height());

		current_point = QVector3D(x,y,z);
		my_geometry.appendVertex(rotation.rotatedVector(current_point));
		my_geometry.appendNormal(rotation.rotatedVector(current_point));

		// next point
		x = scale_top * cos((angle+d_angle));
		y = scale_top * sin(angle+d_angle);
		z = qAbs(z-cylinder.height());

		current_point = QVector3D(x,y,z);
		my_geometry.appendVertex(rotation.rotatedVector(current_point));
		my_geometry.appendNormal(rotation.rotatedVector(current_point));


		z = qAbs(z-cylinder.height());
		angle+=d_angle;
	}
    return my_geometry;
}
开发者ID:kaabimg,项目名称:MgLibrary,代码行数:63,代码来源:mggeometriesdata.cpp


示例6: QgsDebugMsg


//.........这里部分代码省略.........
  for ( int i = 0; i < 4; i++ )
  {
    for ( int j = 0; j < 3; j++ )
    {
      double x = tpoints[i].x();
      double y = tpoints[i].y();
      double dx = ( tpoints[i+1].x() - x ) / 3;
      double dy = ( tpoints[i+1].y() - y ) / 3;
      QgsDebugMsg( QString( "dx = %1 x = %2" ).arg( dx ).arg( x + j*dx ) );
      points << QgsPoint( x + j*dx, y + j*dy );

    }
  }
  points << points[0]; // close polygon

  // Warning: seems that crashes if source == dest
  if ( mProjectionSelector->selectedCrsId() != GEOCRS_ID )
  {
    QgsCoordinateReferenceSystem source = QgsCoordinateReferenceSystem::fromSrsId( mProjectionSelector->selectedCrsId() );

    if ( !source.isValid() )
    {
      QgsGrass::warning( tr( "Cannot create QgsCoordinateReferenceSystem" ) );
      return;
    }

    QgsCoordinateReferenceSystem dest = QgsCoordinateReferenceSystem::fromSrsId( GEOCRS_ID );

    if ( !dest.isValid() )
    {
      QgsGrass::warning( tr( "Cannot create QgsCoordinateReferenceSystem" ) );
      return;
    }

    QgsCoordinateTransform trans( source, dest );

    for ( int i = points.size() - 1; i >= 0; i-- )
    {
      // Warning: I found that with some projections (e.g. Abidjan 1987)
      // if N = 90 or S = -90 the coordinate projected to
      // WGS84 is nonsense (156.983,89.9988 regardless x) ->
      // use 89.9 - for draw it is not so important
      if ( mCellHead.proj == PROJECTION_LL )
      {
        if ( points[i].y() >= 89.9 )
          points[i].setY( 89.9 );
        if ( points[i].y() <= -89.9 )
          points[i].setY( -89.9 );
      }

      QgsDebugMsg( QString( "%1,%2" ).arg( points[i].x() ).arg( points[i].y() ) );

      // exclude points if transformation failed
      try
      {
        points[i] = trans.transform( points[i] );
        QgsDebugMsg( QString( " --> %1,%2" ).arg( points[i].x() ).arg( points[i].y() ) );
      }
      catch ( QgsCsException &cse )
      {
        Q_UNUSED( cse );
        QgsDebugMsg( "Cannot transform point" );
        points.removeAt( i );
      }
    }

    if ( points.size() < 3 )
    {
      QgsDebugMsg( "Cannot reproject region." );
      return;
    }
  }

  for ( int shift = -360; shift <= 360; shift += 360 )
  {
    for ( int i = 0; i < 12; i++ )
    {
      double x1 = points[i].x();
      double x2 = points[i+1].x();

      if ( qAbs( x2 - x1 ) > 150 )
      {
        if ( x2 < x1 )
        {
          x2 += 360;
        }
        else
        {
          x2 -= 360;
        }
      }
      p.drawLine( 180 + shift + ( int )x1, 90 - ( int )points[i].y(),
                  180 + shift + ( int )x2, 90 - ( int )points[i+1].y() );
    }
  }

  p.end();

  mRegionMap->setPixmap( pm );
}
开发者ID:kukupigs,项目名称:QGIS,代码行数:101,代码来源:qgsgrassnewmapset.cpp


示例7: mouseReleaseEvent

void QgsComposerView::mouseReleaseEvent( QMouseEvent* e )
{
  if ( !composition() )
  {
    return;
  }

  QPoint mousePressStopPoint = e->pos();
  int diffX = mousePressStopPoint.x() - mMousePressStartPos.x();
  int diffY = mousePressStopPoint.y() - mMousePressStartPos.y();

  //was this just a click? or a click and drag?
  bool clickOnly = false;
  if ( qAbs( diffX ) < 2 && qAbs( diffY ) < 2 )
  {
    clickOnly = true;
  }

  QPointF scenePoint = mapToScene( e->pos() );

  if ( mPanning )
  {
    mPanning = false;

    if ( clickOnly && e->button() == Qt::MidButton )
    {
      //middle mouse button click = recenter on point

      //get current visible part of scene
      QRect viewportRect( 0, 0, viewport()->width(), viewport()->height() );
      QgsRectangle visibleRect = QgsRectangle( mapToScene( viewportRect ).boundingRect() );
      visibleRect.scale( 1, scenePoint.x(), scenePoint.y() );
      QRectF boundsRect = visibleRect.toRectF();

      //zoom view to fit desired bounds
      fitInView( boundsRect, Qt::KeepAspectRatio );
    }

    //set new cursor
    if ( mCurrentTool == Pan )
    {
      viewport()->setCursor( Qt::OpenHandCursor );
    }
    else
    {
      if ( composition() )
      {
        //allow composer items to change cursor
        composition()->setPreventCursorChange( false );
      }
      viewport()->setCursor( Qt::ArrowCursor );
    }
  }

  if ( mMarqueeSelect )
  {
    endMarqueeSelect( e );
    return;
  }

  switch ( mCurrentTool )
  {
    case Select:
    {
      QGraphicsView::mouseReleaseEvent( e );
      break;
    }

    case Zoom:
    {
      if ( mMarqueeZoom )
      {
        endMarqueeZoom( e );
      }
      break;
    }

    case MoveItemContent:
    {
      if ( mMoveContentItem )
      {
        //update map preview if composer map
        QgsComposerMap* composerMap = dynamic_cast<QgsComposerMap *>( mMoveContentItem );
        if ( composerMap )
        {
          composerMap->setOffset( 0, 0 );
        }

        double moveX = scenePoint.x() - mMoveContentStartPos.x();
        double moveY = scenePoint.y() - mMoveContentStartPos.y();

        composition()->beginCommand( mMoveContentItem, tr( "Move item content" ) );
        mMoveContentItem->moveContent( -moveX, -moveY );
        composition()->endCommand();
        mMoveContentItem = 0;
      }
      break;
    }
    case AddArrow:
      if ( composition() )
//.........这里部分代码省略.........
开发者ID:AndrewBMartin,项目名称:QGIS,代码行数:101,代码来源:qgscomposerview.cpp


示例8: getContentsMargins

void TileLayout::doLayout(const QRect& rect) const
{
	if (m_items.isEmpty())
		return;

	int left, top, right, bottom;
	getContentsMargins(&left, &top, &right, &bottom);
	QRect effectiveRect = rect.adjusted(left, top, -right, -bottom);
	int x = effectiveRect.x();
	int y = effectiveRect.y();

	QWidget* widget = m_items.first()->widget();
	int spaceX = horizontalSpacing();
	if (spaceX == -1)
		spaceX = widget->style()->layoutSpacing(QSizePolicy::DefaultType,
							QSizePolicy::DefaultType,
							Qt::Horizontal);
	int spaceY = verticalSpacing();
	if (spaceY == -1)
		spaceY = widget->style()->layoutSpacing(QSizePolicy::DefaultType,
							QSizePolicy::DefaultType,
							Qt::Vertical);

	qreal layoutAr = qreal(effectiveRect.width()) / effectiveRect.height();
	int count = m_items.size();
	QSize sh = widget->sizeHint();
	qreal pixels = sh.width() * sh.height() * count;

	// Approximation based on the layout's aspect ratio
	qreal totalWidth = qSqrt(pixels * layoutAr);
	int cols = totalWidth / sh.width() + 0.5;
	int rows = (count - 1) / cols + 1;

	// The approximation is far from perfect, so we perform some
	// additional checks to make sure we have as few rows and
	// columns as possible.
	int smallest = qMin(cols, rows);
	if (count <= smallest * smallest)
	{
		cols = smallest;
		rows = smallest;
	}
	if (count <= cols * (rows - 1))
		rows--;
	if (count <= (cols - 1) * rows)
		cols--;

	// Often the column and row counts are backwards, meaning that
	// the available space isn't being used efficiently. In that
	// case we swap the values of 'cols' and 'rows'.
	if (qAbs(cols - rows) >= 1)
	{
		qreal ar1 = qreal(cols * sh.width()) / (rows * sh.height());
		qreal ar2 = qreal(rows * sh.width()) / (cols * sh.height());
		if (qAbs(ar1 - layoutAr) > qAbs(ar2 - layoutAr))
			std::swap(cols, rows);
	}

	int itemWidth = (effectiveRect.width() - (cols - 1) * spaceX) / cols;
	int itemHeight = (effectiveRect.height() - (rows - 1) * spaceY) / rows;

	int col = 0;
	for (QLayoutItem* item : qAsConst(m_items))
	{
		int nextX = x + itemWidth + spaceX;
		if (++col > cols)
		{
			col = 1;
			x = effectiveRect.x();
			y += itemHeight + spaceY;
			nextX = x + itemWidth + spaceX;
		}

		item->setGeometry(QRect(QPoint(x, y), QSize(itemWidth, itemHeight)));

		x = nextX;
	}
}
开发者ID:cutechess,项目名称:cutechess,代码行数:78,代码来源:tilelayout.cpp


示例9: setWindowTitle

void EditAccount::setAccount(QMailAccount *in, AccountConfiguration* conf, bool defaultServer)
{
    account = 0;

    if (!in->id().isValid()) {
        // New account
        accountNameInput->setText("");
        emailInput->setText("");
        mailUserInput->setText("");
        mailPasswInput->setText("");
        mailServerInput->setText("");
        smtpServerInput->setText("");
        mailPortInput->setText("110");
        smtpPortInput->setText("25");
#ifndef QT_NO_OPENSSL
        smtpUsernameInput->setText("");
        smtpPasswordInput->setText("");
        encryption->setCurrentIndex(0);
        authentication->setCurrentIndex(0);
        smtpUsernameInput->setEnabled(false);
        lblSmtpUsername->setEnabled(false);
        smtpPasswordInput->setEnabled(false);
        lblSmtpPassword->setEnabled(false);
        encryptionIncoming->setCurrentIndex(0);
#endif
        pushCheckBox->setChecked(false);
        intervalCheckBox->setChecked(false);
        roamingCheckBox->setEnabled(false);
#ifdef QTOPIA_HOMEUI
        roamingCheckBox->hide();
#endif
        setWindowTitle( tr("Create new account", "translation not longer than English") );

        account = in;
        config = conf;
        typeChanged( 0 );
    } else {
        account = in;
        config = conf;

        accountNameInput->setText( config->accountName() );
        nameInput->setText( config->userName() );
        emailInput->setText( config->emailAddress() );
        mailUserInput->setText( config->mailUserName() );
        mailPasswInput->setText( config->mailPassword() );
        mailServerInput->setText( config->mailServer() );
        smtpServerInput->setText( config->smtpServer() );
        deleteCheckBox->setChecked( config->canDeleteMail() );

        sigCheckBox->setChecked( config->useSignature() );
        sig = config->signature();

        maxSize->setValue(config->maxMailSize());
        thresholdCheckBox->setChecked( config->maxMailSize() != -1 );
        smtpPortInput->setText( QString::number( config->smtpPort() ) );
        defaultMailCheckBox->setChecked( defaultServer );
#ifndef QT_NO_OPENSSL
        smtpUsernameInput->setText(config->smtpUsername());
        smtpPasswordInput->setText(config->smtpPassword());
        authentication->setItemText(3, accountType->currentText());
        authentication->setCurrentIndex(authenticationIndex(config->smtpAuthentication()));
        encryption->setCurrentIndex(static_cast<int>(config->smtpEncryption()));
        AccountConfiguration::AuthType type = authenticationType[authentication->currentIndex()];
        const bool enableCredentials(type == AccountConfiguration::Auth_LOGIN || type == AccountConfiguration::Auth_PLAIN);
        smtpUsernameInput->setEnabled(enableCredentials);
        lblSmtpUsername->setEnabled(enableCredentials);
        smtpPasswordInput->setEnabled(enableCredentials);
        lblSmtpPassword->setEnabled(enableCredentials);
        encryptionIncoming->setCurrentIndex(static_cast<int>(config->mailEncryption()));
#endif
        pushCheckBox->setChecked( config->pushEnabled() );
        intervalCheckBox->setChecked( config->checkInterval() > 0 );
        intervalPeriod->setValue( qAbs( config->checkInterval() ) );
        roamingCheckBox->setChecked( !config->intervalCheckRoamingEnabled() );
        roamingCheckBox->setEnabled( intervalCheckBox->isChecked() );
#ifdef QTOPIA_HOMEUI
        roamingCheckBox->hide();
#endif

        if ( account->messageSources().contains("pop3", Qt::CaseInsensitive)) {
            accountType->setCurrentIndex(0);
            typeChanged(0);
        } else if ( account->messageSources().contains("imap4", Qt::CaseInsensitive)) {
            accountType->setCurrentIndex(1);
            typeChanged(1);
            imapBaseDir->setText( config->baseFolder() );
        } else {
            accountType->setCurrentIndex(2);
            typeChanged(2);
        }
        mailPortInput->setText( QString::number( config->mailPort() ) );
    }

    nameInput->setText( config->userName() );
}
开发者ID:Camelek,项目名称:qtmoko,代码行数:95,代码来源:editaccount.cpp


示例10: write_jpeg_image

static bool write_jpeg_image(const QImage &image, QIODevice *device, int sourceQuality)
{
    bool success = false;
    const QVector<QRgb> cmap = image.colorTable();

    struct jpeg_compress_struct cinfo;
    JSAMPROW row_pointer[1];
    row_pointer[0] = 0;

    struct my_jpeg_destination_mgr *iod_dest = new my_jpeg_destination_mgr(device);
    struct my_error_mgr jerr;

    cinfo.err = jpeg_std_error(&jerr);
    jerr.error_exit = my_error_exit;

    if (!setjmp(jerr.setjmp_buffer)) {
        // WARNING:
        // this if loop is inside a setjmp/longjmp branch
        // do not create C++ temporaries here because the destructor may never be called
        // if you allocate memory, make sure that you can free it (row_pointer[0])
        jpeg_create_compress(&cinfo);

        cinfo.dest = iod_dest;

        cinfo.image_width = image.width();
        cinfo.image_height = image.height();

        bool gray=false;
        switch (image.format()) {
        case QImage::Format_Mono:
        case QImage::Format_MonoLSB:
        case QImage::Format_Indexed8:
            gray = true;
            for (int i = image.colorCount(); gray && i--;) {
                gray = gray & (qRed(cmap[i]) == qGreen(cmap[i]) &&
                               qRed(cmap[i]) == qBlue(cmap[i]));
            }
            cinfo.input_components = gray ? 1 : 3;
            cinfo.in_color_space = gray ? JCS_GRAYSCALE : JCS_RGB;
            break;
        default:
            cinfo.input_components = 3;
            cinfo.in_color_space = JCS_RGB;
        }

        jpeg_set_defaults(&cinfo);

        qreal diffInch = qAbs(image.dotsPerMeterX()*2.54/100. - qRound(image.dotsPerMeterX()*2.54/100.))
                         + qAbs(image.dotsPerMeterY()*2.54/100. - qRound(image.dotsPerMeterY()*2.54/100.));
        qreal diffCm = (qAbs(image.dotsPerMeterX()/100. - qRound(image.dotsPerMeterX()/100.))
                        + qAbs(image.dotsPerMeterY()/100. - qRound(image.dotsPerMeterY()/100.)))*2.54;
        if (diffInch < diffCm) {
            cinfo.density_unit = 1; // dots/inch
            cinfo.X_density = qRound(image.dotsPerMeterX()*2.54/100.);
            cinfo.Y_density = qRound(image.dotsPerMeterY()*2.54/100.);
        } else {
            cinfo.density_unit = 2; // dots/cm
            cinfo.X_density = (image.dotsPerMeterX()+50) / 100;
            cinfo.Y_density = (image.dotsPerMeterY()+50) / 100;
        }


        int quality = sourceQuality >= 0 ? qMin(sourceQuality,100) : 75;
#if defined(Q_OS_UNIXWARE)
        jpeg_set_quality(&cinfo, quality, B_TRUE /* limit to baseline-JPEG values */);
        jpeg_start_compress(&cinfo, B_TRUE);
#else
        jpeg_set_quality(&cinfo, quality, true /* limit to baseline-JPEG values */);
        jpeg_start_compress(&cinfo, true);
#endif

        row_pointer[0] = new uchar[cinfo.image_width*cinfo.input_components];
        int w = cinfo.image_width;
        while (cinfo.next_scanline < cinfo.image_height) {
            uchar *row = row_pointer[0];
            switch (image.format()) {
            case QImage::Format_Mono:
            case QImage::Format_MonoLSB:
                if (gray) {
                    const uchar* data = image.constScanLine(cinfo.next_scanline);
                    if (image.format() == QImage::Format_MonoLSB) {
                        for (int i=0; i<w; i++) {
                            bool bit = !!(*(data + (i >> 3)) & (1 << (i & 7)));
                            row[i] = qRed(cmap[bit]);
                        }
                    } else {
                        for (int i=0; i<w; i++) {
                            bool bit = !!(*(data + (i >> 3)) & (1 << (7 -(i & 7))));
                            row[i] = qRed(cmap[bit]);
                        }
                    }
                } else {
                    const uchar* data = image.constScanLine(cinfo.next_scanline);
                    if (image.format() == QImage::Format_MonoLSB) {
                        for (int i=0; i<w; i++) {
                            bool bit = !!(*(data + (i >> 3)) & (1 << (i & 7)));
                            *row++ = qRed(cmap[bit]);
                            *row++ = qGreen(cmap[bit]);
                            *row++ = qBlue(cmap[bit]);
                        }
//.........这里部分代码省略.........
开发者ID:KDE,项目名称:android-qt,代码行数:101,代码来源:qjpeghandler.cpp


示例11: Q_D

void QDeclarativeMouseArea::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
    Q_D(QDeclarativeMouseArea);
    if (!d->absorb) {
        QDeclarativeItem::mouseMoveEvent(event);
        return;
    }

    d->saveEvent(event);

    // ### we should skip this if these signals aren't used
    // ### can GV handle this for us?
    bool contains = boundingRect().contains(d->lastPos);
    if (d->hovered && !contains)
        setHovered(false);
    else if (!d->hovered && contains)
        setHovered(true);

    if (d->drag && d->drag->target()) {
        if (!d->moved) {
            d->startX = drag()->target()->x();
            d->startY = drag()->target()->y();
        }

        QPointF startLocalPos;
        QPointF curLocalPos;
        if (drag()->target()->parentItem()) {
            startLocalPos = drag()->target()->parentItem()->mapFromScene(d->startScene);
            curLocalPos = drag()->target()->parentItem()->mapFromScene(event->scenePos());
        } else {
            startLocalPos = d->startScene;
            curLocalPos = event->scenePos();
        }

        if (keepMouseGrab() && d->stealMouse)
            d->drag->setActive(true);

        bool dragX = drag()->axis() & QDeclarativeDrag::XAxis;
        bool dragY = drag()->axis() & QDeclarativeDrag::YAxis;

        const qreal x = dragX
                ? qBound(d->drag->xmin(), d->startX + curLocalPos.x() - startLocalPos.x(), d->drag->xmax())
                : d->startX;
        const qreal y = dragY
                ? qBound(d->drag->ymin(), d->startY + curLocalPos.y() - startLocalPos.y(), d->drag->ymax())
                : d->startY;

        if (d->drag->active()) {
            if (dragX && dragY)
                d->drag->target()->setPos(x, y);
            else if (dragX)
                d->drag->target()->setX(x);
            else if (dragY)
                d->drag->target()->setY(y);
        }

        if (!keepMouseGrab()) {
            const int dragThreshold = QApplication::startDragDistance();

            if (qAbs(x - d->startX) > dragThreshold || qAbs(y - d->startY) > dragThreshold) {
                setKeepMouseGrab(true);
                d->stealMouse = true;
            }
        }

        d->moved = true;
    }
    QDeclarativeMouseEvent me(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, false, d->longPress);
    emit mousePositionChanged(&me);
    me.setX(d->lastPos.x());
    me.setY(d->lastPos.y());
    emit positionChanged(&me);
}
开发者ID:stephaneAG,项目名称:PengPod700,代码行数:73,代码来源:qdeclarativemousearea.cpp


示例12: qwtDrawPolyline

static inline void qwtDrawPolyline( QPainter *painter,
    const T *points, int pointCount, bool polylineSplitting )
{
    bool doSplit = false;
    if ( polylineSplitting && pointCount > 3 )
    {
        const QPaintEngine *pe = painter->paintEngine();
        if ( pe && pe->type() == QPaintEngine::Raster )
        {
            if ( painter->pen().width() <= 1 )
            {
#if QT_VERSION < 0x040800
                if ( painter->renderHints() & QPainter::Antialiasing )
                {
                    /*
                        all versions <= 4.7 have issues with 
                        antialiased lines
                     */

                    doSplit = true;
                }
#else
                // all version < 4.8 don't have the bug for
                // short lines below 2 pixels difference
                // in height and width

                doSplit = qwtIsRasterPaintEngineBuggy();
#endif
            }
            else
            {
                /*
                   Raster paint engine is much faster when splitting
                   the polygon, but of course we might see some issues where
                   the pieces are joining
                 */
                doSplit = true;
            }
        }
    }

    if ( doSplit )
    {
        QPen pen = painter->pen();

        const int splitSize = 6;

        if ( pen.width() <= 1 && pen.isSolid() && qwtIsRasterPaintEngineBuggy()
            && !( painter->renderHints() & QPainter::Antialiasing ) )
        {
            int k = 0;

            for ( int i = k + 1; i < pointCount; i++ )
            {
                const QPointF &p1 = points[i-1];
                const QPointF &p2 = points[i];

                const bool isBad = ( qAbs( p2.y() - p1.y() ) <= 1 )
                    &&  qAbs( p2.x() - p1.x() ) <= 1;

                if ( isBad || ( i - k >= splitSize ) )
                {
                    painter->drawPolyline( points + k, i - k + 1 );
                    k = i;
                }
            }

            painter->drawPolyline( points + k, pointCount - k );
        }
        else
        {
            for ( int i = 0; i < pointCount; i += splitSize )
            {
                const int n = qMin( splitSize + 1, pointCount - i );
                painter->drawPolyline( points + i, n );
            }
        }
    }
    else
    {
        painter->drawPolyline( points, pointCount );
    }
}
开发者ID:XelaRellum,项目名称:qwt,代码行数:83,代码来源:qwt_painter.cpp


示例13: qAbs

void MythUIText::FillCutMessage()
{
    m_CutMessage.clear();

    if (m_Message != m_DefaultMessage)
    {
        bool isNumber;
        int value = m_Message.toInt(&isNumber);
        if (isNumber && m_TemplateText.contains("%n"))
        {
            m_CutMessage = qApp->translate("ThemeUI",
                                           m_TemplateText.toUtf8(), NULL,
                                           QCoreApplication::UnicodeUTF8,
                                           qAbs(value));
        }
        else if (m_TemplateText.contains("%1"))
        {
            QString tmp = qApp->translate("ThemeUI", m_TemplateText.toUtf8(),
                                          NULL, QCoreApplication::UnicodeUTF8);
            m_CutMessage = tmp.arg(m_Message);
        }
    }

    if (m_CutMessage.isEmpty())
        m_CutMessage = m_Message;
    if (m_CutMessage.isEmpty())
        return;

    QStringList templist;
    QStringList::iterator it;
    switch (m_textCase)
    {
      case CaseUpper :
        m_CutMessage = m_CutMessage.toUpper();
        break;
      case CaseLower :
        m_CutMessage = m_CutMessage.toLower();
        break;
      case CaseCapitaliseFirst :
        //m_CutMessage = m_CutMessage.toLower();
        templist = m_CutMessage.split(". ");
        for (it = templist.begin(); it != templist.end(); ++it)
            (*it).replace(0,1,(*it).left(1).toUpper());
        m_CutMessage = templist.join(". ");
        break;
      case CaseCapitaliseAll :
        //m_CutMessage = m_CutMessage.toLower();
        templist = m_CutMessage.split(" ");
        for (it = templist.begin(); it != templist.end(); ++it)
            (*it).replace(0,1,(*it).left(1).toUpper());
        m_CutMessage = templist.join(" ");
        break;
    }

    if (m_MinSize.x() > 0)
    {
        QRect rect;
        MakeNarrow(rect);

        // Record the minimal area needed for the message.
        SetMinArea(rect.size());
        if (m_MinArea.width() > 0)
            SetDrawRectSize(m_MinArea.width(), m_MinArea.height());
    }

    if (m_Cutdown)
        m_CutMessage = cutDown(m_CutMessage, m_Font, m_MultiLine);
}
开发者ID:DocOnDev,项目名称:mythtv,代码行数:68,代码来源:mythuitext.cpp


示例14: Q_ASSERT

void ObscuranceMainThread::run()
{
    Q_ASSERT(m_volume);

    m_stopped = false;

    vtkVolumeRayCastMapper *mapper = vtkVolumeRayCastMapper::SafeDownCast(m_volume->GetMapper());
    vtkEncodedGradientEstimator *gradientEstimator = mapper->GetGradientEstimator();
    /// \TODO fent això aquí crec que va més ràpid, però s'hauria de comprovar i provar també amb l'Update()
    gradientEstimator->GetEncodedNormals();

    // Creem els threads
    /// \todo QThread::idealThreadCount() amb Qt >= 4.3
    int numberOfThreads = vtkMultiThreader::GetGlobalDefaultNumberOfThreads();
    QVector<ObscuranceThread*> threads(numberOfThreads);

    // Variables necessàries
    vtkImageData *image = mapper->GetInput();
    unsigned short *data = reinterpret_cast<unsigned short*>(image->GetPointData()->GetScalars()->GetVoidPointer(0));
    int dataSize = image->GetPointData()->GetScalars()->GetSize();
    int dimensions[3];
    image->GetDimensions(dimensions);
    vtkIdType vtkIncrements[3];
    image->GetIncrements(vtkIncrements);

    int increments[3];
    increments[0] = vtkIncrements[0];
    increments[1] = vtkIncrements[1];
    increments[2] = vtkIncrements[2];

    m_obscurance = new Obscurance(dataSize, hasColor(), m_doublePrecision);

    for (int i = 0; i < numberOfThreads; i++)
    {
        ObscuranceThread * thread = new ObscuranceThread(i, numberOfThreads, m_transferFunction);
        thread->setGradientEstimator(gradientEstimator);
        thread->setData(data, dataSize, dimensions, increments);
        thread->setObscuranceParameters(m_maximumDistance, m_function, m_variant, m_obscurance);
        thread->setSaliency(m_saliency, m_fxSaliencyA, m_fxSaliencyB, m_fxSaliencyLow, m_fxSaliencyHigh);
        threads[i] = thread;
    }

    // Estructures de dades reaprofitables
    QVector<Vector3> lineStarts;

    const QVector<Vector3> directions = getDirections();
    int nDirections = directions.size();

    // Iterem per les direccions
    for (int i = 0; i < nDirections && !m_stopped; i++)
    {
        const Vector3 &direction = directions.at(i);

        DEBUG_LOG(QString("Direcció %1: %2").arg(i).arg(direction.toString()));

        // Direcció dominant (0 = x, 1 = y, 2 = z)
        int dominant;
        Vector3 absDirection(qAbs(direction.x), qAbs(direction.y), qAbs(direction.z));
        if (absDirection.x >= absDirection.y)
        {
            if (absDirection.x >= absDirection.z)
            {
                dominant = 0;
            }
            else
            {
                dominant = 2;
            }
        }
        else
        {
            if (absDirection.y >= absDirection.z)
            {
                dominant = 1;
            }
            else
            {
                dominant = 2;
            }
        }

        // Vector per avançar
        Vector3 forward;
        switch (dominant)
        {
            case 0:
                forward = Vector3(direction.x, direction.y, direction.z);
                break;
            case 1:
                forward = Vector3(direction.y, direction.z, direction.x);
                break;
            case 2: 
                forward = Vector3(direction.z, direction.x, direction.y);
                break;
        }
        // La direcció x passa a ser 1 o -1
        forward /= qAbs(forward.x);
        DEBUG_LOG(QString("forward = ") + forward.toString());

        // Dimensions i increments segons la direcció dominant
//.........这里部分代码省略.........
开发者ID:chinhtrandn,项目名称:starviewer,代码行数:101,代码来源:obscurancemainthread.cpp


示例15: NodeControlBase

#include "absnode.h"

#include <fugio/core/uuid.h>

#include <fugio/context_interface.h>

AbsNode::AbsNode( QSharedPointer<fugio::NodeInterface> pNode )
	: NodeControlBase( pNode )
{
	static const QUuid	PII_NUMBER1( "{c13a41c6-544b-46bb-a9f2-19dd156d236c}" );
	static const QUuid	PII_NUMBER2( "{608ac771-490b-4ae6-9c81-12b9af526d09}" );

	mPinInput = pinInput( "Number", PII_NUMBER1 );

	mValOutput = pinOutput<fugio::VariantInterface *>( "Number", mPinOutput, PID_FLOAT, PII_NUMBER2 );
}

void AbsNode::inputsUpdated( qint64 pTimeStamp )
{
	Q_UNUSED( pTimeStamp )

	float		NewVal = qAbs( variant( mPinInput ).toFloat() );

	if( NewVal != mValOutput->variant().toFloat() )
	{
		mValOutput->setVariant( NewVal );

		pinUpdated( mPinOutput );
	}
}
开发者ID:Daandelange,项目名称:Fugio,代码行数:30,代码来源:absnode.cpp


示例16: UndoTransaction

void ResizeGesture::doResize(bool scaleContent)
{
	PageItem* currItem = m_doc->m_Selection->itemAt(0);
	QString targetName = Um::SelectionGroup;
	QPixmap* targetIcon = Um::IGroup;
	if (!m_doc->m_Selection->isMultipleSelection())
	{
		targetName = currItem->getUName();
		targetIcon = currItem->getUPixmap();
	}
	if (!m_transactionStarted)
	{
		m_transactionStarted = new UndoTransaction(Um::instance()->beginTransaction(targetName, targetIcon,
																					Um::Resize, "", Um::IResize));
//		qDebug() << "ResizeGesture::doResize: begin transaction" << m_transactionStarted;
	}
	QRectF newBounds = m_bounds.normalized();
	double dw = (newBounds.width() - m_extraWidth) - currItem->width();
	double dh = (newBounds.height() - m_extraHeight) - currItem->height();
	double dsch = 1.0;
	double dscw = 1.0;
	if (currItem->isArc())
	{
		PageItem_Arc* item = currItem->asArc();
		if (currItem->height() != 0.0)
			dsch = item->arcHeight / currItem->height();
		if (currItem->width() != 0.0)
			dscw = item->arcWidth / currItem->width();
	}
	if (m_doc->m_Selection->isMultipleSelection())
	{
		int RotModeBack = m_doc->RotMode();
		m_doc->RotMode ( 0 );
		double gx, gy, gh, gw;
		m_doc->m_Selection->getGroupRect(&gx, &gy, &gw, & 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ qAddPostRoutine函数代码示例发布时间:2022-05-30
下一篇:
C++ qA函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap