void KNMusicHeaderPlayer::onActionMouseInOut(const QVariant &controlPos) { QPoint controlPosition=controlPos.toPoint(); m_textPalette.setColor(QPalette::WindowText, QColor(255,255,255,-controlPosition.y()*5)); m_title->setPalette(m_textPalette); m_artistAlbum->setPalette(m_textPalette); }
/*! \internal Reimplemented from QGraphicsItemPrivate. ### Qt 5: Move impl to reimplementation QGraphicsProxyWidget::inputMethodQuery(). */ QVariant QGraphicsProxyWidgetPrivate::inputMethodQueryHelper(Qt::InputMethodQuery query) const { Q_Q(const QGraphicsProxyWidget); if (!widget || !q->hasFocus()) return QVariant(); QWidget *focusWidget = widget->focusWidget(); if (!focusWidget) focusWidget = widget; QVariant v = focusWidget->inputMethodQuery(query); QPointF focusWidgetPos = q->subWidgetRect(focusWidget).topLeft(); switch (v.type()) { case QVariant::RectF: v = v.toRectF().translated(focusWidgetPos); break; case QVariant::PointF: v = v.toPointF() + focusWidgetPos; break; case QVariant::Rect: v = v.toRect().translated(focusWidgetPos.toPoint()); break; case QVariant::Point: v = v.toPoint() + focusWidgetPos.toPoint(); break; default: break; } return v; }
void KPointComposedProperty::setValue(KProperty *property, const QVariant &value, bool rememberOldValue) { const QPoint p( value.toPoint() ); property->child("x")->setValue(p.x(), rememberOldValue, false); property->child("y")->setValue(p.y(), rememberOldValue, false); }
bool EnlargeShrink::setOption(const QString &option, const QVariant &value) { bool ok = false; if (option == QuillImageFilter::Radius) { double radius = value.toDouble(&ok); if (ok) { m_Radius = radius; } } else if (option == QuillImageFilter::Center) { QPoint center = value.toPoint(); if (!center.isNull()) { m_Center = center; ok = true; } } else if (option == FORCE_OPTION) { double force = value.toDouble(&ok); ok = ok && force <= 1.0 && force >= -1.0; if (ok) { // Divide by the FORCE_FACTOR to get appropiated values for // the Amplitude used by the "distort" function m_Force = force/FORCE_FACTOR; } } return ok; }
QString CSpmXml::PackValue(const QVariant& vtValue) { QString strValue; switch (vtValue.type()) { case QVariant::Size: { QSize size = vtValue.toSize(); strValue.sprintf(":%s:%d:%d", vtValue.typeName(), size.width(), size.height()); } break; case QVariant::Point: { QPoint pt = vtValue.toPoint(); strValue.sprintf(":%s:%d:%d", vtValue.typeName(), pt.x(), pt.y()); } break; default: strValue = vtValue.toString(); break; }; return strValue; }
QVariant GraphicsComponent::itemChange(GraphicsItemChange change, const QVariant &value) { switch (change) { case ItemPositionChange: { emit itemMoved(this); QPoint pos = value.toPoint(); if (this->parent->getSnapToGrid()){ pos = this->calculateSnap(pos); this->setProperty("x", pos.x()); this->setProperty("y", pos.y()); return QGraphicsItem::itemChange(change, QVariant(pos)); } this->setProperty("x", this->x()); this->setProperty("y", this->y()); } break; case ItemSelectedChange: break; default: break; } return QGraphicsItem::itemChange(change, value); }
QString PointDelegate::displayText( const QVariant& value ) const { const QPoint p(value.toPoint()); return QString::fromLatin1(POINTEDIT_MASK) .arg(p.x()) .arg(p.y()); }
QString write(const QVariant &variant) { if (!variant.isValid()) { qWarning() << "Trying to serialize invalid QVariant"; return QString(); } QString value; switch (variant.type()) { case QMetaType::QPoint: { QPoint p = variant.toPoint(); value = QString("%1,%2").arg(QString::number(p.x()), QString::number(p.y())); break; } case QMetaType::QPointF: { QPointF p = variant.toPointF(); value = QString("%1,%2").arg(QString::number(p.x(), 'f'), QString::number(p.y(), 'f')); break; } case QMetaType::QSize: { QSize s = variant.toSize(); value = QString("%1x%2").arg(QString::number(s.width()), QString::number(s.height())); break; } case QMetaType::QSizeF: { QSizeF s = variant.toSizeF(); value = QString("%1x%2").arg(QString::number(s.width(), 'f'), QString::number(s.height(), 'f')); break; } case QMetaType::QRect: { QRect r = variant.toRect(); value = QString("%1,%2,%3x%4").arg(QString::number(r.x()), QString::number(r.y()), QString::number(r.width()), QString::number(r.height())); break; } case QMetaType::QRectF: { QRectF r = variant.toRectF(); value = QString("%1,%2,%3x%4").arg(QString::number(r.x(), 'f'), QString::number(r.y(), 'f'), QString::number(r.width(), 'f'), QString::number(r.height(), 'f')); break; } default: QVariant strVariant = variant; strVariant.convert(QVariant::String); if (!strVariant.isValid()) qWarning() << Q_FUNC_INFO << "cannot serialize type " << QMetaType::typeName(variant.type()); value = strVariant.toString(); } return value; }
void MainWindow::SetupUi() { resize(600, 400); //set the main toolbar mainToolbar = new QToolBar(); mainToolbar->setEnabled(true); mainToolbar->setIconSize(QSize(16, 16)); addToolBar(Qt::TopToolBarArea, mainToolbar); newAction = new QAction(QIcon(":/Resources/images/new.png"), tr("&New"), this); connect(newAction, SIGNAL(triggered()), this, SLOT(OnNew())); mainToolbar->addAction(newAction); openAction = new QAction(QIcon(":/Resources/images/open.png"), tr("&Open"), this); openAction->setShortcut(QKeySequence::Open); connect(openAction, SIGNAL(triggered()), this, SLOT(OnOpen())); mainToolbar->addAction(openAction); saveAction = new QAction(QIcon(":/Resources/images/save.png"), tr("&Save"), this); saveAction->setShortcut(QKeySequence::Save); connect(saveAction, SIGNAL(triggered()), this, SLOT(OnSave())); mainToolbar->addAction(saveAction); undoAction = new QAction(QIcon(":/Resources/images/undo.png"), tr("&Undo"), this); undoAction->setShortcut(QKeySequence::Undo); connect(undoAction, SIGNAL(triggered()), this, SLOT(OnUndo())); mainToolbar->addAction(undoAction); redoAction = new QAction(QIcon(":/Resources/images/redo.png"), tr("&Redo"), this); redoAction->setShortcut(QKeySequence::Redo); connect(redoAction, SIGNAL(triggered()), this, SLOT(OnRedo())); mainToolbar->addAction(redoAction); setWindowTitle(QApplication::translate("Natural Calculator", "Natural Calculator", 0, QApplication::UnicodeUTF8)); QMetaObject::connectSlotsByName(this); QVariant p = settings.Load("NaturalCalculator", "position"); move(p.toPoint()); p = settings.Load("NaturalCalculator", "size"); resize(p.toSize()); //set the main window formulaWnd = new FormulaWnd(this); formulaWnd->setObjectName(QString::fromUtf8("formulaWnd")); formulaWnd->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); QWidget* c = new QWidget(); QBoxLayout* layout = new QBoxLayout(QBoxLayout::LeftToRight); layout->addWidget(formulaWnd); c->setLayout(layout); setCentralWidget(c); }
static void WriteAttributes(QObject* obj,QDomElement& el,QDomDocument& doc) { el.setAttribute("type",obj->metaObject()->className()); for(int i = 0; i < obj->metaObject()->propertyCount(); ++i) { QMetaProperty metaProperty(obj->metaObject()->property(i)); { QDomElement prop = doc.createElement("property"); prop.setAttribute("name",QString(metaProperty.name())); QVariant value = metaProperty.read(obj); QString strValue; if (metaProperty.type()==QVariant::String) { strValue = value.toString(); } else if (metaProperty.type()==QVariant::Int) { strValue = value.toString(); } else if (metaProperty.type()==QVariant::UInt) { strValue = value.toString(); } else if (metaProperty.type()==QVariant::Double) { strValue = value.toString(); } else if (metaProperty.type()==QVariant::Bool) { strValue = value.toBool() ? "1" : "0"; } else if (metaProperty.type()==QVariant::Point) { strValue = QString::number(value.toPoint().x())+";" + QString::number(value.toPoint().y()); } else if (metaProperty.type()==QVariant::PointF) { strValue = QString::number(value.toPointF().x())+";" + QString::number(value.toPointF().y()); } else if (metaProperty.type()==QVariant::Size) { strValue = QString::number(value.toSize().width())+";" + QString::number(value.toSize().height()); } else if (metaProperty.type()==QVariant::SizeF) { strValue = QString::number(value.toSizeF().width())+";" + QString::number(value.toSizeF().height()); } else { QByteArray ar; QDataStream ds(&ar,QIODevice::WriteOnly); ds << value; strValue = ar.toBase64().data(); } prop.setAttribute("value",strValue); el.appendChild(prop); } } }
void Window::showEvent(QShowEvent* event) { resizeFrame(m_screenWidget->sizeHint().width(), m_screenWidget->sizeHint().height()); QVariant windowPos = m_config->getQtOption("windowPos"); if (!windowPos.isNull()) { move(windowPos.toPoint()); } else { QRect rect = frameGeometry(); rect.moveCenter(QApplication::desktop()->availableGeometry().center()); move(rect.topLeft()); } }
QString VariantDelegate::displayText(const QVariant &value) { switch (value.type()) { case QVariant::Bool: case QVariant::ByteArray: case QVariant::Char: case QVariant::Double: case QVariant::Int: case QVariant::LongLong: case QVariant::String: case QVariant::UInt: case QVariant::ULongLong: return value.toString(); case QVariant::Color: { QColor color = qvariant_cast<QColor>(value); return QString("(%1,%2,%3,%4)") .arg(color.red()).arg(color.green()) .arg(color.blue()).arg(color.alpha()); } case QVariant::Date: return value.toDate().toString(Qt::ISODate); case QVariant::DateTime: return value.toDateTime().toString(Qt::ISODate); case QVariant::Invalid: return "<Invalid>"; case QVariant::Point: { QPoint point = value.toPoint(); return QString("(%1,%2)").arg(point.x()).arg(point.y()); } case QVariant::Rect: { QRect rect = value.toRect(); return QString("(%1,%2,%3,%4)") .arg(rect.x()).arg(rect.y()) .arg(rect.width()).arg(rect.height()); } case QVariant::Size: { QSize size = value.toSize(); return QString("(%1,%2)").arg(size.width()).arg(size.height()); } case QVariant::StringList: return value.toStringList().join(','); case QVariant::Time: return value.toTime().toString(Qt::ISODate); default: break; } return QString("<%1>").arg(value.typeName()); }
void DesktopWindow::loadItemPositions() { // load custom item positions customItemPos_.clear(); Settings& settings = static_cast<Application*>(qApp)->settings(); QString configFile = QString("%1/desktop-items-%2.conf").arg(settings.profileDir(settings.profileName())).arg(screenNum_); QSettings file(configFile, QSettings::IniFormat); auto delegate = static_cast<Fm::FolderItemDelegate*>(listView_->itemDelegateForColumn(0)); auto grid = delegate->itemSize(); QRect workArea = qApp->desktop()->availableGeometry(screenNum_); workArea.adjust(12, 12, -12, -12); char* dektopPath = Fm::Path::getDesktop().toStr(); QString desktopDir = QString(dektopPath) + QString("/"); g_free(dektopPath); std::vector<QPoint> usedPos; for(auto& item: customItemPos_) { usedPos.push_back(item.second); } // FIXME: this is inefficient Q_FOREACH(const QString& name, file.childGroups()) { if(!QFile::exists(desktopDir + name.toUtf8())) { // the file may have been removed from outside LXQT continue; } file.beginGroup(name); QVariant var = file.value("pos"); if(var.isValid()) { QPoint customPos = var.toPoint(); if(customPos.x() >= workArea.x() && customPos.y() >= workArea.y() && customPos.x() + grid.width() <= workArea.right() + 1 && customPos.y() + grid.height() <= workArea.bottom() + 1) { // correct positions that are't aligned to the grid alignToGrid(customPos, workArea.topLeft(), grid, listView_->spacing()); // FIXME: this is very inefficient while(std::find(usedPos.cbegin(), usedPos.cend(), customPos) != usedPos.cend()) { customPos.setY(customPos.y() + grid.height() + listView_->spacing()); if(customPos.y() + grid.height() > workArea.bottom() + 1) { customPos.setX(customPos.x() + grid.width() + listView_->spacing()); customPos.setY(workArea.top()); } } customItemPos_[name.toStdString()] = customPos; usedPos.push_back(customPos); } } file.endGroup(); } }
bool RedEyeDetection::setOption(const QString &option, const QVariant &value) { bool bOk = true; if (option == QuillImageFilter::Center) priv->center = value.toPoint(); else if (option == QuillImageFilter::Radius) priv->eyeRadius = value.toInt(&bOk); else if (option == QuillImageFilter::Tolerance) priv->tapErrorTolerance = value.toInt(&bOk); else bOk = false; return bOk; }
bool TiltShift::setOption(const QString& filterOption, const QVariant& value) { bool result = true; if (filterOption == QuillImageFilter::Radius) { m_radius = value.toInt(); } else if (filterOption == QuillImageFilter::Horizontal) { m_horizontalEffect = value.toBool(); } else if (filterOption == QuillImageFilter::Center) { m_focusPoint = value.toPoint(); } else { result = false; } return result; }
QString KPropertyPointDelegate::valueToString(const QVariant& value, const QLocale &locale) const { const QPoint p(value.toPoint()); if (p.isNull()) { if (locale.language() == QLocale::C) { return QString(); } return QObject::tr("None", "Null value"); } if (locale.language() == QLocale::C) { return QString::fromLatin1("%1, %2").arg(p.x()).arg(p.y()); } return QObject::tr("%1, %2", "Point") .arg(locale.toString(p.x())) .arg(locale.toString(p.y())); }
void DesktopWindow::loadItemPositions() { // load custom item positions customItemPos_.clear(); Settings& settings = static_cast<Application*>(qApp)->settings(); QString configFile = QString("%1/desktop-items-%2.conf").arg(settings.profileDir(settings.profileName())).arg(screenNum_); QSettings file(configFile, QSettings::IniFormat); QSize grid = listView_->gridSize(); QRect workArea = qApp->desktop()->availableGeometry(screenNum_); workArea.adjust(12, 12, -12, -12); char* dektopPath = fm_path_to_str(fm_path_get_desktop()); QString desktopDir = QString(dektopPath) + QString("/"); g_free(dektopPath); Q_FOREACH(const QString& name, file.childGroups()) { if(!QFile::exists(desktopDir + name.toUtf8())) { // the file may have been removed from outside LXQT continue; } file.beginGroup(name); QVariant var = file.value("pos"); if(var.isValid()) { QPoint customPos = var.toPoint(); if (customPos.x() >= workArea.x() && customPos.y() >= workArea.y() && customPos.x() + listView_->gridSize().width() <= workArea.right() + 1 && customPos.y() + listView_->gridSize().height() <= workArea.bottom() + 1) { // correct positions that are't aligned to the grid qreal w = qAbs((qreal)customPos.x() - (qreal)workArea.x()) / (qreal)(grid.width() + listView_->spacing()); qreal h = qAbs(customPos.y() - (qreal)workArea.y()) / (qreal)(grid.height() + listView_->spacing()); customPos.setX(workArea.x() + qRound(w) * (grid.width() + listView_->spacing())); customPos.setY(workArea.y() + qRound(h) * (grid.height() + listView_->spacing())); while(customItemPos_.values().contains(customPos)) { customPos.setY(customPos.y() + grid.height() + listView_->spacing()); if(customPos.y() + grid.height() > workArea.bottom() + 1) { customPos.setX(customPos.x() + grid.width() + listView_->spacing()); customPos.setY(workArea.top()); } } customItemPos_[name.toUtf8()] = customPos; } } file.endGroup(); } }
QVariant HandleItem::itemChange( GraphicsItemChange change, const QVariant &data ) { if( change == ItemPositionChange && m_pressed ) { QPointF movement = data.toPoint() - pos(); QPointF center = m_item->boundingRect().center(); switch( m_role ) { case CenterHandle: m_item->moveBy( movement.x(), movement.y() ); foreach( HandleItem *handle, m_handles ) handle->translate( movement.x(), movement.y() ); break; case RightHandle: if( 2*movement.x() + m_item->sceneBoundingRect().width() <= 5 ) return QGraphicsItem::itemChange( change, pos() ); movement.setY( 0 ); m_item->translate( center.x(), center.y() ); m_item->scale( 1.0+2.0*movement.x()/(m_item->sceneBoundingRect().width()), 1 ); m_item->translate( -center.x(), -center.y() ); break; case TopHandle: if( -2*movement.y() + m_item->sceneBoundingRect().height() <= 5 ) return QGraphicsItem::itemChange( change, pos() ); movement.setX( 0 ); m_item->translate( center.x(), center.y() ); m_item->scale( 1, 1.0-2.0*movement.y()/(m_item->sceneBoundingRect().height()) ); m_item->translate( -center.x(), -center.y() ); break; } return QGraphicsItem::itemChange( change, pos()+movement ); } return QGraphicsItem::itemChange( change, data ); }
void MainWindow::getSettings(){ /* * Getting application settings */ QVariant val; val = CoreLib->getSetting("MainWindow", "size", false, QSize(600, 500)); this->resize(val.toSize()); val = CoreLib->getSetting("MainWindow", "pos", false, QPoint(100, 100)); this->move(val.toPoint()); QList<int> a; a.append(CoreLib->getSetting("MainWindow", "splitterSize0", false, 170).toInt()); a.append(CoreLib->getSetting("MainWindow", "splitterSize1", false, 379).toInt()); splitter->setSizes(a); if (CoreLib->getSetting("app", "showTrareyIcon", false).toBool()){ trayIcon->show(); if (CoreLib->getSetting("app", "minimizeToTray", false).toBool()){ this->setHidden(true); } else { this->setHidden(CoreLib->getSetting("MainWindow", "hidden", false).toBool()); } } else { trayIcon->hide(); } CoreLib->checkSettings(); emit(setDefaultFocus(CoreLib->getSetting("LastPrefix", "prefix", false).toString(), CoreLib->getSetting("LastPrefix", "dir", false).toString())); #ifndef _OS_DARWIN_ //make root if (CoreLib->getSetting("Plugins", "enableMenuDesktop", false, true).toBool()){ sys_menu.create_dir_info(); sys_menu.generateSystemMenu(); } #endif return; }
void PropertyBrowser::applyTilesetValue(PropertyBrowser::PropertyId id, const QVariant &val) { Tileset *tileset = static_cast<Tileset*>(mObject); QUndoStack *undoStack = mMapDocument->undoStack(); switch (id) { case NameProperty: undoStack->push(new RenameTileset(mMapDocument, tileset, val.toString())); break; case TileOffsetProperty: undoStack->push(new ChangeTilesetTileOffset(mMapDocument, tileset, val.toPoint())); break; default: break; } }
void PointCustomProperty::setValue(const QVariant &value, bool rememberOldValue) { if(!m_property) return; if(m_property->parent()) { QPoint p = m_property->parent()->value().toPoint(); if(m_property->type() == Point_X) p.setX(value.toInt()); else if(m_property->type() == Point_Y) p.setY(value.toInt()); m_property->parent()->setValue(p, true, false); } else { QPoint p = value.toPoint(); m_property->child("x")->setValue(p.x(), rememberOldValue, false); m_property->child("y")->setValue(p.y(), rememberOldValue, false); } }
bool GCF::Message::encodeVariant(QDataStream& ds, const QVariant& value) { QString typeName; if( value.isValid() ) { typeName = QString(value.typeName()); if( typeName.isEmpty() ) return false; } else typeName = "Invalid"; if( value.type() >= QVariant::UserType ) return false; // Prepare the typename in-case of bool, char, int, double switch(value.type()) { case QVariant::Int: typeName = is32Bit() ? "qint32" : "qint64"; break; case QVariant::Char: typeName = "quint8"; break; case QVariant::UInt: typeName = is32Bit() ? "quint32" : "quint64"; break; default: break; } // Serialize value on to the byte array switch( value.type() ) { case QVariant::Invalid: ds << typeName; ds << qint32(0); break; case QVariant::Bool: ds << typeName; ds << value.toBool(); break; case QVariant::Char: ds << typeName; ds << value.toChar(); break; case QVariant::Color: ds << typeName; ds << value.value<QColor>(); break; case QVariant::Date: ds << typeName; ds << value.toDate(); break; case QVariant::DateTime: ds << typeName; ds << value.toDateTime(); break; case QVariant::Double: ds << typeName; ds << value.toDouble(); break; case QVariant::Int: ds << typeName; if( is32Bit() ) ds << (qint32)value.toInt(); else ds << (qint64)value.toInt(); break; case QVariant::Time: ds << typeName; ds << value.toTime(); break; case QVariant::UInt: ds << typeName; if( is32Bit() ) ds << (quint32)value.toUInt(); else ds << (quint64)value.toUInt(); break; case QVariant::String: ds << typeName; ds << value.toString(); break; case QVariant::Pixmap: ds << typeName; ds << value.value<QPixmap>(); break; case QVariant::ByteArray: ds << typeName; ds << value.toByteArray(); break; case QVariant::BitArray: ds << typeName; ds << value.toBitArray(); break; case QVariant::Image: ds << typeName; ds << value.value<QImage>(); break; case QVariant::Url: ds << typeName; ds << value.toUrl(); break; case QVariant::StringList: ds << typeName; ds << value.toStringList(); break; case QVariant::SizePolicy: ds << typeName; ds << value.value<QSizePolicy>(); break; case QVariant::SizeF: ds << typeName; ds << value.toSizeF(); break; case QVariant::Size: ds << typeName; ds << value.toSize(); break; case QVariant::RegExp: ds << typeName; ds << value.toRegExp(); break; case QVariant::RectF: ds << typeName; ds << value.toRectF(); break; case QVariant::Rect: ds << typeName; ds << value.toRect(); break; case QVariant::Polygon: ds << typeName; ds << value.value<QPolygon>(); break; case QVariant::PointF: ds << typeName; ds << value.toPointF(); break; case QVariant::Point: ds << typeName; ds << value.toPoint(); break; case QVariant::Matrix: ds << typeName; ds << value.value<QMatrix>(); break; case QVariant::LineF: ds << typeName; ds << value.toLineF(); break; case QVariant::Line: ds << typeName; ds << value.toLine(); break; case QVariant::Brush: ds << typeName; ds << value.value<QBrush>(); break; case QVariant::Bitmap: ds << typeName; ds << value.value<QBitmap>(); break; case QVariant::Transform: ds << typeName; ds << value.value<QTransform>(); break; default: // Other types will be supported shortly. // TODO: support user defined types. return false; } return true; }
void ModelScene::refresh() { // clear existing scene // clear model items for (ModelItemGraphics* MItemG : m_GraphicsItems) { removeItem(MItemG); delete MItemG; } m_GraphicsItems.clear(); // clear connections for (ConnectorGraphics* ConnG : m_GraphicsConnections) { removeItem(ConnG); delete ConnG; } m_GraphicsConnections.clear(); clear(); const std::list<openfluid::fluidx::ModelItemDescriptor*>& Items = m_Model.items(); std::list<openfluid::fluidx::ModelItemDescriptor*>::const_iterator itb = Items.begin(); std::list<openfluid::fluidx::ModelItemDescriptor*>::const_iterator ite = Items.end(); std::list<openfluid::fluidx::ModelItemDescriptor*>::const_iterator it; unsigned int SimCount = 0; unsigned int GenCount = 0; // add model items for (it = itb; it!= ite; ++it) { if ((*it)->isEnabled()) { QString ID = QString::fromStdString(m_Model.getID(*it)); QVariant ConfigPos = openfluid::base::RunContextManager::instance()->getProjectConfigValue("builder.model.graphicalview",ID); QPoint Position(0,0); if (ConfigPos.type() == QVariant::Point) Position = ConfigPos.toPoint(); else { QRectF CurrentRect = itemsBoundingRect(); Position.setX(int(CurrentRect.x()+CurrentRect.width()/2)); Position.setY(int(CurrentRect.y()+CurrentRect.height()/2)); } if ((*it)->getType() == openfluid::ware::WareType::SIMULATOR && openfluid::machine::SimulatorSignatureRegistry::instance()->isSimulatorAvailable(ID.toStdString())) { SimCount++; SimulatorGraphics* SimG = new SimulatorGraphics(QPoint(0,0), ID, SimCount+GenCount, openfluid::machine::SimulatorSignatureRegistry::instance() ->signature(ID.toStdString())); addItem(SimG); SimG->moveBy(Position.x(),Position.y()); SimG->initialize(); m_GraphicsItems.append(SimG); connect(SimG,SIGNAL(srcEditAsked(const QString&,bool)),this,SLOT(notifySrcEditAsked(const QString&,bool))); } else if ((*it)->getType() == openfluid::ware::WareType::GENERATOR)
void NewProjectDialog::setSettings() { OQSettings::SettingsManager *settingsManager = OQSettings::SettingsManager::getSingletonPtr(); if (!settingsManager) return; OQSettings::SettingsManager::ProjectFileInfo *justCreatedProject = settingsManager->newProject( _newProjectDialogForm->editPathToProjectFolder->text().toStdString(), _newProjectDialogForm->editProjectName->text().toStdString(), _newProjectDialogForm->comboboxProjectType->itemData(_newProjectDialogForm->comboboxProjectType->currentIndex()).toString().toStdString()); if (!justCreatedProject) return; OQSettings::GameProjectSettings *projectSettings = (OQSettings::GameProjectSettings*)justCreatedProject->getProjectBaseSettings(); projectSettings->setNeedShowMessage(true); projectSettings->setProjectName(_newProjectDialogForm->editProjectName->text().toStdString()); projectSettings->setPathToProjectFolder(_newProjectDialogForm->editPathToProjectFolder->text().toStdString()); projectSettings->setCurrentOS(_newProjectDialogForm->comboboxCurrentOS->itemText(_newProjectDialogForm->comboboxSceernSize->currentIndex()).toStdString()); projectSettings->setMode3D(_newProjectDialogForm->checkbox3DMode->isChecked()); int height = -1; int width = -1; bool syzeByHand = _newProjectDialogForm->checkboxScreenSizeByHand->isChecked(); if (syzeByHand) { height = _newProjectDialogForm->spinboxScreenSizeHeight->value(); width = _newProjectDialogForm->spinboxScreenSizeWidth->value(); } else { QVariant size = _newProjectDialogForm->comboboxSceernSize->itemData(_newProjectDialogForm->comboboxSceernSize->currentIndex()); width = size.toPoint().x(); height = size.toPoint().y(); } if (height != -1 && width != -1) { int minW = projectSettings->getScreenSizeInfo().first.min; int maxW = projectSettings->getScreenSizeInfo().first.max; int minH = projectSettings->getScreenSizeInfo().second.min; int maxH = projectSettings->getScreenSizeInfo().second.max; if (width < minW) { width = minW; } else if (width > maxW) { width = minW; } if (height < minH) { height = minH; } else if (height > maxH) { height = maxH; } } projectSettings->setScreenHeight(height); projectSettings->setScreenWidth(width); if (settingsManager->saveProject(projectSettings->getProjectName())) { settingsManager->setActiveProject(projectSettings->getProjectName()); Q_EMIT addProjectPage(projectSettings->getProjectName()); close(); } else { settingsManager->closeProject(justCreatedProject->_projectName); } }
Window::Window(ConfigController* config, int playerId, QWidget* parent) : QMainWindow(parent) , m_log(0) , m_logView(new LogView(&m_log)) , m_stateWindow(nullptr) , m_screenWidget(new WindowBackground()) , m_logo(":/res/mgba-1024.png") , m_config(config) , m_inputController(playerId, this) #ifdef USE_FFMPEG , m_videoView(nullptr) #endif #ifdef USE_MAGICK , m_gifView(nullptr) #endif #ifdef USE_GDB_STUB , m_gdbController(nullptr) #endif , m_mruMenu(nullptr) , m_shortcutController(new ShortcutController(this)) , m_playerId(playerId) { setFocusPolicy(Qt::StrongFocus); setAcceptDrops(true); setAttribute(Qt::WA_DeleteOnClose); m_controller = new GameController(this); m_controller->setInputController(&m_inputController); m_controller->setOverrides(m_config->overrides()); updateTitle(); m_display = Display::create(this); m_logo.setDevicePixelRatio(m_screenWidget->devicePixelRatio()); m_logo = m_logo; // Free memory left over in old pixmap m_screenWidget->setMinimumSize(m_display->minimumSize()); m_screenWidget->setSizePolicy(m_display->sizePolicy()); m_screenWidget->setSizeHint(m_display->minimumSize() * 2); m_screenWidget->setPixmap(m_logo); m_screenWidget->setLockAspectRatio(m_logo.width(), m_logo.height()); setCentralWidget(m_screenWidget); QVariant windowPos = m_config->getQtOption("windowPos"); if (!windowPos.isNull()) { move(windowPos.toPoint()); } connect(m_controller, SIGNAL(gameStarted(GBAThread*)), this, SLOT(gameStarted(GBAThread*))); connect(m_controller, SIGNAL(gameStarted(GBAThread*)), &m_inputController, SLOT(suspendScreensaver())); connect(m_controller, SIGNAL(gameStopped(GBAThread*)), m_display, SLOT(stopDrawing())); connect(m_controller, SIGNAL(gameStopped(GBAThread*)), this, SLOT(gameStopped())); connect(m_controller, SIGNAL(gameStopped(GBAThread*)), &m_inputController, SLOT(resumeScreensaver())); connect(m_controller, SIGNAL(stateLoaded(GBAThread*)), m_display, SLOT(forceDraw())); connect(m_controller, SIGNAL(rewound(GBAThread*)), m_display, SLOT(forceDraw())); connect(m_controller, SIGNAL(gamePaused(GBAThread*)), m_display, SLOT(pauseDrawing())); #ifndef Q_OS_MAC connect(m_controller, SIGNAL(gamePaused(GBAThread*)), menuBar(), SLOT(show())); connect(m_controller, &GameController::gameUnpaused, [this]() { if(isFullScreen()) { menuBar()->hide(); } }); #endif connect(m_controller, SIGNAL(gamePaused(GBAThread*)), &m_inputController, SLOT(resumeScreensaver())); connect(m_controller, SIGNAL(gameUnpaused(GBAThread*)), m_display, SLOT(unpauseDrawing())); connect(m_controller, SIGNAL(gameUnpaused(GBAThread*)), &m_inputController, SLOT(suspendScreensaver())); connect(m_controller, SIGNAL(postLog(int, const QString&)), &m_log, SLOT(postLog(int, const QString&))); connect(m_controller, SIGNAL(frameAvailable(const uint32_t*)), this, SLOT(recordFrame())); connect(m_controller, SIGNAL(frameAvailable(const uint32_t*)), m_display, SLOT(framePosted(const uint32_t*))); connect(m_controller, SIGNAL(gameCrashed(const QString&)), this, SLOT(gameCrashed(const QString&))); connect(m_controller, SIGNAL(gameFailed()), this, SLOT(gameFailed())); connect(m_controller, SIGNAL(unimplementedBiosCall(int)), this, SLOT(unimplementedBiosCall(int))); connect(m_controller, SIGNAL(statusPosted(const QString&)), m_display, SLOT(showMessage(const QString&))); connect(&m_log, SIGNAL(levelsSet(int)), m_controller, SLOT(setLogLevel(int))); connect(&m_log, SIGNAL(levelsEnabled(int)), m_controller, SLOT(enableLogLevel(int))); connect(&m_log, SIGNAL(levelsDisabled(int)), m_controller, SLOT(disableLogLevel(int))); connect(this, SIGNAL(startDrawing(GBAThread*)), m_display, SLOT(startDrawing(GBAThread*)), Qt::QueuedConnection); connect(this, SIGNAL(shutdown()), m_display, SLOT(stopDrawing())); connect(this, SIGNAL(shutdown()), m_controller, SLOT(closeGame())); connect(this, SIGNAL(shutdown()), m_logView, SLOT(hide())); connect(this, SIGNAL(audioBufferSamplesChanged(int)), m_controller, SLOT(setAudioBufferSamples(int))); connect(this, SIGNAL(fpsTargetChanged(float)), m_controller, SLOT(setFPSTarget(float))); connect(&m_fpsTimer, SIGNAL(timeout()), this, SLOT(showFPS())); connect(m_display, &Display::hideCursor, [this]() { if (static_cast<QStackedLayout*>(m_screenWidget->layout())->currentWidget() == m_display) { setCursor(Qt::BlankCursor); } }); connect(m_display, &Display::showCursor, [this]() { unsetCursor(); }); connect(&m_inputController, SIGNAL(profileLoaded(const QString&)), m_shortcutController, SLOT(loadProfile(const QString&))); m_log.setLevels(GBA_LOG_WARN | GBA_LOG_ERROR | GBA_LOG_FATAL | GBA_LOG_STATUS); m_fpsTimer.setInterval(FPS_TIMER_INTERVAL); m_shortcutController->setConfigController(m_config); setupMenu(menuBar()); }
void KConfigGroup::writeEntry( const char* key, const QVariant &value, WriteConfigFlags flags ) { Q_ASSERT_X(isValid(), "KConfigGroup::writeEntry", "accessing an invalid group"); Q_ASSERT_X(!d->bConst, "KConfigGroup::writeEntry", "writing to a read-only group"); if ( writeEntryGui( this, key, value, flags ) ) return; // GUI type that was handled QByteArray data; // if a type handler is added here you must add a QVConversions definition // to conversion_check.h, or ConversionCheck::to_QVariant will not allow // writeEntry<T> to convert to QVariant. switch( value.type() ) { case QVariant::Invalid: data = ""; break; case QVariant::ByteArray: data = value.toByteArray(); break; case QVariant::String: case QVariant::Int: case QVariant::UInt: case QVariant::Double: case QMetaType::Float: case QVariant::Bool: case QVariant::LongLong: case QVariant::ULongLong: data = value.toString().toUtf8(); break; case QVariant::List: if (!value.canConvert(QVariant::StringList)) qWarning() << "not all types in \"" << key << "\" can convert to QString," " information will be lost"; case QVariant::StringList: writeEntry( key, value.toList(), flags ); return; case QVariant::Point: { QVariantList list; const QPoint rPoint = value.toPoint(); list.insert( 0, rPoint.x() ); list.insert( 1, rPoint.y() ); writeEntry( key, list, flags ); return; } case QVariant::PointF: { QVariantList list; const QPointF point = value.toPointF(); list.insert( 0, point.x() ); list.insert( 1, point.y() ); writeEntry( key, list, flags ); return; } case QVariant::Rect:{ QVariantList list; const QRect rRect = value.toRect(); list.insert( 0, rRect.left() ); list.insert( 1, rRect.top() ); list.insert( 2, rRect.width() ); list.insert( 3, rRect.height() ); writeEntry( key, list, flags ); return; } case QVariant::RectF:{ QVariantList list; const QRectF rRectF = value.toRectF(); list.insert(0, rRectF.left()); list.insert(1, rRectF.top()); list.insert(2, rRectF.width()); list.insert(3, rRectF.height()); writeEntry(key, list, flags); return; } case QVariant::Size:{ QVariantList list; const QSize rSize = value.toSize(); list.insert( 0, rSize.width() ); list.insert( 1, rSize.height() ); writeEntry( key, list, flags ); return; } case QVariant::SizeF:{ QVariantList list; const QSizeF rSizeF = value.toSizeF(); list.insert(0, rSizeF.width()); list.insert(1, rSizeF.height()); writeEntry(key, list, flags); return; } case QVariant::Date: { QVariantList list; const QDate date = value.toDate(); list.insert( 0, date.year() ); list.insert( 1, date.month() ); list.insert( 2, date.day() ); writeEntry( key, list, flags ); return; } case QVariant::DateTime: { QVariantList list; const QDateTime rDateTime = value.toDateTime(); const QTime time = rDateTime.time(); const QDate date = rDateTime.date(); list.insert( 0, date.year() ); list.insert( 1, date.month() ); list.insert( 2, date.day() ); list.insert( 3, time.hour() ); list.insert( 4, time.minute() ); list.insert( 5, time.second() ); writeEntry( key, list, flags ); return; } case QVariant::Color: case QVariant::Font: qWarning() << "KConfigGroup::writeEntry was passed GUI type '" << value.typeName() << "' but kdeui isn't linked! If it is linked to your program, this is a platform bug. " "Please inform the KDE developers"; break; case QVariant::Url: data = QUrl(value.toUrl()).toString().toUtf8(); break; default: qWarning() << "KConfigGroup::writeEntry - unhandled type" << value.typeName() << "in group" << name(); } writeEntry(key, data, flags); }
QString VariantHandler::displayString(const QVariant& value) { switch (value.type()) { #ifndef QT_NO_CURSOR case QVariant::Cursor: { const QCursor cursor = value.value<QCursor>(); return Util::enumToString(QVariant::fromValue<int>(cursor.shape()), "Qt::CursorShape"); } #endif case QVariant::Icon: { const QIcon icon = value.value<QIcon>(); if (icon.isNull()) { return QObject::tr("<no icon>"); } QStringList l; foreach (const QSize &size, icon.availableSizes()) { l.push_back(displayString(size)); } return l.join(QLatin1String(", ")); } case QVariant::Line: return QString::fromUtf8("%1 x %2 → %3 x %4"). arg(value.toLine().x1()).arg(value.toLine().y1()). arg(value.toLine().x2()).arg(value.toLine().y2()); case QVariant::LineF: return QString::fromUtf8("%1 x %2 → %3 x %4"). arg(value.toLineF().x1()).arg(value.toLineF().y1()). arg(value.toLineF().x2()).arg(value.toLineF().y2()); case QVariant::Locale: return value.value<QLocale>().name(); case QVariant::Point: return QString::fromLatin1("%1x%2"). arg(value.toPoint().x()). arg(value.toPoint().y()); case QVariant::PointF: return QString::fromLatin1("%1x%2"). arg(value.toPointF().x()). arg(value.toPointF().y()); case QVariant::Rect: return QString::fromLatin1("%1x%2 %3x%4"). arg(value.toRect().x()). arg(value.toRect().y()). arg(value.toRect().width()). arg(value.toRect().height()); case QVariant::RectF: return QString::fromLatin1("%1x%2 %3x%4"). arg(value.toRectF().x()). arg(value.toRectF().y()). arg(value.toRectF().width()). arg(value.toRectF().height()); case QVariant::Region: { const QRegion region = value.value<QRegion>(); if (region.isEmpty()) { return QLatin1String("<empty>"); } if (region.rectCount() == 1) { return displayString(region.rects().first()); } else { return QString::fromLatin1("<%1 rects>").arg(region.rectCount()); } } case QVariant::Palette: { const QPalette pal = value.value<QPalette>(); if (pal == qApp->palette()) { return QLatin1String("<inherited>"); } return QLatin1String("<custom>"); } case QVariant::Size: return QString::fromLatin1("%1x%2"). arg(value.toSize().width()). arg(value.toSize().height()); case QVariant::SizeF: return QString::fromLatin1("%1x%2"). arg(value.toSizeF().width()). arg(value.toSizeF().height()); case QVariant::StringList: return value.toStringList().join(", "); case QVariant::Transform: { const QTransform t = value.value<QTransform>(); return QString::fromLatin1("[%1 %2 %3, %4 %5 %6, %7 %8 %9]"). arg(t.m11()).arg(t.m12()).arg(t.m13()). arg(t.m21()).arg(t.m22()).arg(t.m23()). arg(t.m31()).arg(t.m32()).arg(t.m33()); } default: break; } // types with dynamic type ids if (value.type() == (QVariant::Type)qMetaTypeId<QTextLength>()) { const QTextLength l = value.value<QTextLength>(); QString typeStr; switch (l.type()) { case QTextLength::VariableLength: typeStr = QObject::tr("variable"); break; case QTextLength::FixedLength: typeStr = QObject::tr("fixed"); break; case QTextLength::PercentageLength: typeStr = QObject::tr("percentage"); break; } return QString::fromLatin1("%1 (%2)").arg(l.rawValue()).arg(typeStr); } if (value.userType() == qMetaTypeId<QPainterPath>()) { const QPainterPath path = value.value<QPainterPath>(); if (path.isEmpty()) { return QObject::tr("<empty>"); } return QObject::tr("<%1 elements>").arg(path.elementCount()); } if (value.userType() == qMetaTypeId<QMargins>()) { const QMargins margins = value.value<QMargins>(); return QObject::tr("left: %1, top: %2, right: %3, bottom: %4") .arg(margins.left()).arg(margins.top()) .arg(margins.right()).arg(margins.bottom()); } if (value.canConvert<QObject*>()) { return Util::displayString(value.value<QObject*>()); } #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) if (value.userType() == qMetaTypeId<QSet<QByteArray> >()) { const QSet<QByteArray> set = value.value<QSet<QByteArray> >(); QStringList l; foreach (const QByteArray &b, set) l.push_back(QString::fromUtf8(b)); return l.join(", "); } if (value.userType() == qMetaTypeId<QSurfaceFormat>()) { const QSurfaceFormat format = value.value<QSurfaceFormat>(); QString s; switch (format.renderableType()) { case QSurfaceFormat::DefaultRenderableType: s += "Default"; break; case QSurfaceFormat::OpenGL: s += "OpenGL"; break; case QSurfaceFormat::OpenGLES: s += "OpenGL ES"; break; case QSurfaceFormat::OpenVG: s += "OpenVG"; break; } s += " (" + QString::number(format.majorVersion()) + "." + QString::number(format.minorVersion()); switch (format.profile()) { case QSurfaceFormat::CoreProfile: s += " core"; break; case QSurfaceFormat::CompatibilityProfile: s += " compat"; break; case QSurfaceFormat::NoProfile: break; } s += ")"; s += " RGBA: " + QString::number(format.redBufferSize()) + "/" + QString::number(format.greenBufferSize()) + "/" + QString::number(format.blueBufferSize()) + "/" + QString::number(format.alphaBufferSize()); s += " Depth: " + QString::number(format.depthBufferSize()); s += " Stencil: " + QString::number(format.stencilBufferSize()); s += " Buffer: "; switch (format.swapBehavior()) { case QSurfaceFormat::DefaultSwapBehavior: s += "default"; break; case QSurfaceFormat::SingleBuffer: s += "single"; break; case QSurfaceFormat::DoubleBuffer: s += "double"; break; case QSurfaceFormat::TripleBuffer: s += "triple"; break; default: s += "unknown"; } return s; } if (value.userType() == qMetaTypeId<QSurface::SurfaceClass>()) { const QSurface::SurfaceClass sc = value.value<QSurface::SurfaceClass>(); switch (sc) { case QSurface::Window: return QObject::tr("Window"); #if QT_VERSION > QT_VERSION_CHECK(5, 1, 0) case QSurface::Offscreen: return QObject::tr("Offscreen"); #endif default: return QObject::tr("Unknown Surface Class"); } } if (value.userType() == qMetaTypeId<QSurface::SurfaceType>()) { const QSurface::SurfaceType type = value.value<QSurface::SurfaceType>(); switch (type) { case QSurface::RasterSurface: return QObject::tr("Raster"); case QSurface::OpenGLSurface: return QObject::tr("OpenGL"); default: return QObject::tr("Unknown Surface Type"); } } #endif // enums const QString enumStr = Util::enumToString(value); if (!enumStr.isEmpty()) { return enumStr; } // custom converters const QHash<int, Converter<QString>*>::const_iterator it = s_variantHandlerRepository()->stringConverters.constFind(value.userType()); if (it != s_variantHandlerRepository()->stringConverters.constEnd()) { return (*it.value())(value); } return value.toString(); }
PyObject* scribus_getproperty(PyObject* /*self*/, PyObject* args, PyObject* kw) { PyObject* objArg = NULL; char* propertyName = NULL; char* kwargs[] = {const_cast<char*>("object"), const_cast<char*>("property"), NULL}; if (!PyArg_ParseTupleAndKeywords(args, kw, "Oes", kwargs, &objArg, "ascii", &propertyName)) return NULL; // Get the QObject* the object argument refers to QObject* obj = getQObjectFromPyArg(objArg); if (!obj) return NULL; objArg = NULL; // no need to decref, it's borrowed // Get the QMetaProperty for the property, so we can check // if it's a set/enum and do name/value translation. /*qt4 FIXME const QMetaObject* objmeta = obj->metaObject(); int i = objmeta->findProperty(propertyName, true); if (i == -1) { PyErr_SetString(PyExc_ValueError, QObject::tr("Property not found")); return NULL; } const QMetaProperty* propmeta = objmeta->property(i, true); assert(propmeta); */ // Get the property value as a variant type QVariant prop = obj->property(propertyName); // Convert the property to an instance of the closest matching Python type. PyObject* resultobj = NULL; // NUMERIC TYPES if (prop.type() == QVariant::Int) resultobj = PyLong_FromLong(prop.toInt()); else if (prop.type() == QVariant::Double) resultobj = PyFloat_FromDouble(prop.toDouble()); // BOOLEAN else if (prop.type() == QVariant::Bool) resultobj = PyBool_FromLong(prop.toBool()); // STRING TYPES else if (prop.type() == QVariant::ByteArray) resultobj = PyString_FromString(prop.toByteArray().data()); else if (prop.type() == QVariant::String) resultobj = PyString_FromString(prop.toString().toUtf8().data()); // HIGHER ORDER TYPES else if (prop.type() == QVariant::Point) { // Return a QPoint as an (x,y) tuple. QPoint pt = prop.toPoint(); return Py_BuildValue("(ii)", pt.x(), pt.y()); } else if (prop.type() == QVariant::Rect) { // Return a QRect as an (x,y,width,height) tuple. // FIXME: We should really construct and return an object that // matches the API of QRect and has properties to keep // left/top/right/bottom and x/y/width/height in sync. QRect r = prop.toRect(); return Py_BuildValue("(iiii)", r.x(), r.y(), r.width(), r.height()); } else if (prop.type() == QVariant::StringList) { QStringList tmp = prop.toStringList(); return convert_QStringList_to_PyListObject(tmp); } // UNHANDLED TYPE else { PyErr_SetString(PyExc_TypeError, QObject::tr("Couldn't convert result type '%1'.").arg(prop.typeName()).toLocal8Bit().constData() ); return NULL; } // Return the resulting Python object if (resultobj == NULL) { // An exception was set while assigning to resultobj assert(PyErr_Occurred()); return NULL; } else return resultobj; }
void QSGPropertyAnimator::updateProperty(QObject *target, const QString& p) { QSGAnimatedProperty *ap = m_controller->registeredProperty(p, target); if (ap && m_duration > 0) { if (m_elapsed > m_startTime && ((m_elapsed < m_startTime + m_loops * m_duration) || (m_loops < 0))) { QVariant value = ap->value(); qreal tx = int(m_elapsed - m_startTime) % int(m_duration); switch (value.type()) { case QMetaType::Double: value = QVariant(m_from.toReal() + (m_to.toReal() - m_from.toReal()) * m_easing.valueForProgress(tx / m_duration)); break; case QMetaType::QColor: { QColor from = qvariant_cast<QColor>(m_from); QColor to = qvariant_cast<QColor>(m_to); QColor result = qvariant_cast<QColor>(value); result.setRed(from.red() + (to.red() - from.red()) * m_easing.valueForProgress(tx / m_duration)); result.setGreen(from.green() + (to.green() - from.green()) * m_easing.valueForProgress(tx / m_duration)); result.setBlue(from.blue() + (to.blue() - from.blue()) * m_easing.valueForProgress(tx / m_duration)); result.setAlpha(from.alpha() + (to.alpha() - from.alpha()) * m_easing.valueForProgress(tx / m_duration)); value = result; break; } case QMetaType::Int: value = QVariant(m_from.toInt() + (m_to.toInt() - m_from.toInt()) * m_easing.valueForProgress(tx / m_duration)); break; case QMetaType::QSize: { QSize from = m_from.toSize(); QSize to = m_to.toSize(); QSize result = value.toSize(); result.setWidth(from.width() + (to.width() - from.width()) * m_easing.valueForProgress(tx / m_duration)); result.setHeight(from.height() + (to.height() - from.height()) * m_easing.valueForProgress(tx / m_duration)); value = result; break; } case QMetaType::QSizeF: { QSizeF from = m_from.toSize(); QSizeF to = m_to.toSize(); QSizeF result = value.toSize(); result.setWidth(from.width() + (to.width() - from.width()) * m_easing.valueForProgress(tx / m_duration)); result.setHeight(from.height() + (to.height() - from.height()) * m_easing.valueForProgress(tx / m_duration)); value = result; break; } case QMetaType::QPoint: { QPoint from = m_from.toPoint(); QPoint to = m_to.toPoint(); QPoint result = value.toPoint(); result.setX(from.x() + (to.x() - from.x()) * m_easing.valueForProgress(tx / m_duration)); result.setY(from.y() + (to.y() - from.y()) * m_easing.valueForProgress(tx / m_duration)); value = result; break; } case QMetaType::QPointF: { QPointF from = m_from.toPointF(); QPointF to = m_to.toPointF(); QPointF result = value.toPointF(); result.setX(from.x() + (to.x() - from.x()) * m_easing.valueForProgress(tx / m_duration)); result.setY(from.y() + (to.y() - from.y()) * m_easing.valueForProgress(tx / m_duration)); value = result; break; } case QMetaType::QRect: { QRect from = m_from.toRect(); QRect to = m_to.toRect(); QRect result = value.toRect(); result.setX(from.x() + (to.x() - from.x()) * m_easing.valueForProgress(tx / m_duration)); result.setY(from.y() + (to.y() - from.y()) * m_easing.valueForProgress(tx / m_duration)); result.setWidth(from.width() + (to.width() - from.width()) * m_easing.valueForProgress(tx / m_duration)); result.setHeight(from.height() + (to.height() - from.height()) * m_easing.valueForProgress(tx / m_duration)); value = result; break; } case QMetaType::QRectF: { QRectF from = m_from.toRectF(); QRectF to = m_to.toRectF(); QRectF result = value.toRectF(); result.setX(from.x() + (to.x() - from.x()) * m_easing.valueForProgress(tx / m_duration)); result.setY(from.y() + (to.y() - from.y()) * m_easing.valueForProgress(tx / m_duration)); result.setWidth(from.width() + (to.width() - from.width()) * m_easing.valueForProgress(tx / m_duration)); result.setHeight(from.height() + (to.height() - from.height()) * m_easing.valueForProgress(tx / m_duration)); value = result; break; } case QMetaType::QVector3D: { QVector3D from = qvariant_cast<QVector3D>(m_from); QVector3D to = qvariant_cast<QVector3D>(m_to); QVector3D result = qvariant_cast<QVector3D>(value); result.setX(from.x() + (to.x() - from.x()) * m_easing.valueForProgress(tx / m_duration)); result.setY(from.y() + (to.y() - from.y()) * m_easing.valueForProgress(tx / m_duration)); result.setZ(from.z() + (to.z() - from.z()) * m_easing.valueForProgress(tx / m_duration)); value = result; break; } default: break; } ap->setValue(value); } } }
// Apply a simple variant type to a DOM property static bool applySimpleProperty(const QVariant &v, bool translateString, DomProperty *dom_prop) { switch (v.type()) { case QVariant::String: { DomString *str = new DomString(); str->setText(v.toString()); if (!translateString) str->setAttributeNotr(QStringLiteral("true")); dom_prop->setElementString(str); } return true; case QVariant::ByteArray: dom_prop->setElementCstring(QString::fromUtf8(v.toByteArray())); return true; case QVariant::Int: dom_prop->setElementNumber(v.toInt()); return true; case QVariant::UInt: dom_prop->setElementUInt(v.toUInt()); return true; case QVariant::LongLong: dom_prop->setElementLongLong(v.toLongLong()); return true; case QVariant::ULongLong: dom_prop->setElementULongLong(v.toULongLong()); return true; case QVariant::Double: dom_prop->setElementDouble(v.toDouble()); return true; case QVariant::Bool: dom_prop->setElementBool(v.toBool() ? QFormBuilderStrings::instance().trueValue : QFormBuilderStrings::instance().falseValue); return true; case QVariant::Char: { DomChar *ch = new DomChar(); const QChar character = v.toChar(); ch->setElementUnicode(character.unicode()); dom_prop->setElementChar(ch); } return true; case QVariant::Point: { DomPoint *pt = new DomPoint(); const QPoint point = v.toPoint(); pt->setElementX(point.x()); pt->setElementY(point.y()); dom_prop->setElementPoint(pt); } return true; case QVariant::PointF: { DomPointF *ptf = new DomPointF(); const QPointF pointf = v.toPointF(); ptf->setElementX(pointf.x()); ptf->setElementY(pointf.y()); dom_prop->setElementPointF(ptf); } return true; case QVariant::Color: { DomColor *clr = new DomColor(); const QColor color = qvariant_cast<QColor>(v); clr->setElementRed(color.red()); clr->setElementGreen(color.green()); clr->setElementBlue(color.blue()); const int alphaChannel = color.alpha(); if (alphaChannel != 255) clr->setAttributeAlpha(alphaChannel); dom_prop->setElementColor(clr); } return true; case QVariant::Size: { DomSize *sz = new DomSize(); const QSize size = v.toSize(); sz->setElementWidth(size.width()); sz->setElementHeight(size.height()); dom_prop->setElementSize(sz); } return true; case QVariant::SizeF: { DomSizeF *szf = new DomSizeF(); const QSizeF sizef = v.toSizeF(); szf->setElementWidth(sizef.width()); szf->setElementHeight(sizef.height()); dom_prop->setElementSizeF(szf); } return true; case QVariant::Rect: { DomRect *rc = new DomRect(); const QRect rect = v.toRect(); rc->setElementX(rect.x()); rc->setElementY(rect.y()); rc->setElementWidth(rect.width()); rc->setElementHeight(rect.height()); dom_prop->setElementRect(rc); } return true; case QVariant::RectF: { DomRectF *rcf = new DomRectF(); const QRectF rectf = v.toRectF(); rcf->setElementX(rectf.x()); rcf->setElementY(rectf.y()); rcf->setElementWidth(rectf.width()); rcf->setElementHeight(rectf.height()); dom_prop->setElementRectF(rcf); } return true; case QVariant::Font: { DomFont *fnt = new DomFont(); const QFont font = qvariant_cast<QFont>(v); const uint mask = font.resolve(); if (mask & QFont::WeightResolved) { fnt->setElementBold(font.bold()); fnt->setElementWeight(font.weight()); } if (mask & QFont::FamilyResolved) fnt->setElementFamily(font.family()); if (mask & QFont::StyleResolved) fnt->setElementItalic(font.italic()); if (mask & QFont::SizeResolved) fnt->setElementPointSize(font.pointSize()); if (mask & QFont::StrikeOutResolved) fnt->setElementStrikeOut(font.strikeOut()); if (mask & QFont::UnderlineResolved) fnt->setElementUnderline(font.underline()); if (mask & QFont::KerningResolved) fnt->setElementKerning(font.kerning()); if (mask & QFont::StyleStrategyResolved) { const QMetaEnum styleStrategy_enum = metaEnum<QAbstractFormBuilderGadget>("styleStrategy"); fnt->setElementStyleStrategy(QLatin1String(styleStrategy_enum.valueToKey(font.styleStrategy()))); } dom_prop->setElementFont(fnt); } return true; #ifndef QT_NO_CURSOR case QVariant::Cursor: { const QMetaEnum cursorShape_enum = metaEnum<QAbstractFormBuilderGadget>("cursorShape"); dom_prop->setElementCursorShape(QLatin1String(cursorShape_enum.valueToKey(qvariant_cast<QCursor>(v).shape()))); } return true; #endif case QVariant::KeySequence: { DomString *s = new DomString(); s->setText(qvariant_cast<QKeySequence>(v).toString(QKeySequence::PortableText)); dom_prop->setElementString(s); } return true; case QVariant::Locale: { DomLocale *dom = new DomLocale(); const QLocale locale = qvariant_cast<QLocale>(v); const QMetaEnum language_enum = metaEnum<QAbstractFormBuilderGadget>("language"); const QMetaEnum country_enum = metaEnum<QAbstractFormBuilderGadget>("country"); dom->setAttributeLanguage(QLatin1String(language_enum.valueToKey(locale.language()))); dom->setAttributeCountry(QLatin1String(country_enum.valueToKey(locale.country()))); dom_prop->setElementLocale(dom); } return true; case QVariant::SizePolicy: { DomSizePolicy *dom = new DomSizePolicy(); const QSizePolicy sizePolicy = qvariant_cast<QSizePolicy>(v); dom->setElementHorStretch(sizePolicy.horizontalStretch()); dom->setElementVerStretch(sizePolicy.verticalStretch()); const QMetaEnum sizeType_enum = metaEnum<QAbstractFormBuilderGadget>("sizeType"); dom->setAttributeHSizeType(QLatin1String(sizeType_enum.valueToKey(sizePolicy.horizontalPolicy()))); dom->setAttributeVSizeType(QLatin1String(sizeType_enum.valueToKey(sizePolicy.verticalPolicy()))); dom_prop->setElementSizePolicy(dom); } return true; case QVariant::Date: { DomDate *dom = new DomDate(); const QDate date = qvariant_cast<QDate>(v); dom->setElementYear(date.year()); dom->setElementMonth(date.month()); dom->setElementDay(date.day()); dom_prop->setElementDate(dom); } return true; case QVariant::Time: { DomTime *dom = new DomTime(); const QTime time = qvariant_cast<QTime>(v); dom->setElementHour(time.hour()); dom->setElementMinute(time.minute()); dom->setElementSecond(time.second()); dom_prop->setElementTime(dom); } return true; case QVariant::DateTime: { DomDateTime *dom = new DomDateTime(); const QDateTime dateTime = qvariant_cast<QDateTime>(v); dom->setElementHour(dateTime.time().hour()); dom->setElementMinute(dateTime.time().minute()); dom->setElementSecond(dateTime.time().second()); dom->setElementYear(dateTime.date().year()); dom->setElementMonth(dateTime.date().month()); dom->setElementDay(dateTime.date().day()); dom_prop->setElementDateTime(dom); } return true; case QVariant::Url: { DomUrl *dom = new DomUrl(); const QUrl url = v.toUrl(); DomString *str = new DomString(); str->setText(url.toString()); dom->setElementString(str); dom_prop->setElementUrl(dom); } return true; case QVariant::StringList: { DomStringList *sl = new DomStringList; sl->setElementString(qvariant_cast<QStringList>(v)); dom_prop->setElementStringList(sl); } return true; default: break; } return false; }