"Fossies" - the Fresh Open Source Software Archive

Member "cutter-1.10.3/src/plugins/sample-cpp/CutterSamplePlugin.cpp" (8 May 2020, 2146 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 "CutterSamplePlugin.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 <QLabel>
    2 #include <QHBoxLayout>
    3 #include <QPushButton>
    4 #include <QAction>
    5 
    6 #include "CutterSamplePlugin.h"
    7 #include "common/TempConfig.h"
    8 #include "common/Configuration.h"
    9 #include "MainWindow.h"
   10 
   11 void CutterSamplePlugin::setupPlugin()
   12 {
   13 }
   14 
   15 void CutterSamplePlugin::setupInterface(MainWindow *main)
   16 {
   17     QAction *action = new QAction("Sample C++ Plugin", main);
   18     action->setCheckable(true);
   19     CutterSamplePluginWidget *widget = new CutterSamplePluginWidget(main, action);
   20     main->addPluginDockWidget(widget, action);
   21 }
   22 
   23 CutterSamplePluginWidget::CutterSamplePluginWidget(MainWindow *main, QAction *action) :
   24     CutterDockWidget(main, action)
   25 {
   26     this->setObjectName("CutterSamplePluginWidget");
   27     this->setWindowTitle("Sample C++ Plugin");
   28     QWidget *content = new QWidget();
   29     this->setWidget(content);
   30 
   31     QVBoxLayout *layout = new QVBoxLayout(content);
   32     content->setLayout(layout);
   33     text = new QLabel(content);
   34     text->setFont(Config()->getFont());
   35     text->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
   36     layout->addWidget(text);
   37 
   38     QPushButton *button = new QPushButton(content);
   39     button->setText("Want a fortune?");
   40     button->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
   41     button->setMaximumHeight(50);
   42     button->setMaximumWidth(200);
   43     layout->addWidget(button);
   44     layout->setAlignment(button, Qt::AlignHCenter);
   45 
   46     connect(Core(), &CutterCore::seekChanged, this, &CutterSamplePluginWidget::on_seekChanged);
   47     connect(button, &QPushButton::clicked, this, &CutterSamplePluginWidget::on_buttonClicked);
   48 }
   49 
   50 void CutterSamplePluginWidget::on_seekChanged(RVA addr)
   51 {
   52     Q_UNUSED(addr);
   53     QString res;
   54     {
   55         TempConfig tempConfig;
   56         tempConfig.set("scr.color", 0);
   57         res = Core()->cmd("?E `pi 1`");
   58     }
   59     text->setText(res);
   60 }
   61 
   62 void CutterSamplePluginWidget::on_buttonClicked()
   63 {
   64     QString fortune = Core()->cmd("fo").replace("\n", "");
   65     // cmdRaw can be used to execute single raw commands
   66     // this is especially good for user-controlled input
   67     QString res = Core()->cmdRaw("?E " + fortune);
   68     text->setText(res);
   69 }