Esempio n. 1
0
Layer::Layer(LayerType type, QGraphicsItemGroup *parent) :
    QGraphicsItemGroup(parent),
    layerType(type),
    selectionMarker(this),
    TreeItem(0)
{
    this->setFlag(QGraphicsItem::ItemIsMovable,true);
    this->setFlag(QGraphicsItem::ItemIsSelectable,true);
    QColor selectionColor(Qt::gray);
    selectionColor.setAlpha(40);
    QBrush selectionBrush(selectionColor);
    this->selectionMarker.setBrush(selectionBrush);
    this->selectionMarker.setZValue(this->zValue()+1);
}
Esempio n. 2
0
void TFriendItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const {
    // QString line0 = index.model()->data(index.model()->index(index.row(), 1)).toString();
    if (!index.data().canConvert<TFriendData>()) {
        return;
    }
    TFriendData frnd = index.data().value<TFriendData>();
    QStyleOptionViewItemV4 opt = option;
    initStyleOption(&opt, index);

    QRect rect = opt.rect;
    QPalette::ColorGroup cg = opt.state & QStyle::State_Enabled ? QPalette::Normal : QPalette::Disabled;
    if (cg == QPalette::Normal && !(opt.state & QStyle::State_Active)) {
        cg = QPalette::Inactive;
    }

    // set pen color
    if (opt.state & QStyle::State_Selected) {
        painter->save();
        QBrush selectionBrush(Qt::blue);
        painter->setBrush(selectionBrush);
        painter->drawRect(rect.adjusted(1, 1, -1, -1));
        //painter->drawRoundedRect(rect.adjusted(1,1,-1,-1), 5, 5);
        painter->restore();

        painter->setPen(opt.palette.color(cg, QPalette::HighlightedText));
    } else {
        painter->setPen(opt.palette.color(cg, QPalette::Text));
    }

    // draw 2 lines of text
    QFont font;
    font.setPixelSize(MIN_FRIEND_ITEM_HEIGHT - 6);
    painter->setFont(font);
    painter->drawImage(rect.left(), rect.top() + 2, ImageStorage->GetStatusImage(frnd.Status));
    painter->drawText(QRect(rect.left() + 18, rect.top(), rect.width() - 16, rect.height()),
                      opt.displayAlignment, frnd.Login);
}