Commit f1ad849a authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Port some deprecated methods

parent 423e3d0a
Pipeline #184653 passed with stage
in 2 minutes and 4 seconds
......@@ -105,13 +105,24 @@ void AlarmListView::initSections()
header()->setSectionResizeMode(AlarmListModel::NameColumn, QHeaderView::ResizeToContents);
header()->setSectionResizeMode(AlarmListModel::TextColumn, QHeaderView::Stretch);
header()->setStretchLastSection(true); // necessary to ensure ResizeToContents columns do resize to contents!
const int minWidth = viewOptions().fontMetrics.lineSpacing() * 3 / 4;
const int minWidth = listViewOptions().fontMetrics.lineSpacing() * 3 / 4;
header()->setMinimumSectionSize(minWidth);
const int margin = QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin);
header()->resizeSection(AlarmListModel::ColourColumn, minWidth);
header()->resizeSection(AlarmListModel::TypeColumn, AlarmListModel::iconWidth() + 2*margin + 2);
}
QStyleOptionViewItem AlarmListView::listViewOptions() const
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
return QTreeView::viewOptions();
#else
QStyleOptionViewItem option;
initViewItemOption(&option);
return option;
#endif
}
/******************************************************************************
* Called when the column order is changed.
* Save the new order for restoration on program restart.
......
......@@ -39,6 +39,7 @@ private:
void showHideColumn(QMenu&, QAction*);
void setReplaceBlankName();
void enableTimeColumns(QMenu*);
QStyleOptionViewItem listViewOptions() const;
QByteArray mConfigGroup;
};
......
......@@ -156,6 +156,18 @@ void EventListView::resizeEvent(QResizeEvent* se)
initSections();
}
QStyleOptionViewItem EventListView::listViewOptions() const
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
return QTreeView::viewOptions();
#else
QStyleOptionViewItem option;
initViewItemOption(&option);
return option;
#endif
}
/******************************************************************************
* Called when a ToolTip or WhatsThis event occurs.
*/
......@@ -180,7 +192,7 @@ bool EventListView::viewportEvent(QEvent* e)
// Single line tooltip. Only display it if the text column
// is truncated in the view display.
value = model()->data(index, Qt::FontRole);
const QFontMetrics fm(qvariant_cast<QFont>(value).resolve(viewOptions().font));
const QFontMetrics fm(qvariant_cast<QFont>(value).resolve(listViewOptions().font));
const int textWidth = fm.boundingRect(toolTip).width() + 1;
const int margin = QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1;
const int left = columnViewportPosition(index.column()) + margin;
......
......@@ -53,6 +53,7 @@ protected Q_SLOTS:
void sortChanged(int column, Qt::SortOrder);
private:
QStyleOptionViewItem listViewOptions() const;
void findNext(bool forward);
Find* mFind {nullptr};
......
......@@ -681,14 +681,14 @@ bool ResourceView::viewportEvent(QEvent* e)
const int k = toolTip.indexOf(QLatin1Char('@'), j);
const QString name = toolTip.mid(i + 1, j - i - 1);
value = model()->data(index, Qt::FontRole);
const QFontMetrics fm(qvariant_cast<QFont>(value).resolve(viewOptions().font));
const QFontMetrics fm(qvariant_cast<QFont>(value).resolve(listViewOptions().font));
int textWidth = fm.boundingRect(name).width() + 1;
const int margin = QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1;
QStyleOptionButton opt;
opt.QStyleOption::operator=(viewOptions());
opt.QStyleOption::operator=(listViewOptions());
opt.rect = rectForIndex(index);
const int checkWidth = QApplication::style()->subElementRect(QStyle::SE_ItemViewItemCheckIndicator, &opt).width();
const int left = spacing() + 3*margin + checkWidth + viewOptions().decorationSize.width(); // left offset of text
const int left = spacing() + 3*margin + checkWidth + listViewOptions().decorationSize.width(); // left offset of text
const int right = left + textWidth;
if (left >= horizontalOffset() + spacing()
&& right <= horizontalOffset() + width() - spacing() - 2*frameWidth())
......@@ -711,4 +711,14 @@ bool ResourceView::viewportEvent(QEvent* e)
return QListView::viewportEvent(e);
}
QStyleOptionViewItem ResourceView::listViewOptions() const
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
return QListView::viewOptions();
#else
QStyleOptionViewItem option;
initViewItemOption(&option);
return option;
#endif
}
// vim: et sw=4:
......@@ -236,6 +236,8 @@ Q_SIGNALS:
protected:
void mouseReleaseEvent(QMouseEvent*) override;
bool viewportEvent(QEvent*) override;
private:
QStyleOptionViewItem listViewOptions() const;
};
......
......@@ -32,13 +32,24 @@ void TemplateListView::initSections()
header()->setSectionsMovable(false);
header()->setStretchLastSection(true);
header()->setSectionResizeMode(TemplateListModel::TypeColumn, QHeaderView::Fixed);
const int minWidth = viewOptions().fontMetrics.lineSpacing() * 3 / 4;
const int minWidth = listViewOptions().fontMetrics.lineSpacing() * 3 / 4;
header()->setMinimumSectionSize(minWidth);
const int margin = QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin);
header()->resizeSection(TemplateListModel::TypeColumn, EventListModel::iconWidth() + 2*margin + 2);
sortByColumn(TemplateListModel::TemplateNameColumn, Qt::AscendingOrder);
}
QStyleOptionViewItem TemplateListView::listViewOptions() const
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
return QTreeView::viewOptions();
#else
QStyleOptionViewItem option;
initViewItemOption(&option);
return option;
#endif
}
void TemplateListDelegate::edit(KAEvent& event, EventListView* view)
{
KAlarm::editTemplate(event, static_cast<TemplateListView*>(view));
......
......@@ -19,6 +19,8 @@ public:
protected Q_SLOTS:
void initSections() override;
private:
QStyleOptionViewItem listViewOptions() const;
};
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment