Esempio n. 1
0
/** \brief add Widgets to a Container
 *  \details This accepts multiple Widgets.
 *
 */
int UI_Lua::add(lua_State *L){
	int n = lua_gettop(L);  // Number of arguments
	if (n >= 2){
		Container* outer = (Container*)checkWidget(L,1);
		luaL_argcheck(L, outer->GetMask() & WIDGET_CONTAINER, 1, "`Container' expected.");

		for(int i=2; i<=n; i++){
			Widget* inner = checkWidget(L,i);
			outer->AddChild( inner );
		}
	} else {
		luaL_error(L, "Got %d arguments expected 2 or more (self, widget [...])", n);
	}
	return 0;
}
Esempio n. 2
0
/** \brief Set the Form Button for 'Enter' keys to thie Container
 */
int UI_Lua::setFormButton(lua_State *L){
	int n = lua_gettop(L);  // Number of arguments
	if (n == 2){
		Container* container = (Container*)checkWidget(L,1);
		luaL_argcheck(L, container->GetMask() & WIDGET_CONTAINER, 1, "`Container' expected.");

		Button* button = (Button*)checkWidget(L,2);
		luaL_argcheck(L, button->GetMask() & WIDGET_BUTTON, 2, "`Button' expected.");

		container->SetFormButton( button );
	} else {
		luaL_error(L, "Got %d arguments expected 2 (self, picname)", n);
	}
	return 0;
}
Esempio n. 3
0
/**\brief Append an option to this Dropdown
 * \note Tables of strings will be flattened and added
 */
int UI_Lua::AddOption(lua_State *L){
	int n = lua_gettop(L);  // Number of arguments
	if (n < 2)
		return luaL_error(L, "Got %d arguments expected at least 2 (self OPTION [OPTION ...])", n);

	Widget *widget = checkWidget(L, 1);
	luaL_argcheck(L, widget->GetMask() & WIDGET_DROPDOWN, 1, "`Dropdown' expected.");
	Dropdown *dropdown = (Dropdown*)widget;

	// Add the options
	for(int arg = 2; arg <= n; ++arg){
		if( lua_istable(L, arg) ) {
			// Tables can be lists of strings
			list<string>::iterator i;
			list<string> values = Lua::getStringListField( arg );
			for(i = values.begin(); i != values.end(); ++i) {
				dropdown->AddOption( (*i) );
			}
		} else {
			// Everything else is converted into a string
			string option = lua_tostring(L, arg);
			dropdown->AddOption( option );
		}
	}

	return 0;
}
Esempio n. 4
0
/** \brief Test if a checkbox is checked.
 *  \returns true if the Checkbox is checked.
 */
int UI_Lua::IsChecked(lua_State *L){
	int n = lua_gettop(L);  // Number of arguments
	if (n != 1)
		return luaL_error(L, "Got %d arguments expected 1 (self)", n);

	Checkbox *box = (Checkbox*)checkWidget(L,1);
	luaL_argcheck(L, box->GetMask() & WIDGET_CHECKBOX, 1, "`Checkbox' expected.");

	lua_pushboolean(L, (int) box->IsChecked() );

	return 1;
}
Esempio n. 5
0
/** \brief Change the Image in a Picture Widget
 *
 */
int UI_Lua::setPicture(lua_State *L){
	int n = lua_gettop(L);  // Number of arguments
	if (n == 2){
		Picture* pic = (Picture*)checkWidget(L,1);
		luaL_argcheck(L, pic->GetMask() & WIDGET_PICTURE, 1, "`Picture' expected.");
		string picname = luaL_checkstring (L, 2);
		pic->Set( picname );
	
	} else {
		luaL_error(L, "Got %d arguments expected 2 (self, picname)", n);
	}
	return 0;
}
Esempio n. 6
0
/**\brief Get the Position and size of a Widget
 */
