示例#1
0
/* //added by Rolando 04-11-08
 * initFlagListWidget: initializes QtFlagsListWidget with items according QtFlagsManager
 * parameters:  QtFlagsManager * qtFlagsManager, QString flagsNameLanguage
 * returns QString, the country name default stored in config
*/
QString QtFlagsListWidget::init(QtFlagsManager * qtFlagsManager, QComboBox * comboBox, QString flagsNameLanguage) {
    _qListWidget->clear();//VOXOX CHANGE by Rolando - 2009.06.12
    Config & config = ConfigManager::getInstance().getCurrentConfig();
    QString defaultFlagNameFile = QString::fromStdString(config.getCurrentFlag());//gets the default flagname file according config
    QString countryNameDefault = QString::null;

    QListWidgetItem *newItem = new QListWidgetItem();
    QFont font = _qListWidget->font();//VOXOX CHANGE by Rolando - 2009.06.12

    //gets the largest country name text and sets its name to the variable
    QString largestCountryNameText = qtFlagsManager->getLargestCountryNameText();

    //gets the largest country name size in pixels
    int largestCountryNamePixelSize = qtFlagsManager->getPixelSizeText(largestCountryNameText, font);


    int blankSpacePixelSize = qtFlagsManager->getPixelSizeText(QString(" "), font);
    int largestCountryCodePixelSize = 0;

    //gets the flaglist according flagsNameLanguage
    QtFlagsManager::QtFlagList flagList = qtFlagsManager->getQtFlagList(flagsNameLanguage);
    QtFlagsManager::QtFlagList::iterator it;
    QString countryName;
    QString areaCode;
    int numberTimes = 0;
    int tmpCountryCodePixelSize = 0;
    for (it = flagList.begin(); it != flagList.end(); it++) {
        countryName = it->getDefaultCountryName();//gets the country name
        areaCode = it->getDefaultCountryCode();
        //gets number times what FILL_CHAR is needed to justify the country name with code area number
        numberTimes = numberTimesToFillWithChar(FILL_CHAR, largestCountryNamePixelSize, countryName, font);
        if(numberTimes == -1) { // if it is not necessary to fill with FILL_CHAR
            numberTimes = 0;
        }

        newItem = new QListWidgetItem(QIcon(it->getPixmap()),it->getDefaultCountryName().leftJustified(countryName.size()+numberTimes, FILL_CHAR) + QString(" ") + it->getDefaultCountryCode(),_qListWidget);

        if(defaultFlagNameFile == it->getFlagNameFile()) { //if the country name is the default then sets their corresponding flag image to flagButton and selects it on _qtFlagsListWidget
            setDefaultFlag(newItem);
            countryNameDefault = countryName;

        }
    }

    //sortItems();

    //adds a item with text "None" because if we want to dial to another country not available on list or to dial a special phone number not must choose an area code, i.e the voice mail
    newItem = new QListWidgetItem(QIcon(QString::fromStdString(":/flags/none.png")),QString("None"));
    _qListWidget->insertItem ( 0, newItem );

    int totalPixelsSizeCountryName = getWidthNeededInItem(qtFlagsManager, flagsNameLanguage);
    setWidthSize(totalPixelsSizeCountryName);

    return countryNameDefault;

}
示例#2
0
const QtFlag QtVoxOxCallBarFrame::getFlagByPhoneNumber(QtFlagsManager * qtFlagsManager, QString flagsNameLanguage, QString text,QString prefix, bool * error, QString * codeAreaFound ){

	if( text.indexOf(QRegExp("([0-9#\\*])+")) != -1){//if it is a phone number not a contact name
		QtFlagsManager::QtFlagList flagList = qtFlagsManager->getQtFlagList(flagsNameLanguage);
		QtFlagsManager::QtFlagList::iterator it;
		int maxLength = 0;
		int matchedLength = 0;
		QtFlag * flagReturned =  new QtFlag();
		QString areaCode = QString("");
		QRegExp * codeAreaRegExp =  new QRegExp();
		if( text.startsWith ( QChar('+')) ){
			text.replace( 0 ,1, prefix);
		}

		for (it = flagList.begin(); it != flagList.end(); it++) {
			QString countryCode = it->getCountryCode();//gets the country code
			if( countryCode.startsWith ( QChar('+')) ){
				countryCode.replace( 0 ,1, prefix);
				codeAreaRegExp->setPattern(QString("^") + countryCode);
				if(codeAreaRegExp->indexIn(text) != -1){
					matchedLength = codeAreaRegExp->matchedLength();
					if(matchedLength > maxLength){
						areaCode = codeAreaRegExp->cap();						
						*flagReturned = *it;
						maxLength = matchedLength;
					}
				}
			}

			
		}
		
		if(maxLength > 0){
			areaCode.remove(0, prefix.size());
			*codeAreaFound = areaCode;
			*error =  false;
			return *flagReturned;
		}
		else{
			if(text.startsWith(QString("1"))){//VOXOX CHANGE by Rolando - 2009.06.28 
				*codeAreaFound = QString("1");//VOXOX CHANGE by Rolando - 2009.06.28 
				*error =  false;//VOXOX CHANGE by Rolando - 2009.06.28 
				return _qtFlagsManager->getFlagByCountryName(COUNTRY_NAME_USA, FLAGS_NAME_LANGUAGE);	//VOXOX CHANGE by Rolando - 2009.06.28 		
			}
		}
	}
			
	*error = true;//flag was not found so sets error equal true
	return QtFlag();//necessary to return something in case that an areaCode was not found in parameter text
}
示例#3
0
/* //added by Rolando 04-11-08
 * getWidthNeededInItem: gets the width size needed in QtListWidget according the largest text in QtFlagsManager
 * parameters:  QtFlagsManager * qtFlagsManager, QString flagsNameLanguage
 * returns int, the width size needed in QtListWidget
*/
int QtFlagsListWidget::getWidthNeededInItem( QtFlagsManager * qtFlagsManager, QString flagsNameLanguage) {

    QFont font = _qListWidget->font();	//VOXOX CHANGE by Rolando - 2009.06.12

    //gets the largest country name text and sets their name to the variable
    QString largestCountryNameText = qtFlagsManager->getLargestCountryNameText();

    QtFlag flag = qtFlagsManager->getFlagByCountryName(largestCountryNameText,flagsNameLanguage);

    //gets the largest country name size in pixels
    int largestCountryNamePixelSize = qtFlagsManager->getPixelSizeText(largestCountryNameText, font);

    int pixmapWidthSize = flag.getPixmap().width();
    int blankSpacePixelSize = qtFlagsManager->getPixelSizeText(QString(" "), font);
    int largestCountryCodePixelSize = 0;

    //gets the flaglist according flagsNameLanguage
    QtFlagsManager::QtFlagList flagList = qtFlagsManager->getQtFlagList(flagsNameLanguage);
    QtFlagsManager::QtFlagList::iterator it;

    QString areaCode;
    int tmpCountryCodePixelSize = 0;

    for (it = flagList.begin(); it != flagList.end(); it++) {
        areaCode = it->getDefaultCountryCode();
        tmpCountryCodePixelSize =  qtFlagsManager->getPixelSizeText(areaCode, font);

        if(tmpCountryCodePixelSize > largestCountryCodePixelSize) {
            largestCountryCodePixelSize	= tmpCountryCodePixelSize;
        }
    }

    //because the format in item of QtFlagsListWidget is pixmap + blank space + countryName + blank space + areaCode + blank space
    int totalPixelsSizeCountryName = pixmapWidthSize + blankSpacePixelSize + largestCountryNamePixelSize + blankSpacePixelSize + largestCountryCodePixelSize + blankSpacePixelSize;
    return totalPixelsSizeCountryName;
}