示例#1
0
CEvent_editor_dialog::CEvent_editor_dialog(CEvent event,
                                           qint32 ticket_id,
                                           QList<template_xml_element> *elements, //the templates
                                           QHash<quint32, QString> *bool_names_pnt,
                                           QHash<quint32, QString> *variable_names_pnt,
                                           QHash<quint32, QString> *text_names_pnt,
                                           QString projectPath )
{
    // Event Edit Dialog Constructor
    //* 1   Storing Overloaded Values
    //* 1.1 Validating received cacheEvent
    //* 2   Translating Hash to QStringList
    //* 3   Creating GUI
    //* 4   Loading initial Data

    //* 1 Storing Overloaded Values
    this->ticket_id = ticket_id;
    this->elements = elements; // the template elements
    this->previous_listWidgetIndex = 0;
    this->project_path = projectPath;

    //* 2 Translating Hash to QStringList

    //bools:: 1 :: getting biggest index
    quint32 bools_max = 0;
    QHash<quint32, QString>::iterator b_it = bool_names_pnt->begin();
    for (1; b_it != bool_names_pnt->end(); ++b_it)
    {
        if ( b_it.key() >= bools_max )
            bools_max = b_it.key();
//        qDebug() << i.key() << ": " << i.value() << endl;
    }
    //bools:: 2 :: filling list
    for ( quint32 j = 0; j <= bools_max; j++ )
        this->names_bool.append( bool_names_pnt->value( j ) );

    //vars:: 1 :: getting biggest index
    quint32 vars_max = 0;
    QHash<quint32, QString>::iterator v_it = variable_names_pnt->begin();
    for (1; v_it != variable_names_pnt->end(); ++v_it)
        if ( v_it.key() >= vars_max )
            vars_max = v_it.key();
    //vars:: 2 :: filling list
    for ( quint32 j = 0; j <= vars_max; j++ )
        this->names_variable.append( variable_names_pnt->value( j ) );

    //texts:: 1 :: getting biggest index
    quint32 texts_max = 0;
    QHash<quint32, QString>::iterator t_it = text_names_pnt->begin();
    for (1; t_it != text_names_pnt->end(); ++t_it)
        if ( t_it.key() >= texts_max )
            texts_max = t_it.key();
    //texts:: 2 :: filling list
    for ( quint32 j = 0; j <= texts_max; j++ )
        this->names_texts.append( text_names_pnt->value( j ) );



    //* 3 Creating GUI
    this->widget_edit = new Cevent_input_mask( &this->names_bool, &this->names_variable, projectPath );
    QObject::connect( this->widget_edit->gui_enable_add_condition_btn, SIGNAL(clicked()),
                      this, SLOT(re_minHeight_input_mask()) );

    this->widget_templates = new Ctemplatez_page( );
    QObject::connect( this->widget_templates->pickbox, SIGNAL(currentIndexChanged(int)),
                      this, SLOT(switch_behaviour(int)));
    QObject::connect( this->widget_templates, SIGNAL(apply_code()),
                      this, SLOT(confirm_install_template()) );

    this->btn_templates_edit = new QPushButton( QIcon( ":/resources/img/event_editor_code_snippets.png" ), tr( "Templates" ), this );
    this->btn_templates_edit->setIconSize( QSize( 48,48 ) );
    QObject::connect( this->btn_templates_edit, SIGNAL(clicked()),
                      this, SLOT(switch_templates_and_edit()) );


    this->area_edit = new QScrollArea();
    this->area_edit->setAlignment( Qt::AlignCenter );
    this->area_edit->setWidget( this->widget_edit );
    this->area_edit->setBackgroundRole( QPalette::Dark );
    this->area_edit->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
    this->area_template = new QScrollArea();
    this->area_template->setAlignment( Qt::AlignCenter );
    this->area_template->setWidget( this->widget_templates );
    this->area_template->setBackgroundRole( QPalette::Dark );
    this->area_template->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );

    this->stackPit = new QStackedWidget( this );
    this->stackPit->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Expanding );
    this->stackPit->addWidget( this->area_edit );
    this->stackPit->addWidget( this->area_template );

    this->pages_label = new QLabel( tr( "Pages" ) );
    this->pages_label->setAlignment( Qt::AlignCenter );
    this->pages_listWidget = new QListWidget();
    this->pages_listWidget->setCurrentRow( 0 );
    QObject::connect( this->pages_listWidget, SIGNAL(clicked(QModelIndex)),
                      this, SLOT(switch_page()) );

    QString str = QString( "%1" ).arg( event.tileLocation );
    this->label_event_info = new QLabel( event.title + "@" + str );
    this->label_event_info->setAlignment( Qt::AlignCenter );
    this->btn_cancel = new QPushButton( QIcon( ":/resources/img/cancel.png" ), tr( "Cancel" ) );
    this->btn_save_exit = new QPushButton( QIcon( ":/resources/img/save.png" ), tr( "Save and exit" ) );

    QObject::connect( this->btn_cancel, SIGNAL(clicked()), this, SLOT(close()));
    QObject::connect( this->btn_save_exit, SIGNAL(clicked()),this, SLOT(exit_saving()) );


    this->pages_control_btn = new QToolButton();
    this->pages_control_btn->setIcon( QIcon( ":/resources/img/tool.png" ) );

    QMenu *m = new QMenu( tr( "Pages control" ) );
    m->addAction( QIcon( ":/resources/img/edit-add.png" ), tr( "Add new page" ) );
    m->addAction( QIcon( ":/resources/img/edit-copy.png" ), tr( "Copy current page" ) );
    m->addAction( QIcon( ":/resources/img/edit-paste.png" ), tr( "Paste previous copied or cut page" ) );
    m->addAction( QIcon( ":/resources/img/edit-cut.png" ), tr( "Cut current page (Copy+Delete)" ) );
    m->addAction( QIcon( ":/resources/img/edit-delete.png" ), tr( "Delete current page" ) );
    m->addSeparator();
    m->addAction( QIcon( ":/resources/img/edit-rename.png" ), tr( "Rename Event" ) );
    m->addAction( QIcon( ":/resources/img/edit-rename.png" ), tr( "Relocalte Event" ) );
    this->pages_control_btn->setMenu( m );
    this->pages_control_btn->setPopupMode( QToolButton::InstantPopup );

    QObject::connect( m->actions()[0], SIGNAL(triggered()), this, SLOT(add_page()) );
    QObject::connect( m->actions()[1], SIGNAL(triggered()), this, SLOT(copy_page()) );
    QObject::connect( m->actions()[2], SIGNAL(triggered()), this, SLOT(paste_page()) );
    QObject::connect( m->actions()[3], SIGNAL(triggered()), this, SLOT(cut_page()) );
    QObject::connect( m->actions()[4], SIGNAL(triggered()), this, SLOT(del_page()) );
    //5 is the seperator
    QObject::connect( m->actions()[6], SIGNAL(triggered()), this, SLOT(rename_event()) );
    QObject::connect( m->actions()[7], SIGNAL(triggered()), this, SLOT(relocate_event()) );

    //to forbid pasting empty pages at startup
    m->actions()[3]->setEnabled( false );


    QHBoxLayout *h = new QHBoxLayout();

    h->addWidget( this->pages_label );
    h->addWidget( this->pages_control_btn );

    this->vLay = new QVBoxLayout();
    this->vLay->addWidget( this->label_event_info );
    this->vLay->addLayout( h );
    this->vLay->addWidget( this->pages_listWidget );
    this->vLay->addWidget( this->btn_templates_edit );

    this->lay = new QHBoxLayout();
    QWidget *w = new QWidget();
    w->setLayout( this->vLay );
    w->setMaximumWidth( 150 );

    QHBoxLayout *downer_bar = new QHBoxLayout();
    downer_bar->addStretch();
    downer_bar->addWidget( this->btn_cancel );
    downer_bar->addWidget( this->btn_save_exit );

    QVBoxLayout *v = new QVBoxLayout();
    v->addWidget( this->stackPit );
    v->addLayout( downer_bar );

    this->lay->addWidget( w );
    this->lay->addLayout( v );


    this->setLayout( this->lay );

    this->setWindowTitle( this->cacheEvent.title );
    this->setWindowIcon( QIcon( ":/resources/img/tokens_mini_event.png" ) );
