void CSharedPainterScene::drawLastItemBorderRect( void  )
{
	if( ! lastAddItem_ )
		return;

	if( ! lastAddItem_->drawingObject() )
		return;

	QAbstractGraphicsShapeItem* i = reinterpret_cast<QAbstractGraphicsShapeItem *>(lastAddItem_->drawingObject());
	if( ! i )
		return;

	// setting style..
	QPainterPath path = createCoveringBorderPath( lastItemBorderType_, i );
	if ( path.isEmpty() )
		return;

	clearLastItemBorderRect();

	QAbstractGraphicsShapeItem* lastBorderItem = addPath( path );
	lastBorderItem->setPen( QPen( Util::getComplementaryColor(backgroundColor_, penColor() ), 2) );
	lastBorderItem->setZValue( currentZValue() );
	lastCoverGraphicsItem_ = lastBorderItem;

	// clear
	lastTempBlinkShowFlag_ = true;
	lastTimeValue_ = QDateTime::currentDateTime().toMSecsSinceEpoch();
	timeoutRemoveLastCoverItem_ = DEFAULT_TIMEOUT_REMOVE_LAST_COVER_ITEM;
}
Пример #2
0
void cgGdiplusRender::DrawLine( const cgPoint& from, const cgPoint& to, cgColor color )
{
	Gdiplus::Color penColor((Gdiplus::ARGB)color);

	Gdiplus::Pen pen(penColor);;

	m_pkGraphics->DrawLine(&pen, from.x, from.y, to.x, to.y);
}
Пример #3
0
void FadeLabel::paintEvent(QPaintEvent* /*event*/)
{
	QRectF r( rect() );
	r.adjust(1, 1, -1, -1);
	
	QPainter painter(this);
	painter.setRenderHints(QPainter::Antialiasing|QPainter::TextAntialiasing);
	
	QColor penColor( palette().color(QPalette::Button) );
	if(penColor.alpha() > 0)
		painter.setPen( QPen(penColor,2) );
	else
		painter.setPen(Qt::NoPen);
	painter.setBrush( palette().color(QPalette::Window) );
	RenderBackground(painter, r);
	
	sImage &img = m_Images[m_ImageIndex];
	if( !img.pixmap.isNull() )
	{
		painter.drawPixmap(	r.x() + qRound((r.width()-img.pixmap.width())*0.5),
						   r.y() + qRound((r.height()-img.pixmap.height())*0.5),
						   img.pixmap );
	}
	
	QColor textColor( palette().color(QPalette::ButtonText) );
	if( !isEnabled() )
		textColor = textColor.darker(150);
	
	if( !text().isEmpty() )
	{
		if( m_Label.isEmpty() )
		{
			// just text centered
			painter.setPen(textColor);
			painter.drawText(r, Qt::AlignCenter|Qt::TextWordWrap, text());
		}
		else
		{
			// both text and label text
			QRectF textRect;
			painter.setPen(textColor);
			painter.drawText(r, Qt::AlignCenter|Qt::TextWordWrap|Qt::TextDontPrint, text(), &textRect);
			
			QRectF labelRect;
			painter.drawText(r, Qt::AlignCenter|Qt::TextWordWrap|Qt::TextDontPrint, m_Label, &labelRect);
			
			qreal h = (r.height() * 0.5 * (textRect.height()/labelRect.height()));
			painter.drawText(QRectF(r.x(),r.y(),r.width(),h), Qt::AlignCenter|Qt::TextWordWrap, text());
			painter.drawText(QRectF(r.x(),r.y()+h,r.width(),r.height()-h), Qt::AlignCenter|Qt::TextWordWrap, m_Label);
		}
	}
	else if( !m_Label.isEmpty() )
	{
		// just label text centered
		painter.setPen(textColor);
		painter.drawText(r, Qt::AlignCenter|Qt::TextWordWrap, m_Label);
	}
}
Пример #4
0
void cgGdiplusRender::DrawBox( const cgRectF& rect, cgColor color )
{
	Gdiplus::Color penColor((Gdiplus::ARGB)color);

	Gdiplus::Pen pen(penColor);;

	m_pkGraphics->DrawRectangle(&pen, rect.x, rect.y, rect.w, rect.h);

}
Пример #5
0
void DrawingPolyItem::writeXmlAttributes(QXmlStreamWriter& xmlWriter, const QList<DrawingItem*>& items)
{
	DrawingItem::writeXmlAttributes(xmlWriter, items);

	xmlWriter.writeAttribute("penColor", Drawing::colorToString(penColor()));
	xmlWriter.writeAttribute("penWidth", QString::number(penWidth()));
	xmlWriter.writeAttribute("penStyle", QString::number((unsigned int)penStyle()));
	xmlWriter.writeAttribute("penCapStyle", QString::number((unsigned int)penCapStyle()));
	xmlWriter.writeAttribute("penJoinStyle", QString::number((unsigned int)penJoinStyle()));
}
void VesselConnectionView::paint(QPainter *painter,
                                 const QStyleOptionGraphicsItem *option,
                                 QWidget *widget)
{
	Q_UNUSED(widget);

	double lod = option->levelOfDetailFromTransform(painter->transform());
	if (lod < minLOD())
		return;

	QColor fill_color = baseColor(option);
	QColor dark_fill_color = fill_color.dark();

	QGradientStops stops;
	stops << QGradientStop(0.038, dark_fill_color)
	      << QGradientStop(0.128, fill_color)
	      << QGradientStop(0.174, fill_color)
	      << QGradientStop(0.174+0.125-0.03, dark_fill_color)
	      << QGradientStop(0.45, fill_color)
	      << QGradientStop(0.55, fill_color)

	      << QGradientStop(1-(0.174+0.125-0.03), dark_fill_color)
	      << QGradientStop(1-0.174, fill_color)
	      << QGradientStop(1-0.128, fill_color)
	      << QGradientStop(1-0.038, dark_fill_color);
	const QRectF &br = boundingRect();
	QLinearGradient gradient(QLineF(br.topLeft(), br.topRight()).pointAt(0.5),
	                         QLineF(br.bottomRight(), br.bottomLeft()).pointAt(0.5));
	gradient.setStops(stops);

	QLinearGradient gradient2(QLineF(br.topLeft(), br.bottomLeft()).pointAt(0.5),
	                          QLineF(br.topRight(), br.bottomRight()).pointAt(0.5));
	QColor transparent_color(fill_color), semi_transparent_color(fill_color);
	transparent_color.setAlpha(0);
	semi_transparent_color.setAlpha(200);

	gradient2.setStops(QGradientStops()
	                   << QGradientStop(0, transparent_color)
	                   << QGradientStop(0.45, semi_transparent_color)
	                   << QGradientStop(0.55, semi_transparent_color)
	                   << QGradientStop(1, transparent_color));

	painter->setPen(QPen(penColor(option), 32/2, Qt::SolidLine, Qt::FlatCap, Qt::RoundJoin));
	painter->drawPath(path);

	if (isClearBg()) {
		painter->fillPath(fill, Qt::white);
	}
	else {
		painter->fillPath(fill, gradient);
		painter->fillPath(fill, gradient2);
	}
}
void IconEditor::setImagePixel(const QPoint &pos, bool opaque)
{
    int i = pos.x() / zoom;
    int j = pos.y() / zoom;

    if (image.rect().contains(i, j)) {
        if (opaque) {
            image.setPixel(i, j, penColor().rgba());
        } else {
            image.setPixel(i, j, qRgba(0, 0, 0, 0));
        }
        update(pixelRect(i, j));
    }
}
Пример #8
0
ItemSettings::ItemSettings(ItemProperties *prop,QWidget *parent):QWidget(parent,Qt::Tool)
{
    setupUi(this);

    this->prop = prop;

    this->fontColor = prop->fontColor;
    this->penColor = prop->itemPen.color();
    this->brushColor = prop->itemBrush.color();

    QPixmap penColor(45,11);
    penColor.fill(prop->itemPen.color());
    QIcon penIcon(penColor);
    this->pb_penColor->setIcon(penIcon);
    this->pb_penColor->setIconSize(QSize(45,11));
    this->sd_penWidth->setValue(prop->itemPen.width());
    this->cb_penStyle->setCurrentIndex(this->prop->itemPen.style() - 1);

    QPixmap brushColor(45,11);
    brushColor.fill(prop->itemBrush.color());
    QIcon brushIcon(brushColor);
    this->pb_brushColor->setIcon(brushIcon);
    this->pb_brushColor->setIconSize(QSize(45,11));
    this->cb_brushStyle->setCurrentIndex(this->prop->itemBrush.style());

    QPixmap fontColor(45,11);
    fontColor.fill(prop->fontColor);
    QIcon fontIcon(fontColor);
    this->pb_fontColor->setIcon(fontIcon);
    this->pb_fontColor->setIconSize(QSize(45,11));

    connect(pb_penColor,SIGNAL(released()),this,SLOT(setPenColor()));
    connect(pb_brushColor,SIGNAL(released()),this,SLOT(setBrushColor()));
    connect(pb_done,SIGNAL(released()),this,SLOT(saveSettings()));
    connect(pb_selectFont,SIGNAL(released()),this,SLOT(selectFont()));
    connect(pb_fontColor,SIGNAL(released()),this,SLOT(setFontColor()));

    int p_midX = parent->x() + 100;
    int p_midY = parent->y() + 150;

    this->move(p_midX , p_midY) ;

    this->activateWindow();
}
int StickMan::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QGraphicsObject::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        if (_id < 2)
            qt_static_metacall(this, _c, _id, _a);
        _id -= 2;
    }