int UI_Lua::GetEdges(lua_State *L){
	int n = lua_gettop(L);  // Number of arguments
	if (n != 1)
		return luaL_error(L, "Got %d arguments expected 1 (self)", n);

	Widget *widget = checkWidget(L,1);
	lua_pushinteger(L, widget->GetX() );
	lua_pushinteger(L, widget->GetY() );
	lua_pushinteger(L, widget->GetW() );
	lua_pushinteger(L, widget->GetH() );

	return 4;
}
Esempio n. 7
0
/** \brief Set a Slider Value
 */
int UI_Lua::setSliderValue(lua_State *L){
	int n = lua_gettop(L);  // Number of arguments
	if (n != 2)
		return luaL_error(L, "Got %d arguments expected 2 (self, value)", n);
	
	Slider *slide = (Slider*)checkWidget(L,1);
	luaL_argcheck(L, slide->GetMask() & WIDGET_SLIDER, 1, "`Checkbox' expected.");

	float percent= (float)lua_tonumber(L, 2);

	slide->SetVal(percent);
	
	return 0;
}
Esempio n. 8
0
/** \brief Check or Uncheck a checkbox
 */
int UI_Lua::setChecked(lua_State *L){
	int n = lua_gettop(L);  // Number of arguments
	if (n != 2)
		return luaL_error(L, "Got %d arguments expected 2 (self, value)", n);

	Checkbox *box = (Checkbox*)checkWidget(L,1);
	luaL_argcheck(L, box->GetMask() & WIDGET_CHECKBOX, 1, "`Checkbox' expected.");

	bool checked = lua_toboolean(L, 2) != 0;

	box->Set(checked);

	return 0;
}
Esempio n. 9
0
/** \brief Add widgets to the UI.
 *
 *  \details This accepts multiple Widgets.
 */
int UI_Lua::addWidget(lua_State *L) {
	int n = lua_gettop(L);  // Number of arguments
	if (n == 0){
		return luaL_error(L, "Got %d arguments expected 1 (widgets, ...)", n);
	}

	for(int i=1; i<=n; i++){
		Widget* widget = checkWidget(L,i);
		luaL_argcheck(L, false == UI::IsAttached( widget ), i, "This Widget is already attached to the User Interface.");
		UI::Add(widget);
	}

	return 0;
}
Esempio n. 10
0
/** \brief Rotate a Picture Widget
 *
 */
int UI_Lua::rotatePicture(lua_State *L){
	int n = lua_gettop(L);  // Number of arguments
	if (n != 2)
		return luaL_error(L, "Got %d arguments expected 2 (self, angle )", n);

	Picture* pic = (Picture*)checkWidget(L,1);
	luaL_argcheck(L, pic->GetMask() & WIDGET_PICTURE, 1, "`Picture' expected.");

	double angle = luaL_checknumber (L, 2);

	pic->Rotate(angle);

	return 1;
}
Esempio n. 11
0
/*!
    Inserts \a widget at position \a index, with stretch factor \a
    stretch and alignment \a alignment. If \a index is negative, the
    widget is added at the end.

    The stretch factor applies only in the \l{direction()}{direction}
    of the QBoxLayout, and is relative to the other boxes and widgets
    in this QBoxLayout. Widgets and boxes with higher stretch factors
    grow more.

    If the stretch factor is 0 and nothing else in the QBoxLayout has
    a stretch factor greater than zero, the space is distributed
    according to the QWidget:sizePolicy() of each widget that's
    involved.

    The alignment is specified by \a alignment. The default alignment
    is 0, which means that the widget fills the entire cell.

    \sa addWidget(), insertItem()
*/
void QBoxLayout::insertWidget(int index, QWidget *widget, int stretch,
                              Qt::Alignment alignment)
{
    Q_D(QBoxLayout);
    if (!checkWidget(this, widget))
         return;
    addChildWidget(widget);
    if (index < 0)                                // append
        index = d->list.count();
    QWidgetItem *b = QLayoutPrivate::createWidgetItem(this, widget);
    b->setAlignment(alignment);
    QBoxLayoutItem *it = new QBoxLayoutItem(b, stretch);
    d->list.insert(index, it);
    invalidate();
}
Esempio n. 12
0
/** \brief Close a Widget
 *
 *  \details When passed no arguments, it will close all Widgets.
 *           When passed one argument, it will close that Widget.
 */
