Exemple #1
0
static int
qtuiloader_pluginPaths(lua_State *L)
{
  QUiLoader *loader = luaQ_checkqobject<QUiLoader>(L, 1);
  luaQ_pushqt(L, QVariant(loader->pluginPaths()));
  return 1;
}
Exemple #2
0
static int 
qsvgrenderer_new(lua_State *L)
{
  QVariant v = luaQ_toqvariant(L, 1, QMetaType::QString);
  if (v.type() == QVariant::String)
    {
      QObject *p = luaQ_optqobject<QObject>(L, 2);
      luaQ_pushqt(L, new QSvgRenderer(v.toString(), p), !p);
    }
  else
    {
      QObject *p = luaQ_optqobject<QObject>(L, 1);
      luaQ_pushqt(L, new QSvgRenderer(p), !p);
    }
  return 1;
}
Exemple #3
0
static int
qtuiloader_availableWidgets(lua_State *L)
{
  QUiLoader *loader = luaQ_checkqobject<QUiLoader>(L, 1);
  luaQ_pushqt(L, QVariant(loader->availableWidgets()));
  return 1;
}
Exemple #4
0
static int 
qtluasvggenerator_new(lua_State *L)
{
  QVariant v = luaQ_toqvariant(L, 1, QMetaType::QString);
  if (v.type() == QVariant::String)
    {
      QObject *p = luaQ_optqobject<QObject>(L, 2);
      luaQ_pushqt(L, new QtLuaSvgGenerator(v.toString(), p), !p);
    }
  else
    {
      QObject *p = luaQ_optqobject<QObject>(L, 1);
      luaQ_pushqt(L, new QtLuaSvgGenerator(p), !p);
    }
  return 1;
}
Exemple #5
0
static int 
qsvgwidget_renderer(lua_State *L)
{
  QSvgWidget *w = luaQ_checkqobject<QSvgWidget>(L, 1);
  luaQ_pushqt(L, w->renderer());
  return 1;
}
Exemple #6
0
static int 
qsvgwidget_new(lua_State *L)
{
  QVariant v = luaQ_toqvariant(L, 1, QMetaType::QString);
  if (v.type() == QVariant::String)
    {
      QWidget *p = luaQ_optqobject<QWidget>(L, 2);
      luaQ_pushqt(L, new QSvgWidget(v.toString(), p), !p);
    }
  else
    {
      QWidget *p = luaQ_optqobject<QWidget>(L, 1);
      luaQ_pushqt(L, new QSvgWidget(p), !p);
    }
  return 1;
}
Exemple #7
0
static int
qtuiloader_load(lua_State *L)
{
  // this
  QUiLoader *loader = luaQ_checkqobject<QUiLoader>(L, 1);
  // file
  QFile afile;
  QIODevice *file = qobject_cast<QIODevice*>(luaQ_toqobject(L, 2));
  if (!file && lua_isstring(L, 2))
    {
      file = &afile;
      const char *fn = lua_tostring(L, 2);
      afile.setFileName(QFile::decodeName(fn));
      if (! afile.open(QIODevice::ReadOnly))
        luaL_error(L,"cannot open file '%s' for reading (%s)", 
                   fn, afile.errorString().toLocal8Bit().constData() );
    }
  else if (!file)
    {
      file = &afile;
      void *udata = luaL_checkudata(L, 2, LUA_FILEHANDLE);
      if (! afile.open(*(FILE**)udata, QIODevice::ReadOnly))
        luaL_error(L,"cannot use stream for reading (%s)", 
                   afile.errorString().toLocal8Bit().constData() );
    }
  // parent
  QWidget *parent = luaQ_optqobject<QWidget>(L, 3);
  // load
  QWidget *w = loader->load(file, parent);
  luaQ_pushqt(L, w, !parent);
  return 1;
}
Exemple #8
0
static int
qtimer_new(lua_State *L)
{
  QObject *parent = luaQ_optqobject<QObject>(L, 1);
  QTimer *t = new QTimer(parent);
  luaQ_pushqt(L, t, !parent);
  return 1;
}
Exemple #9
0
static int
qtuiloader_createActionGroup(lua_State *L)
{
  QUiLoader *loader = luaQ_checkqobject<QUiLoader>(L, 1);
  QObject *parent = luaQ_optqobject<QObject>(L, 2, 0);
  QString name = luaQ_optqvariant<QString>(L, 3, QString());
  luaQ_pushqt(L, loader->createActionGroup(parent, name), !parent);
  return 1;
}
Exemple #10
0
static int qobject_children(lua_State *L)
{
  QObject *w = luaQ_checkqobject<QObject>(L, 1);
  QVariantList v;
  QObjectPointer p;
  foreach(p, w->children())
    v << qVariantFromValue<QObjectPointer>(p);
  luaQ_pushqt(L, v);
  return 1;
}
Exemple #11
0
static int 
qtuiloader_new(lua_State *L)
{
  if (QApplication::type() == QApplication::Tty)
    luaL_error(L, "Graphics have been disabled (running with -nographics)");
  QObject *parent = luaQ_optqobject<QObject>(L, 1, 0);
  QUiLoader *q = new QUiLoader(parent);
  luaQ_pushqt(L, q, !parent);
  return 1;
}
Exemple #12
0
static int
qtuiloader_createLayout(lua_State *L)
{
  QUiLoader *loader = luaQ_checkqobject<QUiLoader>(L, 1);
  QString classname = luaQ_checkqvariant<QString>(L, 2);
  QObject *parent = luaQ_optqobject<QObject>(L, 3, 0);
  QString name = luaQ_optqvariant<QString>(L, 4, QString());
  luaQ_pushqt(L, loader->createLayout(classname, parent, name), !parent);
  return 1;
}
Exemple #13
0
static int 
qtuiloader_new(lua_State *L)
{
  if (!qApp->arguments().contains(QString("-nographics")))
    luaL_error(L, "Graphics have been disabled (running with -nographics)");
  QObject *parent = luaQ_optqobject<QObject>(L, 1, 0);
  QUiLoader *q = new QUiLoader(parent);
  luaQ_pushqt(L, q, !parent);
  return 1;
}
Exemple #14
0
static int
qvariantlist_totable(lua_State *L)
{
  QVariantList l = luaQ_checkqvariant<QVariantList>(L, 1);
  lua_createtable(L, l.size(), 0);
  for (int i=0; i<l.size(); i++)
    {
      luaQ_pushqt(L, QVariant(l[i]));
      lua_rawseti(L, -2, i+1);
    }
  return 1;
}
Exemple #15
0
static int
qt_m__index(lua_State *L)
{
  const char *s = luaL_checkstring(L, 2);
  QtLuaEngine *engine = luaQ_engine(L);
  QObject *obj = engine->namedObject(s);
  if (obj)
    luaQ_pushqt(L, obj);
  else
    lua_pushnil(L);
  return 1;
}
Exemple #16
0
static int
qvariantmap_totable(lua_State *L)
{
  QVariantMap m = luaQ_checkqvariant<QVariantMap>(L, 1);
  lua_createtable(L, 0, 0);
  for (QVariantMap::const_iterator it=m.constBegin(); it!=m.constEnd(); ++it)
    {
      lua_pushstring(L, it.key().toLocal8Bit().constData());
      luaQ_pushqt(L, it.value());
      lua_rawset(L, -3);
    }
  return 1;
}
Exemple #17
0
int  
luaopen_qt(lua_State *L)
{
  const char *qt = luaL_optstring(L, 1, "qt");
  luaQ_pushqt(L);
  lua_pushvalue(L, -1);
  lua_setfield(L, LUA_GLOBALSINDEX, qt);
  luaL_register(L, qt, qt_lib);

  // add a metatable with __index
  lua_createtable(L, 0, 1);
  lua_pushcfunction(L, qt_m__index);
  lua_setfield(L, -2, "__index");
  lua_setmetatable(L, -2);

  // hooks for objects
#define HOOK(T, t) \
     lua_pushcfunction(L, t ## _hook);\
     luaQ_pushmeta(L, &T::staticMetaObject);\
     lua_call(L, 1, 0);
  
  HOOK(QObject, qobject)
  HOOK(QTimer, qtimer)
  HOOK(QtLuaEngine, no_delete)
  HOOK(QCoreApplication, no_delete)
#undef HOOK

  // hooks for qvariants
#define HOOK(T, t) \
     lua_pushcfunction(L, t ## _hook);\
     luaQ_pushmeta(L, QMetaType::T);\
     lua_call(L, 1, 0)
  
  HOOK(QStringList, qstringlist);
  HOOK(QVariantList, qvariantlist);
  HOOK(QVariantMap, qvariantmap);
  HOOK(QSize,qsize);
  HOOK(QSizeF,qsizef);
  HOOK(QPoint,qpoint);
  HOOK(QPointF,qpointf);
  HOOK(QRect,qrect);
  HOOK(QRectF,qrectf);
  HOOK(QLine,qline);
  HOOK(QLineF,qlinef);
#undef HOOK

  return 1;
}
Exemple #18
0
static int
qvariantlist_new(lua_State *L)
{
  QVariantList l;
  if (! lua_isnone(L, 1))
    {
      luaL_checktype(L, 1, LUA_TTABLE);
      int n = lua_objlen(L, 1);
      for (int i=1; i<=n; i++)
        {
          lua_rawgeti(L, 1, i);
          l += luaQ_toqvariant(L, -1);
          lua_pop(L, 1);
        }
    }
  luaQ_pushqt(L, QVariant(l));
  return 1;
}
Exemple #19
0
static int
qvariantmap_new(lua_State *L)
{
  QVariantMap l;
  if (! lua_isnone(L, 1))
    {
      luaL_checktype(L, 1, LUA_TTABLE);
      lua_pushnil(L);
      while (lua_next(L, -2))
        {
          QVariant k = luaQ_toqvariant(L, -2, QMetaType::QString);
          if (k.userType() != QMetaType::QString)
            luaL_error(L, "table element cannot be converted to a QString");
          l[k.toString()] = luaQ_toqvariant(L, -1);
          lua_pop(L, 1);
        }
    }
  luaQ_pushqt(L, QVariant(l));
  return 1;
}
Exemple #20
0
static int
qstringlist_new(lua_State *L)
{
  QStringList l;
  if (! lua_isnone(L, 1))
    {
      luaL_checktype(L, 1, LUA_TTABLE);
      int n = lua_objlen(L, 1);
      for (int i=1; i<=n; i++)
        {
          lua_rawgeti(L, 1, i);
          QVariant v = luaQ_toqvariant(L, -1, QMetaType::QString);
          if (v.userType() != QMetaType::QString)
            luaL_error(L, "table element cannot be converted to a QString");
          l += v.toString();
          lua_pop(L, 1);
        }
    }
  luaQ_pushqt(L, QVariant(l));
  return 1;
}
Exemple #21
0
int  
luaopen_qt(lua_State *L)
{
  const char *qt = luaL_optstring(L, 1, "qt");
  luaQ_pushqt(L);
  lua_pushvalue(L, -1);
  lua_setfield(L, LUA_GLOBALSINDEX, qt);
  luaL_register(L, qt, qt_lib);

  // Add qt_m_index in a metatable
  lua_createtable(L, 0, 1);
  lua_pushcfunction(L, qt_m__index);
  lua_setfield(L, -2, "__index");
  lua_setmetatable(L, -2);

  // Hide deleteLater in selected classes
  hide_deletelater(L, &QCoreApplication::staticMetaObject);
  hide_deletelater(L, &QtLuaEngine::staticMetaObject);

  return 1;
}
Exemple #22
0
static int qobject_parent(lua_State *L)
{
  QObject *w = luaQ_checkqobject<QObject>(L, 1);
  luaQ_pushqt(L, w->parent());
  return 1;
}
Exemple #23
0
static int
qttorch_qimage_fromtensor(lua_State *L)
{
  THTensor *Tsrc = (THTensor*)luaT_checkudata(L,1,torch_Tensor_id);
  long depth = 1;
  if ( Tsrc->nDimension == 3)
    depth = Tsrc->size[2];
  else if (Tsrc->nDimension != 2)
    luaL_error(L, "tensor must have 2 or 3 dimensions");
  if (depth != 1 && depth != 3 && depth != 4)
    luaL_error(L, "tensor third dimension must be 1, 3, or 4.");
  // create image
  if (Tsrc->size[0] >= INT_MAX || Tsrc->size[1] >= INT_MAX)
    luaL_error(L, "image is too large");
  int width = (int)(Tsrc->size[0]);
  int height = (int)(Tsrc->size[1]);
  QImage image(width, height, QImage::Format_ARGB32_Premultiplied);
  // fill image
  long s0 = Tsrc->stride[0];
  long s1 = Tsrc->stride[1];
  long s2 = (depth > 1) ? Tsrc->stride[2] : 0;
  double *tdata = THTensor_dataPtr(Tsrc);
  for(int j=0; j<height; j++) 
    {
      QRgb *ip = (QRgb*)image.scanLine(j);
      double *tp = tdata + s1 * j;
      if (depth == 1)
        {
          for (int i=0; i<width; i++)
            {
              int g = (int)(tp[0] * 255.0) & 0xff;
              tp += s0;
              ip[i] = qRgb(g,g,g);
            }
        }
      else if (depth == 3)
        {
          for (int i=0; i<width; i++)
            {
              int r = (int)(tp[0] * 255.0) & 0xff;
              int g = (int)(tp[s2] * 255.0) & 0xff;
              int b = (int)(tp[s2+s2] * 255.0) & 0xff;
              tp += s0;
              ip[i] = qRgb(r,g,b);
            }
        }
      else if (depth == 4)
        {
          for (int i=0; i<width; i++)
            {
              int a = (int)(tp[s2+s2+s2] * 255.0) & 0xff;
              int r = (int)(tp[0] * a) & 0xff;
              int g = (int)(tp[s2] * a) & 0xff;
              int b = (int)(tp[s2+s2] * a) & 0xff;
              tp += s0;
              ip[i] = qRgba(r,g,b,a);
            }
        }
    }
  // return
  luaQ_pushqt(L, image);
  return 1;
}
Exemple #24
0
int 
qluaide_new(lua_State *L)
{
  luaQ_pushqt(L, QLuaIde::instance());
  return 1;
}