// from: http://stackoverflow.com/questions/5298614/change-the-size-of-qt-dialogs-depending-on-the-platform void MainWindow::adjustAppearanceToOS(QWidget *rootWidget) { int fontSize = -1; #ifdef Q_OS_WIN fontSize = 8; #elif __APPLE__ fontSize = 12; #elif __linux fontSize = 11; #endif if (rootWidget == NULL) return; QObject *child = NULL; QObjectList Containers; QObject *container = NULL; QStringList DoNotAffect; // Make an exception list (Objects not to be affected) // DoNotAffect.append("widgetName"); // Append root to containers Containers.append(rootWidget); while (!Containers.isEmpty()) { container = Containers.takeFirst(); if (container != NULL) for (int i = 0; i < container->children().size(); i++) { child = container->children()[i]; if (!child->isWidgetType() || DoNotAffect.contains(child->objectName())) continue; if (child->children().size() > 0) Containers.append(child); // (if the object is not of the correct type, it will be NULL) QLabel *label = qobject_cast<QLabel *>(child); if (label != NULL) { label->setText(label->text().replace(QRegExp("font-size:.*;"), "")); QFont font = label->font(); font.setPointSize(fontSize); label->setFont(font); } } } }
QModelIndex MyIndexedModel::index(int row, int column, const QModelIndex &parent) const { QObject *parentObject; if (!parent.isValid()) parentObject = root; else parentObject = static_cast<QObject *>(parent.internalPointer()); if (row >= 0 && row < parentObject->children().size()) return createIndex(row, column, parentObject->children().at(row)); else return QModelIndex(); }
QModelIndex DemandScenarioModel::index(int row, int column, const QModelIndex &parent ) const { QObject *parentObject; if( !parent.isValid() ) parentObject = m_root; else parentObject = static_cast<QObject*>( parent.internalPointer() ); if( row < parentObject->children().count() ) return createIndex( row, column, parentObject->children().at( row ) ); else return QModelIndex(); }
static QObject *qChildHelper(const char *objName, const char *inheritsClass, bool recursiveSearch, const QObjectList &children) { if (children.isEmpty()) return 0; bool onlyWidgets = (inheritsClass && qstrcmp(inheritsClass, "QWidget") == 0); const QLatin1String oName(objName); for (int i = 0; i < children.size(); ++i) { QObject *obj = children.at(i); if (onlyWidgets) { if (obj->isWidgetType() && (!objName || obj->objectName() == oName)) return obj; } else if ((!inheritsClass || obj->inherits(inheritsClass)) && (!objName || obj->objectName() == oName)) return obj; if (recursiveSearch && (dynamic_cast<MythUIGroup *>(obj) != NULL) && (obj = qChildHelper(objName, inheritsClass, recursiveSearch, obj->children()))) return obj; } return 0; }
int MyIndexedModel::rowCount(const QModelIndex &parent) const { if (!parent.isValid()) return root->children().size(); QObject *parentObject = static_cast<QObject *>(parent.internalPointer()); return parentObject->children().size(); }
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; }
int ItemModel::rowCount(const QModelIndex& parent_) const { QObject* parentItem; if (!parent_.isValid()) parentItem = _impl->rootItem.get(); else parentItem = static_cast<QObject*>(parent_.internalPointer()); return parentItem->children().size(); }
int DemandScenarioModel::rowCount(const QModelIndex &parent ) const { QObject *parentObject; if( !parent.isValid() ) parentObject = m_root; else parentObject = static_cast<QObject*>( parent.internalPointer() ); return parentObject->children().count(); }
int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); QQmlApplicationEngine engine; QThread *cameraThread = new QThread(&app); cameraThread->start(); CameraCapturer *capturer = new CameraCapturer(); CameraImageProvider *imageProvider = new CameraImageProvider(); capturer->moveToThread(cameraThread); imageProvider->moveToThread(cameraThread); QObject::connect(capturer, static_cast<void (CameraCapturer::*)(QImage)>( &CameraCapturer::frame), imageProvider, &CameraImageProvider::setImage); engine.addImageProvider("camera", imageProvider); QThread *imageProcessingThread = new QThread(&app); imageProcessingThread->start(); SquintDetector *squintDetector = new SquintDetector(); squintDetector->moveToThread(imageProcessingThread); qRegisterMetaType<cv::Mat>("cv::Mat"); QObject::connect(capturer, static_cast<void (CameraCapturer::*)(cv::Mat)>( &CameraCapturer::frame), squintDetector, &SquintDetector::updateFrame); capturer->startCapture(16); engine.load(QUrl(QStringLiteral("qrc:///main.qml"))); QObject *mainWindow = engine.rootObjects()[0]; QObject *arkanoid = mainWindow->children()[0]; ArkanoidManager *aManager = new ArkanoidManager(arkanoid); QObject::connect(squintDetector, &SquintDetector::leftEye, aManager, &ArkanoidManager::leftEye); QObject::connect(squintDetector, &SquintDetector::rightEye, aManager, &ArkanoidManager::rightEye); QObject::connect(squintDetector, &SquintDetector::noEye, aManager, &ArkanoidManager::noEye); QObject::connect(squintDetector, &SquintDetector::bothEyes, aManager, &ArkanoidManager::bothEyes); QObject::connect(&app, &QGuiApplication::aboutToQuit, [=]() { // capturer->stopCapture(); // delete capturer; // delete imageProvider; // cameraThread->exit(); // delete squintDetector; // imageProcessingThread->exit(); qDebug() << "bye"; }); return app.exec(); }
void qt_object_node::init(QObject& obj) { auto name = obj.objectName(); if (!name.isEmpty()) set_name(obj.objectName().toStdString()); else { std::string str; const QMetaObject* mo = obj.metaObject(); while (str.empty()) { str = mo->className(); mo = mo->superClass(); if (!mo) break; } if (!str.empty()) { set_name(std::move(str)); } else { set_name("Object"); } } // Note : we create the childrens, and then lock the vector // because the children creation operation calls node_base::children() which // causes // double locking. decltype(m_children) children_vect; for (auto c : obj.children()) { children_vect.push_back( std::make_unique<qt_object_node>(*c, m_device, *this)); } for (int i = 0; i < obj.metaObject()->propertyCount(); i++) { children_vect.push_back(std::make_unique<qt_property_node>( obj, obj.metaObject()->property(i), m_device, *this)); } { write_lock_t lock{m_mutex}; std::move( children_vect.begin(), children_vect.end(), std::back_inserter(m_children)); } }
int QObjectTreeModel::rowCount( const QModelIndex& parent ) const { QObject* parentItem; if( parent.column() > 0 ) return 0; if( !parent.isValid() ) parentItem = m_root; else parentItem = static_cast<QObject*>( parent.internalPointer() ); return parentItem->children().count(); }
DlgPreferencePage* DlgPreferences::currentPage() { QObject* pObject = pagesWidget->currentWidget(); for (int i = 0; i < 2; ++i) { if (pObject == NULL) { return NULL; } QObjectList children = pObject->children(); if (children.isEmpty()) { return NULL; } pObject = children[0]; } return dynamic_cast<DlgPreferencePage*>(pObject); }
//---------------------------------------------------------------------------- ctkCmdLineModuleObjectTreeWalker::TokenType ctkCmdLineModuleObjectTreeWalker::readNext() { if (AtEnd) return NoToken; QObject* curr = 0; if (CurrentObject == 0) { curr = RootObject; if (setCurrent(curr)) return CurrentToken; } else { curr = CurrentObject; } while (true) { if (curr) { QObjectList children = curr->children(); QListIterator<QObject*> i(children); i.toBack(); while (i.hasPrevious()) { ObjectStack.push(i.previous()); } if (children.isEmpty()) { curr = 0; } else { curr = ObjectStack.pop(); if (setCurrent(curr)) return CurrentToken; } continue; } if (ObjectStack.isEmpty()) break; curr = ObjectStack.pop(); if (setCurrent(curr)) return CurrentToken; } AtEnd = true; CurrentObject = 0; CurrentToken = NoToken; return NoToken; }
QModelIndex DemandScenarioModel::parent(const QModelIndex &index) const { if( !index.isValid() ) return QModelIndex(); QObject *indexObject = static_cast<QObject*>( index.internalPointer() ); QObject *parentObject = indexObject->parent(); if( parentObject == m_root ) return QModelIndex(); QObject *grandParentObject = parentObject->parent(); return createIndex( grandParentObject->children().indexOf( parentObject ), 0, parentObject ); }
QModelIndex MyIndexedModel::parent(const QModelIndex &child) const { if (child == QModelIndex() || !child.isValid()) return QModelIndex(); QObject *object = static_cast<QObject *>(child.internalPointer()); QObject *parent = object->parent(); if (parent == root) return QModelIndex(); QObject *grandParent = parent->parent(); return createIndex(grandParent->children().indexOf(parent), 0, parent); }
static int lqtL_children(lua_State *L) { QObject* self = static_cast<QObject*>(lqtL_toudata(L, 1, "QObject*")); if (self == NULL) return luaL_argerror(L, 1, "expecting QObject*"); const QObjectList & children = self->children(); lua_newtable(L); for (int i=0; i < children.count(); i++) { QObject * object = children[i]; QString name = object->objectName(); if (!name.isEmpty() && lqtL_pushqobject(L, object)) { lua_setfield(L, -2, qPrintable(name)); } } return 1; }
QModelIndex ItemModel::index(const int row, const int column, const QModelIndex& parent_) const { if (!hasIndex(row, column, parent_)) return QModelIndex(); QObject* parentItem; if (!parent_.isValid()) parentItem = _impl->rootItem.get(); else parentItem = static_cast<QObject*>(parent_.internalPointer()); QObject* childItem = parentItem->children()[row]; if (childItem) return createIndex(row, column, childItem); return QModelIndex(); }
void KeyPreviewImpl::disableKeyPreview() { if(!enabled_) return; // QObject *obj = dynamic_cast<QObject*>(this); // QObjectList chlist = obj->children(); foreach(QObject *child, chlist) { if(child->isWidgetType()) { child->removeEventFilter(&filter_); } } // enabled_ = false; }
QModelIndex QObjectTreeModel::index( int row, int column, const QModelIndex& parent ) const { if( !hasIndex( row, column, parent ) ) return QModelIndex(); QObject* parentItem; if( !parent.isValid() ) parentItem = m_root; else parentItem = static_cast<QObject*>( parent.internalPointer() ); QObject* childItem = parentItem->children().at( row ); if( childItem ) return createIndex( row, column, childItem ); else return QModelIndex(); }
void QSAEditor::completeQObject(const QVector<QObject *> &objects, const QString &object, QVector<CompletionEntry> &res) { for ( int i = 0; i < objects.count(); i++ ) { QObject *qobj = objects[ i ]; if ( !qobj ) continue; // children QObjectList clist; if ( qobj == qApp ) clist = interpreter()->topLevelObjects() != 0 ? *((QObjectList*)interpreter()->topLevelObjects()) : QObjectList(); else clist = qobj->children(); if ( !clist.isEmpty() ) { for (int ci = 0; ci<clist.size(); ++ci) { const QObject *o = clist.at(ci); CompletionEntry c; c.type = o->isWidgetType() ? "widget" : "object"; c.text = o->objectName(); c.postfix2 = o->metaObject()->className(); if ( !c.postfix2.isEmpty() ) c.postfix2.prepend( QString::fromLatin1(" : ") ); res << c; } } QSObject qsobj = interpreter()->wrap( qobj ); int flags = 0; if ( i == 0 ) flags |= IncludeSuperClass; completeQMetaObject( qobj->metaObject(), object, res, flags, qsobj ); } }
void HbXmlLoaderBaseActions::addToObjectMap( QList<QObject *> objects ) { for ( int i = 0; i < objects.size(); i++ ) { QObject *obj = objects.at(i); QGraphicsWidget *widget = qobject_cast<QGraphicsWidget*>(obj); ObjectMapItem item; item.mObject = obj; item.mType = widget ? HbXml::WIDGET : HbXml::OBJECT; item.mOwned = false; mObjectMap.insert( obj->objectName(), item ); if ( widget ) { addToObjectMap( widget->childItems() ); } else { addToObjectMap( obj->children() ); } } }
QVariant ItemModel::data(const QModelIndex& index_, const int role) const { if (!index_.isValid()) return QVariant(); QObject* item = static_cast<QObject*>(index_.internalPointer()); switch (role) { case Qt::DisplayRole: return item->objectName(); case Qt::ToolTipRole: case Qt::UserRole: if (item->children().isEmpty()) return QVariant(); return QString::fromStdString( _impl->service.getHost(item->objectName().toStdString())); default: return QVariant(); } }
void QtHelpers::GenAdjustWidgetAppearanceToOS(QWidget *rootWidget) { if (rootWidget == NULL) return; QObject *child = NULL; QObjectList Containers; QObject *container = NULL; QStringList DoNotAffect; // Make an exception list (Objects not to be affected) DoNotAffect.append("aboutTitleLabel"); // about Dialog DoNotAffect.append("aboutVersionLabel"); // about Dialog DoNotAffect.append("aboutCopyrightLabel"); // about Dialog DoNotAffect.append("aboutUrlLabel"); // about Dialog DoNotAffect.append("aboutLicenseLabel"); // about Dialog // Set sizes according to OS: #ifdef __APPLE__ int ButtonHeight = 35; int cmbxHeight = 30; QFont cntrlFont("Myriad Pro", 14); QFont txtFont("Myriad Pro", 14); #elif _WIN32 // Win XP/7 int ButtonHeight = 24; int cmbxHeight = 20; QFont cntrlFont("MS Shell Dlg 2", 8); QFont txtFont("MS Shell Dlg 2", 8); #else int ButtonHeight = 24; int cmbxHeight = 24; QFont cntrlFont("Ubuntu Condensed", 10); QFont txtFont("Ubuntu", 10); #endif // Append root to containers Containers.append(rootWidget); while (!Containers.isEmpty()) { container = Containers.takeFirst(); if (container != NULL) { for (int ChIdx=0; ChIdx < container->children().size(); ChIdx++) { child = container->children()[ChIdx]; if (!child->isWidgetType() || DoNotAffect.contains(child->objectName())) continue; // Append containers to Stack for recursion if (child->children().size() > 0) Containers.append(child); else { // Cast child object to button and label // (if the object is not of the correct type, it will be NULL) QPushButton *button = qobject_cast<QPushButton *>(child); QLabel *label = qobject_cast<QLabel *>(child); QComboBox *cmbx = qobject_cast<QComboBox *>(child); QLineEdit *ln = qobject_cast<QLineEdit *>(child); QTreeWidget *tree = qobject_cast<QTreeWidget *>(child); QPlainTextEdit *plain = qobject_cast<QPlainTextEdit *>(child); QCheckBox *check = qobject_cast<QCheckBox *>(child); if (button != NULL) { button->setMinimumHeight(ButtonHeight); // Win button->setMaximumHeight(ButtonHeight); // Win button->setFont(cntrlFont); } else if (cmbx != NULL) { cmbx->setFont(cntrlFont); cmbx->setMaximumHeight(cmbxHeight); } else if (label != NULL) label->setFont(txtFont); else if (ln != NULL) ln->setFont(txtFont); else if (tree != NULL) { tree->header()->setFont(txtFont); } else if (plain != NULL) plain->setFont(txtFont); else if (check != NULL) check->setFont(txtFont); } } } } }
/*! Sets internal pointers to frequently used QML items, thus reducing the overhead of repeated searching for them at runtime. */ void CcfQmlBaseScenario::init() { if (mScenarioFile != "") { QStringList unitSideList; QObject *unitsLoader = child("unitsLoader"); QObject *unitItem = unitsLoader->property("unitsItem").value<QObject *>(); QObject *map = child("map"); if (unitItem->objectName() != "Campaign") { // This is a single scenario map->set("source", unitItem->getString("mapFile")); QObjectList tempList = unitItem->children(); for (int i = 0; i < tempList.count(); ++i) { CcfQmlBaseUnit *unit = ccfUnit(tempList.at(i)); if ((unit != 0) && (unit->property("unitIndex").isValid())) { unit->setUnitIndex(i); connect(this, &CcfQmlBaseScenario::togglePause, unit, &CcfQmlBaseUnit::togglePause); connect(unit, &CcfQmlBaseUnit::actionFinished, this, &CcfQmlBaseScenario::actionFinished); connect(unit, &CcfQmlBaseUnit::movementStateChange, this, &CcfQmlBaseScenario::handleUnitMovement); unitSideList.append(unit->getUnitSide()); mUnits.append(unit); } } mMapItem = map->property("mapItem").value<CcfQmlBaseMap *>(); if(mMapItem != 0) mMapItem->setUnits(mUnits); else mlogger->error("MapItem object was not properly initialised", "Robin Hood is a jerk"); } else { // This is a campaign // TODO: add some clever code here ;) } mScenarioState->setAvailableSides(unitSideList); mAimLine = item("aimLine"); mGameArea = item("gameArea"); mZoomArea = item("zoomArea"); mContextMenu = item("contextMenu"); mEffectsTimer = child("effectsTimer"); mRotationTimer = child("rotationTimer"); mFollowingTimer = child("followingTimer"); mMouseAreaMain = child("mouseAreaMain"); mRoster = findChild<CcfQmlBaseRosterMenu *>("roster"); mRoster->populateUnits(mUnits); connect(mContextMenu, SIGNAL(menuEntryClicked(QString)), this, SLOT(scheduleContextAction(QString))); connect(mRotationTimer, SIGNAL(triggered()), this, SLOT(updateAimLine())); connect(mEffectsTimer, SIGNAL(triggered()), this, SLOT(updateEffects())); connect(mFollowingTimer, SIGNAL(triggered()), this, SLOT(updateFollowingUnit())); connect(child("sceneUpdateTimer"), SIGNAL(triggered()), this, SLOT(updateUnitVisibility())); connect(child("rubberBandTimer"), SIGNAL(triggered()), this, SLOT(updateRubberBand())); hideNonPlayerUnits(); setSideMarks(); } }
// ### we may end up with a different search order than QtScript by not // folding this code into the fallbackMethod above, but Fields propagate out // of the binding code Field* QtClass::fieldNamed(const Identifier& identifier, Instance* instance) const { // Check static properties first QtInstance* qtinst = static_cast<QtInstance*>(instance); QObject* obj = qtinst->getObject(); UString ustring = identifier.ustring(); QString objName(QString::fromUtf16((const ushort*)ustring.rep()->data(),ustring.size())); QByteArray ba = objName.toAscii(); // First check for a cached field QtField* f = qtinst->m_fields.value(objName); if (obj) { if (f) { // We only cache real metaproperties, but we do store the // other types so we can delete them later if (f->fieldType() == QtField::MetaProperty) return f; else if (f->fieldType() == QtField::DynamicProperty) { if (obj->dynamicPropertyNames().indexOf(ba) >= 0) return f; else { // Dynamic property that disappeared qtinst->m_fields.remove(objName); delete f; } } else { QList<QObject*> children = obj->children(); for (int index = 0; index < children.count(); ++index) { QObject *child = children.at(index); if (child->objectName() == objName) return f; } // Didn't find it, delete it from the cache qtinst->m_fields.remove(objName); delete f; } } int index = m_metaObject->indexOfProperty(identifier.ascii()); if (index >= 0) { QMetaProperty prop = m_metaObject->property(index); if (prop.isScriptable(obj)) { f = new QtField(prop); qtinst->m_fields.insert(objName, f); return f; } } // Dynamic properties index = obj->dynamicPropertyNames().indexOf(ba); if (index >= 0) { f = new QtField(ba); qtinst->m_fields.insert(objName, f); return f; } // Child objects QList<QObject*> children = obj->children(); for (index = 0; index < children.count(); ++index) { QObject *child = children.at(index); if (child->objectName() == objName) { f = new QtField(child); qtinst->m_fields.insert(objName, f); return f; } } // Nothing named this return 0; } else { QByteArray ba(identifier.ascii()); // For compatibility with qtscript, cached methods don't cause // errors until they are accessed, so don't blindly create an error // here. if (qtinst->m_methods.contains(ba)) return 0; // deleted qobject, but can't throw an error from here (no exec) // create a fake QtField that will throw upon access if (!f) { f = new QtField(ba); qtinst->m_fields.insert(objName, f); } return f; } }
bool CppEditorCompletion::doObjectCompletion( const QString &objName ) { if ( !ths ) return FALSE; QString object( objName ); int i = -1; if ( ( i = object.findRev( "->" ) ) != -1 ) object = object.mid( i + 2 ); if ( ( i = object.findRev( "." ) ) != -1 ) object = object.mid( i + 1 ); object = object.simplifyWhiteSpace(); QObject *obj = 0; if ( ths->name() == object || object == "this" ) { obj = ths; } else { obj = ths->child( object ); } if ( !obj ) return FALSE; QValueList<CompletionEntry> lst; if ( obj->children() ) { for ( QObjectListIt cit( *obj->children() ); cit.current(); ++cit ) { QString s( cit.current()->name() ); if ( s.find( " " ) == -1 && s.find( "qt_" ) == -1 && s.find( "unnamed" ) == -1 ) { CompletionEntry c; c.type = "variable"; c.text = s; c.prefix = ""; lst << c; } } } QStrList props = obj->metaObject()->propertyNames( TRUE ); for ( QPtrListIterator<char> pit( props ); pit.current(); ++pit ) { QString f( pit.current() ); QChar c = f[ 0 ]; f.remove( (uint)0, 1 ); f.prepend( c.upper() ); f.prepend( "set" ); CompletionEntry ce; ce.type = "property"; ce.text = f; ce.postfix = "()"; if ( lst.find( ce ) == lst.end() ) lst << ce; } QStrList slts = obj->metaObject()->slotNames( TRUE ); for ( QPtrListIterator<char> sit( slts ); sit.current(); ++sit ) { QString f( sit.current() ); f = f.left( f.find( "(" ) ); CompletionEntry c; c.type = "slot"; c.text = f; c.postfix = "()"; if ( lst.find( c ) == lst.end() ) lst << c; } if ( lst.isEmpty() ) return FALSE; showCompletion( lst ); return TRUE; }