int UI_Lua::close(lua_State *L){
	int n = lua_gettop(L);  // Number of arguments

	if (n == 0) {
		UI::Close();
	}
	else if(n == 1) {
		Widget* widget = checkWidget(L,1);
		luaL_argcheck(L, UI::IsAttached( widget ), 1, "This Widget is not attached to the User Interface. It may have already been closed. Use UI.search to confirm check if a Widget still exists.");

		UI::Close( widget );
	}
	else {
		luaL_error(L, "Got %d arguments expected 0 or 1 ([widget])", n);
	}
	return 0;
}
void DesignerEventHandler::onMousePress( QMouseEvent * e )
{
  QWidget * w = checkWidget (e->pos());

//qDebug () << "mouse press: "<<w;

  context_widget = dynamic_cast<VtlWidget*>(w);

  if (dynamic_cast<VtlWidget*>(w)) {
    if (e->state() & Qt::ShiftModifier) {
      if (selected_widgets.indexOf((VtlWidget*)w) == -1) {
        addWidgetToSelection((VtlWidget *)w);
      }
      else if (e->button() == Qt::LeftButton) {
        removeWidgetFromSelection((VtlWidget*)w);
      }
    }
    else if (selected_widgets.isEmpty() || selected_widgets.indexOf((VtlWidget*)w) == -1) {
      clearSelection();
      addWidgetToSelection((VtlWidget*)w);
    }

    if (e->button() & Qt::LeftButton) {
      widgetPressed = true;
      widgetGeom = QRect(w->pos(), w->size());
      cursorPos = e->pos();
      oldCursorPos = cursorPos;
      savedCursorPos = cursorPos;
      oldPositions.clear();
      for (SWPtrList::const_iterator iter = selected_widgets.begin(); iter != selected_widgets.end(); ++iter) {
        oldPositions.append(QVariant((*iter)->pos()));
      }
    }
  }
  else if (dynamic_cast<VtlWindow*>(w)) {
    if (e->state() ^ Qt::ShiftModifier) {
      clearSelection();
    }

    if (e->button() & Qt::LeftButton) {
      beginSelRectangle(e->pos());
      drawSelRect = true;
    }
  }
}
Esempio n. 14
0
/** \brief Get the Text Value of a Widget
 *  \todo Currently this only supports Labels and Textboxes, but it shouls support more Widget types.
 *  \returns string or nil
 */
int UI_Lua::GetText(lua_State *L){
	int n = lua_gettop(L);  // Number of arguments
	if (n != 1)
		return luaL_error(L, "Got %d arguments expected 1 (self)", n);

	Widget *widget= checkWidget(L, 1);

	int mask = widget->GetMask();
	mask &= ~WIDGET_CONTAINER; // Turn off the Container flag.
	switch( mask ) {
		// These Widget types currently support setText
		case WIDGET_LABEL:
			lua_pushstring(L, ((Label*)(widget))->GetText().c_str() );
			return 1;
			break;
		case WIDGET_TEXTBOX:
			lua_pushstring(L, ((Textbox*)(widget))->GetText().c_str() );
			return 1;
			break;
		case WIDGET_DROPDOWN:
			lua_pushstring(L, ((Dropdown*)(widget))->GetText().c_str() );
			return 1;
			break;
		case WIDGET_BUTTON:
			lua_pushstring(L, ((Button*)(widget))->GetText().c_str() );
			return 1;
			break;
		// TODO These Widget Types do not currently accept getText, but they should.
		case WIDGET_TAB:
		case WIDGET_WINDOW:
			return luaL_error(L, "Epiar does not currently calling getText on Widgets of type '%s'.", (widget)->GetType().c_str() );
			break;

		// These Widget Types can't accept setText.
		case WIDGET_TABS:
		case WIDGET_FRAME:
		case WIDGET_SLIDER:
		case WIDGET_PICTURE:
		case WIDGET_CHECKBOX:
		case WIDGET_SCROLLBAR:
		case WIDGET_CONTAINER:
		default:
			return luaL_error(L, "Cannot getText to Widget of type '%s'.", (widget)->GetType().c_str() );
	}
}
Esempio n. 15
0
/** \brief Resize a Widget
 *
 */
