mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-08 19:58:16 -04:00
Another way of positioning suggestion icon & text
The problem with this is approach is its effect on the header of the suggestion list - the model data is now considered to be composed of two columns and there is no way to make the header span all columns.
This commit is contained in:
parent
aa4ce594b8
commit
b4a13a7bc0
@ -6,10 +6,10 @@ QTreeView {
|
||||
|
||||
QTreeView::item {
|
||||
border: 1px solid transparent;
|
||||
padding-left: 10px;
|
||||
}
|
||||
|
||||
QTreeView::item:selected {
|
||||
border: 1px solid #3366CC;
|
||||
background-color: #D9E9FF;
|
||||
color: black;
|
||||
}
|
||||
@ -39,4 +39,4 @@ QScrollBar {
|
||||
|
||||
QScrollBar::handle {
|
||||
background-color: grey;
|
||||
}
|
||||
}
|
||||
|
@ -85,6 +85,7 @@ SearchBarLineEdit::SearchBarLineEdit(QWidget *parent) :
|
||||
m_suggestionView->header()->setStretchLastSection(true);
|
||||
m_suggestionView->setRootIsDecorated(false);
|
||||
m_suggestionView->setStyleSheet(KiwixApp::instance()->parseStyleFromFile(":/css/popup.css"));
|
||||
m_suggestionView->setColumnWidth(0, 40);
|
||||
|
||||
const int contentHeight = HeaderSectionCSS::lineHeight;
|
||||
m_suggestionView->setIconSize(QSize(contentHeight, contentHeight));
|
||||
|
@ -17,6 +17,13 @@ SuggestionListModel::~SuggestionListModel()
|
||||
{
|
||||
}
|
||||
|
||||
int SuggestionListModel::columnCount(const QModelIndex &parent) const
|
||||
{
|
||||
Q_UNUSED(parent);
|
||||
|
||||
return 2;
|
||||
}
|
||||
|
||||
int SuggestionListModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
Q_UNUSED(parent);
|
||||
@ -30,6 +37,15 @@ QVariant SuggestionListModel::data(const QModelIndex &index, int role) const
|
||||
if (row < 0 || row >= rowCount())
|
||||
return QVariant();
|
||||
|
||||
if ( index.column() == 0 && role == Qt::DecorationRole )
|
||||
{
|
||||
const auto library = KiwixApp::instance()->getLibrary();
|
||||
const auto zimId = getZimIdFromUrl(m_suggestions.at(row).url);
|
||||
return library->getBookIcon(zimId);
|
||||
}
|
||||
|
||||
if ( index.column() == 1 )
|
||||
{
|
||||
switch (role)
|
||||
{
|
||||
case Qt::DisplayRole:
|
||||
@ -37,12 +53,6 @@ QVariant SuggestionListModel::data(const QModelIndex &index, int role) const
|
||||
return m_suggestions.at(row).text;
|
||||
case Qt::UserRole:
|
||||
return m_suggestions.at(row).url;
|
||||
case Qt::DecorationRole:
|
||||
{
|
||||
const auto library = KiwixApp::instance()->getLibrary();
|
||||
const auto zimId = getZimIdFromUrl(m_suggestions.at(row).url);
|
||||
return library->getBookIcon(zimId);
|
||||
}
|
||||
case Qt::SizeHintRole:
|
||||
{
|
||||
/* Padding in css can't change height, we have to achieve padding
|
||||
@ -53,6 +63,7 @@ QVariant SuggestionListModel::data(const QModelIndex &index, int role) const
|
||||
return QSize(0, lineHeight + 2 * padding);
|
||||
}
|
||||
}
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
@ -60,7 +71,7 @@ QVariant SuggestionListModel::headerData(int section,
|
||||
Qt::Orientation orientation,
|
||||
int role) const
|
||||
{
|
||||
if (section != 0 || orientation != Qt::Orientation::Horizontal)
|
||||
if (section != 1 || orientation != Qt::Orientation::Horizontal)
|
||||
return QVariant();
|
||||
|
||||
switch (role)
|
||||
|
@ -20,6 +20,7 @@ public:
|
||||
explicit SuggestionListModel(QObject *parent = nullptr);
|
||||
~SuggestionListModel();
|
||||
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
|
||||
|
Loading…
x
Reference in New Issue
Block a user