#ifndef QT_NO_PROPERTIES
      else if (_c == QMetaObject::ReadProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: *reinterpret_cast< QColor*>(_v) = penColor(); break;
        case 1: *reinterpret_cast< QColor*>(_v) = fillColor(); break;
        case 2: *reinterpret_cast< bool*>(_v) = isDead(); break;
        }
        _id -= 3;
    } else if (_c == QMetaObject::WriteProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: setPenColor(*reinterpret_cast< QColor*>(_v)); break;
        case 1: setFillColor(*reinterpret_cast< QColor*>(_v)); break;
        case 2: setIsDead(*reinterpret_cast< bool*>(_v)); break;
        }
        _id -= 3;
    } else if (_c == QMetaObject::ResetProperty) {
        _id -= 3;
    } else if (_c == QMetaObject::QueryPropertyDesignable) {
        _id -= 3;
    } else if (_c == QMetaObject::QueryPropertyScriptable) {
        _id -= 3;
    } else if (_c == QMetaObject::QueryPropertyStored) {
        _id -= 3;
    } else if (_c == QMetaObject::QueryPropertyEditable) {
        _id -= 3;
    } else if (_c == QMetaObject::QueryPropertyUser) {
        _id -= 3;
    }
#endif // QT_NO_PROPERTIES
    return _id;
}
Пример #10
0
// -----------------------------------------------------------------------------
// General.
// -----------------------------------------------------------------------------
ReAnimGraphicsScene::ReAnimGraphicsScene( ReAnimModel* _model, QObject* _parent /* = NULL */ )
: TSuper( _parent )
, m_editMenu( NULL )
{
	const int width = 2000;
	const int height = 2000;
	QColor penColor( 190, 190, 190 );
	setSceneRect( -width / 2, -height / 2, width, height );
	setBackgroundBrush( QBrush( Qt::gray ) );
	QGraphicsLineItem* lineA = addLine( -width / 2, 0, width / 2, 0, QPen( penColor ) );
	lineA->setZValue( -999.0f );
	QGraphicsLineItem* lineB = addLine( 0, -height / 2, 0, height / 2, QPen( penColor ) );
	lineA->setZValue( -999.0f );

	m_editMenu = new QMenu();
	m_createItemAction = m_editMenu->addAction( tr( "&Add Item" ) );
	connect( m_createItemAction, SIGNAL( triggered() ), this, SLOT( OnAddItem() ) );
	m_deleteItemAction = m_editMenu->addAction( tr( "&Delete Item" ) );
	connect( m_deleteItemAction, SIGNAL( triggered() ), this, SLOT( OnDeleteItem() ) );
}
Пример #11
0
/*!
  Set the outline
  */