int UI_Lua::move(lua_State *L){
	int n = lua_gettop(L);  // Number of arguments
	if (n != 5)
		return luaL_error(L, "Got %d arguments expected 1 (self, x,y,w,h)", n);
	
	// Get the new postition
	Widget* widget = checkWidget(L, 1);
	int x = luaL_checkinteger(L, 2);
	int y = luaL_checkinteger(L, 3);
	int w = luaL_checkinteger(L, 4);
	int h = luaL_checkinteger(L, 5);

	// Move the widget
	widget->SetX( x );
	widget->SetY( y );
	widget->SetW( w );
	widget->SetH( h );

	return 0;
}
Esempio n. 16
0
/** \brief Change the Background of a Picture Widget
 *
 */
int UI_Lua::setBackground(lua_State *L){
	int n = lua_gettop(L);  // Number of arguments
	if ((n == 4) || (n == 5)){
		Picture* pic = (Picture*)checkWidget(L,1);
		luaL_argcheck(L, pic->GetMask() & WIDGET_PICTURE, 1, "`Picture' expected.");

		float r = luaL_checknumber (L, 2);
		float g = luaL_checknumber (L, 3);
		float b = luaL_checknumber (L, 4);
		float a = pic->GetAlpha();
		if( n == 5 ) {
			a = luaL_checknumber (L, 5);
		}

		pic->SetColor( r, g, b, a );
	
	} else {
		luaL_error(L, "Got %d arguments expected 2 (self, picname)", n);
	}
	return 0;
}
void DesignerEventHandler::onContextMenu(QContextMenuEvent * e)
{
  QMenu * menu = new QMenu(parentWidget);

  QAction * copy_action     = menu->addAction(tr("Copy"), this, SLOT(onCopy()));
  menu->addAction(tr("Paste"), this, SLOT(onPaste()));
  QAction * delete_action   = menu->addAction(tr("Delete"), this, SLOT(onDelete()));
  QAction * delete_with_s_action   = menu->addAction(tr("Delete with sourcers"), this, SLOT(onDeleteWithSourcers()));
  QMenu* go = menu->addMenu(tr("Geometry operations"));
  go->addAction(tr("Align left") , this, SLOT(onAlignLeft()));
  go->addAction(tr("Align top")  , this, SLOT(onAlignTop()));
  go->addAction(tr("Align right"), this, SLOT(onAlignRight()));
  go->addAction(tr("Align bottom"),this, SLOT(onAlignBottom()));
  go->addAction(tr("Align vertical"),this, SLOT(onAlignVertical()));
  go->addAction(tr("Align horisontal"), this, SLOT (onAlignHorizontal()) );
  go->addAction(tr("Queue x"), this, SLOT (onQuequeX()) );
  go->addAction(tr("Queue y"), this, SLOT (onQuequeY()) );
  go->insertSeparator();
  go->addAction(tr("Same width"), this, SLOT(onSameWidth()));
  go->addAction(tr("Same height"), this, SLOT(onSameHeight()));
  QMenu* popupWindows = menu->addMenu(tr("Popup windows"));
  QMenu* leftButtonPW = popupWindows->addMenu(tr("Left button"));
  QAction * left_pw_add_action    = leftButtonPW->addAction( tr("Add"), this, SLOT(onLeftPwAdd()));
  QAction * left_pw_copy_action   = leftButtonPW->addAction( tr("Copy"), this, SLOT(onLeftPwCopy()));
  leftButtonPW->addAction( tr("Paste"), this, SLOT(onLeftPwPaste()));
  QAction * left_pw_delete_action = leftButtonPW->addAction( tr("Delete"), this, SLOT(onLeftDelete()));
  QMenu* rightButtonPW = popupWindows->addMenu (tr ("Right button"));
  QAction * right_pw_add_action    = rightButtonPW->addAction( tr("Add"), this, SLOT(onRightPwAdd()));
  QAction * right_pw_copy_action   = rightButtonPW->addAction( tr("Copy"), this, SLOT(onRightPwCopy()));
  rightButtonPW->addAction( tr("Paste"), this, SLOT(onRightPwPaste()));
  QAction * right_pw_delete_action = rightButtonPW->addAction( tr("Delete"), this, SLOT(onRightDelete()));

  QAction* show_properties_action = menu->addAction(tr("Properties"), this, SLOT(showProps()));
  QFont f = show_properties_action->font();
  f.setBold(true);
  show_properties_action->setFont(f);

  menu->addAction( tr("Export lists"), this, SLOT(onExportLists()) );
  //menu->insertSeparator();
  QMenu * predef = menu->addMenu ("Predef windows");
  QStringList names = PredefPw::Factory::availableNames();
  for (QStringList::iterator iter = names.begin(); iter != names.end(); ++iter ) {
    QAction * a = predef->addAction (*iter);
    //a->setMenu (predef);
    a->setData (12345);
  }
  
  menu->addAction ( "Find sourcer", this, SLOT (onFindSourcerByWidget() ) );
   
  if (selected_widgets.count( ) == 0 ){
    copy_action->setEnabled(false);
    delete_action->setEnabled(false);
    delete_with_s_action->setEnabled(false);
    go->setEnabled(false);
    popupWindows->setEnabled(false);
  }
  else {
    VtlWidget * w = (VtlWidget*)checkWidget(e->pos());
    if (w) {
      if (w->isLbPopupCreated()) {
        left_pw_add_action->setEnabled(false);
      }
      else {
        left_pw_copy_action->setEnabled(false);
        left_pw_delete_action->setEnabled(false);
      }
      if (w->isRbPopupCreated()) {
        right_pw_add_action->setEnabled(false);
      }
      else {
        right_pw_copy_action->setEnabled(false);
        right_pw_delete_action->setEnabled(false);
      }
    }
  }
  
  if ( context_widget )
    context_widget->prepareContextMenu (menu);
  
  if (e->state() & Qt::ControlModifier )
    control_modifier = true;
    
  QAction * a = menu->exec(e->globalPos());
  
  control_modifier = false;
  
  if ( a && a->data().toInt() == 12345 ) {
    QMessageBox box ( vtl::app );
    QAbstractButton * left_btn  = box.addButton ("Left" , QMessageBox::ActionRole );
    QAbstractButton * right_btn = box.addButton ("Right", QMessageBox::ActionRole );
    box.setWindowTitle ("Mouse button?");
    
    box.exec ();
    if ( box.clickedButton()     == left_btn ) {
      for (SWPtrList::iterator iter = selected_widgets.begin(); iter != selected_widgets.end(); ++iter )  {
         (*iter)->createLbPredefPw ( a->text() );
      }
    }
    else if (box.clickedButton() == right_btn ) {
      for (SWPtrList::iterator iter = selected_widgets.begin(); iter != selected_widgets.end(); ++iter )  {
         (*iter)->createRbPredefPw ( a->text() );
      }
    }
  }

  delete menu;
}