本文整理汇总了C++中QTextCharFormat类的典型用法代码示例。如果您正苦于以下问题:C++ QTextCharFormat类的具体用法?C++ QTextCharFormat怎么用?C++ QTextCharFormat使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QTextCharFormat类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: switch
void QTextOdfWriter::writeCharacterFormat(QXmlStreamWriter &writer, QTextCharFormat format, int formatIndex) const
{
writer.writeStartElement(styleNS, QString::fromLatin1("style"));
writer.writeAttribute(styleNS, QString::fromLatin1("name"), QString::fromLatin1("c%1").arg(formatIndex));
writer.writeAttribute(styleNS, QString::fromLatin1("family"), QString::fromLatin1("text"));
writer.writeEmptyElement(styleNS, QString::fromLatin1("text-properties"));
if (format.fontItalic())
writer.writeAttribute(foNS, QString::fromLatin1("font-style"), QString::fromLatin1("italic"));
if (format.hasProperty(QTextFormat::FontWeight) && format.fontWeight() != QFont::Normal) {
QString value;
if (format.fontWeight() == QFont::Bold)
value = QString::fromLatin1("bold");
else
value = QString::number(format.fontWeight() * 10);
writer.writeAttribute(foNS, QString::fromLatin1("font-weight"), value);
}
if (format.hasProperty(QTextFormat::FontFamily))
writer.writeAttribute(foNS, QString::fromLatin1("font-family"), format.fontFamily());
else
writer.writeAttribute(foNS, QString::fromLatin1("font-family"), QString::fromLatin1("Sans")); // Qt default
if (format.hasProperty(QTextFormat::FontPointSize))
writer.writeAttribute(foNS, QString::fromLatin1("font-size"), QString::fromLatin1("%1pt").arg(format.fontPointSize()));
if (format.hasProperty(QTextFormat::FontCapitalization)) {
switch(format.fontCapitalization()) {
case QFont::MixedCase:
writer.writeAttribute(foNS, QString::fromLatin1("text-transform"), QString::fromLatin1("none")); break;
case QFont::AllUppercase:
writer.writeAttribute(foNS, QString::fromLatin1("text-transform"), QString::fromLatin1("uppercase")); break;
case QFont::AllLowercase:
writer.writeAttribute(foNS, QString::fromLatin1("text-transform"), QString::fromLatin1("lowercase")); break;
case QFont::Capitalize:
writer.writeAttribute(foNS, QString::fromLatin1("text-transform"), QString::fromLatin1("capitalize")); break;
case QFont::SmallCaps:
writer.writeAttribute(foNS, QString::fromLatin1("font-variant"), QString::fromLatin1("small-caps")); break;
}
}
if (format.hasProperty(QTextFormat::FontLetterSpacing))
writer.writeAttribute(foNS, QString::fromLatin1("letter-spacing"), pixelToPoint(format.fontLetterSpacing()));
if (format.hasProperty(QTextFormat::FontWordSpacing) && format.fontWordSpacing() != 0)
writer.writeAttribute(foNS, QString::fromLatin1("word-spacing"), pixelToPoint(format.fontWordSpacing()));
if (format.hasProperty(QTextFormat::FontUnderline))
writer.writeAttribute(styleNS, QString::fromLatin1("text-underline-type"),
format.fontUnderline() ? QString::fromLatin1("single") : QString::fromLatin1("none"));
if (format.hasProperty(QTextFormat::FontOverline)) {
// bool fontOverline () const TODO
}
if (format.hasProperty(QTextFormat::FontStrikeOut))
writer.writeAttribute(styleNS,QString::fromLatin1( "text-line-through-type"),
format.fontStrikeOut() ? QString::fromLatin1("single") : QString::fromLatin1("none"));
if (format.hasProperty(QTextFormat::TextUnderlineColor))
writer.writeAttribute(styleNS, QString::fromLatin1("text-underline-color"), format.underlineColor().name());
if (format.hasProperty(QTextFormat::FontFixedPitch)) {
// bool fontFixedPitch () const TODO
}
if (format.hasProperty(QTextFormat::TextUnderlineStyle)) {
QString value;
switch (format.underlineStyle()) {
case QTextCharFormat::NoUnderline: value = QString::fromLatin1("none"); break;
case QTextCharFormat::SingleUnderline: value = QString::fromLatin1("solid"); break;
case QTextCharFormat::DashUnderline: value = QString::fromLatin1("dash"); break;
case QTextCharFormat::DotLine: value = QString::fromLatin1("dotted"); break;
case QTextCharFormat::DashDotLine: value = QString::fromLatin1("dash-dot"); break;
case QTextCharFormat::DashDotDotLine: value = QString::fromLatin1("dot-dot-dash"); break;
case QTextCharFormat::WaveUnderline: value = QString::fromLatin1("wave"); break;
case QTextCharFormat::SpellCheckUnderline: value = QString::fromLatin1("none"); break;
}
writer.writeAttribute(styleNS, QString::fromLatin1("text-underline-style"), value);
}
if (format.hasProperty(QTextFormat::TextVerticalAlignment)) {
QString value;
switch (format.verticalAlignment()) {
case QTextCharFormat::AlignMiddle:
case QTextCharFormat::AlignBaseline:
case QTextCharFormat::AlignNormal: value = QString::fromLatin1("0%"); break;
case QTextCharFormat::AlignSuperScript: value = QString::fromLatin1("super"); break;
case QTextCharFormat::AlignSubScript: value = QString::fromLatin1("sub"); break;
case QTextCharFormat::AlignTop: value = QString::fromLatin1("100%"); break;
case QTextCharFormat::AlignBottom : value = QString::fromLatin1("-100%"); break;
}
writer.writeAttribute(styleNS, QString::fromLatin1("text-position"), value);
}
if (format.hasProperty(QTextFormat::TextOutline))
writer.writeAttribute(styleNS, QString::fromLatin1("text-outline"), QString::fromLatin1("true"));
if (format.hasProperty(QTextFormat::TextToolTip)) {
// QString toolTip () const TODO
}
if (format.hasProperty(QTextFormat::IsAnchor)) {
// bool isAnchor () const TODO
}
if (format.hasProperty(QTextFormat::AnchorHref)) {
// QString anchorHref () const TODO
}
if (format.hasProperty(QTextFormat::AnchorName)) {
// QString anchorName () const TODO
}
if (format.hasProperty(QTextFormat::ForegroundBrush)) {
QBrush brush = format.foreground();
writer.writeAttribute(foNS, QString::fromLatin1("color"), brush.color().name());
}
if (format.hasProperty(QTextFormat::BackgroundBrush)) {
//.........这里部分代码省略.........
示例2: onTextBoldTriggerred
void MailEditorMainWindow::onTextBoldTriggerred(bool checked)
{
QTextCharFormat fmt;
fmt.setFontWeight(checked ? QFont::Bold : QFont::Normal);
mergeFormatOnWordOrSelection(fmt);
}
示例3: onTextFamilyChanged
void MailEditorMainWindow::onTextFamilyChanged(const QString& f)
{
QTextCharFormat fmt;
fmt.setFontFamily(f);
mergeFormatOnWordOrSelection(fmt);
}
示例4: Q_UNUSED
void TextContent::drawContent(QPainter * painter, const QRect & targetRect, Qt::AspectRatioMode ratio)
{
Q_UNUSED(ratio)
// check whether we're drawing shaped
const bool shapedPaint = hasShape() && !m_shapeRect.isEmpty();
QPointF shapeOffset = m_shapeRect.topLeft();
// scale painter for adapting the Text Rect to the Contents Rect
QRect sourceRect = shapedPaint ? m_shapeRect : m_textRect;
painter->save();
painter->translate(targetRect.topLeft());
if (sourceRect.width() > 0 && sourceRect.height() > 0) {
qreal xScale = (qreal)targetRect.width() / (qreal)sourceRect.width();
qreal yScale = (qreal)targetRect.height() / (qreal)sourceRect.height();
if (!qFuzzyCompare(xScale, (qreal)1.0) || !qFuzzyCompare(yScale, (qreal)1.0))
painter->scale(xScale, yScale);
}
// shape
//const bool drawHovering = RenderOpts::HQRendering ? false : isSelected();
if (shapedPaint)
painter->translate(-shapeOffset);
//if (shapedPaint && drawHovering)
// painter->strokePath(m_shapePath, QPen(Qt::red, 0));
// TEMP - for PDF exporting - standard rich text document drawing
if (RenderOpts::PDFExporting) {
if (shapedPaint)
QMessageBox::information(0, tr("PDF Export Warning"), tr("Shaped text could not be exported in PDF"), QMessageBox::Ok);
QAbstractTextDocumentLayout::PaintContext pCtx;
m_text->documentLayout()->draw(painter, pCtx);
} else {
// manual drawing
QPointF blockPos = shapedPaint ? QPointF(0, 0) : -m_textRect.topLeft();
// 1. for each Text Block
int blockRectIdx = 0;
for (QTextBlock tb = m_text->begin(); tb.isValid(); tb = tb.next()) {
if (!tb.isVisible() || blockRectIdx > m_blockRects.size())
continue;
// 1.1. compute text insertion position
const QRect & blockRect = m_blockRects[blockRectIdx++];
QPointF iPos = shapedPaint ? blockPos : blockPos - blockRect.topLeft();
blockPos += QPointF(0, blockRect.height());
qreal curLen = 8;
// 1.2. iterate over text fragments
for (QTextBlock::iterator tbIt = tb.begin(); !(tbIt.atEnd()); ++tbIt) {
QTextFragment frag = tbIt.fragment();
if (!frag.isValid())
continue;
// 1.2.1. setup painter and metrics for text fragment
QTextCharFormat format = frag.charFormat();
QFont font = format.font();
painter->setFont(font);
painter->setPen(format.foreground().color());
painter->setBrush(Qt::NoBrush);
QFontMetrics metrics(font);
// 1.2.2. draw each character
QString text = frag.text();
foreach (const QChar & textChar, text) {
const qreal charWidth = metrics.width(textChar);
if (shapedPaint) {
// find point on shape and angle
qreal t = m_shapePath.percentAtLength(curLen);
QPointF pt = m_shapePath.pointAtPercent(t);
qreal angle = -m_shapePath.angleAtPercent(t);
if (m_shakeRadius > 0)
pt += QPointF(1 + (qrand() % m_shakeRadius) - m_shakeRadius/2, 1 + (qrand() % (2*m_shakeRadius)) - m_shakeRadius);
// draw rotated letter
painter->save();
painter->translate(pt);
painter->rotate(angle);
painter->drawText(iPos, textChar);
painter->restore();
curLen += charWidth;
} else {
painter->drawText(iPos, textChar);
iPos += QPointF(charWidth, 0);
}
}
}
}
}
painter->restore();
}
示例5: setPlainText
void
FormText::setCfg( const Cfg::Text & c )
{
setPlainText( QString() );
QFont f = font();
QTextCharFormat fmt = textCursor().charFormat();
QTextBlockFormat b = textCursor().blockFormat();
foreach( const Cfg::TextStyle & s, c.text() )
{
if( s.style().contains( Cfg::c_normalStyle ) )
{
f.setWeight( QFont::Normal );
f.setItalic( false );
f.setUnderline( false );
fmt.setFontWeight( QFont::Normal );
fmt.setFontItalic( false );
fmt.setFontUnderline( false );
}
else
{
if( s.style().contains( Cfg::c_boldStyle ) )
{
f.setWeight( QFont::Bold );
fmt.setFontWeight( QFont::Bold );
}
else
{
f.setWeight( QFont::Normal );
fmt.setFontWeight( QFont::Normal );
}
if( s.style().contains( Cfg::c_italicStyle ) )
{
f.setItalic( true );
fmt.setFontItalic( true );
}
else
{
f.setItalic( false );
fmt.setFontItalic( false );
}
if( s.style().contains( Cfg::c_underlineStyle ) )
{
f.setUnderline( true );
fmt.setFontUnderline( true );
}
else
{
f.setUnderline( false );
fmt.setFontUnderline( false );
}
}
Cfg::initBlockFormat( b, s );
f.setPointSize( s.fontSize() );
fmt.setFontPointSize( s.fontSize() );
setFont( f );
QTextCursor cursor = textCursor();
cursor.movePosition( QTextCursor::End );
cursor.setCharFormat( fmt );
cursor.setBlockFormat( b );
cursor.insertText( s.text() );
setTextCursor( cursor );
}
document()->clearUndoRedoStacks();
setObjectId( c.objectId() );
setTextWidth( c.textWidth() );
setPos( QPointF( c.pos().x(), c.pos().y() ) );
setLink( c.link() );
QRectF r = boundingRect();
r.moveTo( pos() );
d->m_proxy->setRect( r );
}
示例6: QString
int RichTextRenderer::fitToSize(const QSize& size, int minimumFontSize, int maximumFontSize)
{
int width = size.width();
int height = size.height();
const QString sizeKey = QString("%1:%2:%3:%4").arg(html()).arg(width).arg(height).arg(minimumFontSize);
// for centering
qreal boxHeight = -1;
double ptSize = -1;
if(static_autoTextSizeCache.contains(sizeKey))
{
ptSize = *(static_autoTextSizeCache[sizeKey]);
//qDebug()<<"RichTextRenderer::fitToSize(): size search: CACHE HIT: loaded size:"<<ptSize;
// We go thru the much-more-verbose method of creating
// the document and setting the html, width, merge cursor,
// etc, just so we can get the document height after
// setting the font size inorder to use it to center the textbox.
// If we didnt nead the height, we could just use autoText->setFontSize()
QTextDocument doc;
doc.setTextWidth(width);
if (Qt::mightBeRichText(html()))
doc.setHtml(html());
else
doc.setPlainText(html());
QTextCursor cursor(&doc);
cursor.select(QTextCursor::Document);
QTextCharFormat format;
format.setFontPointSize(ptSize);
cursor.mergeCharFormat(format);
boxHeight = doc.documentLayout()->documentSize().height();
setHtml(doc.toHtml());
}
else
{
double ptSize = minimumFontSize > 0 ? minimumFontSize : findFontSize();
double sizeInc = 1; // how big of a jump to add to the ptSize each iteration
int count = 0; // current loop iteration
int maxCount = 100; // max iterations of the search loop
bool done = false;
double lastGoodSize = ptSize;
QString lastGoodHtml = html();
QTextDocument doc;
qreal heightTmp;
doc.setTextWidth(width);
if (Qt::mightBeRichText(html()))
doc.setHtml(html());
else
doc.setPlainText(html());
QTextCursor cursor(&doc);
cursor.select(QTextCursor::Document);
QTextCharFormat format;
while(!done && count++ < maxCount)
{
format.setFontPointSize(ptSize);
cursor.mergeCharFormat(format);
heightTmp = doc.documentLayout()->documentSize().height();
if(heightTmp < height &&
ptSize < maximumFontSize)
{
lastGoodSize = ptSize;
//lastGoodHtml = html();
boxHeight = heightTmp;
sizeInc *= 1.1;
// qDebug()<<"size search: "<<ptSize<<"pt was good, trying higher, inc:"<<sizeInc<<"pt";
ptSize += sizeInc;
}
else
{
// qDebug()<<"fitToSize: size search: last good ptsize:"<<lastGoodSize<<", stopping search";
done = true;
}
}
if(boxHeight < 0 && minimumFontSize <= 0) // didnt find a size
{
ptSize = 100;
count = 0;
//.........这里部分代码省略.........
示例7: qWarning
void QMaliitPlatformInputContext::updatePreedit(const QDBusMessage &message)
{
if (!inputMethodAccepted())
return;
QList<QVariant> arguments = message.arguments();
if (arguments.count() != 5) {
qWarning() << "QMaliitPlatformInputContext::updatePreedit: Received message from input method server with wrong parameters.";
return;
}
d->preedit = arguments[0].toString();
QList<QInputMethodEvent::Attribute> attributes;
const QDBusArgument formats = arguments[1].value<QDBusArgument>();
formats.beginArray();
while (!formats.atEnd()) {
formats.beginStructure();
int start, length, preeditFace;
formats >> start >> length >> preeditFace;
formats.endStructure();
QTextCharFormat format;
enum PreeditFace {
PreeditDefault,
PreeditNoCandidates,
PreeditKeyPress, //!< Used for displaying the hwkbd key just pressed
PreeditUnconvertible, //!< Inactive preedit region, not clickable
PreeditActive, //!< Preedit region with active suggestions
};
switch (PreeditFace(preeditFace)) {
case PreeditDefault:
case PreeditKeyPress:
format.setUnderlineStyle(QTextCharFormat::SingleUnderline);
format.setUnderlineColor(QColor(0, 0, 0));
break;
case PreeditNoCandidates:
format.setUnderlineStyle(QTextCharFormat::SingleUnderline);
format.setUnderlineColor(QColor(255, 0, 0));
break;
case PreeditUnconvertible:
format.setForeground(QBrush(QColor(128, 128, 128)));
break;
case PreeditActive:
format.setForeground(QBrush(QColor(153, 50, 204)));
format.setFontWeight(QFont::Bold);
break;
default:
break;
}
attributes << QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat, start, length, format);
}
formats.endArray();
int replacementStart = arguments[2].toInt();
int replacementLength = arguments[3].toInt();
int cursorPos = arguments[4].toInt();
if (debug)
qWarning() << "updatePreedit" << d->preedit << replacementStart << replacementLength << cursorPos;
if (cursorPos >= 0)
attributes << QInputMethodEvent::Attribute(QInputMethodEvent::Cursor, cursorPos, 1, QVariant());
QInputMethodEvent event(d->preedit, attributes);
if (replacementStart || replacementLength)
event.setCommitString(QString(), replacementStart, replacementLength);
QCoreApplication::sendEvent(qGuiApp->focusObject(), &event);
}
示例8: onTextCharFormatChanged
void MainWindow::onTextCharFormatChanged( const QTextCharFormat & sFormat )
{
QFont fnt = sFormat.font();
m_pCmbFont->setCurrentText( fnt.family() );
m_pCmbFontPointSize->setCurrentText( QString::number( fnt.pointSize() ) );
}
示例9: fragment
QString FlatTextarea::getText(int32 start, int32 end) const {
if (end >= 0 && end <= start) return QString();
if (start < 0) start = 0;
bool full = (start == 0) && (end < 0);
QTextDocument *doc(document());
QTextBlock from = full ? doc->begin() : doc->findBlock(start), till = (end < 0) ? doc->end() : doc->findBlock(end);
if (till.isValid()) till = till.next();
int32 possibleLen = 0;
for (QTextBlock b = from; b != till; b = b.next()) {
possibleLen += b.length();
}
QString result;
result.reserve(possibleLen + 1);
if (!full && end < 0) {
end = possibleLen;
}
for (QTextBlock b = from; b != till; b = b.next()) {
for (QTextBlock::Iterator iter = b.begin(); !iter.atEnd(); ++iter) {
QTextFragment fragment(iter.fragment());
if (!fragment.isValid()) continue;
int32 p = full ? 0 : fragment.position(), e = full ? 0 : (p + fragment.length());
if (!full) {
if (p >= end || e <= start) {
continue;
}
}
QTextCharFormat f = fragment.charFormat();
QString emojiText;
QString t(fragment.text());
if (!full) {
if (p < start) {
t = t.mid(start - p, end - start);
} else if (e > end) {
t = t.mid(0, end - p);
}
}
QChar *ub = t.data(), *uc = ub, *ue = uc + t.size();
for (; uc != ue; ++uc) {
switch (uc->unicode()) {
case 0xfdd0: // QTextBeginningOfFrame
case 0xfdd1: // QTextEndOfFrame
case QChar::ParagraphSeparator:
case QChar::LineSeparator:
*uc = QLatin1Char('\n');
break;
case QChar::Nbsp:
*uc = QLatin1Char(' ');
break;
case QChar::ObjectReplacementCharacter:
if (emojiText.isEmpty() && f.isImageFormat()) {
QString imageName = static_cast<QTextImageFormat*>(&f)->name();
if (imageName.midRef(0, 8) == qsl("emoji://")) {
uint32 index = imageName.mid(8).toUInt(0, 16);
const EmojiData *emoji = getEmoji(index);
if (emoji) {
emojiText = textEmojiString(emoji);
}
}
}
if (uc > ub) result.append(ub, uc - ub);
if (!emojiText.isEmpty()) result.append(emojiText);
ub = uc + 1;
break;
}
}
if (uc > ub) result.append(ub, uc - ub);
}
result.append('\n');
}
result.chop(1);
return result;
}
示例10: QToolBar
Tools::Tools(bool thisIsABackup, QWidget *parent) : QToolBar(parent) {
// This variable holds whether the toolbar is used for a backup or not (add and edit buttons disabled for backups)
this->thisIsABackup = thisIsABackup;
this->setFloatable(false);
this->setMovable(false);
this->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
this->setIconSize(QSize(20,20));
addBooking = new QToolButton;
addBooking->setIcon(QIcon(":/images/add.png"));
addBooking->setText("Add &New");
addBooking->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
addBooking->setStyleSheet("font-size: 11pt; font-weight: bold");
addBooking->setFixedHeight(40);
addBooking->setStatusTip("Add a new booking");
if(thisIsABackup) addBooking->setEnabled(false);
editBooking = new QToolButton;
editBooking->setIcon(QIcon(":/images/edit.png"));
editBooking->setText("&Edit");
editBooking->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
editBooking->setStyleSheet("font-size: 11pt; font-weight: bold");
editBooking->setFixedHeight(40);
editBooking->setStatusTip("Edit Booking");
if(thisIsABackup) editBooking->setEnabled(false);
gotoToday_but = new QToolButton;
gotoToday_but->setIcon(QIcon(":/images/calendar.png"));
gotoToday_but->setText("Go to &Today");
gotoToday_but->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
gotoToday_but->setStyleSheet("font-size: 11pt; font-weight: bold");
gotoToday_but->setFixedHeight(40);
gotoToday_but->setStatusTip("Go to Today");
currentDate = QDate::currentDate();
gotoPrev = new QToolButton;
gotoPrev->setIcon(QIcon(":/images/left.png"));
gotoPrev->setStatusTip("Go to previous day");
gotoPrev->setFixedSize(50,40);
gotoPrev->setShortcut(QKeySequence("Alt+Left"));
gotoNext = new QToolButton;
gotoNext->setIcon(QIcon(":/images/right.png"));
gotoNext->setStatusTip("Go to next day");
gotoNext->setFixedSize(50,40);
gotoNext->setShortcut(QKeySequence("Alt+Right"));
curDate = new QToolButton;
curDate->setStatusTip("Select date from calendar");
curDate->setText(QDate::currentDate().toString("dddd, dd MMM yyyy"));
curDate->setStyleSheet("font-size: 11pt; font-weight: bold");
curDate->setFixedSize(220,40);
curDate->setPopupMode(QToolButton::InstantPopup);
curDate->setShortcut(QKeySequence("Alt+C"));
cal = new QCalendarWidget;
cal->setMinimumDate(QDate(QDate::currentDate().year()-100,1,1));
cal->setMaximumDate(QDate(QDate::currentDate().year()+100,12,31));
cal->setFixedWidth(400);
cal->setFixedHeight(300);
cal->setGridVisible(true);
cal->setStyleSheet("font-size: 12pt; font-weight: bold");
QTextCharFormat format;
format.setFontWeight(QFont::Bold);
format.setBackground(QBrush(QColor(220,220,220)));
cal->setHeaderTextFormat(format);
m = new QMenu;
QWidgetAction *a = new QWidgetAction(m);
a->setDefaultWidget(cal);
m->addAction(a);
curDate->setMenu(m);
m->installEventFilter(this);
connect(m, SIGNAL(aboutToShow()), this, SLOT(clickForCalendar()));
showCancelled = new QCheckBox("Also show cancelled bookings");
filterAdv = new QToolButton;
filterAdv->setCheckable(true);
filterAdv->setText("&Search");
filterAdv->setIcon(QIcon(":/images/search.png"));
filterAdv->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
filterAdv->setStyleSheet("font-size: 11pt; font-weight: bold");
filterAdv->setFixedHeight(40);
filter = new CustomLineEdit;
filter->setStyleSheet("font-size: 11pt");
this->addWidget(addBooking);
this->addSeparator();
this->addWidget(editBooking);
this->addSeparator();
this->addWidget(gotoToday_but);
this->addWidget(gotoPrev);
this->addWidget(curDate);
this->addWidget(gotoNext);
QWidget *separator1 = new QWidget;
separator1->setSizePolicy(QSizePolicy::Expanding,
QSizePolicy::Expanding);
QWidget *separator2 = new QWidget;
//.........这里部分代码省略.........
示例11: loadConfiguration
void SyntaxHighlighter::loadConfiguration(const QString &filename)
{
if(filename!="")
{
map<QString, QString> attribs;
QString elem, expr_type, group;
bool groups_decl=false, chr_sensitive=false,
bold=false, italic=false,
underline=false, partial_match=false;
QTextCharFormat format;
QRegExp regexp;
QColor bg_color, fg_color;
vector<QString>::iterator itr, itr_end;
try
{
clearConfiguration();
XMLParser::restartParser();
XMLParser::setDTDFile(GlobalAttributes::CONFIGURATIONS_DIR +
GlobalAttributes::DIR_SEPARATOR +
GlobalAttributes::OBJECT_DTD_DIR +
GlobalAttributes::DIR_SEPARATOR +
GlobalAttributes::CODE_HIGHLIGHT_CONF +
GlobalAttributes::OBJECT_DTD_EXT,
GlobalAttributes::CODE_HIGHLIGHT_CONF);
XMLParser::loadXMLFile(filename);
if(XMLParser::accessElement(XMLParser::CHILD_ELEMENT))
{
do
{
if(XMLParser::getElementType()==XML_ELEMENT_NODE)
{
elem=XMLParser::getElementName();
if(elem==ParsersAttributes::WORD_SEPARATORS)
{
XMLParser::getElementAttributes(attribs);
word_separators=attribs[ParsersAttributes::VALUE];
}
else if(elem==ParsersAttributes::WORD_DELIMITERS)
{
XMLParser::getElementAttributes(attribs);
word_delimiters=attribs[ParsersAttributes::VALUE];
}
else if(elem==ParsersAttributes::IGNORED_CHARS)
{
XMLParser::getElementAttributes(attribs);
ignored_chars=attribs[ParsersAttributes::VALUE];
}
/* If the element is what defines the order of application of the groups
highlight in the (highlight-order). Is in this block that are declared
the groups used to highlight the source code. ALL groups
in this block must be declared before they are built
otherwise an error will be triggered. */
else if(elem==ParsersAttributes::HIGHLIGHT_ORDER)
{
//Marks a flag indication that groups are being declared
groups_decl=true;
XMLParser::savePosition();
XMLParser::accessElement(XMLParser::CHILD_ELEMENT);
elem=XMLParser::getElementName();
}
if(elem==ParsersAttributes::GROUP)
{
XMLParser::getElementAttributes(attribs);
group=attribs[ParsersAttributes::NAME];
/* If the parser is on the group declaration block and not in the build block
some validations are made. */
if(groups_decl)
{
//Raises an error if the group was declared before
if(find(groups_order.begin(), groups_order.end(), group)!=groups_order.end())
{
throw Exception(Exception::getErrorMessage(ERR_REDECL_HL_GROUP).arg(group),
ERR_REDECL_HL_GROUP,__PRETTY_FUNCTION__,__FILE__,__LINE__);
}
//Raises an error if the group is being declared and build at the declaration statment (not permitted)
else if(attribs.size() > 1 || XMLParser::hasElement(XMLParser::CHILD_ELEMENT))
{
throw Exception(Exception::getErrorMessage(ERR_DEF_INV_GROUP_DECL)
.arg(group).arg(ParsersAttributes::HIGHLIGHT_ORDER),
ERR_REDECL_HL_GROUP,__PRETTY_FUNCTION__,__FILE__,__LINE__);
}
groups_order.push_back(group);
}
//Case the parser is on the contruction block and not in declaration of groups
else
{
//Raises an error if the group is being constructed by a second time
if(initial_exprs.count(group)!=0)
{
throw Exception(Exception::getErrorMessage(ERR_DEF_DUPLIC_GROUP).arg(group),
ERR_DEF_DUPLIC_GROUP,__PRETTY_FUNCTION__,__FILE__,__LINE__);
}
//.........这里部分代码省略.........
示例12: QMenu
MainWindow::MainWindow()
{
QMenu *fileMenu = new QMenu(tr("&File"));
QAction *saveAction = fileMenu->addAction(tr("&Save..."));
saveAction->setShortcut(tr("Ctrl+S"));
QAction *quitAction = fileMenu->addAction(tr("E&xit"));
quitAction->setShortcut(tr("Ctrl+Q"));
menuBar()->addMenu(fileMenu);
editor = new QTextEdit();
QTextCursor cursor(editor->textCursor());
cursor.movePosition(QTextCursor::Start);
QTextFrame *mainFrame = cursor.currentFrame();
QTextCharFormat plainCharFormat;
QTextCharFormat boldCharFormat;
boldCharFormat.setFontWeight(QFont::Bold);
/* main frame
//! [0]
QTextFrame *mainFrame = cursor.currentFrame();
cursor.insertText(...);
//! [0]
*/
cursor.insertText("Text documents are represented by the "
"QTextDocument class, rather than by QString objects. "
"Each QTextDocument object contains information about "
"the document's internal representation, its structure, "
"and keeps track of modifications to provide undo/redo "
"facilities. This approach allows features such as the "
"layout management to be delegated to specialized "
"classes, but also provides a focus for the framework.",
plainCharFormat);
//! [1]
QTextFrameFormat frameFormat;
frameFormat.setMargin(32);
frameFormat.setPadding(8);
frameFormat.setBorder(4);
//! [1]
cursor.insertFrame(frameFormat);
/* insert frame
//! [2]
cursor.insertFrame(frameFormat);
cursor.insertText(...);
//! [2]
*/
cursor.insertText("Documents are either converted from external sources "
"or created from scratch using Qt. The creation process "
"can done by an editor widget, such as QTextEdit, or by "
"explicit calls to the Scribe API.", boldCharFormat);
cursor = mainFrame->lastCursorPosition();
/* last cursor
//! [3]
cursor = mainFrame->lastCursorPosition();
cursor.insertText(...);
//! [3]
*/
cursor.insertText("There are two complementary ways to visualize the "
"contents of a document: as a linear buffer that is "
"used by editors to modify the contents, and as an "
"object hierarchy containing structural information "
"that is useful to layout engines. In the hierarchical "
"model, the objects generally correspond to visual "
"elements such as frames, tables, and lists. At a lower "
"level, these elements describe properties such as the "
"style of text used and its alignment. The linear "
"representation of the document is used for editing and "
"manipulation of the document's contents.",
plainCharFormat);
connect(saveAction, SIGNAL(triggered()), this, SLOT(saveFile()));
connect(quitAction, SIGNAL(triggered()), this, SLOT(close()));
setCentralWidget(editor);
setWindowTitle(tr("Text Document Frames"));
}
示例13: while
bool KoReportODTRenderer::render(const KoReportRendererContext& context, ORODocument* document, int /*page*/)
{
QTextTableFormat tableFormat;
tableFormat.setCellPadding(5);
tableFormat.setHeaderRowCount(1);
tableFormat.setBorderStyle(QTextFrameFormat::BorderStyle_Solid);
tableFormat.setWidth(QTextLength(QTextLength::PercentageLength, 100));
QTextTable *table = m_cursor.insertTable(1, 1, tableFormat);
long renderedSections = 0;
for (long s = 0; s < document->sections(); s++) {
OROSection *section = document->section(s);
section->sortPrimatives(OROSection::SortX);
if (section->type() == KRSectionData::GroupHeader || section->type() == KRSectionData::GroupFooter ||
section->type() == KRSectionData::ReportHeader || section->type() == KRSectionData::ReportFooter ||
section->type() == KRSectionData::Detail){
//Add this section to the document
//Resize the table to accomodate all the primitives in the section
if (table->columns() < section->primitives()) {
table->appendColumns(section->primitives() - table->columns());
}
if (renderedSections > 0) {
//We need to back a row, then forward a row to get at the start cell
m_cursor.movePosition(QTextCursor::PreviousRow);
m_cursor.movePosition(QTextCursor::NextRow);
} else {
//On the first row, ensure we are in the first cell after expanding the table
while (m_cursor.movePosition(QTextCursor::PreviousCell)){}
}
//Render the objects in each section
for (int i = 0; i < section->primitives(); i++) {
//Colour the cell using hte section background colour
OROPrimitive * prim = section->primitive(i);
QTextTableCell cell = table->cellAt(m_cursor);
QTextCharFormat format = cell.format();
format.setBackground(section->backgroundColor());
cell.setFormat(format);
if (prim->type() == OROTextBox::TextBox) {
OROTextBox * tb = (OROTextBox*) prim;
m_cursor.insertText(tb->text());
} else if (prim->type() == OROImage::Image) {
OROImage * im = (OROImage*) prim;
m_cursor.insertImage(im->image().scaled(im->size().width(), im->size().height(), Qt::KeepAspectRatio));
} else if (prim->type() == OROPicture::Picture) {
OROPicture * im = (OROPicture*) prim;
QImage image(im->size().toSize(), QImage::Format_RGB32);
QPainter painter(&image);
im->picture()->play(&painter);
m_cursor.insertImage(image);
} else {
kDebug() << "unhandled primitive type";
}
m_cursor.movePosition(QTextCursor::NextCell);
}
if (s < document->sections() - 1) {
table->appendRows(1);
}
renderedSections++;
}
}
QTextDocumentWriter writer(context.destinationUrl.toLocalFile());
return writer.write(m_document);
}
示例14: QMenu
MainWindow::MainWindow()
{
QMenu *fileMenu = new QMenu(tr("&File"));
QAction *saveAction = fileMenu->addAction(tr("&Save..."));
saveAction->setShortcut(tr("Ctrl+S"));
QAction *quitAction = fileMenu->addAction(tr("E&xit"));
quitAction->setShortcut(tr("Ctrl+Q"));
QMenu *showMenu = new QMenu(tr("&Show"));
QAction *showTableAction = showMenu->addAction(tr("&Table"));
menuBar()->addMenu(fileMenu);
menuBar()->addMenu(showMenu);
editor = new QTextEdit();
//! [0] //! [1]
QTextCursor cursor(editor->textCursor());
//! [0]
cursor.movePosition(QTextCursor::Start);
//! [1]
int rows = 11;
int columns = 4;
//! [2]
QTextTableFormat tableFormat;
tableFormat.setBackground(QColor("#e0e0e0"));
QVector<QTextLength> constraints;
constraints << QTextLength(QTextLength::PercentageLength, 16);
constraints << QTextLength(QTextLength::PercentageLength, 28);
constraints << QTextLength(QTextLength::PercentageLength, 28);
constraints << QTextLength(QTextLength::PercentageLength, 28);
tableFormat.setColumnWidthConstraints(constraints);
//! [3]
QTextTable *table = cursor.insertTable(rows, columns, tableFormat);
//! [2] //! [3]
int column;
int row;
QTextTableCell cell;
QTextCursor cellCursor;
QTextCharFormat charFormat;
charFormat.setForeground(Qt::black);
//! [4]
cell = table->cellAt(0, 0);
cellCursor = cell.firstCursorPosition();
cellCursor.insertText(tr("Week"), charFormat);
//! [4]
//! [5]
for (column = 1; column < columns; ++column) {
cell = table->cellAt(0, column);
cellCursor = cell.firstCursorPosition();
cellCursor.insertText(tr("Team %1").arg(column), charFormat);
}
for (row = 1; row < rows; ++row) {
cell = table->cellAt(row, 0);
cellCursor = cell.firstCursorPosition();
cellCursor.insertText(tr("%1").arg(row), charFormat);
for (column = 1; column < columns; ++column) {
if ((row-1) % 3 == column-1) {
//! [5] //! [6]
cell = table->cellAt(row, column);
QTextCursor cellCursor = cell.firstCursorPosition();
cellCursor.insertText(tr("On duty"), charFormat);
}
//! [6] //! [7]
}
//! [7] //! [8]
}
//! [8]
connect(saveAction, SIGNAL(triggered()), this, SLOT(saveFile()));
connect(quitAction, SIGNAL(triggered()), this, SLOT(close()));
connect(showTableAction, SIGNAL(triggered()), this, SLOT(showTable()));
setCentralWidget(editor);
setWindowTitle(tr("Text Document Tables"));
}
示例15: changeFormatType
void CreateBlogMsg::changeFormatType(int styleIndex )
{
ui.msgEdit->setFocus( Qt::OtherFocusReason );
QTextCursor cursor = ui.msgEdit->textCursor();
//QTextBlockFormat bformat = cursor.blockFormat();
QTextBlockFormat bformat;
QTextCharFormat cformat;
switch (styleIndex) {
default:
case 0:
bformat.setProperty( TextFormat::HtmlHeading, QVariant( 0 ) );
cformat.setFontWeight( QFont::Normal );
cformat.setProperty( QTextFormat::FontSizeAdjustment, QVariant( 0 ) );
break;
case 1:
bformat.setProperty( TextFormat::HtmlHeading, QVariant( 1 ) );
cformat.setFontWeight( QFont::Bold );
cformat.setProperty( QTextFormat::FontSizeAdjustment, QVariant( 3 ) );
break;
case 2:
bformat.setProperty( TextFormat::HtmlHeading, QVariant( 2 ) );
cformat.setFontWeight( QFont::Bold );
cformat.setProperty( QTextFormat::FontSizeAdjustment, QVariant( 2 ) );
break;
case 3:
bformat.setProperty( TextFormat::HtmlHeading, QVariant( 3 ) );
cformat.setFontWeight( QFont::Bold );
cformat.setProperty( QTextFormat::FontSizeAdjustment, QVariant( 1 ) );
break;
case 4:
bformat.setProperty( TextFormat::HtmlHeading, QVariant( 4 ) );
cformat.setFontWeight( QFont::Bold );
cformat.setProperty( QTextFormat::FontSizeAdjustment, QVariant( 0 ) );
break;
case 5:
bformat.setProperty( TextFormat::HtmlHeading, QVariant( 5 ) );
cformat.setFontWeight( QFont::Bold );
cformat.setProperty( QTextFormat::FontSizeAdjustment, QVariant( -1 ) );
break;
case 6:
bformat.setProperty( TextFormat::HtmlHeading, QVariant( 6 ) );
cformat.setFontWeight( QFont::Bold );
cformat.setProperty( QTextFormat::FontSizeAdjustment, QVariant( -2 ) );
break;
}
//cformat.clearProperty( TextFormat::HasCodeStyle );
cursor.beginEditBlock();
cursor.mergeBlockFormat( bformat );
cursor.select( QTextCursor::BlockUnderCursor );
cursor.mergeCharFormat( cformat );
cursor.endEditBlock();
}