diff --git a/lib/qcustomfilesystemmodel/qcustomfilesystemmodel.cpp b/lib/qcustomfilesystemmodel/qcustomfilesystemmodel.cpp index 01a283aa..8c3e0a1a 100644 --- a/lib/qcustomfilesystemmodel/qcustomfilesystemmodel.cpp +++ b/lib/qcustomfilesystemmodel/qcustomfilesystemmodel.cpp @@ -124,6 +124,7 @@ int QCustomFileSystemModel::rowCount(const QModelIndex &parent) const { } int QCustomFileSystemModel::columnCount(const QModelIndex &parent) const { + if(m_onlyName) return 1; if (parent.isValid() && indexValid(parent)) return static_cast(parent.internalPointer())->columnCount(); else @@ -137,6 +138,8 @@ QVariant QCustomFileSystemModel::data(const QModelIndex &index, int role) const return QVariant(); if (role != Qt::DisplayRole && role != Qt::DecorationRole) return QVariant(); + if(m_onlyName && role == Qt::DecorationRole) + return QVariant(); QCustomFileSystemItem *item = static_cast(index.internalPointer()); if(item->data().toString() == "") return QVariant(); @@ -259,6 +262,7 @@ QModelIndex QCustomFileSystemModel::setRootPath(const QString &path) { QCustomFileSystemItem *rootItem = new QCustomFileSystemItem(path); m_rootPath = path; QStringList rootEntries = pathEntryList(m_rootPath); + QList allItems; QList dirItems; QList fileItems; for (int i = 0; i < rootEntries.count(); ++i) { @@ -275,20 +279,34 @@ QModelIndex QCustomFileSystemModel::setRootPath(const QString &path) { if (isDir) { //QStringList childEntries = pathEntryList(childPath); //childItem->setSize(childEntries.count()); - dirItems.append(childItem); + if(m_DistinguishType) { + dirItems.append(childItem); + } else { + allItems.append(childItem); + } //add dummy item QCustomFileSystemItem *dummyItem = new QCustomFileSystemItem("", childItem); childItem->appendChild(dummyItem); } else { childItem->setSize(size); - fileItems.append(childItem); + if(m_DistinguishType) { + fileItems.append(childItem); + } else { + allItems.append(childItem); + } } } - foreach(QCustomFileSystemItem *item, dirItems) { - rootItem->appendChild(item); - } - foreach(QCustomFileSystemItem *item, fileItems) { - rootItem->appendChild(item); + if(m_DistinguishType) { + foreach(QCustomFileSystemItem *item, dirItems) { + rootItem->appendChild(item); + } + foreach(QCustomFileSystemItem *item, fileItems) { + rootItem->appendChild(item); + } + } else { + foreach(QCustomFileSystemItem *item, allItems) { + rootItem->appendChild(item); + } } QModelIndex index = createIndex(0, 0, rootItem); m_rootItem = rootItem; diff --git a/lib/qcustomfilesystemmodel/qcustomfilesystemmodel.h b/lib/qcustomfilesystemmodel/qcustomfilesystemmodel.h index 5c6aa0f1..7c32b9e4 100644 --- a/lib/qcustomfilesystemmodel/qcustomfilesystemmodel.h +++ b/lib/qcustomfilesystemmodel/qcustomfilesystemmodel.h @@ -84,6 +84,9 @@ class QCustomFileSystemModel : public QAbstractItemModel QString filePath(const QModelIndex &index); + void setOnlyName(bool onlyName) { m_onlyName = onlyName; } + void setDistinguishType(bool distinguishType) { m_DistinguishType = distinguishType; } + virtual QString separator() const = 0; virtual QStringList pathEntryList(const QString &path) = 0; virtual void pathInfo(QString path, bool &isDir, uint64_t &size, QDateTime &lastModified) = 0; @@ -91,6 +94,8 @@ class QCustomFileSystemModel : public QAbstractItemModel private: QString m_rootPath; QCustomFileSystemItem *m_rootItem = nullptr; + bool m_onlyName = false; + bool m_DistinguishType = true; }; class QNativeFileSystemModel : public QCustomFileSystemModel diff --git a/lib/qtermwidget/TerminalDisplay.cpp b/lib/qtermwidget/TerminalDisplay.cpp index b679bbdd..fa423968 100644 --- a/lib/qtermwidget/TerminalDisplay.cpp +++ b/lib/qtermwidget/TerminalDisplay.cpp @@ -98,7 +98,6 @@ const ColorEntry base_color_table[TABLE_COLORS] = // static bool TerminalDisplay::_antialiasText = true; -bool TerminalDisplay::HAVE_TRANSPARENCY = true; // we use this to force QPainter to display text in LTR mode // more information can be found in: http://unicode.org/reports/tr9/ diff --git a/lib/qtermwidget/TerminalDisplay.h b/lib/qtermwidget/TerminalDisplay.h index 9b7c587e..044e39b7 100644 --- a/lib/qtermwidget/TerminalDisplay.h +++ b/lib/qtermwidget/TerminalDisplay.h @@ -416,8 +416,6 @@ class TerminalDisplay : public QWidget /** Returns the terminal screen section which is displayed in this widget. See setScreenWindow() */ ScreenWindow* screenWindow() const; - static bool HAVE_TRANSPARENCY; - void setMotionAfterPasting(MotionAfterPasting action); int motionAfterPasting(); void setConfirmMultilinePaste(bool confirmMultilinePaste); @@ -928,12 +926,6 @@ private slots: QWidget *messageParentWidget = nullptr; bool _fix_quardCRT_issue33 = false; - -public: - static void setTransparencyEnabled(bool enable) - { - HAVE_TRANSPARENCY = enable; - } }; class AutoScrollHandler : public QObject diff --git a/src/globaloptions/globaloptionsadvancedwidget.ui b/src/globaloptions/globaloptionsadvancedwidget.ui index d2224f0b..2b7bab34 100644 --- a/src/globaloptions/globaloptionsadvancedwidget.ui +++ b/src/globaloptions/globaloptionsadvancedwidget.ui @@ -7,7 +7,7 @@ 0 0 449 - 368 + 397 diff --git a/src/globaloptions/globaloptionsappearancewidget.ui b/src/globaloptions/globaloptionsappearancewidget.ui index 10c8ff57..4de497eb 100644 --- a/src/globaloptions/globaloptionsappearancewidget.ui +++ b/src/globaloptions/globaloptionsappearancewidget.ui @@ -7,7 +7,7 @@ 0 0 550 - 501 + 528 @@ -675,14 +675,14 @@ 70 - Qt::Horizontal + Qt::Orientation::Horizontal - Qt::Vertical + Qt::Orientation::Vertical diff --git a/src/globaloptions/globaloptionsgeneralwidget.ui b/src/globaloptions/globaloptionsgeneralwidget.ui index bf6ff954..789c5906 100644 --- a/src/globaloptions/globaloptionsgeneralwidget.ui +++ b/src/globaloptions/globaloptionsgeneralwidget.ui @@ -7,7 +7,7 @@ 0 0 379 - 337 + 363 @@ -267,7 +267,7 @@ - Qt::Vertical + Qt::Orientation::Vertical diff --git a/src/globaloptions/globaloptionswindow.cpp b/src/globaloptions/globaloptionswindow.cpp index ac0bae32..3f55e430 100644 --- a/src/globaloptions/globaloptionswindow.cpp +++ b/src/globaloptions/globaloptionswindow.cpp @@ -18,7 +18,6 @@ * along with this program; if not, see . */ #include -#include #include #include #include @@ -46,6 +45,79 @@ #include "ui_globaloptionstransferwidget.h" #include "ui_globaloptionsadvancedwidget.h" +GlobalOptionsModel::GlobalOptionsModel(QObject *parent) + : QCustomFileSystemModel(parent) { +} + +GlobalOptionsModel::~GlobalOptionsModel() { +} + +QString GlobalOptionsModel::separator() const { + return "/"; +} + +GlobalOptionsModel::TreeNode GlobalOptionsModel::findNode(const QString &name, const TreeNode &fnode) { + foreach (const TreeNode &node, fnode.children) { + if(node.name == name) { + return node; + } + } + return TreeNode(); +}; + +QStringList GlobalOptionsModel::pathEntryList(const QString &path) { + QStringList files; + + if(path == "/") { + foreach (const TreeNode &node, rootInfo.children) { + files << node.name; + } + return files; + } else { + QStringList pathList = path.split(separator()); + TreeNode node = rootInfo; + for(int i = 1; i < pathList.size(); i++) { + node = findNode(pathList[i], node); + if(node.name.isEmpty()) { + return files; + } + } + foreach (const TreeNode &child, node.children) { + files << child.name; + } + } + + return files; +} + +void GlobalOptionsModel::pathInfo(QString path, bool &isDir, uint64_t &size, QDateTime &lastModified) { + isDir = false; + size = 0; + Q_UNUSED(lastModified); + + if(path == "/") { + size = rootInfo.children.size(); + if(size) + isDir = true; + } else { + QStringList pathList = path.split(separator()); + TreeNode node = rootInfo; + for(int i = 1; i < pathList.size(); i++) { + node = findNode(pathList[i], node); + if(node.name.isEmpty()) { + return; + } + } + size = node.children.size(); + if(size) + isDir = true; + } +} + +void GlobalOptionsModel::setTree(const TreeNode &tree) { + rootInfo = tree; +} + const QString GlobalOptionsWindow::defaultColorScheme = "QuardCRT"; const QString GlobalOptionsWindow::defaultColorSchemeBak = "QuardCRT Light"; @@ -61,10 +133,11 @@ GlobalOptionsWindow::GlobalOptionsWindow(QWidget *parent) : QSplitter *splitter = new QSplitter(Qt::Horizontal, this); splitter->setHandleWidth(1); ui->horizontalLayout->addWidget(splitter); - QTreeView *treeView = new QTreeView(this); + treeView = new QTreeView(this); treeView->setHeaderHidden(true); - model = new QStringListModel(treeView); - treeView->setModel(model); + model = new GlobalOptionsModel(treeView); + model->setOnlyName(true); + model->setDistinguishType(false); treeView->setEditTriggers(QAbstractItemView::NoEditTriggers); splitter->addWidget(treeView); QWidget *widget = new QWidget(this); @@ -88,9 +161,9 @@ GlobalOptionsWindow::GlobalOptionsWindow(QWidget *parent) : globalOptionsAdvancedWidget = new GlobalOptionsAdvancedWidget(widget); widget->layout()->addWidget(globalOptionsAdvancedWidget); - setActiveWidget(0); - + treeView->setModel(model); retranslateUi(); + setActiveWidget(globalOptionsGeneralWidget); GlobalSetting settings; globalOptionsAdvancedWidget->ui->lineEditConfigFile->setText(settings.fileName()); @@ -373,7 +446,17 @@ GlobalOptionsWindow::GlobalOptionsWindow(QWidget *parent) : connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &GlobalOptionsWindow::buttonBoxRejected); connect(treeView, &QTreeView::clicked, [&](const QModelIndex &index) { - setActiveWidget(index.row()); + QString filePath = model->filePath(index); + QStringList pathList = filePath.split(model->separator()); + GlobalOptionsModel::TreeNode node = rootInfo; + for(int i = 1; i < pathList.size(); i++) { + node = GlobalOptionsModel::findNode(pathList[i], node); + if(node.name.isEmpty()) { + setActiveWidget(nullptr); + return; + } + } + setActiveWidget(node.widget); }); } @@ -384,7 +467,17 @@ GlobalOptionsWindow::~GlobalOptionsWindow() void GlobalOptionsWindow::retranslateUi() { - model->setStringList(QStringList() << tr("General") << tr("Appearance") << tr("Terminal") << tr("Window") << tr("Transfer") << tr("Advanced")); + rootInfo.children.clear(); + GlobalOptionsModel::TreeNode generalNode(tr("General"),globalOptionsGeneralWidget); + GlobalOptionsModel::TreeNode appearance(tr("Appearance"),globalOptionsAppearanceWidget); + GlobalOptionsModel::TreeNode terminal(tr("Terminal"),globalOptionsTerminalWidget); + GlobalOptionsModel::TreeNode window(tr("Window"),globalOptionsWindowWidget); + GlobalOptionsModel::TreeNode transfer(tr("Transfer"),globalOptionsTransferWidget); + //transfer.children << GlobalOptionsModel::TreeNode(tr("Serial")) << GlobalOptionsModel::TreeNode("SSH"); + GlobalOptionsModel::TreeNode advanced(tr("Advanced"),globalOptionsAdvancedWidget); + rootInfo.children << generalNode << appearance << terminal << window << transfer << advanced; + model->setTree(rootInfo); + treeView->setRootIndex(model->setRootPath("/")); ui->retranslateUi(this); globalOptionsGeneralWidget->ui->retranslateUi(this); globalOptionsGeneralWidget->ui->retranslateUi(this); @@ -395,7 +488,7 @@ void GlobalOptionsWindow::retranslateUi() globalOptionsAdvancedWidget->ui->retranslateUi(this); } -void GlobalOptionsWindow::setActiveWidget(int index) +void GlobalOptionsWindow::setActiveWidget(QWidget *widget) { globalOptionsGeneralWidget->setVisible(false); globalOptionsAppearanceWidget->setVisible(false); @@ -404,26 +497,8 @@ void GlobalOptionsWindow::setActiveWidget(int index) globalOptionsTransferWidget->setVisible(false); globalOptionsAdvancedWidget->setVisible(false); - switch(index) { - case 0: - globalOptionsGeneralWidget->setVisible(true); - break; - case 1: - globalOptionsAppearanceWidget->setVisible(true); - break; - case 2: - globalOptionsTerminalWidget->setVisible(true); - break; - case 3: - globalOptionsWindowWidget->setVisible(true); - break; - case 4: - globalOptionsTransferWidget->setVisible(true); - break; - case 5: - globalOptionsAdvancedWidget->setVisible(true); - break; - } + if(widget) + widget->setVisible(true); } void GlobalOptionsWindow::setAvailableColorSchemes(QStringList colorSchemes) diff --git a/src/globaloptions/globaloptionswindow.h b/src/globaloptions/globaloptionswindow.h index ec0818fa..3b4d863c 100644 --- a/src/globaloptions/globaloptionswindow.h +++ b/src/globaloptions/globaloptionswindow.h @@ -23,6 +23,7 @@ #include #include #include +#include #include #include "globaloptionsgeneralwidget.h" #include "globaloptionsappearancewidget.h" @@ -31,11 +32,50 @@ #include "globaloptionstransferwidget.h" #include "globaloptionsadvancedwidget.h" #include "CharacterColor.h" +#include "qcustomfilesystemmodel.h" namespace Ui { class GlobalOptionsWindow; } +class GlobalOptionsModel : public QCustomFileSystemModel +{ + Q_OBJECT +public: + explicit GlobalOptionsModel(QObject *parent = 0); + ~GlobalOptionsModel(); + + QString separator() const override; + QStringList pathEntryList(const QString &path) override; + void pathInfo(QString path, bool &isDir, uint64_t &size, QDateTime &lastModified) override; + + class TreeNode { + public: + TreeNode(const QString &name = QString(), QWidget *widget = nullptr, const QList &children = QList()) + : name(name), widget(widget), children(children) {} + TreeNode(const TreeNode &node) { + name = node.name; + widget = node.widget; + children = node.children; + } + TreeNode& operator=(const TreeNode &node) { + if (this != &node) { + name = node.name; + widget = node.widget; + children = node.children; + } + return *this; + } + QString name; + QWidget *widget; + QList children; + }; + void setTree(const TreeNode &tree); + TreeNode rootInfo; + + static TreeNode findNode(const QString &name, const TreeNode &fnode); +}; + class GlobalOptionsWindow : public QDialog { Q_OBJECT @@ -89,7 +129,7 @@ class GlobalOptionsWindow : public QDialog const static QString defaultColorSchemeBak; private: - void setActiveWidget(int index); + void setActiveWidget(QWidget *widget); signals: void colorSchemeChanged(QString colorScheme); @@ -114,10 +154,12 @@ private slots: GlobalOptionsWindowWidget *globalOptionsWindowWidget; GlobalOptionsTransferWidget *globalOptionsTransferWidget; GlobalOptionsAdvancedWidget *globalOptionsAdvancedWidget; - QStringListModel *model; + QTreeView *treeView; + GlobalOptionsModel *model; QFont font; QString cursorColorStr; ColorEntry table[TABLE_COLORS]; + GlobalOptionsModel::TreeNode rootInfo; }; #endif //GLOBALOPTIONSWINDOW_H