mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-11 13:30:03 -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 {
|
QTreeView::item {
|
||||||
border: 1px solid transparent;
|
border: 1px solid transparent;
|
||||||
|
padding-left: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
QTreeView::item:selected {
|
QTreeView::item:selected {
|
||||||
border: 1px solid #3366CC;
|
|
||||||
background-color: #D9E9FF;
|
background-color: #D9E9FF;
|
||||||
color: black;
|
color: black;
|
||||||
}
|
}
|
||||||
|
@ -85,6 +85,7 @@ SearchBarLineEdit::SearchBarLineEdit(QWidget *parent) :
|
|||||||
m_suggestionView->header()->setStretchLastSection(true);
|
m_suggestionView->header()->setStretchLastSection(true);
|
||||||
m_suggestionView->setRootIsDecorated(false);
|
m_suggestionView->setRootIsDecorated(false);
|
||||||
m_suggestionView->setStyleSheet(KiwixApp::instance()->parseStyleFromFile(":/css/popup.css"));
|
m_suggestionView->setStyleSheet(KiwixApp::instance()->parseStyleFromFile(":/css/popup.css"));
|
||||||
|
m_suggestionView->setColumnWidth(0, 40);
|
||||||
|
|
||||||
const int contentHeight = HeaderSectionCSS::lineHeight;
|
const int contentHeight = HeaderSectionCSS::lineHeight;
|
||||||
m_suggestionView->setIconSize(QSize(contentHeight, contentHeight));
|
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
|
int SuggestionListModel::rowCount(const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
Q_UNUSED(parent);
|
Q_UNUSED(parent);
|
||||||
@ -30,6 +37,15 @@ QVariant SuggestionListModel::data(const QModelIndex &index, int role) const
|
|||||||
if (row < 0 || row >= rowCount())
|
if (row < 0 || row >= rowCount())
|
||||||
return QVariant();
|
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)
|
switch (role)
|
||||||
{
|
{
|
||||||
case Qt::DisplayRole:
|
case Qt::DisplayRole:
|
||||||
@ -37,12 +53,6 @@ QVariant SuggestionListModel::data(const QModelIndex &index, int role) const
|
|||||||
return m_suggestions.at(row).text;
|
return m_suggestions.at(row).text;
|
||||||
case Qt::UserRole:
|
case Qt::UserRole:
|
||||||
return m_suggestions.at(row).url;
|
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:
|
case Qt::SizeHintRole:
|
||||||
{
|
{
|
||||||
/* Padding in css can't change height, we have to achieve padding
|
/* 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 QSize(0, lineHeight + 2 * padding);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,7 +71,7 @@ QVariant SuggestionListModel::headerData(int section,
|
|||||||
Qt::Orientation orientation,
|
Qt::Orientation orientation,
|
||||||
int role) const
|
int role) const
|
||||||
{
|
{
|
||||||
if (section != 0 || orientation != Qt::Orientation::Horizontal)
|
if (section != 1 || orientation != Qt::Orientation::Horizontal)
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
||||||
switch (role)
|
switch (role)
|
||||||
|
@ -20,6 +20,7 @@ public:
|
|||||||
explicit SuggestionListModel(QObject *parent = nullptr);
|
explicit SuggestionListModel(QObject *parent = nullptr);
|
||||||
~SuggestionListModel();
|
~SuggestionListModel();
|
||||||
|
|
||||||
|
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||||
int rowCount(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 data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||||
QVariant headerData(int section, Qt::Orientation orientation, 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