void CurrencyWidget::localeChanged(QLocale locale) { setLocale(locale); currencySymbol->setText(locale.currencySymbol()); currencyISO->setText(locale.currencySymbol(QLocale::CurrencyIsoCode)); currencyName->setText(locale.currencySymbol(QLocale::CurrencyDisplayName)); updateCurrencyFormatting(); }
void OptionsDialog::setupCurrenciesModel() { /* QList<QLocale> locales = QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript, QLocale::AnyCountry); foreach (QLocale locale, locales) { QString isoCode = locale.currencySymbol(QLocale::CurrencyIsoCode); if(!_uniqueCurrencies.contains(isoCode)){ _uniqueCurrencies.insert(isoCode, locale.currencySymbol(QLocale::CurrencySymbol)); } } ui->currencyComboBox->addItems(_uniqueCurrencies.keys()); */ ui->currencyComboBox->addItems(CurrencyHelper::currencies(CurrencyHelper::All)); QLocale defaultLocale; ui->currencyFormatComboBox->addItem(defaultLocale.currencySymbol(QLocale::CurrencyIsoCode), QLocale::CurrencyIsoCode); ui->currencyFormatComboBox->addItem(defaultLocale.currencySymbol(QLocale::CurrencySymbol), QLocale::CurrencySymbol); }
QV4::ReturnedValue QQmlLocaleData::method_currencySymbol(QV4::CallContext *ctx) { QLocale *locale = getThisLocale(ctx); if (!locale) return QV4::Encode::undefined(); if (ctx->argc() > 1) V4THROW_ERROR("Locale: currencySymbol(): Invalid arguments"); QLocale::CurrencySymbolFormat format = QLocale::CurrencySymbol; if (ctx->argc() == 1) { quint32 intFormat = ctx->args()[0].toNumber(); format = QLocale::CurrencySymbolFormat(intFormat); } return ctx->d()->engine->newString(locale->currencySymbol(format))->asReturnedValue(); }
void BudgetEntityDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { if (index.column() != 0 || !index.data().canConvert<BudgetEntity>()) { QStyledItemDelegate::paint(painter, option, index); return; } BudgetEntity entity = qvariant_cast<BudgetEntity>(index.data()); painter->save(); painter->setRenderHint(QPainter::Antialiasing); QLocale locale; QStyleOptionViewItemV4 opt = option; QStyledItemDelegate::initStyleOption(&opt, index); QRect rect = opt.rect; opt.text = ""; QStyle *style = opt.widget ? opt.widget->style() : QApplication::style(); style->drawControl(QStyle::CE_ItemViewItem, &opt, painter, opt.widget); QPalette::ColorGroup cg = opt.state & QStyle::State_Enabled ? QPalette::Normal : QPalette::Disabled; if (opt.state & QStyle::State_Selected) { painter->setPen(opt.palette.color(cg, QPalette::HighlightedText)); } else { painter->setPen(opt.palette.color(cg, QPalette::Text)); } if (dateWidth <= 0) { QDate _date = QDate(9999, 12, 29); //*((int*)(&dateWidth)) = painter->fontMetrics().width(_date.toString(locale.dateFormat(QLocale::ShortFormat))) + 10; dateWidth = painter->fontMetrics().width(_date.toString(locale.dateFormat(QLocale::ShortFormat))) + 10;; } QString amount = locale.toCurrencyString(entity.amount(), locale.currencySymbol(QLocale::CurrencySymbol)); int amountWidth = painter->fontMetrics().width(amount); QRect adj = rect.adjusted(3, rect.height()/3, -3, rect.height()/3); painter->drawText(adj.adjusted(0, 0, -amountWidth, 0), Qt::TextSingleLine, entity.date().toString(locale.dateFormat(QLocale::ShortFormat))); painter->drawText(adj.adjusted(adj.left() + dateWidth, 0, -amountWidth, 0), Qt::TextWordWrap, entity.description()); painter->drawText(adj.adjusted(adj.left() + dateWidth + amountWidth, 0, 0, 0), Qt::AlignRight | Qt::TextSingleLine, amount); painter->restore(); }
QWidget *BudgetEntityDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem & /*option*/, const QModelIndex & /*index*/) const { QLocale locale; QWidget *editor = new QWidget(parent); QHBoxLayout *lay = new QHBoxLayout; QDateEdit *dateEdit = new QDateEdit(QDate::currentDate()); QPlainTextEdit *textEdit = new QPlainTextEdit("Textedig"); QDoubleSpinBox *spinBox = new QDoubleSpinBox; dateEdit->setDisplayFormat("yyyy-MM-dd"); dateEdit->setCalendarPopup(true); spinBox->setMaximum(1e+08); spinBox->setMinimum(-1e+07); spinBox->setPrefix(locale.currencySymbol(QLocale::CurrencySymbol)); spinBox->setAlignment(Qt::AlignVCenter | Qt::AlignRight); editor->setLayout(lay); lay->addWidget(dateEdit); lay->addWidget(textEdit); lay->addWidget(spinBox); return editor; }