示例#1
0
DbConsole::DbConsole(QWidget* parent) :
  QWidget( parent ),
  mQueryModel( 0 )
{
  ui.setupUi( this );

  ui.execButton->setIcon( KIcon( "application-x-executable" ) );
  connect( ui.execButton, SIGNAL(clicked()), SLOT(execClicked()) );

  ui.queryEdit->setFont( KGlobalSettings::fixedFont() );
  ui.errorView->setFont( KGlobalSettings::fixedFont() );
}
示例#2
0
//-----------------------------------------------------------------------------
void DebugScriptWindow::setupUI()
{
  // Testing setting up the UI programatically, as opposed to using QTCreator
  // and its generated XML.

  QWidget* dockWidgetContents = new QWidget();
  dockWidgetContents->setObjectName(QString::fromUtf8("DebugWindowContents"));
  this->setWidget(dockWidgetContents);

  mMainLayout = new QVBoxLayout(dockWidgetContents);
  mMainLayout->setSpacing(6);
  mMainLayout->setContentsMargins(9, 9, 9, 9);
  mMainLayout->setObjectName(QString::fromUtf8("verticalLayout"));

  // Script debug implementation.
  {
    QWidget* scriptTabContents = new QWidget();
    mMainLayout->addWidget(scriptTabContents);

    QHBoxLayout* scriptLayout = new QHBoxLayout(scriptTabContents);
    scriptTabContents->setLayout(scriptLayout);

    // Output / one line interaction
    {
      QWidget* outputContents = new QWidget();
      scriptLayout->addWidget(outputContents);

      QVBoxLayout* outputLayout = new QVBoxLayout();
      outputContents->setLayout(outputLayout);

      mListWidget = new QListWidget();
      outputLayout->addWidget(mListWidget);

      // Lower line edit and label.
      {
        QWidget* cont = new QWidget();
        cont->setMinimumHeight(0);
        outputLayout->addWidget(cont);

        QHBoxLayout* hboxLayout = new QHBoxLayout();
        cont->setLayout(hboxLayout);

        QLabel* lbl = new QLabel();
        lbl->setText(QString::fromUtf8("Command: "));
        lbl->setMinimumSize(QSize(0, 0));
        hboxLayout->addWidget(lbl);

        mScriptOneLineEdit = new QLineEdit();
        hboxLayout->addWidget(mScriptOneLineEdit);
        QObject::connect(mScriptOneLineEdit, SIGNAL(returnPressed()), this,
                         SLOT(oneLineEditOnReturnPressed()));
        QObject::connect(mScriptOneLineEdit, SIGNAL(textEdited(const QString&)),
                         this, SLOT(oneLineEditOnEdited(const QString&)));
      }
    }

    // Script interaction.
    {
      QWidget* editContents = new QWidget();
      scriptLayout->addWidget(editContents);

      QVBoxLayout* editLayout = new QVBoxLayout();
      editContents->setLayout(editLayout);

      mScriptTextEdit = new QTextEdit();
      QFont font("Monospace");
      font.setStyleHint(QFont::TypeWriter);
      mScriptTextEdit->setCurrentFont(font);
      editLayout->addWidget(mScriptTextEdit);

      // Combo box combined with execute button.
      {
        QWidget* comboExecContents = new QWidget();
        comboExecContents->setMinimumHeight(0);
        editLayout->addWidget(comboExecContents);

        QHBoxLayout* comboExecLayout = new QHBoxLayout();
        comboExecContents->setLayout(comboExecLayout);

        QLabel* lbl = new QLabel();
        lbl->setText(QString::fromUtf8("Examples: "));
        comboExecLayout->addWidget(lbl);

        mScriptExamplesBox = new QComboBox();
        comboExecLayout->addWidget(mScriptExamplesBox);
        QString emptyExample = QString::fromUtf8(" ");

        mScriptExamplesBox->addItem(QString::fromUtf8(" "),
                                    QVariant(emptyExample));

        QString regressionTesting = QString::fromUtf8(
            "-- Please modify the variables below to point to valid paths.\n"
            "local homeDir = os.getenv('HOME')\n"
            "regress_scriptDir = homeDir .. '/sci/imagevis3d/Tuvok/LuaScripting"
            "/Regression/iv3d'\n"
            "regress_c60Dir = homeDir .. '/sci/datasets/c60.uvf'\n"
            "regress_outputDir = homeDir .. '/sci/datasets/output'\n"
            "luaVerboseMode(true)\n\n"
            "-- Todo: Switch to LuaFileSystem -- cross platform\n"
            "for fname in dir(regress_scriptDir) do\n"
            "  if fname ~= '.' and fname ~= '..' then\n"
            "    -- Ignore vim swap files\n"
            "    ext = fname:match('.(%a*)$'):lower()\n"
            "    if ext ~= 'swp' then\n"
            "      print('Running \\'' .. fname .. '\\'')\n"
            "      dofile(regress_scriptDir .. '/' .. fname)\n"
            "    end\n"
            "  end\n"
            "end\n\n"
            "luaVerboseMode(false)\n");
        mScriptExamplesBox->addItem(QString::fromUtf8("Regression Testing"),
                                    QVariant(regressionTesting));

        QString autoScreenCap = QString::fromUtf8(
            "-- This script will only run on a Posix compliant OS.\n"
            "-- Opens the dataset given by 'filename' and begins taking screen captures.\n"
            "-- You can manually transform the dataset while the script is running.\n"
            "-- Expect horrible things to happen if you close the render window while\n"
            "-- the script is running.\n"
            "local homeDir = os.getenv('HOME')\n"
            "local filename = homeDir .. '/sci/datasets/c60.uvf'\n"
            "local outputDir = homeDir .. '/sci/datasets/output/images'\n"
            "local numScreenCaps = 128\n\n"
            "print('Animate and capture script')\n"
            "print('Results will be output to: ' .. outputDir)\n"
            "os.execute('mkdir -p ' .. outputDir)\n\n"
            "-- data = Render window to animate.\n"
            "-- numFrames = Number of frames to capture during the animation.\n"
            "function doAnim (data, numFrames)\n"
            "  local datasetPath = data.getDataset().fullpath()\n"
            "  local baseName = os.capture('basename ' .. datasetPath .. ' .uvf', false)\n"
            "  print('Using basename: ' .. baseName)\n"
            "  t = 0.0\n"
            "  dt = 2.0 * math.pi / numFrames\n"
            "  for i=1,numFrames do\n"
            "    t = t + dt\n"
            "    print('Capturing screen ' .. i)\n"
            "    data.screenCapture(outputDir .. '/' .. baseName .. '_' .. i .. '.png', false)\n"
            "    -- Dirty hack to get the UI to update.\n"
            "    iv3d.processUI()\n"
            "  end\n"
            "end\n\n"
            "print('Loading data')\n"
            "data = iv3d.renderer.new(filename)\n"
            "print('Performing screen captures')\n"
            "data.setRendererTarget(1)\n"
            "doAnim(data, numScreenCaps)\n"
            "data.setRendererTarget(0)\n");
        mScriptExamplesBox->addItem(QString::fromUtf8("Auto Screen Cap"),
                                    QVariant(autoScreenCap));


        QString exampleMath = QString::fromUtf8(
            "print('-- Binary Operators --')\n"
            "print(5 + 79)\n"
            "print('Basic binary operators: ' .. (3 * 5 - 2) / 5 + 1 )\n"
            "print('Exponentiation: ' .. 3 ^ 5)\n"
            "a = 17; b = 5;\n"
            "print('Modulo: ' .. a % b)\n"
            "print('-- Relational Operators --')\n"
            "print('Is it equal?: ' .. tostring(a%b == a-math.floor(a/b)*b))\n"
            "print('a less than b?: ' .. tostring(a < b))\n"
            "print('a greater than b?: ' .. tostring(a > b))\n");
        mScriptExamplesBox->addItem(QString::fromUtf8("Basic Math"),
                                    QVariant(exampleMath));
        QString exampleLightOnAll = QString::fromUtf8(
            "for i in ...;\n"
            "...\n"
            "...\n"
            "...\n"
            "..");
        mScriptExamplesBox->addItem(QString::fromUtf8("Turn On All Lighting"),
                                    QVariant(exampleLightOnAll));
        QString rotate360AndScreenCap = QString::fromUtf8(
            "for i in ...;\n"
            "...\n"
            "...\n"
            "...\n"
            "..");
        mScriptExamplesBox->addItem(QString::fromUtf8("Rotate 360 and Screen "
                                                      "Cap"),
                                    QVariant(rotate360AndScreenCap));
        QObject::connect(mScriptExamplesBox, SIGNAL(currentIndexChanged(int)),
                         this, SLOT(exampComboIndexChanged(int)));

        QSpacerItem* spacer = new QSpacerItem(40, 10,
                                              QSizePolicy::Expanding,
                                              QSizePolicy::Preferred);
        comboExecLayout->addSpacerItem(spacer);

        mExecButton = new QPushButton();
        mExecButton->setMinimumSize(QSize(0, 23));  // Required, if not, button
        // is shifted downwards beyond its layout control.
        mExecButton->setText(QString::fromUtf8("Execute Script"));
        comboExecLayout->addWidget(mExecButton);
        QObject::connect(mExecButton, SIGNAL(clicked()), this,
                         SLOT(execClicked()));
      }
    }
  }
  connect(mScriptTextEdit, SIGNAL(textChanged()), this, SLOT(fixFont()));
}