예제 #1
0
void  MultiDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index)  const
{
    QVariant  value = index.model()->data( index, Qt::EditRole);
    //qDebug() << "Paint dataType=" << value.typeName();
    switch (value.type()) {
    case QMetaType::QImage:
        {
            QImage  img = value.value<QImage>();
            return paintPixmap( painter, option, QPixmap::fromImage(img));
        }
        case QMetaType::QPixmap:
        {
            QPixmap  pixmap = value.value<QPixmap>();
            return paintPixmap( painter, option, pixmap);
        }
        case QMetaType::QIcon:
        {
            //qDebug() << "Paint Icon:";
            QIcon  icon = value.value<QIcon>();
            QPixmap  pixmap = icon.pixmap( option.rect.size(), QIcon::Mode(0));
            return paintPixmap( painter, option, pixmap);
        }
    default:
        return QItemDelegate::paint( painter, option, index);
    }
}
예제 #2
0
void WaSlider::paintEvent(QPaintEvent *)
{
    // POSBAR.BMP does not have full height in all Winamp skins
    // Paint background before painting slider to be on the safe side
    if(sliderBarId == _WA_SKIN_POS_BAR)
        paintPixmap(-1);

    paintPixmap(sliderBarId, value());

    if (slider_visible) 
        paintPixmap(lDragging ? up_pixmap : down_pixmap, slider_x, slider_y);
}
예제 #3
0
//! [3]
void TabletCanvas::tabletEvent(QTabletEvent *event)
{
  qDebug()<< event;
    switch (event->type()) {
        case QEvent::TabletPress:
            if (!deviceDown) {
                deviceDown = true;
                polyLine[0] = polyLine[1] = polyLine[2] = event->pos();
            }
            break;
        case QEvent::TabletRelease:
            if (deviceDown)
                deviceDown = false;
            break;
        case QEvent::TabletMove:
            polyLine[2] = polyLine[1];
            polyLine[1] = polyLine[0];
            polyLine[0] = event->pos();

            if (deviceDown) {
                updateBrush(event);
                QPainter painter(&pixmap);
                painter.setRenderHint(QPainter::Antialiasing);
                painter.setRenderHint(QPainter::SmoothPixmapTransform);
                paintPixmap(painter, event);
            }
            break;
        default:
            break;
    }
    update();
}
//! [3]
void TabletCanvas::tabletEvent(QTabletEvent *event)
{

    switch (event->type()) {
        case QEvent::TabletPress:
            if (!deviceDown) {
                deviceDown = true;
                polyLine[0] = polyLine[1] = polyLine[2] = event->pos();
            }
            break;
        case QEvent::TabletRelease:
            if (deviceDown)
                deviceDown = false;
            break;
        case QEvent::TabletMove:
            polyLine[2] = polyLine[1];
            polyLine[1] = polyLine[0];
            polyLine[0] = event->pos();

            if (deviceDown) {
                updateBrush(event);
                QPainter painter(&pixmap);
                paintPixmap(painter, event);
            }
            break;
        default:
            break;
    }
    update();
}
예제 #5
0
void KFileIVIDesktop::paintItem( TQPainter *p, const TQColorGroup &cg)
{
  TQColorGroup colors = updateColors(cg);

  TQIconView* view = iconView();
  Q_ASSERT( view );

  if ( !view )
    return;

  if ( !wordWrap() )
    return;

  p->save();

  // draw the pixmap as in TDEIconViewItem::paintItem(...)
  paintPixmap(p, colors);

  //
  // Paint the text as shadowed if the shadow is available
  //
  if (m_shadow != 0L && (static_cast<KDesktopShadowSettings *> (m_shadow->shadowSettings()))->isEnabled())
    drawShadowedText(p, colors);
  else {
    paintFontUpdate(p);
    paintText(p, colors);
  }

  p->restore();

  paintOverlay(p);
  paintOverlayProgressBar(p);
}
예제 #6
0
  /**
   * Constructor for visual display.
   *
   * @param parent
   */
  VisualDisplay::VisualDisplay(QWidget *parent) : QWidget(parent),
    p_boxSamps(3),
    p_boxLines(3),
    p_boxWidth(20),
    p_boxHeight(20),
    p_oldWidth(20),
    p_oldHeight(20),
    p_ulSamp(-1),
    p_ulLine(-1),
    p_set(false),
    p_showText(true),
    p_showPixels(false),
    p_showDeviation(false) {

    p_stretch.SetNull(0.0);
    p_stretch.SetLis(0.0);
    p_stretch.SetLrs(0.0);
    p_stretch.SetHis(255.0);
    p_stretch.SetHrs(255.0);
    p_stretch.SetMinimum(0.0);
    p_stretch.SetMaximum(255.0);
    p_pixelData = QVector<QVector<double> >(p_boxLines, QVector<double>(p_boxSamps, Null));
    paintPixmap();
    setMouseTracking(true);
    setBackgroundRole(QPalette::Dark);
    setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
  }
