Beispiel #1
0
TextContent::TextContent(bool spontaneous, QGraphicsScene * scene, QGraphicsItem * parent)
    : AbstractContent(scene, spontaneous, false, parent)
    , m_text(0)
    , m_textRect(0, 0, 0, 0)
    , m_textMargin(4)
    , m_shakeRadius(0)
    , m_shapeEditor(0)
{
    setFrame(0);
    setFrameTextEnabled(false);
    setToolTip(tr("Right click to Edit the text"));

    // create a text document
    m_text = new QTextDocument(this);
    m_textMargin = m_text->documentMargin();

    // template text
    QFont font;
#if defined(Q_OS_WIN) || defined(Q_OS_OS2)
    font.setFamily("Arial");
#endif
    font.setPointSize(16);
    m_text->setDefaultFont(font);
    setPlainText(tr("right click to edit..."));

    // shape editor
    m_shapeEditor = new BezierCubicItem(this);
    m_shapeEditor->setVisible(false);
    m_shapeEditor->setControlPoints(QList<QPointF>() << QPointF(-100, -50) << QPointF(-10, 40) << QPointF(100, -50) << QPointF(100, 50));
    connect(m_shapeEditor, SIGNAL(shapeChanged(const QPainterPath &)), this, SLOT(setShapePath(const QPainterPath &)));
}
bool AbstractContent::fromXml(QDomElement & contentElement, const QDir & /*baseDir*/)
{
    // restore content properties
    QDomElement domElement;

    // Load image size saved in the rect node
    domElement = contentElement.firstChildElement("rect");
    qreal x, y, w, h;
    x = domElement.firstChildElement("x").text().toDouble();
    y = domElement.firstChildElement("y").text().toDouble();
    w = domElement.firstChildElement("w").text().toDouble();
    h = domElement.firstChildElement("h").text().toDouble();
    resizeContents(QRect(x, y, w, h));

    // Load position coordinates
    domElement = contentElement.firstChildElement("pos");
    x = domElement.firstChildElement("x").text().toDouble();
    y = domElement.firstChildElement("y").text().toDouble();
    setPos(x, y);

    qreal zvalue = contentElement.firstChildElement("zvalue").text().toDouble();
    setZValue(zvalue);

    bool visible = contentElement.firstChildElement("visible").text().toInt();
    setVisible(visible);

    qreal opacity = contentElement.firstChildElement("opacity").text().toDouble();
    if (opacity > 0.0 && opacity < 1.0)
        setContentOpacity(opacity);

    int fxIdx = contentElement.firstChildElement("fxindex").text().toInt();
    if (fxIdx > 0)
        setFxIndex(fxIdx);

    bool hasText = contentElement.firstChildElement("frame-text-enabled").text().toInt();
    setFrameTextEnabled(hasText);
    if (hasText) {
        QString text = contentElement.firstChildElement("frame-text").text();
        setFrameText(text);
    }

    quint32 frameClass = contentElement.firstChildElement("frame-class").text().toInt();
    setFrame(frameClass ? FrameFactory::createFrame(frameClass) : 0);

    // restore transformation
    QDomElement te = contentElement.firstChildElement("transformation");
    if (!te.isNull()) {
        m_perspectiveAngles = QPointF(te.attribute("xRot").toDouble(), te.attribute("yRot").toDouble());
#if QT_VERSION < 0x040600
        m_rotationAngle = te.attribute("zRot").toDouble();
#else
        setRotation(te.attribute("zRot").toDouble());
#endif
        applyTransforms();
    }
    domElement = contentElement.firstChildElement("mirror");
    setMirrored(domElement.attribute("state").toInt());

    return true;
}
Beispiel #3
0
PictureContent::PictureContent(QGraphicsScene * scene, QGraphicsItem * parent)
    : AbstractContent(scene, parent, false)
    , m_photo(0)
    , m_opaquePhoto(false)
    , m_progress(0)
    , m_netWidth(0)
    , m_netHeight(0)
    , m_netReply(0)
{
    // enable frame text
    setFrameTextEnabled(true);
    setFrameText(tr("..."));

    // add flipping buttons
    ButtonItem * bFlipH = new ButtonItem(ButtonItem::FlipH, Qt::blue, QIcon(":/data/action-flip-horizontal.png"), this);
    bFlipH->setToolTip(tr("Flip horizontally"));
    bFlipH->setFlag(QGraphicsItem::ItemIgnoresTransformations, false);
    connect(bFlipH, SIGNAL(clicked()), this, SIGNAL(flipHorizontally()));
    addButtonItem(bFlipH);

    ButtonItem * bFlipV = new ButtonItem(ButtonItem::FlipV, Qt::blue, QIcon(":/data/action-flip-vertical.png"), this);
    bFlipV->setToolTip(tr("Flip vertically"));
    bFlipV->setFlag(QGraphicsItem::ItemIgnoresTransformations, false);
    addButtonItem(bFlipV);
    connect(bFlipV, SIGNAL(clicked()), this, SIGNAL(flipVertically()));

    /*ButtonItem * bCrop = new ButtonItem(ButtonItem::Control, Qt::blue, QIcon(":/data/action-scale.png"), this);
    bCrop->setToolTip(tr(""));
    bCrop->setFlag(QGraphicsItem::ItemIgnoresTransformations, false);
    addButtonItem(bCrop);
    connect(bCrop, SIGNAL(clicked()), this, SIGNAL(toggleCropMode()));*/
}
Beispiel #4
0
WebcamContent::WebcamContent(int input, QGraphicsScene * scene, QGraphicsItem * parent)
    : AbstractContent(scene, parent, false)
    , m_input(input)
    , m_still(false)
{
    // enable frame text
    setFrameTextEnabled(true);
    setFrameText(tr("This is a mirror ;-)"));

    // initial pixmap
    setPixmap(QPixmap(":/data/insert-camera.png"));

    // add swap button
    ButtonItem * bSwap = new ButtonItem(ButtonItem::Control, Qt::blue, QIcon(":/data/action-flip-horizontal.png"), this);
    bSwap->setToolTip(tr("Mirror Video"));
    connect(bSwap, SIGNAL(clicked()), this, SLOT(slotToggleSwap()));
    addButtonItem(bSwap);

    // add snapshot button
    ButtonItem * bStill = new ButtonItem(ButtonItem::Control, Qt::blue, QIcon(":/data/action-snapshot.png"), this);
    bStill->setToolTip(tr("Still picture"));
    connect(bStill, SIGNAL(clicked()), this, SLOT(slotToggleStill()));
    addButtonItem(bStill);

    // start the video flow
    VideoProvider::instance()->connectInput(input, this, SLOT(setPixmap(const QPixmap &)));
}
Beispiel #5
0
bool AbstractContent::fromXml(QDomElement & pe)
{
    // restore content properties
    QDomElement domElement;

    // Load image size saved in the rect node
    domElement = pe.firstChildElement("rect");
    qreal x, y, w, h;
    x = domElement.firstChildElement("x").text().toDouble();
    y = domElement.firstChildElement("y").text().toDouble();
    w = domElement.firstChildElement("w").text().toDouble();
    h = domElement.firstChildElement("h").text().toDouble();
    resizeContents(QRect(x, y, w, h));

    // Load position coordinates
    domElement = pe.firstChildElement("pos");
    x = domElement.firstChildElement("x").text().toDouble();
    y = domElement.firstChildElement("y").text().toDouble();
    setPos(x, y);

    int zvalue = pe.firstChildElement("zvalue").text().toDouble();
    setZValue(zvalue);

    bool visible = pe.firstChildElement("visible").text().toInt();
    setVisible(visible);

    bool hasText = pe.firstChildElement("frame-text-enabled").text().toInt();
    setFrameTextEnabled(hasText);
    if (hasText) {
        QString text = pe.firstChildElement("frame-text").text();
        setFrameText(text);
    }

    quint32 frameClass = pe.firstChildElement("frame-class").text().toInt();
    setFrame(frameClass ? FrameFactory::createFrame(frameClass) : 0);

    // restore transformation
    QDomElement te = pe.firstChildElement("transformation");
    if (!te.isNull()) {
        m_xRotationAngle = te.attribute("xRot").toDouble();
        m_yRotationAngle = te.attribute("yRot").toDouble();
        m_zRotationAngle = te.attribute("zRot").toDouble();
        applyRotations();
    }
    domElement = pe.firstChildElement("mirror");
    setMirrorEnabled(domElement.attribute("state").toInt());

    return true;
}
Beispiel #6
0
SimpleTextContent::SimpleTextContent(QGraphicsScene * scene, QGraphicsItem * parent)
    : AbstractContent(scene, parent, false)
    , m_text("")
    , m_textRect(0, 0, 0, 0)
    , m_textMargin(4)
{
	m_dontSyncToModel = true;
	
	setFrame(0);
	setFrameTextEnabled(false);
	setToolTip(tr("Right click to Edit the text"));
	
	setText("Welcome");
	
	m_dontSyncToModel = false;
}
Beispiel #7
0
bool PictureContent::loadFromNetwork(const QString & url, QNetworkReply * reply, const QString & title, int width, int height)
{
    dropNetworkConnection();
    delete m_photo;
    m_cachedPhoto = QPixmap();
    m_opaquePhoto = false;
    m_photo = 0;
    m_fileUrl = url;
    m_netWidth = width;
    m_netHeight = height;

    // start a download if not passed as a paramenter
    if (!reply) {
        // the QNAM will be auto-deleted on closure
        QNetworkAccessManager * nam = new QNetworkAccessManager(this);
        QNetworkRequest request(url);
        m_netReply = nam->get(request);
    } else
        m_netReply = reply;

    // set title
    if (!title.isEmpty()) {
        setFrameTextEnabled(true);
        setFrameText(title);
    }

#if QT_VERSION >= 0x040600
    // Immediate Decode: just handle the reply if done
    if (m_netReply->isFinished())
        return slotLoadNetworkData();
#else
    // No Precaching ensures signals to be emitted later
#endif

    // Deferred Decode: listen to the network job
    setAcceptHoverEvents(false);
    setControlsVisible(false);
    m_progress = 0.01;
    connect(m_netReply, SIGNAL(finished()), this, SLOT(slotLoadNetworkData()));
    connect(m_netReply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(slotNetworkError()));
    connect(m_netReply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(slotNetworkProgress(qint64,qint64)));

    // reset size, if got the network one
    if (m_netWidth > 0 && m_netHeight > 0)
        resetContentsRatio();
    return true;
}
Beispiel #8
0
TextBoxContent::TextBoxContent(QGraphicsScene * scene, QGraphicsItem * parent)
    : AbstractContent(scene, parent, false)
    , m_text(0)
    , m_shadowText(0)
    , m_textRect(0, 0, 0, 0)
    , m_textMargin(4)
    , m_lastModelRev(0)
{
	DEBUG_TSTART();
	m_dontSyncToModel = true;

	setFrame(0);
	setFrameTextEnabled(false);
	setToolTip(tr("Right click to Edit the text"));
	// create a text document
	m_text = new QTextDocument(this);
	// for drawing the shadow
	m_shadowText = new QTextDocument(this);

	#if QT_VERSION >= 0x040500
		m_textMargin = (int)m_text->documentMargin();
	#endif
	// template text
	QFont font;
	#ifdef Q_OS_WIN
		font.setFamily("Arial");
	#endif
	font.setPointSize(16);
	m_text->setDefaultFont(font);

	//connect(this, SIGNAL(resized()), this, SLOT(delayContentsResized()));
	for(int i=0;i<m_cornerItems.size();i++)
		m_cornerItems.at(i)->setDefaultLeftOp(CornerItem::Scale);

	m_zoomAnimationTimer = new QTimer(this);
	connect(m_zoomAnimationTimer, SIGNAL(timeout()), this, SLOT(animateZoom()));
	
	m_dontSyncToModel = false;
	
	//qDebug() << "TextBoxContent(): \t \t Elapsed:"<<(((double)total.elapsed())/1000.0)<<" sec";
}
Beispiel #9
0
PictureContent::PictureContent(bool spontaneous, QGraphicsScene * scene, QGraphicsItem * parent)
    : AbstractContent(scene, spontaneous, false, parent)
    , m_photo(0)
    , m_opaquePhoto(false)
    , m_progress(0)
    , m_netWidth(0)
    , m_netHeight(0)
    , m_netReply(0)
    , m_watcher(0)
    , m_watcherTimer(0)
{
    // enable frame text
    setFrameTextEnabled(true);
    setFrameText(tr("..."));

    // allow dropping
    setAcceptDrops(true);

    // add flipping buttons
    ButtonItem * bFlipH = new ButtonItem(ButtonItem::FlipH, Qt::blue, QIcon(":/data/action-flip-horizontal.png"), this);
    bFlipH->setToolTip(tr("Flip horizontally"));
    bFlipH->setFlag(QGraphicsItem::ItemIgnoresTransformations, false);
    connect(bFlipH, SIGNAL(clicked()), this, SIGNAL(flipHorizontally()));
    addButtonItem(bFlipH);

    ButtonItem * bFlipV = new ButtonItem(ButtonItem::FlipV, Qt::blue, QIcon(":/data/action-flip-vertical.png"), this);
    bFlipV->setToolTip(tr("Flip vertically"));
    bFlipV->setFlag(QGraphicsItem::ItemIgnoresTransformations, false);
    addButtonItem(bFlipV);
    connect(bFlipV, SIGNAL(clicked()), this, SIGNAL(flipVertically()));

#if 0
    // add cropping button (TODO: enable this?)
    ButtonItem * bCrop = new ButtonItem(ButtonItem::Control, Qt::blue, QIcon(":/data/action-scale.png"), this);
    bCrop->setToolTip(tr(""));
    bCrop->setFlag(QGraphicsItem::ItemIgnoresTransformations, false);
    addButtonItem(bCrop);
    connect(bCrop, SIGNAL(clicked()), this, SIGNAL(requestCrop()));
#endif
}
Beispiel #10
0
TextContent::TextContent(QGraphicsScene * scene, QGraphicsItem * parent)
    : AbstractContent(scene, parent, false)
    , m_text(0)
{
    setFrame(0);
    setFrameTextEnabled(false);
    setToolTip(tr("Right click to Edit the text"));

    // create a text document
    m_text = new QTextDocument(this);
    QAbstractTextDocumentLayout * layout = m_text->documentLayout();
    connect(layout, SIGNAL(documentSizeChanged(const QSizeF &)), this, SLOT(slotTextResized(const QSizeF &)));

    // template text
    QFont font;
#ifdef Q_OS_WIN
    font.setFamily("Arial");
#endif
    font.setPointSize(16);
    m_text->setDefaultFont(font);
    m_text->setPlainText(tr("insert text here..."));
}
Beispiel #11
0
bool PictureContent::loadPixmap(const QPixmap & pixmap, const QString & title)
{
    dropNetworkConnection();
    delete m_photo;
    m_cachedPhoto = QPixmap();
    m_opaquePhoto = false;
    m_photo = 0;
    m_fileUrl = QString();
    m_netWidth = 0;
    m_netHeight = 0;

    m_photo = new CPixmap(pixmap.toImage());
    m_opaquePhoto = !pixmap.hasAlpha();
    m_fileUrl = QString("data:/");
    resetContentsRatio();
    setFrameTextEnabled(!title.isEmpty());
    setFrameText(title);
    applyPostLoadEffects();

    // notify image change
    emit contentChanged();
    return true;
}