QSize YaAvatarLabel::sizeHint() const { if (avatar().isNull()) return maximumSize(); return avatar().actualSize(maximumSize()); }
ConnectionDialog::ConnectionDialog(QWidget *parent) : QDialog(parent), ui(new Ui::ConnectionDialog) { ui->setupUi(this); ui->nameLineEdit->setText(Config.UserName); ui->nameLineEdit->setMaxLength(32); ui->hostComboBox->addItems(Config.HistoryIPs); ui->hostComboBox->lineEdit()->setText(Config.HostAddress); ui->getNodeListButton->setFocus(); ui->portLineEdit->setText(QString::number(Config.ServerPort)); ui->portLineEdit->setValidator(new QIntValidator(1, 9999, ui->portLineEdit)); // ui->connectButton->setFocus(); const General *avatar_general = Sanguosha->getGeneral(Config.UserAvatar); if(avatar_general){ QPixmap avatar(avatar_general->getPixmapPath("big")); ui->avatarPixmap->setPixmap(avatar); } QList<const General*> generals = Sanguosha->findChildren<const General*>(); foreach(const General *general, generals){ QIcon icon(general->getPixmapPath("big")); QString text = Sanguosha->translate(general->objectName()); QListWidgetItem *item = new QListWidgetItem(icon, text, ui->avatarList); item->setData(Qt::UserRole, general->objectName()); }
void ContactInfoDialog::Private::onChangeAvatarButtonClicked() { QPointer<QFileDialog> fileDialog = new QFileDialog(q); // fileDialog->setPreviewWidget(new KImageFilePreview(fileDialog)); //TODO KF5 - is there a replacement? fileDialog->setMimeTypeFilters(QStringList() << QStringLiteral("image/*")); fileDialog->setFileMode(QFileDialog::ExistingFile); int c = fileDialog->exec(); if (fileDialog && c && !fileDialog->selectedFiles().isEmpty()) { newAvatarFile = fileDialog->selectedFiles().first(); QPixmap avatar(newAvatarFile); if (avatar.isNull()) { KMessageBox::error(q, i18n("Failed to load the new avatar image")); newAvatarFile.clear(); delete fileDialog; return; } avatarLabel->setPixmap(avatar.scaled(avatarLabel->maximumSize(), Qt::KeepAspectRatio, Qt::SmoothTransformation)); avatarChanged = true; clearAvatarButton->setEnabled(true); } delete fileDialog; }
bool TrainerTeam::loadFromFile(const QString &path) { QFile file(path); if (!file.open(QFile::ReadOnly)) { return false; } QDomDocument document; QString msg; int line,col; if(!document.setContent(&file,&msg,&line,&col)) { QMessageBox::information(0,QObject::tr("Load Team"),QObject::tr("Error while loading the team.")); return false; } QDomElement team = document.firstChildElement("Team"); if(team.isNull()) { QMessageBox::information(0,QObject::tr("Load Team"),QObject::tr("Error while loading the team.")); return false; } int version = team.attribute("version", "0").toInt(); if (version > 1) { QMessageBox::information(0,QObject::tr("Load Team"),QObject::tr("Error while loading the team, the client is outdated.")); return false; } int gen = team.attribute("gen", "4").toInt(); if (gen < GEN_MIN || gen > GEN_MAX) gen = GEN_MAX; this->team().setGen(gen); defaultTier() = team.attribute("defaultTier"); QDomElement trainer = team.firstChildElement("Trainer"); if(trainer.isNull()) { QMessageBox::information(0,QObject::tr("Load Team"),QObject::tr("Error while loading the team.")); return false; } setTrainerNick(trainer.text()); setTrainerInfo(trainer.attribute("infoMsg")); setTrainerLose(trainer.attribute("loseMsg")); setTrainerWin(trainer.attribute("winMsg")); avatar() = trainer.attribute("avatar", 0).toInt(); QDomElement poke = team.firstChildElement("Pokemon"); int cpt = 0; while(!poke.isNull()) { this->team().poke(cpt).loadFromXml(poke, version); cpt++; poke = poke.nextSiblingElement("Pokemon"); } return true; }
void TimeImpl::initialize() { //we either already have the avatar, or we need to wait until it's been created Eris::Avatar* avatar(0); if ((avatar = EmberServices::getSingleton().getServerService().getAvatar())) { createCalendar(avatar); } else { EmberServices::getSingleton().getServerService().GotAvatar.connect(sigc::mem_fun(*this, &TimeImpl::Server_GotAvatar)); } }
void ConnectionDialog::on_avatarList_itemDoubleClicked(QListWidgetItem *item) { QString general_name = item->data(Qt::UserRole).toString(); QPixmap avatar(G_ROOM_SKIN.getGeneralPixmap(general_name, QSanRoomSkin::S_GENERAL_ICON_SIZE_LARGE)); ui->avatarPixmap->setPixmap(avatar); Config.UserAvatar = general_name; Config.setValue("UserAvatar", general_name); hideAvatarList(); setFixedWidth(ShrinkWidth); }
void CDoodChatManagerModel::updateItemNameAndAvatar(QString localId,QString userId) { QString tmp = chatType(); if(chatType()=="1"){ CDoodChatItem* item = m_pChatMap.value(localId,NULL); if(item != NULL){ if(item->fromId() == mAccountUserId){ item->setContactThumbAvatar(mAccountAvater); item->setName(mAccountName); }else{ item->setContactThumbAvatar(avatar()); if(item->name() == item->fromId()){ item->setName(name()); } } } }else if(chatType()=="2"){ CDoodChatItem* item = m_pChatMap.value(localId,NULL); //emit reqestUserInfo(item->fromId()); if(item != NULL){ if(item->fromId() == mAccountUserId){ item->setContactThumbAvatar(mAccountAvater); item->setName(mAccountName); }else{ int size = mGroupMemList.size(); if(size == 0){ //emit reqestUserInfo(item->fromId()); }else{ for(int i=0;i<size;++i){ Member mem = mGroupMemList.at(i); if(mem.id == item->fromId()){ item->setContactThumbAvatar(mem.thumbAvatar); if(item->name() ==item->fromId()){ item->setName(mem.name); } updateGroupChatInfo(mem.id,mem.name,mem.thumbAvatar); return; } } } } } }else if(chatType() == "6"){ CDoodChatItem* item = m_pChatMap.value(localId,NULL); if(item != NULL){ if(!item->contactThumbAvatar().startsWith("qrc")){ item->setContactThumbAvatar(mAccountAvater); item->setName(mAccountName); }else{ item->setName("我的电脑"); } } } }
void Login::on_userid_comboBox_editTextChanged(const QString &arg1) { QString path =UserData::AvatarPath + arg1+".png"; QFile avatar(path); if(!avatar.exists()) { return; } ui->avatar_label->setPixmap(QPixmap(path)); }
void TalkablePainter::computeAvatarRect() { AvatarRect = QRect(ItemRect.x() + ItemRect.width(), ItemRect.y(), 0, 0); if (!Configuration->showAvatars()) return; int width = Configuration->defaultAvatarSize().width() + HFrameMargin; AvatarRect.setWidth(width); AvatarRect.moveLeft(AvatarRect.left() - width); if (!avatar().isNull()) AvatarRect.setHeight(Configuration->defaultAvatarSize().height() + 2 * VFrameMargin); }
void AvatarWidget::refreshAvatarImage() { if (mGxsId.isNull()==false) { QPixmap avatar; AvatarDefs::getAvatarFromGxsId(mGxsId, avatar, defaultAvatar); setPixmap(avatar); return; } if (mId.isNotSet()) { QPixmap avatar(defaultAvatar); setPixmap(avatar); return; } else if (mFlag.isOwnId && mId.isPeerId()) { QPixmap avatar; AvatarDefs::getOwnAvatar(avatar); setPixmap(avatar); return; } else if (mId.isPeerId()) { QPixmap avatar; AvatarDefs::getAvatarFromSslId(mId.toPeerId(), avatar, defaultAvatar); setPixmap(avatar); return; } else if (mId.isDistantChatId()) { QPixmap avatar; DistantChatPeerInfo dcpinfo ; if(rsMsgs->getDistantChatStatus(mId.toDistantChatId(),dcpinfo)) { if(mFlag.isOwnId) AvatarDefs::getAvatarFromGxsId(dcpinfo.own_id, avatar, defaultAvatar); else AvatarDefs::getAvatarFromGxsId(dcpinfo.to_id, avatar, defaultAvatar); setPixmap(avatar); return; } } else std::cerr << "WARNING: unhandled situation in AvatarWidget::refreshAvatarImage()" << std::endl; }
void AvatarWidget::updateAvatar(const QString &peerId) { if (mId.empty()) { QPixmap avatar(defaultAvatar); setPixmap(avatar); return; } if (mFlag.isOwnId) { QPixmap avatar; AvatarDefs::getOwnAvatar(avatar); setPixmap(avatar); return; } if (mFlag.isGpg) { if (mId == peerId.toStdString()) { /* called from AvatarWidget with gpg id */ QPixmap avatar; AvatarDefs::getAvatarFromGpgId(mId, avatar, defaultAvatar); setPixmap(avatar); return; } /* Is this one of the ssl ids of the gpg id ? */ std::list<std::string> sslIds; if (rsPeers->getAssociatedSSLIds(mId, sslIds) == false) { return; } if (std::find(sslIds.begin(), sslIds.end(), peerId.toStdString()) != sslIds.end()) { /* One of the ssl ids of the gpg id */ QPixmap avatar; AvatarDefs::getAvatarFromGpgId(mId, avatar, defaultAvatar); setPixmap(avatar); } return; } if (mId == peerId.toStdString()) { QPixmap avatar; AvatarDefs::getAvatarFromSslId(mId, avatar, defaultAvatar); setPixmap(avatar); return; } }
void lmcChatRoomWindow::setUserAvatar(QString* lpszUserId, QString* lpszFilePath) { QTreeWidgetItem* pUserItem = getUserItem(lpszUserId); if(!pUserItem) return; QDir cacheDir(StdLocation::cacheDir()); QString fileName = "avt_" + *lpszUserId + ".png"; QString filePath = cacheDir.absoluteFilePath(fileName); QPixmap avatar(filePath); avatar = avatar.scaled(QSize(32, 32), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); pUserItem->setData(0, AvatarRole, QIcon(avatar)); if(lpszFilePath) filePath = *lpszFilePath; pMessageLog->updateAvatar(lpszUserId, &filePath); }
QImage AvatarJob::makeCircularAvatar(const QImage &baseAvatar) { int dim = baseAvatar.width(); QImage avatar(dim, dim, baseAvatar.format()); avatar.fill(Qt::transparent); QPainter painter(&avatar); painter.setRenderHint(QPainter::Antialiasing); QPainterPath path; path.addEllipse(0, 0, dim, dim); painter.setClipPath(path); painter.drawImage(0, 0, baseAvatar); painter.end(); return avatar; }
void CDoodChatManagerModel::setName(const QString &name) { qDebug() << Q_FUNC_INFO; mName = name; emit nameChanged(); QList<CDoodChatItem*> list = m_pChatMap.values(); for(int i = 0;i<list.size();++i){ CDoodChatItem* item = list.at(i); if(item != NULL){ if(item->fromId() == id() && chatType() == "1"){ item->setName(name); if(item->contactThumbAvatar() ==""){ item->setContactThumbAvatar(avatar()); } } } } }
/** * Saves and then loads an Avatar, then ensures that the loaded Avatar matched the original. */ TEST(TestAvatarSerializer, TestSaveAndLoad) { // Create the new avatar Avatar avatar("SomeCreativeNameHere", 23, ClassType::Mage); // Save the avatar to disk AvatarSerializer::GetInstance().SaveAvatar(avatar); // Load the avatar ASSERT_TRUE(AvatarSerializer::GetInstance().LoadAvatar("SomeCreativeNameHere")); // Make sure the loaded avatar matches our original Avatar *loadedAvatar = AvatarSerializer::GetInstance().GetPlayer(); EXPECT_EQ(avatar.GetName(), loadedAvatar->GetName()); EXPECT_EQ(avatar.GetLevel(), loadedAvatar->GetLevel()); EXPECT_EQ(avatar.GetClass().GetClassType(), loadedAvatar->GetClass().GetClassType()); std::remove("SomeCreativeNameHere.dat"); // Remove the saved avatar }
void RoundedPixmap::paintEvent(QPaintEvent * event) { QPainter painter(this); painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing, true); QPixmap blank(this->pixmap()->size()); blank.fill(QColor(0,0,0,0)); QPixmap avatar(*this->pixmap()); QPainter compPainter(&blank); compPainter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing, true); compPainter.setBrush(Qt::white); compPainter.setPen(QColor(0,0,0,0)); compPainter.drawRoundedRect(avatar.rect(), 5,5); compPainter.setCompositionMode(QPainter::CompositionMode_SourceIn); compPainter.drawPixmap(QPoint(0,0), avatar); painter.drawPixmap(QPoint(0,0), blank); }
void TrainerTeam::toXml(QDomDocument &document) const { QDomElement Team = document.createElement("Team"); Team.setAttribute("gen", team().gen()); Team.setAttribute("defaultTier", defaultTier()); Team.setAttribute("version", 1); document.appendChild(Team); QDomElement trainer = document.createElement("Trainer"); Team.appendChild(trainer); QDomText trainerName = document.createTextNode(trainerNick()); trainer.appendChild(trainerName); trainer.setAttribute("winMsg",trainerWin()); trainer.setAttribute("loseMsg",trainerLose()); trainer.setAttribute("infoMsg",trainerInfo()); trainer.setAttribute("avatar", avatar()); for(int i = 0; i < 6; i++) { QDomElement pokemon = document.createElement("Pokemon"); Team.appendChild(team().poke(i).toXml(pokemon)); } }
void NickListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { // save painter->save(); QString strNicklistNickColor = Settings::instance()->get("nicklist_nick_color"); QString strNicklistSelectedNickColor = Settings::instance()->get("nicklist_selected_nick_color"); QString strNicklistBusyNickColor = Settings::instance()->get("nicklist_busy_nick_color"); QString strNicklistGradient1Color = Settings::instance()->get("nicklist_gradient_1_color"); QString strNicklistGradient2Color = Settings::instance()->get("nicklist_gradient_2_color"); QPen fontPen(QColor(strNicklistNickColor), 1, Qt::SolidLine); QPen selectedFontPen(QColor(strNicklistSelectedNickColor), 1, Qt::SolidLine); QPen busyPen(QColor(strNicklistBusyNickColor), 1, Qt::SolidLine); QColor cUserSexMale = QColor("#71A3FF"); QColor cUserSexFemale = QColor("#FF49BF"); QColor cUserSexUnknown = QColor("#999999"); QColor cGradient1 = QColor(strNicklistGradient1Color); QColor cGradient2 = QColor(strNicklistGradient2Color); int marginLeft = 3; int marginRight = 3; bool selected; if (option.state & QStyle::State_Selected) { QLinearGradient backgroundGradient(option.rect.left(), option.rect.top(), option.rect.left(), option.rect.bottom()); backgroundGradient.setColorAt(0.0, cGradient1); backgroundGradient.setColorAt(1.0, cGradient2); painter->fillRect(option.rect, QBrush(backgroundGradient)); painter->setPen(selectedFontPen); selected = true; } /* #ifndef Q_OS_WIN else if (option.state & QStyle::State_MouseOver) { painter->fillRect(option.rect, option.palette.highlight()); painter->setPen(selectedFontPen); selected = true; } #endif */ else { painter->setPen(fontPen); selected = false; } QString nick = index.data(Qt::DisplayRole).toString(); QString modes = index.data(NickListModesRole).toString(); QString userAvatar = index.data(NickListAvatarUrlRole).toString(); QChar userSex = index.data(NickListSexRole).toChar(); QString channel = index.data(NickListChannelRole).toString(); bool busy = false; bool statusIcons = true; QList<QIcon> icons; if (modes.contains(FLAG_BUSY)) { busy = true; } if ((modes.contains(FLAG_CAM_PRIV)) && (channel.at(0) == '^')) { icons << QIcon(":/images/privcam.png"); } if (modes.contains(FLAG_CAM_PUB)) { icons << QIcon(":/images/pubcam.png"); } if (modes.contains(FLAG_VOICE)) { icons << QIcon(":/images/voice.png"); } if (modes.contains(FLAG_SCREENER)) { icons << QIcon(":/images/screener.png"); } if (modes.contains(FLAG_MOD)) { icons << QIcon(":/images/mod.png"); } if (modes.contains(FLAG_HALFOP)) { icons << QIcon(":/images/halfop.png"); } if (modes.contains(FLAG_OP)) { icons << QIcon(":/images/op.png"); } if (modes.contains(FLAG_OWNER)) { icons << QIcon(":/images/owner.png"); } if (modes.contains(FLAG_DEV)) { icons << QIcon(":/images/dev.png"); } else if (modes.contains(FLAG_BOT)) { icons << QIcon(":/images/bot.png"); } else if (modes.contains(FLAG_ADMIN)) { icons << QIcon(":/images/admin.png"); } // avatar if (Themes::instance()->isCurrentWithNicklistAvatar()) { // is valid avatar if (userAvatar.isEmpty()) { if (nick.at(0) == '~') userAvatar = Avatar::instance()->getEmptyUnregisteredUserAvatar(); else userAvatar = Avatar::instance()->getEmptyRegisteredUserAvatar(); } else userAvatar = Avatar::instance()->getAvatarPath(userAvatar); QIcon avatar(userAvatar); int x = option.rect.left(); int y = option.rect.top(); int w = 35; int h = 35; avatar.paint(painter, x, y, w, h); } // sex if ((nick.at(0) != '~') && (Themes::instance()->isCurrentWithNicklistAvatar())) { if (userSex == USER_SEX_MALE || userSex == USER_SEX_FEMALE) { QColor cSexColor; if (userSex == USER_SEX_MALE) cSexColor = cUserSexMale; else if (userSex == USER_SEX_FEMALE) cSexColor = cUserSexFemale; else cSexColor = cUserSexUnknown; QRect rect = option.rect; int x = rect.x()+35+2; int y = rect.top()+1; int w = 2; int h = 35-2; painter->fillRect(x, y, w, h, cSexColor); } } // nick if (Themes::instance()->isCurrentWithNicklistAvatar()) { QRect rect = option.rect; // with avatars if ((busy) && (!selected)) painter->setPen(busyPen); // gray QFont font = option.font; font.setWeight(busy ? QFont::Light : QFont::Normal); font.setItalic(busy ? true : false); painter->setFont(font); if (nick.at(0) != '~') rect.setX(rect.x()+35+5+5); else rect.setX(rect.x()+35+5); painter->drawText(rect, Qt::AlignVCenter | Qt::AlignLeft, nick); } else { QRect rect = option.rect; rect.setX(rect.x() + marginLeft); // without avatars if ((busy) && (!selected)) painter->setPen(busyPen); // gray QFont font = option.font; font.setWeight(busy ? QFont::Light : QFont::Normal); font.setItalic(busy ? true : false); painter->setFont(font); painter->drawText(rect, Qt::AlignVCenter | Qt::AlignLeft, nick); } // status icons if (statusIcons) { QRect rect = option.rect; rect.setX(rect.right() - marginRight); foreach (const QIcon &icon, icons) { rect.setX(rect.x() - 16); icon.paint(painter, rect, Qt::AlignVCenter | Qt::AlignAbsolute, QIcon::Normal, QIcon::On); } }
void YaAvatarLabel::paintAvatar(QPainter* painter) { Ya::VisualUtil::drawAvatar(painter, rect(), status_, avatar()); }
TrainerTeam::TrainerTeam() { avatar() = 0; }