"Fossies" - the Fresh Open Source Software Archive

Member "cutter-1.10.3/src/widgets/GraphWidget.cpp" (8 May 2020, 3046 Bytes) of package /linux/privat/cutter-1.10.3.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "GraphWidget.cpp" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 1.10.2_vs_1.10.3.

    1 #include "core/MainWindow.h"
    2 #include "GraphWidget.h"
    3 #include "DisassemblerGraphView.h"
    4 #include "WidgetShortcuts.h"
    5 #include <QVBoxLayout>
    6 
    7 GraphWidget::GraphWidget(MainWindow *main, QAction *action) :
    8     MemoryDockWidget(MemoryWidgetType::Graph, main, action)
    9 {
   10     setObjectName(main
   11                   ? main->getUniqueObjectName(getWidgetType())
   12                   : getWidgetType());
   13 
   14     setAllowedAreas(Qt::AllDockWidgetAreas);
   15 
   16     auto *layoutWidget = new QWidget(this);
   17     setWidget(layoutWidget);
   18     auto *layout = new QVBoxLayout(layoutWidget);
   19     layout->setContentsMargins(0, 0, 0, 0);
   20     layoutWidget->setLayout(layout);
   21 
   22     header = new QLineEdit(this);
   23     header->setReadOnly(true);
   24     layout->addWidget(header);
   25 
   26     graphView = new DisassemblerGraphView(layoutWidget, seekable, main, {&syncAction});
   27     layout->addWidget(graphView);
   28 
   29     // Title needs to get set after graphView is defined
   30     updateWindowTitle();
   31 
   32     // getting the name of the class is implementation defined, and cannot be
   33     // used reliably across different compilers.
   34     //QShortcut *toggle_shortcut = new QShortcut(widgetShortcuts[typeid(this).name()], main);
   35     QShortcut *toggle_shortcut = new QShortcut(widgetShortcuts["GraphWidget"], main);
   36     connect(toggle_shortcut, &QShortcut::activated, this, [ = ]() {
   37             toggleDockWidget(true); 
   38     });
   39 
   40     connect(graphView, &DisassemblerGraphView::nameChanged, this, &MemoryDockWidget::updateWindowTitle);
   41 
   42     connect(this, &QDockWidget::visibilityChanged, this, [ = ](bool visibility) {
   43         main->toggleOverview(visibility, this);
   44         if (visibility) {
   45             graphView->onSeekChanged(Core()->getOffset());
   46         }
   47     });
   48 
   49     QAction *switchAction = new QAction(this);
   50     switchAction->setShortcut(Qt::Key_Space);
   51     switchAction->setShortcutContext(Qt::WidgetWithChildrenShortcut);
   52     addAction(switchAction);
   53     connect(switchAction, &QAction::triggered, this, [this] {
   54         mainWindow->showMemoryWidget(MemoryWidgetType::Disassembly);
   55     });
   56 
   57     connect(graphView, &DisassemblerGraphView::graphMoved, this, [ = ]() {
   58         main->toggleOverview(true, this);
   59     });
   60     connect(seekable, &CutterSeekable::seekableSeekChanged, this, &GraphWidget::prepareHeader);
   61     connect(Core(), &CutterCore::functionRenamed, this, &GraphWidget::prepareHeader);
   62     graphView->installEventFilter(this);
   63 }
   64 
   65 QWidget *GraphWidget::widgetToFocusOnRaise()
   66 {
   67     return graphView;
   68 }
   69 
   70 void GraphWidget::closeEvent(QCloseEvent *event)
   71 {
   72     CutterDockWidget::closeEvent(event);
   73     emit graphClosed();
   74 }
   75 
   76 QString GraphWidget::getWindowTitle() const
   77 {
   78     return graphView->windowTitle;
   79 }
   80 
   81 DisassemblerGraphView *GraphWidget::getGraphView() const
   82 {
   83     return graphView;
   84 }
   85 
   86 QString GraphWidget::getWidgetType()
   87 {
   88     return "Graph";
   89 }
   90 
   91 void GraphWidget::prepareHeader()
   92 {
   93     QString afcf = Core()->cmdRawAt("afcf", seekable->getOffset()).trimmed();
   94     if (afcf.isEmpty()) {
   95         header->hide();
   96         return;
   97     }
   98     header->show();
   99     header->setText(afcf);
  100 }
  101