Logo Search packages:      
Sourcecode: kaptain version File versions  Download package

void Kaptain::create_special (  )

substitution

separation

inserting the fields

selection

Definition at line 807 of file kaptain.cpp.

Referenced by create().

{
  int spec=im->spec_type;
  bool again=false;
  /* creates a widget and sets myself to point to it */
  switch (spec)
    {    
    case 1: // @integer
      again=spin_box;
      if (!again)
        {
          spin_box=new QSpinBox(parent_widget);
          myself=spin_box;
          spin_box->setFixedSize(spin_box->sizeHint());
        }
      {
        /* initial setup */
        int min=0, max=99, init=0;
        if (im->parameter_type(0,T_NUMERAL)) init=im->get_int_parameter(0);
        if (im->parameter_type(1,T_NUMERAL)) min=im->get_int_parameter(1);
        if (im->parameter_type(2,T_NUMERAL)) max=im->get_int_parameter(2);
        if (max<min) max=min;
        if (init<min) init=min;
        if (init>max) init=max;
        spin_box->setRange(min,max);
        spin_box->setValue(init);        
      }
      break;

    case 2: // @string --> @float, @regex, @password
      again=line_edit;
      if (!again)
        {
          line_edit=new QLineEdit(parent_widget);
          myself=line_edit;
        }
      /* initial value */
      if (im->parameter_type(0,T_STRING)) 
        line_edit->setText(QString(im->get_string_parameter(0).c_str()));
      /* maximum length */
      if (im->parameter_type(1,T_NUMERAL)) 
        line_edit->setMaxLength(im->get_int_parameter(1));
      break;

    case 3: // @list --> @combo, @comborw
      {
        again=list_box;
        if (!again)
          {
            list_box=new Q3ListBox(parent_widget);
                        connect(list_box, SIGNAL(highlighted(const QString &)),
                                      SLOT(message_listbox(const QString &)));
            myself=list_box;
          }
        else
          {
            if (im->get_parameter_num()>0) 
              list_box->clear();
          }

        bool has_string_regexp_init=false, regexp=false;
        bool s_global_flag=false, has_substitution=false;
        string s_pattern, s_replacement, pattern;
        list<string> result;
        
        if (im->parameter_type(0,T_STRING) || im->parameter_type(0,T_REGEXP))
          {
            has_string_regexp_init=true;
            regexp=im->parameter_type(0,T_REGEXP);
            pattern=im->get_string_parameter(0);
          }
      
        int items_inserted=0;
        /* process parameters and initvalue */
        int pn=im->get_parameter_num();
        for (int i=1; i<=pn; i++) {
          if (im->parameter_type(i,T_SUBST))
            {
              /* update substitution */
              has_substitution=true;
              im->get_subst_parameter(i, s_pattern, s_replacement, 
                                      s_global_flag);
            }
          if (im->parameter_type(i,T_STRING))
            {
              list<string> lines;
              Regexp::split('\n', im->get_string_parameter(i), lines);
              list<string>::iterator it;
              for (it=lines.begin();
                   it!=lines.end();
                   it++)
                {
                  string original_line=(*it), 
                    modified_line=original_line;
                  /* execute substitution */
                  if (has_substitution)
                    Regexp::substitute(s_pattern, original_line,
                                       s_replacement, modified_line, 
                                       s_global_flag);
                  list_box->insertItem(modified_line.c_str());
                  if (has_string_regexp_init)
                    {
                      /* select the line 
                         - equal to a string 
                         - matching a regexp
                      */
                      if ((!regexp && pattern==(*it)) ||
                          (regexp && Regexp::matches
                           (pattern, original_line, result)))
                        {
                          has_string_regexp_init=false; // select first choice
                          list_box->setCurrentItem(items_inserted);
                        }
                    }
                  items_inserted++;
                }
            }
        }
        /* integer initvalue */
        if (im->parameter_type(0,T_NUMERAL))
          list_box->setCurrentItem(im->get_int_parameter(0)-1);
      }
      break;

    case 4: // @float --> @string, @regex, @password
      again=line_edit;
      if (!again)
        {
          line_edit=new QLineEdit(parent_widget);
          myself=line_edit;
          line_edit->setValidator(new QDoubleValidator(parent_widget));
        }
      /* initial value */
      if (im->parameter_type(0,T_STRING)) 
        line_edit->setText(QString(im->get_string_parameter(0).c_str()));
      if (im->parameter_type(0,T_NUMERAL)) 
        line_edit->setText(QString::number(im->get_int_parameter(0)));
      break;

    case 5: // @button
    case 12: // @close
    case 13: // @action
    case 16: // @exec
    case 17: // @echo
    case 20: // @execclose
    case 21: // @execbuffer
    case 22: // @dump
    case 23: // @preview
    case 26: // @fork
      again=push_button;
      if (!again)
        {
          push_button=new QPushButton(parent_widget);
          myself=push_button;
        }

      /* initial value is the label */
      if (im->parameter_type(0,T_STRING))
        button_label(push_button, im->get_string_parameter(0));
      push_button->setFixedSize(push_button->sizeHint());
      if (im->parameter_type(0,T_STRING) 
                   && im->get_string_parameter(0)[0]==' ')
        //if (im->is_default_button())
        push_button->setDefault(true);

      /* button pressed ... */
      if (!again)
        connect(push_button, SIGNAL(clicked()), SLOT(button_pressed()));
      break;

    case 6: // @regex --> @string, @float, @password
      again=line_edit;
      if (!again)
        {
          line_edit=new QLineEdit(parent_widget);
          myself=line_edit;
        }

      /* first parameter is regular expression */
      if (im->parameter_type(1,T_STRING) ||
          im->parameter_type(1,T_REGEXP))
        {
          line_edit->setValidator
            (new QRegValidator(im->get_string_parameter(1).c_str(), 
                               parent_widget));
          list<string> result;
          /* initial value */
          if (im->parameter_type(0,T_STRING) && 
              Regexp::matches(im->get_string_parameter(1).c_str(),
                              im->get_string_parameter(0).c_str(),result))
            line_edit->setText(im->get_string_parameter(0).c_str());
        }
      break;

    case 7: // @infile
    case 8: // @outfile
    case 9: // @directory
      again=line_edit;
      if (!again)
        {
          myself=new Q3HBox(parent_widget);
          ((Q3HBox *)myself)->setSpacing(SPACING);
          line_edit=new QLineEdit(myself);
          push_button=new QPushButton(myself);
          push_button->setText("...");
          push_button->adjustSize();
        }
      if (im->parameter_type(0,T_STRING))
        line_edit->setText(im->get_string_parameter(0).c_str());
      /* button pressed ... */
      if (!again)
        connect(push_button, SIGNAL(clicked()), SLOT(button_pressed()));
      break;

    case 10: // @combo
    case 15: // @combow --> @list
      {
        again=combo_box;
        if (!again)
          {
            combo_box=new QComboBox(spec==15, parent_widget);
                        connect(combo_box, SIGNAL(activated(const QString &)),
                                      SLOT(message_listbox(const QString &)));
            myself=combo_box;
          }
        else
          {
            if (im->get_parameter_num()>0) 
              combo_box->clear();
          }

        bool has_string_regexp_init=false, regexp=false;
        bool s_global_flag=false, has_substitution=false;
        string s_pattern, s_replacement, pattern;
        list<string> result;
        
        if (im->parameter_type(0,T_STRING) || im->parameter_type(0,T_REGEXP))
          {
            has_string_regexp_init=true;
            regexp=im->parameter_type(0,T_REGEXP);
            pattern=im->get_string_parameter(0);
          }
      
        int items_inserted=0;
        /* process parameters and initvalue */
        int pn=im->get_parameter_num();
        for (int i=1; i<=pn; i++) {
          if (im->parameter_type(i,T_SUBST))
            {
              /* update substitution */
              has_substitution=true;
              im->get_subst_parameter(i, s_pattern, s_replacement, 
                                      s_global_flag);
            }
          if (im->parameter_type(i,T_STRING))
            {
              list<string> lines;
              Regexp::split('\n', im->get_string_parameter(i), lines);
              list<string>::iterator it;
              for (it=lines.begin();
                   it!=lines.end();
                   it++)
                {
                  string original_line=(*it), 
                    modified_line=original_line;
                  /* execute substitution */
                  if (has_substitution)
                    Regexp::substitute(s_pattern, original_line,
                                       s_replacement, modified_line, 
                                       s_global_flag);
                  combo_box->insertItem(modified_line.c_str());
                  if (has_string_regexp_init)
                    {
                      /* select the line 
                         - equal to a string 
                         - matching a regexp
                      */
                      if ((!regexp && pattern==(*it)) ||
                          (regexp && Regexp::matches
                           (pattern, original_line, result)))
                        {
                          has_string_regexp_init=false; // select first choice
                          combo_box->setCurrentItem(items_inserted);
                        }
                    }
                  items_inserted++;
                }
            }
        }
        /* integer initvalue */
        if (im->parameter_type(0,T_NUMERAL))
          combo_box->setCurrentItem(im->get_int_parameter(0)-1);
      }
      break;
        
    case 11: // @container
      {
        again=list_box;
        if (!again)
          {
            Q3VBox * vbox=new Q3VBox(parent_widget);
            myself=vbox;
            Q3HBox * hbox=new Q3HBox(vbox);
            hbox->setSpacing(SPACING);
            vbox->setSpacing(SPACING);
            list_box=new Q3ListBox(vbox);
            // buttons
            push_button=new QPushButton(hbox);
            push_button2=new QPushButton(hbox);
          }

        string txt_add("Add");
        string txt_remove("Remove");
        /* 1: source for the container: NONTERMINAL */
        if (im->parameter_type(1,T_NONTERM))
          container_source=im->get_int_parameter(1);
        /* 2,3: Add, Remove button label: string */
        if (im->parameter_type(2,T_STRING))
          txt_add=im->get_string_parameter(2);
        if (im->parameter_type(3,T_STRING))
          txt_remove=im->get_string_parameter(3);
        // text or image label
        if (!again || im->parameter_type(2,T_STRING))
          button_label(push_button, txt_add.c_str());
        if (!again || im->parameter_type(3,T_STRING))
          button_label(push_button2, txt_remove.c_str());
        push_button->setFixedSize(push_button->sizeHint());
        push_button2->setFixedSize(push_button2->sizeHint());
        /* when button is pressed */
        if (!again)
          {
            connect(push_button, SIGNAL(clicked()), SLOT(container_add()));
            connect(push_button2, SIGNAL(clicked()), SLOT(container_remove()));
          }
      }
      break;

    case 14: // @edit --> @preview's pressed action
      {
        again=edit;
        if (!again)
          {
            edit=new Q3MultiLineEdit(parent_widget);
            myself=edit;
          }
        /* init value */
        if (im->parameter_type(0,T_STRING))
          edit->setText(im->get_string_parameter(0).c_str());
        int param=1;
        /* font, size parameters */
        if (im->parameter_type(1,T_STRING)) {
          string font_name=im->get_string_parameter(1);
          QFont font(font_name.c_str());
          if (font_name[0]=='-')
            font.setRawName(font_name.c_str());
          edit->setFont(font);
          param++;
        }
        /* window size */
        if (im->parameter_type(param,T_NUMERAL))
          edit->setMinimumWidth(im->get_int_parameter(param));
        if (im->parameter_type(param+1,T_NUMERAL))
          edit->setMinimumHeight(im->get_int_parameter(param+1));
      }
      break;

    case 18: // @icon
      {
        QLabel * label=(QLabel *)myself;
        again=label;
        if (!again)
          {
            label=new QLabel(parent_widget);
            myself=label;
          }

        if (im->parameter_type(1,T_STRING))
          {
            QPixmap & pixmap=get_pixmap(im->get_string_parameter(1).c_str());
            label->setPixmap(pixmap);
            label->setFixedSize(pixmap.size());
          }
      }
      break;

    case 19: // @text
      {
        QLabel * text=(QLabel *)myself;
        again=text;
        if (!again)
          {
            text=new QLabel(parent_widget);
            myself=text;
            text->setAlignment(Qt::AlignLeft|Qt::AlignTop|Qt::TextWordWrap);
            text->setFrameStyle(Q3Frame::Panel | Q3Frame::Sunken);
          }

        /* concatenate parameters */
        list<string> lines;
        int pm=im->get_parameter_num();
        for (int i=0; i<=pm; i++)
          {
            if (im->parameter_type(i,T_STRING))
              lines.push_back(im->get_string_parameter(i));
          }
        string joined;
        Regexp::join('\n', lines, joined);
        text->setText(joined.c_str());
      }
      break;

    case 24: // @size
      if (im->parameter_type(1,T_NUMERAL))
        parent_widget->setMinimumWidth(im->get_int_parameter(1));
      if (im->parameter_type(2,T_NUMERAL))
        parent_widget->setMinimumHeight(im->get_int_parameter(2));
      if (im->parameter_type(3,T_NUMERAL))
        parent_widget->setMaximumWidth(im->get_int_parameter(3));
      if (im->parameter_type(4,T_NUMERAL))
        parent_widget->setMaximumHeight(im->get_int_parameter(4));
      break;

    case 25: // @password --> @string, @float, @regex
      again=line_edit;
      if (!again)
        {
          line_edit=new QLineEdit(parent_widget);
          myself=line_edit;
          line_edit->setEchoMode(QLineEdit::Password);
        }

      /* initial value */
      if (im->parameter_type(0,T_STRING)) 
        line_edit->setText(QString(im->get_string_parameter(0).c_str()));
      /* maximum length */
      if (im->parameter_type(1,T_NUMERAL)) 
        line_edit->setMaxLength(im->get_int_parameter(1));
      break;

    case 27: // @fill
      myself=new QWidget(parent_widget);
      parent_layout->addWidget(myself,1);
      myself=0; // do not add it later to the layout
      break;

    case 28: // @multicol -:-> @list
      {
        again=list_view;
        if (!again)
          {
            list_view=new Q3ListView(parent_widget);
            list_view->setAllColumnsShowFocus(true);
            list_view->setSorting(-1);
            myself=list_view;
          }
        else
          {
            list_view->clear();
          }

        /* coulomn separation, substitution */
        bool has_regexp=false, has_substitution=false;
        string s_pattern, s_replacement;
        string separator_reg;
        bool s_global_flag;
        list<string> result;

        /* initial value selection */
        bool init_regexp=false, init_string=false, init_number=false;
        int init_num=0;
        string init_str;
        string init_reg;

        /*  initial value */
        if (im->parameter_type(0,T_NUMERAL))
          { init_number=true; init_num=im->get_int_parameter(0); }
        if (im->parameter_type(0,T_REGEXP))
          { init_regexp=true; init_reg=im->get_string_parameter(0); }
        if (im->parameter_type(0,T_STRING))
          { init_string=true; init_str=im->get_string_parameter(0); }

        int i=1, item_inserted=0, pn=im->get_parameter_num();
        bool init_selected=false, has_header=false;
        int max_col_num=0;
        Q3ListViewItem * current_item=0;

        /* optional first regexp */
        if (im->parameter_type(i, T_REGEXP))
          {
            has_regexp=true;
            separator_reg=im->get_string_parameter(i);
            i++;
          }

        for (; i<=pn; i++) {
          /* process multiline strings like for @list */
          if (im->parameter_type(i,T_SUBST))
            {
              /* update substitution */
              has_substitution=true;
              im->get_subst_parameter(i, s_pattern, s_replacement, 
                                      s_global_flag);
            }
          if (im->parameter_type(i,T_STRING))
            {
              list<string> lines;
              Regexp::split('\n', im->get_string_parameter(i), lines);
              list<string>::iterator it;
              for (it=lines.begin();
                   it!=lines.end();
                   it++)
                {
                  string original_line=(*it), 
                    modified_line=original_line;

                  /** substitution **/
                  if (has_substitution)
                    Regexp::substitute(s_pattern, original_line,
                                       s_replacement, modified_line, 
                                       s_global_flag);
                  
                  /** separation **/
                  result.clear();
                  if (has_regexp) // separate using regexp
                    {
                      if (!Regexp::matches
                          (separator_reg, modified_line, result))
                        result.push_back(modified_line);
                    }
                  else // separate at tabs
                    {
                      Regexp::split('\t', modified_line, result);
                    }

                  if (has_header)
                    current_item=new Q3ListViewItem(list_view,current_item);


                  /** inserting the fields **/
                  list<string>::iterator si;
                  int col=0;
                  for (si=result.begin();
                       si!=result.end();
                       si++, col++)
                    if (has_header)
                      {
                        if (max_col_num==col)
                          {
                            max_col_num++;
                            list_view->addColumn("");
                          }
                        current_item->setText(col,(*si).c_str());
                      }
                    else
                      {
                        /* create header field */
                        list_view->addColumn((*si).c_str());
                        max_col_num++;
                      }

                  /** selection **/
                  result.clear();
                  if (!init_selected && has_header)
                    {
                      /* select the line 
                         - equal to a string 
                         - matching a regexp
                         - equal to an integer
                      */
                      if ((init_string && init_str.c_str()==(*it)) ||
                          (init_number && init_num==item_inserted+1) ||
                          (init_regexp && Regexp::matches
                           (string(init_reg), 
                            string(original_line), 
                            result)))
                        {
                          init_selected=true; // select first choice
                          list_view->setCurrentItem(current_item);
                        }
                    }
                  if (has_header)
                    item_inserted++;

                  has_header=true; //only the first time
                }
            }
          }
        
      }
      break;

    case 29: // @line
      {
        again=myself;
        if (!again)
          {
            Q3Frame * line=new Q3Frame(parent_widget);
            line->setFrameStyle( Q3Frame::HLine | Q3Frame::Sunken );
            myself=line;
          }
      }
      break;

    default: // fallback to @integer
      again=spin_box;
      if (!again)
        {
          spin_box=new QSpinBox(parent_widget);
          myself=spin_box;
        }
    }

}

Here is the caller graph for this function:


Generated by  Doxygen 1.6.0   Back to index