From 65a668943a4a7059c9486e716e1c6dbb50f448c0 Mon Sep 17 00:00:00 2001 From: karliss Date: Sun, 19 Jul 2020 22:00:05 +0300 Subject: [PATCH] Reorganize R2GraphWidget UI (#2298) * Reorganize R2GraphWidget UI. --- src/core/MainWindow.cpp | 5 ++++ src/widgets/CutterDockWidget.cpp | 8 ++++- src/widgets/CutterDockWidget.h | 7 +++++ src/widgets/R2GraphWidget.cpp | 39 +++++++++++++++++------- src/widgets/R2GraphWidget.ui | 51 +++++++++++++++++++++++++------- 5 files changed, 89 insertions(+), 21 deletions(-) diff --git a/src/core/MainWindow.cpp b/src/core/MainWindow.cpp index 9213f358..a7b04dd6 100644 --- a/src/core/MainWindow.cpp +++ b/src/core/MainWindow.cpp @@ -1351,6 +1351,7 @@ void MainWindow::setViewLayout(const CutterLayout &layout) dock->deserializeViewProperties({}); // call with empty properties to reset the widget newDocks.push_back(dock); } + dock->ignoreVisibilityStatus(true); } if (!isDefault) { @@ -1373,6 +1374,10 @@ void MainWindow::setViewLayout(const CutterLayout &layout) showZenDocks(); } } + + for (auto dock : dockWidgets) { + dock->ignoreVisibilityStatus(false); + } } void MainWindow::loadLayouts(QSettings &settings) diff --git a/src/widgets/CutterDockWidget.cpp b/src/widgets/CutterDockWidget.cpp index a0559777..e91df442 100644 --- a/src/widgets/CutterDockWidget.cpp +++ b/src/widgets/CutterDockWidget.cpp @@ -43,6 +43,12 @@ void CutterDockWidget::deserializeViewProperties(const QVariantMap &) { } +void CutterDockWidget::ignoreVisibilityStatus(bool ignore) +{ + this->ignoreVisibility = ignore; + updateIsVisibleToUser(); +} + void CutterDockWidget::toggleDockWidget(bool show) { if (!show) { @@ -61,7 +67,7 @@ QWidget *CutterDockWidget::widgetToFocusOnRaise() void CutterDockWidget::updateIsVisibleToUser() { // Check if the user can actually see the widget. - bool visibleToUser = isVisible() && !visibleRegion().isEmpty(); + bool visibleToUser = isVisible() && !visibleRegion().isEmpty() && !ignoreVisibility; if (visibleToUser == isVisibleToUserCurrent) { return; } diff --git a/src/widgets/CutterDockWidget.h b/src/widgets/CutterDockWidget.h index 910046da..652b4946 100644 --- a/src/widgets/CutterDockWidget.h +++ b/src/widgets/CutterDockWidget.h @@ -86,6 +86,12 @@ public: * @see CutterDockWidget#serializeViewProprties */ virtual void deserializeViewProperties(const QVariantMap &properties); + /** + * @brief Ignore visibility status. + * Useful for temporary ignoring visibility changes while this information is unreliable. + * @param ignored - set to true for enabling ignoring mode + */ + void ignoreVisibilityStatus(bool ignored); signals: void becameVisibleToUser(); void closed(); @@ -105,6 +111,7 @@ private: bool isTransient = false; bool isVisibleToUserCurrent = false; + bool ignoreVisibility = false; void updateIsVisibleToUser(); }; diff --git a/src/widgets/R2GraphWidget.cpp b/src/widgets/R2GraphWidget.cpp index 09fcd557..8cb3d090 100644 --- a/src/widgets/R2GraphWidget.cpp +++ b/src/widgets/R2GraphWidget.cpp @@ -19,21 +19,36 @@ R2GraphWidget::R2GraphWidget(MainWindow *main) QChar commandChar; QString label; } types[] = { - {'a', tr("aga - Data reference graph")}, - {'A', tr("agA - Global data references graph")}, + {'a', tr("Data reference graph (aga)")}, + {'A', tr("Global data references graph (agA)")}, // {'c', tr("c - Function callgraph")}, // {'C', tr("C - Global callgraph")}, // {'f', tr("f - Basic blocks function graph")}, - {'i', tr("agi - Imports graph")}, - {'r', tr("agr - References graph")}, - {'R', tr("agR - Global references graph")}, - {'x', tr("agx - Cross references graph")}, - {'g', tr("agg - Custom graph")}, + {'i', tr("Imports graph (agi)")}, + {'r', tr("References graph (agr)")}, + {'R', tr("Global references graph (agR)")}, + {'x', tr("Cross references graph (agx)")}, + {'g', tr("Custom graph (agg)")}, + {' ', tr("User command")}, }; for (auto &graphType : types) { - ui->graphType->addItem(graphType.label, graphType.commandChar); + if (graphType.commandChar != ' ') { + ui->graphType->addItem(graphType.label, graphType.commandChar); + } else { + ui->graphType->addItem(graphType.label, QVariant()); + } + } - connect(ui->graphType, &QComboBox::currentTextChanged, this, &R2GraphWidget::typeChanged); + connect(ui->graphType, &QComboBox::currentIndexChanged, this, &R2GraphWidget::typeChanged); + connect(ui->customCommand, &QLineEdit::textEdited, this, [this](){ + graphView->setGraphCommand(ui->customCommand->text()); + }); + connect(ui->customCommand, &QLineEdit::returnPressed, this, [this](){ + graphView->setGraphCommand(ui->customCommand->text()); + graphView->refreshView(); + }); + ui->customCommand->hide(); + typeChanged(); } R2GraphWidget::~R2GraphWidget() @@ -44,10 +59,14 @@ void R2GraphWidget::typeChanged() { auto currentData = ui->graphType->currentData(); if (currentData.isNull()) { - graphView->setGraphCommand(ui->graphType->currentText()); + ui->customCommand->setVisible(true); + graphView->setGraphCommand(ui->customCommand->text()); + ui->customCommand->setFocus(); } else { + ui->customCommand->setVisible(false); auto command = QString("ag%1").arg(currentData.toChar()); graphView->setGraphCommand(command); + graphView->refreshView(); } } diff --git a/src/widgets/R2GraphWidget.ui b/src/widgets/R2GraphWidget.ui index 5a05bc5c..22745fd9 100644 --- a/src/widgets/R2GraphWidget.ui +++ b/src/widgets/R2GraphWidget.ui @@ -29,38 +29,69 @@ - - - - ag - - - - + 0 0 + false + + + + + + true + + + 1 + 0 + + + + ag... + - Refresh + + + + + :/img/icons/arrow_right.svg:/img/icons/arrow_right.svg + + + + Qt::Horizontal + + + QSizePolicy::MinimumExpanding + + + + 0 + 20 + + + + - + + +