void NumberedTextView::textChanged( int pos, int removed, int added )
{
    Q_UNUSED( pos );

    if ( removed == 0 && added == 0 )
	return;

    QTextBlock block = highlight.block();
    QTextBlockFormat fmt = block.blockFormat();
    QColor bg = view->palette().base().color();
    fmt.setBackground( bg );
    highlight.setBlockFormat( fmt );

    int lineCount = 1;
    for ( QTextBlock block = view->document()->begin();
	  block.isValid(); block = block.next(), ++lineCount ) 
    {
        if ( lineCount == markedLine )
        {
            fmt = block.blockFormat();
            QColor bg = Qt::red;
            fmt.setBackground( bg.light(150) );

            highlight = QTextCursor( block );
            highlight.movePosition( QTextCursor::EndOfBlock, QTextCursor::KeepAnchor );
            highlight.setBlockFormat( fmt );

            break;
        }
    }
}
Example #2
0
void MainWindow::highlightListItems()
{
    QTextCursor cursor = editor->textCursor();
    QTextList *list = cursor.currentList();

    if (!list)
        return;

    cursor.beginEditBlock();
//! [0]
    for (int index = 0; index < list->count(); ++index) {
        QTextBlock listItem = list->item(index);
//! [0]
        QTextBlockFormat newBlockFormat = listItem.blockFormat();
        newBlockFormat.setBackground(Qt::lightGray);
        QTextCursor itemCursor = cursor;
        itemCursor.setPosition(listItem.position());
        //itemCursor.movePosition(QTextCursor::StartOfBlock);
        itemCursor.movePosition(QTextCursor::EndOfBlock,
                                QTextCursor::KeepAnchor);
        itemCursor.setBlockFormat(newBlockFormat);
        /*
//! [1]
        processListItem(listItem);
//! [1]
        */
//! [2]
    }
//! [2]
    cursor.endEditBlock();
}
void QLineNumberTextEdit::textChanged( int pos, int removed, int added )
{
	return;
	Q_UNUSED( pos );
#if 0
	if ( removed == 0 && added == 0 )
		return;

	if(doHighlighting)
	{
		QTextBlock block = highlight.block();
		QTextBlockFormat fmt = block.blockFormat();
		QColor bg = view->palette().base().color();
		fmt.setBackground( bg );
		highlight.setBlockFormat( fmt );

		int lineCount = 1;
		for ( QTextBlock block = view->document()->begin();
			 block.isValid(); block = block.next(), ++lineCount ) {

			//		if ( lineCount == infoLine ) {
			//			fmt = block.blockFormat();
			//			QColor bg = view->palette().highlight().color().light(150);
			//			fmt.setBackground( bg );

			//			highlight = QTextCursor( block );
			//			highlight.movePosition( QTextCursor::EndOfBlock, QTextCursor::KeepAnchor );
			//			highlight.setBlockFormat( fmt );

			//			break;
			//		} else if ( lineCount == warningLine ) {
			//			fmt = block.blockFormat();
			//			QColor bg = view->palette().highlight().color().light(100);
			//			fmt.setBackground( bg );

			//			highlight = QTextCursor( block );
			//			highlight.movePosition( QTextCursor::EndOfBlock, QTextCursor::KeepAnchor );
			//			highlight.setBlockFormat( fmt );

			//			break;
			//		} else if ( lineCount == errorLine ) {
			//			fmt = block.blockFormat();
			//			QColor bg = view->palette().highlight().color().light(100);
			//			fmt.setBackground( bg );

			//			highlight = QTextCursor( block );
			//			highlight.movePosition( QTextCursor::EndOfBlock, QTextCursor::KeepAnchor );
			//			highlight.setBlockFormat( fmt );

			//			break;
			//		}
		}
	}
#endif
}
void DisplayText::_insertText(const QString text, const QString bg)
{
    QString tt = text.mid(0,_maxDisplayedCharacters); //truncate to max display chars
    QString s = "<table border=0 cellspacing=0 width=100%><tr><td bgcolor=\"" +
                bg + "\"><pre>" + tt + "</pre></td></tr></table>";

    QTextCursor cursor = textCursor();
    cursor.movePosition(QTextCursor::End);
    QTextBlockFormat bf = cursor.blockFormat();
    bf.setBackground(QBrush(QColor(bg)));
    cursor.insertHtml(s);
    this->setTextCursor(cursor);
}
Example #5
0
/*
 Send the contents of the commandLine to the serial port,
 and add them to the output console
*/
void UsbConsole::onCommandLine( )
{
  if(port->isOpen() && !commandLine->currentText().isEmpty())
  {
    if(port->write(commandLine->currentText().toUtf8()) < 0)
      closeDevice();
    else
    {
      QTextBlockFormat format;
      format.setBackground(QColor(229, 237, 247, 255)); // light blue
      if(currentView == "Characters")
        outputConsole->appendPlainText(commandLine->currentText()); // insert the message
      else if(currentView == "Hex")
        outputConsole->appendPlainText(strToHex(commandLine->currentText()));
      outputConsole->moveCursor(QTextCursor::End); // move the cursor to the end
      outputConsole->textCursor().setBlockFormat(format);
      outputConsole->insertPlainText("\n");
      format.setBackground(Qt::white); // reset the format to white for any subsequent messages received
      outputConsole->textCursor().setBlockFormat(format);
    }
    commandLine->clear();
  }
}
Example #6
0
QTextCursor ChatView::prepareBlock(bool same)
{
	lastSender.clear();
	
	QTextCursor cursor(document()->lastBlock());
	cursor.movePosition(QTextCursor::End);
	if (!same) {
		QTextBlockFormat blockFormat;
		if ((evenNumber = !evenNumber))
			blockFormat.setBackground(palette().alternateBase());
		blockFormat.setBottomMargin(2);
		cursor.insertBlock(blockFormat);
	} else
		cursor.insertHtml("<br>");
	
	return cursor;
}
Example #7
0
File: main.cpp Project: cedrus/qt4
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();
}
Example #8
0
void
WChatLog::ChatLog_EventsDisplay(const CArrayPtrEvents & arraypEvents, int iEventStart)
	{
	Assert(iEventStart >= 0);
	Assert(m_oTextBlockComposing.isValid());
//	CSocketXmpp * pSocket = m_pContactOrGroup->Xmpp_PGetSocketOnlyIfReady();

	OCursorSelectBlock oCursor(m_oTextBlockComposing);
	QTextBlock oTextBlockEvent;	// Text block for each event to insert
	IEvent ** ppEventStop;
	IEvent ** ppEventFirst = arraypEvents.PrgpGetEventsStop(OUT &ppEventStop) + iEventStart;
	IEvent ** ppEvent = ppEventFirst;
	if (!m_fDisplayAllMessages)
		{
		// For performance, limit the display to the last 100 events
		if (ppEventStop != NULL)
			{
			IEvent ** ppEventStart = ppEventStop - 100;
			if (ppEventStart > ppEvent)
				{
				ppEvent = ppEventStart;

				QTextBlockFormat oFormat;
				oFormat.setAlignment(Qt::AlignHCenter);
				oFormat.setBackground(c_brushSilver);	// Use a silver color
				oCursor.setBlockFormat(oFormat);
				g_strScratchBufferStatusBar.Format("<a href='" d_SzMakeCambrianAction(d_szCambrianAction_DisplayAllHistory) "'>Display complete history ($I messages)</a>", arraypEvents.GetSize());
				oCursor.insertHtml(g_strScratchBufferStatusBar);
				oCursor.AppendBlockBlank();
				}
			}
		}

	while (ppEvent < ppEventStop)
		{
		IEvent * pEvent = *ppEvent++;
		AssertValidEvent(pEvent);
		if (pEvent->m_tsEventID >= m_tsMidnightNext)
			{
			QDateTime dtl = QDateTime::fromMSecsSinceEpoch(pEvent->m_tsEventID).toLocalTime();
			QDate date = dtl.date();	// Strip the time of the day
			m_tsMidnightNext = QDateTime(date).toMSecsSinceEpoch() + d_ts_cDays;	// I am sure there is a more elegant way to strip the time from a date, however at the moment I don't have time to investigate a better solution (and this code works)

			QTextBlockFormat oFormatBlock;
			oFormatBlock.setAlignment(Qt::AlignHCenter);
			oFormatBlock.setBackground(c_brushSilver);
			oCursor.setBlockFormat(oFormatBlock);
			QTextCharFormat oFormatChar; // = oCursor.charFormat();
			oFormatChar.setFontWeight(QFont::Bold);
			//oFormatChar.setFontItalic(true);
			//oCursor.setCharFormat(oFormatChar);
			oCursor.insertText(date.toString("dddd MMMM d, yyyy"), oFormatChar);
			oCursor.AppendBlockBlank();
			}
		oTextBlockEvent = oCursor.block();	// Get the current block under the cursor
		Endorse(oTextBlockEvent.userData() == NULL);

		if (pEvent->m_uFlagsEvent & IEvent::FE_kfReplacing)
			{
			MessageLog_AppendTextFormatSev(eSeverityComment, "Attempting to replace Event ID $t\n", pEvent->m_tsEventID);
			QTextBlock oTextBlockUpdate;
			QTextBlock oTextBlockTemp = document()->lastBlock();
			IEvent * pEventOld = pEvent;
			const EEventClass eEventClassUpdater = pEvent->Event_FIsEventTypeSent() ? CEventUpdaterSent::c_eEventClass : CEventUpdaterReceived::c_eEventClass;	// Which updater to search for
			// The event is replacing an older event.  This code is a bit complex because the Chat Log may not display all events and therefore we need to find the most recent block displaying the most recent event.
			IEvent ** ppEventStop;
			IEvent ** ppEventFirst = pEvent->m_pVaultParent_NZ->m_arraypaEvents.PrgpGetEventsStop(OUT &ppEventStop);
			IEvent ** ppEventCompare = ppEventStop;	// Search the array from the end, as the event to search is likely to be a recent one
			while (ppEventFirst < ppEventCompare)
				{
				// Find the updater which should be right before the replacing event
				IEvent * pEventTemp = *--ppEventCompare;
				TryAgain:
				if (pEventTemp == pEventOld && ppEventFirst < ppEventCompare)
					{
					CEventUpdaterSent * pEventUpdater = (CEventUpdaterSent *)*--ppEventCompare;	// Get the updater which is just before the event
					if (pEventUpdater->EGetEventClass() != eEventClassUpdater)
						{
						MessageLog_AppendTextFormatSev(eSeverityErrorWarning, "\t Missing Updater for Event ID $t ({tL}); instead found class '$U' with Event ID $t.\n", pEventTemp->m_tsEventID, pEventTemp->m_tsEventID, pEventUpdater->EGetEventClass(), pEventUpdater->m_tsEventID);
						pEvent->m_uFlagsEvent &= ~IEvent::FE_kfReplacing;	// Remove the bit to avoid displaying the error again and again
						pEvent->m_pVaultParent_NZ->SetModified();			// Save the change
						continue;
						}
					const TIMESTAMP tsEventIdOld = pEventUpdater->m_tsEventIdOld;
					MessageLog_AppendTextFormatSev(eSeverityNoise, "\t [$i] Found updater: $t  ->  $t\n", ppEventCompare - ppEventFirst, pEventUpdater->m_tsEventIdNew, tsEventIdOld);
					// Now, search for the block containing the replacement event
					while (oTextBlockTemp.isValid())
						{
						OTextBlockUserDataEvent * pUserData = (OTextBlockUserDataEvent *)oTextBlockTemp.userData();
						if (pUserData != NULL)
							{
							TIMESTAMP_DELTA dtsEvent = (pUserData->m_pEvent->m_tsEventID - tsEventIdOld);
							MessageLog_AppendTextFormatCo(d_coPurple, "Comparing block Event ID $t with $t: dtsEvent = $T\n", pUserData->m_pEvent->m_tsEventID, tsEventIdOld, dtsEvent);
							if (dtsEvent <= 0)
								{
								if (dtsEvent == 0)
									{
									MessageLog_AppendTextFormatSev(eSeverityNoise, "\t Found matching textblock for replacement: Event ID $t  ->  $t\n", pEventOld->m_tsEventID, tsEventIdOld);
									oTextBlockUpdate = oTextBlockTemp;
									}
								break;
								}
							}
						oTextBlockTemp = oTextBlockTemp.previous();
						} // while
					// Keep searching in case there are chained updated events
					while (ppEventFirst < ppEventCompare)
						{
						pEventTemp = *--ppEventCompare;
						if (pEventTemp->m_tsEventID == tsEventIdOld)
							{
							MessageLog_AppendTextFormatSev(eSeverityNoise, "\t [$i] Found chained replacement: Event ID $t  -> $t\n", ppEventCompare - ppEventFirst, pEvent->m_tsEventID, tsEventIdOld);
							pEventTemp->m_uFlagsEvent |= IEvent::FE_kfReplaced;
							pEventOld = pEventTemp;
							goto TryAgain;
							}
						} // while
					} // if
				} // while
			if (oTextBlockUpdate.isValid())
				{
				MessageLog_AppendTextFormatSev(eSeverityNoise, "\t Event ID $t is updating its old Event ID $t\n", pEvent->m_tsEventID, pEventOld->m_tsEventID);
				OCursorSelectBlock oCursorEventOld(oTextBlockUpdate);
				pEvent->ChatLogUpdateTextBlock(INOUT &oCursorEventOld);
				continue;
				}
			MessageLog_AppendTextFormatSev(eSeverityErrorWarning, "Event ID $t is replacing another event which cannot be found\n", pEvent->m_tsEventID);
			} // if (replacing)
		oTextBlockEvent.setUserData(PA_CHILD new OTextBlockUserDataEvent(pEvent));		// Assign an event for each text block
		pEvent->ChatLogUpdateTextBlock(INOUT &oCursor);
		if ((pEvent->m_uFlagsEvent & IEvent::FE_kfEventHidden) == 0)
			oCursor.AppendBlockBlank();	// If the event is visible, then add a new text block (otherwise it will reuse the same old block)
		else
			oTextBlockEvent.setUserData(NULL);	// Since we are reusing the same block, delete its userdata so we may assing another OTextBlockUserDataEvent
		} // while
	m_oTextBlockComposing = oCursor.block();
	ChatLog_ChatStateTextAppend(INOUT oCursor);
	Widget_ScrollToEnd(INOUT this);
	} // ChatLog_EventsDisplay()