void QgsRubberBand::setBorderColor( const QColor & color )
{
  QColor penColor( color.red(), color.green(), color.blue(), color.alpha() );
  mPen.setColor( penColor );
}
Пример #12
0
void Executer::executePenColor(TreeNode* node) {
//	//qDebug() << "called";
	if (!checkParameterQuantity(node, 3, 20000+Token::PenColor*100+90) ||
		!checkParameterType(node, Value::Number, 20000+Token::PenColor*100+91)) return;
	emit penColor(node->child(0)->value()->number(), node->child(1)->value()->number(), node->child(2)->value()->number());
}
Пример #13
0
void Plugin14CRefView::setDate(const Date& d, const ProjectSettings& settings)
{
    QLocale locale=QLocale();
    GraphViewRefAbstract::setDate(d, settings);
    Date date = d;
    
    mGraph->removeAllCurves();
    mGraph->clearInfos();
    mGraph->showInfos(true);
    mGraph->setRangeX(mSettings.mTmin, mSettings.mTmax);
    mGraph->setCurrentX(mSettings.mTmin, mSettings.mTmax);
    mGraph->setFormatFunctX(mFormatFuncX);
    
    if(!date.isNull())
    {
        double age = date.mData.value(DATE_14C_AGE_STR).toDouble();
        double error = date.mData.value(DATE_14C_ERROR_STR).toDouble();
        double delta_r = date.mData.value(DATE_14C_DELTA_R_STR).toDouble();
        double delta_r_error = date.mData.value(DATE_14C_DELTA_R_ERROR_STR).toDouble();
        QString ref_curve = date.mData.value(DATE_14C_REF_CURVE_STR).toString().toLower();
        
        // ----------------------------------------------
        //  Reference curve
        // ----------------------------------------------
        
        QColor color2(150, 150, 150);
        
        Plugin14C* plugin = (Plugin14C*)date.mPlugin;

        const QMap<QString, QMap<double, double> >& curves = plugin->getRefData(ref_curve);
        
        
        QMap<double, double> curveG;
        QMap<double, double> curveG95Sup;
        QMap<double, double> curveG95Inf;
        
        double yMin = curves["G95Inf"][mSettings.mTmin];
        double yMax = curves["G95Sup"][mSettings.mTmin];
        
        double tMinGraph=curves["G"].firstKey()>mSettings.mTmin ? curves["G"].firstKey(): mSettings.mTmin;
        double tMaxGraph=curves["G"].lastKey()<mSettings.mTmax ?  curves["G"].lastKey() : mSettings.mTmax;
        
        for(double t=tMinGraph; t<=tMaxGraph; ++t) {
            curveG[t] = curves["G"][t];
            curveG95Sup[t] = curves["G95Sup"][t];
            curveG95Inf[t] = curves["G95Inf"][t];
            
            yMin = qMin(yMin, curveG95Inf[t]);
            yMax = qMax(yMax, curveG95Sup[t]);
        }
        
        GraphCurve graphCurveG;
        graphCurveG.mName = "G";
        graphCurveG.mData = curveG;
        graphCurveG.mPen.setColor(Qt::blue);
        graphCurveG.mIsHisto = false;
        mGraph->addCurve(graphCurveG);
        
        GraphCurve graphCurveG95Sup;
        graphCurveG95Sup.mName = "G95Sup";
        graphCurveG95Sup.mData = curveG95Sup;
        graphCurveG95Sup.mPen.setColor(QColor(180, 180, 180));
        graphCurveG95Sup.mIsHisto = false;
        mGraph->addCurve(graphCurveG95Sup);
        
        GraphCurve graphCurveG95Inf;
        graphCurveG95Inf.mName = "G95Inf";
        graphCurveG95Inf.mData = curveG95Inf;
        graphCurveG95Inf.mPen.setColor(QColor(180, 180, 180));
        graphCurveG95Inf.mIsHisto = false;
        mGraph->addCurve(graphCurveG95Inf);
        
        // Display reference curve name
        mGraph->addInfo(tr("Ref : ") + ref_curve);
        
        // -------------------------------------------
        
        yMin = qMin(yMin, age);
        yMin = floor(yMin/10)*10;
        
        yMax = qMax(yMax, age);
        yMax = ceil(yMax/10)*10;
        
        mGraph->setRangeY(yMin, yMax);
        
        // ----------------------------------------------
        //  Measure curve
        // ----------------------------------------------
        GraphCurve curveMeasure;
        curveMeasure.mName = "Measure";
        
        QColor penColor(mMeasureColor);
        QColor brushColor(mMeasureColor);
        
        // Lower opacity in case of delta r not null
        if(delta_r != 0 && delta_r_error != 0){
            penColor.setAlpha(100);
            brushColor.setAlpha(15);
        }else{
            penColor.setAlpha(255);
            brushColor.setAlpha(50);
        }
        curveMeasure.mPen = penColor;
        curveMeasure.mBrush = brushColor;
        
        curveMeasure.mIsVertical = true;
        curveMeasure.mIsHisto = false;
        
        // 5000 pts are used on vertical measure
        // because the y scale auto adjusts depending on x zoom.
        // => the visible part of the measure may be very reduced !
        double step = (yMax - yMin) / 5000.;
        for(double t=yMin; t<yMax; t += step)
        {
            double v = exp(-0.5 * pow((age - t) / error, 2));
            curveMeasure.mData[t] = v;
        }
        curveMeasure.mData = normalize_map(curveMeasure.mData);
        mGraph->addCurve(curveMeasure);
        
        // Infos to write :
        QString info = tr("Age BP : ") + locale.toString(age) + " ± " + locale.toString(error);
        
        // ----------------------------------------------
        //  Delta R curve
        // ----------------------------------------------
        if(delta_r != 0 && delta_r_error != 0)
        {
            // Apply reservoir effect
            age = (age - delta_r);
            error = sqrt(error * error + delta_r_error * delta_r_error);
            
            GraphCurve curveDeltaR;
            curveDeltaR.mName = "Delta R";
            
            penColor = mMeasureColor;
            brushColor = mMeasureColor;
            brushColor.setAlpha(50);
            
            curveDeltaR.mPen = penColor;
            curveDeltaR.mBrush = brushColor;
            
            curveDeltaR.mIsVertical = true;
            curveDeltaR.mIsHisto = false;
            
            // 5000 pts are used on vertical measure
            // because the y scale auto adjusts depending on x zoom.
            // => the visible part of the measure may be very reduced !
            step = (yMax - yMin) / 5000.;
            for(double t=yMin; t<yMax; t += step)
            {
                double v = exp(-0.5 * pow((age - t) / error, 2));
                curveDeltaR.mData[t] = v;
            }
            curveDeltaR.mData = normalize_map(curveDeltaR.mData);
            mGraph->addCurve(curveDeltaR);
            
            info += tr(", ΔR : ") + locale.toString(delta_r) + " ± " + locale.toString(delta_r_error);
        }
        
        // ----------------------------------------------
        //  Sub-dates curves (combination)
        // ----------------------------------------------
        for(int i=0; i<date.mSubDates.size(); ++i){
            const Date& d = date.mSubDates[i];
            
            GraphCurve curveSubMeasure;
            curveSubMeasure.mName = "Sub-Measure " + QString::number(i);
            
            QColor penColor = QColor(167, 126, 73);
            QColor brushColor = QColor(167, 126, 73);
            
            double sub_age = d.mData.value(DATE_14C_AGE_STR).toDouble();
            double sub_error = d.mData.value(DATE_14C_ERROR_STR).toDouble();
            double sub_delta_r = d.mData.value(DATE_14C_DELTA_R_STR).toDouble();
            double sub_delta_r_error = d.mData.value(DATE_14C_DELTA_R_ERROR_STR).toDouble();
            
            // Apply reservoir effect
            sub_age = (sub_age - sub_delta_r);
            sub_error = sqrt(sub_error * sub_error + sub_delta_r_error * sub_delta_r_error);
            
            penColor.setAlpha(255);
            brushColor.setAlpha(50);
            
            curveSubMeasure.mPen = penColor;
            curveSubMeasure.mBrush = brushColor;
            
            curveSubMeasure.mIsVertical = true;
            curveSubMeasure.mIsHisto = false;
            
            // 5000 pts are used on vertical measure
            // because the y scale auto adjusts depending on x zoom.
            // => the visible part of the measure may be very reduced !
            double step = (yMax - yMin) / 5000.;
            for(double t=yMin; t<yMax; t += step)
            {
                double v = exp(-0.5 * pow((sub_age - t) / sub_error, 2));
                curveSubMeasure.mData[t] = v;
            }
            curveSubMeasure.mData = normalize_map(curveSubMeasure.mData);
            mGraph->addCurve(curveSubMeasure);
        }

        // ----------------------------------------------
        //  Textual info
        // ----------------------------------------------
        
        mGraph->addInfo(info);
        
        // ----------------------------------------------
        //  Error on measure (horizontal lines)
        // ----------------------------------------------
        
        GraphCurve curveMeasureAvg;
        curveMeasureAvg.mName = "MeasureAvg";
        curveMeasureAvg.mPen.setColor(mMeasureColor);
        curveMeasureAvg.mPen.setStyle(Qt::SolidLine);
        curveMeasureAvg.mIsHorizontalLine = true;
        
        GraphCurve curveMeasureSup;
        curveMeasureSup.mName = "MeasureSup";
        curveMeasureSup.mPen.setColor(mMeasureColor);
        curveMeasureSup.mPen.setStyle(Qt::DashLine);
        curveMeasureSup.mIsHorizontalLine = true;
        
        GraphCurve curveMeasureInf;
        curveMeasureInf.mName = "MeasureInf";
        curveMeasureInf.mPen.setColor(mMeasureColor);
        curveMeasureInf.mPen.setStyle(Qt::DashLine);
        curveMeasureInf.mIsHorizontalLine = true;
        
        curveMeasureAvg.mHorizontalValue = age;
        curveMeasureSup.mHorizontalValue = age + error;
        curveMeasureInf.mHorizontalValue = age - error;
        
        mGraph->addCurve(curveMeasureAvg);
        mGraph->addCurve(curveMeasureSup);
        mGraph->addCurve(curveMeasureInf);
    }
}
Пример #14
0
QColor UBSettings::currentPenColor()
{
    return penColor(isDarkBackground());
}
Пример #15
0
void CategorizedListViewPainter::drawCategory(const QModelIndex &index,
                int /*sortRole*/,
                const QStyleOption &option,
                QPainter *painter) const
{
        painter->setRenderHint(QPainter::Antialiasing);

        const QString category = index.model()->data(index, CategorizedSortFilterProxyModel::CategoryDisplayRole).toString();
        const QRect optRect = option.rect;
        QFont font(QApplication::font());
        font.setBold(true);
        const QFontMetrics fontMetrics = QFontMetrics(font);

        QColor outlineColor = option.palette.text().color();
        outlineColor.setAlphaF(0.35);

        //BEGIN: top left corner
        {
                painter->save();
                painter->setPen(outlineColor);
                const QPointF topLeft(optRect.topLeft());
                QRectF arc(topLeft, QSizeF(4, 4));
                arc.translate(0.5, 0.5);
                painter->drawArc(arc, 1440, 1440);
                painter->restore();
        }

        //END: top left corner

        //BEGIN: left vertical line
        {
                QPoint start(optRect.topLeft());
                start.ry() += 3;
                QPoint verticalGradBottom(optRect.topLeft());
                verticalGradBottom.ry() += fontMetrics.height() + 5;
                QLinearGradient gradient(start, verticalGradBottom);
                gradient.setColorAt(0, outlineColor);
                gradient.setColorAt(1, Qt::transparent);
                painter->fillRect(QRect(start, QSize(1, fontMetrics.height() + 5)), gradient);
        }

        //END: left vertical line

        //BEGIN: horizontal line
        {
                QPoint start(optRect.topLeft());
                start.rx() += 3;
                QPoint horizontalGradTop(optRect.topLeft());
                horizontalGradTop.rx() += optRect.width() - 6;
                painter->fillRect(QRect(start, QSize(optRect.width() - 6, 1)), outlineColor);
        }

        //END: horizontal line

        //BEGIN: top right corner
        {
                painter->save();
                painter->setPen(outlineColor);
                QPointF topRight(optRect.topRight());
                topRight.rx() -= 4;
                QRectF arc(topRight, QSizeF(4, 4));
                arc.translate(0.5, 0.5);
                painter->drawArc(arc, 0, 1440);
                painter->restore();
        }

        //END: top right corner

        //BEGIN: right vertical line
        {
                QPoint start(optRect.topRight());
                start.ry() += 3;
                QPoint verticalGradBottom(optRect.topRight());
                verticalGradBottom.ry() += fontMetrics.height() + 5;
                QLinearGradient gradient(start, verticalGradBottom);
                gradient.setColorAt(0, outlineColor);
                gradient.setColorAt(1, Qt::transparent);
                painter->fillRect(QRect(start, QSize(1, fontMetrics.height() + 5)), gradient);
        }

        //END: right vertical line

        //BEGIN: text
        {
                QRect textRect(option.rect);
                textRect.setTop(textRect.top() + 7);
                textRect.setLeft(textRect.left() + 7);
                textRect.setHeight(fontMetrics.height());
                textRect.setRight(textRect.right() - 7);

                painter->save();
                painter->setFont(font);
                QColor penColor(option.palette.text().color());
                penColor.setAlphaF(0.6);
                painter->setPen(penColor);
                painter->drawText(textRect, Qt::AlignLeft | Qt::AlignVCenter, category);
                painter->restore();
        }

        //END: text
}
Пример #16
0
void KateCategoryDrawer::drawCategory(const QModelIndex &index,
                                            int sortRole,
                                            const QStyleOption &option,
                                            QPainter *painter) const
{
    Q_UNUSED( sortRole )

    painter->setRenderHint(QPainter::Antialiasing);

    const QRect optRect = option.rect;
    QFont font(QApplication::font());
    font.setBold(true);
    const QFontMetrics fontMetrics = QFontMetrics(font);
    const int height = categoryHeight(index, option);
    const bool leftToRight = painter->layoutDirection() == Qt::LeftToRight;

    //BEGIN: decoration gradient
    {
        QPainterPath path(optRect.bottomLeft());

        path.lineTo(QPoint(optRect.topLeft().x(), optRect.topLeft().y() - 3));
        const QPointF topLeft(optRect.topLeft());
        QRectF arc(topLeft, QSizeF(4, 4));
        path.arcTo(arc, 180, -90);
        path.lineTo(optRect.topRight());
        path.lineTo(optRect.bottomRight());
        path.lineTo(optRect.bottomLeft());

        QColor window(option.palette.window().color());
        const QColor base(option.palette.base().color());

        window.setAlphaF(0.4);

        QLinearGradient decoGradient1;
        if (leftToRight) {
            decoGradient1.setStart(optRect.topLeft());
            decoGradient1.setFinalStop(optRect.bottomLeft());
        } else {
            decoGradient1.setStart(optRect.topRight());
            decoGradient1.setFinalStop(optRect.bottomRight());
        }
        decoGradient1.setColorAt(0, window);
        decoGradient1.setColorAt(1, Qt::transparent);

        QLinearGradient decoGradient2;
        if (leftToRight) {
            decoGradient2.setStart(optRect.topLeft());
            decoGradient2.setFinalStop(optRect.topRight());
        } else {
            decoGradient2.setStart(optRect.topRight());
            decoGradient2.setFinalStop(optRect.topLeft());
        }
        decoGradient2.setColorAt(0, Qt::transparent);
        decoGradient2.setColorAt(1, base);

        painter->fillPath(path, decoGradient1);
        painter->fillPath(path, decoGradient2);
    }
    //END: decoration gradient

    {
        QRect newOptRect(optRect);

        if (leftToRight) {
            newOptRect.translate(1, 1);
        } else {
            newOptRect.translate(-1, 1);
        }

        //BEGIN: inner top left corner
        {
            painter->save();
            painter->setPen(option.palette.base().color());
            QRectF arc;
            if (leftToRight) {
                const QPointF topLeft(newOptRect.topLeft());
                arc = QRectF(topLeft, QSizeF(4, 4));
                arc.translate(0.5, 0.5);
                painter->drawArc(arc, 1440, 1440);
            } else {
                QPointF topRight(newOptRect.topRight());
                topRight.rx() -= 4;
                arc = QRectF(topRight, QSizeF(4, 4));
                arc.translate(-0.5, 0.5);
                painter->drawArc(arc, 0, 1440);
            }
            painter->restore();
        }
        //END: inner top left corner

        //BEGIN: inner left vertical line
        {
            QPoint start;
            QPoint verticalGradBottom;
            if (leftToRight) {
                start = newOptRect.topLeft();
                verticalGradBottom = newOptRect.topLeft();
            } else {
                start = newOptRect.topRight();
                verticalGradBottom = newOptRect.topRight();
            }
            start.ry() += 3;
            verticalGradBottom.ry() += newOptRect.height() - 3;
            QLinearGradient gradient(start, verticalGradBottom);
            gradient.setColorAt(0, option.palette.base().color());
            gradient.setColorAt(1, Qt::transparent);
            painter->fillRect(QRect(start, QSize(1, newOptRect.height() - 3)), gradient);
        }
        //END: inner left vertical line

        //BEGIN: inner horizontal line
        {
            QPoint start;
            QPoint horizontalGradTop;
            if (leftToRight) {
                start = newOptRect.topLeft();
                horizontalGradTop = newOptRect.topLeft();
                start.rx() += 3;
                horizontalGradTop.rx() += newOptRect.width() - 3;
            } else {
                start = newOptRect.topRight();
                horizontalGradTop = newOptRect.topRight();
                start.rx() -= 3;
                horizontalGradTop.rx() -= newOptRect.width() - 3;
            }
            QLinearGradient gradient(start, horizontalGradTop);
            gradient.setColorAt(0, option.palette.base().color());
            gradient.setColorAt(1, Qt::transparent);
            QSize rectSize;
            if (leftToRight) {
                rectSize = QSize(newOptRect.width() - 3, 1);
            } else {
                rectSize = QSize(-newOptRect.width() + 3, 1);
            }
            painter->fillRect(QRect(start, rectSize), gradient);
        }
        //END: inner horizontal line
    }

    QColor outlineColor = option.palette.text().color();
    outlineColor.setAlphaF(0.35);

    //BEGIN: top left corner
    {
        painter->save();
        painter->setPen(outlineColor);
        QRectF arc;
        if (leftToRight) {
            const QPointF topLeft(optRect.topLeft());
            arc = QRectF(topLeft, QSizeF(4, 4));
            arc.translate(0.5, 0.5);
            painter->drawArc(arc, 1440, 1440);
        } else {
            QPointF topRight(optRect.topRight());
            topRight.rx() -= 4;
            arc = QRectF(topRight, QSizeF(4, 4));
            arc.translate(-0.5, 0.5);
            painter->drawArc(arc, 0, 1440);
        }
        painter->restore();
    }
    //END: top left corner

    //BEGIN: left vertical line
    {
        QPoint start;
        QPoint verticalGradBottom;
        if (leftToRight) {
            start = optRect.topLeft();
            verticalGradBottom = optRect.topLeft();
        } else {
            start = optRect.topRight();
            verticalGradBottom = optRect.topRight();
        }
        start.ry() += 3;
        verticalGradBottom.ry() += optRect.height() - 3;
        QLinearGradient gradient(start, verticalGradBottom);
        gradient.setColorAt(0, outlineColor);
        gradient.setColorAt(1, option.palette.base().color());
        painter->fillRect(QRect(start, QSize(1, optRect.height() - 3)), gradient);
    }
    //END: left vertical line

    //BEGIN: horizontal line
    {
        QPoint start;
        QPoint horizontalGradTop;
        if (leftToRight) {
            start = optRect.topLeft();
            horizontalGradTop = optRect.topLeft();
            start.rx() += 3;
            horizontalGradTop.rx() += optRect.width() - 3;
        } else {
            start = optRect.topRight();
            horizontalGradTop = optRect.topRight();
            start.rx() -= 3;
            horizontalGradTop.rx() -= optRect.width() - 3;
        }
        QLinearGradient gradient(start, horizontalGradTop);
        gradient.setColorAt(0, outlineColor);
        gradient.setColorAt(1, option.palette.base().color());
        QSize rectSize;
        if (leftToRight) {
            rectSize = QSize(optRect.width() - 3, 1);
        } else {
            rectSize = QSize(-optRect.width() + 3, 1);
        }
        painter->fillRect(QRect(start, rectSize), gradient);
    }
    //END: horizontal line

    //BEGIN: draw text
    {
        const QString category = index.model()->data(index, Qt::DisplayRole).toString(); // KCategorizedSortFilterProxyModel::CategoryDisplayRole).toString();
        QRect textRect = QRect(option.rect.topLeft(), QSize(option.rect.width() - 2 - 3 - 3, height));
        textRect.setTop(textRect.top() + 2 + 3 /* corner */);
        textRect.setLeft(textRect.left() + 2 + 3 /* corner */ + 3 /* a bit of margin */);
        painter->save();
        painter->setFont(font);
        QColor penColor(option.palette.text().color());
        penColor.setAlphaF(0.6);
        painter->setPen(penColor);
        painter->drawText(textRect, Qt::AlignLeft | Qt::AlignTop, category);
        painter->restore();
    }
    //END: draw text
}
Пример #17
0
void GfxPorts::drawWindow(Window *pWnd) {
	if (pWnd->bDrawn)
		return;
	int16 wndStyle = pWnd->wndStyle;

	pWnd->bDrawn = true;
	Port *oldport = setPort(_wmgrPort);
	penColor(0);
	if ((wndStyle & SCI_WINDOWMGR_STYLE_TRANSPARENT) == 0) {
		pWnd->hSaved1 = _paint16->bitsSave(pWnd->restoreRect, GFX_SCREEN_MASK_VISUAL);
		if (pWnd->saveScreenMask & GFX_SCREEN_MASK_PRIORITY) {
			pWnd->hSaved2 = _paint16->bitsSave(pWnd->restoreRect, GFX_SCREEN_MASK_PRIORITY);
			if ((wndStyle & SCI_WINDOWMGR_STYLE_USER) == 0)
				_paint16->fillRect(pWnd->restoreRect, GFX_SCREEN_MASK_PRIORITY, 0, 15);
		}
	}

	// drawing frame,shadow and title
	if ((getSciVersion() >= SCI_VERSION_1_LATE) ? !(wndStyle & _styleUser) : wndStyle != _styleUser) {
		Common::Rect r = pWnd->dims;

		if (!(wndStyle & SCI_WINDOWMGR_STYLE_NOFRAME)) {
			r.top++;
			r.left++;
			_paint16->frameRect(r);// draw shadow
			r.translate(-1, -1);
			_paint16->frameRect(r);// draw actual window frame

			if (wndStyle & SCI_WINDOWMGR_STYLE_TITLE) {
				if (getSciVersion() <= SCI_VERSION_0_LATE) {
					// draw a black line between titlebar and actual window content for SCI0
					r.bottom = r.top + 10;
					_paint16->frameRect(r);
				}
				r.grow(-1);
				if (getSciVersion() <= SCI_VERSION_0_LATE)
					_paint16->fillRect(r, GFX_SCREEN_MASK_VISUAL, 8); // grey titlebar for SCI0
				else
					_paint16->fillRect(r, GFX_SCREEN_MASK_VISUAL, 0); // black titlebar for SCI01+
				if (!pWnd->title.empty()) {
					int16 oldcolor = getPort()->penClr;
					penColor(_screen->getColorWhite());
					_text16->Box(pWnd->title.c_str(), true, r, SCI_TEXT16_ALIGNMENT_CENTER, 0);
					penColor(oldcolor);
				}

				r.grow(+1);
				r.bottom = pWnd->dims.bottom - 1;
				r.top += 9;
			}

			r.grow(-1);
		}

		if (!(wndStyle & SCI_WINDOWMGR_STYLE_TRANSPARENT))
			_paint16->fillRect(r, GFX_SCREEN_MASK_VISUAL, pWnd->backClr);

		_paint16->bitsShow(pWnd->dims);
	}
	setPort(oldport);
}
Пример #18
0
QJsonObject Style::saveData() const
{
    QJsonObject json = Entity::saveData();

    json["parentStyle"] = parentStyle().isValid() ? parentStyle().entity<Style>()->uid().toString() : Uid().toString();

    if (penColorSet()) {
        json["penColor"] = penColor().name();
    }

    if (fillColorSet()) {
        json["fillColor"] = fillColor().name();
    }

    if (penOpacitySet()) {
        json["penOpacity"] = penOpacity();
    }

    if (fillOpacitySet()) {
        json["fillOpacity"] = fillOpacity();
    }

    if (penStyleSet()) {
        json["penStyle"] = toString(penStyle());
    }

    if (lineWidthSet()) {
        json["lineWidth"] = lineWidth().toString();
    }

    // FIXME line type

    if (doubleLineSet()) {
        json["doubleLine"] = doubleLine();
    }

    if (innerLineWidthSet()) {
        json["innerLineWidth"] = innerLineWidth().toString();
    }

    if (innerLineColorSet()) {
        json["innerLineColor"] = innerLineColor().name();
    }

    if (rotationSet()) {
        json["rotation"] = rotation();
    }

    if (radiusXSet()) {
        json["radiusX"] = radiusX().toString();
    }

    if (radiusYSet()) {
        json["radiusY"] = radiusY().toString();
    }

    if (bendAngleSet()) {
        json["bendAngle"] = bendAngle();
    }

    if (loosenessSet()) {
        json["looseness"] = looseness();
    }

    if (outAngleSet()) {
        json["outAngle"] = outAngle();
    }

    if (inAngleSet()) {
        json["inAngle"] = inAngle();
    }

    if (arrowTailSet()) {
        json["arrowTail"] = toString(arrowTail());
    }

    if (arrowHeadSet()) {
        json["arrowHead"] = toString(arrowHead());
    }

    if (shortenStartSet()) {
        json["shortenStart"] = shortenStart().toString();
    }

    if (shortenEndSet()) {
        json["shortenEnd"] = shortenEnd().toString();
    }

    if (textAlignSet()) {
        json["textAlign"] = toString(textAlign());
    }

    if (shapeSet()) {
        json["shape"] = toString(shape());
    }

    if (minimumWidthSet()) {
        json["minimumWidth"] = minimumWidth().toString();
    }

    if (minimumHeightSet()) {
        json["minimumHeight"] = minimumHeight().toString();
    }

    if (innerSepSet()) {
        json["innerSep"] = innerSep().toString();
    }

    if (outerSepSet()) {
        json["outerSep"] = outerSep().toString();
    }

    return json;
}
Пример #19
0
        QAction *action = new QAction(text, this);
        action->setData(format);
        connect(action, SIGNAL(triggered()), this, SLOT(save()));
        saveAsActs.append(action);
    }

    printAct = new QAction(tr("&Print..."), this);
    connect(printAct, SIGNAL(triggered()), scribbleArea, SLOT(print()));

    exitAct = new QAction(tr("E&xit"), this);
    exitAct->setShortcuts(QKeySequence::Quit);
    connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));

    penColorAct = new QAction(tr("&Pen Color..."), this);
    connect(penColorAct, SIGNAL(triggered()), this, SLOT(penColor()));

    penWidthAct = new QAction(tr("Pen &Width..."), this);
    connect(penWidthAct, SIGNAL(triggered()), this, SLOT(penWidth()));

    clearScreenAct = new QAction(tr("&Clear Screen"), this);
    clearScreenAct->setShortcut(tr("Ctrl+L"));
    connect(clearScreenAct, SIGNAL(triggered()),
            scribbleArea, SLOT(clearImage()));

    aboutAct = new QAction(tr("&About"), this);
    connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));

    aboutQtAct = new QAction(tr("About &Qt"), this);
    connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
}
Пример #20
0
QPen DrawingPolyItem::pen() const
{
	return QPen(penColor(), penWidth(), penStyle(), penCapStyle(), penJoinStyle());
}
Пример #21
0
void
CaptionObject::createImage()
{
  m_recreate = false;
  QStringList regExprs;
  regExprs << "\\$[0-9]*[f|F]";
  regExprs << "\\$[0-9]*[v|V][0-3]*";
  regExprs << "\\$[n|N]\\(\\d*\\.*\\d*\\)";
  regExprs << "\\$[d|D]\\(\\d*\\.*\\d*\\)";

  QString finalText = m_text;

  bool drawPi = false;
  float drawPiAngle = 0;
  for (int nr=0; nr<regExprs.count(); nr++)
    {
      QRegExp rx(regExprs[nr]);
      if (rx.indexIn(finalText) > -1)
	{
	  m_recreate = true;

	  QString txt = rx.cap();
	  QChar fillChar = '0';
	  int fieldWidth = 0;
	  if (txt.length() > 2)
	    {
	      txt.remove(0,1);
	      txt.chop(1);
	      if (txt.endsWith("v", Qt::CaseInsensitive))
		txt.chop(1);
	      fieldWidth = txt.toInt();
	    }

	  QString ftxt;
	  if (nr == 0)
	    ftxt = QString("%1").arg((int)Global::frameNumber(),
				     fieldWidth, 10, fillChar);
	  else if (nr == 1)
	    {
	      QString txt = rx.cap();
	      QStringList rem = txt.split("v",
					  QString::SkipEmptyParts,
					  Qt::CaseInsensitive);
	      int vol = 0;
	      if (rem.count() > 1)
		vol = rem[1].toInt();

	      ftxt = QString("%1").arg((int)Global::actualVolumeNumber(vol),
				       fieldWidth, 10, fillChar);
	    }
	  else if (nr == 2)
	    {
	      QStringList rem = txt.split("(");
	      if (rem.count() > 1)
		ftxt = rem[1];
	    }
	  else if (nr == 3)
	    {
	      drawPi = true;
	      QStringList rem = txt.split("(");
	      if (rem.count() > 1)
		drawPiAngle = rem[1].toDouble();
	    }
	    
	  finalText.replace(rx, ftxt);
	}
    }


  QFontMetrics metric(m_font);
  m_width = metric.width(finalText);

  int mde = metric.descent();
  int fwd = m_width;
  int fht = m_height;
  if (drawPi > 0)
    fwd += fht;

  QImage bImage = QImage(fwd, fht, QImage::Format_ARGB32);
  bImage.fill(0);
  {
    QPainter bpainter(&bImage);
    // we have image as ARGB, but we want RGBA
    // so switch red and blue colors here itself
    QColor penColor(m_haloColor.blue(),
		    m_haloColor.green(),
		    m_haloColor.red());
    bpainter.setPen(penColor);
    bpainter.setFont(m_font);
    if (drawPi)
      bpainter.drawText(fht+1, fht-mde, finalText);
    else
      bpainter.drawText(1, fht-mde, finalText);

    if (drawPi)
      {
	bpainter.setBrush(penColor);
	bpainter.setPen(Qt::NoPen);
	bpainter.drawPie(3,3, fht-6, fht-6,
			 90*16, -360*16);
      }

    uchar *dbits = new uchar[4*fht*fwd];
    uchar *bits = bImage.bits();
    for(int nt=0; nt < 3; nt++)
      {
	memcpy(dbits, bits, 4*fht*fwd);

	for(int i=2; i<fht-2; i++)
	  for(int j=2; j<fwd-2; j++)
	    {
	      for (int k=0; k<4; k++)
		{
		  int sum = 0;
		  
		  for(int i0=-2; i0<=2; i0++)
		    for(int j0=-2; j0<=2; j0++)
		      sum += dbits[4*((i+i0)*fwd+(j+j0)) + k];
		  
		  bits[4*(i*fwd+j) + k] = sum/25;
		}
	    }
      }
    delete [] dbits;
  }


  QImage cImage = QImage(fwd, fht, QImage::Format_ARGB32);
  cImage.fill(0);
  {
    QPainter cpainter(&cImage);
    // first draw the halo image
    cpainter.drawImage(0, 0, bImage);

    // we have image as ARGB, but we want RGBA
    // so switch red and blue colors here itself
    QColor penColor(m_color.blue(),
		    m_color.green(),
		    m_color.red());
    cpainter.setPen(penColor);
    cpainter.setFont(m_font);
    if (drawPi)
      cpainter.drawText(fht+1, fht-mde, finalText);
    else
      cpainter.drawText(1, fht-mde, finalText);

    if (drawPi)
      {
	QColor bgColor(m_haloColor.blue(),
		       m_haloColor.green(),
		       m_haloColor.red());
	cpainter.setPen(Qt::NoPen);
	int nturns = drawPiAngle/360;
	if (qAbs(nturns)%2 == 0)
	  {
	    cpainter.setBrush(bgColor);
	    cpainter.drawPie(3,3, fht-6, fht-6,
			     90*16, -360*16);
	    if(fabs(drawPiAngle-nturns*360) > 0)
	      {		
		cpainter.setBrush(penColor);
		cpainter.drawPie(3,3, fht-6, fht-6,
				 90*16, -(drawPiAngle-nturns*360)*16);
	      }
	  }
	else
	  {
	    cpainter.setBrush(penColor);
	    cpainter.drawPie(3,3, fht-6, fht-6,
			     90*16, -360*16);
	    if(fabs(drawPiAngle-nturns*360) > 0)
	      {		
		cpainter.setBrush(bgColor);
		cpainter.drawPie(3,3, fht-6, fht-6,
				 90*16, -(drawPiAngle-nturns*360)*16);
	      }
	  }

	cpainter.setBrush(Qt::NoBrush);
	cpainter.setPen(penColor);
	cpainter.drawPie(3,3, fht-6, fht-6,
			 90*16, -drawPiAngle*16);

      }

    float alpha = m_color.alpha()/255.0;
    uchar *bits = cImage.bits();
    for(int i=0; i<fht*fwd; i++)
      {
	bits[4*i+0] *= alpha;
	bits[4*i+1] *= alpha;
	bits[4*i+2] *= alpha;
	bits[4*i+3] *= alpha;
      }
  }
  
  m_image = cImage.mirrored();
}
Пример #22
0
void LogScene::getTaskItem(const QModelIndex &index) {
    Task* task = _model->task(index);

    Calendar* calendar = task->project()->projectDefaultCalendar();
    int hoursInDay = calendar->endHour().hour() - calendar->startHour().hour();
    std::vector<TaskLog*>* logs =task->logs();
    double startHour = 0;//calendar->startHour().hour();
    double endHour = 24;//calendar->endHour().hour() + 1;
    double minuteSize = (double)24*BLOCKSIZE / (double)((endHour - startHour) * 60);
    int red = 0;
    for (std::vector<TaskLog*>::iterator iter = logs->begin(); iter != logs->end(); iter++) {
        TaskLog* log = *iter;

        QSize size = sizeHint(index);

        int bordermargin = (size.height() * .4) / 2;

        int daysToStart = _startDate.daysTo(*log->start);
        double x1 = (double)daysToStart * (double)_dayWidth;
        DTime logStartTime = log->start->time();
        double y1 = (double)(logStartTime.totalMinutes() - (startHour*60)) * minuteSize;

        double x2 = (daysToStart + 1) * (double)_dayWidth;
        DTime logEndTime = log->end->time();
        if (log->end->getDay() != log->start->getDay()) {
            logEndTime = DTime(23, 59, 59);
        }
        double y2 = (double)(logEndTime.totalMinutes() - (startHour*60)) * minuteSize;

        QBrush b(task->taskColor());//QImage(":/img/task_bar.png"));//(QPixmap(":/img/task_bar.png"));
        red += 20;
        QColor penColor((task->taskColor().red() < 100) ? 0: (task->taskColor().red() - 100),
                        (task->taskColor().green() < 100) ? 0: (task->taskColor().green() - 100),
                        (task->taskColor().blue() < 100) ? 0: (task->taskColor().blue() - 100));
        QPen pen(penColor);
        if (log->activeLog) {
            pen.setWidth(3);
        }

        QGraphicsItem* item = this->addRect(x1, y1, (x2 - x1), (y2 - y1), pen, b);
        item->setZValue(1);
        if ((y2 - y1) > 20) {
            QFont f("Arial", 8);
            f.setWeight(QFont::Light);
            QBrush brush(penColor);

            std::string description = *task->shortDescription();
            int textY = y1 + 5;
            while (description.length() > 0) {
                std::string label;
                if (description.length() > 15) {
                    label = description.substr(0, 15);
                    description = description.substr(15);
                    if ((label.at(label.length() - 1) != ' ') &&
                        (description.at(0) != ' ')) {
                        int pos;
                        if ((pos = label.rfind(' ')) != std::string::npos) {
                            description = label.substr(pos) + description;
                            label = label.substr(0, pos);
                        }
                    }
                } else {
                    label = description;
                    description = "";
                }
                label = label.erase(label.find_last_not_of(" \n\r\t")+1);
                description = description.erase(description.find_last_not_of(" \n\r\t")+1);
                if ((textY + 20) < y2) {
                    QGraphicsSimpleTextItem* text = this->addSimpleText(tr(label.c_str()));
                    text->setPos(x1 + 10, textY);
                    //text->rotate(90);
                    text->setVisible(true);
                    text->setBrush(brush);
                    text->setFont(f);
                    text->setZValue(2);
                    textY += 15;
                } else {
                    break;
                }
            }
        }
        _currentY += sizeHint(index).height();
    }
    delete(logs);
}
Пример #23
0
void
ClipObject::loadCaption(QString ct, QFont cf,
			QColor cc, QColor chc)
{
  m_captionText = ct;
  m_captionFont = cf;
  m_captionColor = cc;
  m_captionHaloColor = chc;

  if (m_captionText.isEmpty())
    {
      m_captionPresent = false;
      return;
    }

  QFontMetrics metric(m_captionFont);
  int mde = metric.descent();
  int fht = metric.height();
  int fwd = metric.width(m_captionText)+2;

  //-------------------
  QImage bImage = QImage(fwd, fht, QImage::Format_ARGB32);
  bImage.fill(0);
  {
    QPainter bpainter(&bImage);
    // we have image as ARGB, but we want RGBA
    // so switch red and blue colors here itself
    QColor penColor(m_captionHaloColor.blue(),
		    m_captionHaloColor.green(),
		    m_captionHaloColor.red());
    // do not use alpha(),
    // opacity will be modulated using clip-plane's opacity parameter  
    bpainter.setPen(penColor);
    bpainter.setFont(m_captionFont);
    bpainter.drawText(1, fht-mde, m_captionText);

    uchar *dbits = new uchar[4*fht*fwd];
    uchar *bits = bImage.bits();
    memcpy(dbits, bits, 4*fht*fwd);

    for(int i=2; i<fht-2; i++)
      for(int j=2; j<fwd-2; j++)
	{
	  for (int k=0; k<4; k++)
	    {
	      int sum = 0;
	      
	      for(int i0=-2; i0<=2; i0++)
		for(int j0=-2; j0<=2; j0++)
		  sum += dbits[4*((i+i0)*fwd+(j+j0)) + k];
	      
	      bits[4*(i*fwd+j) + k] = sum/25;
	    }
	}
    delete [] dbits;
  }
  //-------------------

  QImage cImage = QImage(fwd, fht, QImage::Format_ARGB32);
  cImage.fill(0);
  QPainter cpainter(&cImage);

  // first draw the halo image
  cpainter.drawImage(0, 0, bImage);


  // we have image as ARGB, but we want RGBA
  // so switch red and blue colors here itself
  QColor penColor(m_captionColor.blue(),
		  m_captionColor.green(),
		  m_captionColor.red());
  // do not use alpha(),
  // opacity will be modulated using clip-plane's opacity parameter  
  cpainter.setPen(penColor);
  cpainter.setFont(m_captionFont);
  cpainter.drawText(1, fht-mde, m_captionText);
  m_textureWidth = fwd;
  m_textureHeight = fht;
      
  unsigned char *image = new unsigned char[4*m_textureWidth*m_textureHeight];
  memcpy(image, cImage.bits(), 4*m_textureWidth*m_textureHeight); 

  if (m_imageTex)
    glDeleteTextures(1, &m_imageTex);
  glGenTextures(1, &m_imageTex);

  glActiveTexture(GL_TEXTURE0);
  glBindTexture(GL_TEXTURE_RECTANGLE_ARB, m_imageTex);
  glTexParameterf(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 
  glTexParameterf(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 
  glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  glTexImage2D(GL_TEXTURE_RECTANGLE_ARB,
	       0,
	       4,
	       m_textureWidth,
	       m_textureHeight,
	       0,
	       GL_RGBA,
	       GL_UNSIGNED_BYTE,
	       image);
  glDisable(GL_TEXTURE_RECTANGLE_ARB);

  delete [] image;

  clearImage();

  m_captionPresent = true;
}
Пример #24
0
void
ScaleBarObject::draw(float pixelGLRatio,
		     int screenWidth, int screenHeight,
		     int viewWidth, int viewHeight,
		     bool grabsMouse)
{
  VolumeInformation pvlInfo = VolumeInformation::volumeInformation();

  QString str;
  bool horizontal = m_type;
  float slen = voxels();
  if (pvlInfo.voxelUnit > 0)
    {
      float avg = (pvlInfo.voxelSize[0] +
		   pvlInfo.voxelSize[1] +
		   pvlInfo.voxelSize[2])/3.0f;
      
      str = QString("%1 %2").			     \
	arg(slen, 0, 'f', Global::floatPrecision()).	\
	arg(pvlInfo.voxelUnitStringShort());     
      
      slen /= avg;
    }
  else
    str = QString("%1 voxels").arg(slen);

  slen = slen/pixelGLRatio;

  Vec s0 = Vec(m_pos.x()*viewWidth,
	       m_pos.y()*viewHeight,
	       1);
  
  Vec s1 = s0;
  if (horizontal)
    {
      slen *= (float)viewWidth/(float)screenWidth;
      s0 -= Vec(slen/2, 0, 0);
      s1 += Vec(slen/2, 0, 0);
    }
  else
    {
      slen *= (float)viewHeight/(float)screenHeight;
      s0 -= Vec(0, slen/2, 0);
      s1 += Vec(0, slen/2, 0);
    }
  
  glEnable(GL_BLEND);
  glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); // back to front
  glColor4f(0, 0, 0, 0.8f);
  if (grabsMouse)
    {
      glColor4f(0.5f, 0, 0, 0.8f);
      glBegin(GL_QUADS);
      if (horizontal)
	{
	  glVertex2f(s0.x-5, s0.y-10);
	  glVertex2f(s1.x+5, s0.y-10);
	  glVertex2f(s1.x+5, s0.y+10);
	  glVertex2f(s0.x-5, s0.y+10);
	}
      else
	{
	  glVertex2f(s0.x-10, s0.y-5);
	  glVertex2f(s0.x-10, s1.y+5);
	  glVertex2f(s0.x+10, s1.y+5);
	  glVertex2f(s0.x+10, s0.y-5);
	}
      glEnd();
    }
  
  
  glDisable(GL_BLEND);
  glColor3f(1,1,1);
  glLineWidth(10);
  glBegin(GL_LINES);
  glVertex3fv(s0);
  glVertex3fv(s1);
  glEnd();
  
  glColor3f(0.5,0.5,0.5);
  glLineWidth(2);
  glBegin(GL_LINES);
  if (horizontal)
    {
      glVertex2f(s0.x+slen/2, s0.y-3);
      glVertex2f(s0.x+slen/2, s1.y+3);
    }
  else
    {
      glVertex2f(s1.x-3, (s1.y+s0.y)/2);
      glVertex2f(s0.x+3, (s1.y+s0.y)/2);
    }
  glEnd();
  glColor3f(0,0,0);
  glLineWidth(2);
  glBegin(GL_LINES);
  if (horizontal)
    {
      glVertex2f(s0.x+1, s0.y);
      glVertex2f(s1.x-1, s1.y);
    }
  else
    {
      glVertex2f(s0.x, s0.y+1);
      glVertex2f(s1.x, s1.y-1);
    }
  glEnd();
  glLineWidth(1);
  glColor3f(1,1,1);
  
  {
    Vec w0 = Vec(m_pos.x()*screenWidth, (1-m_pos.y())*screenHeight,1);
    Vec w1 = w0;
    if (horizontal)
      {
	w0 -= Vec(slen/2, 0, 0);
	w1 += Vec(slen/2, 0, 0);
      }
    else
      {
	w0 -= Vec(0, slen/2, 0);
	w1 += Vec(0, slen/2, 0);
      }
    
    QFont tfont = QFont("Helvetica", 12);
    tfont.setStyleStrategy(QFont::PreferAntialias);
    QFontMetrics metric(tfont);
    int mde = metric.descent();
    int fht = metric.height()+2;

    int fwd = metric.width(str)+2;
    QImage bImage = QImage(fwd, fht, QImage::Format_ARGB32);
    bImage.fill(0);
    QPainter bpainter(&bImage);
    Vec bgcolor = Global::backgroundColor();
    bpainter.setBackgroundMode(Qt::OpaqueMode);
    bpainter.setBackground(QColor(bgcolor.z*255,
				  bgcolor.y*255,
				  bgcolor.x*255));
    float bgintensity = (0.3*bgcolor.x +
			 0.5*bgcolor.y +
			 0.2*bgcolor.z);
    QColor penColor(Qt::white);
    if (bgintensity > 0.5) penColor = Qt::black;
    bpainter.setPen(penColor);
    bpainter.setFont(tfont);
    bpainter.drawText(1, fht-mde, str);
    
    QImage cImage = bImage.mirrored();
    if (!horizontal)
      {	    
	QMatrix matrix;
	matrix.rotate(90);
	cImage = cImage.transformed(matrix);
      }
    int x,y;
    if (horizontal)
      {
	x = (w0.x+w1.x)/2 - cImage.width()/2;
	y = w0.y-3-cImage.height();
	if (!m_textpos)
	  y = w0.y+6;
      }
    else
      {
	x = w1.x+3;
	if (!m_textpos)
	  x = w1.x-5-cImage.width();
	y = (w0.y+w1.y)/2 - cImage.height()/2;
      }
    glWindowPos2i(x,y);
    const uchar *bits = cImage.bits();
    glDrawPixels(cImage.width(), cImage.height(),
		 GL_RGBA,
		 GL_UNSIGNED_BYTE,
		 bits);
  }
}