Example #1
0
void EventDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &idx) const
{
    QPixmap icon;
    QString text = idx.data(Qt::DisplayRole).toString();
    QDateTime time = idx.data(QZeitgeist::LogModel::TimeRole).toDateTime();

    QStyle *style = QApplication::style();

    style->drawPrimitive(QStyle::PE_PanelItemViewItem, &option, painter);

    QRect baseRect = option.rect.adjusted(5, 5, -5, -5);

    QRect iconRect(baseRect);
    QRect descRect(baseRect);

    iconRect.setWidth(iconRect.width()/3);
    descRect.setX(iconRect.right());

    QIcon::Mode mode = QIcon::Normal;
    if (option.state == QStyle::State_Active)
        mode = QIcon::Active;
    if (option.state == QStyle::State_Selected)
        mode = QIcon::Selected;

    painter->save();
    painter->setOpacity(0.4);

    QString url(idx.data(QZeitgeist::LogModel::URLRole).toString());
    QPixmap overlay;
    if (!m_iconCache.contains(url)) {
      icon = idx.data(QZeitgeist::LogModel::ThumbnailRole).value<QPixmap>();
      if (icon.isNull()) {
          KIcon kicon = KIcon(QUrl(idx.data(QZeitgeist::LogModel::ActorRole).toString()).authority().section(".desktop", 0, 0));
          icon = kicon.pixmap(iconRect.size());
      } else {
          icon = icon.scaled(iconRect.size(), Qt::KeepAspectRatio);
          KIcon kicon = KIcon(QUrl(idx.data(QZeitgeist::LogModel::ActorRole).toString()).authority().section(".desktop", 0, 0));
          QPainter overlayPainter(&icon);
          QRect overlayRect(QPoint(0, 0), iconRect.size());
          int iconSize = qMin(overlayRect.width(), overlayRect.height());
          overlayRect.setX(iconSize/2);
          overlayRect.setY(iconSize/2);
          kicon.paint(&overlayPainter, overlayRect, Qt::AlignCenter, QIcon::Active);
      }
      m_iconCache[url] = icon;
    } else {
      icon = m_iconCache[url];
    }

    painter->drawPixmap(iconRect, icon);
    
    //icon.paint(painter, iconRect, Qt::AlignCenter, mode);

    painter->setOpacity(1);
    QFont font;
    font.setBold(true);
    font.setPixelSize(15);
    painter->setFont(font);

    painter->drawText(baseRect, Qt::AlignLeft | Qt::TextWordWrap, text);
    painter->restore();

    painter->drawText(baseRect, Qt::AlignRight | Qt::AlignBottom, time.toString(Qt::SystemLocaleShortDate));
}
Example #2
0
void View::setXPos(int x)
      {
      int delta  = xpos - x;         // -  -> shift left
      xpos  = x;
      
      #ifdef VIEW_USE_DOUBLE_BUFFERING
      if (pm.isNull())
            return;
      if (!pmValid) {
            //printf("View::setXPos !pmValid x:%d width:%d delta:%d\n", x, width(), delta);
            redraw();
            return;
            }
            
      int w = width();
      int h = height();

      QRect r;
      if (delta >= w || delta <= -w)
            r = QRect(0, 0, w, h);
      else if (delta < 0) {   // shift left
            //bitBlt(&pm,  0, 0, &pm,  -delta, 0, w + delta, h, CopyROP, true);
            QPainter p(&pm);
            p.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform | QPainter::HighQualityAntialiasing, false);
            //printf("View::setXPos x:%d w:%d delta:%d r.x:%d r.w:%d\n", 
            //  x, w, delta, r.x(), r.width());                    
            p.drawPixmap(0, 0, pm, -delta, 0, w + delta, h);
            r = QRect(w + delta, 0, -delta, h);
            }
      else {                  // shift right
            //bitBlt(&pm,  delta, 0, &pm,     0, 0, w-delta, h, CopyROP, true);
            QPainter p(&pm);
            p.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform | QPainter::HighQualityAntialiasing, false);
            //printf("View::setXPos x:%d w:%d delta:%d r.x:%d r.w:%d\n", 
            //  x, w, delta, r.x(), r.width());                    
            p.drawPixmap(delta, 0, pm,     0, 0, w-delta, h);
            r = QRect(0, 0, delta, h);
            }
      QRect olr = overlayRect();
      QRect olr1(olr);
      olr1.translate(delta, 0);

      r |= olr;
      r |= olr1;
      
      //printf("View::setXPos x:%d w:%d delta:%d r.x:%d r.w:%d\n", x, w, delta, r.x(), r.width());
      //printf("View::setXPos paint delta:%d r.x:%d r.y:%d r.w:%d r.h:%d\n", delta, r.x(), r.y(), r.width(), r.height());  
      
      paint(r);
      update();
      
      #else
      scroll(delta, 0);
      QRect olr = overlayRect();
      // Is there an overlay?
      if(!olr.isNull())
      {
        // Are we shifting right (moving left)?
        if(delta >= 0)
        {
          // Translate not good - need to set x to delta.
          //olr.translate(delta, 0);
          olr.setX(delta);
          olr.setWidth(olr.x() + olr.width() + delta);
        }
        else
        // We are shifting left (moving right).
        {
          // Translate not good - need to limit x to 0.
          //olr.translate(delta, 0);
          olr.setX(olr.x() + delta);
        }
        
        if(olr.x() < 0)
          olr.setX(0);
        if(olr.right() > width())
          olr.setRight(width());
        
        if(olr.y() < 0)
          olr.setY(0);
        if(olr.bottom() > height())
          olr.setBottom(height());
        
        //printf("scroll X update: x:%d y:%d w:%d h:%d\n", olr.x(), olr.y(), olr.width(), olr.height()); 
        update(olr);
      }  
      #endif
      }