void UIGDetailsElement::paintElementInfo(QPainter *pPainter, const QStyleOptionGraphicsItem*)
{
    /* Initialize some necessary variables: */
    int iMargin = data(ElementData_Margin).toInt();
    int iSpacing = data(ElementData_Spacing).toInt();

    /* Calculate attributes: */
    int iPixmapHeight = m_pixmapSize.height();
    int iNameHeight = m_nameSize.height();
    int iMaximumHeight = qMax(iPixmapHeight, iNameHeight);

    /* Prepare color: */
    QPalette pal = palette();
    QColor buttonTextColor = pal.color(QPalette::Active, QPalette::ButtonText);
    QColor linkTextColor = pal.color(QPalette::Active, QPalette::Link);

    /* Paint pixmap: */
    int iElementPixmapX = 2 * iMargin;
    int iElementPixmapY = iPixmapHeight == iMaximumHeight ?
                          iMargin : iMargin + (iMaximumHeight - iPixmapHeight) / 2;
    paintPixmap(/* Painter: */
                pPainter,
                /* Rectangle to paint in: */
                QRect(QPoint(iElementPixmapX, iElementPixmapY), m_pixmapSize),
                /* Pixmap to paint: */
                m_pixmap);

    /* Paint name: */
    int iMachineNameX = iElementPixmapX +
                        m_pixmapSize.width() +
                        iSpacing;
    int iMachineNameY = iNameHeight == iMaximumHeight ?
                        iMargin : iMargin + (iMaximumHeight - iNameHeight) / 2;
    paintText(/* Painter: */
              pPainter,
              /* Rectangle to paint in: */
              QPoint(iMachineNameX, iMachineNameY),
              /* Font to paint text: */
              m_nameFont,
              /* Paint device: */
              model()->paintDevice(),
              /* Text to paint: */
              m_strName,
              /* Name hovered? */
              m_fNameHovered ? linkTextColor : buttonTextColor);
}
예제 #8
0
  /**
   * Update the size of the box
   *
   */
  void VisualDisplay::updateSize() {
    if(p_boxSamps > this->sizeHint().width() / p_boxWidth) {
      resize(this->sizeHint().width() + (p_boxWidth * (p_boxSamps - this->sizeHint().width() / p_boxWidth)), this->size().height());
    }
    else {
      resize(this->sizeHint().width(), this->size().height());
    }

    if(p_boxLines > this->sizeHint().height() / p_boxHeight) {
      resize(this->size().width(), this->sizeHint().height() + (p_boxHeight * (p_boxLines - this->sizeHint().height() / p_boxHeight)));
    }
    else {
      resize(this->size().width(), this->sizeHint().height());
    }

    paintPixmap();
    update();
  }