Example #9
0
void CBuoni::generateReport()
{


    QApplication::setOverrideCursor(Qt::WaitCursor);



    modregs->setRelation(3,QSqlRelation("tipi_mov","ID","descrizione"));
    modregs->setRelation(4,QSqlRelation("anagrafica","ID","descrizione"));
    modrighe->setRelation(2,QSqlRelation("tipi_ope","ID","descrizione"));

    models->append(modregs);
    models->append(modrighe);


    CPrintingJob *f=new CPrintingJob(0,models);


    QDate dal=ui->deDal->date();
    QDate al= ui->deAL->date();
    int printpages=ui->cbPrintNumber->currentIndex();
    qDebug()<<"printpages: "<<printpages;



    modregs->setFilter("datareg between '" +dal.toString("yyyy-MM-dd")+"' and '" + al.toString("yyyy-MM-dd")+"'");
     f->cursorToStart();
    int rws=modregs->rowCount();
    for (int row=0;row<rws;row++)
    {

        modregs->setSort(0,Qt::AscendingOrder);
        QString ID=modregs->index(row,0).data(0).toString();
        QString del=modregs->index(row,1).data(0).toDate().toString("dd-MM-yyyy");
        QString dip =modregs->index(row,2).data(0).toString();

        modrighe->setFilter("righe_reg.ID="+ID);


        f->cursorToEnd();
        QTextBlockFormat frm;
        frm.setBackground(Qt::white);
        f->addText("BUONO N."+ID+" del "+del,frm);
        f->cursorToEnd();
        f->addText("Dipendente: "+dip);
        f->cursorToEnd();
        f->addSqlTable(1,true);
        f->cursorToEnd();
        f->addText("importo: "+QString::number(calcImporti(row),'f',2)+"\n");
        f->cursorToEnd();

        int formsforpage;
        int page;

        switch(printpages)
        {
        case 0:
            //stampa continua
        break;

        case 1:
            //uno per pagina
            f->insertPageBreak();
            f->cursorToEnd();

        break;

        case 2:
            //due per pagina
            formsforpage=2;



        break;

        case 3:
          //  quattro per pagina
            formsforpage=4;

        break;


        }

        page=row+1;


        if (page % formsforpage==0)
        {
            f->insertPageBreak();
            f->cursorToEnd();
        }


   }







    QApplication::restoreOverrideCursor();
    f->show();
}