Example #3
0
void View::setYPos(int y)
      {
      int delta  = ypos - y;         // -  -> shift up
      ypos  = y;
      
      #ifdef VIEW_USE_DOUBLE_BUFFERING
      if (pm.isNull())
            return;
      if (!pmValid) {
            //printf("View::setYPos !pmValid y:%d height:%d delta:%d\n", y, height(), delta);
            
            redraw();
            return;
            }
      
      int w = width();
      int h = height();
      
      QRect r;
      if (delta >= h || delta <= -h)
            r = QRect(0, 0, w, h);
      else if (delta < 0) {   // shift up
            //bitBlt(&pm,  0, 0, &pm, 0, -delta, w, h + delta, CopyROP, true);
            QPainter p(&pm);
            p.drawPixmap(0, 0, pm, 0, -delta, w, h + delta);
            r = QRect(0, h + delta, w, -delta);
            }
      else {                  // shift down
            //bitBlt(&pm,  0, delta, &pm, 0, 0, w, h-delta, CopyROP, true);
            QPainter p(&pm);
            p.drawPixmap(0, delta, pm, 0, 0, w, h-delta);
            r = QRect(0, 0, w, delta);
            }
      QRect olr = overlayRect();
      QRect olr1(olr);
      olr1.translate(0, delta);

      r |= olr;
      r |= olr1;

      //printf("View::setYPos paint delta:%d r.x:%d r.y:%d r.w:%d r.h:%d\n", delta, r.x(), r.y(), r.width(), r.height());  
      
      paint(r);
      update();
      
      #else
      scroll(0, delta);
      QRect olr = overlayRect();
      // Is there an overlay?
      if(!olr.isNull())
      {
        // Are we shifting down (moving up)?
        if(delta >= 0)
        {
          // Translate not good - need to set y to delta.
          //olr.translate(0, delta);
          olr.setY(delta);
          olr.setHeight(olr.y() + olr.height() + delta);
        }
        else
        // We are shifting up (moving down).
        {
          // Translate not good - need to limit y to 0.
          //olr.translate(0, delta);
          olr.setY(olr.y() + delta);
        }
        
        if(olr.x() < 0)
          olr.setX(0);
        if(olr.right() > width())
          olr.setRight(width());
        
        if(olr.y() < 0)
          olr.setY(0);
        if(olr.bottom() > height())
          olr.setBottom(height());
        
        //printf("scroll Y update: x:%d y:%d w:%d h:%d\n", olr.x(), olr.y(), olr.width(), olr.height()); 
        update(olr);
      }  
      #endif
      }
void HighlightScrollBarOverlay::paintEvent(QPaintEvent *paintEvent)
{
    QWidget::paintEvent(paintEvent);

    updateCache();

    if (m_highlightCache.isEmpty())
        return;

    QPainter painter(this);
    painter.setRenderHint(QPainter::Antialiasing, false);

    const QRect &gRect = overlayRect();
    const QRect &hRect = handleRect();

    const int marginX = 3;
    const int marginH = -2 * marginX + 1;
    const QRect aboveHandleRect = QRect(gRect.x() + marginX,
                                        gRect.y(),
                                        gRect.width() + marginH,
                                        hRect.y() - gRect.y());
    const QRect handleRect      = QRect(gRect.x() + marginX,
                                        hRect.y(),
                                        gRect.width() + marginH,
                                        hRect.height());
    const QRect belowHandleRect = QRect(gRect.x() + marginX,
                                        hRect.y() + hRect.height(),
                                        gRect.width() + marginH,
                                        gRect.height() - hRect.height() + gRect.y() - hRect.y());

    const int aboveValue = m_scrollBar->value();
    const int belowValue = m_scrollBar->maximum() - m_scrollBar->value();
    const int sizeDocAbove = aboveValue * int(m_highlightController->lineHeight());
    const int sizeDocBelow = belowValue * int(m_highlightController->lineHeight());
    const int sizeDocVisible = int(m_highlightController->visibleRange());

    const int scrollBarBackgroundHeight = aboveHandleRect.height() + belowHandleRect.height();
    const int sizeDocInvisible = sizeDocAbove + sizeDocBelow;
    const double backgroundRatio = sizeDocInvisible
            ? ((double)scrollBarBackgroundHeight / sizeDocInvisible) : 0;


    if (aboveValue) {
        drawHighlights(&painter,
                       0,
                       sizeDocAbove,
                       backgroundRatio,
                       0,
                       aboveHandleRect);
    }

    if (belowValue) {
        // This is the hypothetical handle height if the handle would
        // be stretched using the background ratio.
        const double handleVirtualHeight = sizeDocVisible * backgroundRatio;
        // Skip the doc above and visible part.
        const int offset = qRound(aboveHandleRect.height() + handleVirtualHeight);

        drawHighlights(&painter,
                       sizeDocAbove + sizeDocVisible,
                       sizeDocBelow,
                       backgroundRatio,
                       offset,
                       belowHandleRect);
    }

    const double handleRatio = sizeDocVisible
            ? ((double)handleRect.height() / sizeDocVisible) : 0;

    // This is the hypothetical handle position if the background would
    // be stretched using the handle ratio.
    const double aboveVirtualHeight = sizeDocAbove * handleRatio;

    // This is the accurate handle position (double)
    const double accurateHandlePos = sizeDocAbove * backgroundRatio;
    // The correction between handle position (int) and accurate position (double)
    const double correction = aboveHandleRect.height() - accurateHandlePos;
    // Skip the doc above and apply correction
    const int offset = qRound(aboveVirtualHeight + correction);

    drawHighlights(&painter,
                   sizeDocAbove,
                   sizeDocVisible,
                   handleRatio,
                   offset,
                   handleRect);
}