void NoteEditWidget::resizeEvent(QResizeEvent *) { int screenWidth = width(); int screenHeight = height(); if (screenWidth > screenHeight) { // we have a classical landscape monitor noteEditHeight = screenHeight - TextEditMargin; noteEditWidth = static_cast<int>(noteEditHeight * NoteEditWidthMultiplier); } else { // we have monitor standing in portrait noteEditWidth = screenWidth - TextEditMargin; noteEditHeight = static_cast<int>(noteEditWidth / NoteEditWidthMultiplier); } noteEditXPos = (screenWidth - noteEditWidth) / 2; noteEditYPos = (screenHeight - noteEditHeight) / 2; visualCover->setGeometry(0, 0, width(), height()); textEdit->setGeometry(noteEditXPos, noteEditYPos, noteEditWidth, noteEditHeight); textEdit->setFocus(); textEdit->setFont(getFontForTextEditWith(noteEditWidth)); for (QTextBlock block = textEdit->document()->begin(); block.isValid(); block = block.next()) { QTextCursor tc = QTextCursor(block); QTextBlockFormat fmt = block.blockFormat(); fmt.setLineHeight(LineHeightPercentage, QTextBlockFormat::ProportionalHeight); tc.setBlockFormat(fmt); } }
ChatWindow::ChatWindow(QWidget* parent) : QWidget(parent, Qt::Window | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint), ui(new Ui::ChatWindow), numMessagesAfterLastTimeStamp(0), _mousePressed(false), _mouseStartPosition(), _trayIcon(parent), _effectPlayer() { setAttribute(Qt::WA_DeleteOnClose, false); ui->setupUi(this); FlowLayout* flowLayout = new FlowLayout(0, 4, 4); ui->usersWidget->setLayout(flowLayout); ui->messagePlainTextEdit->installEventFilter(this); ui->messagePlainTextEdit->setWordWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere); QTextCursor cursor(ui->messagePlainTextEdit->textCursor()); cursor.movePosition(QTextCursor::Start); QTextBlockFormat format = cursor.blockFormat(); format.setLineHeight(130, QTextBlockFormat::ProportionalHeight); cursor.setBlockFormat(format); ui->messagePlainTextEdit->setTextCursor(cursor); if (!AccountManager::getInstance().isLoggedIn()) { ui->connectingToXMPPLabel->setText(tr("You must be logged in to chat with others.")); } #ifdef HAVE_QXMPP const QXmppClient& xmppClient = XmppClient::getInstance().getXMPPClient(); if (xmppClient.isConnected()) { participantsChanged(); const QXmppMucRoom* publicChatRoom = XmppClient::getInstance().getPublicChatRoom(); connect(publicChatRoom, SIGNAL(participantsChanged()), this, SLOT(participantsChanged())); ui->connectingToXMPPLabel->hide(); startTimerForTimeStamps(); } else { ui->numOnlineLabel->hide(); ui->usersArea->hide(); ui->messagesScrollArea->hide(); ui->messagePlainTextEdit->hide(); connect(&XmppClient::getInstance(), SIGNAL(joinedPublicChatRoom()), this, SLOT(connected())); } connect(&xmppClient, SIGNAL(messageReceived(QXmppMessage)), this, SLOT(messageReceived(QXmppMessage))); connect(&_trayIcon, SIGNAL(messageClicked()), this, SLOT(notificationClicked())); #endif // HAVE_QXMPP QDir mentionSoundsDir(Application::resourcesPath() + mentionSoundsPath); _mentionSounds = mentionSoundsDir.entryList(QDir::Files); _trayIcon.setIcon(QIcon( Application::resourcesPath() + "/images/hifi-logo.svg")); }
QTextDocument *Exporter::prepareTextDoc(QTextDocument *textDoc) { QTextDocument *textDocument = textDoc->clone(this); // textDocument->setDefaultStyleSheet("p, li { white-space: pre-wrap; } p{line-height: 2em; font-family:'Liberation Serif'; font-size:19pt;margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:72px;}"); //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->mergeBlockFormat(blockFormat); // tCursor->mergeBlockCharFormat(charFormat); 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)); return textDocument; }
void Dialog_report::buat_table() { int i; QTextCursor cursor( ui->edit->textCursor()); cursor.movePosition(QTextCursor::Start); ui->edit->setText("Ini report"); /* QTextTableFormat format; format.setHeight( 600 ); format.setWidth( 800 ); format.setCellPadding( 1 ); format.setCellSpacing( 1 ); format.setHeaderRowCount( 2 ); QTextTable *table = cursor.insertTable(10, 5, format); */ QTextTable *table = cursor.insertTable(10, 5 ); QTextBlockFormat centerAlignment; centerAlignment.setAlignment(Qt::AlignHCenter); centerAlignment.setLineHeight( 30, QTextBlockFormat::FixedHeight); centerAlignment.setLeftMargin( 10 ); centerAlignment.setRightMargin( 10 ); QTextCursor cursor2; cursor2 = table->cellAt(0, 0).firstCursorPosition(); cursor2.insertText(QString::fromUtf8("No")); cursor2.setBlockFormat(centerAlignment); for (i=1; i<9; i++) { cursor2 = table->cellAt(i, 0).firstCursorPosition(); cursor2.setBlockFormat(centerAlignment); cursor2.insertText(QString::number(i+1) + "Sil"); } /* int i, y; for (i=0; i<4; i++) { for (y=0;y<5; y++) QTextTable *table = cursor.insertTable( y, i ); //QTextTable *table = cursor.insertTable( y, i, tableFormat); }*/ //QTextTable *tbl; //tbl = new QTextTable( ui->edit ); }
void ChatMessageArea::setHtml(const QString& html) { // Create format with updated line height QTextBlockFormat format; format.setLineHeight(CHAT_MESSAGE_LINE_HEIGHT, QTextBlockFormat::ProportionalHeight); // Possibly a bug in QT, the format won't take effect if `insertHtml` is used first. Inserting a space and deleting // it after ensures the format is applied. QTextCursor cursor = textCursor(); cursor.setBlockFormat(format); cursor.insertText(" "); cursor.insertHtml(html); cursor.setPosition(0); cursor.deleteChar(); }
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; }
void MarkdownHighlighter::applyLineHeight() { QTextBlock block = document->firstBlock(); while (block.isValid()) { QTextCursor cursor(block); QTextBlockFormat format = cursor.blockFormat(); // Don't apply lineHeight if it's already applied it to this block if (format.lineHeightType() != QTextBlockFormat::ProportionalHeight) { format.setLineHeight(130, QTextBlockFormat::ProportionalHeight); // joining previous edit is crucial, otherwise formatting changes are recorded // as separate operations in undo/redo stack, and pressing Ctrl-Z undoes // line height changes, clearly not what we want cursor.joinPreviousEditBlock(); cursor.setBlockFormat(format); cursor.endEditBlock(); } block = block.next(); } }
void TextBrowser::append(const QString& text, bool highlight) { if (!text.isEmpty()) { QTextBrowser::append(text); #if QT_VERSION >= 0x040800 QTextCursor cursor(document()); cursor.movePosition(QTextCursor::End); QTextBlockFormat format = cursor.blockFormat(); format.setLineHeight(120, QTextBlockFormat::ProportionalHeight); cursor.setBlockFormat(format); #endif // QT_VERSION int count = document()->blockCount(); if (count == document()->maximumBlockCount()) { if (d.ub != -1) --d.ub; QMutableListIterator<int> mt(d.markers); while (mt.hasNext()) { --mt.next(); if (mt.value() < 0) mt.remove(); } QMutableListIterator<int> ht(d.highlights); while (ht.hasNext()) { --ht.next(); if (ht.value() < 0) ht.remove(); } } if (!isVisible() && d.ub == -1) d.ub = count - 1; if (highlight) d.highlights.append(count - 1); } }
void ConsoleLog::appendToLog(QString message) { bool scrollToBottom = false; if(_log->verticalScrollBar()->value() == _log->verticalScrollBar()->maximum()) { scrollToBottom = true; } QTextBlockFormat format; format.setLineHeight(30, 0); QTextCursor cursor = _log->textCursor(); cursor.setBlockFormat(format); int pos = cursor.position(); cursor.setPosition(_log->toPlainText().length()); cursor.insertHtml(message + "<br/><br/><br/>"); cursor.setPosition(pos); if(scrollToBottom) _log->verticalScrollBar()->setValue(_log->verticalScrollBar()->maximum()); }
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; }
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 ); }