-
-
Notifications
You must be signed in to change notification settings - Fork 101
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
Implement Fine-Tuned Zim Search #1189
base: main
Are you sure you want to change the base?
Changes from 1 commit
7b7c949
1f1743b
8611a1c
6cbc9e8
c029da2
d5de7c6
0aac03f
84e29ec
2aca115
1894d41
d0a1680
76bae0d
a7d7304
d713173
b3d9424
ff7117b
ce36366
b9f4f94
02e042a
dac8d04
fcebdd0
64b30c3
b19ea81
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,11 @@ QVariant SuggestionListModel::data(const QModelIndex &index, int role) const | |
return library->getZimIcon(zimId, defaultIcon); | ||
} | ||
break; | ||
case Qt::SizeHintRole: | ||
/* See resources/css/popup.css QHeaderView::section. | ||
Take line-height + 5 padding top and bottom. | ||
*/ | ||
return QSize(0, 34); | ||
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. If this value cannot be computed from values obtained from CSS, then you can at least minimize the maintenance burden by defining a few constants in a dedicated source file and cross referencing it with the css file so that at most 2 locations have to be updated if/when any of those values changes. For example css_constants.h namespace CSS
{
// Need a good explanation of why this file is needed and the logical connection
// of these values to their counterparts in the CSS files must be emphasized.
// A cross reference to each constant from this file must be put beside the respective
// property in the CSS file.
// QHeaderView::section:line-height
const int SUGGESTION_LINE_HEIGHT = 24;
// QHeaderView::section:padding-top
const int SUGGESTION_LINE_PADDING_TOP = 5;
} and then return QSize(0, CSS::SUGGESTION_LINE_HEIGHT + CSS::SUGGESTION_LINE_PADDING_TOP + CSS::SUGGESTION_LINE_PADDING_BOTTOM); Note that the current value of 34 doesn't match the formula from the code comment and the actual CSS values (which rather evaluates to 39). All other similar magic numbers introduced in C++ code by this PR must be eliminated in a similar way. 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. @veloman-yunkan I furthur propose we can use multi-level namespaces to further structure the CSS. If a file wants to use, for example, CSS::QTabBar::QWidget, they can do an aliasing to get a shorter name. One question, why does it evaluate it to 39? 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.
Your formula says line-height + 5 padding top and bottom Relevant CSS is QHeaderView::section {
...
padding-top: 10px;
...
padding-bottom: 5px;
...
line-height: 24px;
...
} 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. Ah.. I forgot to explain the padding top has an extra 5px. Will restructure this in the next PR with better explanations. |
||
} | ||
return QVariant(); | ||
} | ||
|
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.
Does Qt provide a way of obtaining values from the stylesheet in effect?
Note that this comment applies to other magic number (CSS property values duplicated/hardcoded in C++ code) of this commit.
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.
I don't think its possible unless we parse the entire CSS to a global object like a JSON object. That will be a whole new project in itself.