예제 #9
0
  /**
   * Set pixel data and upper left sample/line
   *
   * @param data
   * @param samp
   * @param line
   */
  void VisualDisplay::setPixelData(QVector<QVector<double> > data, int samp, int line) {
    p_pixelData = data;
    p_ulSamp = samp;
    p_ulLine = line;

    p_stats.Reset();

    for(int i = 0; i < data.size(); i++) {
      for(int j = 0; j < data[i].size(); j++) {
        if(p_ulSamp + j < 0 || p_ulLine + i < 0) continue;
        p_stats.AddData(data[i][j]);
      }
    }

    if(fabs(p_stats.BestMinimum()) < DBL_MAX && fabs(p_stats.BestMaximum()) < DBL_MAX) {
      Histogram hist(p_stats.BestMinimum(), p_stats.BestMaximum());
      for(int i = 0; i < data.size(); i++) {
        hist.AddData(data[i].data(), data[i].size());
      }

      p_stretch.ClearPairs();
      if(hist.Percent(0.5) != hist.Percent(99.5)) {
        p_stretch.AddPair(hist.Percent(0.5), 0.0);
        p_stretch.AddPair(hist.Percent(99.5), 255.0);
      }
      else {
        p_stretch.AddPair(-DBL_MAX, 0.0);
        p_stretch.AddPair(DBL_MAX, 255.0);
      }
    }
    else {
      p_stretch.ClearPairs();
      p_stretch.AddPair(-DBL_MAX, 0.0);
      p_stretch.AddPair(DBL_MAX, 255.0);
    }

    p_set = true;
    paintPixmap();
  }
