/* form qtexdocument to this margin an papersize */ void M_PageSize::HandlePrint( QTextDocument *doc ) { const qreal RightMargin = P_margin.y(); const qreal LeftMargin = P_margin.height(); const qreal LargeDoc = G_regt.width() - RightMargin - LeftMargin; doc->setPageSize ( G_regt.size() ); QTextFrame *Tframe = doc->rootFrame(); QTextFrameFormat Ftf = Tframe->frameFormat(); Ftf.setLeftMargin(P_margin.height()); Ftf.setBottomMargin(P_margin.width()); Ftf.setTopMargin(P_margin.x()); Ftf.setBackground(QBrush(Qt::transparent)); Ftf.setRightMargin(P_margin.y()); Ftf.setPadding ( 0); Tframe->setFrameFormat(Ftf); doc->setPageSize ( G_regt.size() ); }
TextEditor::TextEditor(Graph *g): QTextEdit(g), d_graph(g) { setAttribute(Qt::WA_DeleteOnClose); setFrameShadow(QFrame::Plain); setFrameShape(QFrame::Box); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); QPalette palette = this->palette(); palette.setColor(QPalette::Active, QPalette::WindowText, Qt::blue); palette.setColor(QPalette::Active, QPalette::Base, Qt::white); setPalette(palette); bool moveCrs = true; QString text; if (g->activeText()){ setParent(g->multiLayer()->canvas()); d_target = g->activeText(); setGeometry(d_target->geometry()); text = ((LegendWidget*)d_target)->text(); d_target->hide(); setFont(((LegendWidget*)d_target)->font()); } else if (g->titleSelected()){ d_target = g->titleLabel(); QwtText t = g->title(); text = t.text(); setAlignment((Qt::Alignment)t.renderFlags()); setFont(t.font()); setGeometry(d_target->geometry()); } else if (g->selectedScale()){ d_target = g->selectedScale(); QwtScaleWidget *scale = (QwtScaleWidget*)d_target; QwtText t = scale->title(); text = t.text(); setAlignment((Qt::Alignment)t.renderFlags()); setFont(t.font()); QRect rect = g->axisTitleRect(scale); if (scale->alignment() == QwtScaleDraw::BottomScale || scale->alignment() == QwtScaleDraw::TopScale){ resize(rect.size()); move(QPoint(d_target->x() + rect.x(), d_target->y() + rect.y())); } else { resize(QSize(rect.height(), rect.width())); if (scale->alignment() == QwtScaleDraw::LeftScale) move(QPoint(d_target->x() + rect.x(), d_target->y() + rect.y() + rect.height()/2)); else if (scale->alignment() == QwtScaleDraw::RightScale) move(QPoint(d_target->x() - rect.height(), d_target->y() + rect.y() + rect.height()/2)); t.setText(" "); t.setBackgroundPen(QPen(Qt::NoPen)); scale->setTitle(t); moveCrs = false; } } QTextCursor cursor = textCursor(); cursor.insertText(text); d_initial_text = text; setWordWrapMode (QTextOption::NoWrap); setAlignment(Qt::AlignCenter); QTextFrame *frame = document()->rootFrame(); QTextFrameFormat format = frame->frameFormat(); format.setTopMargin(format.topMargin () + 3); frame->setFrameFormat(format); show(); if (moveCrs) setTextCursor(cursorForPosition(mapFromGlobal(QCursor::pos()))); setFocus(); }
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++; }
static void setFormatMargins(QTextFrameFormat& format, const cf::Rect& margins) { format.setTopMargin(margins.top()); format.setRightMargin(margins.right()); format.setBottomMargin(margins.bottom()); format.setLeftMargin(margins.left()); }