calamares/0008-progromTree.patch

661 lines
22 KiB
Diff

From dd87845d5196cb45fc409ea0d445ff157cda7d33 Mon Sep 17 00:00:00 2001
From: cui-gaoleng <562344211@qq.com>
Date: Fri, 8 Nov 2024 00:48:41 +0800
Subject: [PATCH] =?UTF-8?q?=E8=BF=9B=E5=BA=A6=E6=9D=A1=E9=83=A8=E5=88=86?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../progresstree/ProgressTreeDelegate.cpp | 338 ++++++++++++------
.../progresstree/ProgressTreeDelegate.h | 62 ++--
.../progresstree/ProgressTreeView.cpp | 142 ++++----
src/calamares/progresstree/ProgressTreeView.h | 80 +++--
5 files changed, 375 insertions(+), 250 deletions(-)
diff --git a/src/calamares/progresstree/ProgressTreeDelegate.cpp b/src/calamares/progresstree/ProgressTreeDelegate.cpp
index df513f2..6d5f865 100644
--- a/src/calamares/progresstree/ProgressTreeDelegate.cpp
+++ b/src/calamares/progresstree/ProgressTreeDelegate.cpp
@@ -1,119 +1,219 @@
-/* === This file is part of Calamares - <https://calamares.io> ===
- *
- * SPDX-FileCopyrightText: 2014-2015 Teo Mrnjavac <teo@kde.org>
- * SPDX-FileCopyrightText: 2017 Adriaan de Groot <groot@kde.org>
- * SPDX-License-Identifier: GPL-3.0-or-later
- *
- * Calamares is Free Software: see the License-Identifier above.
- *
- */
-
-#include "ProgressTreeDelegate.h"
-
-#include "Branding.h"
-#include "CalamaresApplication.h"
-#include "CalamaresWindow.h"
-#include "ViewManager.h"
-#include "utils/Gui.h"
-
-#include <QPainter>
-
-static constexpr int const item_margin = 8;
-static inline int
-item_fontsize()
-{
- return Calamares::defaultFontSize() + 4;
-}
-
-static void
-paintViewStep( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index )
-{
- QRect textRect = option.rect.adjusted( item_margin, item_margin, -item_margin, -item_margin );
- QFont font = qApp->font();
- font.setPointSize( item_fontsize() );
- font.setBold( false );
- painter->setFont( font );
-
- if ( index.row() == index.data( Calamares::ViewManager::ProgressTreeItemCurrentIndex ).toInt() )
- {
- painter->setPen( Calamares::Branding::instance()->styleString( Calamares::Branding::SidebarTextCurrent ) );
- QString textHighlight
- = Calamares::Branding::instance()->styleString( Calamares::Branding::SidebarBackgroundCurrent );
- if ( textHighlight.isEmpty() )
- {
- painter->setBrush( CalamaresApplication::instance()->mainWindow()->palette().window() );
- }
- else
- {
- painter->setBrush( QColor( textHighlight ) );
- }
- }
-
- // Draw the text at least once. If it doesn't fit, then shrink the font
- // being used by 1 pt on each iteration, up to a maximum of maximumShrink
- // times. On each loop, we'll have to blank out the rectangle again, so this
- // is an expensive (in terms of drawing operations) thing to do.
- //
- // (The loop uses <= because the counter is incremented at the start).
- static constexpr int const maximumShrink = 4;
- int shrinkSteps = 0;
- do
- {
- painter->fillRect( option.rect, painter->brush().color() );
- shrinkSteps++;
-
- QRectF boundingBox;
- painter->drawText(
- textRect, Qt::AlignHCenter | Qt::AlignVCenter | Qt::TextSingleLine, index.data().toString(), &boundingBox );
-
- // The extra check here is to avoid the changing-font-size if we're not going to use
- // it in the next iteration of the loop anyway.
- if ( ( shrinkSteps <= maximumShrink ) && ( boundingBox.width() > textRect.width() ) )
- {
- font.setPointSize( item_fontsize() - shrinkSteps );
- painter->setFont( font );
- }
- else
- {
- break; // It fits
- }
- } while ( shrinkSteps <= maximumShrink );
-}
-
-QSize
-ProgressTreeDelegate::sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const
-{
- if ( !index.isValid() )
- {
- return option.rect.size();
- }
-
- QFont font = qApp->font();
-
- font.setPointSize( item_fontsize() );
- QFontMetrics fm( font );
- int height = fm.height();
-
- height += 2 * item_margin;
-
- return QSize( option.rect.width(), height );
-}
-
-void
-ProgressTreeDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const
-{
- QStyleOptionViewItem opt = option;
-
- painter->save();
-
- initStyleOption( &opt, index );
- opt.text.clear();
-
- painter->setBrush(
- QColor( Calamares::Branding::instance()->styleString( Calamares::Branding::SidebarBackground ) ) );
- painter->setPen( QColor( Calamares::Branding::instance()->styleString( Calamares::Branding::SidebarText ) ) );
-
- paintViewStep( painter, opt, index );
-
- painter->restore();
-}
+/* === This file is part of Calamares - <https://calamares.io> ===
+ *
+ * SPDX-FileCopyrightText: 2014-2015 Teo Mrnjavac <teo@kde.org>
+ * SPDX-FileCopyrightText: 2017 Adriaan de Groot <groot@kde.org>
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ *
+ * Calamares is Free Software: see the License-Identifier above.
+ *
+ */
+
+#include "ProgressTreeDelegate.h"
+
+#include "Branding.h"
+#include "CalamaresApplication.h"
+#include "CalamaresWindow.h"
+#include "ViewManager.h"
+#include "utils/Gui.h"
+#include "utils/Logger.h"
+
+#include <QPainter>
+#include <QLocale>
+static constexpr int const item_margin = 8;
+static inline int
+item_fontsize()
+{
+ return Calamares::defaultFontSize();
+}
+static bool contains(const std::vector<QString>& vec,const QString& value){
+ for(const QString& v : vec){
+ if(v==value){
+ return true;
+ }
+ }
+ return false;
+}
+static QString getTypeOfStep(const QString& stepString){
+ std::vector<QString> baseSetting1 = {"Location","Keyboard"};
+ std::vector<QString> userSetting1 = {"Users","Packages"};
+ std::vector<QString> installSteps1 = {"Partitions","Summary","Install","Finish"};
+ std::vector<QString> baseSetting2 = {"位置","键盘"};
+ std::vector<QString> userSetting2 = {"用户","桌面"};
+ std::vector<QString> installSteps2 = {"分区","摘要","安装","结束"};
+ std::vector<QString> baseSetting3 = {"位置", "鍵盤"};
+ std::vector<QString> userSetting3 = {"使用者", "軟體包"};
+ std::vector<QString> installSteps3 = {"分割區", "總覽", "安裝", "完成"};
+ // 获取当前系统的语言设置
+ QLocale locale;
+ QLocale::Language lang = locale.language();
+
+ // 将语言枚举值转换为字符串
+ QString languageString = QLocale::languageToString(lang);
+ QLocale::Country country = locale.country();
+
+ // 将地区枚举值转换为字符串
+ QString countryString = QLocale::countryToString(country);
+ // 输出当前语言
+ cDebug() << "-------------------------------------------当前系统语言:" << languageString;
+ cDebug() << "-------------------------------------------当前系统地区:" << countryString;
+ if(contains(baseSetting1,stepString)){
+ return "BaseSetting";
+ }
+ if(contains(userSetting1,stepString)){
+ return "UserSetting";
+ }
+ if(contains(installSteps1,stepString)){
+ return "InstallSetting";
+ }
+ if(contains(baseSetting2,stepString) && countryString=="China"){
+ return "基础设置";
+ }
+ if(contains(userSetting2,stepString) && countryString=="China"){
+ return "用户设置";
+ }
+ if(contains(installSteps2,stepString) && countryString=="China"){
+ return "安装设置";
+ }
+ if (contains(baseSetting3, stepString) && countryString=="Taiwan") {
+ return "基礎設定";
+ }
+ if (contains(userSetting3, stepString) && countryString=="Taiwan"){
+ return "使用者設定";
+ }
+ if (contains(installSteps3, stepString) && countryString=="Taiwan") {
+ return "安裝設定";
+ }
+ return 0;
+}
+static int getTypeOfStep(int val){
+ if(val<=1){
+ return 1;
+ }
+ else if(val<=3){
+ return 2;
+ }
+ else if(val<=8){
+ return 3;
+ }
+ else{
+ return 0;
+ }
+}
+static bool isVisable(const QString& stepString){
+ std::vector<QString> installSteps = {"鍵盤", "軟體包", "總覽", "安裝", "完成",
+ "Keyboard","Packages","Summary","Install","Finish",
+ "键盘","桌面","摘要","安装","结束"};
+ return !contains(installSteps, stepString);
+}
+static void
+paintViewStep( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index )
+{
+ QRect textRect = option.rect.adjusted( item_margin, item_margin, -item_margin, -item_margin );
+ QFont font = qApp->font();
+ font.setPointSize( item_fontsize() );
+ font.setBold( false );
+ painter->setFont( font );
+
+ int CurrentTypeOfStep = getTypeOfStep(index.data( Calamares::ViewManager::ProgressTreeItemCurrentIndex ).toInt());
+ int TypeOfStep = getTypeOfStep(index.row());
+ if ( CurrentTypeOfStep == TypeOfStep )
+ {
+ painter->setPen( Calamares::Branding::instance()->styleString( Calamares::Branding::SidebarTextCurrent ) );
+ QString textHighlight
+ = Calamares::Branding::instance()->styleString( Calamares::Branding::SidebarBackgroundCurrent );
+ if ( textHighlight.isEmpty() )
+ {
+ painter->setBrush( CalamaresApplication::instance()->mainWindow()->palette().window() );
+ }
+ else
+ {
+ painter->setBrush( QColor( textHighlight ) );
+ }
+ }
+
+ // Draw the text at least once. If it doesn't fit, then shrink the font
+ // being used by 1 pt on each iteration, up to a maximum of maximumShrink
+ // times. On each loop, we'll have to blank out the rectangle again, so this
+ // is an expensive (in terms of drawing operations) thing to do.
+ //
+ // (The loop uses <= because the counter is incremented at the start).
+ static constexpr int const maximumShrink = 4;
+ int shrinkSteps = 0;
+ do
+ {
+
+ shrinkSteps++;
+
+ QRectF boundingBox;
+ cDebug() << "index.data().toString()" << index.data().toString();
+ QString text;
+ if(index.data().toString()=="欢迎" || index.data().toString()=="Welcome"||!isVisable(index.data().toString())){
+ text = "";
+ }else{
+ text = getTypeOfStep(index.data().toString());
+ painter->fillRect( option.rect, painter->brush().color() );
+ }
+ painter->drawText(
+ textRect, Qt::AlignHCenter | Qt::AlignVCenter | Qt::TextSingleLine, text, &boundingBox );
+
+ // The extra check here is to avoid the changing-font-size if we're not going to use
+ // it in the next iteration of the loop anyway.
+ if ( ( shrinkSteps <= maximumShrink ) && ( boundingBox.width() > textRect.width() ) )
+ {
+ font.setPointSize( item_fontsize() );
+ painter->setFont( font );
+ }
+ else
+ {
+ break; // It fits
+ }
+ } while ( shrinkSteps <= maximumShrink );
+}
+
+QSize
+ProgressTreeDelegate::sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const
+{
+ if ( !index.isValid() )
+ {
+ return option.rect.size();
+ }
+
+ QFont font = qApp->font();
+ cDebug() << "ProgressTreeDelegate::sizeHint";
+
+ font.setPointSize( item_fontsize() );
+ QFontMetrics fm( font );
+ int height = fm.height();
+ height += 2 * item_margin;
+ if(index.data().toString()=="欢迎" || index.data().toString()=="Welcome"||!isVisable(index.data().toString())){
+ return QSize( 0, 0 );
+ }else{
+ return QSize( (Calamares::windowMinimumWidth*0.9)/3, height*2 );
+ }
+// return QSize( option.rect.width(), height );
+
+}
+
+void
+ProgressTreeDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const
+{
+ cDebug() << "ProgressTreeDelegate::paint----------";
+ QStyleOptionViewItem opt = option;
+
+ painter->save();
+
+ initStyleOption( &opt, index );
+ opt.text.clear();
+
+ painter->setBrush(
+ QColor( Calamares::Branding::instance()->styleString( Calamares::Branding::SidebarBackground ) ) );
+ painter->setPen( QColor( Calamares::Branding::instance()->styleString( Calamares::Branding::SidebarText ) ) );
+ if(index.data().toString()=="欢迎" || index.data().toString()=="Welcome"){
+ cDebug() << "ProgressTreeDelegate::欢迎Welcome--------Nopaint----------";
+ }else{
+ paintViewStep( painter, opt, index );
+ }
+ //paintViewStep( painter, opt, index );
+
+ painter->restore();
+}
diff --git a/src/calamares/progresstree/ProgressTreeDelegate.h b/src/calamares/progresstree/ProgressTreeDelegate.h
index d5a5abc..af4fef9 100644
--- a/src/calamares/progresstree/ProgressTreeDelegate.h
+++ b/src/calamares/progresstree/ProgressTreeDelegate.h
@@ -1,31 +1,31 @@
-/* === This file is part of Calamares - <https://calamares.io> ===
- *
- * SPDX-FileCopyrightText: 2014-2015 Teo Mrnjavac <teo@kde.org>
- * SPDX-FileCopyrightText: 2019 Adriaan de Groot <groot@kde.org>
- * SPDX-License-Identifier: GPL-3.0-or-later
- *
- * Calamares is Free Software: see the License-Identifier above.
- *
- */
-
-#ifndef PROGRESSTREEDELEGATE_H
-#define PROGRESSTREEDELEGATE_H
-
-#include <QStyledItemDelegate>
-
-/**
- * @brief The ProgressTreeDelegate class customizes the look and feel of the
- * ProgressTreeView elements.
- * @see ProgressTreeView
- */
-class ProgressTreeDelegate : public QStyledItemDelegate
-{
-public:
- using QStyledItemDelegate::QStyledItemDelegate;
-
-protected:
- QSize sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const override;
- void paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const override;
-};
-
-#endif // PROGRESSTREEDELEGATE_H
+/* === This file is part of Calamares - <https://calamares.io> ===
+ *
+ * SPDX-FileCopyrightText: 2014-2015 Teo Mrnjavac <teo@kde.org>
+ * SPDX-FileCopyrightText: 2019 Adriaan de Groot <groot@kde.org>
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ *
+ * Calamares is Free Software: see the License-Identifier above.
+ *
+ */
+
+#ifndef PROGRESSTREEDELEGATE_H
+#define PROGRESSTREEDELEGATE_H
+
+#include <QStyledItemDelegate>
+
+/**
+ * @brief The ProgressTreeDelegate class customizes the look and feel of the
+ * ProgressTreeView elements.
+ * @see ProgressTreeView
+ */
+class ProgressTreeDelegate : public QStyledItemDelegate
+{
+public:
+ using QStyledItemDelegate::QStyledItemDelegate;
+
+protected:
+ QSize sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const override;
+ void paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const override;
+};
+
+#endif // PROGRESSTREEDELEGATE_H
diff --git a/src/calamares/progresstree/ProgressTreeView.cpp b/src/calamares/progresstree/ProgressTreeView.cpp
index 9d49ea2..29ee7ee 100644
--- a/src/calamares/progresstree/ProgressTreeView.cpp
+++ b/src/calamares/progresstree/ProgressTreeView.cpp
@@ -1,61 +1,81 @@
-/* === This file is part of Calamares - <https://calamares.io> ===
- *
- * SPDX-FileCopyrightText: 2014 Teo Mrnjavac <teo@kde.org>
- * SPDX-License-Identifier: GPL-3.0-or-later
- *
- * Calamares is Free Software: see the License-Identifier above.
- *
- */
-
-#include "ProgressTreeView.h"
-
-#include "ProgressTreeDelegate.h"
-
-#include "Branding.h"
-#include "ViewManager.h"
-
-ProgressTreeView::ProgressTreeView( QWidget* parent )
- : QListView( parent )
-{
- this->setObjectName( "sidebarMenuApp" );
- setFrameShape( QFrame::NoFrame );
- setContentsMargins( 0, 0, 0, 0 );
-
- setSelectionMode( QAbstractItemView::NoSelection );
- setDragDropMode( QAbstractItemView::NoDragDrop );
- setAcceptDrops( false );
-
- setItemDelegate( new ProgressTreeDelegate( this ) );
-
- QPalette plt = palette();
- plt.setColor( QPalette::Base,
- Calamares::Branding::instance()->styleString( Calamares::Branding::SidebarBackground ) );
- setPalette( plt );
-}
-
-
-ProgressTreeView::~ProgressTreeView() {}
-
-
-void
-ProgressTreeView::setModel( QAbstractItemModel* model )
-{
- if ( ProgressTreeView::model() )
- {
- return;
- }
-
- QListView::setModel( model );
-
- connect( Calamares::ViewManager::instance(),
- &Calamares::ViewManager::currentStepChanged,
- this,
- &ProgressTreeView::update,
- Qt::UniqueConnection );
-}
-
-void
-ProgressTreeView::update()
-{
- viewport()->update();
-}
+/* === This file is part of Calamares - <https://calamares.io> ===
+ *
+ * SPDX-FileCopyrightText: 2014 Teo Mrnjavac <teo@kde.org>
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ *
+ * Calamares is Free Software: see the License-Identifier above.
+ *
+ */
+
+#include "ProgressTreeView.h"
+
+#include "ProgressTreeDelegate.h"
+
+#include "Branding.h"
+#include "ViewManager.h"
+#include "utils/Logger.h"
+
+ProgressTreeView::ProgressTreeView( QWidget* parent )
+ : QListView( parent )
+{
+ this->setObjectName( "sidebarMenuApp" );
+ setFrameShape( QFrame::NoFrame );
+ setContentsMargins( 0, 0, 0, 0 );
+
+ setFlow(QListView::LeftToRight);//
+ setSelectionMode( QAbstractItemView::NoSelection );
+ setDragDropMode( QAbstractItemView::NoDragDrop );
+ setAcceptDrops( false );
+// setVisible( false);
+
+ setItemDelegate( new ProgressTreeDelegate( this ) );
+
+ QPalette plt = palette();
+ plt.setColor( QPalette::Base,
+ Calamares::Branding::instance()->styleString( Calamares::Branding::SidebarBackground ) );
+ setPalette( plt );
+// connect(parent, SIGNAL(currentStepChanged(int)), this, SLOT(updateVisibility(int)));
+ connect( Calamares::ViewManager::instance(),
+ &Calamares::ViewManager::currentStepChanged,
+ this,
+ &ProgressTreeView::updateVisibility,
+ Qt::UniqueConnection );
+// connect(viewManager, &ViewManager::currentStepChanged, this, &ProgressTreeView::updateVisibility);
+}
+
+
+ProgressTreeView::~ProgressTreeView() {}
+
+
+
+void
+ProgressTreeView::setModel( QAbstractItemModel* model )
+{
+ if ( ProgressTreeView::model() )
+ {
+ return;
+ }
+
+ QListView::setModel( model );
+
+ connect( Calamares::ViewManager::instance(),
+ &Calamares::ViewManager::currentStepChanged,
+ this,
+ &ProgressTreeView::update,
+ Qt::UniqueConnection );
+}
+
+void
+ProgressTreeView::update()
+{
+ cDebug() << "update ---------------------";
+ viewport()->update();
+}
+
+void
+ProgressTreeView::updateVisibility(int currentStep)
+{
+ cDebug() << "int currentStep ------------------ " << currentStep;
+ // 在第一个步骤隐藏,其他步骤显示
+ this->setVisible(currentStep > 0);
+}
diff --git a/src/calamares/progresstree/ProgressTreeView.h b/src/calamares/progresstree/ProgressTreeView.h
index d845cc7..b02b9ce 100644
--- a/src/calamares/progresstree/ProgressTreeView.h
+++ b/src/calamares/progresstree/ProgressTreeView.h
@@ -1,39 +1,41 @@
-/* === This file is part of Calamares - <https://calamares.io> ===
- *
- * SPDX-FileCopyrightText: 2014 Teo Mrnjavac <teo@kde.org>
- * SPDX-FileCopyrightText: 2017 Adriaan de Groot <groot@kde.org>
- * SPDX-License-Identifier: GPL-3.0-or-later
- *
- * Calamares is Free Software: see the License-Identifier above.
- *
- */
-
-#ifndef PROGRESSTREEVIEW_H
-#define PROGRESSTREEVIEW_H
-
-#include <QListView>
-
-/**
- * @brief Displays progress through the list of (visible) steps
- *
- * The ProgressTreeView class is a modified QListView which displays the
- * available view steps and the user's progress through them.
- * Since Calamares doesn't support "sub steps", it isn't really a tree.
- */
-class ProgressTreeView : public QListView
-{
- Q_OBJECT
-public:
- explicit ProgressTreeView( QWidget* parent = nullptr );
- ~ProgressTreeView() override;
-
- /**
- * @brief setModel assigns a model to this view.
- */
- void setModel( QAbstractItemModel* model ) override;
-
-public Q_SLOTS:
- void update();
-};
-
-#endif // PROGRESSTREEVIEW_H
+/* === This file is part of Calamares - <https://calamares.io> ===
+ *
+ * SPDX-FileCopyrightText: 2014 Teo Mrnjavac <teo@kde.org>
+ * SPDX-FileCopyrightText: 2017 Adriaan de Groot <groot@kde.org>
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ *
+ * Calamares is Free Software: see the License-Identifier above.
+ *
+ */
+
+#ifndef PROGRESSTREEVIEW_H
+#define PROGRESSTREEVIEW_H
+
+#include <QListView>
+#include "utils/Logger.h"
+
+/**
+ * @brief Displays progress through the list of (visible) steps
+ *
+ * The ProgressTreeView class is a modified QListView which displays the
+ * available view steps and the user's progress through them.
+ * Since Calamares doesn't support "sub steps", it isn't really a tree.
+ */
+class ProgressTreeView : public QListView
+{
+ Q_OBJECT
+public:
+ explicit ProgressTreeView( QWidget* parent = nullptr );
+ ~ProgressTreeView() override;
+
+ /**
+ * @brief setModel assigns a model to this view.
+ */
+ void setModel( QAbstractItemModel* model ) override;
+
+public Q_SLOTS:
+ void update();
+ void updateVisibility(int currentStep);
+};
+
+#endif // PROGRESSTREEVIEW_H
--
2.43.0