+
+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);
+
+ itemzoom->setEnabled(false);
+ itemrotatex->setEnabled(false);
+ itemrotatey->setEnabled(false);
+ itemrotatez->setEnabled(false);
+ frame_properties->setEnabled(false);
+ } else {
+ effect_frame->setEnabled(true);
+ frame_properties->setEnabled(true);
+ if (referenceItem != m_startViewport && referenceItem != m_endViewport) {
+ itemzoom->setEnabled(true);
+ itemrotatex->setEnabled(true);
+ itemrotatey->setEnabled(true);
+ itemrotatez->setEnabled(true);
+ } else {
+ itemzoom->setEnabled(false);
+ itemrotatex->setEnabled(false);
+ itemrotatey->setEnabled(false);
+ itemrotatez->setEnabled(false);
+ updateInfoText();
+ }
+ if (referenceItem->type() == TEXTITEM) {
+ showToolbars(TITLE_TEXT);
+ QGraphicsTextItem* i = static_cast <QGraphicsTextItem *>(referenceItem);
+ if (!i->toPlainText().isEmpty()) {
+ // We have an existing text item selected
+ if (!i->data(100).isNull()) {
+ // Item has an effect
+ QStringList effdata = i->data(100).toStringList();
+ QString effectName = effdata.takeFirst();
+ if (effectName == "typewriter") {
+ QStringList params = effdata.at(0).split(';');
+ typewriter_delay->setValue(params.at(0).toInt());
+ typewriter_start->setValue(params.at(1).toInt());
+ effect_list->setCurrentIndex(effect_list->findData((int) TYPEWRITEREFFECT));
+ effect_stack->setHidden(false);
+ }
+ } else {
+#if QT_VERSION >= 0x040600
+ if (i->graphicsEffect()) {
+ QGraphicsBlurEffect *blur = static_cast <QGraphicsBlurEffect *>(i->graphicsEffect());
+ if (blur) {
+ effect_list->setCurrentIndex(effect_list->findData((int) BLUREFFECT));
+ int rad = (int) blur->blurRadius();
+ blur_radius->setValue(rad);
+ effect_stack->setHidden(false);
+ } else {
+ QGraphicsDropShadowEffect *shad = static_cast <QGraphicsDropShadowEffect *>(i->graphicsEffect());
+ if (shad) {
+ effect_list->setCurrentIndex(effect_list->findData((int) SHADOWEFFECT));
+ shadow_radius->setValue(shad->blurRadius());
+ shadow_x->setValue(shad->xOffset());
+ shadow_y->setValue(shad->yOffset());
+ effect_stack->setHidden(false);
+ }
+ }
+ } else {
+ effect_list->setCurrentIndex(effect_list->findData((int) NOEFFECT));
+ effect_stack->setHidden(true);
+ }
+#else
+ effect_list->setCurrentIndex(effect_list->findData((int) NOEFFECT));
+ effect_stack->setHidden(true);
+#endif
+ }
+ font_size->blockSignals(true);
+ font_family->blockSignals(true);
+ font_weight_box->blockSignals(true);
+ buttonItalic->blockSignals(true);
+ buttonUnder->blockSignals(true);
+ fontColorButton->blockSignals(true);
+#if not KDE_IS_VERSION(4,5,0)
+ textAlpha->blockSignals(true);
+#endif
+ buttonAlignLeft->blockSignals(true);
+ buttonAlignRight->blockSignals(true);
+ buttonAlignNone->blockSignals(true);
+ buttonAlignCenter->blockSignals(true);
+
+ QFont font = i->font();
+ font_family->setCurrentFont(font);
+ font_size->setValue(font.pixelSize());
+ m_scene->slotUpdateFontSize(font.pixelSize());
+ buttonItalic->setChecked(font.italic());
+ buttonUnder->setChecked(font.underline());
+ setFontBoxWeight(font.weight());
+
+ QTextCursor cursor(i->document());
+ cursor.select(QTextCursor::Document);
+ QColor color = cursor.charFormat().foreground().color();
+#if not KDE_IS_VERSION(4,5,0)
+ textAlpha->setValue(color.alpha());
+ color.setAlpha(255);
+#endif
+ fontColorButton->setColor(color);
+
+ if (!i->data(101).isNull()) {
+ textOutline->blockSignals(true);
+ textOutline->setValue(i->data(101).toDouble() * 10);
+ textOutline->blockSignals(false);
+ }
+ if (!i->data(102).isNull()) {
+ textOutlineColor->blockSignals(true);
+ QVariant variant = i->data(102);
+ color = variant.value<QColor>();
+#if not KDE_IS_VERSION(4,5,0)
+ textOutlineAlpha->blockSignals(true);
+ textOutlineAlpha->setValue(color.alpha());
+ color.setAlpha(255);
+ textOutlineAlpha->blockSignals(false);
+#endif
+ textOutlineColor->setColor(color);
+ textOutlineColor->blockSignals(false);
+ }
+ QTextCursor cur = i->textCursor();
+ QTextBlockFormat format = cur.blockFormat();
+ if (i->textWidth() == -1) buttonAlignNone->setChecked(true);
+ else if (format.alignment() == Qt::AlignHCenter) buttonAlignCenter->setChecked(true);
+ else if (format.alignment() == Qt::AlignRight) buttonAlignRight->setChecked(true);
+ else if (format.alignment() == Qt::AlignLeft) buttonAlignLeft->setChecked(true);
+
+ font_size->blockSignals(false);
+ font_family->blockSignals(false);
+ font_weight_box->blockSignals(false);
+ buttonItalic->blockSignals(false);
+ buttonUnder->blockSignals(false);
+ fontColorButton->blockSignals(false);
+#if not KDE_IS_VERSION(4,5,0)
+ textAlpha->blockSignals(false);
+#endif
+ buttonAlignLeft->blockSignals(false);
+ buttonAlignRight->blockSignals(false);
+ buttonAlignNone->blockSignals(false);
+ buttonAlignCenter->blockSignals(false);
+
+ // mbt 1607: Select text if the text item is an unchanged template item.
+ if (i->property("isTemplate").isValid()) {
+ cur.setPosition(0, QTextCursor::MoveAnchor);
+ cur.select(QTextCursor::Document);
+ i->setTextCursor(cur);
+ // Make text editable now.
+ i->grabKeyboard();
+ i->setTextInteractionFlags(Qt::TextEditorInteraction);
+ }
+ }
+
+ updateAxisButtons(i);
+ updateCoordinates(i);
+ updateDimension(i);
+ enableToolbars(TITLE_TEXT);
+
+ } else if ((referenceItem)->type() == RECTITEM) {
+ showToolbars(TITLE_RECTANGLE);
+ settingUp = true;
+ QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(referenceItem);
+ if (rec == m_startViewport || rec == m_endViewport) {
+ /*toolBox->setCurrentIndex(3);
+ toolBox->widget(0)->setEnabled(false);
+ toolBox->widget(1)->setEnabled(false);*/
+ enableToolbars(TITLE_SELECT);
+ } else {
+ /*toolBox->widget(0)->setEnabled(true);
+ toolBox->widget(1)->setEnabled(true);
+ toolBox->setCurrentIndex(0);*/
+ //toolBox->setItemEnabled(3, true);
+#if not KDE_IS_VERSION(4,5,0)
+ rectFAlpha->setValue(rec->pen().color().alpha());
+ rectBAlpha->setValue(rec->brush().color().alpha());
+#endif
+ //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());
+ enableToolbars(TITLE_RECTANGLE);
+ }
+
+ updateAxisButtons(referenceItem);
+ updateCoordinates(rec);
+ updateDimension(rec);
+
+ } else if (referenceItem->type() == IMAGEITEM) {
+ showToolbars(TITLE_IMAGE);
+
+ updateCoordinates(referenceItem);
+ updateDimension(referenceItem);
+
+ enableToolbars(TITLE_IMAGE);
+
+ } else {
+ //toolBox->setCurrentIndex(0);
+ showToolbars(TITLE_SELECT);
+ enableToolbars(TITLE_SELECT);
+ frame_properties->setEnabled(false);
+ }
+ zValue->setValue((int)referenceItem->zValue());
+ if (!referenceItem->data(ZOOMFACTOR).isNull()) itemzoom->setValue(referenceItem->data(ZOOMFACTOR).toInt());
+ else itemzoom->setValue((int)(m_transformations.value(referenceItem).scalex * 100.0 + 0.5));
+ itemrotatex->setValue((int)(m_transformations.value(referenceItem).rotatex));
+ itemrotatey->setValue((int)(m_transformations.value(referenceItem).rotatey));
+ itemrotatez->setValue((int)(m_transformations.value(referenceItem).rotatez));
+ }
+
+
+ effect_list->blockSignals(blockEff);
+ itemrotatex->blockSignals(blockRX);
+ itemrotatey->blockSignals(blockRY);
+ itemrotatez->blockSignals(blockRZ);
+ itemzoom->blockSignals(blockZoom);
+ origin_x_left->blockSignals(blockOX);
+ origin_y_top->blockSignals(blockOY);
+ value_x->blockSignals(blockX);
+ value_y->blockSignals(blockY);
+ value_w->blockSignals(blockW);
+ value_h->blockSignals(blockH);
+}
+
+#include "titlewidget.moc"