Login  Register

text object drawing

Posted by gnagno91 on Jun 12, 2012; 5:06pm
URL: https://forum.librecad.org/text-object-drawing-tp5706744.html

Hi!
I created a method split in rs_actiondrawtext class to split lines of text input for a TEXT object. I'm not able to create appropriate independent objects for each, playing with methods in rs_actiondrawtext class. The split method looks like:

QVector<RS_Text*> RS_ActionDrawText::split(RS_Text *pText, RS_EntityContainer* parent){
    int m = 100;
   for(int i = 0; i < pText->getLines().size(); i++) {
        QString line = pText->getLines().at(i);
         RS_Text* t = new RS_Text(parent, pText->getData());
         t->setText(line);
         RS_Vector point((t->getInsertionPoint().x)+m,t->getInsertionPoint().y);
         t->setInsertionPoint(point);
        list.push_back(t);
    }
    return list;
}

I modify the init() function and the preparePreview() function in this way:

void RS_ActionDrawText::init(int status) {
    RS_ActionInterface::init(status);
    if (RS_DIALOGFACTORY!=NULL) {

        switch (status) {
        case ShowDialog: {
                reset();
                RS_Text tmp(NULL, data);
                if (RS_DIALOGFACTORY->requestTextDialog(&tmp)) {
                       data = tmp.getData();
                       list = split(&tmp,container);
                        foreach(RS_Text* t, list){
                            RS_TextData obj(t->getInsertionPoint(),
                                            t->getHeight(),
                                            t->getWidth(),
                                            t->getVAlign(),
                                            t->getHAlign(),
                                            t->getText(),
                                            t->getStyle(),
                                            t->getAngle(),
                                            t->getInclination());
                            dataSplitted.append(obj);
                        }

                        setStatus(SetPos);
                        showOptions();
                } else {
                    hideOptions();
                    setFinished();
                }
            }
            break;

        case SetPos:
            RS_DIALOGFACTORY->requestOptions(this, true, true);
            deletePreview();
            preview->setVisible(true);
            preparePreview();
            break;

        default:
            break;
        }
    }
}
void RS_ActionDrawText::preparePreview() {
    for(int i = 0; i < list.size(); i++){
       RS_Text* text = new RS_Text(preview, dataSplitted.at(i));
        text->update();

        preview->addEntity(text);
        textChanged = false;
   }
    data.insertionPoint = pos;
}

I also added two variable in the class: QVector>RS_Text*> list and QVector<RS_TextData> data.
Luca