Esempio n. 1
0
void NMGChartLabel::paint(QPainter* painter,
                          const QStyleOptionGraphicsItem* option, 
                          QWidget* widget)
{
  if(hasEnoughSpace())
  {
    painter->setFont(currentFont);
    QPen pen;
    pen.setColor(QColor(baseColor));
    pen.setWidth(1);
    painter->setPen(pen);
    
    QFontMetrics fm(currentFont);
    QRect boundingForText = fm.boundingRect(currentText);
    
    if(type == NMGChartLabel::AXIS_Y) 
    {
      painter->save();
    
      painter->translate(0,currentHeightIntoScene);
      painter->rotate(-90);
      painter->drawText((currentHeightIntoScene - boundingForText.width())/2, 
                        (currentWidthIntoScene - boundingForText.height())/2 + fm.ascent(), 
                        currentText);
      painter->restore();
    }
    else
    {
      painter->drawText((currentWidthIntoScene - boundingForText.width())/2, 
                        (currentHeightIntoScene - boundingForText.height())/2 + fm.ascent(), 
                        currentText);
    }
  }
  else emit signalGiveMeMoreSpace();
}
Esempio n. 2
0
void NMGChartLegend::paint(QPainter* painter,
                           const QStyleOptionGraphicsItem* option, 
                           QWidget* widget)
{
  if(hasEnoughSpace())
  {
    painter->setFont(currentFont);
    QPen pen;
    pen.setColor(Qt::black);
    pen.setWidth(1);
    painter->setPen(pen);
    painter->setBrush(background);
    QFontMetrics fm(currentFont);
    
    painter->save();
    translateToCurrentPosition(painter);
    
    // painting legend outline
    painter->drawRect(0,0,
                      neededMinimumWidthIntoScene-(currentPaddingMargin << 1), 
                      neededMinimumHeightIntoScene-(currentPaddingMargin << 1));
    
    // painting legend entries
    
    // first we new to calculate the space available for each visible legend entry
    double yInterval = (double)(neededMinimumHeightIntoScene-(currentPaddingMargin << 1) -
                       (internalPaddingMargin << 1)) / (double)numberOfVisibleEntries();
    // for performance issues we calculate the relative position of a decoration for any entry
    double decorationRelativeYPos = yInterval-decorationPixels;
    if(decorationRelativeYPos > 0) decorationRelativeYPos /= 2;

    QList<QString>::const_iterator it;
    int idx = 1;
    for(it = entriesOrder.constBegin(); it != entriesOrder.constEnd(); it++)
    {
      LegendEntry entry = legendEntries.find(*it).value();
      if(entry.visible)
      {
        // text
        painter->drawText(internalPaddingMargin + decorationPixels + decorationToTextPadding,
                          internalPaddingMargin + (int)(idx*yInterval) - fm.descent(), 
                          entry.text);
        
        // decoration
        painter->setBrush(entry.color);
        painter->drawRect(internalPaddingMargin,
                          (int)(internalPaddingMargin + (idx-1)*yInterval + 
                                decorationRelativeYPos),
                          decorationPixels,
                          decorationPixels);
        idx++;
      }
    }
    painter->restore();
  }
  else emit signalGiveMeMoreSpace();
}
Esempio n. 3
0
void StyleArray::addStyler( int styleID, TCHAR *styleName )
{
	assert( hasEnoughSpace() );

	_styleArray[_nbStyler]._styleID = styleID;
	_styleArray[_nbStyler]._styleDesc = styleName;
	_styleArray[_nbStyler]._fgColor = black;
	_styleArray[_nbStyler]._bgColor = white;
	_nbStyler++;
}
Esempio n. 4
0
bool aCache::insertItem(CacheItem ci)
{
	if(!hasEnoughSpace(ci)) return false;

	numItems++;

	cache.push_back(ci);
	updateCacheUsed(ci);
	return true;
}
/*!
    \internal
    Install the unzipped widgets at \a source to \a target. The Unique ID is given as \a appId.
 */