//    this->resize( this->area_edit->width() + this->btn_templates_edit->width() + 44 , 400 );


    //* 4 Loading initial Data

    // appending code snippet elements from the pointer
    this->widget_templates->pickbox->clear();
    for ( int i = 0; i < this->elements->count(); i++ )
    {
//        QListWidgetItem *lwi = new QListWidgetItem(
//                QIcon( this->project_path + "/res/code_snippets/" + this->elements[i].iconSmall ),
//                this->elements[i].title );
        this->widget_templates->pickbox->addItem( QIcon( this->elements->at(i).iconSmall ),
                                                   this->elements->at(i).title );
    }
    //setting some first values
    if ( this->elements->count() > 0 )
    {
        this->widget_templates->label_big_symbol->setPixmap( QPixmap( this->elements->at(0).iconBig ) );
        this->widget_templates->label_description_text->setText( this->elements->at(0).description );
    }

    //loading original osps

    if ( this->cacheEvent.pages.count() >= 1 )
        this->widget_edit->gui_behavior_cmd_widget->setOSPs( this->cacheEvent.pages[0].original_commandos_string );
    else
        this->add_page(); // to have at least an empty page

    this->rebuild_listwidget_entries_index();
    this->put_original_strings_into_gui(); // the current page is 0 at this time


    this->resize(840,400);
}
示例#2
0
HyperDocPage *
parse_patch(PasteNode *paste)
{
    TextNode *new_paste;
    TextNode *end_node;
    TextNode *begin_node;
    TextNode *arg_node;
    TextNode *old;
    TextNode *next_node;
    InputItem *paste_item = paste->paste_item;
    int where = paste->where;
    GroupItem *g = paste->group;
    ItemStack *is = paste->item_stack;
    PatchStore *patch;
    char *patch_name;
    int ret_value = 1;

    /* prepare to throw away the current paste node */
    end_node = paste->end_node;
    next_node = end_node->next;
    begin_node = paste->begin_node;
    arg_node = paste->arg_node;
    old = begin_node->next;

    /* now read the new stuff and add it in between all this stuff */

    switch (where) {
      case openaxiom_FromFile_input:
        patch_name = print_to_string(arg_node);
        patch = (PatchStore *) hash_find(gWindow->fPatchHashTable, patch_name);
        if (!patch) {
            fprintf(stderr, "(HyperDoc) Unknown patch name %s\n", patch_name);
            BeepAtTheUser();
            return 0;
        }
        if (!patch->loaded)
            load_patch(patch);
        input_type = openaxiom_FromString_input;
        input_string = patch->string;
        break;
      case openaxiom_FromSpadSocket_input:
        input_type = openaxiom_FromSpadSocket_input;
        ret_value = issue_serverpaste(arg_node);
        if (ret_value < 0) {
            paste->where = where;
            paste->end_node = end_node;
            paste->arg_node = arg_node;
            paste->group = g;
            paste->item_stack = is;
            paste->haspaste = 1;
            return 0;
        }
        break;
      case openaxiom_FromUnixFD_input:
        input_type = openaxiom_FromUnixFD_input;
        issue_unixpaste(arg_node);
        break;
      default:
        fprintf(stderr, "(HyperDoc) \\parsebutton error: Unknown where\n");
        exit(-1);
        break;
    }

    paste->where = 0;
    paste->end_node = paste->arg_node = paste->begin_node = 0;
    paste->group = 0;
    paste->item_stack = 0;
    paste->haspaste = 0;
    paste->paste_item = 0;


    /* set the jump buffer in case it is needed */
    if (setjmp(jmpbuf)) {
        /*** OOOPS, an error occurred ****/
        fprintf(stderr, "(HyperDoc) Had an error parsing a patch: Goodbye!\n");
        exit(-1);
    }


    end_node->next = 0;
    free_node(old, 1);

    init_parse_patch(gWindow->page);
    init_paste_item(paste_item);
    get_token();
    if (token.type != openaxiom_Patch_token) {
        fprintf(stderr, "(HyperDoc) Pastebutton %s was expecting a patch\n",
                paste->name);
        jump();
    }
    if (input_type == openaxiom_FromString_input) {
        get_token();
        if (token.type != openaxiom_Lbrace_token) {
            token_name(token.type);
            fprintf(stderr, "(HyperDoc) Unexpected %s \n", ebuffer);
            print_page_and_filename();
            jump();
        }

        get_token();
        if (token.type != openaxiom_Word_token) {
            token_name(token.type);
            fprintf(stderr, "(HyperDoc) Unexpected %s \n", ebuffer);
            print_page_and_filename();
            jump();
        }

        get_token();
        if (token.type != openaxiom_Rbrace_token) {
            token_name(token.type);
            fprintf(stderr, "(HyperDoc) Unexpected %s \n", ebuffer);
            print_page_and_filename();
            jump();
        }
    }
    new_paste = alloc_node();
    curr_node = new_paste;
    parse_HyperDoc();

    /* Once I am back, I need only reallign all the text structures */
    curr_node->type = openaxiom_Noop_token;
    curr_node->next = next_node;
    begin_node->next = new_paste;
    begin_node->type = openaxiom_Noop_token;
    free(begin_node->data.text);
    begin_node->data.text = 0;

    gWindow->fDisplayedWindow = gWindow->fScrollWindow;

    repaste_item();

    paste_page(begin_node);

    /* so now I should just be able to disappear */
    return gWindow->page;
}