// ******************************************************************************************
// Constructor
// ******************************************************************************************
VirtualJointsWidget::VirtualJointsWidget( QWidget *parent, moveit_setup_assistant::MoveItConfigDataPtr config_data )
  : SetupScreenWidget( parent ), config_data_(config_data)
{
  // Basic widget container
  QVBoxLayout *layout = new QVBoxLayout( );

  // Top Header Area ------------------------------------------------

  HeaderWidget *header = new HeaderWidget( "Virtual Joints",
                                           "Define a virtual joint between a robot link and an external frame of reference (considered fixed with respect to the robot).",
                                           this);
  layout->addWidget( header );

  // Create contents screens ---------------------------------------

  vjoint_list_widget_ = createContentsWidget();
  vjoint_edit_widget_ = createEditWidget();

  // Create stacked layout -----------------------------------------
  stacked_layout_ = new QStackedLayout( this );
  stacked_layout_->addWidget( vjoint_list_widget_ ); // screen index 0
  stacked_layout_->addWidget( vjoint_edit_widget_ ); // screen index 1

  // Create Widget wrapper for layout
  QWidget *stacked_layout_widget = new QWidget( this );
  stacked_layout_widget->setLayout( stacked_layout_ );

  layout->addWidget( stacked_layout_widget );

  // Finish Layout --------------------------------------------------
  this->setLayout(layout);

}
// ******************************************************************************************
// Constructor
// ******************************************************************************************
EndEffectorsWidget::EndEffectorsWidget( QWidget *parent, moveit_setup_assistant::MoveItConfigDataPtr config_data )
  : SetupScreenWidget( parent ), config_data_(config_data)
{
  // Basic widget container
  QVBoxLayout *layout = new QVBoxLayout( );

  // Top Header Area ------------------------------------------------

  HeaderWidget *header = new HeaderWidget( "End Effectors",
                                           "Setup grippers and other end effectors for your robot",
                                           this);
  layout->addWidget( header );

  // Create contents screens ---------------------------------------

  effector_list_widget_ = createContentsWidget();
  effector_edit_widget_ = createEditWidget();

  // Create stacked layout -----------------------------------------
  stacked_layout_ = new QStackedLayout( this );
  stacked_layout_->addWidget( effector_list_widget_ ); // screen index 0
  stacked_layout_->addWidget( effector_edit_widget_ ); // screen index 1

  // Create Widget wrapper for layout
  QWidget *stacked_layout_widget = new QWidget( this );
  stacked_layout_widget->setLayout( stacked_layout_ );

  layout->addWidget( stacked_layout_widget );


  // Finish Layout --------------------------------------------------
  this->setLayout(layout);

}
void WidgetMOItem::initializeGui()
{
    clearGui();
    QGridLayout* itemLayout = dynamic_cast<QGridLayout*>(itemWidget->layout());
    QLabel* label;
    if(item)
    {
        ui->groupItem->setTitle(item->name());
        QWidget* curWidget;

        for(int iF=0;iF<item->getNbFields();iF++)
        {
            curWidget = createEditWidget(item, iF, _editable);
            if(curWidget)
            {
                curWidget->setParent(this);
                fieldEditWidget.insert(iF,curWidget);


                // add it to gui
                label = new QLabel(item->getFieldName(iF),this);
                label->setSizePolicy(QSizePolicy::Maximum,QSizePolicy::Maximum);
                itemLayout->addWidget(label,iF,0);
                itemLayout->addWidget(curWidget,iF,1);

                // connect change
                QComboBox* combo = dynamic_cast<QComboBox*>(curWidget);
                if(combo)
                    connect(combo,SIGNAL(thiseditTextChanged(const QString &)),
                            this,SLOT(onValueChanged(const QString &)));

                QSpinBox* spinBox = dynamic_cast<QSpinBox*>(curWidget);
                if(spinBox)
                    connect(spinBox,SIGNAL(valueChanged( const QString & )),
                            this,SLOT(onValueChanged(const QString &)));

                QScienceSpinBox* doubleSpinBox = dynamic_cast<QScienceSpinBox*>(curWidget);
                if(doubleSpinBox)
                    connect(doubleSpinBox,SIGNAL(valueChanged( const QString & )),
                            this,SLOT(onValueChanged(const QString &)));

                QCheckBox* checkBox = dynamic_cast<QCheckBox*>(curWidget);
                if(checkBox)
                    connect(checkBox,SIGNAL(stateChanged(int)),
                            this,SLOT(onCheckChanged(int)));

                QLineEdit* lineEdit = dynamic_cast<QLineEdit*>(curWidget);
                if(lineEdit)
                    connect(lineEdit,SIGNAL(editingFinished()),
                            this,SLOT(onLineEditValueChanged()));
            }
        }
    }
}
void TextZone::createActions()
{
    undoAct = new QAction(QIcon(":/pics/edit-undo.png"),tr("&Undo"), this);
    undoAct->setShortcuts(QKeySequence::Undo);
    undoAct->setStatusTip(tr("Undo the last operation"));
    connect(undoAct, SIGNAL(triggered()), this, SLOT(undo()));

    redoAct = new QAction(QIcon(":/pics/edit-redo.png"),tr("&Redo"), this);
    redoAct->setShortcuts(QKeySequence::Redo);
    redoAct->setStatusTip(tr("Redo the last operation"));
    connect(redoAct, SIGNAL(triggered()), this, SLOT(redo()));

    cutAct = new QAction(QIcon(":/pics/edit-cut.png"),tr("Cu&t"), this);
    cutAct->setShortcuts(QKeySequence::Cut);
    cutAct->setStatusTip(tr("Cut the current selection's contents to the "
                            "clipboard"));
    connect(cutAct, SIGNAL(triggered()), this, SLOT(cut()));

    copyAct = new QAction(QIcon(":/pics/edit-copy.png"),tr("&Copy"), this);
    copyAct->setShortcuts(QKeySequence::Copy);
    copyAct->setStatusTip(tr("Copy the current selection's contents to the "
                             "clipboard"));
    connect(copyAct, SIGNAL(triggered()), this, SLOT(copy()));

    pasteAct = new QAction(QIcon(":/pics/edit-paste.png"),tr("&Paste"), this);
    pasteAct->setShortcuts(QKeySequence::Paste);
    pasteAct->setStatusTip(tr("Paste the clipboard's contents into the current "
                              "selection"));
    connect(pasteAct, SIGNAL(triggered()), this, SLOT(paste()));

    pasteWithoutFormattingAct = new QAction(QIcon(":/pics/edit-paste.png"),tr("&Paste Unformatted"), this);
    pasteWithoutFormattingAct->setStatusTip(tr("Paste without formatting the clipboard's contents into the current "
                                               "selection"));
    QList<QKeySequence> klist;
    klist.append(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_V));
    pasteWithoutFormattingAct->setShortcuts(klist);
    connect(pasteWithoutFormattingAct, SIGNAL(triggered()), this, SLOT(pasteWithoutFormatting()));

    boldAct = new QAction(QIcon(":/pics/format-text-bold.png"),tr("&Bold"), this);
    boldAct->setCheckable(true);
    boldAct->setShortcuts(QKeySequence::Bold);
    boldAct->setStatusTip(tr("Make the text bold"));
    connect(boldAct, SIGNAL(triggered(bool)), this, SLOT(bold(bool)));

    QFont boldFont = boldAct->font();
    boldFont.setBold(true);
    boldAct->setFont(boldFont);

    italicAct = new QAction(QIcon(":/pics/format-text-italic.png"),tr("&Italic"), this);
    italicAct->setCheckable(true);
    italicAct->setShortcuts(QKeySequence::Italic);
    italicAct->setStatusTip(tr("Make the text italic"));
    connect(italicAct, SIGNAL(triggered(bool)), this, SLOT(italic(bool)));

    QFont italicFont = italicAct->font();
    italicFont.setItalic(true);
    italicAct->setFont(italicFont);

    spellcheckAct = new QAction(QIcon(":/pics/tools-check-spelling.png"),tr("&Check Spelling"), this);
    spellcheckAct->setCheckable(true);
    //    spellcheckAct->setShortcuts(QKeySequence::Italic);
    spellcheckAct->setStatusTip(tr("Verify your spelling"));
    connect(spellcheckAct, SIGNAL(triggered(bool)), this, SIGNAL(activateSpellcheckSignal(bool)));

    addToUserDictAct = new QAction(QIcon(""),tr("&Add to Dictionary"), this);
    //    addToUserDictAct->setShortcuts(QKeySequence::Paste);
    addToUserDictAct->setStatusTip(tr("Add the current word selection to the project dictionary"));
    connect(addToUserDictAct, SIGNAL(triggered()), this, SLOT(addToUserDictionary()));

    addHyphenToUserDictAct = new QAction(QIcon(""),tr("Add &Hyphen to Dictionary"), this);
    //    addToUserDictAct->setShortcuts(QKeySequence::Paste);
    addHyphenToUserDictAct->setStatusTip(tr("Add the selected hyphenated word to the project dictionary"));
    connect(addHyphenToUserDictAct, SIGNAL(triggered()), this, SLOT(addHyphenToUserDictionary()));

    removeFromUserDictAct = new QAction(QIcon(""),tr("&Remove from Dictionary"), this);
    //    addToUserDictAct->setShortcuts(QKeySequence::Paste);
    removeFromUserDictAct->setStatusTip(tr("Remove the current word selection from the project dictionary"));
    connect(removeFromUserDictAct, SIGNAL(triggered()), this, SLOT(removeFromUserDictionary()));


    createEditWidget();
    QWidgetAction *editWidgetAct = new QWidgetAction(this);
    editWidgetAct->setDefaultWidget(editWidget);

    manageStylesAct = new QAction(/*QIcon(":/pics/edit-find-replace.png"),*/tr("Manage &Styles"),this);
    // aboutAct->setShortcut(QKeySequence::Quit);
    manageStylesAct->setToolTip(tr("Manage the styles"));
    connect(manageStylesAct, SIGNAL(triggered()), this, SIGNAL(manageStylesSignal()));

    stylesGroup = new QMenu(tr("&Styles"),this);
    stylesGroup->addAction(editWidgetAct);
    stylesGroup->addAction(manageStylesAct);


    //    setLineSpacingAct = new QAction(tr("Set &Line Spacing..."), this);
    //    setLineSpacingAct->setStatusTip(tr("Change the gap between the lines of a "
    //                                       "paragraph"));
    //    connect(setLineSpacingAct, SIGNAL(triggered()), this, SLOT(setLineSpacing()));

    //    setParagraphSpacingAct = new QAction(tr("Set &Paragraph Spacing..."), this);
    //    setParagraphSpacingAct->setStatusTip(tr("Change the gap between paragraphs"));
    //    connect(setParagraphSpacingAct, SIGNAL(triggered()),
    //            this, SLOT(setParagraphSpacing()));

    //    leftAlignAct = new QAction(QIcon(":/pics/format-justify-left.png"),tr("&Left Align"), this);
    //    leftAlignAct->setCheckable(true);
    //    leftAlignAct->setShortcut(tr("Ctrl+L"));
    //    leftAlignAct->setStatusTip(tr("Left align the selected text"));
    //    connect(leftAlignAct, SIGNAL(triggered(bool)), this, SLOT(leftAlign(bool)));

    //    rightAlignAct = new QAction(QIcon(":/pics/format-justify-right.png"),tr("&Right Align"), this);
    //    rightAlignAct->setCheckable(true);
    //    rightAlignAct->setShortcut(tr("Ctrl+R"));
    //    rightAlignAct->setStatusTip(tr("Right align the selected text"));
    //    connect(rightAlignAct, SIGNAL(triggered(bool)), this, SLOT(rightAlign(bool)));

    //    justifyAct = new QAction(QIcon(":/pics/format-justify-fill.png"),tr("&Justify"), this);
    //    justifyAct->setCheckable(true);
    //    justifyAct->setShortcut(tr("Ctrl+J"));
    //    justifyAct->setStatusTip(tr("Justify the selected text"));
    //    connect(justifyAct, SIGNAL(triggered(bool)), this, SLOT(justify(bool)));

    //    centerAct = new QAction(QIcon(":/pics/format-justify-center.png"),tr("&Center"), this);
    //    centerAct->setCheckable(true);
    //    centerAct->setShortcut(tr("Ctrl+E"));
    //    centerAct->setStatusTip(tr("Center the selected text"));
    //    connect(centerAct, SIGNAL(triggered(bool)), this, SLOT(center(bool)));

    //    alignmentGroup = new QMenu(tr("&Alignment"),this);
    //    alignmentGroup->addAction(leftAlignAct);
    //    alignmentGroup->addAction(rightAlignAct);
    //    alignmentGroup->addAction(justifyAct);
    //    alignmentGroup->addAction(centerAct);
    //    leftAlignAct->setChecked(true);




}