+ backgroundColor->setColor(titleConfig.readEntry("background_color", backgroundColor->color()));
+ backgroundAlpha->setValue(titleConfig.readEntry("background_alpha", backgroundAlpha->value()));
+}
+
+void TitleWidget::adjustFrameSize()
+{
+ m_frameWidth = m_titledocument.frameWidth();
+ m_frameHeight = m_titledocument.frameHeight();
+ m_frameBorder->setRect(0, 0, m_frameWidth, m_frameHeight);
+ displayBackgroundFrame();
+}
+
+void TitleWidget::slotAnimStart(bool anim)
+{
+ if (anim && anim_end->isChecked()) {
+ anim_end->setChecked(false);
+ m_endViewport->setZValue(-1000);
+ m_endViewport->setBrush(QBrush());
+ }
+ slotSelectTool();
+ QList<QGraphicsItem *> list = m_scene->items();
+ for (int i = 0; i < list.count(); ++i) {
+ if (list.at(i)->zValue() > -1000) {
+ list.at(i)->setFlag(QGraphicsItem::ItemIsMovable, !anim);
+ list.at(i)->setFlag(QGraphicsItem::ItemIsSelectable, !anim);
+ }
+ }
+ align_box->setEnabled(anim);
+ itemzoom->setEnabled(!anim);
+ itemrotatex->setEnabled(!anim);
+ itemrotatey->setEnabled(!anim);
+ itemrotatez->setEnabled(!anim);
+ frame_toolbar->setEnabled(!anim);
+ toolbar_stack->setEnabled(!anim);
+ if (anim) {
+ keep_aspect->setChecked(!m_startViewport->data(0).isNull());
+ m_startViewport->setZValue(1100);
+ QColor col = m_startViewport->pen().color();
+ col.setAlpha(100);
+ m_startViewport->setBrush(col);
+ m_startViewport->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
+ m_startViewport->setSelected(true);
+ selectionChanged();
+ slotSelectTool();
+ if (m_startViewport->childItems().isEmpty()) addAnimInfoText();
+ } else {
+ m_startViewport->setZValue(-1000);
+ m_startViewport->setBrush(QBrush());
+ m_startViewport->setFlags(0);
+ if (!anim_end->isChecked()) deleteAnimInfoText();
+ }
+
+}
+
+void TitleWidget::slotAnimEnd(bool anim)
+{
+ if (anim && anim_start->isChecked()) {
+ anim_start->setChecked(false);
+ m_startViewport->setZValue(-1000);
+ m_startViewport->setBrush(QBrush());
+ }
+ slotSelectTool();
+ QList<QGraphicsItem *> list = m_scene->items();
+ for (int i = 0; i < list.count(); ++i) {
+ if (list.at(i)->zValue() > -1000) {
+ list.at(i)->setFlag(QGraphicsItem::ItemIsMovable, !anim);
+ list.at(i)->setFlag(QGraphicsItem::ItemIsSelectable, !anim);
+ }
+ }
+ align_box->setEnabled(anim);
+ itemzoom->setEnabled(!anim);
+ itemrotatex->setEnabled(!anim);
+ itemrotatey->setEnabled(!anim);
+ itemrotatez->setEnabled(!anim);
+ frame_toolbar->setEnabled(!anim);
+ toolbar_stack->setEnabled(!anim);
+ if (anim) {
+ keep_aspect->setChecked(!m_endViewport->data(0).isNull());
+ m_endViewport->setZValue(1100);
+ QColor col = m_endViewport->pen().color();
+ col.setAlpha(100);
+ m_endViewport->setBrush(col);
+ m_endViewport->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
+ m_endViewport->setSelected(true);
+ selectionChanged();
+ slotSelectTool();
+ if (m_endViewport->childItems().isEmpty()) addAnimInfoText();
+ } else {
+ m_endViewport->setZValue(-1000);
+ m_endViewport->setBrush(QBrush());
+ m_endViewport->setFlags(0);
+ if (!anim_start->isChecked()) deleteAnimInfoText();
+ }
+}
+
+void TitleWidget::addAnimInfoText()
+{
+ // add text to anim viewport
+ QGraphicsTextItem *t = new QGraphicsTextItem(i18nc("Indicates the start of an animation", "Start"), m_startViewport);
+ QGraphicsTextItem *t2 = new QGraphicsTextItem(i18nc("Indicates the end of an animation", "End"), m_endViewport);
+ QFont font = t->font();
+ font.setPixelSize(m_startViewport->rect().width() / 10);
+ QColor col = m_startViewport->pen().color();
+ col.setAlpha(255);
+ t->setDefaultTextColor(col);
+ t->setFont(font);
+ font.setPixelSize(m_endViewport->rect().width() / 10);
+ col = m_endViewport->pen().color();
+ col.setAlpha(255);
+ t2->setDefaultTextColor(col);
+ t2->setFont(font);
+}
+
+void TitleWidget::updateInfoText()
+{
+ // update info text font
+ if (!m_startViewport->childItems().isEmpty()) {
+ QGraphicsTextItem *item = static_cast <QGraphicsTextItem *>(m_startViewport->childItems().at(0));
+ if (item) {
+ QFont font = item->font();
+ font.setPixelSize(m_startViewport->rect().width() / 10);
+ item->setFont(font);
+ }
+ }
+ if (!m_endViewport->childItems().isEmpty()) {
+ QGraphicsTextItem *item = static_cast <QGraphicsTextItem *>(m_endViewport->childItems().at(0));
+ if (item) {
+ QFont font = item->font();
+ font.setPixelSize(m_endViewport->rect().width() / 10);
+ item->setFont(font);
+ }
+ }
+}
+
+void TitleWidget::deleteAnimInfoText()
+{
+ // end animation editing, remove info text
+ while (!m_startViewport->childItems().isEmpty()) {
+ QGraphicsItem *item = m_startViewport->childItems().at(0);
+ m_scene->removeItem(item);
+ delete item;
+ }
+ while (!m_endViewport->childItems().isEmpty()) {
+ QGraphicsItem *item = m_endViewport->childItems().at(0);
+ m_scene->removeItem(item);
+ delete item;
+ }
+}
+
+void TitleWidget::slotKeepAspect(bool keep)
+{
+ if (m_endViewport->zValue() == 1100) {
+ m_endViewport->setData(0, keep == true ? m_frameWidth : QVariant());
+ m_endViewport->setData(1, keep == true ? m_frameHeight : QVariant());
+ } else {
+ m_startViewport->setData(0, keep == true ? m_frameWidth : QVariant());
+ m_startViewport->setData(1, keep == true ? m_frameHeight : QVariant());
+ }
+}
+
+void TitleWidget::slotResize50()
+{
+ if (m_endViewport->zValue() == 1100) {
+ m_endViewport->setRect(0, 0, m_frameWidth / 2, m_frameHeight / 2);
+ } else m_startViewport->setRect(0, 0, m_frameWidth / 2, m_frameHeight / 2);
+}
+
+void TitleWidget::slotResize100()
+{
+ if (m_endViewport->zValue() == 1100) {
+ m_endViewport->setRect(0, 0, m_frameWidth, m_frameHeight);
+ } else m_startViewport->setRect(0, 0, m_frameWidth, m_frameHeight);
+}
+
+void TitleWidget::slotResize200()
+{
+ if (m_endViewport->zValue() == 1100) {
+ m_endViewport->setRect(0, 0, m_frameWidth * 2, m_frameHeight * 2);
+ } else m_startViewport->setRect(0, 0, m_frameWidth * 2, m_frameHeight * 2);
+}
+
+void TitleWidget::slotAddEffect(int ix)
+{
+ QList<QGraphicsItem *> list = graphicsView->scene()->selectedItems();
+ int effect = effect_list->itemData(ix).toInt();
+
+ if (list.size() == 1) {
+ if (effect == NOEFFECT)
+ effect_stack->setHidden(true);
+ else {
+ effect_stack->setCurrentIndex(effect - 1);
+ effect_stack->setHidden(false);
+ }
+ } else // Hide the effects stack when more than one element is selected.
+ effect_stack->setHidden(true);
+
+ foreach(QGraphicsItem * item, list) {
+ switch (effect) {
+ case NOEFFECT:
+ item->setData(100, QVariant());
+#if QT_VERSION >= 0x040600
+ item->setGraphicsEffect(0);
+#endif
+ break;
+ case TYPEWRITEREFFECT:
+ /*
+ * Allow the user to set the typewriter effect to more than one
+ * element, but do not add it to non-text elements.
+ */
+ if (item->type() == TEXTITEM) {
+ QStringList effdata = QStringList() << "typewriter" << QString::number(typewriter_delay->value()) + ';' + QString::number(typewriter_start->value());
+ item->setData(100, effdata);
+ }
+ break;
+#if QT_VERSION >= 0x040600
+ // Do not remove the non-QGraphicsEffects.
+ case BLUREFFECT:
+ item->setGraphicsEffect(new QGraphicsBlurEffect());
+ break;
+ case SHADOWEFFECT:
+ item->setGraphicsEffect(new QGraphicsDropShadowEffect());
+ break;
+#endif
+ }
+ }
+}
+
+void TitleWidget::slotFontText(const QString& s)
+{
+ const QFont f(s);
+ if (f.exactMatch()) {
+ // Font really exists (could also just be a «d» if the user
+ // starts typing «dejavu» for example).
+ font_family->setCurrentFont(f);
+ }
+ // Note: Typing dejavu serif does not recognize the font (takes sans)
+ // in older Qt versions. Case must match there (except for first letter)
+}
+
+void TitleWidget::slotEditTypewriter(int /*ix*/)
+{
+ QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
+ if (l.size() == 1) {
+ QStringList effdata = QStringList() << "typewriter" << QString::number(typewriter_delay->value()) + ';' + QString::number(typewriter_start->value());
+ l[0]->setData(100, effdata);
+ }
+}
+
+void TitleWidget::slotEditBlur(int ix)
+{
+#if QT_VERSION < 0x040600
+ return;
+#else
+ QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
+ if (l.size() == 1) {
+ QGraphicsEffect *eff = l[0]->graphicsEffect();
+ QGraphicsBlurEffect *blur = static_cast <QGraphicsBlurEffect *>(eff);
+ if (blur) blur->setBlurRadius(ix);
+ }
+#endif
+}
+
+void TitleWidget::slotEditShadow()
+{
+#if QT_VERSION < 0x040600
+ return;
+#else
+ QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
+ if (l.size() == 1) {
+ QGraphicsEffect *eff = l[0]->graphicsEffect();
+ QGraphicsDropShadowEffect *shadow = static_cast <QGraphicsDropShadowEffect *>(eff);
+ if (shadow) {
+ shadow->setBlurRadius(shadow_radius->value());
+ shadow->setOffset(shadow_x->value(), shadow_y->value());
+ }
+ }
+#endif
+}
+
+qreal TitleWidget::zIndexBounds(bool maxBound, bool intersectingOnly)
+{
+ qreal bound = maxBound ? -99 : 99;
+ QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
+ if (l.size() > 0) {
+ QList<QGraphicsItem*> lItems;
+ // Get items (all or intersecting only)
+ if (intersectingOnly) {
+ lItems = graphicsView->scene()->items(l[0]->sceneBoundingRect(), Qt::IntersectsItemShape);
+ } else {
+ lItems = graphicsView->scene()->items();
+ }
+ if (lItems.size() > 0) {
+ int n = lItems.size();
+ qreal z;
+ if (maxBound) {
+ for (int i = 0; i < n; ++i) {
+ z = lItems[i]->zValue();
+ if (z > bound && !lItems[i]->isSelected()) {
+ bound = z;
+ } else if (z - 1 > bound) {
+ // To get the maximum index even if it is of an item of the current selection.
+ // Used when updating multiple items, to get all to the same level.
+ // Otherwise, the maximum would stay at -99 if the highest item is in the selection.
+ bound = z - 1;
+ }
+ }
+ } else {
+ // Get minimum z index.
+ for (int i = 0; i < n; ++i) {
+ z = lItems[i]->zValue();
+ if (z < bound && !lItems[i]->isSelected() && z > -999) {
+ // There are items at the very bottom (background e.g.) with z-index < -1000.
+ bound = z;
+ } else if (z + 1 < bound && z > -999) {
+ bound = z + 1;
+ }
+ }
+ }
+ }
+ }
+ return bound;
+}
+
+void TitleWidget::slotZIndexUp()
+{
+ QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
+ if (l.size() >= 1) {
+ qreal currentZ = l[0]->zValue();
+ qreal max = zIndexBounds(true, true);
+ if (currentZ <= max) {
+ l[0]->setZValue(currentZ + 1);
+ updateDimension(l[0]);
+ }
+ }
+}
+
+void TitleWidget::slotZIndexTop()
+{
+ QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
+ qreal max = zIndexBounds(true, false);
+ std::cout << "Max z-index is " << max << ".\n";
+ for (int i = 0; i < l.size(); ++i) {
+ qreal currentZ = l[i]->zValue();
+ if (currentZ <= max) {
+ std::cout << "Updating item " << i << ", is " << currentZ << ".\n";
+ l[i]->setZValue(max + 1);
+ } else {
+ std::cout << "Not updating " << i << ", is " << currentZ << ".\n";
+ }
+ }
+ // Update the z index value in the GUI
+ if (l.size() > 0) {
+ updateDimension(l[0]);
+ }
+}
+
+void TitleWidget::slotZIndexDown()
+{
+ QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
+ if (l.size() >= 1) {
+ qreal currentZ = l[0]->zValue();
+ qreal min = zIndexBounds(false, true);
+ if (currentZ >= min) {
+ l[0]->setZValue(currentZ - 1);
+ updateDimension(l[0]);
+ }
+ }
+}
+
+void TitleWidget::slotZIndexBottom()
+{
+ QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
+ qreal min = zIndexBounds(false, false);
+ for (int i = 0; i < l.size(); ++i) {
+ qreal currentZ = l[i]->zValue();
+ if (currentZ >= min) {
+ l[i]->setZValue(min - 1);
+ }
+ }
+ // Update the z index value in the GUI
+ if (l.size() > 0) {
+ updateDimension(l[0]);
+ }
+}
+
+void TitleWidget::slotSelectAll()
+{
+ QList<QGraphicsItem*> l = graphicsView->scene()->items();
+ for (int i = 0; i < l.size(); ++i) {
+ l.at(i)->setSelected(true);
+ }
+}
+
+void TitleWidget::selectItems(int itemType)
+{
+ QList<QGraphicsItem*> l;
+ if (graphicsView->scene()->selectedItems().size() > 0) {
+ l = graphicsView->scene()->selectedItems();
+ for (int i = 0; i < l.size(); ++i) {
+ if (l.at(i)->type() != itemType) {
+ l.at(i)->setSelected(false);
+ }
+ }
+ } else {
+ l = graphicsView->scene()->items();
+ for (int i = 0; i < l.size(); ++i) {
+ if (l.at(i)->type() == itemType) {
+ l.at(i)->setSelected(true);
+ }
+ }
+ }
+}
+
+void TitleWidget::slotSelectText()
+{
+ selectItems(TEXTITEM);
+}
+
+void TitleWidget::slotSelectRects()
+{
+ selectItems(RECTITEM);
+}
+
+void TitleWidget::slotSelectImages()
+{
+ selectItems(IMAGEITEM);
+}
+
+void TitleWidget::slotSelectNone()
+{
+ graphicsView->blockSignals(true);
+ QList<QGraphicsItem*> l = graphicsView->scene()->items();
+ for (int i = 0; i < l.size(); ++i) {
+ l.at(i)->setSelected(false);
+ }
+ graphicsView->blockSignals(false);
+ selectionChanged();
+}
+
+QString TitleWidget::getTooltipWithShortcut(const QString &text, QAction *button)
+{
+ return text + " <b>" + button->shortcut().toString() + "</b>";