示例#1
0
void View::Invoicing::OperationDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    if(index.column() == ColumnOperationId) {
        int id = index.model() -> data(index, Qt::DisplayRole).toInt();
        QString text = QString::number(id).rightJustified(4, '0');
        QStyleOptionViewItem myOption = option;

        myOption.displayAlignment = Qt::AlignHCenter | Qt::AlignVCenter;

        drawDisplay(painter, myOption, myOption.rect, text);
        drawFocus(painter, myOption, myOption.rect);
    } else if(index.column() == ColumnOperationDiscount) {
        double discountValue = index.model() -> data(index, Qt::DisplayRole).toDouble();
        QString text;
        QStyleOptionViewItem myOption = option;

        if(discountValue == 0)
            text = QString("-");
        else if(discountValue < 100)
            text = QString::number(discountValue, 'f', 2);
        else
            text = QObject::tr("Free");

        myOption.displayAlignment = Qt::AlignHCenter | Qt::AlignVCenter;

        drawDisplay(painter, myOption, myOption.rect, text);
        drawFocus(painter, myOption, myOption.rect);
    } else
        QItemDelegate::paint(painter, option, index);
}
// paint the cells for date and time - pass through for all the
// other cells. Uses the model data to display.
void RideDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
                         const QModelIndex &index) const
{
    if (index.column() == dateColumn) {

        QString value = index.model()->data(index, Qt::DisplayRole).toString();
        // display with angles to show its doing something
        QString text = QString("%1").arg(value);

        QStyleOptionViewItem myOption = option;
        myOption.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
        drawDisplay(painter, myOption, myOption.rect, text);
        drawFocus(painter, myOption, myOption.rect);

    } else if (index.column() == dateColumn+1) {

        QString value = index.model()->data(index, Qt::DisplayRole).toString();
        // display with angles to show its doing something
        QString text = QString("%1").arg(value);

        QStyleOptionViewItem myOption = option;
        myOption.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
        drawDisplay(painter, myOption, myOption.rect, text);
        drawFocus(painter, myOption, myOption.rect);

    } else {

        QItemDelegate::paint(painter, option, index);

    }
}
示例#3
0
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void UKvyt_Delegate::paint(QPainter *painter,
                          const QStyleOptionViewItem &option,
                          const QModelIndex &index) const
{
    if ( index.column() == durationColumn_2 ){
        double number = index.model()->data(index, Qt::DisplayRole).toDouble();
        QString text = uMToStr2(number);
        QStyleOptionViewItem myOption = option;
        myOption.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
        drawDisplay(painter, myOption, myOption.rect, text);
        drawFocus(painter, myOption, myOption.rect);
    } 
	else if ( (index.column() == durationColumn_3) || (index.column() == durationColumn_4) ){
		QDate date( index.model()->data(index, Qt::DisplayRole).toDate() );
        QString text = QString("%1.%2.%3")
                       .arg(QVariant(date.day()).toString())
                       .arg(QVariant(date.month()).toString(), 2, QChar('0'))
					   .arg(QVariant(date.year()).toString(), 4, QChar('-'));
        QStyleOptionViewItem myOption = option;
        myOption.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
        drawDisplay(painter, myOption, myOption.rect, text);
        drawFocus(painter, myOption, myOption.rect);
	}
	else{
        QItemDelegate::paint(painter, option, index);
    }
}
示例#4
0
void MovieDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,const QModelIndex &index) const
{
    if (index.column() == 6)
    {
        QString text = statusValueList().at(index.data().toInt());

        QStyleOptionViewItem optionViewItem = option;
        optionViewItem.displayAlignment = Qt::AlignLeft | Qt::AlignVCenter;

        drawDisplay(painter, optionViewItem, optionViewItem.rect, text);
        drawFocus(painter, optionViewItem, optionViewItem.rect);
    }
    else if (index.column() == 7)
    {
        QString text = rentValueList().at(index.data().toInt());

        QStyleOptionViewItem optionViewItem = option;
        optionViewItem.displayAlignment = Qt::AlignLeft | Qt::AlignVCenter;

        drawDisplay(painter, optionViewItem, optionViewItem.rect, text);
        drawFocus(painter, optionViewItem, optionViewItem.rect);
    }
    else
    {
        QSqlRelationalDelegate::paint(painter, option, index);
    }
}
示例#5
0
void PlaneTableDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
	QString strong;
	QStyleOptionViewItem myOption = option;
    int NUFOs  = Objects3D::s_oaPlane.size();

	if(index.row()> NUFOs)
	{
		strong=" ";
		drawDisplay(painter, myOption, myOption.rect, strong);
		drawFocus(painter, myOption, myOption.rect);
	}
	else if(index.column()==0)
	{
		myOption.displayAlignment = Qt::AlignLeft | Qt::AlignVCenter;
		strong = index.model()->data(index, Qt::DisplayRole).toString();
		drawDisplay(painter, myOption, myOption.rect, strong);
		drawFocus(painter, myOption, myOption.rect);
	}
	else
	{
		myOption.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
		strong = QString("%1").arg(index.model()->data(index, Qt::DisplayRole).toDouble(), 0,'f',m_Precision[index.column()]);
		drawDisplay(painter, myOption, myOption.rect, strong);
		drawFocus(painter, myOption, myOption.rect);
	}
}
void CoefDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    if( index.column() == column )
    {
        QString text = index.model()->data(index, Qt::DisplayRole ).toString();

        bool ok = false;
        double d = text.toDouble(&ok);
        if( ok )
        {
            if( d == 1 || d == 0 )
                text = "";
            else
            {
                text = QString::number( d, 'f', 4 );
                text = convertSumForDouble( text );
            }
        }

        QStyleOptionViewItem myOption = option;
        myOption.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;

        drawDisplay(painter, myOption, myOption.rect, text );
        drawFocus(painter, myOption, myOption.rect);
    }
    else
        QItemDelegate::paint(painter, option, index );
}
void ContactDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    QList<QVariant> modelData = index.model()->data(index, Qt::DisplayRole).toList();

    //QList<Contact> contacts;

    foreach(QVariant var, modelData) {
        Contact c("", "", "");
        QStringList contactData = var.toString().split("/");
        if (contactData.size() > 10) {
            c.setFirstName(contactData.at(0));
            c.setLastName(contactData.at(1));
            c.setEmail(contactData.at(2));
            c.setBirthday(QDate(contactData.at(3).toInt(), contactData.at(4).toInt(), contactData.at(5).toInt()));
            c.setPosition(contactData.at(6).toInt(), contactData.at(7).toInt(), contactData.at(8).toInt());
            int phoneNumberListSize = contactData.at(9).toInt();
            if (contactData.size() > phoneNumberListSize + 9)
            for (int i = 0; i < phoneNumberListSize; ++i) {
                c.addPhoneNumber(contactData.at(10 + i));
            }
        }

        //painter->fillRect(c.getPosition().x * 50, c.getPosition().y * 50, 150, 50, Qt::darkGray);
        //painter->drawText(c.getPosition().x * 50, c.getPosition().y * 50 + 30, c.getFirstName() + " " + c.getLastName());
        QStyleOptionViewItem myOption = option;
        myOption.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
        drawDisplay(painter, myOption, myOption.rect, c.getFirstName() + " " + c.getLastName());
        drawFocus(painter, myOption, myOption.rect);
    }
