#include <QGraphicsView>
#include <QCursor>
#include <QList>
+#include <QKeyEvent>
#include "graphicsscenerectmove.h"
zoom = 1.0;
}
+void GraphicsSceneRectMove::setSelectedItem(QGraphicsItem *item) {
+ m_selectedItem = item;
+ item->setSelected(true);
+}
+
+//virtual
+void GraphicsSceneRectMove::keyPressEvent(QKeyEvent * keyEvent) {
+ if (m_selectedItem == NULL) {
+ QGraphicsScene::keyPressEvent(keyEvent);
+ return;
+ }
+ int diff = 1;
+ if (keyEvent->modifiers() & Qt::ControlModifier) diff = 10;
+ switch (keyEvent->key()) {
+ case Qt::Key_Left:
+ m_selectedItem->setPos(m_selectedItem->pos() - QPointF(diff, 0));
+ break;
+ case Qt::Key_Right:
+ m_selectedItem->setPos(m_selectedItem->pos() + QPointF(diff, 0));
+ break;
+ case Qt::Key_Up:
+ m_selectedItem->setPos(m_selectedItem->pos() - QPointF(0, diff));
+ break;
+ case Qt::Key_Down:
+ m_selectedItem->setPos(m_selectedItem->pos() + QPointF(0, diff));
+ break;
+ default:
+ QGraphicsScene::keyPressEvent(keyEvent);
+ }
+ emit itemMoved();
+}
+
//virtual
void GraphicsSceneRectMove::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* e) {
QPointF p = e->scenePos();
QPointF p = e->scenePos();
p += QPoint(-2, -2);
resizeMode = NoResize;
- bool itemFound = false;
+ bool itemFound = false;
foreach(QGraphicsItem* g, items(QRectF(p , QSizeF(4, 4)).toRect())) {
if (g->type() == 3) {
QGraphicsRectItem *gi = (QGraphicsRectItem*)g;
QRectF r = gi->rect();
r.translate(gi->scenePos());
- itemFound = true;
+ itemFound = true;
if ((r.toRect().topLeft() - e->scenePos().toPoint()).manhattanLength() < 6 / zoom) {
setCursor(QCursor(Qt::SizeFDiagCursor));
} else if ((r.toRect().bottomLeft() - e->scenePos().toPoint()).manhattanLength() < 6 / zoom) {
} else if (qAbs(r.toRect().bottom() - e->scenePos().toPoint().y()) < 3 / zoom) {
setCursor(Qt::SizeVerCursor);
} else setCursor(QCursor(Qt::ArrowCursor));
- break;
+ break;
}
- if (!itemFound) setCursor(QCursor(Qt::ArrowCursor));
+ if (!itemFound) setCursor(QCursor(Qt::ArrowCursor));
}
QGraphicsScene::mouseMoveEvent(e);
}
public:
GraphicsSceneRectMove(QObject* parent = 0);
+ void setSelectedItem(QGraphicsItem *item);
void setScale(double s);
void setZoom(double s);
+protected:
+ virtual void keyPressEvent(QKeyEvent * keyEvent);
virtual void mousePressEvent(QGraphicsSceneMouseEvent*);
virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent* e);
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent*);
int groupId = -1;
ProjectItem *item = static_cast <ProjectItem*>(listView->currentItem());
if (item && item->clipType() != FOLDER) {
- while (item->parent()) {
- item = static_cast <ProjectItem*>(item->parent());
+ while (item->parent()) {
+ item = static_cast <ProjectItem*>(item->parent());
if (item->clipType() == FOLDER) break;
}
}
int settingUp = false;
-TitleWidget::TitleWidget(Render *render, QWidget *parent): QDialog(parent) {
+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());
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())) ;
+ connect(font_family, SIGNAL(currentFontChanged(const QFont &)), this, SLOT(slotUpdateText())) ;
+ connect(font_size, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateText())) ;
connect(textAlpha, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateText()));
//connect (ktextedit, SIGNAL(selectionChanged()), this , SLOT (textChanged()));
connect(value_h, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
connect(buttonFitZoom, SIGNAL(clicked()), this, SLOT(slotAdjustZoom()));
connect(buttonRealSize, SIGNAL(clicked()), this, SLOT(slotZoomOneToOne()));
+ connect(buttonBold, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
+ connect(buttonItalic, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
+ connect(buttonUnder, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
+ connect(displayBg, SIGNAL(stateChanged(int)), this, SLOT(displayBackgroundFrame()));
buttonFitZoom->setIcon(KIcon("zoom-fit-best"));
buttonRealSize->setIcon(KIcon("zoom-original"));
+ buttonBold->setIcon(KIcon("format-text-bold"));
+ buttonItalic->setIcon(KIcon("format-text-italic"));
+ buttonUnder->setIcon(KIcon("format-text-underline"));
+
m_scene = new GraphicsSceneRectMove(this);
// a gradient background
framepen.setColor(Qt::red);
m_frameWidth = render->renderWidth();
m_frameHeight = render->renderHeight();
- QPixmap bg = render->extractFrame((int) render->seekPosition().frames(render->fps()), m_frameWidth, m_frameHeight);
- QGraphicsPixmapItem *fb = new QGraphicsPixmapItem(bg);
- fb->setZValue(-1000);
- fb->setFlags(QGraphicsItem::ItemClipsToShape);
- graphicsView->scene()->addItem(fb);
m_frameBorder = new QGraphicsRectItem(QRectF(0, 0, m_frameWidth, m_frameHeight));
m_frameBorder->setPen(framepen);
//slotAdjustZoom();
}
+void TitleWidget::displayBackgroundFrame() {
+ if (m_frameImage) delete m_frameImage;
+ m_frameImage = NULL;
+ if (!displayBg->isChecked()) return;
+ QPixmap bg = m_render->extractFrame((int) m_render->seekPosition().frames(m_render->fps()), m_frameWidth / 2, m_frameHeight / 2);
+ m_frameImage = new QGraphicsPixmapItem(bg);
+ QTransform qtrans;
+ qtrans.scale(2.0, 2.0);
+ m_frameImage->setTransform(qtrans);
+ m_frameImage->setZValue(-1100);
+ m_frameImage->setFlags(QGraphicsItem::ItemClipsToShape);
+ graphicsView->scene()->addItem(m_frameImage);
+}
+
void TitleWidget::initViewports() {
startViewport = new QGraphicsPolygonItem(QPolygonF(QRectF(0, 0, 0, 0)));
endViewport = new QGraphicsPolygonItem(QPolygonF(QRectF(0, 0, 0, 0)));
QColor b = rectBColor->color();
b.setAlpha(rectBAlpha->value());
ri->setBrush(QBrush(b));
+ ri->setZValue(m_count++);
+ setCurrentItem(ri);
+ graphicsView->setFocus();
}
void TitleWidget::slotNewText() {
tt->setTextInteractionFlags(Qt::NoTextInteraction);
tt->setPos(m_frameWidth / 2, m_frameHeight / 2);
QFont font = font_family->currentFont();
- font.setPointSize (font_size->value());
+ font.setPointSize(font_size->value());
tt->setFont(font);
- connect(tt->document(), SIGNAL(contentsChanged()), this, SLOT(selectionChanged()));
+ 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<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
+ if (l.size() >= 1) {
+ l[0]->setSelected(false);
+ }
+ m_scene->setSelectedItem(item);
+}
+
void TitleWidget::zIndexChanged(int v) {
QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
if (l.size() >= 1) {
ktextedit->setHtml(i->toHtml());
toolBox->setCurrentIndex(2);
toolBox->setItemEnabled(2, true);
+
+
+ QFont font = i->font();
+ font_family->setCurrentFont(font);
+ font_size->setValue(font.pointSize());
+ buttonBold->setChecked(font.bold());
+ buttonItalic->setChecked(font.italic());
+ buttonUnder->setChecked(font.underline());
+
+ QColor color = i->defaultTextColor();
+ fontColorButton->setColor(color);
+ textAlpha->setValue(color.alpha());
+
value_x->setValue((int) i->pos().x());
value_y->setValue((int) i->pos().y());
value_w->setValue((int) i->boundingRect().width());
void TitleWidget::slotUpdateText() {
QFont font = font_family->currentFont();
- font.setPointSize (font_size->value());
+ font.setPointSize(font_size->value());
+ font.setBold(buttonBold->isChecked());
+ font.setItalic(buttonItalic->isChecked());
+ font.setUnderline(buttonUnder->isChecked());
QColor color = fontColorButton->color();
color.setAlpha(textAlpha->value());
QGraphicsTextItem* item = NULL;
QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
if (l.size() == 1 && (l[0])->type() == 8) {
- item = (QGraphicsTextItem*)l[0];
+ item = (QGraphicsTextItem*)l[0];
}
if (!item) return;
- if (item->textCursor().selection ().isEmpty())
+ //if (item->textCursor().selection ().isEmpty())
{
- item->setFont(font);
- item->setDefaultTextColor(color);
+ item->setFont(font);
+ item->setDefaultTextColor(color);
}
/*else {
- QTextDocumentFragment selec = item->textCursor().selection ();
- selec.set
+ QTextDocumentFragment selec = item->textCursor().selection ();
+ selec.set
}*/
//if (ktextedit->textCursor().selectedText().isEmpty()) ktextedit->selectAll();
//ktextedit->setTextColor(color);
/*QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
if (l.size() == 1 && (l[0])->type() == 8 && l[0]->hasFocus()) {
- QGraphicsTextItem* item = static_cast <QGraphicsTextItem*> (l[0]);
- //item-
+ QGraphicsTextItem* item = static_cast <QGraphicsTextItem*> (l[0]);
+ //item-
}*/
}
#include <QDialog>
+
#include <QMap>
#include "ui_titlewidget_ui.h"
QMap<QGraphicsItem*, Transform > transformations;
TitleDocument m_titledocument;
QGraphicsRectItem *m_frameBorder;
+ QGraphicsPixmapItem *m_frameImage;
int m_frameWidth;
int m_frameHeight;
+ Render *m_render;
+ int m_count;
public slots:
void slotNewText();
void slotAdjustZoom();
void slotZoomOneToOne();
void slotUpdateText();
+ void displayBackgroundFrame();
+ void setCurrentItem(QGraphicsItem *item);
};
<x>0</x>
<y>0</y>
<width>771</width>
- <height>510</height>
+ <height>612</height>
</rect>
</property>
<property name="sizePolicy" >
<string>Dialog</string>
</property>
<layout class="QGridLayout" name="gridLayout_4" >
- <item row="0" column="0" colspan="5" >
+ <item row="0" column="0" colspan="6" >
<layout class="QHBoxLayout" >
<item>
<widget class="QPushButton" name="newRectButton" >
</item>
</layout>
</item>
- <item row="1" column="0" colspan="5" >
+ <item row="1" column="0" colspan="6" >
<widget class="QFrame" name="frame_properties" >
<property name="frameShape" >
<enum>QFrame::StyledPanel</enum>
</layout>
</item>
</layout>
- <zorder>splitter</zorder>
</widget>
</item>
- <item row="2" column="0" colspan="5" >
+ <item row="3" column="0" >
+ <widget class="QToolButton" name="buttonFitZoom" >
+ <property name="text" >
+ <string>V</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="1" >
+ <widget class="QToolButton" name="buttonRealSize" >
+ <property name="text" >
+ <string>V</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="2" >
+ <widget class="QSlider" name="zoom_slider" >
+ <property name="minimumSize" >
+ <size>
+ <width>100</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="maximumSize" >
+ <size>
+ <width>150</width>
+ <height>16777215</height>
+ </size>
+ </property>
+ <property name="minimum" >
+ <number>1</number>
+ </property>
+ <property name="maximum" >
+ <number>10</number>
+ </property>
+ <property name="pageStep" >
+ <number>2</number>
+ </property>
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="3" >
+ <widget class="QLabel" name="zoom_label" >
+ <property name="text" >
+ <string>x1</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="5" >
+ <widget class="QDialogButtonBox" name="buttonBox" >
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="standardButtons" >
+ <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="0" colspan="6" >
<widget class="QSplitter" name="splitter" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Expanding" hsizetype="Expanding" >
<rect>
<x>0</x>
<y>0</y>
- <width>297</width>
- <height>185</height>
+ <width>395</width>
+ <height>279</height>
</rect>
</property>
<attribute name="label" >
<rect>
<x>0</x>
<y>0</y>
- <width>297</width>
- <height>185</height>
+ <width>395</width>
+ <height>279</height>
</rect>
</property>
<attribute name="label" >
<rect>
<x>0</x>
<y>0</y>
- <width>267</width>
- <height>177</height>
+ <width>395</width>
+ <height>279</height>
</rect>
</property>
<attribute name="label" >
<item row="0" column="0" >
<widget class="QFontComboBox" name="font_family" />
</item>
- <item row="1" column="0" >
- <layout class="QHBoxLayout" name="horizontalLayout" >
- <item>
- <widget class="QSpinBox" name="font_size" >
- <property name="minimum" >
- <number>8</number>
- </property>
- <property name="maximum" >
- <number>1000</number>
- </property>
- <property name="value" >
- <number>20</number>
- </property>
- </widget>
- </item>
- <item>
- <widget class="KColorButton" name="fontColorButton" />
- </item>
- <item>
- <widget class="QSlider" name="textAlpha" >
- <property name="maximum" >
- <number>255</number>
- </property>
- <property name="value" >
- <number>255</number>
- </property>
- <property name="orientation" >
- <enum>Qt::Horizontal</enum>
- </property>
- </widget>
- </item>
- </layout>
+ <item row="3" column="0" >
+ <widget class="KTextEdit" name="ktextedit" />
</item>
<item row="2" column="0" >
<layout class="QHBoxLayout" name="horizontalLayout_2" >
<item>
- <widget class="QToolButton" name="toolButton_6" >
+ <widget class="QToolButton" name="buttonBold" >
<property name="text" >
<string>...</string>
</property>
+ <property name="checkable" >
+ <bool>true</bool>
+ </property>
+ <property name="checked" >
+ <bool>false</bool>
+ </property>
</widget>
</item>
<item>
- <widget class="QToolButton" name="toolButton_5" >
+ <widget class="QToolButton" name="buttonItalic" >
<property name="text" >
<string>...</string>
</property>
+ <property name="checkable" >
+ <bool>true</bool>
+ </property>
</widget>
</item>
<item>
- <widget class="QToolButton" name="toolButton_4" >
+ <widget class="QToolButton" name="buttonUnder" >
<property name="text" >
<string>...</string>
</property>
+ <property name="checkable" >
+ <bool>true</bool>
+ </property>
</widget>
</item>
<item>
</item>
</layout>
</item>
- <item row="3" column="0" >
- <widget class="KTextEdit" name="ktextedit" />
+ <item row="1" column="0" >
+ <layout class="QHBoxLayout" name="horizontalLayout" >
+ <item>
+ <widget class="QSpinBox" name="font_size" >
+ <property name="minimum" >
+ <number>8</number>
+ </property>
+ <property name="maximum" >
+ <number>1000</number>
+ </property>
+ <property name="value" >
+ <number>20</number>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="KColorButton" name="fontColorButton" />
+ </item>
+ <item>
+ <widget class="QSlider" name="textAlpha" >
+ <property name="maximum" >
+ <number>255</number>
+ </property>
+ <property name="value" >
+ <number>255</number>
+ </property>
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item row="4" column="0" >
+ <spacer name="verticalSpacer" >
+ <property name="orientation" >
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0" >
+ <size>
+ <width>20</width>
+ <height>40</height>
+ </size>
+ </property>
+ </spacer>
</item>
</layout>
</widget>
<rect>
<x>0</x>
<y>0</y>
- <width>278</width>
- <height>249</height>
+ <width>395</width>
+ <height>279</height>
</rect>
</property>
<attribute name="label" >
<rect>
<x>0</x>
<y>0</y>
- <width>297</width>
- <height>185</height>
+ <width>395</width>
+ <height>279</height>
</rect>
</property>
<attribute name="label" >
<rect>
<x>0</x>
<y>0</y>
- <width>278</width>
- <height>224</height>
+ <width>395</width>
+ <height>279</height>
</rect>
</property>
<attribute name="label" >
</widget>
</widget>
</item>
- <item row="3" column="0" >
- <widget class="QToolButton" name="buttonFitZoom" >
- <property name="text" >
- <string>V</string>
- </property>
- </widget>
- </item>
- <item row="3" column="1" >
- <widget class="QToolButton" name="buttonRealSize" >
- <property name="text" >
- <string>V</string>
- </property>
- </widget>
- </item>
- <item row="3" column="2" >
- <widget class="QSlider" name="zoom_slider" >
- <property name="minimumSize" >
- <size>
- <width>100</width>
- <height>0</height>
- </size>
- </property>
- <property name="maximumSize" >
- <size>
- <width>150</width>
- <height>16777215</height>
- </size>
- </property>
- <property name="minimum" >
- <number>1</number>
- </property>
- <property name="maximum" >
- <number>10</number>
- </property>
- <property name="pageStep" >
- <number>2</number>
- </property>
- <property name="orientation" >
- <enum>Qt::Horizontal</enum>
- </property>
- </widget>
- </item>
- <item row="3" column="3" >
- <widget class="QLabel" name="zoom_label" >
- <property name="text" >
- <string>x1</string>
- </property>
- </widget>
- </item>
<item row="3" column="4" >
- <widget class="QDialogButtonBox" name="buttonBox" >
- <property name="orientation" >
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="standardButtons" >
- <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+ <widget class="QCheckBox" name="displayBg" >
+ <property name="text" >
+ <string>Show background</string>
</property>
</widget>
</item>