+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>";
+}
+
+void TitleWidget::prepareTools(QGraphicsItem *referenceItem)
+{
+ // Let some GUI elements block signals. We may want to change their values without any sideeffects.
+ // Additionally, store the previous blocking state to avoid side effects when this function is called from within another one.
+ // Note: Disabling an element also blocks signals. So disabled elements don't need to be set to blocking too.
+ bool blockOX = origin_x_left->signalsBlocked();
+ bool blockOY = origin_y_top->signalsBlocked();
+ bool blockEff = effect_list->signalsBlocked();
+ bool blockRX = itemrotatex->signalsBlocked();
+ bool blockRY = itemrotatey->signalsBlocked();
+ bool blockRZ = itemrotatez->signalsBlocked();
+ bool blockZoom = itemzoom->signalsBlocked();
+ bool blockX = value_x->signalsBlocked();
+ bool blockY = value_y->signalsBlocked();
+ bool blockW = value_w->signalsBlocked();
+ bool blockH = value_h->signalsBlocked();
+ origin_x_left->blockSignals(true);
+ origin_y_top->blockSignals(true);
+ effect_list->blockSignals(true);
+ itemrotatex->blockSignals(true);
+ itemrotatey->blockSignals(true);
+ itemrotatez->blockSignals(true);
+ itemzoom->blockSignals(true);
+ value_x->blockSignals(true);
+ value_y->blockSignals(true);
+ value_w->blockSignals(true);
+ value_h->blockSignals(true);
+
+ if (referenceItem == NULL) {
+ std::cout << "NULL item.\n";
+ effect_stack->setHidden(true);
+ effect_frame->setEnabled(false);
+ effect_list->setCurrentIndex(0);
+ origin_x_left->setChecked(false);
+ origin_y_top->setChecked(false);
+ updateTextOriginX();
+ updateTextOriginY();
+ enableToolbars(TITLE_SELECT);
+ showToolbars(TITLE_SELECT);