mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-09 07:02:41 -04:00
Fix RSElidedItemDelegate
This commit is contained in:
parent
7f5f03bcda
commit
bfb1159ca0
1 changed files with 14 additions and 4 deletions
|
@ -202,7 +202,7 @@ void RSElidedItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
|
||||||
moOption.decorationPosition = QStyleOptionViewItem::Left;
|
moOption.decorationPosition = QStyleOptionViewItem::Left;
|
||||||
moOption.decorationSize = QSize();
|
moOption.decorationSize = QSize();
|
||||||
moOption.displayAlignment = Qt::AlignLeft | Qt::AlignTop;
|
moOption.displayAlignment = Qt::AlignLeft | Qt::AlignTop;
|
||||||
moOption.features=0;
|
moOption.features=QStyleOptionViewItem::ViewItemFeatures();
|
||||||
moOption.font = QFont();
|
moOption.font = QFont();
|
||||||
moOption.icon = QIcon();
|
moOption.icon = QIcon();
|
||||||
moOption.index = QModelIndex();
|
moOption.index = QModelIndex();
|
||||||
|
@ -217,7 +217,8 @@ void RSElidedItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
|
||||||
moOption.palette = QPalette();
|
moOption.palette = QPalette();
|
||||||
moOption.styleObject = nullptr;
|
moOption.styleObject = nullptr;
|
||||||
}
|
}
|
||||||
QStyledItemDelegate::paint(&moPnt, moOption, QModelIndex());
|
//QStyledItemDelegate::paint(&moPnt, moOption, QModelIndex(index));//This update option now.
|
||||||
|
ownStyle->drawControl(QStyle::CE_ItemViewItem, &moOption, &moPnt, widget);
|
||||||
|
|
||||||
//// But these lines doesn't works.
|
//// But these lines doesn't works.
|
||||||
{
|
{
|
||||||
|
@ -300,9 +301,9 @@ void RSElidedItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
|
||||||
{
|
{
|
||||||
QStyleOptionViewItem tstOption = option;
|
QStyleOptionViewItem tstOption = option;
|
||||||
// Reduce rect to get this item bg color external and base internal
|
// Reduce rect to get this item bg color external and base internal
|
||||||
tstOption.rect.adjust(3,3,-6,-6);
|
tstOption.rect.adjust(2,2,-2,-2);
|
||||||
// To draw with base for debug purpose
|
// To draw with base for debug purpose
|
||||||
QStyledItemDelegate::paint(painter, tstOption, index);
|
RSStyledItemDelegate::paint(painter, tstOption, index);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -379,6 +380,10 @@ void RSElidedItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
|
||||||
|
|
||||||
QTextLayout textLayout(ownOption.text, painter->font());
|
QTextLayout textLayout(ownOption.text, painter->font());
|
||||||
QTextOption to = textLayout.textOption();
|
QTextOption to = textLayout.textOption();
|
||||||
|
const int textHMargin = ownStyle->pixelMetric(QStyle::PM_FocusFrameHMargin, nullptr, widget) + 1;
|
||||||
|
const int textVMargin = ownStyle->pixelMetric(QStyle::PM_FocusFrameVMargin, nullptr, widget) + 1;
|
||||||
|
textRect = textRect.adjusted(textHMargin, textVMargin, -textHMargin, -textVMargin); // remove width padding
|
||||||
|
|
||||||
StyledElidedLabel::paintElidedLine(painter,ownOption.text,textRect,ownOption.font,ownOption.displayAlignment,to.wrapMode()&QTextOption::WordWrap,mPaintRoundedRect);
|
StyledElidedLabel::paintElidedLine(painter,ownOption.text,textRect,ownOption.font,ownOption.displayAlignment,to.wrapMode()&QTextOption::WordWrap,mPaintRoundedRect);
|
||||||
}
|
}
|
||||||
painter->restore();
|
painter->restore();
|
||||||
|
@ -393,7 +398,9 @@ bool RSElidedItemDelegate::editorEvent(QEvent *event, QAbstractItemModel *model,
|
||||||
QMouseEvent *ev = static_cast<QMouseEvent *>(event);
|
QMouseEvent *ev = static_cast<QMouseEvent *>(event);
|
||||||
if (ev) {
|
if (ev) {
|
||||||
if (ev->buttons()==Qt::LeftButton) {
|
if (ev->buttons()==Qt::LeftButton) {
|
||||||
|
#ifdef DEBUG_EID_PAINT
|
||||||
QVariant var = index.data();
|
QVariant var = index.data();
|
||||||
|
#endif
|
||||||
if (index.data().type() == QVariant::String) {
|
if (index.data().type() == QVariant::String) {
|
||||||
QString text = index.data().toString();
|
QString text = index.data().toString();
|
||||||
if (!text.isEmpty()) {
|
if (!text.isEmpty()) {
|
||||||
|
@ -417,6 +424,9 @@ bool RSElidedItemDelegate::editorEvent(QEvent *event, QAbstractItemModel *model,
|
||||||
ownOption.fontMetrics = QFontMetrics(font);
|
ownOption.fontMetrics = QFontMetrics(font);
|
||||||
}
|
}
|
||||||
QRect textRect = ownStyle->subElementRect(QStyle::SE_ItemViewItemText, &ownOption, widget);
|
QRect textRect = ownStyle->subElementRect(QStyle::SE_ItemViewItemText, &ownOption, widget);
|
||||||
|
const int textHMargin = ownStyle->pixelMetric(QStyle::PM_FocusFrameHMargin, nullptr, widget) + 1;
|
||||||
|
const int textVMargin = ownStyle->pixelMetric(QStyle::PM_FocusFrameVMargin, nullptr, widget) + 1;
|
||||||
|
textRect = textRect.adjusted(textHMargin, textVMargin, -textHMargin, -textVMargin); // remove width padding
|
||||||
|
|
||||||
QTextLayout textLayout(text, ownOption.font);
|
QTextLayout textLayout(text, ownOption.font);
|
||||||
QTextOption to = textLayout.textOption();
|
QTextOption to = textLayout.textOption();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue