Esempio n. 1
0
QmvPopup::QmvPopup ( const QString& contents, const QPoint& pos, QWidget * parent, const char * name )
        : QWidget( parent, name, WType_Popup | WDestructiveClose )
{
    
    const int shadowWidth = 6;   // also used as '5' and '6' and even '8' below
    const int vMargin = 8;
    const int hMargin = 12;

    setBackgroundMode( QWidget::NoBackground );
    QSimpleRichText* doc = new QSimpleRichText( contents, font() );
  
    doc->adjustSize();
    QRect r( 0, 0, doc->widthUsed(), doc->height() );
    int w = r.width() + 2*hMargin;
    int h = r.height() + 2*vMargin;
 
    resize( w + shadowWidth, h + shadowWidth ); 

    move( pos - rect().center());
     if (geometry().right() > QApplication::desktop()->width())
         move( QApplication::desktop()->width() - width(),
               y() );
     if (geometry().bottom() > QApplication::desktop()->height())
         move( x(),
               QApplication::desktop()->height() - height() );
     if ( x() < 0 )
         move( 0, y() );
     if ( y() < 0 )
         move( x(), 0 );
    show();

    QPainter p( this );
    p.setPen( QApplication::palette().normal().foreground() );
    p.drawRect( 0, 0, w, h );
    p.setPen( QApplication::palette().normal().mid() );
    p.setBrush( QColor( 255, 255, 240 ) );
    p.drawRect( 1, 1, w-2, h-2 );
    p.setPen( black );
    doc->draw( &p, hMargin, vMargin, r, colorGroup(), 0 );
    delete doc;
    p.drawPoint( w + 5, 6 );
    p.drawLine( w + 3, 6,
                w + 5, 8 );
    p.drawLine( w + 1, 6,
                w + 5, 10 );
    int i;
    for( i=7; i < h; i += 2 )
        p.drawLine( w, i,
                    w + 5, i + 5 );
    for( i = w - i + h; i > 6; i -= 2 )
        p.drawLine( i, h,
                    i + 5, h + 5 );
    for( ; i > 0 ; i -= 2 )
        p.drawLine( 6, h + 6 - i,
                    i + 5, h + 5 );

}
Esempio n. 2
0
void Canvas::drawForeground(QPainter &p, const QRect & clip) {
	QCanvas::drawForeground(p, clip);

	if (!m_pMessageTimeout->isActive())
		return;

	// Following code stolen and adapted from amarok/src/playlist.cpp :)

	// Find out width of smallest view
	QSize minSize;

	const ViewList viewList = p_itemDocument->viewList();

	ViewList::const_iterator end = viewList.end();
	View *firstView = 0;
	for (ViewList::const_iterator it = viewList.begin(); it != end; ++it) {
		if (!*it) continue;

		if (!firstView) {
			firstView = *it;
			minSize = (*it)->size();
		} else	minSize = minSize.boundedTo((*it)->size());
	}

	if (!firstView) return;

	QSimpleRichText *t = new QSimpleRichText(m_message, QApplication::font());

	const int w = t->width();
	const int h = t->height();
	const int x = rect().left() + 15;
	const int y = rect().top() + 15;
	const int b = 10; // text padding

	if (w + 2 * b >= minSize.width() || h + 2 * b >= minSize.height()) {
		delete t;
		return;
	}

	p.setBrush(firstView->colorGroup().background());

	p.drawRoundRect(x, y,
			w + 2 * b,
			h + 2 * b,
			(8 * 200) / (w + 2 * b),
			(8 * 200) / (h + 2 * b));

	t->draw(&p, x + b, y + b, QRect(), firstView->colorGroup());
	delete t;
}
Esempio n. 3
0
void QwtPainter::drawSimpleRichText(QPainter *painter, const QRect &rect,
    int flags, QSimpleRichText &text)
{
    QColorGroup cg;
    cg.setColor(QColorGroup::Text, painter->pen().color());

    const QRect scaledRect = d_metricsMap.layoutToDevice(rect, painter);

    text.setWidth(painter, scaledRect.width());

    // QSimpleRichText is Qt::AlignTop by default

    int y = scaledRect.y();
    if (flags & Qt::AlignBottom)
        y += (scaledRect.height() - text.height());
    else if (flags & Qt::AlignVCenter)
        y += (scaledRect.height() - text.height())/2;

    text.draw(painter, scaledRect.x(), y, scaledRect, cg);
}
Esempio n. 4
0
void QTextBrowser::popupDetail( const QString& contents, const QPoint& pos )
{

    const int shadowWidth = 6;   // also used as '5' and '6' and even '8' below
    const int vMargin = 8;
    const int hMargin = 12;

    QWidget* popup = new QTextDetailPopup;
    popup->setBackgroundMode( QWidget::NoBackground );

    QSimpleRichText* doc = new QSimpleRichText( contents, popup->font() );
    doc->adjustSize();
    QRect r( 0, 0, doc->width(), doc->height() );

    int w = r.width() + 2*hMargin;
    int h = r.height() + 2*vMargin;

    popup->resize( w + shadowWidth, h + shadowWidth );

    // okay, now to find a suitable location
    //###### we need a global fancy popup positioning somewhere
    popup->move(pos - popup->rect().center());
    if (popup->geometry().right() > QApplication::desktop()->width())
        popup->move( QApplication::desktop()->width() - popup->width(),
                     popup->y() );
    if (popup->geometry().bottom() > QApplication::desktop()->height())
        popup->move( popup->x(),
                     QApplication::desktop()->height() - popup->height() );
    if ( popup->x() < 0 )
        popup->move( 0, popup->y() );
    if ( popup->y() < 0 )
        popup->move( popup->x(), 0 );


    popup->show();

    // now for super-clever shadow stuff.  super-clever mostly in
    // how many window system problems it skirts around.

    QPainter p( popup );
    p.setPen( QApplication::palette().active().foreground() );
    p.drawRect( 0, 0, w, h );
    p.setPen( QApplication::palette().active().mid() );
    p.setBrush( QColor( 255, 255, 240 ) );
    p.drawRect( 1, 1, w-2, h-2 );
    p.setPen( black );

    doc->draw( &p, hMargin, vMargin, r, popup->colorGroup(), 0 );
    delete doc;

    p.drawPoint( w + 5, 6 );
    p.drawLine( w + 3, 6,
                w + 5, 8 );
    p.drawLine( w + 1, 6,
                w + 5, 10 );
    int i;
    for( i=7; i < h; i += 2 )
        p.drawLine( w, i,
                    w + 5, i + 5 );
    for( i = w - i + h; i > 6; i -= 2 )
        p.drawLine( i, h,
                    i + 5, h + 5 );
    for( ; i > 0 ; i -= 2 )
        p.drawLine( 6, h + 6 - i,
                    i + 5, h + 5 );
}
Esempio n. 5
0
void Tips::paintEvent(QPaintEvent* )
{
#ifndef NO_EZX
	setBackgroundMode( QWidget::NoBackground );
#else
    setBackgroundMode( Qt::NoBackground );
#endif //NO_EZX
	setPalette( QToolTip::palette(), TRUE );
	
    const int shadowWidth = 6;   // also used as '5' and '6' and even '8' below
    const int vMargin = 8;
    const int hMargin = 12;

    if ( currentText.isEmpty() )
	return;

    QRect r;
#ifndef QT_NO_RICHTEXT
    QSimpleRichText* doc = 0;

    if ( QStyleSheet::mightBeRichText( currentText ) ) {
		doc = new QSimpleRichText( currentText, font() );
		doc->adjustSize();
		r.setRect( 0, 0, doc->width(), doc->height() );
    }
    else
#endif
    {
		int sw = QApplication::desktop()->width() / 3;
		if ( sw < 200 )
			sw = 200;
		else if ( sw > 300 )
	    	sw = 300;

		r = fontMetrics().boundingRect( 0, 0, sw, 1000, Qt::AlignLeft + Qt::AlignTop + Qt::WordBreak + Qt::ExpandTabs, currentText );
    }

    int w = r.width() + 2*hMargin;
    int h = r.height() + 2*vMargin;

	// okay, now to find a suitable location

	int x;

	// first try locating the widget immediately above/below,
	// with nice alignment if possible.
	QPoint pos;
	if ( parentWidget() )
		pos = parentWidget()->mapToGlobal( QPoint( 0,0 ) );

	if ( parentWidget() && w > parentWidget()->width() + 16 )
		x = pos.x() + parentWidget()->width()/2 - w/2;
	else
	    x = ppos.x() - w/2;

	// squeeze it in if that would result in part of what's this
	// being only partially visible
	if ( x + w > QApplication::desktop()->width() )
	    x = (parentWidget()? (QMIN(QApplication::desktop()->width(),
			      pos.x() + parentWidget()->width())
			 ) : QApplication::desktop()->width() )
		- w;

	int sx = QApplication::desktop()->x();
	int sy = QApplication::desktop()->y();
	
	if ( x < sx ) x = sx;

	int y;
	if ( parentWidget() && h > parentWidget()->height() + 16 ) {
		y = pos.y() + parentWidget()->height() + 2; // below, two pixels spacing
		// what's this is above or below, wherever there's most space
		if ( y + h + 10 > QApplication::desktop()->height() )
		y = pos.y() + 2 - shadowWidth - h; // above, overlap
	}
	y = ppos.y() + 2;

	// squeeze it in if that would result in part of what's this
	// being only partially visible
	if ( y + h > QApplication::desktop()->height() )
	    y = ( parentWidget() ? (QMIN(QApplication::desktop()->height(),
				 pos.y() + parentWidget()->height())
			    ) : QApplication:: desktop()->height() )
		- h;
	if ( y < sy )
		y = sy;
	
	setGeometry( x, y, w + shadowWidth, h + shadowWidth );
	show();

    // now for super-clever shadow stuff.  super-clever mostly in
    // how many window system problems it skirts around.

    QPainter p( this );
    p.setPen( colorGroup().foreground() );
    p.drawRect( 0, 0, w, h );
    p.setPen( colorGroup().mid() );
    p.setBrush( colorGroup().background() );
    p.drawRect( 1, 1, w-2, h-2 );
    p.setPen( colorGroup().foreground() );

#ifndef QT_NO_RICHTEXT
    if ( doc ) {
	doc->draw( &p, hMargin, vMargin, r, colorGroup(), 0 );
	delete doc;
    }
    else
#endif
    {
	p.drawText( hMargin, vMargin, r.width(), r.height(),
		    Qt::AlignLeft + Qt::AlignTop + Qt::WordBreak + Qt::ExpandTabs,
		    currentText );
    }
    p.setPen( colorGroup().shadow() );

    p.drawPoint( w + 5, 6 );
    p.drawLine( w + 3, 6,
		w + 5, 8 );
    p.drawLine( w + 1, 6,
		w + 5, 10 );
    int i;
    for( i=7; i < h; i += 2 )
	p.drawLine( w, i,
		    w + 5, i + 5 );
    for( i = w - i + h; i > 6; i -= 2 )
	p.drawLine( i, h,
		    i + 5, h + 5 );
    for( ; i > 0 ; i -= 2 )
	p.drawLine( 6, h + 6 - i,
		    i + 5, h + 5 );
}