/* set all margin to zero qt4 send 12 top 12 bottom by default */
QTextBlockFormat DefaultMargin( QTextBlockFormat rootformats )
{
    rootformats.setBottomMargin(4);
    rootformats.setTopMargin(4);
    rootformats.setRightMargin(0);
    rootformats.setLeftMargin(0);
    rootformats.setAlignment( Qt::AlignLeft );
    return rootformats;
}
void TextZone::changeTextStyleSlot(int styleIndex)
{


    QTextBlockFormat blockFormat;
    blockFormat.setBottomMargin(textStyles->blockBottomMarginAt(styleIndex));
    blockFormat.setTextIndent(textStyles->blockFirstLineIndentAt(styleIndex));
    blockFormat.setLeftMargin(textStyles->blockLeftMarginAt(styleIndex));
    blockFormat.setAlignment(textStyles->blockAlignmentTrueNameAt(styleIndex));
    blockFormat.setTopMargin(0);
    blockFormat.setRightMargin(0);
    QTextCharFormat charFormat;
    charFormat.setFontPointSize(textStyles->fontSizeAt(styleIndex));
    charFormat.setFontFamily(textStyles->fontFamilyAt(styleIndex));
    //    charFormat.setFontItalic(textStyles->fontItalicAt(styleIndex));
    //    if (textStyles->fontBoldAt(styleIndex) == true)
    //        charFormat.setFontWeight(75);
    //    else
    //        charFormat.setFontWeight(50);
    //    charFormat.setFontUnderline(textStyles->fontUnderlineAt(styleIndex));
    //    charFormat.setFontStrikeOut(textStyles->fontStrikeOutAt(styleIndex));

    //    charFormat.clearForeground();


    QTextCursor tCursor = this->textCursor();

    // select all of the blocks selected :

    QTextCursor tStartCursor = this->textCursor();
    tStartCursor.setPosition(tCursor.selectionStart());
    tStartCursor.movePosition(QTextCursor::StartOfBlock);
    int startFirstBlock = tStartCursor.position();

    QTextCursor tEndCursor =  this->textCursor();
    tEndCursor.setPosition(tCursor.selectionEnd());
    tEndCursor.movePosition(QTextCursor::EndOfBlock);
    int endLastBlock = tEndCursor.position();

    tCursor.setPosition(startFirstBlock);
    tCursor.setPosition(endLastBlock, QTextCursor::KeepAnchor);


    // merge :
    tCursor.mergeBlockFormat(blockFormat);
    tCursor.mergeCharFormat(charFormat);
    this->mergeCurrentCharFormat(charFormat);

}
void PrintDialog::insertSeparatorLine(QTextCursor & cursor)
{
	QTextBlockFormat blockSeparatorFormat;
	blockSeparatorFormat.setAlignment(Qt::AlignCenter);
	blockSeparatorFormat.setTopMargin(10.0);
	blockSeparatorFormat.setBottomMargin(10.0);

	QTextCharFormat separatorFormat;
	separatorFormat.setFontCapitalization(QFont::AllUppercase);
	separatorFormat.setFontWeight(50);
	separatorFormat.setFontPointSize(10.0);

	cursor.insertBlock(blockSeparatorFormat);
	cursor.insertText("_______________________________________________",separatorFormat);
}
void PrintDialog::insertTitleResult(QTextCursor & cursor, const QString & raceName)
{
	QTextBlockFormat blockTitleFormat;
	blockTitleFormat.setAlignment(Qt::AlignCenter);
	blockTitleFormat.setTopMargin(0.0);
	blockTitleFormat.setBottomMargin(80.0);

	QTextCharFormat titleFormat;
	titleFormat.setFontPointSize(20);
	titleFormat.setFontWeight(50);
	titleFormat.setFontCapitalization(QFont::AllUppercase);

	cursor.insertBlock(blockTitleFormat);
	cursor.insertText(raceName, titleFormat);
}
QTextDocument *Exporter::prepareNoteDoc(QTextDocument *noteDoc)
{
    QTextDocument *textDocument = noteDoc->clone(this);




    //cut blank spaces at the begining and end :



    QTextCursor *tCursor = new QTextCursor(textDocument);
    tCursor->movePosition(QTextCursor::Start, QTextCursor::MoveAnchor,1);
    tCursor->movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor,1);

    while(tCursor->selectedText() == " "){
        tCursor->deleteChar();
        tCursor->movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor,1);
    }

    tCursor->movePosition(QTextCursor::End, QTextCursor::MoveAnchor,1);
    tCursor->movePosition(QTextCursor::PreviousCharacter, QTextCursor::KeepAnchor,1);

    while(tCursor->selectedText() == " "){
        tCursor->deleteChar();
        tCursor->movePosition(QTextCursor::PreviousCharacter, QTextCursor::KeepAnchor,1);
    }

    //set text config :

    QTextBlockFormat blockFormat;
    blockFormat.setBottomMargin(0);
    blockFormat.setTopMargin(0);
    blockFormat.setTextIndent(72);
    blockFormat.setLineHeight(200, QTextBlockFormat::ProportionalHeight);
    blockFormat.setAlignment(Qt::AlignJustify);
    QTextCharFormat charFormat;
    charFormat.setFontPointSize(12);
    charFormat.setFontFamily("Courrier");

    tCursor->select(QTextCursor::Document);
    tCursor->mergeBlockCharFormat(charFormat);
    tCursor->mergeBlockFormat(blockFormat);


    return textDocument;
}
Exemple #6
0
WndListenJob::WndListenJob( int JobId, const QString & Name):
   WndText( "Listen Job"),
   jobid( JobId),
   jobname( Name)
{
#if QT_VERSION >= 0x040300
   layout->setContentsMargins( 10, 10, 10, 10);
#endif
   setContentsMargins(1,1,1,1);

   qTextEdit->moveCursor( QTextCursor::End, QTextCursor::KeepAnchor);
   QTextCursor cursor = qTextEdit->textCursor();
   QTextBlockFormat blockFormat;
   blockFormat.setTopMargin(-5);
   blockFormat.setBottomMargin(-5);
   cursor.setBlockFormat( blockFormat);
   qTextEdit->setTextCursor( cursor);
   qTextEdit->setWordWrapMode( QTextOption::NoWrap);
   setWindowTitle( jobname);

   af::MCListenAddress mclass( af::MCListenAddress::TOLISTEN, Watch::getClientAddress(), jobid);
   Watch::sendMsg( new af::Msg( af::Msg::TTaskListenOutput, &mclass));
}
void PrintDialog::insertHeaderResult(QTextCursor & cursor, const QString & location, const QString & date)
{
	QTextBlockFormat blockHeaderFormat;
	blockHeaderFormat.setAlignment(Qt::AlignLeft);
	blockHeaderFormat.setTopMargin(5.0);
	blockHeaderFormat.setBottomMargin(0.0);
	blockHeaderFormat.setLeftMargin(20.0);

	QTextCharFormat headerFormat1;
	headerFormat1.setFontPointSize(10);
	headerFormat1.setFontWeight(50);
	QTextCharFormat headerFormat2;
	headerFormat2.setFontPointSize(10);
	headerFormat2.setFontWeight(50);

	cursor.insertBlock(blockHeaderFormat);
	cursor.insertText(tr("Location : "), headerFormat1);
	cursor.insertText(location, headerFormat2);

	cursor.insertBlock(blockHeaderFormat);
	cursor.insertText(tr("Date : "), headerFormat1);
	cursor.insertText(date, headerFormat2);
}
QTextDocument * Exporter::buildFinalDoc()
{
    //search for checked items :

    QDomDocument domDoc = hub->project()->mainTreeDomDoc();
    QDomElement root = domDoc.documentElement();

    QList<QDomElement> itemList = searchForCheckedItems(root);

    if(itemList.size() == 0)
        return new QTextDocument();


    // set up the progress bar :
    QWidget *progressWidget = new QWidget(this, Qt::Dialog | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
    QHBoxLayout *progressLayout = new QHBoxLayout(progressWidget);
    QProgressBar *progressBar = new QProgressBar(progressWidget);
    int progressValue = 0;

    progressLayout->addWidget(progressBar);
    progressWidget->setLayout(progressLayout);

    progressBar->setMaximum(itemList.size());
    progressBar->setValue(progressValue);
    progressWidget->show();



    //    QString debug;
    //    qDebug() << "itemList" << debug.setNum(itemList->size());

    QTextDocument *textDocument = new QTextDocument(this);
    QTextEdit *edit = new QTextEdit(this);

    textDocument->setDefaultStyleSheet("p, li { white-space: pre-wrap; } p{line-height: 2em; font-family:'Liberation Serif'; font-size:12pt;margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:72px;}");



    for(int i = 0; i < itemList.size(); ++i){
        QDomElement element = itemList.at(i);
        QTextCursor *tCursor = new QTextCursor(textDocument);

        QTextBlockFormat blockFormatLeft;
        blockFormatLeft.setBottomMargin(0);
        blockFormatLeft.setTopMargin(0);
        blockFormatLeft.setTextIndent(72);
        blockFormatLeft.setLineHeight(200, QTextBlockFormat::ProportionalHeight);
        blockFormatLeft.setAlignment(Qt::AlignJustify);
        QTextCharFormat charFormatLeft;
        charFormatLeft.setFontPointSize(12);
        charFormatLeft.setFontFamily("Courrier");

        QTextBlockFormat blockFormatCenter;
        blockFormatCenter.setAlignment(Qt::AlignCenter);


        if(element.tagName() != "separator"){

            qDebug() << "element name : "+ element.attribute("name");
            MainTextDocument *textDoc = hub->project()->findChild<MainTextDocument *>("textDoc_" + element.attribute("number"));
            MainTextDocument *synDoc = hub->project()->findChild<MainTextDocument *>("synDoc_" + element.attribute("number"));
            MainTextDocument *noteDoc = hub->project()->findChild<MainTextDocument *>("noteDoc_" + element.attribute("number"));

            QTextDocumentFragment textFrag(prepareTextDoc(textDoc));
            QTextDocumentFragment synFrag(prepareSynDoc(synDoc));
            QTextDocumentFragment noteFrag(prepareNoteDoc(noteDoc));

            edit->setDocument(textDocument);




            if(element.tagName() == "book"){
                textDocument->setMetaInformation(QTextDocument::DocumentTitle,element.attribute("name", ""));
                edit->append("<h1>" + element.attribute("name", "") + "</h1>");
                tCursor->movePosition(QTextCursor::End, QTextCursor::MoveAnchor,1);
                tCursor->mergeBlockFormat(blockFormatCenter);
                edit->append("<h4>" + QDateTime::currentDateTime().toString() + "</h4>");
                tCursor->movePosition(QTextCursor::End, QTextCursor::MoveAnchor,1);
                tCursor->mergeBlockFormat(blockFormatCenter);
                edit->append("<br>");
                edit->append("<br>");

            }
            if(element.tagName() == "act"){
                edit->append("<br>");
                edit->append("<br>");
                edit->append("<h2>" + element.attribute("name", "") + "</h2>");
                tCursor->movePosition(QTextCursor::End, QTextCursor::MoveAnchor,1);
                tCursor->mergeBlockFormat(blockFormatCenter);
                edit->append("<br>");

            }
            if(element.tagName() == "chapter"){
                edit->append("<br>");
                edit->append("<br>");
                edit->append("<h2>" + element.attribute("name", "") + "</h2>");
                tCursor->movePosition(QTextCursor::End, QTextCursor::MoveAnchor,1);
                tCursor->mergeBlockFormat(blockFormatCenter);
                edit->append("<br>");

            }

            if(element.tagName() == "scene" && ui->setSceneTitlesComboBox->currentIndex() != 0){
                QString sceneTitle;
                switch (ui->setSceneTitlesComboBox->currentIndex()){
                case 1:
                    sceneTitle = element.attribute("name", "");
                    break;
                case 2:
                    sceneTitle = "###";
                    break;
                case 3:
                    sceneTitle = "***";
                    break;
                default:
                    sceneTitle = element.attribute("name", "");
                    break;

                }

                edit->append("<br>");
                edit->append("<h3>" + sceneTitle + "</h3>");
                tCursor->movePosition(QTextCursor::End, QTextCursor::MoveAnchor,1);
                tCursor->mergeBlockFormat(blockFormatCenter);
                edit->append("<br>");

            }

            if(ui->synopsisCheckBox->isChecked() && !synFrag.isEmpty()){
                edit->append("<br>");
                edit->append("<h4>" + tr("Synopsis") + "</h4>");
                tCursor->movePosition(QTextCursor::End, QTextCursor::MoveAnchor,1);
                tCursor->mergeBlockFormat(blockFormatCenter);
                edit->append("<br>");
                tCursor->movePosition(QTextCursor::End, QTextCursor::MoveAnchor,1);
                tCursor->insertBlock(blockFormatLeft, charFormatLeft);
                tCursor->insertFragment(synFrag);
            }

            if(ui->notesCheckBox->isChecked() && !noteFrag.isEmpty()){
                edit->append("<br>");
                edit->append("<h4>" + tr("Note") + "</h4>");
                tCursor->movePosition(QTextCursor::End, QTextCursor::MoveAnchor,1);
                tCursor->mergeBlockFormat(blockFormatCenter);
                edit->append("<br>");
                tCursor->movePosition(QTextCursor::End, QTextCursor::MoveAnchor,1);
                tCursor->insertBlock(blockFormatLeft, charFormatLeft);
                tCursor->insertFragment(noteFrag);
            }

            if(ui->storyCheckBox->isChecked()){
                if((ui->synopsisCheckBox->isChecked() || ui->notesCheckBox->isChecked()) && !textFrag.isEmpty()){
                    tCursor->insertBlock();
                    tCursor->insertHtml("<h4>" + tr("Story") + "</h4>");
                    tCursor->mergeBlockFormat(blockFormatCenter);
                    tCursor->insertBlock();

                }
                tCursor->insertHtml("<br>");
                //                tCursor->movePosition(QTextCursor::End, QTextCursor::MoveAnchor,1);
                tCursor->insertBlock(blockFormatLeft, charFormatLeft);
                tCursor->insertFragment(textFrag);
                //                edit->append(textFrag->toHtml());
            }
        }
        else if(element.tagName() == "separator"){
            edit->append("<br>");
            edit->append("<h3>#</h3>");
            tCursor->movePosition(QTextCursor::End, QTextCursor::MoveAnchor,1);
            tCursor->mergeBlockFormat(blockFormatCenter);
            edit->append("<br>");
            tCursor->movePosition(QTextCursor::End, QTextCursor::MoveAnchor,1);
            tCursor->mergeBlockFormat(blockFormatLeft);
        }




        progressValue += 1;
        progressBar->setValue(progressValue);

    }
    QRegExp reg("-qt-paragraph-type:.*;|margin-top:.*;|margin-bottom:.*;|margin-left:.*;|margin-right:.*;|-qt-block-indent:.*;|text-indent:.*;|font-family:.*;|font-size:.*;");
    reg.setMinimal(true);
    textDocument->setHtml(textDocument->toHtml().remove(reg));

    //find and change final page css style :

    //textDocument->setDefaultStyleSheet("p, li { white-space: pre-wrap; } p{line-height: 2em; font-family:'Liberation Serif'; font-size:14pt;margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:72px;}");

    //            <style type="text/css">
    //            p, li { white-space: pre-wrap; }
    //            </style>

    //            tCursor
    //            qDebug() << textDocument->toHtml();


    progressWidget->close();

    return textDocument;
}
QTextHtmlImporter::ProcessNodeResult QTextHtmlImporter::processSpecialNodes()
{
    switch (currentNode->id) {
        case Html_body:
            if (currentNode->charFormat.background().style() != Qt::NoBrush) {
                QTextFrameFormat fmt = doc->rootFrame()->frameFormat();
                fmt.setBackground(currentNode->charFormat.background());
                doc->rootFrame()->setFrameFormat(fmt);
                const_cast<QTextHtmlParserNode *>(currentNode)->charFormat.clearProperty(QTextFormat::BackgroundBrush);
            }
            break;

        case Html_ol:
        case Html_ul: {
            QTextListFormat::Style style = currentNode->listStyle;

            if (currentNode->id == Html_ul && !currentNode->hasOwnListStyle && currentNode->parent) {
                const QTextHtmlParserNode *n = &at(currentNode->parent);
                while (n) {
                    if (n->id == Html_ul) {
                        style = nextListStyle(currentNode->listStyle);
                    }
                    if (n->parent)
                        n = &at(n->parent);
                    else
                        n = 0;
                }
            }

            QTextListFormat listFmt;
            listFmt.setStyle(style);

            ++indent;
            if (currentNode->hasCssListIndent)
                listFmt.setIndent(currentNode->cssListIndent);
            else
                listFmt.setIndent(indent);

            List l;
            l.format = listFmt;
            l.listNode = currentNodeIdx;
            lists.append(l);
            compressNextWhitespace = true;

            // broken html: <ul>Text here<li>Foo
            const QString simpl = currentNode->text.simplified();
            if (simpl.isEmpty() || simpl.at(0).isSpace())
                return ContinueWithNextNode;
            break;
        }

        case Html_table: {
            Table t = scanTable(currentNodeIdx);
            tables.append(t);
            hasBlock = false;
            return ContinueWithNextNode;
        }

        case Html_tr:
            return ContinueWithNextNode;

        case Html_img: {
            QTextImageFormat fmt;
            fmt.setName(currentNode->imageName);

            fmt.merge(currentNode->charFormat);

            if (currentNode->imageWidth >= 0)
                fmt.setWidth(currentNode->imageWidth);
            if (currentNode->imageHeight >= 0)
                fmt.setHeight(currentNode->imageHeight);

            cursor.insertImage(fmt, QTextFrameFormat::Position(currentNode->cssFloat));

            cursor.movePosition(QTextCursor::Left, QTextCursor::KeepAnchor);
            cursor.mergeCharFormat(currentNode->charFormat);
            cursor.movePosition(QTextCursor::Right);

            hasBlock = false;
            return ContinueWithNextNode;
        }

        case Html_hr: {
            QTextBlockFormat blockFormat = currentNode->blockFormat;
            blockFormat.setTopMargin(topMargin(currentNodeIdx));
            blockFormat.setBottomMargin(bottomMargin(currentNodeIdx));
            blockFormat.setProperty(QTextFormat::BlockTrailingHorizontalRulerWidth, currentNode->width);
            if (hasBlock && importMode == ImportToDocument)
                cursor.mergeBlockFormat(blockFormat);
            else
                appendBlock(blockFormat);
            hasBlock = false;
            return ContinueWithNextNode;
        }

        default: break;
    }
    return ContinueWithCurrentNode;
}
Exemple #10
0
void CDiaryEdit::draw(QTextDocument& doc)
{
    CDiaryEditLock lock(this);
    QFontMetrics fm(QFont(font().family(),10));

    bool hasGeoCaches = false;
    int cnt;
    int w = doc.textWidth();
    int pointSize = ((10 * (w - 2 * ROOT_FRAME_MARGIN)) / (CHAR_PER_LINE *  fm.width("X")));

    if(pointSize == 0) return;

    doc.setUndoRedoEnabled(false);

    QFont f = textEdit->font();
    f.setPointSize(pointSize);
    textEdit->setFont(f);

    QTextCharFormat fmtCharHeading1;
    fmtCharHeading1.setFont(f);
    fmtCharHeading1.setFontWeight(QFont::Black);
    fmtCharHeading1.setFontPointSize(f.pointSize() + 8);

    QTextCharFormat fmtCharHeading2;
    fmtCharHeading2.setFont(f);
    fmtCharHeading2.setFontWeight(QFont::Black);
    fmtCharHeading2.setFontPointSize(f.pointSize() + 4);

    QTextCharFormat fmtCharStandard;
    fmtCharStandard.setFont(f);

    QTextCharFormat fmtCharHeader;
    fmtCharHeader.setFont(f);
    fmtCharHeader.setBackground(Qt::darkBlue);
    fmtCharHeader.setFontWeight(QFont::Bold);
    fmtCharHeader.setForeground(Qt::white);

    QTextBlockFormat fmtBlockStandard;
    fmtBlockStandard.setTopMargin(10);
    fmtBlockStandard.setBottomMargin(10);
    fmtBlockStandard.setAlignment(Qt::AlignJustify);

    QTextFrameFormat fmtFrameStandard;
    fmtFrameStandard.setTopMargin(5);
    fmtFrameStandard.setBottomMargin(5);
    fmtFrameStandard.setWidth(w - 2 * ROOT_FRAME_MARGIN);

    QTextFrameFormat fmtFrameRoot;
    fmtFrameRoot.setTopMargin(ROOT_FRAME_MARGIN);
    fmtFrameRoot.setBottomMargin(ROOT_FRAME_MARGIN);
    fmtFrameRoot.setLeftMargin(ROOT_FRAME_MARGIN);
    fmtFrameRoot.setRightMargin(ROOT_FRAME_MARGIN);

    QTextTableFormat fmtTableStandard;
    fmtTableStandard.setBorder(1);
    fmtTableStandard.setBorderBrush(Qt::black);
    fmtTableStandard.setCellPadding(4);
    fmtTableStandard.setCellSpacing(0);
    fmtTableStandard.setHeaderRowCount(1);
    fmtTableStandard.setTopMargin(10);
    fmtTableStandard.setBottomMargin(20);
    fmtTableStandard.setWidth(w - 2 * ROOT_FRAME_MARGIN);

    QVector<QTextLength> constraints;
    constraints << QTextLength(QTextLength::FixedLength, 32);
    constraints << QTextLength(QTextLength::VariableLength, 50);
    constraints << QTextLength(QTextLength::VariableLength, 100);
    fmtTableStandard.setColumnWidthConstraints(constraints);

    doc.rootFrame()->setFrameFormat(fmtFrameRoot);
    QTextCursor cursor = doc.rootFrame()->firstCursorPosition();

    cursor.insertText(diary.getName(), fmtCharHeading1);
    cursor.setCharFormat(fmtCharStandard);
    cursor.setBlockFormat(fmtBlockStandard);

    diary.diaryFrame = cursor.insertFrame(fmtFrameStandard);
    {
        QTextCursor cursor1(diary.diaryFrame);

        cursor1.setCharFormat(fmtCharStandard);
        cursor1.setBlockFormat(fmtBlockStandard);

        if(diary.getComment().isEmpty())
        {
            cursor1.insertText(tr("Add your own text here..."));
        }
        else
        {
            cursor1.insertHtml(diary.getComment());
        }
        cursor.setPosition(cursor1.position()+1);
    }

    if(!diary.getWpts().isEmpty())
    {
        QList<CWpt*>& wpts = diary.getWpts();
        cursor.insertText(tr("Waypoints"),fmtCharHeading2);

        QTextTable * table = cursor.insertTable(wpts.count()+1, eMax, fmtTableStandard);
        diary.tblWpt = table;
        table->cellAt(0,eSym).setFormat(fmtCharHeader);
        table->cellAt(0,eInfo).setFormat(fmtCharHeader);
        table->cellAt(0,eComment).setFormat(fmtCharHeader);

        table->cellAt(0,eInfo).firstCursorPosition().insertText(tr("Info"));
        table->cellAt(0,eComment).firstCursorPosition().insertText(tr("Comment"));

        cnt = 1;
        qSort(wpts.begin(), wpts.end(), qSortWptLessTime);

        foreach(CWpt * wpt, wpts)
        {

            table->cellAt(cnt,eSym).firstCursorPosition().insertImage(wpt->getIcon().toImage().scaledToWidth(16, Qt::SmoothTransformation));
            table->cellAt(cnt,eInfo).firstCursorPosition().insertText(wpt->getName() + "\n" + wpt->getInfo(), fmtCharStandard);

            QTextCursor c = table->cellAt(cnt,eComment).firstCursorPosition();
            c.setCharFormat(fmtCharStandard);
            c.setBlockFormat(fmtBlockStandard);
            c.insertHtml(wpt->getComment());

            if(wpt->isGeoCache())
            {
                hasGeoCaches = true;
            }
            cnt++;
        }
TableauDeRemplissage::TableauDeRemplissage(int idEvenement, QObject *parent)
    : Etat(tr("Tableau de remplissage"), idEvenement, parent)
{
    QSqlQuery query;
    if (query.prepare("select *"
                      " from tableau_de_remplissage"
                      " where id_evenement=:id_evenement")) {
        query.bindValue(":id_evenement", idEvenement);
        if (query.exec()) {
            // FIXME : ce rapport devrait être une feuille de calcul

            QString symboleAcceptee = "●";
            QString symboleProposee = "◍";
            QString symbolePossible = "○";
            QString symboleManquante = "◌";

            QTextCursor c(this);

            QTextBlockFormat formatDuTitreDeLaLegende;
            formatDuTitreDeLaLegende.setBottomMargin(10);

            QTextCharFormat formatDesCaracteresDuTitreDeLaLegende;
            formatDesCaracteresDuTitreDeLaLegende.setUnderlineStyle(QTextCharFormat::SingleUnderline);

            QTextBlockFormat formatDesBlocsDeLaLegende;

            QTextCharFormat formatDesCaracteresDeLaLegende;

            QTextListFormat formatDeLaListeDeLaLegende;

            QTextBlockFormat formatDuBlocJour;
            formatDuBlocJour.setPageBreakPolicy(QTextFormat::PageBreak_AlwaysBefore);
            formatDuBlocJour.setAlignment(Qt::AlignCenter);
            formatDuBlocJour.setBottomMargin(20);

            QTextCharFormat formatDesCaracteresDuJour;
            formatDesCaracteresDuJour.setFontCapitalization(QFont::Capitalize);
            formatDesCaracteresDuJour.setFontPointSize(14);
            formatDesCaracteresDuJour.setFontWeight(QFont::Bold);

            QTextBlockFormat formatDuBlocTour;
            formatDuBlocTour.setTopMargin(20);

            QTextCharFormat formatDesCaracteresDuTour;
            formatDesCaracteresDuTour.setFontWeight(QFont::Bold);

            QTextBlockFormat formatDuBlocDesResponsables;

            QTextCharFormat formatDesCaracteresDesResponsables;

            QTextBlockFormat formatDuBlocDuRemplissage;

            QTextCharFormat formatDesCaracteresDuRemplissage;

            if (query.first()) {
                c.movePosition(QTextCursor::End);
                c.insertBlock(formatDuTitreDeLaLegende, formatDesCaracteresDuTitreDeLaLegende);
                c.insertText(tr("Légende"));
                c.insertBlock(formatDesBlocsDeLaLegende, formatDesCaracteresDeLaLegende);
                c.insertList(formatDeLaListeDeLaLegende);
                c.insertText(tr("%1 affectation acceptée ou validée").arg(symboleAcceptee));
                c.insertText("\n");
                c.insertText(tr("%1 affectation proposée, en attente d'acceptation").arg(symboleProposee));
                c.insertText("\n");
                c.insertText(tr("%1 affectation possible, à proposer ou valider").arg(symbolePossible));
                c.insertText("\n");
                c.insertText(tr("%1 affectation manquante, reste à créer").arg(symboleManquante));
                QSqlRecord r = query.record();
                do {
                    QDate jour = r.value("debut_tour").toDate();
                    c.insertBlock(formatDuBlocJour, formatDesCaracteresDuJour);
                    c.insertText(QLocale().toString(jour));
                    do {
                        int
                                min = r.value("min").toInt(),
                                max = r.value("max").toInt(),
                                possibles = r.value("nombre_affectations_possibles").toInt(),
                                proposees = r.value("nombre_affectations_proposees").toInt(),
                                acceptees = r.value("nombre_affectations_validees_ou_acceptees").toInt(),
                                trouvees = acceptees + proposees + possibles,
                                manquantes = trouvees < min ? min - trouvees : 0,
                                enTrop = max < trouvees ? trouvees - max : 0;
                        QString responsables = r.value("liste_responsables").toString();
                        c.insertBlock(formatDuBlocTour, formatDesCaracteresDuTour);
                        c.insertText(tr("De %1 à %2 / %3")
                                     .arg(r.value("debut_tour").toTime().toString("H:mm"))
                                     .arg(r.value("fin_tour").toTime().toString("H:mm"))
                                     .arg(r.value("nom_poste").toString())
                                     );
                        if (!responsables.isEmpty()) {
                            c.insertBlock(formatDuBlocDesResponsables, formatDesCaracteresDesResponsables);
                            c.insertText(tr("Responsable(s) : %1").arg(responsables));
                        }
                        c.insertBlock(formatDuBlocDuRemplissage, formatDesCaracteresDuRemplissage);
                        c.insertText(symboleAcceptee.repeated(acceptees));
                        c.insertText(symboleProposee.repeated(proposees));
                        c.insertText(symbolePossible.repeated(possibles));
                        c.insertText(symboleManquante.repeated(manquantes));
                        if (enTrop) c.insertText(tr(" (%n affectation(s) en trop)", "", enTrop));
                        query.next();
                        r = query.record();
                    } while (query.isValid()
                             && r.value("debut_tour").toDate() == jour);
                } while (query.isValid());
            } else {
                qWarning() << tr("Aucune affectation trouvée");
            }
        } else {
            qCritical() << query.lastError();
        }
    } else {
        qCritical() << query.lastError();
    }
}
Exemple #12
0
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

//! [0]
    QTextEdit *editor = new QTextEdit();
    QTextCursor cursor(editor->textCursor());
//! [0]
    cursor.movePosition(QTextCursor::Start);

    QTextBlockFormat blockFormat = cursor.blockFormat();
    blockFormat.setTopMargin(4);
    blockFormat.setLeftMargin(4);
    blockFormat.setRightMargin(4);
    blockFormat.setBottomMargin(4);

    cursor.setBlockFormat(blockFormat);
    cursor.insertText(tr("This contains plain text inside a "
                         "text block with margins to keep it separate "
                         "from other parts of the document."));

    cursor.insertBlock();

//! [1]
    QTextBlockFormat backgroundFormat = blockFormat;
    backgroundFormat.setBackground(QColor("lightGray"));

    cursor.setBlockFormat(backgroundFormat);
//! [1]
    cursor.insertText(tr("The background color of a text block can be "
                         "changed to highlight text."));

    cursor.insertBlock();

    QTextBlockFormat rightAlignedFormat = blockFormat;
    rightAlignedFormat.setAlignment(Qt::AlignRight);

    cursor.setBlockFormat(rightAlignedFormat);
    cursor.insertText(tr("The alignment of the text within a block is "
                         "controlled by the alignment properties of "
                         "the block itself. This text block is "
                         "right-aligned."));

    cursor.insertBlock();

    QTextBlockFormat paragraphFormat = blockFormat;
    paragraphFormat.setAlignment(Qt::AlignJustify);
    paragraphFormat.setTextIndent(32);

    cursor.setBlockFormat(paragraphFormat);
    cursor.insertText(tr("Text can be formatted so that the first "
                         "line in a paragraph has its own margin. "
                         "This makes the text more readable."));

    cursor.insertBlock();

    QTextBlockFormat reverseFormat = blockFormat;
    reverseFormat.setAlignment(Qt::AlignJustify);
    reverseFormat.setTextIndent(32);

    cursor.setBlockFormat(reverseFormat);
    cursor.insertText(tr("The direction of the text can be reversed. "
                         "This is useful for right-to-left "
                         "languages."));

    editor->setWindowTitle(tr("Text Block Formats"));
    editor->resize(480, 480);
    editor->show();

    return app.exec();
}
QTextTable * PrintDialog::insertCategoryTable(QTextCursor & cursor, const QString & categoryName)
{
	QTextBlockFormat blockCategoryTitleFormat;
	blockCategoryTitleFormat.setAlignment(Qt::AlignCenter);
	blockCategoryTitleFormat.setTopMargin(40.0);
	blockCategoryTitleFormat.setBottomMargin(30.0);

	QTextCharFormat categoryTitleFormat;
	categoryTitleFormat.setFontCapitalization(QFont::AllUppercase);
	categoryTitleFormat.setFontWeight(25);
	categoryTitleFormat.setFontPointSize(14.0);
	QString category = "Category \"";
	category += categoryName;
	category += "\"";

	cursor.insertBlock(blockCategoryTitleFormat);
	cursor.insertText(category,categoryTitleFormat);


	cursor.insertBlock(QTextBlockFormat()); // to break the previous block format
	QTextTable * table = cursor.insertTable(1, 4);
	if(!table)
		return NULL;
	QTextTableFormat categoryTableFormat;
	categoryTableFormat.setAlignment(Qt::AlignHCenter);
	categoryTableFormat.setHeaderRowCount(1); // header line
	categoryTableFormat.setBorderStyle(QTextTableFormat::BorderStyle_Solid);
	categoryTableFormat.setBorder(1.0);
	categoryTableFormat.setCellPadding(10);
	categoryTableFormat.setCellSpacing(0);

	table->setFormat(categoryTableFormat);

	// header :
	// header cell format :
	QTextCharFormat headerCellFormat;
	headerCellFormat.setFontWeight(50);
	headerCellFormat.setFontPointSize(12.0);
	headerCellFormat.setBackground(QBrush(QColor(60,60,60)));
	headerCellFormat.setForeground(QBrush(QColor(255,255,255)));

	QTextTableCell cell = table->cellAt(0,0);
	cell.setFormat(headerCellFormat);
	cursor = cell.firstCursorPosition();
	cursor.insertText(tr("Position"));

	cell = table->cellAt(0,1);
	cell.setFormat(headerCellFormat);
	cursor = cell.firstCursorPosition();
	cursor.insertText(tr("LastName"));

	cell = table->cellAt(0,2);
	cell.setFormat(headerCellFormat);
	cursor = cell.firstCursorPosition();
	cursor.insertText(tr("Firstname"));

	cell = table->cellAt(0,3);
	cell.setFormat(headerCellFormat);
	cursor = cell.firstCursorPosition();
	cursor.insertText(tr("Time"));

	return table;
}
ScriptFormatter::ScriptFormatter( QQmlEngine* newEngine, QObject *parent ) : QObject(parent) {
	QFont baseFont; //The base from which all other fonts are derived
	baseFont.setBold( false );
	baseFont.setCapitalization( QFont::MixedCase );
	baseFont.setFamily( "Courier" );
	baseFont.setItalic( false );
	baseFont.setPointSize( 12 );
	baseFont.setStyleHint( QFont::Courier );
	
	QTextBlockFormat baseFormat;
	baseFormat.setAlignment( Qt::AlignLeft );
	baseFormat.setIndent( 0 );
	baseFormat.setLineHeight( 1, QTextBlockFormat::SingleHeight ); //The first argument should be ignored according to the documentation, since we're setting the LineHeightType (2nd argument) to single height
	baseFormat.setNonBreakableLines( false );
	//baseFormat.setPageBreakPolicy( QTextFormat::PageBreak_Auto );
	baseFormat.setTextIndent( 0 );
	baseFormat.setTopMargin( 0 );
	baseFormat.setBottomMargin( 0 );
	baseFormat.setLeftMargin( 0 );
	baseFormat.setRightMargin( 0 );
	baseFormat.setNonBreakableLines( false );
	
	//Scenes are left-aligned, bold, and all caps
	sceneFont = QFont( baseFont );
	sceneFont.setBold( true );
	sceneFont.setCapitalization( QFont::AllUppercase );
	sceneBlockFormat = QTextBlockFormat( baseFormat );
	sceneBlockFormat.setAlignment( Qt::AlignLeft );
	//sceneBlockFormat.setPageBreakPolicy( QTextFormat::PageBreak_AlwaysBefore );
	
	//Actions are left-aligned
	actionFont = QFont( baseFont );
	actionBlockFormat = QTextBlockFormat( baseFormat );
	actionBlockFormat.setAlignment( Qt::AlignLeft );
	
	//Character names are centered and all caps
	characterFont = QFont( baseFont );
	characterFont.setCapitalization( QFont::AllUppercase );
	characterBlockFormat = QTextBlockFormat( baseFormat );
	characterBlockFormat.setAlignment( Qt::AlignHCenter );
	//characterBlockFormat.setPageBreakPolicy( QTextFormat::PageBreak_AlwaysBefore );
	
	//Dialog is centered
	dialogFont = QFont( baseFont );
	dialogBlockFormat = QTextBlockFormat( baseFormat );
	dialogBlockFormat.setAlignment( Qt::AlignHCenter );
	//dialogBlockFormat.setPageBreakPolicy( QTextFormat::PageBreak_AlwaysAfter );
	
	//Parentheticals are centered and italicized
	parentheticalFont = QFont( baseFont );
	parentheticalFont.setItalic( true );
	parentheticalBlockFormat = QTextBlockFormat( baseFormat );
	parentheticalBlockFormat.setAlignment( Qt::AlignHCenter );
	
	//Transitions are right-aligned and all caps
	transitionFont = QFont( baseFont );
	transitionFont.setCapitalization( QFont::AllUppercase );
	transitionBlockFormat = QTextBlockFormat( baseFormat );
	transitionBlockFormat.setAlignment( Qt::AlignRight );
	
	//Shots are left-aligned and all caps
	shotFont = QFont( baseFont );
	shotFont.setCapitalization( QFont::AllUppercase );
	shotBlockFormat = QTextBlockFormat( baseFormat );
	shotBlockFormat.setAlignment( Qt::AlignLeft );
	
	//Act breaks are centered, bold, and underlined
	actBreakFont = QFont( baseFont );
	actBreakFont.setBold( true );
	actBreakFont.setUnderline( true );
	actBreakBlockFormat = QTextBlockFormat( baseFormat );
	actBreakBlockFormat.setAlignment( Qt::AlignHCenter );
	
}