ExpressionEditorWindow::ExpressionEditorWindow(
    const Project&  project,
    ParamArray&     settings,
    const QString&  widget_name,
    const string&   expression,
    QWidget*        parent)
  : WindowBase(parent, "expression_editor_window")
  , m_ui(new Ui::ExpressionEditorWindow())
  , m_project(project)
  , m_settings(settings)
  , m_widget_name(widget_name)
  , m_show_examples(false)
{
    m_ui->setupUi(this);

    setAttribute(Qt::WA_DeleteOnClose);
    setWindowFlags(Qt::Tool);

    QHBoxLayout* root_layout = new QHBoxLayout(m_ui->scrollarea);

    QVBoxLayout* left_layout = new QVBoxLayout();
    QVBoxLayout* right_layout = new QVBoxLayout();
    root_layout->addLayout(left_layout);
    root_layout->addLayout(right_layout);

    // Expression controls.
    SeExprEdControlCollection* controls = new SeExprEdControlCollection();
    QScrollArea* controls_scrollarea = new QScrollArea(this);
    controls_scrollarea->setObjectName("expression_controls");
    controls_scrollarea->setMinimumHeight(200);
    controls_scrollarea->setWidgetResizable(true);
    controls_scrollarea->setWidget(controls);
    left_layout->addWidget(controls_scrollarea);

    // Clear button.
    QShortcut* clear_shortcut = new QShortcut(QKeySequence("Ctrl+N"), this);
    connect(clear_shortcut, SIGNAL(activated()), SLOT(slot_clear_expression()));
    QPushButton* clear_button = new QPushButton("Clear");
    clear_button->setToolTip(clear_shortcut->key().toString(QKeySequence::NativeText));
    connect(clear_button, SIGNAL(clicked()), SLOT(slot_clear_expression()));

    // Save button.
    QShortcut* save_shortcut = new QShortcut(QKeySequence("Ctrl+S"), this);
    connect(save_shortcut, SIGNAL(activated()), SLOT(slot_save_script()));
    QPushButton* save_button = new QPushButton("Save");
    save_button->setToolTip(save_shortcut->key().toString(QKeySequence::NativeText));
    connect(save_button, SIGNAL(clicked()), SLOT(slot_save_script()));

    // Load button.
    QShortcut* load_shortcut = new QShortcut(QKeySequence("Ctrl+O"), this);
    connect(load_shortcut, SIGNAL(activated()), SLOT(slot_load_script()));
    QPushButton* load_button = new QPushButton("Load");
    load_button->setToolTip(load_shortcut->key().toString(QKeySequence::NativeText));
    connect(load_button, SIGNAL(clicked()), SLOT(slot_load_script()));

    // Help button.
    QPushButton* help_button = new QPushButton("Help");
    connect(help_button, SIGNAL(clicked()), SLOT(slot_show_help()));

    // Examples button.
    QPushButton* examples_button = new QPushButton("Examples");
    connect(examples_button, SIGNAL(clicked()), SLOT(slot_show_examples()));

    QHBoxLayout* file_buttonbox = new QHBoxLayout();
    file_buttonbox->addWidget(clear_button);
    file_buttonbox->addWidget(load_button);
    file_buttonbox->addWidget(save_button);
    file_buttonbox->addWidget(help_button);
    file_buttonbox->addWidget(examples_button);
    left_layout->addLayout(file_buttonbox);

    m_editor = new SeExprEditor(this, controls);
    QTextEdit* text_edit = m_editor->findChild<QTextEdit*>("");
    text_edit->setObjectName("expression_editor");
    m_editor->setExpr(expression, true);
    left_layout->addWidget(m_editor);

    m_error = new QLabel("Expression has errors. Check log for details.");
    m_error->setObjectName("error");
    m_error->hide();
    left_layout->addWidget(m_error);

    // Expression browser.
    m_browser = new SeExprEdBrowser(nullptr, m_editor);
    const bf::path root_path(Application::get_root_path());
    const string scripts_path = (root_path / "seexpr").string();
    m_browser->addPath("Examples", scripts_path);
    m_browser->update();
    m_browser->hide();
    right_layout->addWidget(m_browser);

    m_ui->buttonbox_layout->addStretch(1);
    m_ui->buttonbox_layout->setStretch(0, 1);
    m_ui->buttonbox_layout->setStretch(1, 0);

    connect(m_ui->buttonbox, SIGNAL(accepted()), SLOT(slot_accept()));
    connect(m_ui->buttonbox, SIGNAL(rejected()), SLOT(slot_cancel()));

    connect(
        m_ui->buttonbox->button(QDialogButtonBox::Apply), SIGNAL(clicked()),
        SLOT(slot_apply()));

    connect(
        create_window_local_shortcut(this, Qt::Key_Escape), SIGNAL(activated()),
        SLOT(close()));

    WindowBase::load_settings();
}
Esempio n. 2
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    textChanged=false;
    current_filename="./scripts/default.txt";

    ui->setupUi(this);

    for(int i=0; i<NBColorMode; i++) {
        ui->cb__color_mode->addItem(ColorMode_str[i]);
    }
    for(int i=0; i<NB_Gradients; i++) {
        ui->cb_gradient_preset->addItem(ColorGradients_str[i]);
    }

    //Menu
    algo_group=new QActionGroup(NULL);
    QMenu * menu=new QMenu;
    for(int i=0; i<NBSolveMode; i++)
    {
        QAction * new_action=new QAction(QString(SolveMode_str[i]),this);
        new_action->setShortcut(QString("Ctrl+F%1").arg(i+1));
        new_action->setCheckable(true);
        menu->addAction(new_action);
        algo_group->addAction(new_action);
    }
    ui->actionAlgorithms->setMenu(menu);

    QList<QAction*> list=algo_group->actions();
    list[0]->setChecked(true);

    //Display
    output_1d=new Viewer1D();
    output_2d=new Viewer2D();
    output_3d=new Viewer3D();

    tab_plots=new QTabWidget();
    tab_plots->addTab(output_1d,"Plot 1D");
    tab_plots->addTab(output_2d,"Plot 2D");
    tab_plots->addTab(output_3d,"Plot 3D");
    tab_plots->setWindowTitle("2D/3D Plots");

    //System
    sys=new System();
    ui->tabSystem->addTab(sys->getParamHandler(),QString("Parameters"));

    qRegisterMetaType< Box >("Box");
    qRegisterMetaType< std::vector<double> >("std::vector<double>");
    qRegisterMetaType< std::vector<std::vector<double>> >("std::vector<std::vector<double>>");
    qRegisterMetaType< std::vector<std::vector<std::vector<double>>> >("std::vector<std::vector<std::vector<double>>");

    connect(ui->actionMinimize,SIGNAL(triggered()),this,SLOT(slot_run_script()));
    connect(ui->actionSave,SIGNAL(triggered()),this,SLOT(slot_direct_save_script()));
    connect(ui->actionSaveUnder,SIGNAL(triggered()),this,SLOT(slot_save_script()));
    connect(ui->actionOpen,SIGNAL(triggered()),this,SLOT(slot_load_script()));
    connect(ui->te_script,SIGNAL(textChanged()),this,SLOT(slot_text_changed()));
    connect(ui->actionQuit,SIGNAL(triggered(bool)),this,SLOT(close()));
    connect(ui->pb_calculate_conv,SIGNAL(clicked()),this,SLOT(slot_conv()));
    connect(ui->pb_calculate_func,SIGNAL(clicked()),this,SLOT(slot_func()));
    connect(ui->pb_save_conv_setting,SIGNAL(clicked()),this,SLOT(slot_save_conv_setting()));
    connect(ui->pb_load_conv_setting,SIGNAL(clicked()),this,SLOT(slot_load_conv_setting()));

    connect(ui->rb_1D,SIGNAL(clicked()),this,SLOT(update_button_names_1d()));
    connect(ui->rb_2D,SIGNAL(clicked()),this,SLOT(update_button_names_2d()));
    connect(ui->rb_3D,SIGNAL(clicked()),this,SLOT(update_button_names_3d()));

    connect(output_2d,SIGNAL(pick(double,double)),this,SLOT(pick(double,double)));
    connect(sys,SIGNAL(progress(int)),ui->progressBar,SLOT(setValue(int)));
    connect(ui->a_tiles,SIGNAL(triggered()),ui->mdiArea,SLOT(tileSubWindows()));
    connect(ui->cb_param1,SIGNAL(currentIndexChanged(int)),this,SLOT(id1_changed(int)));
    connect(ui->cb_param2,SIGNAL(currentIndexChanged(int)),this,SLOT(id2_changed(int)));
    connect(ui->cb_param3,SIGNAL(currentIndexChanged(int)),this,SLOT(id3_changed(int)));

    connect(ui->cb_gradient_preset,SIGNAL(currentIndexChanged(int)),output_3d,SLOT(setGradient(int)));
    connect(ui->cb_gradient_preset,SIGNAL(currentIndexChanged(int)),output_2d,SLOT(setGradient(int)));

    connect(&worker,SIGNAL(sig_solve()),this,SLOT(slot_solve_over()));

    connect(&worker,SIGNAL(sig_output_1d(std::vector<double>,Box)),output_1d,SLOT(slot_set_data(std::vector<double>,Box)));
    connect(&worker,SIGNAL(sig_output_2d(std::vector<std::vector<double>>,Box)),output_2d,SLOT(slot_set_data(std::vector<std::vector<double>>,Box)));
    connect(&worker,SIGNAL(sig_output_3d(std::vector<std::vector<std::vector<double>>>,Box)),output_3d,SLOT(slot_set_data(std::vector<std::vector<std::vector<double>>>,Box)));

    setStyle(this,"./style.qss");
    setStyle(sys,"./style.qss");
    setStyle(output_2d,"./style.qss");
    setStyle(output_3d,"./style.qss");


    ui->mdiArea->addSubWindow(sys,Qt::CustomizeWindowHint | Qt::WindowMinMaxButtonsHint);
    ui->mdiArea->addSubWindow(tab_plots,Qt::CustomizeWindowHint | Qt::WindowMinMaxButtonsHint);
    ui->mdiArea->addSubWindow(ui->tabSystem,Qt::CustomizeWindowHint | Qt::WindowMinMaxButtonsHint);

    id1_changed(ui->cb_param1->currentIndex());
    id2_changed(ui->cb_param2->currentIndex());
    id3_changed(ui->cb_param3->currentIndex());

    QTimer::singleShot(500, ui->mdiArea, SLOT(tileSubWindows()));
}