void UIGSelectorItemMachine::paint(QPainter *pPainter, const QStyleOptionGraphicsItem *pOption, QWidget * /* pWidget = 0 */)
{
    /* Initialize some necessary variables: */
    QRect fullRect = pOption->rect;
    int iMachineItemMargin = data(MachineItemData_MachineItemMargin).toInt();
    int iMachineItemMajorSpacing = data(MachineItemData_MachineItemMajorSpacing).toInt();
    int iMachineItemMinorSpacing = data(MachineItemData_MachineItemMinorSpacing).toInt();
    int iMachineItemTextSpacing = data(MachineItemData_MachineItemTextSpacing).toInt();
    QSize machinePixmapSize = data(MachineItemData_MachinePixmapSize).toSize();
    QSize machineNameSize = data(MachineItemData_MachineNameSize).toSize();
    QString strSnapshotName = data(MachineItemData_SnapshotName).toString();
    QSize snapshotNameSize = data(MachineItemData_SnapshotNameSize).toSize();
    QSize machineStatePixmapSize = data(MachineItemData_MachineStatePixmapSize).toSize();
    QSize machineStateTextSize = data(MachineItemData_MachineStateTextSize).toSize();

    /* Paint background: */
    paintBackground(/* Painter: */
                    pPainter,
                    /* Rectangle to paint in: */
                    fullRect,
                    /* Has parent? */
                    parentItem(),
                    /* Is item selected? */
                    model()->selectionList().contains(this),
                    /* Gradient darkness for animation: */
                    gradient(),
                    /* Show drag where? */
                    dragTokenPlace());

    /* Paint pixmap: */
    paintPixmap(/* Painter: */
                pPainter,
                /* Rectangle to paint in: */
                QRect(fullRect.topLeft() +
                      QPoint(iMachineItemMargin, iMachineItemMargin),
                      machinePixmapSize),
                /* Pixmap to paint: */
                data(MachineItemData_MachinePixmap).value<QIcon>().pixmap(machinePixmapSize));

    /* Paint name: */
    paintText(/* Painter: */
              pPainter,
              /* Rectangle to paint in: */
              QRect(fullRect.topLeft() +
                    QPoint(iMachineItemMargin, iMachineItemMargin) +
                    QPoint(machinePixmapSize.width() + iMachineItemMajorSpacing, 0),
                    machineNameSize),
              /* Font to paint text: */
              data(MachineItemData_MachineNameFont).value<QFont>(),
              /* Text to paint: */
              data(MachineItemData_MachineName).toString());

    /* Paint snapshot name (if necessary): */
    if (!strSnapshotName.isEmpty())
        paintText(/* Painter: */
                  pPainter,
                  /* Rectangle to paint in: */
                  QRect(fullRect.topLeft() +
                        QPoint(iMachineItemMargin, iMachineItemMargin) +
                        QPoint(machinePixmapSize.width() + iMachineItemMajorSpacing, 0) +
                        QPoint(machineNameSize.width() + iMachineItemMinorSpacing, 0),
                        snapshotNameSize),
                  /* Font to paint text: */
                  data(MachineItemData_SnapshotNameFont).value<QFont>(),
                  /* Text to paint: */
                  QString("(%1)").arg(strSnapshotName));

    /* Paint state pixmap: */
    paintPixmap(/* Painter: */
                pPainter,
                /* Rectangle to paint in: */
                QRect(fullRect.topLeft() +
                      QPoint(iMachineItemMargin, iMachineItemMargin) +
                      QPoint(machinePixmapSize.width() + iMachineItemMajorSpacing, 0) +
                      QPoint(0, machineNameSize.height() + iMachineItemTextSpacing),
                      machineStatePixmapSize),
                /* Pixmap to paint: */
                data(MachineItemData_MachineStatePixmap).value<QIcon>().pixmap(machineStatePixmapSize));

    /* Paint state text: */
    paintText(/* Painter: */
              pPainter,
              /* Rectangle to paint in: */
              QRect(fullRect.topLeft() +
                    QPoint(iMachineItemMargin, iMachineItemMargin) +
                    QPoint(machinePixmapSize.width() + iMachineItemMajorSpacing, 0) +
                    QPoint(0, machineNameSize.height() + iMachineItemTextSpacing) +
                    QPoint(machineStatePixmapSize.width() + iMachineItemMinorSpacing, 0),
                    machineStateTextSize),
              /* Font to paint text: */
              data(MachineItemData_MachineStateTextFont).value<QFont>(),
              /* Text to paint: */
              data(MachineItemData_MachineStateText).toString());

    /* Paint focus (if necessary): */
    if (model()->focusItem() == this)
        paintFocus(/* Painter: */
                   pPainter,
                   /* Rectangle to paint in: */
                   fullRect);
}
void UIGChooserItemMachine::paintMachineInfo(QPainter *pPainter, const QStyleOptionGraphicsItem *pOption)
{
    /* Prepare variables: */
    QRect fullRect = pOption->rect;
    int iFullHeight = fullRect.height();
    int iMargin = data(MachineItemData_Margin).toInt();
    int iMachineItemMajorSpacing = data(MachineItemData_MajorSpacing).toInt();
    int iMachineItemMinorSpacing = data(MachineItemData_MinorSpacing).toInt();
    int iMachineItemTextSpacing = data(MachineItemData_TextSpacing).toInt();
    QSize machinePixmapSize = data(MachineItemData_PixmapSize).toSize();
    QSize machineNameSize = data(MachineItemData_NameSize).toSize();
    QSize snapshotNameSize = data(MachineItemData_SnapshotNameSize).toSize();
    QSize machineStatePixmapSize = data(MachineItemData_StatePixmapSize).toSize();
    QSize machineStateTextSize = data(MachineItemData_StateTextSize).toSize();

    /* Update palette: */
    if (model()->selectionList().contains(this))
    {
        QPalette pal = palette();
        pPainter->setPen(pal.color(QPalette::HighlightedText));
    }

    /* Calculate indents: */
    int iLeftColumnIndent = iMargin;

    /* Paint left column: */
    {
        /* Prepare variables: */
        int iMachinePixmapX = iLeftColumnIndent;
        int iMachinePixmapY = (iFullHeight - machinePixmapSize.height()) / 2;
        /* Paint pixmap: */
        paintPixmap(/* Painter: */
                    pPainter,
                    /* Rectangle to paint in: */
                    QRect(QPoint(iMachinePixmapX, iMachinePixmapY), machinePixmapSize),
                    /* Pixmap to paint: */
                    data(MachineItemData_Pixmap).value<QIcon>().pixmap(machinePixmapSize));
    }

    /* Calculate indents: */
    int iRightColumnIndent = iLeftColumnIndent +
                             machinePixmapSize.width() +
                             iMachineItemMajorSpacing;

    /* Paint right column: */
    {
        /* Calculate indents: */
        int iTopLineHeight = qMax(machineNameSize.height(), snapshotNameSize.height());
        int iBottomLineHeight = qMax(machineStatePixmapSize.height(), machineStateTextSize.height());
        int iRightColumnHeight = iTopLineHeight + iMachineItemTextSpacing + iBottomLineHeight;
        int iTopLineIndent = (iFullHeight - iRightColumnHeight) / 2;

        /* Paint top line: */
        {
            /* Paint left element: */
            {
                /* Prepare variables: */
                int iNameX = iRightColumnIndent;
                int iNameY = iTopLineIndent;
                /* Paint name: */
                paintText(/* Painter: */
                          pPainter,
                          /* Point to paint in: */
                          QPoint(iNameX, iNameY),
                          /* Font to paint text: */
                          data(MachineItemData_NameFont).value<QFont>(),
                          /* Paint device: */
                          model()->paintDevice(),
                          /* Text to paint: */
                          data(MachineItemData_Name).toString());
            }

            /* Calculate indents: */
            int iSnapshotNameIndent = iRightColumnIndent +
                                      machineNameSize.width() +
                                      iMachineItemMinorSpacing;

            /* Paint right element: */
            if (!snapshotName().isEmpty())
            {
                /* Prepare variables: */
                int iSnapshotNameX = iSnapshotNameIndent;
                int iSnapshotNameY = iTopLineIndent;
                /* Paint snapshot name: */
                paintText(/* Painter: */
                          pPainter,
                          /* Point to paint in: */
                          QPoint(iSnapshotNameX, iSnapshotNameY),
                          /* Font to paint text: */
                          data(MachineItemData_SnapshotNameFont).value<QFont>(),
                          /* Paint device: */
                          model()->paintDevice(),
                          /* Text to paint: */
                          data(MachineItemData_SnapshotName).toString());
            }
        }

        /* Calculate indents: */
        int iBottomLineIndent = iTopLineIndent + iTopLineHeight;

        /* Paint bottom line: */
        {
            /* Paint left element: */
            {
                /* Prepare variables: */
                int iMachineStatePixmapX = iRightColumnIndent;
                int iMachineStatePixmapY = iBottomLineIndent;
                /* Paint state pixmap: */
                paintPixmap(/* Painter: */
                            pPainter,
                            /* Rectangle to paint in: */
                            QRect(QPoint(iMachineStatePixmapX, iMachineStatePixmapY), machineStatePixmapSize),
                            /* Pixmap to paint: */
                            data(MachineItemData_StatePixmap).value<QIcon>().pixmap(machineStatePixmapSize));
            }

            /* Calculate indents: */
            int iMachineStateTextIndent = iRightColumnIndent +
                                          machineStatePixmapSize.width() +
                                          iMachineItemMinorSpacing;

            /* Paint right element: */
            {
                /* Prepare variables: */
                int iMachineStateTextX = iMachineStateTextIndent;
                int iMachineStateTextY = iBottomLineIndent;
                /* Paint state text: */
                paintText(/* Painter: */
                          pPainter,
                          /* Point to paint in: */
                          QPoint(iMachineStateTextX, iMachineStateTextY),
                          /* Font to paint text: */
                          data(MachineItemData_StateTextFont).value<QFont>(),
                          /* Paint device: */
                          model()->paintDevice(),
                          /* Text to paint: */
                          data(MachineItemData_StateText).toString());
            }
        }
    }

    /* Tool-bar: */
    if (m_pToolBar)
    {
        /* Show/hide tool-bar: */
        if (isHovered())
        {
            if (!m_pToolBar->isVisible())
                m_pToolBar->show();
        }
        else
        {
            if (m_pToolBar->isVisible())
                m_pToolBar->hide();
        }
    }
}