#include <KDebug>
#include <QGraphicsSceneMouseEvent>
#include <QGraphicsRectItem>
+#include <QGraphicsSvgItem>
#include <QGraphicsView>
#include <QCursor>
#include <QList>
}
t->setTextInteractionFlags(Qt::NoTextInteraction);
setCursor(Qt::ClosedHandCursor);
- } else if (item->type() == 3) {
- QGraphicsRectItem *gi = (QGraphicsRectItem*)item;
- QRectF r = gi->rect();
- r.translate(gi->scenePos());
+ } else if (item->type() == 3 || item->type() == 13 || item->type() == 7) {
+ QRectF r = item->boundingRect();
+ r.translate(item->scenePos());
if ((r.toRect().topLeft() - e->scenePos().toPoint()).manhattanLength() < 6 / zoom) {
resizeMode = TopLeft;
} else if ((r.toRect().bottomLeft() - e->scenePos().toPoint()).manhattanLength() < 6 / zoom) {
void GraphicsSceneRectMove::mouseMoveEvent(QGraphicsSceneMouseEvent* e) {
if (m_selectedItem && e->buttons() & Qt::LeftButton) {
- if (m_selectedItem->type() == 3) {
- QGraphicsRectItem *gi = (QGraphicsRectItem*)m_selectedItem;
- QRectF newrect = gi->rect();
+ if (m_selectedItem->type() == 3 || m_selectedItem->type() == 13 || m_selectedItem->type() == 7) {
+ QRectF newrect = m_selectedItem->boundingRect();
QPointF newpoint = e->scenePos();
//newpoint -= m_selectedItem->scenePos();
switch (resizeMode) {
case TopLeft:
- newrect.setBottomRight(newrect.bottomRight() + gi->pos() - newpoint);
- gi->setPos(newpoint);
+ newrect.setBottomRight(newrect.bottomRight() + m_selectedItem->pos() - newpoint);
+ m_selectedItem->setPos(newpoint);
break;
case BottomLeft:
- newrect.setBottomRight(QPointF(newrect.bottomRight().x() + gi->pos().x() - newpoint.x(), newpoint.y() - gi->pos().y()));
- gi->setPos(QPointF(newpoint.x(), gi->pos().y()));
+ newrect.setBottomRight(QPointF(newrect.bottomRight().x() + m_selectedItem->pos().x() - newpoint.x(), newpoint.y() - m_selectedItem->pos().y()));
+ m_selectedItem->setPos(QPointF(newpoint.x(), m_selectedItem->pos().y()));
break;
case TopRight:
- newrect.setBottomRight(QPointF(newpoint.x() - gi->pos().x(), newrect.bottom() + gi->pos().y() - newpoint.y()));
- gi->setPos(QPointF(gi->pos().x(), newpoint.y()));
+ newrect.setBottomRight(QPointF(newpoint.x() - m_selectedItem->pos().x(), newrect.bottom() + m_selectedItem->pos().y() - newpoint.y()));
+ m_selectedItem->setPos(QPointF(m_selectedItem->pos().x(), newpoint.y()));
break;
case BottomRight:
- newrect.setBottomRight(newpoint - gi->pos());
+ newrect.setBottomRight(newpoint - m_selectedItem->pos());
break;
case Left:
- newrect.setRight(gi->pos().x() + newrect.width() - newpoint.x());
- gi->setPos(QPointF(newpoint.x(), gi->pos().y()));
+ newrect.setRight(m_selectedItem->pos().x() + newrect.width() - newpoint.x());
+ m_selectedItem->setPos(QPointF(newpoint.x(), m_selectedItem->pos().y()));
break;
case Right:
- newrect.setRight(newpoint.x() - gi->pos().x());
+ newrect.setRight(newpoint.x() - m_selectedItem->pos().x());
break;
case Up:
- newrect.setBottom(gi->pos().y() + newrect.bottom() - newpoint.y());
- gi->setPos(QPointF(gi->pos().x(), newpoint.y()));
+ newrect.setBottom(m_selectedItem->pos().y() + newrect.bottom() - newpoint.y());
+ m_selectedItem->setPos(QPointF(m_selectedItem->pos().x(), newpoint.y()));
break;
case Down:
- newrect.setBottom(newpoint.y() - gi->pos().y());
+ newrect.setBottom(newpoint.y() - m_selectedItem->pos().y());
break;
default:
QPointF diff = e->scenePos() - m_clickPoint;
m_clickPoint = e->scenePos();
- gi->moveBy(diff.x(), diff.y());
+ m_selectedItem->moveBy(diff.x(), diff.y());
break;
}
- gi->setRect(newrect);
+ if (m_selectedItem->type() == 3) {
+ QGraphicsRectItem *gi = (QGraphicsRectItem*)m_selectedItem;
+ gi->setRect(newrect);
+ }
+ /*else {
+ qreal s;
+ if (resizeMode == Left || resizeMode == Right ) s = m_selectedItem->boundingRect().width() / newrect.width();
+ else s = m_selectedItem->boundingRect().height() / newrect.height();
+ m_selectedItem->scale( 1 / s, 1 / s );
+ kDebug()<<"/// SCALING SVG, RESIZE MODE: "<<resizeMode<<", RECT:"<<m_selectedItem->boundingRect();
+ }*/
//gi->setPos(m_selectedItem->scenePos());
/*if (resizeMode == NoResize) {
QGraphicsScene::mouseMoveEvent(e);
resizeMode = NoResize;
bool itemFound = false;
foreach(QGraphicsItem* g, items(QRectF(p , QSizeF(4, 4)).toRect())) {
- if (g->type() == 3 && g->zValue() > -1000) {
- QGraphicsRectItem *gi = (QGraphicsRectItem*)g;
- QRectF r = gi->rect();
- r.translate(gi->scenePos());
+ if ((g->type() == 13 || g->type() == 7) && g->zValue() > -1000) {
+ // image or svg item
+ setCursor(Qt::OpenHandCursor);
+ break;
+ } else if (g->type() == 3 && g->zValue() > -1000) {
+ QRectF r = g->boundingRect();
+ r.translate(g->scenePos());
itemFound = true;
if ((r.toRect().topLeft() - e->scenePos().toPoint()).manhattanLength() < 6 / zoom) {
setCursor(QCursor(Qt::SizeFDiagCursor));
#include <QGraphicsItem>
#include <QGraphicsRectItem>
#include <QGraphicsTextItem>
+#include <QGraphicsSvgItem>
#include <KDebug>
#include <QFile>
#include <KTemporaryFile>
QGraphicsTextItem *t;
switch (item->type()) {
+ case 7:
+ e.setAttribute("type", "QGraphicsPixmapItem");
+ content.setAttribute("url", item->data(Qt::UserRole).toString());
+ break;
+ case 13:
+ e.setAttribute("type", "QGraphicsSvgItem");
+ content.setAttribute("url", item->data(Qt::UserRole).toString());
+ break;
case 3:
e.setAttribute("type", "QGraphicsRectItem");
content.setAttribute("rect", rectFToString(((QGraphicsRectItem*)item)->rect()));
//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()));
+ content.setAttribute("font", font.family());
+ content.setAttribute("font-bold", font.bold());
+ content.setAttribute("font-size", font.pointSize());
+ content.setAttribute("font-italic", font.italic());
+ content.setAttribute("font-underline", font.underline());
+ content.setAttribute("font-color", colorToString(t->defaultTextColor()));
break;
default:
continue;
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()));
+ QFont font(items.item(i).namedItem("content").attributes().namedItem("font").nodeValue());
+ font.setBold(items.item(i).namedItem("content").attributes().namedItem("font-bold").nodeValue().toInt());
+ font.setItalic(items.item(i).namedItem("content").attributes().namedItem("font-italic").nodeValue().toInt());
+ font.setUnderline(items.item(i).namedItem("content").attributes().namedItem("font-underline").nodeValue().toInt());
+ font.setPointSize(items.item(i).namedItem("content").attributes().namedItem("font-size").nodeValue().toInt());
+ QColor col(stringToColor(items.item(i).namedItem("content").attributes().namedItem("font-color").nodeValue()));
QGraphicsTextItem *txt = scene->addText(items.item(i).namedItem("content").firstChild().nodeValue(), font);
txt->setDefaultTextColor(col);
txt->setTextInteractionFlags(Qt::NoTextInteraction);
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;
- }
+ } else
+ if (items.item(i).attributes().namedItem("type").nodeValue() == "QGraphicsPixmapItem") {
+ QString url = items.item(i).namedItem("content").attributes().namedItem("url").nodeValue();
+ QPixmap pix(url);
+ QGraphicsPixmapItem *rec = scene->addPixmap(pix);
+ rec->setData(Qt::UserRole, url);
+ gitem = rec;
+ } else
+ if (items.item(i).attributes().namedItem("type").nodeValue() == "QGraphicsSvgItem") {
+ QString url = items.item(i).namedItem("content").attributes().namedItem("url").nodeValue();
+ QGraphicsSvgItem *rec = new QGraphicsSvgItem(url);
+ scene->addItem(rec);
+ rec->setData(Qt::UserRole, url);
+ gitem = rec;
+ }
//pos and transform
if (gitem) {
QPointF p(items.item(i).namedItem("position").attributes().namedItem("x").nodeValue().toDouble(),
connect(endViewportSize, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
connect(zValue, SIGNAL(valueChanged(int)), this, SLOT(zIndexChanged(int)));
- connect(svgfilename, SIGNAL(urlSelected(const KUrl&)), this, SLOT(svgSelected(const KUrl &)));
connect(itemzoom, SIGNAL(valueChanged(int)), this, SLOT(itemScaled(int)));
connect(itemrotate, SIGNAL(valueChanged(int)), this, SLOT(itemRotate(int)));
connect(m_buttonText, SIGNAL(triggered()), this, SLOT(slotTextTool()));
m_buttonImage = m_toolbar->addAction(KIcon("insert-image"), i18n("Add Image"));
- m_buttonImage->setCheckable(true);
+ m_buttonImage->setCheckable(false);
connect(m_buttonImage, SIGNAL(triggered()), this, SLOT(slotImageTool()));
m_buttonCursor = m_toolbar->addAction(KIcon("select-rectangular"), i18n("Selection Tool"));
//graphicsView->resize(400, 300);
kDebug() << "// TITLE WIDGWT: " << graphicsView->viewport()->width() << "x" << graphicsView->viewport()->height();
toolBox->setItemEnabled(2, false);
- toolBox->setItemEnabled(3, false);
if (!url.isEmpty()) {
m_count = m_titledocument.loadDocument(url, startViewport, endViewport) + 1;
slotSelectTool();
m_scene->setTool(TITLE_TEXT);
m_buttonRect->setChecked(false);
m_buttonCursor->setChecked(false);
- m_buttonImage->setChecked(false);
}
void TitleWidget::slotRectTool() {
m_scene->setTool(TITLE_RECTANGLE);
m_buttonText->setChecked(false);
m_buttonCursor->setChecked(false);
- m_buttonImage->setChecked(false);
}
void TitleWidget::slotSelectTool() {
m_buttonCursor->setChecked(true);
m_buttonText->setChecked(false);
m_buttonRect->setChecked(false);
- m_buttonImage->setChecked(false);
+}
+
+void TitleWidget::slotImageTool() {
+ KUrl url = KFileDialog::getOpenUrl(KUrl(), "*.svg *.png *.jpg *.jpeg *.gif *.raw", this, i18n("Load Image"));
+ if (!url.isEmpty()) {
+ if (url.path().endsWith(".svg")) {
+ QGraphicsSvgItem *svg = new QGraphicsSvgItem(url.toLocalFile());
+ svg->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
+ svg->setZValue(m_count++);
+ svg->setData(Qt::UserRole, url.path());
+ graphicsView->scene()->addItem(svg);
+ } else {
+ QPixmap pix(url.path());
+ QGraphicsPixmapItem *image = new QGraphicsPixmapItem(pix);
+ image->setShapeMode(QGraphicsPixmapItem::BoundingRectShape);
+ image->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
+ image->setData(Qt::UserRole, url.path());
+ image->setZValue(m_count++);
+ graphicsView->scene()->addItem(image);
+ }
+ }
+ m_scene->setTool(TITLE_SELECT);
+ m_buttonRect->setChecked(false);
+ m_buttonCursor->setChecked(true);
+ m_buttonText->setChecked(false);
}
void TitleWidget::displayBackgroundFrame() {
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);
+ itemzoom->setValue((int)(transformations[l[0]].scalex * 100));
+ itemrotate->setValue((int)(transformations[l[0]].rotate));
value_x->blockSignals(false);
value_y->blockSignals(false);
value_w->blockSignals(false);
}
}
-void TitleWidget::svgSelected(const KUrl& u) {
- QGraphicsSvgItem *svg = new QGraphicsSvgItem(u.toLocalFile());
- svg->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
- graphicsView->scene()->addItem(svg);
-}
-
void TitleWidget::itemScaled(int val) {
QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
if (l.size() == 1) {
}
void TitleWidget::loadTitle() {
- KUrl url = KFileDialog::getOpenUrl(KUrl(m_projectPath), "*.kdenlivetitle", this, tr("Save Title"));
+ KUrl url = KFileDialog::getOpenUrl(KUrl(m_projectPath), "*.kdenlivetitle", this, i18n("Load Title"));
if (!url.isEmpty()) {
QList<QGraphicsItem *> items = m_scene->items();
for (int i = 0; i < items.size(); i++) {
}
void TitleWidget::saveTitle(KUrl url) {
- if (url.isEmpty()) KUrl url = KFileDialog::getSaveUrl(KUrl(m_projectPath), "*.kdenlivetitle", this, tr("Save Title"));
+ if (url.isEmpty()) url = KFileDialog::getSaveUrl(KUrl(m_projectPath), "*.kdenlivetitle", this, i18n("Save Title"));
if (!url.isEmpty()) m_titledocument.saveDocument(url, startViewport, endViewport);
}
void fontBold();
void setupViewports();
void zIndexChanged(int);
- void svgSelected(const KUrl&);
void itemScaled(int);
void itemRotate(int);
void saveTitle(KUrl url = KUrl());
void slotTextTool();
void slotRectTool();
void slotSelectTool();
+ void slotImageTool();
};
<widget class="QGraphicsView" name="graphicsView" />
<widget class="QToolBox" name="toolBox" >
<property name="currentIndex" >
- <number>0</number>
+ <number>1</number>
</property>
<widget class="QWidget" name="BasicOperations" >
<property name="geometry" >
<x>0</x>
<y>0</y>
<width>309</width>
- <height>108</height>
+ <height>140</height>
</rect>
</property>
<attribute name="label" >
<rect>
<x>0</x>
<y>0</y>
- <width>381</width>
- <height>157</height>
+ <width>309</width>
+ <height>140</height>
</rect>
</property>
<attribute name="label" >
</item>
</layout>
</widget>
- <widget class="QWidget" name="SVG" >
- <property name="geometry" >
- <rect>
- <x>0</x>
- <y>0</y>
- <width>381</width>
- <height>157</height>
- </rect>
- </property>
- <attribute name="label" >
- <string>SVG</string>
- </attribute>
- <layout class="QGridLayout" >
- <item row="0" column="0" >
- <layout class="QVBoxLayout" >
- <item>
- <widget class="QLabel" name="label_13" >
- <property name="sizePolicy" >
- <sizepolicy vsizetype="Preferred" hsizetype="Preferred" >
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="text" >
- <string>Filename:</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="KUrlRequester" name="svgfilename" >
- <property name="filter" >
- <string>*.svg *.svgz</string>
- </property>
- </widget>
- </item>
- <item>
- <spacer>
- <property name="orientation" >
- <enum>Qt::Vertical</enum>
- </property>
- <property name="sizeType" >
- <enum>QSizePolicy::Expanding</enum>
- </property>
- <property name="sizeHint" stdset="0" >
- <size>
- <width>20</width>
- <height>151</height>
- </size>
- </property>
- </spacer>
- </item>
- </layout>
- </item>
- </layout>
- </widget>
<widget class="QWidget" name="Seite" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
- <width>362</width>
+ <width>273</width>
<height>224</height>
</rect>
</property>
<extends>QSpinBox</extends>
<header>knuminput.h</header>
</customwidget>
- <customwidget>
- <class>KUrlRequester</class>
- <extends>QFrame</extends>
- <header>kurlrequester.h</header>
- </customwidget>
</customwidgets>
<resources/>
<connections>