Ejemplo n.º 1
0
void SysTrayIcon::updateUnreadCount( int changeOfUnreadPosts )
{
    kDebug();
    unread += changeOfUnreadPosts;

    if ( unread <= 0 ) {
        setIconByName(currentIconName());
        unread = 0;
    } else {
        // adapted from KMSystemTray::updateCount()
        int oldWidth = 22;

        QString countStr = QString::number( unread );
        QFont f = KGlobalSettings::generalFont();
        f.setBold( true );

        float pointSize = f.pointSizeF();
        QFontMetrics fm( f );
        int w = fm.width( countStr );
        if ( w > ( oldWidth - 2 ) ) {
            pointSize *= float( oldWidth - 2 ) / float( w );
            f.setPointSizeF( pointSize );
        }

        // overlay
        QPixmap overlayImg = KIcon(currentIconName()).pixmap(22,22);
        QPainter p( &overlayImg );
        p.setFont( f );
        KColorScheme scheme( QPalette::Active, KColorScheme::View );

        fm = QFontMetrics( f );
        QRect boundingRect = fm.tightBoundingRect( countStr );
        boundingRect.adjust( 0, 0, 0, 2 );
        boundingRect.setHeight( qMin( boundingRect.height(), oldWidth ) );
        boundingRect.moveTo(( oldWidth - boundingRect.width() ) / 2,
                            (( oldWidth - boundingRect.height() ) / 2 ) - 1 );
        p.setOpacity( 0.7 );
        QBrush br(QColor(255, 255, 255), Qt::SolidPattern);
        p.setBrush( br );
        p.setPen( QColor(255, 255, 255) );
        p.drawRoundedRect( boundingRect, 2.0, 2.0 );

        p.setBrush( Qt::NoBrush );
        p.setPen( QColor( 0, 0, 0 ) );
        p.setOpacity( 1.0 );
        p.drawText( overlayImg.rect(), Qt::AlignCenter, countStr );
        setIconByPixmap( overlayImg );
    }
    this->setToolTip( "choqok", i18n("Choqok"), i18np( "1 unread post", "%1 unread posts", unread ) );
}
Ejemplo n.º 2
0
SysTrayIcon::SysTrayIcon( Choqok::UI::MainWindow* parent )
: KStatusNotifierItem( parent ), _mainwin(parent), isOffline(false)
{
    kDebug();
    unread = 0;
    setAssociatedWidget(parent);
    setCategory(ApplicationStatus);
    setStandardActionsEnabled(false);
    setStatus(Active);
    setIconByName( currentIconName() );
}
Ejemplo n.º 3
0
QString StatusNotifierItem::iconName() const
{
    return currentIconName();
}