[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.
This commit is contained in:
Adriaan de Groot 2022-05-18 00:25:04 +02:00
parent 542aa5c083
commit 62f3055e5a
3 changed files with 39 additions and 1 deletions

View File

@ -8,6 +8,7 @@ calamares_add_plugin( netinstall
EXPORT_MACRO PLUGINDLLEXPORT_PRO EXPORT_MACRO PLUGINDLLEXPORT_PRO
SOURCES SOURCES
Config.cpp Config.cpp
groupstreeview.cpp
LoaderQueue.cpp LoaderQueue.cpp
NetInstallViewStep.cpp NetInstallViewStep.cpp
NetInstallPage.cpp NetInstallPage.cpp

View File

@ -0,0 +1,30 @@
/* === This file is part of Calamares - <https://calamares.io> ===
*
* SPDX-FileCopyrightText: 2022 Adriaan de Groot <groot@kde.org>
* 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 <QPainter>
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);
}
}

View File

@ -8,4 +8,11 @@
*/ */
#include <QTreeView> #include <QTreeView>
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;
};