From a38d77c9690ea8160b152cde36ad97545aecbc66 Mon Sep 17 00:00:00 2001 From: Kamay Date: Sun, 25 Jul 2021 08:33:51 +0200 Subject: [PATCH] Improved function widget (#2659) --- src/common/Configuration.cpp | 2 +- src/img/icons/function_dark.svg | 210 +++++++++++++ src/img/icons/function_entry_dark.svg | 326 ++++++++++++++++++++ src/img/icons/function_entry_light.svg | 326 ++++++++++++++++++++ src/img/icons/function_export_dark.svg | 305 +++++++++++++++++++ src/img/icons/function_export_light.svg | 305 +++++++++++++++++++ src/img/icons/function_import_dark.svg | 229 +++++++++++++++ src/img/icons/function_import_light.svg | 229 +++++++++++++++ src/img/icons/function_light.svg | 210 +++++++++++++ src/img/icons/function_main_dark.svg | 376 ++++++++++++++++++++++++ src/img/icons/function_main_light.svg | 376 ++++++++++++++++++++++++ src/img/icons/function_tlscb_dark.svg | 230 +++++++++++++++ src/img/icons/function_tlscb_light.svg | 230 +++++++++++++++ src/img/icons/import_light.svg | 53 ---- src/resources.qrc | 13 +- src/widgets/FunctionsWidget.cpp | 58 +++- src/widgets/FunctionsWidget.h | 7 + 17 files changed, 3420 insertions(+), 65 deletions(-) create mode 100644 src/img/icons/function_dark.svg create mode 100644 src/img/icons/function_entry_dark.svg create mode 100644 src/img/icons/function_entry_light.svg create mode 100644 src/img/icons/function_export_dark.svg create mode 100644 src/img/icons/function_export_light.svg create mode 100644 src/img/icons/function_import_dark.svg create mode 100644 src/img/icons/function_import_light.svg create mode 100644 src/img/icons/function_light.svg create mode 100644 src/img/icons/function_main_dark.svg create mode 100644 src/img/icons/function_main_light.svg create mode 100644 src/img/icons/function_tlscb_dark.svg create mode 100644 src/img/icons/function_tlscb_light.svg delete mode 100644 src/img/icons/import_light.svg diff --git a/src/common/Configuration.cpp b/src/common/Configuration.cpp index a5be951a..756c59d1 100644 --- a/src/common/Configuration.cpp +++ b/src/common/Configuration.cpp @@ -39,7 +39,7 @@ const QHash> Configuration::cutterOptionColor { "gui.item_invalid", { { DarkFlag, QColor(0x9b, 0x9b, 0x9b) }, { LightFlag, QColor(0x9b, 0x9b, 0x9b) } } }, { "gui.main", - { { DarkFlag, QColor(0x00, 0x80, 0x00) }, { LightFlag, QColor(0x00, 0x80, 0x00) } } }, + { { DarkFlag, QColor(0x21, 0xd8, 0x93) }, { LightFlag, QColor(0x00, 0x80, 0x00) } } }, { "gui.item_unsafe", { { DarkFlag, QColor(0xff, 0x81, 0x7b) }, { LightFlag, QColor(0xff, 0x81, 0x7b) } } }, { "gui.navbar.seek", diff --git a/src/img/icons/function_dark.svg b/src/img/icons/function_dark.svg new file mode 100644 index 00000000..8999d724 --- /dev/null +++ b/src/img/icons/function_dark.svg @@ -0,0 +1,210 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + diff --git a/src/img/icons/function_entry_dark.svg b/src/img/icons/function_entry_dark.svg new file mode 100644 index 00000000..3a0812af --- /dev/null +++ b/src/img/icons/function_entry_dark.svg @@ -0,0 +1,326 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + diff --git a/src/img/icons/function_entry_light.svg b/src/img/icons/function_entry_light.svg new file mode 100644 index 00000000..7cedcef4 --- /dev/null +++ b/src/img/icons/function_entry_light.svg @@ -0,0 +1,326 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + diff --git a/src/img/icons/function_export_dark.svg b/src/img/icons/function_export_dark.svg new file mode 100644 index 00000000..4401642d --- /dev/null +++ b/src/img/icons/function_export_dark.svg @@ -0,0 +1,305 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + diff --git a/src/img/icons/function_export_light.svg b/src/img/icons/function_export_light.svg new file mode 100644 index 00000000..0fa11e16 --- /dev/null +++ b/src/img/icons/function_export_light.svg @@ -0,0 +1,305 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + diff --git a/src/img/icons/function_import_dark.svg b/src/img/icons/function_import_dark.svg new file mode 100644 index 00000000..333eac02 --- /dev/null +++ b/src/img/icons/function_import_dark.svg @@ -0,0 +1,229 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + diff --git a/src/img/icons/function_import_light.svg b/src/img/icons/function_import_light.svg new file mode 100644 index 00000000..c8944d0f --- /dev/null +++ b/src/img/icons/function_import_light.svg @@ -0,0 +1,229 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + diff --git a/src/img/icons/function_light.svg b/src/img/icons/function_light.svg new file mode 100644 index 00000000..bd3fe353 --- /dev/null +++ b/src/img/icons/function_light.svg @@ -0,0 +1,210 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + diff --git a/src/img/icons/function_main_dark.svg b/src/img/icons/function_main_dark.svg new file mode 100644 index 00000000..494988e1 --- /dev/null +++ b/src/img/icons/function_main_dark.svg @@ -0,0 +1,376 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/img/icons/function_main_light.svg b/src/img/icons/function_main_light.svg new file mode 100644 index 00000000..7b37066a --- /dev/null +++ b/src/img/icons/function_main_light.svg @@ -0,0 +1,376 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/img/icons/function_tlscb_dark.svg b/src/img/icons/function_tlscb_dark.svg new file mode 100644 index 00000000..8e0751d7 --- /dev/null +++ b/src/img/icons/function_tlscb_dark.svg @@ -0,0 +1,230 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + diff --git a/src/img/icons/function_tlscb_light.svg b/src/img/icons/function_tlscb_light.svg new file mode 100644 index 00000000..b29ec12d --- /dev/null +++ b/src/img/icons/function_tlscb_light.svg @@ -0,0 +1,230 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + diff --git a/src/img/icons/import_light.svg b/src/img/icons/import_light.svg deleted file mode 100644 index ec2e4e8f..00000000 --- a/src/img/icons/import_light.svg +++ /dev/null @@ -1,53 +0,0 @@ - - - -image/svg+xml \ No newline at end of file diff --git a/src/resources.qrc b/src/resources.qrc index f7cc7b12..0f80520b 100644 --- a/src/resources.qrc +++ b/src/resources.qrc @@ -89,7 +89,18 @@ img/icons/transfer.svg img/icons/transfer_white.svg img/icons/spin_light.svg - img/icons/import_light.svg + img/icons/function_light.svg + img/icons/function_import_light.svg + img/icons/function_entry_light.svg + img/icons/function_export_light.svg + img/icons/function_tlscb_light.svg + img/icons/function_main_light.svg + img/icons/function_dark.svg + img/icons/function_import_dark.svg + img/icons/function_entry_dark.svg + img/icons/function_export_dark.svg + img/icons/function_tlscb_dark.svg + img/icons/function_main_dark.svg img/icons/home.svg fonts/Anonymous Pro.ttf fonts/Inconsolata-Regular.ttf diff --git a/src/widgets/FunctionsWidget.cpp b/src/widgets/FunctionsWidget.cpp index b04f6169..b0e72d6c 100644 --- a/src/widgets/FunctionsWidget.cpp +++ b/src/widgets/FunctionsWidget.cpp @@ -17,6 +17,8 @@ #include #include #include +#include +#include namespace { @@ -36,7 +38,13 @@ FunctionModel::FunctionModel(QList *functions, QSet *i highlightFont(highlight_font), defaultFont(default_font), nested(nested), - currentIndex(-1) + currentIndex(-1), + iconFuncImpDark(":/img/icons/function_import_dark.svg"), + iconFuncImpLight(":/img/icons/function_import_light.svg"), + iconFuncMainDark(":/img/icons/function_main_dark.svg"), + iconFuncMainLight(":/img/icons/function_main_light.svg"), + iconFuncDark(":/img/icons/function_dark.svg"), + iconFuncLight(":/img/icons/function_light.svg") { connect(Core(), &CutterCore::seekChanged, this, &FunctionModel::seekChanged); @@ -101,6 +109,8 @@ QVariant FunctionModel::data(const QModelIndex &index, int role) const int function_index; bool subnode; + bool is_dark; + if (index.internalId() != 0) { // sub-node function_index = index.parent().row(); subnode = true; @@ -151,6 +161,8 @@ QVariant FunctionModel::data(const QModelIndex &index, int role) const return function.name; case SizeColumn: return QString::number(function.linearSize); + case ImportColumn: + return functionIsImport(function.offset) ? tr("true") : tr("false"); case OffsetColumn: return RAddressString(function.offset); case NargsColumn: @@ -172,13 +184,37 @@ QVariant FunctionModel::data(const QModelIndex &index, int role) const } } - case Qt::DecorationRole: - if (importAddresses->contains(function.offset) - && (nested ? false : index.column() == ImportColumn)) { - const static QIcon importIcon(":/img/icons/import_light.svg"); - return importIcon; + case Qt::DecorationRole: { + + // Check if we aren't inside a tree view + if (nested && subnode) { + return QVariant(); } + + if (index.column() == NameColumn) { + is_dark = Config()->windowColorIsDark(); + + if (functionIsImport(function.offset)) { + if (is_dark) { + return iconFuncImpDark; + } + return iconFuncImpLight; + + } else if (functionIsMain(function.offset)) { + if (is_dark) { + return iconFuncMainDark; + } + return iconFuncMainLight; + } + + if (is_dark) { + return iconFuncDark; + } + return iconFuncLight; + } + return QVariant(); + } case Qt::FontRole: if (currentIndex == function_index) @@ -214,8 +250,8 @@ QVariant FunctionModel::data(const QModelIndex &index, int role) const QString("
") .arg(fnt.family()) - .arg(qMax(6, fnt.pointSize() - 1)); // slightly decrease font size, to keep - // more text in the same box + .arg(qMax(6, fnt.pointSize() - 1)); // slightly decrease font size, to + // keep more text in the same box if (!disasmPreview.isEmpty()) toolTipContent += tr("
Disassembly " @@ -233,10 +269,12 @@ QVariant FunctionModel::data(const QModelIndex &index, int role) const } case Qt::ForegroundRole: - if (functionIsImport(function.offset)) + if (functionIsImport(function.offset)) { return QVariant(ConfigColor("gui.imports")); - if (functionIsMain(function.offset)) + } else if (functionIsMain(function.offset)) { return QVariant(ConfigColor("gui.main")); + } + return QVariant(this->property("color")); case FunctionDescriptionRole: diff --git a/src/widgets/FunctionsWidget.h b/src/widgets/FunctionsWidget.h index 99ab7656..40cd89b6 100644 --- a/src/widgets/FunctionsWidget.h +++ b/src/widgets/FunctionsWidget.h @@ -28,6 +28,13 @@ private: int currentIndex; + QIcon iconFuncImpDark; + QIcon iconFuncImpLight; + QIcon iconFuncMainDark; + QIcon iconFuncMainLight; + QIcon iconFuncDark; + QIcon iconFuncLight; + bool functionIsImport(ut64 addr) const; bool functionIsMain(ut64 addr) const;