WidgetInstallerPrivate::InstallationStatus WidgetInstallerPrivate::install(QString source, QString target, QString appId)
{
    WBM("Maemo specific installation");

    m_appId = appId;
    m_packageName = m_appId + "-wrt-widget";
    
    QStringList arguments = QCoreApplication::arguments();
    for (int i = 0; i < arguments.size(); ++i) {
        if (arguments.at(i) == "--path") {
            if(i+1 < arguments.size())
                m_outputPath = arguments.at(i+1);
        } else if (arguments.at(i) == "--ovi-productid") {
            if(i + 1 < arguments.size()) {
                m_productId = arguments.at(i+1);
                m_packageName = OVISTORE_WEBAPPS_PACKAGE_NAME_PREFIX + m_productId;
            }
        }
    }

    m_installationPath = target;
    if (!m_installationPath.endsWith(QDir::separator()))
        m_installationPath.append(QDir::separator());

#if defined(Q_OS_MAEMO5) || defined(Q_OS_MAEMO6)
    m_packageUtils = new DebianUtils(m_widget, m_packageName, source, m_installationPath, m_appId);
    
#if ENABLE(AEGIS_LOCALSIG)
    //If coming from from trusted zone set the the flag to true for the
    //debian utils and it will create the local signature
    if (m_widget->getWidgetType() == WidgetTypeW3c || m_widget->getWidgetType() == WidgetTypeJIL) {
        WgtWidget* wgtwidget = static_cast<WgtWidget*>(m_widget);
        if (wgtwidget && wgtwidget->isFromTrustedDomain()) {
            static_cast<DebianUtils*>(m_packageUtils)->installFromTrustedOrigin(true);
        }
    }
#endif  //AEGIS_LOCALSIG
    
#elif defined(Q_OS_MEEGO)
    m_packageUtils = new RpmUtils(m_widget, m_packageName, source, m_installationPath, m_appId);
#else
    // TODO: fix for other platforms
#endif

#if defined(Q_OS_MAEMO6)
     if(m_userCancelled)
         return OperationCancelled;
#endif

    if (!m_packageUtils->createPackage()) {
        qCritical() << "Couldn't create package";
        emit m_widget->installationError(WidgetPlatformSpecificInstallFailed);
        return PackageCreationFailed;
    }

#if defined(Q_OS_MAEMO6)
    QCoreApplication::processEvents();
    if(m_userCancelled)
        return OperationCancelled;
    m_packageManager = new PackageManager();
#endif

    int pathIndex = arguments.indexOf("--installation-info-file") + 1;
    if (pathIndex) {
        QFile file(arguments.at(pathIndex));
        if (file.open(QIODevice::WriteOnly | QIODevice::Text)) {
            QTextStream out(&file);
            out << "debcreated: " << m_packageUtils->packageFilePath() << "\n";
            out << "installpath: " << m_installationPath;
            file.close();
        } else
            qCritical() << "Could not open infofile (" << arguments.at(pathIndex) << ") for writing";
    }

    if (m_outputPath.isEmpty() && m_noInstall)
        m_outputPath = QDir::currentPath();

    if (!m_outputPath.isEmpty()) {
        if (!hasEnoughSpace(m_packageUtils->packageFilePath(), m_outputPath)) {
            qCritical() << "Not enough space";
            emit m_widget->installationError(WidgetInsufficientDiskSpace);
            return NotEnoughSpace;
        }

        m_outputPath.append(QDir::separator() + m_packageUtils->packageFileName());
        if (QFile::exists(m_outputPath))
            QFile::remove(m_outputPath);

        if (!QFile::rename(m_packageUtils->packageFilePath(), m_outputPath)) {
            qCritical() << "Couldn't move the package";
            emit m_widget->installationError(WidgetPlatformSpecificInstallFailed);
            return PackageMovingFailed;
        }

        return Success;
    }
    
#if defined(Q_OS_MAEMO6)
    QCoreApplication::processEvents();
    if(m_userCancelled) {
        return OperationCancelled;
    }
#endif

    if (!installPackage()) {
#if defined(Q_OS_MAEMO6)
        if (m_userCancelled)
            return OperationCancelled;
#endif
        qCritical() << "Couldn't install Debian package";
        return PackageInstallationFailed;
    }

    return Success;
}
Esempio n. 6
0
void NMGChartYAxis::paint(QPainter* painter, 
                          const QStyleOptionGraphicsItem* option, 
                          QWidget* widget)
{
  if(hasEnoughSpace())
  {
    painter->setFont(currentFont);
    QPen pen;
    pen.setWidth(1);
    
    // painting a base rectangle for axis line
    pen.setColor(Qt::white);
    painter->setPen(pen);
    painter->setBrush(Qt::white);
    painter->drawRect(currentWidthIntoScene-5, 0, 5, currentHeightIntoScene);
    painter->setBrush(Qt::NoBrush);
    
    // painting axis line
    pen.setColor(Qt::black);
    pen.setStyle(Qt::SolidLine);
    painter->setPen(pen);
    
    double yInterval = 0.0;
    double y = 0.0;
    painter->drawLine(currentWidthIntoScene, 0, currentWidthIntoScene, currentHeightIntoScene);
    if(location == NMGChartAxis::EXTERNAL)
    {
      yInterval = (double)currentHeightIntoScene/(double)(numReferenceValues-1);
      for(int j = 0; j < numReferenceValues; j++)
      {
        y = j*yInterval;
        painter->drawLine(QLineF(currentWidthIntoScene-5, y, currentWidthIntoScene, y));
      }
    }
    else
    { // INTERNAL
      yInterval = (double)currentHeightIntoScene/(double)(numReferenceValues+1);
      for(int j = 1; j <= numReferenceValues; j++)
      {
        y = j*yInterval;
        painter->drawLine(QLineF(currentWidthIntoScene-5, y, currentWidthIntoScene, y)); 
      }
    }
    
    // painting labels
    painter->save();
    painter->translate(0, currentHeightIntoScene); // starting at bottom side
    QFontMetricsF fm(currentFont);
    if(location == NMGChartAxis::EXTERNAL)
    {
      yInterval = (double)currentHeightIntoScene/(double)(numReferenceValues-1);
      // NOTE numReferenceValues-1 is always > 0 because in external mode there are 
      // a minimum of 2 reference values.
      for(int j = 0 ; j < labelsList.size(); j++)
      {
        QRectF boundingForText = fm.boundingRect(labelsList.at(j));
        painter->drawText(QPointF(currentWidthIntoScene - currentPaddingMargin -  
                                  fm.width(labelsList.at(j)), 
                                  -j*yInterval+boundingForText.height()/4.0), 
                          labelsList.at(j));
      }
    }
    else
    { // INTERNAL
      if(!labelsList.isEmpty())
      { // there is at least one label to be painted
        yInterval = (double)currentHeightIntoScene/(double)(numReferenceValues+1);
        for(int j = 0; j < labelsList.size(); j++)
        {
          QRectF boundingForText = fm.boundingRect(labelsList.at(j));
          painter->drawText(QPointF(currentWidthIntoScene - currentPaddingMargin -  
                                    fm.width(labelsList.at(j)), 
                                    -((j+1)*yInterval) + boundingForText.height()/4.0), 
                            labelsList.at(j));
        }
      }
    }
    painter->restore();
  }
  else emit signalGiveMeMoreSpace();
}
Esempio n. 7
0
void StyleArray::addStyler(int styleID, TiXmlNode *styleNode)
{
	assert( hasEnoughSpace() );

	_styleArray[_nbStyler]._styleID = styleID;

	if (styleNode)
	{
		TiXmlElement *element = styleNode->ToElement();

		// For _fgColor, _bgColor :
		// RGB() | (result & 0xFF000000) It's the case for -1 (0xFFFFFFFF)
		// returned by hexStrVal(str)
		const TCHAR *str = element->Attribute(TEXT("name"));
		if (str)
		{
			_styleArray[_nbStyler]._styleDesc = str;
		}

		str = element->Attribute(TEXT("fgColor"));
		if (str)
		{
			unsigned long result = hexStrVal(str);
			_styleArray[_nbStyler]._fgColor = (RGB((result >> 16) & 0xFF, (result >> 8) & 0xFF, result & 0xFF)) | (result & 0xFF000000);

		}

		str = element->Attribute(TEXT("bgColor"));
		if (str)
		{
			unsigned long result = hexStrVal(str);
			_styleArray[_nbStyler]._bgColor = (RGB((result >> 16) & 0xFF, (result >> 8) & 0xFF, result & 0xFF)) | (result & 0xFF000000);
		}

		str = element->Attribute(TEXT("colorStyle"));
		if (str)
		{
			_styleArray[_nbStyler]._colorStyle = decStrVal(str);
		}

		str = element->Attribute(TEXT("fontName"));
		if (str)
		{
			_styleArray[_nbStyler]._fontName = str;
		}

		str = element->Attribute(TEXT("fontStyle"));
		if (str)
		{
			_styleArray[_nbStyler]._fontStyle = decStrVal(str);
		}

		str = element->Attribute(TEXT("fontSize"));
		if (str)
		{
			_styleArray[_nbStyler]._fontSize = decStrVal(str);
		}

		str = element->Attribute(TEXT("keywordClass"));
		if (str)
		{
			_styleArray[_nbStyler]._keywordClass = getKwClassFromName(str);
		}

		TiXmlNode *v = styleNode->FirstChild();
		if (v)
		{
			_styleArray[_nbStyler]._keywords = new generic_string(v->Value());
		}
	}
	_nbStyler++;
}