示例#8
0
void BookDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
                           const QModelIndex &index) const
{
    if (index.column() != 5) {
        QStyleOptionViewItemV3 opt = option;
        opt.rect.adjust(0, 0, -1, -1); // since we draw the grid ourselves
        QSqlRelationalDelegate::paint(painter, opt, index);
    } else {
        const QAbstractItemModel *model = index.model();
        QPalette::ColorGroup cg = (option.state & QStyle::State_Enabled) ?
            (option.state & QStyle::State_Active) ? QPalette::Normal : QPalette::Inactive : QPalette::Disabled;

        if (option.state & QStyle::State_Selected)
            painter->fillRect(option.rect, option.palette.color(cg, QPalette::Highlight));

        int rating = model->data(index, Qt::DisplayRole).toInt();
        int width = star.width();
        int height = star.height();
        int x = option.rect.x();
        int y = option.rect.y() + (option.rect.height() / 2) - (height / 2);
        for (int i = 0; i < rating; ++i) {
            painter->drawPixmap(x, y, star);
            x += width;
        }
        drawFocus(painter, option, option.rect.adjusted(0, 0, -1, -1)); // since we draw the grid ourselves
    }

    QPen pen = painter->pen();
    painter->setPen(option.palette.color(QPalette::Mid));
    painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight());
    painter->drawLine(option.rect.topRight(), option.rect.bottomRight());
    painter->setPen(pen);
}
示例#9
0
static void drawUnselected( HDC hdc, int x, int y )
{
    RECT        rect;
    HBRUSH      hColourBrush;
    COLORREF    nearest;

    rect.left = 0;
    rect.top = 0;
    rect.right = WIDTH * NUM_ACROSS;
    rect.bottom = HEIGHT * NUM_DOWN;
    MapDialogRect( hColorbar, &rect );

    Width = (rect.right - rect.left) / NUM_ACROSS;
    Height = (rect.bottom - rect.top) / NUM_DOWN;


    rect.left = x * Width + SPC;
    rect.top = y * Height + SPC;
    rect.right = (x + 1) * Width - SPC;
    rect.bottom = (y + 1) * Height - SPC;
    // MapDialogRect( hColorbar, &rect );

    nearest = GetNearestColor( hdc, RGBValues[y * NUM_ACROSS + x] );
    hColourBrush = CreateSolidBrush( nearest );
    FillRect( hdc, &rect, hColourBrush );
    drawFocus( hdc, &rect, false );

    DeleteObject( hColourBrush );
}
示例#10
0
void KWQTableDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const
{
  painter->save();
  drawBackground(painter, option, index);

  QStyleOptionViewItem opt = option;
  opt.decorationSize = QSize(0, 0);
  QPixmap decorationPixmap;
  QVariant decorationVariant = index.data(Qt::DecorationRole);
  if (!decorationVariant.isNull()) {
    decorationPixmap = decoration(option, decorationVariant);
    opt.decorationPosition = QStyleOptionViewItem::Right;
    opt.decorationAlignment = Qt::AlignRight | Qt::AlignVCenter;
    opt.decorationSize = QSize(decorationPixmap.width(), decorationPixmap.height());
    drawDecoration(painter, opt, opt.rect, decorationPixmap);
  }

  opt.rect.adjust(0, 0, -opt.decorationSize.width(), 0);
  const KWQTableModel *model = static_cast<const KWQTableModel *>(index.model());

  if (!model->checkBlanksSyntax(index.data(Qt::DisplayRole).toString())) {
    QPalette::ColorGroup cg = QPalette::Normal;
    opt.palette.setColor(cg, QPalette::Text, Qt::red);
  }
  opt.font = index.data(Qt::FontRole).value<QFont>();
  drawDisplay(painter, opt, opt.rect, index.data(Qt::DisplayRole).toString());
  if (!index.data(KWQTableModel::SoundRole).isNull())
    painter->fillRect(option.rect.right() - 3, option.rect.top(), 4, 4, Qt::red);
  drawFocus(painter, opt, option.rect);

  painter->restore();
}
void DBFRedactorDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
	QStyleOptionViewItem m_option(option);

	if (index.data(Qt::UserRole).toBool()) {
		m_option.palette.setBrush(QPalette::Background, m_settings.value("Removed_Color", Qt::darkGray).value<QColor>());
		painter->fillRect(option.rect, m_option.palette.background());
	}

	if (option.state & QStyle::State_Selected)
		painter->fillRect(option.rect, option.palette.highlight());

	QString text;
	switch (m_redactor->field(index.column()).type) {
		case DBFRedactor::TYPE_LOGICAL: {
			QStyleOptionViewItem opt(option);
			opt.rect = checkRect(option, option.rect);
			opt.state = opt.state & ~QStyle::State_HasFocus;
			opt.state |= (index.data(Qt::CheckStateRole).toInt() == Qt::Checked ? QStyle::State_On : QStyle::State_Off);
			qApp->style()->drawPrimitive(QStyle::PE_IndicatorViewItemCheck, &opt, painter);
			return;
			break;
		}
		case DBFRedactor::TYPE_DATE:
			m_option.displayAlignment |= static_cast<Qt::AlignmentFlag> (m_settings.value("Date_Alignment", Qt::AlignHCenter).toInt());
			m_option.palette.setColor(QPalette::Text, m_settings.value("Date_Color", Qt::darkYellow).value<QColor>());
			m_option.font = m_settings.value("Date_Font", option.font).value<QFont> ();
			text = index.data(Qt::DisplayRole).toDate().toString(Qt::SystemLocaleShortDate);
			break;
		case DBFRedactor::TYPE_FLOAT:
			m_option.displayAlignment |= static_cast<Qt::AlignmentFlag> (m_settings.value("Float_Alignment", Qt::AlignRight).toInt());
			m_option.palette.setColor(QPalette::Text, m_settings.value("Float_Color", Qt::darkBlue).value<QColor>());
			m_option.font = m_settings.value("Float_Font", option.font).value<QFont> ();
			text = index.data(Qt::DisplayRole).toString();
			break;
		case DBFRedactor::TYPE_NUMERIC:
			m_option.displayAlignment |= static_cast<Qt::AlignmentFlag> (m_settings.value("Numeric_Alignment", Qt::AlignRight).toInt());
			m_option.palette.setColor(QPalette::Text, m_settings.value("Numeric_Color", Qt::darkBlue).value<QColor>());
			m_option.font = m_settings.value("Numeric_Font", option.font).value<QFont> ();
			text = index.data(Qt::DisplayRole).toString();
			break;
		case DBFRedactor::TYPE_CHAR:
			m_option.displayAlignment |= static_cast<Qt::AlignmentFlag> (m_settings.value("String_Alignment", Qt::AlignLeft).toInt());
			m_option.palette.setColor(QPalette::Text, m_settings.value("String_Color", option.palette.color(QPalette::Text)).value<QColor>());
			m_option.font = m_settings.value("String_Font", option.font).value<QFont> ();
			text = index.data(Qt::DisplayRole).toString();
			break;
		case DBFRedactor::TYPE_MEMO:
			m_option.displayAlignment |= static_cast<Qt::AlignmentFlag> (m_settings.value("Memo_Alignment", Qt::AlignLeft).toInt());
			m_option.palette.setColor(QPalette::Text, m_settings.value("Memo_Color", option.palette.color(QPalette::Text)).value<QColor>());
			m_option.font = m_settings.value("Memo_Font", option.font).value<QFont> ();
			text = index.data(Qt::DisplayRole).toString();
			break;
		default:
			text = index.data(Qt::DisplayRole).toString();
	}

	drawDisplay(painter, m_option, m_option.rect, text);
	drawFocus(painter, m_option, m_option.rect);
}
void PivotPropertyTableDelegate::paint ( QPainter* painter,
                                         const QStyleOptionViewItem& option,
                                         const QModelIndex& index ) const
{
    if ( index.column() != 1 ) {
        QStyleOptionViewItem opt = option;
        QItemDelegate::paint( painter, opt, index );
    }
    else
    {
        QPalette::ColorGroup cg = option.state& QStyle::State_Enabled ?
                                  QPalette::Normal : QPalette::Disabled;
        if ( option.state & QStyle::State_Selected )
            painter->fillRect( option.rect,
                               option.palette.color( cg,
                                                     QPalette::Highlight ) );
        QVariant material = index.model()->data( index, Qt::DisplayRole );
        Q_ASSERT( qVariantCanConvert<const TrussMaterial*>(material) );
        const TrussMaterial* currentMaterial =
                  qVariantValue<const TrussMaterial*>(material);
        if ( currentMaterial )
            drawDisplay( painter, option, option.rect,
                         currentMaterial->getMaterialName() );
        // since we draw the grid ourselves
        drawFocus( painter, option, option.rect );
    }
}
示例#13
0
void QItemDelegate_QtDShell::__override_drawFocus(QPainter*  painter0, const QStyleOptionViewItem&  option1, const QRect&  rect2, bool static_call) const
{
    if (static_call) {
        QItemDelegate::drawFocus((QPainter* )painter0, (const QStyleOptionViewItem& )option1, (const QRect& )rect2);
    } else {
        drawFocus((QPainter* )painter0, (const QStyleOptionViewItem& )option1, (const QRect& )rect2);
    }
}
示例#14
0
//=============================
void ComboBoxDelegate::paint( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const 
{
	QStyleOptionViewItem opt = option;
	QString text; 
  text = yesNoHash.value(index.model()->data(index, Qt::DisplayRole).toInt());
  drawDisplay(painter, opt, opt.rect, text);
  drawFocus(painter, opt, opt.rect);
}
示例#15
0
void IconDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
                          const QModelIndex &index) const
{
    Q_ASSERT(index.isValid());
    const QAbstractItemModel *model = index.model();
    Q_ASSERT(model);

    QStyleOptionViewItem opt = option;

    // set font
    QVariant value = model->data(index, Qt::FontRole);
    if (value.isValid())
        opt.font = qvariant_cast<QFont>(value);

    // set text alignment
    value = model->data(index, Qt::TextAlignmentRole);
    if (value.isValid())
        opt.displayAlignment = QFlag(value.toInt());

    // set text color
    value = model->data(index, Qt::TextColorRole);
    if (value.isValid() && qvariant_cast<QColor>(value).isValid())
        opt.palette.setColor(QPalette::Text, qvariant_cast<QColor>(value));

    // do layout
    value = model->data(index, Qt::DecorationRole);
    QPixmap pixmap = decoration(opt, value);
    QRect pixmapRect = pixmap.rect();

    QFontMetrics fontMetrics(opt.font);
    QString text = model->data(index, Qt::DisplayRole).toString();
    QRect textRect(0, 0, 0,0);
    //QRect textRect(0, 0, fontMetrics.width(text), fontMetrics.lineSpacing());

    value = model->data(index, Qt::CheckStateRole);
    QRect checkRect = check(opt, opt.rect, value);
    Qt::CheckState checkState = static_cast<Qt::CheckState>(value.toInt());

    doLayout(opt, &checkRect, &pixmapRect, &textRect, false);

    // draw the background color
    if (option.showDecorationSelected && (option.state & QStyle::State_Selected)) {
        QPalette::ColorGroup cg = option.state & QStyle::State_Enabled
                                  ? QPalette::Normal : QPalette::Disabled;
        painter->fillRect(option.rect, option.palette.brush(cg, QPalette::Highlight));
    } else {
        value = model->data(index, Qt::BackgroundColorRole);
        if (value.isValid() && qvariant_cast<QColor>(value).isValid())
            painter->fillRect(option.rect, qvariant_cast<QColor>(value));
    }

    // draw the item
    drawCheck(painter, opt, checkRect, checkState);
    drawDecoration(painter, opt, pixmapRect, pixmap);
//    drawDisplay(painter, opt, textRect, text);
    drawFocus(painter, opt, textRect);
}
//--------------------------------------------------------------------------------------
void RMapObjectTableViewDelegate::paint(QPainter *painter,
										const QStyleOptionViewItem &option,
										const QModelIndex &index) const
{
    switch (index.data(Qt::UserRole).toInt()) {
    case RMapObjectModel::ET_COLOR_SELECTOR: {
        QColor color = index.model()->data(index, Qt::DisplayRole).value<QColor>();
        painter->fillRect(option.rect, color);
        drawFocus(painter, option, option.rect);
        break;
    }

    case RMapObjectModel::ET_FONT_SELECTOR: {
        const RFontDescriptor *fd = index.model()->data(index, Qt::DisplayRole).value<const RFontDescriptor *>();
        QStyleOptionViewItem opt = option;
        opt.displayAlignment = Qt::AlignCenter;
        drawDisplay(painter, opt, opt.rect, fd->text());
        drawFocus(painter, opt, opt.rect);
        break;
    }

    case RMapObjectModel::ET_PICTURE_SELECTOR: {
        const RImageDescriptor *id = index.model()->data(index, Qt::DisplayRole).value<const RImageDescriptor *>();
        QStyleOptionViewItem opt = option;
        opt.displayAlignment = Qt::AlignCenter;
        drawDisplay(painter, opt, opt.rect, id->text());
        drawFocus(painter, opt, opt.rect);
        break;
    }

    case RMapObjectModel::ET_REFS_SELECTOR: {
        const RRefsDescriptor *rd = index.model()->data(index, Qt::DisplayRole).value<const RRefsDescriptor *>();
        QStyleOptionViewItem opt = option;
        opt.displayAlignment = Qt::AlignCenter;
        drawDisplay(painter, opt, opt.rect, rd->text());
        drawFocus(painter, opt, opt.rect);
        break;
    }

    default:
        QItemDelegate::paint(painter, option, index);
        break;
    }
}
示例#17
0
void DateDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    QString texto = index.model()->data(index, Qt::DisplayRole).toDate().toString("dd/MM/yyyy");


     QStyleOptionViewItem myOption = option;
     myOption.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
     drawDisplay(painter, myOption, myOption.rect,texto);
     drawFocus(painter, myOption, myOption.rect);
}
示例#18
0
static void drawSelected( HDC hdc, int x, int y )
{
    RECT    rect;

    rect.left = x * Width + SPC;
    rect.top = y * Height + SPC;
    rect.right = (x + 1) * Width - SPC;
    rect.bottom = (y + 1) * Height - SPC;

    drawFocus( hdc, &rect, true );
}
示例#19
0
void BodyTableDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
	QString strong;
	QStyleOptionViewItem myOption = option;
	myOption.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
	strong = QString("%1").arg(index.model()->data(index, Qt::DisplayRole).toDouble(),0,'f', m_Precision[index.column()]);
	
