connect(itemhcenter, SIGNAL(clicked()), this, SLOT(itemHCenter()));
connect(itemvcenter, SIGNAL(clicked()), this, SLOT(itemVCenter()));
+ connect(origin_x_left, SIGNAL(clicked()), this, SLOT(slotOriginXClicked()));
+ connect(origin_y_top, SIGNAL(clicked()), this, SLOT(slotOriginYClicked()));
+
connect(value_x, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
connect(value_y, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
connect(value_w, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
buttonAlignNone->blockSignals(false);
buttonAlignCenter->blockSignals(false);
- value_x->setValue((int) i->pos().x());
- value_y->setValue((int) i->pos().y());
+ updateCoordinates(i);
value_w->setValue((int) i->boundingRect().width());
value_h->setValue((int) i->boundingRect().height());
frame_properties->setEnabled(true);
rectBColor->setColor(bcol);
settingUp = false;
rectLineWidth->setValue(rec->pen().width());
- value_x->setValue((int) rec->pos().x());
- value_y->setValue((int) rec->pos().y());
+
+ updateCoordinates(rec);
value_w->setValue((int) rec->rect().width());
value_h->setValue((int) rec->rect().height());
frame_properties->setEnabled(true);
if (l.at(0)->type() == RECTITEM) {
//rect item
QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(l.at(0));
- rec->setPos(value_x->value(), value_y->value());
+ updatePosition(rec);
rec->setRect(QRect(0, 0, value_w->value(), value_h->value()));
} else if (l.at(0)->type() == TEXTITEM) {
//text item
- QGraphicsTextItem *rec = static_cast <QGraphicsTextItem *>(l.at(0));
- rec->setPos(value_x->value(), value_y->value());
+ updatePosition(l.at(0));
}
}
}
+void TitleWidget::updateCoordinates(QGraphicsItem *i)
+{
+ value_x->blockSignals(true);
+
+ if (i->type() == TEXTITEM) {
+
+ QGraphicsTextItem *rec = static_cast <QGraphicsTextItem *> (i);
+
+ // Set the correct x coordinate value
+ if (origin_x_left->isChecked()) {
+ // Origin (0 point) is at m_frameWidth
+ value_x->setValue((int) (rec->pos().x() + rec->boundingRect().width() - m_frameWidth));
+ } else {
+ // Origin is at 0 (default)
+ value_x->setValue((int) rec->pos().x());
+ }
+
+ // Same for y
+ if (origin_y_top->isChecked()) {
+ value_y->setValue((int) (rec->pos().y() + rec->boundingRect().height() - m_frameHeight));
+ } else {
+ value_y->setValue((int) rec->pos().y());
+ }
+
+ } else if (i->type() == RECTITEM) {
+
+ QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *> (i);
+
+ if (origin_x_left->isChecked()) {
+ // Origin (0 point) is at m_frameWidth
+ value_x->setValue((int) (rec->pos().x() + rec->rect().width() - m_frameWidth));
+ } else {
+ // Origin is at 0 (default)
+ value_x->setValue((int) rec->pos().x());
+ }
+
+ if (origin_y_top->isChecked()) {
+ value_y->setValue((int) (rec->pos().y() + rec->rect().height() - m_frameHeight));
+ } else {
+ value_y->setValue((int) rec->pos().y());
+ }
+
+
+ }
+
+ value_x->blockSignals(false);
+}
+
+void TitleWidget::updatePosition(QGraphicsItem *i) {
+
+ if (i->type() == TEXTITEM) {
+ QGraphicsTextItem *rec = static_cast <QGraphicsTextItem *>(i);
+
+ int posX = value_x->value();
+ if (origin_x_left->isChecked()) {
+ /* Origin of the x axis is at m_frameWidth,
+ * and distance to right border of the item is taken.
+ * Add m_frameWidth, subtract object width
+ */
+ posX += m_frameWidth - rec->boundingRect().width();
+ }
+
+ int posY = value_y->value();
+ if (origin_y_top->isChecked()) {
+ /* Same for y axis */
+ posY += m_frameHeight - rec->boundingRect().height();
+ }
+
+ rec->setPos(posX, posY);
+ } else if (i->type() == RECTITEM) {
+
+ QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *> (i);
+
+ int posX = value_x->value();
+ if (origin_x_left->isChecked()) {
+ posX += m_frameWidth - rec->rect().width();
+ }
+
+ int posY = value_y->value();
+ if (origin_y_top->isChecked()) {
+ posY += m_frameHeight - rec->rect().height();
+ }
+
+ rec->setPos(posX, posY);
+ }
+
+}
+
+void TitleWidget::slotOriginXClicked()
+{
+ // Update the text displayed on the button.
+ if (origin_x_left->isChecked()) {
+ origin_x_left->setText(i18n("\u2212X"));
+ } else {
+ origin_x_left->setText(i18n("+X"));
+ }
+
+ QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
+ if (l.size() >= 1) {
+ updateCoordinates(l.at(0));
+ }
+}
+
+void TitleWidget::slotOriginYClicked()
+{
+ // Update the text displayed on the button.
+ if (origin_y_top->isChecked()) {
+ origin_y_top->setText(i18n("\u2212Y"));
+ } else {
+ origin_y_top->setText(i18n("+Y"));
+ }
+
+ QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
+ if (l.size() >= 1) {
+ updateCoordinates(l.at(0));
+ }
+}
+
void TitleWidget::slotChangeBackground()
{
QColor color = kcolorbutton->color();
void TitleWidget::textChanged()
{
+ // TODO not yet working
QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
- if (l.size() == 1 && l.at(0)->type() == TEXTITEM && !l.at(0)->hasFocus()) {
- //kDebug() << ktextedit->document()->toHtml();
- //((QGraphicsTextItem*)l[0])->setHtml(ktextedit->toHtml());
- }
+ if (l.size() >= 1 && l.at(0)->type() == TEXTITEM) {
+ if (origin_x_left->isChecked()) {
+ updatePosition(l.at(0));
+ }
+
+ }
+ //if (l.size() == 1 && l.at(0)->type() == TEXTITEM && !l.at(0)->hasFocus()) {
+ // kDebug() << ktextedit->document()->toHtml();
+ // ((QGraphicsTextItem*)l[0])->setHtml(ktextedit->toHtml());
+ //}
}
void TitleWidget::slotUpdateText()
void writeChoices();
/** \brief Read the last stored choices into the dialog */
void readChoices();
+ /** \brief Update the displayed X/Y coordinates */
+ void updateCoordinates(QGraphicsItem *i);
+ /** \brief Update the item's position */
+ void updatePosition(QGraphicsItem *i);
public slots:
void slotNewText(QGraphicsTextItem *tt);
private slots:
void slotAdjustSelectedItem();
- void slotUpdateZoom(int pos);
+
+ /**
+ * \brief Switches the origin of the x axis between left and right
+ * border of the frame (offset from left/right frame border)
+ * \param originLeft Take left border?
+ *
+ * Called when the origin of the x coorinate has been changed. The
+ * x origin will either be at the left or at the right side of the frame.
+ *
+ * When the origin of the x axis is at the left side, the user can
+ * enter the distance between an element's left border and the left
+ * side of the frame.
+ *
+ * When on the right, the distance from the right border of the
+ * frame to the right border of the element can be entered. This
+ * will result in negative values as long as the element's right
+ * border is at the left of the frame's right border.
+ *
+ * Default value is left.
+ *
+ * |----l----->|#######|<-------r|
+ * | |---w-->| |
+ * | |#######| |
+ * | |
+ * |----------m_frameWidth------>|
+ * | |
+ *
+ * Left selected: Value = l
+ * Right selected: Value = m_frameWidth + r - w
+ *
+ */
+ void slotOriginXClicked();
+ /** \brief Same as slotOriginYChanged, but for the Y axis; default is top.
+ * \param originTop Take top border? */
+ void slotOriginYClicked();
+
void slotZoom(bool up);
+ void slotUpdateZoom(int pos);
void slotAdjustZoom();
void slotZoomOneToOne();
+
void slotUpdateText();
+
void displayBackgroundFrame();
+
void setCurrentItem(QGraphicsItem *item);
+
void slotTextTool();
void slotRectTool();
void slotSelectTool();
void slotImageTool();
+
/** \brief Called when accepted, stores the user selections for next time use */
void slotAccepted();
};