Exemple #1
0
void ImageItem::paint(QPainter *ppainter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    ppainter->save();
    if (isSelected()) ppainter->setOpacity(Const::SELECTION_OPACITY);
    else ppainter->setOpacity(qreal(opacity())/100);

    QPointF point = rect().topLeft();
    QImage img;

    if (m_scale && !image().isNull()){
        img = image().scaled(rect().width(), rect().height(), keepAspectRatio() ? Qt::KeepAspectRatio : Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
    } else {
        img = image();
    }

    qreal shiftHeight = rect().height() - img.height();
    qreal shiftWidth = rect().width() - img.width();

    if (m_center){
        if (shiftHeight<0 || shiftWidth<0){
            qreal cutX = 0;
            qreal cutY = 0;
            qreal cutWidth = img.width();
            qreal cutHeigth = img.height();

            if (shiftWidth > 0){
                point.setX(point.x()+shiftWidth/2);
            } else {
                cutX = abs(shiftWidth/2);
                cutWidth += shiftWidth;
            }

            if (shiftHeight > 0){
                point.setY(point.x()+shiftHeight/2);
            } else {
                cutY = abs(shiftHeight/2);
                cutHeigth += shiftHeight;
            }

            img = img.copy(cutX,cutY,cutWidth,cutHeigth);
        } else {
            point.setX(point.x()+shiftWidth/2);
            point.setY(point.y()+shiftHeight/2);
        }
    }

    if (img.isNull() && itemMode()==DesignMode){
        QString text;
        ppainter->setFont(transformToSceneFont(QFont("Arial",10)));
        if (!datasource().isEmpty() && !field().isEmpty())
            text = datasource()+"."+field();
        else text = tr("Image");
        ppainter->drawText(rect().adjusted(4,4,-4,-4), Qt::AlignCenter, text );
    } else {
        ppainter->drawImage(point,img);
    }
    ItemDesignIntf::paint(ppainter,option,widget);
    ppainter->restore();
}
Exemple #2
0
void TextItem::geometryChangedEvent(QRectF , QRectF)
{
//    if ((m_angle==Angle0)||(m_angle==Angle180)){
//        m_text->setTextWidth(rect().width()-fakeMarginSize()*2);
//    } else {
//        m_text->setTextWidth(rect().height()-fakeMarginSize()*2);
//    }
//    m_textSize=m_text->size();
    if (itemMode() == DesignMode) initText();
}
Exemple #3
0
void TextItem::setContent(const QString &value)
{
    if (m_strText.compare(value)!=0){
        QString oldValue = m_strText;
        m_strText=value;
        if (allowHTML())
            m_text->setHtml(replaceReturns(value.trimmed()));
        else
            m_text->setPlainText(value);
        //m_text->setTextWidth(width());
        //m_textSize=m_text->size();
        if (itemMode() == DesignMode){
            initText();
        }

        if (!isLoading()){
          update(rect());
          notify("content",oldValue,value);
          //updateLayout();
        }
    }
}