From: Jean-Baptiste Mardelle Date: Sat, 5 Apr 2008 21:45:15 +0000 (+0000) Subject: Title widget improvements: X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=e44ebbaee1314e4088b03169273f66848c7795d7;p=kdenlive Title widget improvements: * redesign widget ui * fix load/save problems * initial support for title pixmap creation svn path=/branches/KDE4/; revision=2156 --- diff --git a/src/graphicsscenerectmove.cpp b/src/graphicsscenerectmove.cpp index 0f425d1f..d7e2fb41 100644 --- a/src/graphicsscenerectmove.cpp +++ b/src/graphicsscenerectmove.cpp @@ -6,17 +6,39 @@ #include #include #include +#include #include "graphicsscenerectmove.h" -GraphicsSceneRectMove::GraphicsSceneRectMove(QObject *parent): QGraphicsScene(parent), m_selectedItem(NULL), resizeMode(NoResize) { +GraphicsSceneRectMove::GraphicsSceneRectMove(QObject *parent): QGraphicsScene(parent), m_selectedItem(NULL), resizeMode(NoResize), m_tool(TITLE_RECTANGLE) { //grabMouse(); zoom = 1.0; + setBackgroundBrush(QBrush(QColor(0, 0, 0, 0))); } void GraphicsSceneRectMove::setSelectedItem(QGraphicsItem *item) { + clearSelection(); m_selectedItem = item; item->setSelected(true); + update(); +} + +TITLETOOL GraphicsSceneRectMove::tool() { + return m_tool; +} + +void GraphicsSceneRectMove::setTool(TITLETOOL tool) { + m_tool = tool; + switch (m_tool) { + case TITLE_RECTANGLE: + setCursor(Qt::CrossCursor); + break; + case TITLE_TEXT: + setCursor(Qt::IBeamCursor); + break; + default: + setCursor(Qt::ArrowCursor); + } } //virtual @@ -30,20 +52,28 @@ void GraphicsSceneRectMove::keyPressEvent(QKeyEvent * keyEvent) { switch (keyEvent->key()) { case Qt::Key_Left: m_selectedItem->setPos(m_selectedItem->pos() - QPointF(diff, 0)); + emit itemMoved(); break; case Qt::Key_Right: m_selectedItem->setPos(m_selectedItem->pos() + QPointF(diff, 0)); + emit itemMoved(); break; case Qt::Key_Up: m_selectedItem->setPos(m_selectedItem->pos() - QPointF(0, diff)); + emit itemMoved(); break; case Qt::Key_Down: m_selectedItem->setPos(m_selectedItem->pos() + QPointF(0, diff)); + emit itemMoved(); + break; + case Qt::Key_Delete: + case Qt::Key_Backspace: + delete m_selectedItem; + emit selectionChanged(); break; default: QGraphicsScene::keyPressEvent(keyEvent); } - emit itemMoved(); } //virtual @@ -62,6 +92,12 @@ void GraphicsSceneRectMove::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* e) { QGraphicsScene::mouseDoubleClickEvent(e); } +void GraphicsSceneRectMove::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) { + if (m_tool == TITLE_RECTANGLE && m_selectedItem) setSelectedItem(m_selectedItem); + emit actionFinished(); + QGraphicsScene::mouseReleaseEvent(e); +} + void GraphicsSceneRectMove::mousePressEvent(QGraphicsSceneMouseEvent* e) { QPointF p = e->scenePos(); p += QPoint(-2, -2); @@ -69,72 +105,83 @@ void GraphicsSceneRectMove::mousePressEvent(QGraphicsSceneMouseEvent* e) { QList list = items(QRectF(p , QSizeF(4, 4)).toRect()); QGraphicsItem *item = NULL; bool hasSelected = false; - foreach(QGraphicsItem* g, list) { - // check is there is a selected item in list - if (g->zValue() > -1000 && g->isSelected()) { - hasSelected = true; - item = g; - break; - } - } - if (item == NULL) { - if (m_selectedItem && m_selectedItem->type() == 8) { - // disable text editing - QGraphicsTextItem *t = static_cast(m_selectedItem); - t->setTextInteractionFlags(Qt::NoTextInteraction); - } - m_selectedItem = NULL; + + if (m_tool == TITLE_SELECT) { foreach(QGraphicsItem* g, list) { - if (g->zValue() > -1000) { + kDebug() << " - - CHECKING ITEM Z:" << g->zValue() << ", TYPE: " << g->type(); + // check is there is a selected item in list + if (g->zValue() > -1000 && g->isSelected()) { + hasSelected = true; item = g; break; } } - } - if (item != NULL) { - m_clickPoint = e->scenePos(); - m_selectedItem = item; - if (item->type() == 8) { - QGraphicsTextItem *t = static_cast(item); - if (t->textInteractionFlags() == Qt::TextEditorInteraction) { - QGraphicsScene::mousePressEvent(e); - return; + if (item == NULL) { + if (m_selectedItem && m_selectedItem->type() == 8) { + // disable text editing + QGraphicsTextItem *t = static_cast(m_selectedItem); + t->setTextInteractionFlags(Qt::NoTextInteraction); } - t->setTextInteractionFlags(Qt::NoTextInteraction); - } else if (item->type() == 3) { - QGraphicsRectItem *gi = (QGraphicsRectItem*)item; - QRectF r = gi->rect(); - r.translate(gi->scenePos()); - if ((r.toRect().topLeft() - e->scenePos().toPoint()).manhattanLength() < 6 / zoom) { - resizeMode = TopLeft; - } else if ((r.toRect().bottomLeft() - e->scenePos().toPoint()).manhattanLength() < 6 / zoom) { - resizeMode = BottomLeft; - } else if ((r.toRect().topRight() - e->scenePos().toPoint()).manhattanLength() < 6 / zoom) { - resizeMode = TopRight; - } else if ((r.toRect().bottomRight() - e->scenePos().toPoint()).manhattanLength() < 6 / zoom) { - resizeMode = BottomRight; - } else if (qAbs(r.toRect().left() - e->scenePos().toPoint().x()) < 3 / zoom) { - resizeMode = Left; - } else if (qAbs(r.toRect().right() - e->scenePos().toPoint().x()) < 3 / zoom) { - resizeMode = Right; - } else if (qAbs(r.toRect().top() - e->scenePos().toPoint().y()) < 3 / zoom) { - resizeMode = Up; - } else if (qAbs(r.toRect().bottom() - e->scenePos().toPoint().y()) < 3 / zoom) { - resizeMode = Down; + m_selectedItem = NULL; + foreach(QGraphicsItem* g, list) { + if (g->zValue() > -1000) { + item = g; + break; + } } } + if (item != NULL) { + m_clickPoint = e->scenePos(); + m_selectedItem = item; + kDebug() << "///////// ITEM TYPE: " << item->type(); + if (item->type() == 8) { + QGraphicsTextItem *t = static_cast(item); + if (t->textInteractionFlags() == Qt::TextEditorInteraction) { + QGraphicsScene::mousePressEvent(e); + return; + } + t->setTextInteractionFlags(Qt::NoTextInteraction); + setCursor(Qt::ClosedHandCursor); + } else if (item->type() == 3) { + QGraphicsRectItem *gi = (QGraphicsRectItem*)item; + QRectF r = gi->rect(); + r.translate(gi->scenePos()); + if ((r.toRect().topLeft() - e->scenePos().toPoint()).manhattanLength() < 6 / zoom) { + resizeMode = TopLeft; + } else if ((r.toRect().bottomLeft() - e->scenePos().toPoint()).manhattanLength() < 6 / zoom) { + resizeMode = BottomLeft; + } else if ((r.toRect().topRight() - e->scenePos().toPoint()).manhattanLength() < 6 / zoom) { + resizeMode = TopRight; + } else if ((r.toRect().bottomRight() - e->scenePos().toPoint()).manhattanLength() < 6 / zoom) { + resizeMode = BottomRight; + } else if (qAbs(r.toRect().left() - e->scenePos().toPoint().x()) < 3 / zoom) { + resizeMode = Left; + } else if (qAbs(r.toRect().right() - e->scenePos().toPoint().x()) < 3 / zoom) { + resizeMode = Right; + } else if (qAbs(r.toRect().top() - e->scenePos().toPoint().y()) < 3 / zoom) { + resizeMode = Up; + } else if (qAbs(r.toRect().bottom() - e->scenePos().toPoint().y()) < 3 / zoom) { + resizeMode = Down; + } else setCursor(Qt::ClosedHandCursor); + } + } + QGraphicsScene::mousePressEvent(e); + } else if (m_tool == TITLE_RECTANGLE) { + m_clickPoint = e->scenePos(); + m_selectedItem = NULL; + } else if (m_tool == TITLE_TEXT) { + m_selectedItem = addText(QString()); + emit newText((QGraphicsTextItem *) m_selectedItem); + m_selectedItem->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); + ((QGraphicsTextItem *)m_selectedItem)->setTextInteractionFlags(Qt::TextEditorInteraction); + m_selectedItem->setPos(e->scenePos()); + QGraphicsScene::mousePressEvent(e); } - QGraphicsScene::mousePressEvent(e); kDebug() << "////// MOUSE CLICK, RESIZE MODE: " << resizeMode; } -//virtual -void GraphicsSceneRectMove::mouseReleaseEvent(QGraphicsSceneMouseEvent* e) { - //m_selectedItem = NULL; -} - //virtual void GraphicsSceneRectMove::mouseMoveEvent(QGraphicsSceneMouseEvent* e) { @@ -198,14 +245,14 @@ void GraphicsSceneRectMove::mouseMoveEvent(QGraphicsSceneMouseEvent* e) { m_selectedItem->moveBy(diff.x(), diff.y()); } emit itemMoved(); - } else { + } else if (m_tool == TITLE_SELECT) { QPointF p = e->scenePos(); p += QPoint(-2, -2); resizeMode = NoResize; bool itemFound = false; foreach(QGraphicsItem* g, items(QRectF(p , QSizeF(4, 4)).toRect())) { - if (g->type() == 3) { + if (g->type() == 3 && g->zValue() > -1000) { QGraphicsRectItem *gi = (QGraphicsRectItem*)g; QRectF r = gi->rect(); r.translate(gi->scenePos()); @@ -226,12 +273,22 @@ void GraphicsSceneRectMove::mouseMoveEvent(QGraphicsSceneMouseEvent* e) { setCursor(Qt::SizeVerCursor); } else if (qAbs(r.toRect().bottom() - e->scenePos().toPoint().y()) < 3 / zoom) { setCursor(Qt::SizeVerCursor); - } else setCursor(QCursor(Qt::ArrowCursor)); + } else setCursor(Qt::OpenHandCursor); break; } - if (!itemFound) setCursor(QCursor(Qt::ArrowCursor)); + if (!itemFound) setCursor(Qt::ArrowCursor); } QGraphicsScene::mouseMoveEvent(e); + } else if (m_tool == TITLE_RECTANGLE && e->buttons() & Qt::LeftButton) { + if (m_selectedItem == NULL && (m_clickPoint.toPoint() - e->scenePos().toPoint()).manhattanLength() >= QApplication::startDragDistance()) { + // create new rect item + m_selectedItem = addRect(0, 0, e->scenePos().x() - m_clickPoint.x(), e->scenePos().y() - m_clickPoint.y()); + emit newRect((QGraphicsRectItem *) m_selectedItem); + m_selectedItem->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); + m_selectedItem->setPos(m_clickPoint); + resizeMode = BottomRight; + QGraphicsScene::mouseMoveEvent(e); + } } } diff --git a/src/graphicsscenerectmove.h b/src/graphicsscenerectmove.h index 6549a8b1..09170243 100644 --- a/src/graphicsscenerectmove.h +++ b/src/graphicsscenerectmove.h @@ -4,6 +4,7 @@ #include enum resizeModes {NoResize, TopLeft, BottomLeft, TopRight, BottomRight, Left, Right, Up, Down}; +enum TITLETOOL { TITLE_SELECT = 0, TITLE_RECTANGLE = 1, TITLE_TEXT = 2, TITLE_IMAGE = 3 }; class GraphicsSceneRectMove: public QGraphicsScene { Q_OBJECT @@ -13,13 +14,15 @@ public: void setSelectedItem(QGraphicsItem *item); void setScale(double s); void setZoom(double s); + void setTool(TITLETOOL tool); + TITLETOOL tool(); protected: virtual void keyPressEvent(QKeyEvent * keyEvent); virtual void mousePressEvent(QGraphicsSceneMouseEvent*); + virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent*); virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent* e); virtual void mouseMoveEvent(QGraphicsSceneMouseEvent*); - virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent*); virtual void wheelEvent(QGraphicsSceneWheelEvent * wheelEvent); private: @@ -28,10 +31,14 @@ private: QGraphicsItem* m_selectedItem; resizeModes resizeMode; QPointF m_clickPoint; + TITLETOOL m_tool; signals: void itemMoved(); void sceneZoom(bool); + void newRect(QGraphicsRectItem *); + void newText(QGraphicsTextItem *); + void actionFinished(); }; #endif diff --git a/src/kdenlivedoc.cpp b/src/kdenlivedoc.cpp index 69250019..0d7fd96c 100644 --- a/src/kdenlivedoc.cpp +++ b/src/kdenlivedoc.cpp @@ -371,6 +371,9 @@ void KdenliveDoc::slotAddColorClipFile(const QString name, const QString color, void KdenliveDoc::slotCreateTextClip(QString group, int groupId) { TitleWidget *dia_ui = new TitleWidget(m_render, 0); if (dia_ui->exec() == QDialog::Accepted) { + QPixmap p = dia_ui->renderedPixmap(); + p.save("/tmp/kdenlivetitle.png"); + slotAddClipFile(KUrl("/tmp/kdenlivetitle.png"), QString(), -1); } delete dia_ui; } diff --git a/src/titledocument.cpp b/src/titledocument.cpp index c334b715..ca30117b 100644 --- a/src/titledocument.cpp +++ b/src/titledocument.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include TitleDocument::TitleDocument() { @@ -45,6 +46,8 @@ bool TitleDocument::saveDocument(const KUrl& url, QGraphicsPolygonItem* startv, foreach(QGraphicsItem* item, scene->items()) { QDomElement e = doc.createElement("item"); QDomElement content = doc.createElement("content"); + QFont font; + QGraphicsTextItem *t; switch (item->type()) { case 3: @@ -56,7 +59,16 @@ bool TitleDocument::saveDocument(const KUrl& url, QGraphicsPolygonItem* startv, break; case 8: e.setAttribute("type", "QGraphicsTextItem"); - content.appendChild(doc.createTextNode(((QGraphicsTextItem*)item)->toHtml())); + t = static_cast(item); + //content.appendChild(doc.createTextNode(((QGraphicsTextItem*)item)->toHtml())); + content.appendChild(doc.createTextNode(t->toPlainText())); + font = t->font(); + e.setAttribute("font", font.family()); + e.setAttribute("font-bold", font.bold()); + e.setAttribute("font-size", font.pointSize()); + e.setAttribute("font-italic", font.italic()); + e.setAttribute("font-underline", font.underline()); + e.setAttribute("font-color", colorToString(t->defaultTextColor())); break; default: continue; @@ -77,7 +89,7 @@ bool TitleDocument::saveDocument(const KUrl& url, QGraphicsPolygonItem* startv, e.appendChild(pos); e.appendChild(content); - main.appendChild(e); + if (item->zValue() > -1100) main.appendChild(e); } if (startv && endv) { QDomElement endp = doc.createElement("endviewport"); @@ -96,23 +108,34 @@ bool TitleDocument::saveDocument(const KUrl& url, QGraphicsPolygonItem* startv, main.appendChild(endp); } QDomElement backgr = doc.createElement("background"); - backgr.setAttribute("color", colorToString(scene->backgroundBrush().color())); + QList items = scene->items(); + QColor color(0, 0, 0, 0); + for (int i = 0; i < items.size(); i++) { + if (items.at(i)->zValue() == -1100) { + color = ((QGraphicsRectItem *)items.at(i))->brush().color(); + break; + } + } + backgr.setAttribute("color", colorToString(color)); main.appendChild(backgr); - QString tmpfile = "/tmp/newtitle"; - QFile xmlf(tmpfile); + KTemporaryFile tmpfile; + if (!tmpfile.open()) kWarning() << "///// CANNOT CREATE TMP FILE in: " << tmpfile.fileName(); + QFile xmlf(tmpfile.fileName()); xmlf.open(QIODevice::WriteOnly); xmlf.write(doc.toString().toAscii()); xmlf.close(); - kDebug() << KIO::NetAccess::upload(tmpfile, url, 0); + kDebug() << KIO::NetAccess::upload(tmpfile.fileName(), url, 0); + } -bool TitleDocument::loadDocument(const KUrl& url , QGraphicsPolygonItem* startv, QGraphicsPolygonItem* endv) { +int TitleDocument::loadDocument(const KUrl& url , QGraphicsPolygonItem* startv, QGraphicsPolygonItem* endv) { QString tmpfile; QDomDocument doc; + int maxZValue = 0; double aspect_ratio = 4.0 / 3.0; if (!scene) - return false; + return -1; if (KIO::NetAccess::download(url, tmpfile, 0)) { QFile file(tmpfile); @@ -120,7 +143,7 @@ bool TitleDocument::loadDocument(const KUrl& url , QGraphicsPolygonItem* startv, doc.setContent(&file, false); file.close(); } else - return false; + return -1; KIO::NetAccess::removeTempFile(tmpfile); QDomNodeList titles = doc.elementsByTagName("kdenlivetitle"); if (titles.size()) { @@ -129,30 +152,51 @@ bool TitleDocument::loadDocument(const KUrl& url , QGraphicsPolygonItem* startv, for (int i = 0;i < items.count();i++) { QGraphicsItem *gitem = NULL; kDebug() << items.item(i).attributes().namedItem("type").nodeValue(); - if (items.item(i).attributes().namedItem("type").nodeValue() == "QGraphicsTextItem") { - QGraphicsTextItem *txt = scene->addText(""); - txt->setHtml(items.item(i).namedItem("content").firstChild().nodeValue()); - gitem = txt; - } else - if (items.item(i).attributes().namedItem("type").nodeValue() == "QGraphicsRectItem") { - QString rect = items.item(i).namedItem("content").attributes().namedItem("rect").nodeValue(); - QString br_str = items.item(i).namedItem("content").attributes().namedItem("brushcolor").nodeValue(); - QString pen_str = items.item(i).namedItem("content").attributes().namedItem("pencolor").nodeValue(); - double penwidth = items.item(i).namedItem("content").attributes().namedItem("penwidth").nodeValue().toDouble(); - QGraphicsRectItem *rec = scene->addRect(stringToRect(rect), QPen(QBrush(stringToColor(pen_str)), penwidth), QBrush(stringToColor(br_str))); - gitem = rec; - } + int zValue = items.item(i).attributes().namedItem("z-index").nodeValue().toInt(); + if (zValue > -1000) + if (items.item(i).attributes().namedItem("type").nodeValue() == "QGraphicsTextItem") { + QFont font(items.item(i).attributes().namedItem("font").nodeValue()); + font.setBold(items.item(i).attributes().namedItem("font-bold").nodeValue().toInt()); + font.setItalic(items.item(i).attributes().namedItem("font-italic").nodeValue().toInt()); + font.setUnderline(items.item(i).attributes().namedItem("font-underline").nodeValue().toInt()); + font.setPointSize(items.item(i).attributes().namedItem("font-size").nodeValue().toInt()); + QColor col(stringToColor(items.item(i).attributes().namedItem("font-color").nodeValue())); + QGraphicsTextItem *txt = scene->addText(items.item(i).namedItem("content").firstChild().nodeValue(), font); + txt->setDefaultTextColor(col); + txt->setTextInteractionFlags(Qt::NoTextInteraction); + gitem = txt; + } else + if (items.item(i).attributes().namedItem("type").nodeValue() == "QGraphicsRectItem") { + QString rect = items.item(i).namedItem("content").attributes().namedItem("rect").nodeValue(); + QString br_str = items.item(i).namedItem("content").attributes().namedItem("brushcolor").nodeValue(); + QString pen_str = items.item(i).namedItem("content").attributes().namedItem("pencolor").nodeValue(); + double penwidth = items.item(i).namedItem("content").attributes().namedItem("penwidth").nodeValue().toDouble(); + QGraphicsRectItem *rec = scene->addRect(stringToRect(rect), QPen(QBrush(stringToColor(pen_str)), penwidth), QBrush(stringToColor(br_str))); + gitem = rec; + } //pos and transform if (gitem) { QPointF p(items.item(i).namedItem("position").attributes().namedItem("x").nodeValue().toDouble(), items.item(i).namedItem("position").attributes().namedItem("y").nodeValue().toDouble()); gitem->setPos(p); gitem->setTransform(stringToTransform(items.item(i).namedItem("position").firstChild().firstChild().nodeValue())); + int zValue = items.item(i).attributes().namedItem("z-index").nodeValue().toInt(); + if (zValue > maxZValue) maxZValue = zValue; + gitem->setZValue(zValue); + gitem->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); } if (items.item(i).nodeName() == "background") { kDebug() << items.item(i).attributes().namedItem("color").nodeValue(); - scene->setBackgroundBrush(QBrush(stringToColor(items.item(i).attributes().namedItem("color").nodeValue()))); - } else if (items.item(i).nodeName() == "startviewport" && startv) { + QColor color = QColor(stringToColor(items.item(i).attributes().namedItem("color").nodeValue())); + //color.setAlpha(items.item(i).attributes().namedItem("alpha").nodeValue().toInt()); + QList items = scene->items(); + for (int i = 0; i < items.size(); i++) { + if (items.at(i)->zValue() == -1100) { + ((QGraphicsRectItem *)items.at(i))->setBrush(QBrush(color)); + break; + } + } + } /*else if (items.item(i).nodeName() == "startviewport" && startv) { QPointF p(items.item(i).attributes().namedItem("x").nodeValue().toDouble(), items.item(i).attributes().namedItem("y").nodeValue().toDouble()); double width = items.item(i).attributes().namedItem("size").nodeValue().toDouble(); QRectF rect(-width, -width / aspect_ratio, width*2.0, width / aspect_ratio*2.0); @@ -166,16 +210,11 @@ bool TitleDocument::loadDocument(const KUrl& url , QGraphicsPolygonItem* startv, kDebug() << width << rect; endv->setPolygon(rect); endv->setPos(p); - } - + }*/ } - - } - - } - return true; + return maxZValue; } QString TitleDocument::colorToString(const QColor& c) { diff --git a/src/titledocument.h b/src/titledocument.h index fab51a5e..5fcc3d03 100644 --- a/src/titledocument.h +++ b/src/titledocument.h @@ -27,7 +27,7 @@ public: TitleDocument(); void setScene(QGraphicsScene* scene); bool saveDocument(const KUrl& url, QGraphicsPolygonItem* startv, QGraphicsPolygonItem* endv); - bool loadDocument(const KUrl& url, QGraphicsPolygonItem* startv, QGraphicsPolygonItem* endv); + int loadDocument(const KUrl& url, QGraphicsPolygonItem* startv, QGraphicsPolygonItem* endv); private: QString colorToString(const QColor&); QString rectFToString(const QRectF&); diff --git a/src/titlewidget.cpp b/src/titlewidget.cpp index 4a71f114..918ff2c1 100644 --- a/src/titlewidget.cpp +++ b/src/titlewidget.cpp @@ -35,19 +35,20 @@ int settingUp = false; TitleWidget::TitleWidget(Render *render, QWidget *parent): QDialog(parent), m_frameImage(NULL), m_render(render), m_count(0) { setupUi(this); - frame_properties->setFont(KGlobalSettings::toolBarFont()); - toolBox->setFont(KGlobalSettings::toolBarFont()); + //frame_properties-> + setFont(KGlobalSettings::toolBarFont()); + //toolBox->setFont(KGlobalSettings::toolBarFont()); frame_properties->setEnabled(false); - connect(newTextButton, SIGNAL(clicked()), this, SLOT(slotNewText())); - connect(newRectButton, SIGNAL(clicked()), this, SLOT(slotNewRect())); + //connect(newTextButton, SIGNAL(clicked()), this, SLOT(slotNewText())); + //connect(newRectButton, SIGNAL(clicked()), this, SLOT(slotNewRect())); connect(kcolorbutton, SIGNAL(clicked()), this, SLOT(slotChangeBackground())) ; connect(horizontalSlider, SIGNAL(valueChanged(int)), this, SLOT(slotChangeBackground())) ; - connect(ktextedit, SIGNAL(textChanged()), this , SLOT(textChanged())); + //connect(ktextedit, SIGNAL(textChanged()), this , SLOT(textChanged())); //connect (fontBold, SIGNAL ( clicked()), this, SLOT( setBold()) ) ; - connect(loadButton, SIGNAL(clicked()), this, SLOT(loadTitle())) ; - connect(saveButton, SIGNAL(clicked()), this, SLOT(saveTitle())) ; + connect(buttonLoad, SIGNAL(clicked()), this, SLOT(loadTitle())) ; + connect(buttonSave, SIGNAL(clicked()), this, SLOT(saveTitle())) ; - ktextedit->setHidden(true); + //ktextedit->setHidden(true); connect(fontColorButton, SIGNAL(clicked()), this, SLOT(slotUpdateText())) ; connect(font_family, SIGNAL(currentFontChanged(const QFont &)), this, SLOT(slotUpdateText())) ; connect(font_size, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateText())) ; @@ -89,6 +90,20 @@ TitleWidget::TitleWidget(Render *render, QWidget *parent): QDialog(parent), m_fr buttonItalic->setIcon(KIcon("format-text-italic")); buttonUnder->setIcon(KIcon("format-text-underline")); + buttonRect->setIcon(KIcon("insert-rect")); + buttonText->setIcon(KIcon("insert-text")); + buttonImage->setIcon(KIcon("insert-image")); + buttonCursor->setIcon(KIcon("select-rectangular")); + buttonSave->setIcon(KIcon("document-save")); + buttonLoad->setIcon(KIcon("document-open")); + + connect(buttonRect, SIGNAL(clicked()), this, SLOT(slotRectTool())); + connect(buttonText, SIGNAL(clicked()), this, SLOT(slotTextTool())); + connect(buttonImage, SIGNAL(clicked()), this, SLOT(slotImageTool())); + connect(buttonCursor, SIGNAL(clicked()), this, SLOT(slotSelectTool())); + + text_properties->setHidden(true); + m_scene = new GraphicsSceneRectMove(this); // a gradient background @@ -96,31 +111,33 @@ TitleWidget::TitleWidget(Render *render, QWidget *parent): QDialog(parent), m_fr gradient->setSpread(QGradient::ReflectSpread); //scene->setBackgroundBrush(*gradient); - - graphicsView->setScene(m_scene); - m_titledocument.setScene(m_scene); - connect(graphicsView->scene(), SIGNAL(selectionChanged()), this , SLOT(selectionChanged())); + connect(m_scene, SIGNAL(selectionChanged()), this , SLOT(selectionChanged())); connect(m_scene, SIGNAL(itemMoved()), this , SLOT(selectionChanged())); connect(m_scene, SIGNAL(sceneZoom(bool)), this , SLOT(slotZoom(bool))); + connect(m_scene, SIGNAL(actionFinished()), this , SLOT(slotSelectTool())); + connect(m_scene, SIGNAL(actionFinished()), this , SLOT(selectionChanged())); + connect(m_scene, SIGNAL(newRect(QGraphicsRectItem *)), this , SLOT(slotNewRect(QGraphicsRectItem *))); + connect(m_scene, SIGNAL(newText(QGraphicsTextItem *)), this , SLOT(slotNewText(QGraphicsTextItem *))); connect(zoom_slider, SIGNAL(valueChanged(int)), this , SLOT(slotUpdateZoom(int))); + graphicsView->setScene(m_scene); + m_titledocument.setScene(m_scene); QPen framepen(Qt::DotLine); framepen.setColor(Qt::red); m_frameWidth = render->renderWidth(); m_frameHeight = render->renderHeight(); - + slotRectTool(); m_frameBorder = new QGraphicsRectItem(QRectF(0, 0, m_frameWidth, m_frameHeight)); m_frameBorder->setPen(framepen); - m_frameBorder->setZValue(-1000); + m_frameBorder->setZValue(-1100); + m_frameBorder->setBrush(QColor(0, 0, 0, 0)); m_frameBorder->setFlags(QGraphicsItem::ItemClipsToShape); graphicsView->scene()->addItem(m_frameBorder); initViewports(); - - graphicsView->show(); graphicsView->setRenderHint(QPainter::Antialiasing); graphicsView->setInteractive(true); @@ -137,6 +154,32 @@ void TitleWidget::resizeEvent(QResizeEvent * event) { //slotAdjustZoom(); } +void TitleWidget::slotTextTool() { + rect_properties->setHidden(true); + text_properties->setHidden(false); + m_scene->setTool(TITLE_TEXT); + buttonRect->setChecked(false); + buttonCursor->setChecked(false); + buttonImage->setChecked(false); +} + +void TitleWidget::slotRectTool() { + rect_properties->setHidden(false); + text_properties->setHidden(true); + m_scene->setTool(TITLE_RECTANGLE); + buttonText->setChecked(false); + buttonCursor->setChecked(false); + buttonImage->setChecked(false); +} + +void TitleWidget::slotSelectTool() { + m_scene->setTool(TITLE_SELECT); + buttonCursor->setChecked(true); + buttonText->setChecked(false); + buttonRect->setChecked(false); + buttonImage->setChecked(false); +} + void TitleWidget::displayBackgroundFrame() { if (m_frameImage) delete m_frameImage; m_frameImage = NULL; @@ -146,7 +189,7 @@ void TitleWidget::displayBackgroundFrame() { QTransform qtrans; qtrans.scale(2.0, 2.0); m_frameImage->setTransform(qtrans); - m_frameImage->setZValue(-1100); + m_frameImage->setZValue(-1200); m_frameImage->setFlags(QGraphicsItem::ItemClipsToShape); graphicsView->scene()->addItem(m_frameImage); } @@ -202,46 +245,32 @@ void TitleWidget::slotZoomOneToOne() { graphicsView->centerOn(m_frameBorder); } -void TitleWidget::slotNewRect() { - QGraphicsRectItem * ri = graphicsView->scene()->addRect(0, 0, 100, 100); - ri->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); - ri->setPos(m_frameWidth / 2, m_frameHeight / 2); +void TitleWidget::slotNewRect(QGraphicsRectItem * rect) { QColor f = rectFColor->color(); f.setAlpha(rectFAlpha->value()); QPen penf(f); penf.setWidth(rectLineWidth->value()); - ri->setPen(penf); + rect->setPen(penf); QColor b = rectBColor->color(); b.setAlpha(rectBAlpha->value()); - ri->setBrush(QBrush(b)); - ri->setZValue(m_count++); - setCurrentItem(ri); - graphicsView->setFocus(); + rect->setBrush(QBrush(b)); + rect->setZValue(m_count++); + //setCurrentItem(rect); + //graphicsView->setFocus(); } -void TitleWidget::slotNewText() { - QGraphicsTextItem *tt = graphicsView->scene()->addText("Text here"); - tt->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); - tt->setTextInteractionFlags(Qt::NoTextInteraction); - tt->setPos(m_frameWidth / 2, m_frameHeight / 2); +void TitleWidget::slotNewText(QGraphicsTextItem *tt) { QFont font = font_family->currentFont(); font.setPointSize(font_size->value()); tt->setFont(font); + QColor color = fontColorButton->color(); + color.setAlpha(textAlpha->value()); + tt->setDefaultTextColor(color); tt->setZValue(m_count++); setCurrentItem(tt); - graphicsView->setFocus(); - //connect(tt->document(), SIGNAL(contentsChanged()), this, SLOT(selectionChanged())); - kDebug() << tt->metaObject()->className(); - /*QGraphicsRectItem * ri=graphicsView->scene()->addRect(-50,-50,100,100); - ri->setFlags(QGraphicsItem::ItemIsMovable|QGraphicsItem::ItemIsSelectable);*/ - } void TitleWidget::setCurrentItem(QGraphicsItem *item) { - QList l = graphicsView->scene()->selectedItems(); - if (l.size() >= 1) { - l[0]->setSelected(false); - } m_scene->setSelectedItem(item); } @@ -253,21 +282,31 @@ void TitleWidget::zIndexChanged(int v) { } void TitleWidget::selectionChanged() { + if (m_scene->tool() != TITLE_SELECT) return; QList l = graphicsView->scene()->selectedItems(); - toolBox->setItemEnabled(2, false); - toolBox->setItemEnabled(3, false); + //toolBox->setItemEnabled(2, false); + //toolBox->setItemEnabled(3, false); value_x->blockSignals(true); value_y->blockSignals(true); value_w->blockSignals(true); value_h->blockSignals(true); + kDebug() << "//////// SELECTION CHANGED; ITEMS: " << l.size(); if (l.size() == 1) { if ((l[0])->type() == 8) { + rect_properties->setHidden(true); + text_properties->setHidden(false); QGraphicsTextItem* i = ((QGraphicsTextItem*)l[0]); - if (l[0]->hasFocus()) - ktextedit->setHtml(i->toHtml()); - toolBox->setCurrentIndex(2); - toolBox->setItemEnabled(2, true); - + //if (l[0]->hasFocus()) + //ktextedit->setHtml(i->toHtml()); + toolBox->setCurrentIndex(0); + //toolBox->setItemEnabled(2, true); + font_size->blockSignals(true); + font_family->blockSignals(true); + buttonBold->blockSignals(true); + buttonItalic->blockSignals(true); + buttonUnder->blockSignals(true); + fontColorButton->blockSignals(true); + textAlpha->blockSignals(true); QFont font = i->font(); font_family->setCurrentFont(font); @@ -280,6 +319,14 @@ void TitleWidget::selectionChanged() { fontColorButton->setColor(color); textAlpha->setValue(color.alpha()); + font_size->blockSignals(false); + font_family->blockSignals(false); + buttonBold->blockSignals(false); + buttonItalic->blockSignals(false); + buttonUnder->blockSignals(false); + fontColorButton->blockSignals(false); + textAlpha->blockSignals(false); + value_x->setValue((int) i->pos().x()); value_y->setValue((int) i->pos().y()); value_w->setValue((int) i->boundingRect().width()); @@ -287,34 +334,35 @@ void TitleWidget::selectionChanged() { frame_properties->setEnabled(true); value_w->setEnabled(false); value_h->setEnabled(false); - } else - if ((l[0])->type() == 3) { - settingUp = true; - QGraphicsRectItem *rec = ((QGraphicsRectItem*)l[0]); - toolBox->setCurrentIndex(3); - toolBox->setItemEnabled(3, true); - rectFAlpha->setValue(rec->pen().color().alpha()); - rectBAlpha->setValue(rec->brush().color().alpha()); - kDebug() << rec->brush().color().alpha(); - QColor fcol = rec->pen().color(); - QColor bcol = rec->brush().color(); - //fcol.setAlpha(255); - //bcol.setAlpha(255); - rectFColor->setColor(fcol); - rectBColor->setColor(bcol); - settingUp = false; - rectLineWidth->setValue(rec->pen().width()); - value_x->setValue((int) rec->pos().x()); - value_y->setValue((int) rec->pos().y()); - value_w->setValue((int) rec->rect().width()); - value_h->setValue((int) rec->rect().height()); - frame_properties->setEnabled(true); - value_w->setEnabled(true); - value_h->setEnabled(true); - } else { - //toolBox->setCurrentIndex(0); - frame_properties->setEnabled(false); - } + } else if ((l[0])->type() == 3) { + rect_properties->setHidden(false); + text_properties->setHidden(true); + settingUp = true; + QGraphicsRectItem *rec = ((QGraphicsRectItem*)l[0]); + toolBox->setCurrentIndex(0); + //toolBox->setItemEnabled(3, true); + rectFAlpha->setValue(rec->pen().color().alpha()); + rectBAlpha->setValue(rec->brush().color().alpha()); + kDebug() << rec->brush().color().alpha(); + QColor fcol = rec->pen().color(); + QColor bcol = rec->brush().color(); + //fcol.setAlpha(255); + //bcol.setAlpha(255); + rectFColor->setColor(fcol); + rectBColor->setColor(bcol); + settingUp = false; + rectLineWidth->setValue(rec->pen().width()); + value_x->setValue((int) rec->pos().x()); + value_y->setValue((int) rec->pos().y()); + value_w->setValue((int) rec->rect().width()); + value_h->setValue((int) rec->rect().height()); + frame_properties->setEnabled(true); + value_w->setEnabled(true); + value_h->setEnabled(true); + } else { + //toolBox->setCurrentIndex(0); + frame_properties->setEnabled(false); + } zValue->setValue((int)l[0]->zValue()); itemzoom->setValue((int)transformations[l[0]].scalex*100); itemrotate->setValue((int)transformations[l[0]].rotate); @@ -322,7 +370,7 @@ void TitleWidget::selectionChanged() { value_y->blockSignals(false); value_w->blockSignals(false); value_h->blockSignals(false); - } + } else frame_properties->setEnabled(false); } void TitleWidget::slotAdjustSelectedItem() { @@ -350,8 +398,8 @@ void TitleWidget::slotChangeBackground() { void TitleWidget::textChanged() { QList l = graphicsView->scene()->selectedItems(); if (l.size() == 1 && (l[0])->type() == 8 && !l[0]->hasFocus()) { - kDebug() << ktextedit->document()->toHtml(); - ((QGraphicsTextItem*)l[0])->setHtml(ktextedit->toHtml()); + //kDebug() << ktextedit->document()->toHtml(); + //((QGraphicsTextItem*)l[0])->setHtml(ktextedit->toHtml()); } } @@ -467,7 +515,14 @@ void TitleWidget::setupViewports() { void TitleWidget::loadTitle() { KUrl url = KFileDialog::getOpenUrl(KUrl(), "*.kdenlivetitle", this, tr("Save Title")); - m_titledocument.loadDocument(url, startViewport, endViewport); + if (!url.isEmpty()) { + QList items = m_scene->items(); + for (int i = 0; i < items.size(); i++) { + if (items.at(i)->zValue() > -1000) delete items.at(i); + } + m_count = m_titledocument.loadDocument(url, startViewport, endViewport) + 1; + slotSelectTool(); + } } void TitleWidget::saveTitle() { @@ -475,5 +530,27 @@ void TitleWidget::saveTitle() { m_titledocument.saveDocument(url, startViewport, endViewport); } +QPixmap TitleWidget::renderedPixmap() { + QPixmap pix(m_frameWidth, m_frameHeight); + pix.fill(Qt::transparent); + QPainter painter(&pix); + + m_scene->clearSelection(); + QPen framepen = m_frameBorder->pen(); + m_frameBorder->setPen(Qt::NoPen); + QPen startpen = startViewport->pen(); + QPen endpen = endViewport->pen(); + startViewport->setPen(Qt::NoPen); + endViewport->setPen(Qt::NoPen); + if (m_frameImage) delete m_frameImage; + m_frameImage = NULL; + m_scene->render(&painter, QRectF(), QRectF(0, 0, m_frameWidth, m_frameHeight)); + m_frameBorder->setPen(framepen); + startViewport->setPen(startpen); + endViewport->setPen(endpen); + displayBackgroundFrame(); + return pix; +} + #include "moc_titlewidget.cpp" diff --git a/src/titlewidget.h b/src/titlewidget.h index 6a1771cd..42113f38 100644 --- a/src/titlewidget.h +++ b/src/titlewidget.h @@ -28,6 +28,8 @@ #include "renderer.h" #include "graphicsscenerectmove.h" + + class Transform { public: Transform() { @@ -61,8 +63,8 @@ private: int m_count; public slots: - void slotNewText(); - void slotNewRect(); + void slotNewText(QGraphicsTextItem *tt); + void slotNewRect(QGraphicsRectItem *rect); void slotChangeBackground(); void selectionChanged(); void textChanged(); @@ -75,6 +77,7 @@ public slots: void itemRotate(int); void saveTitle(); void loadTitle(); + QPixmap renderedPixmap(); private slots: void slotAdjustSelectedItem(); @@ -85,6 +88,9 @@ private slots: void slotUpdateText(); void displayBackgroundFrame(); void setCurrentItem(QGraphicsItem *item); + void slotTextTool(); + void slotRectTool(); + void slotSelectTool(); }; diff --git a/src/widgets/titlewidget_ui.ui b/src/widgets/titlewidget_ui.ui index 41855248..06977efa 100644 --- a/src/widgets/titlewidget_ui.ui +++ b/src/widgets/titlewidget_ui.ui @@ -5,8 +5,8 @@ 0 0 - 771 - 612 + 850 + 575 @@ -18,60 +18,53 @@ Dialog - - - - - - - New Rect - - - - - - - New Text - - - - - - - Load Title - - - - - - - Save Title - - - - - - - Preview - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - + + + + + true + + + true + + + + + + + true + + + + + + + true + + + + + + + true + + + + + + + false + + + + + + + false + + - + QFrame::StyledPanel @@ -185,66 +178,207 @@ - - - - V - - - - - - - V - - - - - - - - 100 - 0 - - - - - 150 - 16777215 - - - - 1 - - - 10 - - - 2 - - - Qt::Horizontal + + + + QFrame::StyledPanel - - - - - - x1 + + QFrame::Sunken + + + + + + + Fill color + + + + + + + + + + 255 + + + 255 + + + Qt::Horizontal + + + + + + + Qt::Vertical + + + + + + + Border color + + + + + + + + + + 255 + + + 0 + + + Qt::Horizontal + + + + + + + Width + + + + + + + + + + Qt::Horizontal + + + + 241 + 28 + + + + + + + - - - - Qt::Horizontal + + + + QFrame::StyledPanel - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + QFrame::Sunken + + + + + + + + + + Width + + + + + + + 8 + + + 1000 + + + 20 + + + + + + + + 0 + 0 + + + + + + + + 255 + + + 255 + + + Qt::Horizontal + + + + + + + ... + + + true + + + false + + + + + + + ... + + + true + + + + + + + ... + + + true + + + + + + + Qt::Horizontal + + + + 52 + 20 + + + + + + + - + @@ -258,15 +392,15 @@ - 2 + 0 0 0 - 395 - 279 + 465 + 241 @@ -365,8 +499,8 @@ 0 0 - 395 - 279 + 465 + 241 @@ -408,282 +542,13 @@ - - - - 0 - 0 - 395 - 279 - - - - Text - - - - - - - - - - - - - - ... - - - true - - - false - - - - - - - ... - - - true - - - - - - - ... - - - true - - - - - - - ... - - - - - - - ... - - - - - - - ... - - - - - - - Qt::Horizontal - - - - 52 - 20 - - - - - - - - - - - - 8 - - - 1000 - - - 20 - - - - - - - - - - 255 - - - 255 - - - Qt::Horizontal - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - 0 - 0 - 395 - 279 - - - - Rectangle - - - - - - - - Border - - - - - - - - Alpha - - - - - - - Linewidth - - - - - - - 255 - - - Qt::Horizontal - - - - - - - - - - Color - - - - - - - - - - - - - - - - 0 - 0 - - - - Background - - - - - - - - Alpha: - - - - - - - Color - - - - - - - 255 - - - 255 - - - Qt::Horizontal - - - - - - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - 0 0 - 395 - 279 + 465 + 241 @@ -737,8 +602,8 @@ 0 0 - 395 - 279 + 465 + 241 @@ -907,13 +772,85 @@ - + + + + V + + + + + + + V + + + + + + + + 100 + 0 + + + + + 150 + 16777215 + + + + 1 + + + 10 + + + 2 + + + Qt::Horizontal + + + + + + + x1 + + + + Show background + + + + Qt::Horizontal + + + + 235 + 28 + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + @@ -927,11 +864,6 @@ QSpinBox
knuminput.h
- - KTextEdit - QTextEdit -
ktextedit.h
-
KUrlRequester QFrame @@ -972,21 +904,5 @@ - - fontColorButton - changed(QColor) - ktextedit - setColor(QColor) - - - 599 - 120 - - - 621 - 256 - - -