ConfigurationManagerWindow::ConfigurationManagerWindow(QWidget* parent)
  : QWidget(parent)
  , m_ui(new Ui::ConfigurationManagerWindow())
{
    m_ui->setupUi(this);

    setWindowFlags(Qt::Window);

    disable_osx_focus_rect(m_ui->treewidget_configurations);

    connect(m_ui->buttonbox, SIGNAL(accepted()), this, SLOT(close()));
    connect(m_ui->buttonbox, SIGNAL(rejected()), this, SLOT(close()));

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

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

    connect(
        create_window_local_shortcut(this, Qt::Key_Escape), SIGNAL(activated()),
        this, SLOT(close()));
}
void EntityEditorWindow::create_connections()
{
    connect(
        m_entity_editor.get(), SIGNAL(signal_applied(foundation::Dictionary)),
        SIGNAL(signal_applied(foundation::Dictionary)));

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

    connect(
        create_window_local_shortcut(this, Qt::Key_Escape), SIGNAL(activated()),
        SLOT(slot_cancel()));
}
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();
}