//	if(index.row()> *m_pNRows) strong=" ";
	drawDisplay(painter, myOption, myOption.rect, strong);
	drawFocus(painter, myOption, myOption.rect);
}
示例#20
0
void
AttributeDelegate::paint(QPainter *painter,
                        const QStyleOptionViewItem &option,
                        const QModelIndex &index) const
{
  switch (index.column())
  {

    case AttributesModel::REQUIRED:
    {
      bool enabled = index.data().toBool();

      drawCheck(painter, option, option.rect, enabled ? Qt::Checked : Qt::Unchecked);
      drawFocus(painter, option, option.rect);
      return;
    }

    case AttributesModel::ABSTRACT:
    {
      QModelIndex typeIndex = index.model()->index(index.row(), AttributesModel::TYPE);
      QString type = typeIndex.data().toString();

      if (type == "element" || type == "inline_lo_element" || type == "lo_element")
      {
        bool enabled = index.data().toBool();
        drawCheck(painter, option, option.rect, enabled ? Qt::Checked : Qt::Unchecked);
        drawFocus(painter, option, option.rect);
      }
      return;
    }

    default:
    case AttributesModel::TYPE:
  {
      QItemDelegate::paint(painter, option, index);
      return;
  }

  }

}
示例#21
0
void GuiVolumeDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
  if (index.column() >= first_column) {
    QString text = index.model()->data(index, Qt::DisplayRole).toString();
    QStyleOptionViewItem myOption = option;
    myOption.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
    drawDisplay(painter, myOption, myOption.rect, text);
    drawFocus(painter, myOption, myOption.rect);
  } else{
    QItemDelegate::paint(painter, option, index);
  }
}
示例#22
0
void MonetaryDelegate_totals::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    QString texto = index.model()->data(index, Qt::DisplayRole).toString();
    double valor_moneda = texto.toDouble();
    QString valor_moneda_string = QString::number(valor_moneda,'f',Configuracion_global->decimales_campos_totales);
     texto = Configuracion_global->toFormatoMoneda(valor_moneda_string);

     QStyleOptionViewItem myOption = option;
     myOption.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
     drawDisplay(painter, myOption, myOption.rect,texto);
     drawFocus(painter, myOption, myOption.rect);
}
示例#23
0
	// reimplemented
	virtual void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
	{
		QStyleOptionViewItemV4 opt(option);
		opt.showDecorationSelected = true;
		opt.rect.adjust(0, 0, 0, -1);

		painter->save();
		QStyle *style = opt.widget ? opt.widget->style() : QApplication::style();
		style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, opt.widget);

		QIcon icon = index.data(Qt::DecorationRole).value<QIcon>();
		QSize iconSize;
