示例#1
0
void DPText::drawShape( QPainter &p )
{
	QRect bound = m_sizeRect;
	bound.setWidth( bound.width()-2 );
	bound.setHeight( bound.height()-2 );
	bound.translate( int(x()+1), int(y()+1) );
	
	if (b_displayBackground)
	{
		p.save();
		p.setPen( QPen( m_frameColor, 1, Qt::DotLine) );
		p.setBrush(m_backgroundColor);
		p.drawRect(bound);
		p.restore();
	}
	
	const int pad = 6;
	
	bound.setLeft( bound.left()+pad );
	bound.setTop( bound.top() );
	bound.setRight( bound.right()-pad );
	bound.setBottom( bound.bottom()-pad );
	
	QTextEdit * t = new QTextEdit( m_text );
    t->resize( bound.width(), bound.height() ); // t->setWidth( bound.width() );
    t->viewport()->setAutoFillBackground( false );
    t->setFrameStyle(QFrame::NoFrame);

    t->render( &p, bound.topLeft(), QRegion(), QWidget::DrawChildren ); //t->draw( &p, bound.left(), bound.top(), bound, QColorGroup() );
	delete t;
}
示例#2
0
void TransparentBg::backgroundUpdated()
{
    if (parent()->inherits("QTextEdit")){
        QTextEdit *text = static_cast<QTextEdit*>(parent());
        const QPixmap *pix = background(text->colorGroup().color(QColorGroup::Base));
        QPoint pp = text->viewportToContents(QPoint(0, 0));
        bgX = pp.x();
        bgY = pp.y();
        if ((pix == NULL) || pix->isNull()){
            if (text->paper().pixmap() && !text->paper().pixmap()->isNull()){
                text->setPaper(QBrush(text->colorGroup().base()));
                text->setStaticBackground(false);
            }
            return;
        }
        QPoint pp1 = text->topLevelWidget()->mapFromGlobal(text->mapToGlobal(QPoint(0, 0)));
        QPixmap bg(bgX + text->width(), bgY + text->height());
        QPainter p;
        p.begin(&bg);
        p.drawTiledPixmap(bgX, bgY, text->width(), text->height(), *pix, pp1.x(), pp1.y());
        p.end();
        text->setPaper(QBrush(text->colorGroup().background(), bg));
        text->setStaticBackground(true);
        text->setBackgroundMode(QWidget::NoBackground);
        text->viewport()->setBackgroundMode(QWidget::NoBackground);
        return;
    }
    if (parent()->inherits("QListView")){
        QListView *p = static_cast<QListView*>(parent());
        p->viewport()->repaint();
    }
}
void TextEdit::fileNew()
{
    QTextEdit *edit = new QTextEdit( tabWidget );
    doConnections( edit );
    tabWidget->addTab( edit, tr( "noname" ) );
    tabWidget->showPage( edit );
    edit->viewport()->setFocus();
}
示例#4
0
TransparentBg::TransparentBg(QWidget *p, const char *name)
        : QObject(p, name)
{
    if (p->inherits("QTextEdit")){
        QTextEdit *parent = static_cast<QTextEdit*>(p);
        parent->viewport()->installEventFilter(this);
    }
    init(p);
}
void TextEdit::load( const QString &f )
{
    if ( !QFile::exists( f ) )
	return;
    QTextEdit *edit = new QTextEdit( tabWidget );
    doConnections( edit );
    tabWidget->addTab( edit, QFileInfo( f ).fileName() );

    QFile fl( f );
    fl.open( IO_ReadOnly );
    QByteArray array = fl.readAll();
    array.resize( array.size() +1 );
    array[ (int)array.size() - 1 ] = '\0';
    QString text = ( f.find( "bidi.txt" ) != -1 ? QString::fromUtf8( array.data() ) : QString::fromLatin1( array.data() ) );
    edit->setText( text );

    edit->viewport()->setFocus();
    edit->setTextFormat( Qt::RichText );
}
示例#6
0
void TextEdit::load( const QString &f )
{
    if ( !QFile::exists( f ) )
	return;
    QTextEdit *edit = new QTextEdit( tabWidget );
    edit->setTextFormat( RichText );
    doConnections( edit );
    tabWidget->addTab( edit, QFileInfo( f ).fileName() );
    QFile file( f );
    if ( !file.open( IO_ReadOnly ) )
	return;
    QTextStream ts( &file );
    QString txt = ts.read();
    if ( !QStyleSheet::mightBeRichText( txt ) )
	txt = QStyleSheet::convertFromPlainText( txt, QStyleSheetItem::WhiteSpacePre );
    edit->setText( txt );
    tabWidget->showPage( edit );
    edit->viewport()->setFocus();
    filenames.replace( edit, f );
}