From 62f3055e5a7ca6fc0a55060857e5ea8760b803df Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 18 May 2022 00:25:04 +0200 Subject: [PATCH] [netinstall] Implement a special "blank" item - If the name of an item is empty, treat it as a "separator line", do not paint it like a regular item. The branches of the tree just pass it by. --- src/modules/netinstall/CMakeLists.txt | 1 + src/modules/netinstall/groupstreeview.cpp | 30 +++++++++++++++++++++++ src/modules/netinstall/groupstreeview.h | 9 ++++++- 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 src/modules/netinstall/groupstreeview.cpp diff --git a/src/modules/netinstall/CMakeLists.txt b/src/modules/netinstall/CMakeLists.txt index f31ac6d79..13c6fa0ce 100644 --- a/src/modules/netinstall/CMakeLists.txt +++ b/src/modules/netinstall/CMakeLists.txt @@ -8,6 +8,7 @@ calamares_add_plugin( netinstall EXPORT_MACRO PLUGINDLLEXPORT_PRO SOURCES Config.cpp + groupstreeview.cpp LoaderQueue.cpp NetInstallViewStep.cpp NetInstallPage.cpp diff --git a/src/modules/netinstall/groupstreeview.cpp b/src/modules/netinstall/groupstreeview.cpp new file mode 100644 index 000000000..226fccc7e --- /dev/null +++ b/src/modules/netinstall/groupstreeview.cpp @@ -0,0 +1,30 @@ +/* === This file is part of Calamares - === + * + * SPDX-FileCopyrightText: 2022 Adriaan de Groot + * SPDX-License-Identifier: GPL-3.0-or-later + * + * Calamares is Free Software: see the License-Identifier above. + * + */ +#include "groupstreeview.h" + +#include "utils/Logger.h" + +#include + +void GroupsTreeView::drawBranches(QPainter* painter, const QRect& rect, const QModelIndex& index) const +{ + QTreeView::drawBranches(painter, rect, index); + + // Empty names are handled specially: don't draw them as items, + // so the "branch" seems to just pass them by. + const QString s = index.data().toString(); + if (s.isEmpty()) + { + QStyleOptionViewItem opt = viewOptions(); + opt.state = QStyle::State_Sibling; + opt.rect = QRect (!isRightToLeft() ? rect.left() : rect.right() + 1, rect.top(), indentation(), rect.height()); + painter->eraseRect(opt.rect); + style()->drawPrimitive(QStyle::PE_IndicatorBranch, &opt, painter, this); + } +} diff --git a/src/modules/netinstall/groupstreeview.h b/src/modules/netinstall/groupstreeview.h index a22ea7016..fb096db58 100644 --- a/src/modules/netinstall/groupstreeview.h +++ b/src/modules/netinstall/groupstreeview.h @@ -8,4 +8,11 @@ */ #include -using GroupsTreeView = QTreeView; +class GroupsTreeView : public QTreeView +{ +public: + using QTreeView::QTreeView; + +protected: + virtual void drawBranches(QPainter*painter, const QRect& rect, const QModelIndex& index) const override; +};