-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make TableView rendering consistent with what Qt native does #84
Open
dunkelstern
wants to merge
2
commits into
oclero:dev
Choose a base branch
from
dunkelstern:j.schriewer/tableview-rendering
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -861,8 +861,31 @@ void QlementineStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption* opt | |||||||||||
const auto focus = | ||||||||||||
widgetHasFocus && selection == SelectionState::Selected ? FocusState::Focused : FocusState::NotFocused; | ||||||||||||
const auto active = getActiveState(itemState); | ||||||||||||
const auto& color = listItemBackgroundColor(mouse, selection, focus, active, optItem->index, w); | ||||||||||||
p->fillRect(rect, color); | ||||||||||||
if (const QStyleOptionViewItem *vopt = qstyleoption_cast<const QStyleOptionViewItem*>(opt)) { | ||||||||||||
QPalette::ColorGroup cg = (w ? w->isEnabled() : (vopt->state & QStyle::State_Enabled)) | ||||||||||||
? QPalette::Normal : QPalette::Disabled; | ||||||||||||
if (cg == QPalette::Normal && !(vopt->state & QStyle::State_Active)) | ||||||||||||
cg = QPalette::Inactive; | ||||||||||||
Comment on lines
+867
to
+868
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use brackets 😊
Suggested change
|
||||||||||||
|
||||||||||||
if (vopt->showDecorationSelected && (vopt->state & QStyle::State_Selected)) { | ||||||||||||
p->fillRect(vopt->rect, vopt->palette.brush(cg, QPalette::Highlight)); | ||||||||||||
} else { | ||||||||||||
if (vopt->backgroundBrush.style() != Qt::NoBrush) { | ||||||||||||
QPointF oldBO = p->brushOrigin(); | ||||||||||||
p->setBrushOrigin(vopt->rect.topLeft()); | ||||||||||||
p->fillRect(vopt->rect, vopt->backgroundBrush); | ||||||||||||
p->setBrushOrigin(oldBO); | ||||||||||||
} | ||||||||||||
|
||||||||||||
if (vopt->state & QStyle::State_Selected) { | ||||||||||||
QRect textRect = subElementRect(QStyle::SE_ItemViewItemText, opt, w); | ||||||||||||
p->fillRect(textRect, vopt->palette.brush(cg, QPalette::Highlight)); | ||||||||||||
} | ||||||||||||
} | ||||||||||||
} else { | ||||||||||||
const auto &color = listItemBackgroundColor(mouse, selection, focus, active, optItem->index, w); | ||||||||||||
p->fillRect(rect, color); | ||||||||||||
} | ||||||||||||
|
||||||||||||
// Border on the left if necessary. | ||||||||||||
if (column == 0) { | ||||||||||||
|
@@ -3935,18 +3958,16 @@ QSize QlementineStyle::sizeFromContents( | |||||||||||
} | ||||||||||||
const auto lineW = _impl->theme.borderWidth; | ||||||||||||
const auto iconExtent = pixelMetric(PM_SmallIconSize, opt); | ||||||||||||
const auto fm = QFontMetrics(font); | ||||||||||||
const auto textW = qlementine::textWidth(fm, optHeader->text); | ||||||||||||
const QSize textSize = optHeader->fontMetrics.size(0, optHeader->text); | ||||||||||||
const auto& icon = optHeader->icon; | ||||||||||||
const auto hasIcon = !icon.isNull(); | ||||||||||||
const auto iconW = hasIcon ? iconExtent + spacing : 0; | ||||||||||||
const auto hasArrow = optHeader->sortIndicator != QStyleOptionHeader::SortIndicator::None; | ||||||||||||
const auto arrowW = hasArrow ? iconExtent + spacing : 0; | ||||||||||||
const auto paddingH = pixelMetric(PM_HeaderMargin); | ||||||||||||
const auto paddingV = paddingH / 2; | ||||||||||||
const auto textH = fm.height(); | ||||||||||||
const auto w = lineW + paddingH + iconW + textW + arrowW + paddingH + lineW; | ||||||||||||
const auto h = lineW + paddingV + std::max(iconExtent, textH) + paddingV + lineW; | ||||||||||||
const auto w = lineW + paddingH + iconW + textSize.width() + arrowW + paddingH + lineW; | ||||||||||||
const auto h = lineW + paddingV + std::max(iconExtent, textSize.height()) + paddingV + lineW; | ||||||||||||
return QSize{ w, h }; | ||||||||||||
} | ||||||||||||
break; | ||||||||||||
|
@@ -3982,19 +4003,18 @@ QSize QlementineStyle::sizeFromContents( | |||||||||||
const auto& iconSize = hasIcon ? optItem->decorationSize : QSize{ 0, 0 }; | ||||||||||||
|
||||||||||||
const auto hasText = features.testFlag(QStyleOptionViewItem::HasDisplay) && !optItem->text.isEmpty(); | ||||||||||||
const auto textH = hasText ? optItem->fontMetrics.height() : 0; | ||||||||||||
QSize textSize(0,0); | ||||||||||||
if (hasText) { | ||||||||||||
textSize = optItem->fontMetrics.size(0, optItem->text); | ||||||||||||
} | ||||||||||||
|
||||||||||||
const auto hasCheck = features.testFlag(QStyleOptionViewItem::HasCheckIndicator); | ||||||||||||
const auto& checkSize = hasCheck ? _impl->theme.iconSize : QSize{ 0, 0 }; | ||||||||||||
|
||||||||||||
auto font = QFont(widget->font()); | ||||||||||||
const auto fm = QFontMetrics(font); | ||||||||||||
const auto textW = qlementine::textWidth(fm, optItem->text); | ||||||||||||
|
||||||||||||
const auto w = textW + 2 * hPadding + (iconSize.width() > 0 ? iconSize.width() + spacing : 0) | ||||||||||||
const auto w = textSize.width() + 2 * hPadding + (iconSize.width() > 0 ? iconSize.width() + spacing : 0) | ||||||||||||
+ (checkSize.width() > 0 ? checkSize.width() + spacing : 0); | ||||||||||||
const auto defaultH = _impl->theme.controlHeightLarge; | ||||||||||||
const auto h = std::max({ iconSize.height() + spacing, textH + spacing, defaultH }); | ||||||||||||
const auto h = std::max({ iconSize.height() + spacing, textSize.height() + spacing, defaultH }); | ||||||||||||
return QSize{ w, h }; | ||||||||||||
} | ||||||||||||
break; | ||||||||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use
auto
as much as possible 😊There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw, why do you cast again
opt
? It's already made a few lines above?So the code in the
else
statement will never be called... So you broke the styling made by Qlementine.