#if 0
		if (icon.availableSizes().isEmpty())
			iconSize = icon.availableSizes().first();
		else
#endif
			int s = PsiIconset::instance()->system().iconSize();
			iconSize = QSize(s,s);
		QRect iconRect = opt.rect;
		iconRect.setLeft(4);
		iconRect.setWidth(iconSize.width());
		icon.paint(painter, iconRect, Qt::AlignCenter, QIcon::Normal, QIcon::On);

		QRect textRect = opt.rect;
		textRect.setLeft(iconRect.right() + 8);
		QPalette::ColorGroup cg = option.state & QStyle::State_Enabled
		                          ? QPalette::Normal : QPalette::Disabled;
		if (cg == QPalette::Normal && !(option.state & QStyle::State_Active)) {
			cg = QPalette::Inactive;
		}
		if (option.state & QStyle::State_Selected) {
			painter->setPen(option.palette.color(cg, QPalette::HighlightedText));
		}
		else {
			painter->setPen(option.palette.color(cg, QPalette::Text));
		}
		painter->drawText(textRect, index.data(Qt::DisplayRole).toString(), Qt::AlignLeft | Qt::AlignVCenter);
		drawFocus(painter, option, option.rect); // not opt, because drawFocus() expects normal rect
		painter->restore();

		painter->save();
		QPen pen(QColor(0xE0, 0xE0, 0xE0));
		QVector<qreal> dashes;
		dashes << 1.0 << 1.0;
		pen.setCapStyle(Qt::FlatCap);
		pen.setDashPattern(dashes);

		painter->setPen(pen);
		painter->drawLine(option.rect.left(), option.rect.bottom(), option.rect.right(), option.rect.bottom());
		painter->restore();
	}
示例#24
0
void ThumbnailDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const
{
    Q_ASSERT(index.isValid());
    const QContentSetModel *model = qobject_cast< const QContentSetModel * >( index.model() );
    Q_ASSERT(model);

    QStyleOptionViewItem opt = option;

    // set text alignment
    opt.displayAlignment = Qt::AlignCenter;

    // do layout
    QContent content = model->content( index );
    QPixmap pixmap;

    if( content.fileKnown() ) {
        pixmap = repository_->thumbnail( ThumbnailRequest( index, content.file(), option.decorationSize, content.lastUpdated() ) );
    }
    if( pixmap.isNull() ) {
        QIcon icon = qvariant_cast<QIcon>(model->data(index, Qt::DecorationRole));
        pixmap = icon.pixmap( option.decorationSize );
    }
    QRect pixmapRect = QRect(0, 0, option.decorationSize.width(),
                           option.decorationSize.height());

    QFontMetrics fontMetrics(opt.font);
    QString text = model->data(index, Qt::DisplayRole).toString();
    QRect textRect(0, 0, option.decorationSize.width(), fontMetrics.lineSpacing());

    QVariant value = model->data(index, Qt::CheckStateRole);
    QRect checkRect = check(opt, opt.rect, value);
    Qt::CheckState checkState = static_cast<Qt::CheckState>(value.toInt());

    doLayout(opt, &checkRect, &pixmapRect, &textRect, false);

    // draw the background color
    if (option.showDecorationSelected && (option.state & QStyle::State_Selected)) {
        QPalette::ColorGroup cg = option.state & QStyle::State_Enabled
                                  ? QPalette::Normal : QPalette::Disabled;
        painter->fillRect(option.rect, option.palette.brush(cg, QPalette::Highlight));
    } else {
        value = model->data(index, Qt::BackgroundColorRole);
        if (value.isValid() && qvariant_cast<QColor>(value).isValid())
            painter->fillRect(option.rect, qvariant_cast<QColor>(value));
    }

    // draw the item
    drawCheck(painter, opt, checkRect, checkState);
    drawDecoration(painter, opt, pixmapRect, pixmap);
    drawDisplay(painter, opt, textRect, text);
    drawFocus(painter, opt, textRect);
}
示例#25
0
void Values_delegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const
{
  switch(index.column())
  {
  case Values_list::Color: {
    painter->fillRect(option.rect, index.data().value<QColor>());
    drawFocus(painter, option, option.rect);
    break;
  }
  default:
    QItemDelegate::paint(painter, option, index);
  }
}
示例#26
0
void TimeEditDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
                         const QModelIndex &index) const
{
    QDateTime dtval = index.model()->data(index, Qt::DisplayRole).toDateTime();

    QString indexvalue = tr("Date not set");
    if(dtval.isValid())
    {
        indexvalue = dtval.toString(timeformat);
    }
    Q_ASSERT(index.isValid());
    QStyleOptionViewItemV3 opt = setOptions(index, option);
    const QStyleOptionViewItemV2 *v2 = qstyleoption_cast<const QStyleOptionViewItemV2 *>(&option);
    opt.features = v2 ? v2->features
                    : QStyleOptionViewItemV2::ViewItemFeatures(QStyleOptionViewItemV2::None);
    const QStyleOptionViewItemV3 *v3 = qstyleoption_cast<const QStyleOptionViewItemV3 *>(&option);
    opt.locale = v3 ? v3->locale : QLocale();
    opt.widget = v3 ? v3->widget : 0;
    // prepare
    painter->save();
    painter->setClipRect(opt.rect);
    // get the data and the rectangles
    QVariant value;
    QPixmap pixmap;
    QRect decorationRect;
    value = index.data(Qt::DecorationRole);
    QString text;
    QRect displayRect;
    value = index.data(Qt::DisplayRole);
    if (value.isValid()) {
        text = indexvalue;
        displayRect = textRectangle(painter, option.rect, opt.font, text);
    }
    QRect checkRect;
    Qt::CheckState checkState = Qt::Unchecked;
    value = index.data(Qt::CheckStateRole);
    if (value.isValid()) {
        checkState = static_cast<Qt::CheckState>(value.toInt());
        //checkRect = check(opt, opt.rect, value);
    }
    // do the layout
    doLayout(opt, &checkRect, &decorationRect, &displayRect, false);
    // draw the item
    drawBackground(painter, opt, index);
    drawCheck(painter, opt, checkRect, checkState);
    drawDecoration(painter, opt, decorationRect, pixmap);
    drawDisplay(painter, opt, displayRect, text);
    drawFocus(painter, opt, displayRect);
    // done
    painter->restore();
}
示例#27
0
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void USplata_zaborg_Delegate::paint(QPainter *painter,
                          const QStyleOptionViewItem &option,
                          const QModelIndex &index) const
{
    if ( index.column() == durationColumn_2 ){
        double number = index.model()->data(index, Qt::DisplayRole).toDouble();
        QString text = uMToStr2(number);
        QStyleOptionViewItem myOption = option;
        myOption.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
        drawDisplay(painter, myOption, myOption.rect, text);
        drawFocus(painter, myOption, myOption.rect);
    } else{
        QItemDelegate::paint(painter, option, index);
    }
}
void TwitterAccountsDelegate::paint( QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index ) const
{
  if ( checkBoxColumns.contains( index.column() ) ) {
    Qt::CheckState state;
    if ( index.model()->data( index, Qt::DisplayRole ).toBool() )
      state = Qt::Checked;
    else
      state = Qt::Unchecked;

    drawDisplay( painter, option, option.rect, " " );
    drawFocus( painter, option, option.rect );
    drawCheck( painter, option, QRect( option.rect.x()+15, option.rect.y()+3 , option.rect.height()-5, option.rect.height()-5 ), state );
  } else {
    QItemDelegate::paint(painter, option, index);
  }
}
示例#29
0
void ColNumDelegato::paint(QPainter *painter,
                 const QStyleOptionViewItem & option,
                 const QModelIndex & index) const
{

    double numero = index.model()->data(index, Qt::DisplayRole).toDouble();

    QString text = QString("%L1").arg(numero,13,'f',2);

    QStyleOptionViewItem myOption = option;
    myOption.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;

    drawDisplay(painter, myOption, myOption.rect, text);
    drawFocus(painter, myOption, myOption.rect);

}
void MonetaryDelegate_contabilidad::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    QString texto = index.model()->data(index, Qt::DisplayRole).toString();
     texto = Configuracion_global->toFormatoMoneda(texto);
     if(texto =="0,00")
         texto = "";
     QStyleOptionViewItem myOption = option;
     myOption.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
     if(texto.left(1)=="-")
        myOption.palette.setColor(QPalette::Text, Qt::red);
     else
        myOption.palette.setColor(QPalette::Text, Qt::blue);
     drawDisplay(painter, myOption, myOption.rect,texto);
     drawFocus(painter, myOption, myOption.rect);

}