void DirectShowVideoWidget::setProducer(Mlt::Producer *producer)
{
    QString resource = QString(producer->get("resource"));
    QString resource2 = QString(producer->get("resource2"));
    const char* videoDevice = "dshow:video=";
    const char* audioDevice = "dshow:audio=";
    if (resource.startsWith(videoDevice)) {
        QStringRef name = resource.midRef(qstrlen(videoDevice));
        for (int i = 1; i < ui->videoCombo->count(); i++) {
            if (ui->videoCombo->itemText(i) == name) {
                ui->videoCombo->setCurrentIndex(i);
                break;
            }
        }
    } else if (resource.startsWith(audioDevice)) {
        QStringRef name = resource.midRef(qstrlen(audioDevice));
        for (int i = 1; i < ui->audioCombo->count(); i++) {
            if (ui->audioCombo->itemText(i) == name) {
                ui->audioCombo->setCurrentIndex(i);
                break;
            }
        }
    }
    if (resource2.startsWith(audioDevice)) {
        QStringRef name = resource2.midRef(qstrlen(audioDevice));
        for (int i = 1; i < ui->audioCombo->count(); i++) {
            if (ui->audioCombo->itemText(i) == name) {
                ui->audioCombo->setCurrentIndex(i);
                break;
            }
        }
    }
    AbstractProducerWidget::setProducer(producer);
}
Example #2
0
MessageHandlerAsyncResult FormulaHandler::doHandle(Message &message)
{
	int index = 0;
	int lastIndex = 0;
	const QString html = message.html();
	QString newHtml;
	newHtml.reserve(html.size());
    while ((index = m_regexp.indexIn(html, index)) >= 0) {
		html.midRef(lastIndex, index - lastIndex).appendTo(&newHtml);
		// html is already escaped
		const QString equation = m_regexp.cap(0);
		const QString url = QLatin1String("http://latex.codecogs.com/png.latex?")
		                    + QUrl::toPercentEncoding(unescape(m_regexp.cap(1)));
		newHtml += QLatin1String("<img src=\"");
		newHtml += url;
		newHtml += QLatin1String("\"alt=\"");
		newHtml += equation;
		newHtml += QLatin1String("\" title=\"");
		newHtml += equation;
		newHtml += QLatin1String("\">");
		index += m_regexp.cap(0).length();
		lastIndex = index;
    }
	html.midRef(lastIndex, html.size() - lastIndex).appendTo(&newHtml);
	message.setHtml(newHtml);
	return makeAsyncResult(Accept, QString());
}
Example #3
0
void RemoteClient::receive(void)
{
    static QString buffer;

    buffer.append(this->readLine());

    int tOpenB = buffer.indexOf('<');
    int tOpenE = buffer.indexOf('>');
    int tCloseB = buffer.lastIndexOf('<');
    int tCloseE = buffer.lastIndexOf('>');

    QStringRef tag = buffer.midRef(tOpenB + 1, tOpenE - tOpenB - 1);
    QStringRef tagClose = buffer.midRef(tCloseB + 1, tCloseE - tCloseB - 1);

    if (tag == "command" && tagClose == "/command")
    {
        Command command(Command::stringToType(buffer.midRef(tOpenE + 1, tCloseB - tOpenE - 1)));

        if (!command.isNull())
        {
            MSG("command " << Command::typeToString(command.type()) << " received");
            emit this->command(command);
        }

        buffer.clear();
    }
    else if (tag == "data" && tagClose == "/data")
    {

    }
}
Example #4
0
void Widget::midRefFunction()
{
    //! [midRef]
    QString x = "Nine pineapples";
    QStringRef y = x.midRef(5, 4);      // y == "pine"
    QStringRef z = x.midRef(5);         // z == "pineapples"
    //! [midRef]
}
Example #5
0
QString QgsActionManager::expandAction( const QString& action, QgsFeature &feat, const QMap<QString, QVariant> *substitutionMap )
{
  // This function currently replaces each expression between [% and %]
  // in the action with the result of its evaluation on the feature
  // passed as argument.

  // Additional substitutions can be passed through the substitutionMap
  // parameter

  QString expr_action;

  int index = 0;
  while ( index < action.size() )
  {
    QRegExp rx = QRegExp( "\\[%([^\\]]+)%\\]" );

    int pos = rx.indexIn( action, index );
    if ( pos < 0 )
      break;

    int start = index;
    index = pos + rx.matchedLength();

    QString to_replace = rx.cap( 1 ).trimmed();
    QgsDebugMsg( "Found expression: " + to_replace );

    if ( substitutionMap && substitutionMap->contains( to_replace ) )
    {
      expr_action += action.mid( start, pos - start ) + substitutionMap->value( to_replace ).toString();
      continue;
    }

    QgsExpression exp( to_replace );
    if ( exp.hasParserError() )
    {
      QgsDebugMsg( "Expression parser error: " + exp.parserErrorString() );
      expr_action += action.midRef( start, index - start );
      continue;
    }

    QgsExpressionContext context = createExpressionContext();
    context.setFeature( feat );

    QVariant result = exp.evaluate( &context );
    if ( exp.hasEvalError() )
    {
      QgsDebugMsg( "Expression parser eval error: " + exp.evalErrorString() );
      expr_action += action.midRef( start, index - start );
      continue;
    }

    QgsDebugMsg( "Expression result is: " + result.toString() );
    expr_action += action.mid( start, pos - start ) + result.toString();
  }

  expr_action += action.midRef( index );
  return expr_action;
}
void WebDavInventoryDataModel::FetchRootFolder()
{
    webdavclient_ = pythonQtMainModule_.evalScript("connection.WebDavClient()\n", Py_eval_input);
    if (!webdavclient_)
    {
        ErrorOccurredCreateEmptyRootFolder();
        return;
    }

    // Set urls
    webdavclient_.call("setHostAndUser", QVariantList() << webdavIdentityUrl_ << webdavUrl_);
    // Connect to webdav
    webdavclient_.call("setupConnection");
    // Fetch root resources
    QStringList rootResources = webdavclient_.call("listResources").toStringList();
    if (rootResources.count() < 1)
    {
        ErrorOccurredCreateEmptyRootFolder();
        return;
    }

    QMap<QString, QString> folders;
    InventoryFolder *parentFolder;
    for (int index=0; index<=rootResources.count(); index++)
    {
        folders[rootResources.value(index)] = rootResources.value(index+1);
        index++;
    }

    if (!rootFolder_)
    {
        rootFolder_ = new InventoryFolder("root", "Webdav Inventory", false, 0);
        parentFolder = new InventoryFolder("", QString("My Inventory"), false, rootFolder_);
        rootFolder_->AddChild(parentFolder);
        rootFolder_->SetDirty(true);
    }

    AbstractInventoryItem *newItem = 0;
    QString path;
    QString name;
    QString type;

    for (QMap<QString, QString>::iterator iter = folders.begin(); iter!=folders.end(); ++iter)
    {
        path = iter.key();
        name = path.midRef(0, path.lastIndexOf("/")).toString();
        name = path.midRef(path.lastIndexOf("/")).toString();
        type = iter.value();
        if (name != "")
        {
            if (type == "resource")
                newItem = new InventoryAsset(path, "", name, parentFolder);
            else
                newItem = new InventoryFolder(path, name, parentFolder, true);
            parentFolder->AddChild(newItem);
        }
    }
}
Example #7
0
QVariant Playlist::parse(QString filename)
{
    QStringList myList;
    QString filepath;
    QUrl url(filename);
    filepath = url.toLocalFile();

    QFile file(filepath);

    if (!file.exists()) {
        qDebug() << "File: " << file.fileName() << "does not exist";
    }

    if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
        qDebug() << "Couldn't open file: " << file.fileName();
    }

    // check file type
    bool m3uType = false;
    QTextStream stream(&file);
    QString line = stream.readLine();
    if (line.midRef(0,7) == "#EXTM3U" ) {
         //qDebug() << "valid M3U";
         m3uType = true;
    }
    else {
        qDebug() << "invalid file type";
        m3uType = false;
    }

    if (m3uType) {
        while(!stream.atEnd()) {
            QString line = stream.readLine();
            if (line.midRef(0,8) == "#EXTINF:" ) {
                int d1 = line.indexOf(",");
                myList << line.mid(8,d1-8).trimmed();                   // duration
                int d2 = line.indexOf(" - ");
                myList << line.mid(d1+1,d2-d1-1).trimmed();             // author
                myList << line.mid(d2+2,line.count()-d2+2).trimmed();   // title                
                line = stream.readLine();
                myList << line.trimmed();                                // file
                myList << getMimeType(line);                             // mime type
            }
            else {
            }
        }
    }


    file.close();

    return QVariant::fromValue(myList);
}
QStringRef Subtitle::Parser::processLine(int &idx, const QString &contents) {
	int from = idx;
	idx = contents.indexOf(QLatin1Char('\n'), from);
	if (idx < 0)
		idx = contents.indexOf(QLatin1Char('\r'), from);
	if (idx < 0) {
		idx = contents.size();
		return contents.midRef(from);
	} else {
		return contents.midRef(from, (idx++) - from);
	}
}
Example #9
0
QString QgsExpression::replaceExpressionText( const QString &action, const QgsExpressionContext *context, const QgsDistanceArea *distanceArea )
{
  QString expr_action;

  int index = 0;
  while ( index < action.size() )
  {
    QRegExp rx = QRegExp( "\\[%([^\\]]+)%\\]" );

    int pos = rx.indexIn( action, index );
    if ( pos < 0 )
      break;

    int start = index;
    index = pos + rx.matchedLength();
    QString to_replace = rx.cap( 1 ).trimmed();
    QgsDebugMsg( "Found expression: " + to_replace );

    QgsExpression exp( to_replace );
    if ( exp.hasParserError() )
    {
      QgsDebugMsg( "Expression parser error: " + exp.parserErrorString() );
      expr_action += action.midRef( start, index - start );
      continue;
    }

    if ( distanceArea )
    {
      //if QgsDistanceArea specified for area/distance conversion, use it
      exp.setGeomCalculator( distanceArea );
    }

    QVariant result = exp.evaluate( context );

    if ( exp.hasEvalError() )
    {
      QgsDebugMsg( "Expression parser eval error: " + exp.evalErrorString() );
      expr_action += action.midRef( start, index - start );
      continue;
    }

    QgsDebugMsg( "Expression result is: " + result.toString() );
    expr_action += action.mid( start, pos - start ) + result.toString();
  }

  expr_action += action.midRef( index );

  return expr_action;
}
Example #10
0
OSMAND_CORE_API QVector<QStringRef> OSMAND_CORE_CALL OsmAnd::ICU::getTextWrappingRefs(const QString& input, const int maxCharsPerLine)
{
    QVector<QStringRef> result;
    const auto lineStartIndices = getTextWrapping(input, maxCharsPerLine);
    result.reserve(lineStartIndices.size());
    auto lastStartIndex = lineStartIndices[0];
    for(auto idx = 1, count = lineStartIndices.size(); idx < count; idx++)
    {
        auto startIndex = lineStartIndices[idx];
        result.push_back(input.midRef(lastStartIndex, startIndex - lastStartIndex));
        lastStartIndex = startIndex;
    }
    result.push_back(input.midRef(lastStartIndex));
    return result;
}
Example #11
0
bool Okular::extractLilyPondSourceReference( const QString &url, QString *file, int *row, int *col )
{
    if ( !url.startsWith( QLatin1String( "textedit://" ) ) )
        return false;

    *row = 0;
    *col = 0;
    int lilyChar = 0;
    typedef int *IntPtr;
    const IntPtr int_data[] = { row, &lilyChar, col };
    int int_index = sizeof( int_data ) / sizeof( int* ) - 1;
    int index_last = -1;
    int index = url.lastIndexOf( QLatin1Char( ':' ), index_last );
    while ( index != -1 && int_index >= 0 )
    {
        // read the current "chunk"
        const QStringRef ref = url.midRef( index + 1, index_last - index - 1 );
        *int_data[ int_index ] = QString::fromRawData( ref.data(), ref.count() ).toInt();
        // find the previous "chunk"
        index_last = index;
        index = url.lastIndexOf( QLatin1Char( ':' ), index_last - 1 );
        --int_index;
    }
    // NOTE: 11 is the length of "textedit://"
    *file = QUrl::fromPercentEncoding( url.mid( 11, index_last != -1 ? index_last - 11 : -1 ).toUtf8() );
    return true;
}
Example #12
0
void MessageLinksParser::apply(
		const QString &text,
		const QVector<LinkRange> &ranges) {
	const auto count = int(ranges.size());
	const auto current = _list.current();
	const auto computeLink = [&](const LinkRange &range) {
		return range.custom.isEmpty()
			? text.midRef(range.start, range.length)
			: range.custom.midRef(0);
	};
	const auto changed = [&] {
		if (current.size() != count) {
			return true;
		}
		for (auto i = 0; i != count; ++i) {
			if (computeLink(ranges[i]) != current[i]) {
				return true;
			}
		}
		return false;
	}();
	if (!changed) {
		return;
	}
	auto parsed = QStringList();
	parsed.reserve(count);
	for (const auto &range : ranges) {
		parsed.push_back(computeLink(range).toString());
	}
	_list = std::move(parsed);
}
Example #13
0
void FileMetaDataToolTip::setName(const QString& name)
{
    QTextOption textOption;
    textOption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);

    const QString processedName = Qt::mightBeRichText(name) ? name : KStringHandler::preProcessWrap(name);

    QTextLayout textLayout(processedName);
    textLayout.setFont(m_name->font());
    textLayout.setTextOption(textOption);

    QString wrappedText;
    wrappedText.reserve(processedName.length());

    // wrap the text to fit into the maximum width of m_name
    textLayout.beginLayout();
    QTextLine line = textLayout.createLine();
    while (line.isValid()) {
        line.setLineWidth(m_name->maximumWidth());
        wrappedText += processedName.midRef(line.textStart(), line.textLength());

        line = textLayout.createLine();
        if (line.isValid()) {
            wrappedText += QChar::LineSeparator;
        }
    }
    textLayout.endLayout();

    m_name->setText(wrappedText);
}
Example #14
0
/*!
    \internal
    Parses configuration from \a stream.
*/
void QLoggingSettingsParser::setContent(QTextStream &stream)
{
    _rules.clear();
    while (!stream.atEnd()) {
        QString line = stream.readLine();

        // Remove all whitespace from line
        line = line.simplified();
        line.remove(QLatin1Char(' '));

        // comment
        if (line.startsWith(QLatin1Char(';')))
            continue;

        if (line.startsWith(QLatin1Char('[')) && line.endsWith(QLatin1Char(']'))) {
            // new section
            _section = line.mid(1, line.size() - 2);
            continue;
        }

        if (_section == QLatin1String("Rules")) {
            int equalPos = line.indexOf(QLatin1Char('='));
            if ((equalPos != -1)
                    && (line.lastIndexOf(QLatin1Char('=')) == equalPos)) {
                const QString pattern = line.left(equalPos);
                const QStringRef value = line.midRef(equalPos + 1);
                bool enabled = (value.compare(QLatin1String("true"),
                                              Qt::CaseInsensitive) == 0);
                _rules.append(QLoggingRule(pattern, enabled));
            }
        }
    }
}
bool LanguageChooser::languageMatch(const QString& lang, const QString& qmFile)
{
    //qmFile: i18n_xx.qm
    const QString prefix = "i18n_";
    const int langTokenLength = 2; /*FIXME: is checking two chars enough?*/
    return qmFile.midRef(qmFile.indexOf(prefix) + prefix.length(), langTokenLength) == lang.leftRef(langTokenLength);
}
Example #16
0
Akonadi::Item::Flags Maildir::readEntryFlags(const QString &key) const
{
    Akonadi::Item::Flags flags;

    const QRegularExpression rx = statusSeparatorRx();
    const int index = key.indexOf(rx);
    if (index != -1) {
        const QStringRef mailDirFlags = key.midRef(index + 3);   // after "(:|!)2,"
        const int flagSize(mailDirFlags.size());
        for (int i = 0; i < flagSize; ++i) {
            const QChar flag = mailDirFlags.at(i);
            if (flag == QLatin1Char('P')) {
                flags << Akonadi::MessageFlags::Forwarded;
            } else if (flag == QLatin1Char('R')) {
                flags << Akonadi::MessageFlags::Replied;
            } else if (flag == QLatin1Char('S')) {
                flags << Akonadi::MessageFlags::Seen;
            } else if (flag == QLatin1Char('F')) {
                flags << Akonadi::MessageFlags::Flagged;
            }
        }
    }

    return flags;
}
Example #17
0
double OsmAnd::Utilities::parseLength(const QString& value, double defValue, bool* wasParsed/* = nullptr*/)
{
    int first, last;
    if (wasParsed)
        *wasParsed = false;
    if (!extractFirstNumberPosition(value, first, last, false, true))
        return defValue;
    bool ok;
    auto result = value.midRef(first, last - first + 1).toDouble(&ok);
    if (!ok)
        return defValue;

    if (wasParsed)
        *wasParsed = true;
    if (value.contains(QLatin1String("ft")) || value.contains('"'))
        result *= 0.3048;
    if (value.contains('\''))
    {
        auto inchesSubstr = value.mid(value.indexOf('"') + 1);
        if (!extractFirstNumberPosition(inchesSubstr, first, last, false, true))
        {
            if (wasParsed)
                *wasParsed = false;

            return defValue;
        }
        bool ok;
        auto inches = inchesSubstr.midRef(first, last - first + 1).toDouble(&ok);
        if (ok)
            result += inches * 0.0254;
    }
    return result;
}
Example #18
0
double OsmAnd::Utilities::parseSpeed(const QString& value, double defValue, bool* wasParsed/* = nullptr*/)
{
    if (value == QLatin1String("none"))
    {
        if (wasParsed)
            *wasParsed = true;
        return 40;
    }

    int first, last;
    if (!extractFirstNumberPosition(value, first, last, false, true))
    {
        if (wasParsed)
            *wasParsed = false;
        return defValue;
    }
    bool ok;
    auto result = value.midRef(first, last - first + 1).toDouble(&ok);
    if (wasParsed)
        *wasParsed = ok;
    if (!ok)
        return defValue;

    result /= 3.6;
    if (value.contains(QLatin1String("mph")))
        result *= 1.6;
    return result;
}
QStringList QMacSettingsPrivate::children(const QString &prefix, ChildSpec spec) const
{
    QStringList result;
    int startPos = prefix.size();

    for (int i = 0; i < numDomains; ++i) {
        for (int j = 0; j < numHostNames; ++j) {
            QCFType<CFArrayRef> cfarray = CFPreferencesCopyKeyList(domains[i].applicationOrSuiteId,
                                                                   domains[i].userName,
                                                                   hostNames[j]);
            if (cfarray) {
                CFIndex size = CFArrayGetCount(cfarray);
                for (CFIndex k = 0; k < size; ++k) {
                    QString currentKey =
                            qtKey(static_cast<CFStringRef>(CFArrayGetValueAtIndex(cfarray, k)));
                    if (currentKey.startsWith(prefix))
                        processChild(currentKey.midRef(startPos), spec, result);
                }
            }
        }

        if (!fallbacks)
            break;
    }
    std::sort(result.begin(), result.end());
    result.erase(std::unique(result.begin(), result.end()),
                 result.end());
    return result;
}
Example #20
0
QString ChatEdit::textEditToPlainText()
{
	QTextDocument *doc = document();
	QString result;
	result.reserve(doc->characterCount());
	QTextCursor begin(doc);
	QTextCursor end;
	QString specialChar = QChar(QChar::ObjectReplacementCharacter);
	bool first = true;
	while (!begin.atEnd()) {
		end = doc->find(specialChar, begin, QTextDocument::FindCaseSensitively);
		QString postValue;
		bool atEnd = end.isNull();
		if (atEnd) {
			end = QTextCursor(doc);
			QTextBlock block = doc->lastBlock();
			end.setPosition(block.position() + block.length() - 1);
		} else {
			postValue = end.charFormat().toolTip();
		}
		begin.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor,
						   end.position() - begin.position() - (atEnd ? 0 : 1));
		QString selectionText = begin.selection().toPlainText();
		if (!first)
			result += selectionText.midRef(1);
		else
			result += selectionText;
		result += postValue;
		begin = end;
		end.clearSelection();
		first = false;
	}
	return result;
}
Example #21
0
// Try to find end position of first or middle element
// @input:
// - str - string with data
// - startPos - start position of the current element in the string
// - separator - string or character that separate elements
// - textDelimiter - string that is used as text delimiter
// @output:
// - int - end position of the element or -1 if this element is not first
// or middle
int ReaderPrivate::FindMiddleElementPositioin(const QString& str,
                                              const int& startPos,
                                              const QString& separator,
                                              const QString& txtDelim)
{
    const int ERROR = -1;
    if (str.isEmpty() ||
            startPos < 0 ||
            separator.isEmpty() ||
            txtDelim.isEmpty())
    {
        return ERROR;
    }

    const QString elemEndSymbols = txtDelim + separator;
    int elemEndPos = startPos;
    while(elemEndPos < str.size())
    {
        // Find position of element end symbol
        elemEndPos = str.indexOf(elemEndSymbols, elemEndPos);
        if (elemEndPos < 0)
        {
            // This element could not be the middle element, becaise string
            // do not contains any end symbols
            return ERROR;
        }

        // Check that this is really the end symbols of the
        // element and we don't mix up it with double delimiter
        // and separator. Calc number of delimiter symbols from elemEndPos
        // to startPos that stands together.
        int numOfDelimiters = 0;
        for (int pos = elemEndPos; startPos <= pos; --pos, ++numOfDelimiters)
        {
            QStringRef strRef = str.midRef(pos, txtDelim.size());
            if (QStringRef::compare(strRef, txtDelim) != 0)
            {
                break;
            }
        }

        // If we have odd number of delimiter symbols that stand together,
        // then this is the even number of double delimiter symbols + last
        // delimiter symbol. That means that we have found end position of
        // the middle element.
        if (numOfDelimiters % 2 == 1)
        {
            return elemEndPos;
        }
        else
        {
            // Otherwise this is not the end of the middle element and we
            // should try again
            elemEndPos += elemEndSymbols.size();
        }
    }

    return ERROR;
}
Example #22
0
QString newlineToBr(const QString &input)
{
	QString out;
	int pos=0;
	int last=0;
	while((pos=input.indexOf('\n', last))>=0) {
		out.append(input.midRef(last, pos-last));
		out.append("<br>");
		last=pos+1;
	}

	if(last==0)
		return input;

	out.append(input.midRef(last));
	return out;
}
Example #23
0
QString convertToHTML(const QString &inputParam)
{
  // this code goes over the input string once and replaces all bbtags
  // it encounters. This function is called recursively for every replaced
  // string to convert nested tags.
  //
  // This could be implemented simpler by applying a set of regular expressions
  // for each recognized bb-tag one after the other but that would probably be
  // very inefficient (O(n^2)).

  QString input = inputParam.mid(0).replace("\r\n", "<br/>");
  input.replace("\\\"", "\"").replace("\\'", "'");
  QString result;
  int lastBlock = 0;
  int pos = 0;

  // iterate over the input buffer
  while ((pos = input.indexOf('[', lastBlock)) != -1) {
    // append everything between the previous tag-block and the current one
    result.append(input.midRef(lastBlock, pos - lastBlock));

    if ((pos < (input.size() - 1)) && (input.at(pos + 1) == '/')) {
       // skip invalid end tag
      int tagEnd = input.indexOf(']',  pos) + 1;
      pos = tagEnd;
    } else {
      // convert the tag and content if necessary
      int length = -1;
      QString replacement = BBCodeMap::instance().convertTag(input.mid(pos), length);
      if (length != 0) {
        result.append(convertToHTML(replacement));
        // length contains the number of characters in the original tag
        pos += length;
      } else {
        // nothing replaced
        result.append('[');
        ++pos;
      }
    }
    lastBlock = pos;
  }

  // append the remainder (everything after the last tag)
  result.append(input.midRef(lastBlock));
  return result;
}
Example #24
0
QString stripParameterUrl(const QString &url, const QString &scheme)
{
    QStringRef ref = url.midRef(scheme.length() + 1);
    if (ref.startsWith(QLatin1String("//")))
        ref = ref.mid(2);
    if (ref.endsWith(QLatin1Char('/')))
        ref = ref.left(ref.length() - 1);
    return ref.toString();
}
bool ImageLoader::validateExtension(QString filename) const {
    /**
      * Assumption OS does not allow an empty filename (excluding exten-
      * sion) to be used for files, thus is it pointless to provide only
      * the extension to the file.
      */

    QStringRef ref = filename.midRef(filename.length()-3,3);

    if(ref.compare(".sr",Qt::CaseInsensitive) == 0){
        return true;
    }

    //if filename is smaller than 5 it can not be valid anymore
    if(filename.length() < 5) return false;

    ref.clear();
    ref = filename.midRef(filename.length()-4,4);
    if(ref.compare(".bmp",Qt::CaseInsensitive) == 0
        || ref.compare(".dib",Qt::CaseInsensitive) == 0
        || ref.compare(".jpg",Qt::CaseInsensitive) == 0
        || ref.compare(".jpe",Qt::CaseInsensitive) == 0
        || ref.compare(".png",Qt::CaseInsensitive) == 0
        || ref.compare(".pbm",Qt::CaseInsensitive) == 0
        || ref.compare(".pgm",Qt::CaseInsensitive) == 0
        || ref.compare(".ppm",Qt::CaseInsensitive) == 0
        || ref.compare(".ras",Qt::CaseInsensitive) == 0
        || ref.compare(".tif",Qt::CaseInsensitive) == 0 ){
        return true;
    }

    //if filename is smaller than 6 it can not be valid anymore
    if(filename.length() < 6) return false;

    ref.clear();
    ref = filename.midRef(filename.length()-5,5);
    if(ref.compare(".jpeg",Qt::CaseInsensitive) == 0
        || ref.compare(".tiff",Qt::CaseInsensitive) == 0 ){
        return true;
    }

    //none of the cases matched.
    return false;
}
Example #26
0
void ScColor::setNamedColor(QString name)
{
	bool ok;
	if (name.length () == 9)
	{
		int c = name.midRef(1,2).toInt(&ok, 16);
		int m = name.midRef(3,2).toInt(&ok, 16);
		int y = name.midRef(5,2).toInt(&ok, 16);
		int k = name.midRef(7,2).toInt(&ok, 16);
		setColor(c, m, y, k);
	}
	else if (name.length () == 7)
	{
		int r = name.midRef(1,2).toInt(&ok, 16);
		int g = name.midRef(3,2).toInt(&ok, 16);
		int b = name.midRef(5,2).toInt(&ok, 16);
		setColorRGB(r, g, b);
	}
}
Example #27
0
QSize resSize(const QString &str)
{
    int index = str.indexOf('x');
    if (index != -1) {
        return QSize(str.leftRef(index).toInt(),
                     str.midRef(index + 1).toInt());
    }

    return QSize();
}
Example #28
0
    static QVector3D vector3DFromString(const QString &s, bool *ok)
    {
        if (s.count(QLatin1Char(',')) == 2) {
            int index = s.indexOf(QLatin1Char(','));
            int index2 = s.indexOf(QLatin1Char(','), index+1);

            bool xGood, yGood, zGood;
            float xCoord = s.leftRef(index).toFloat(&xGood);
            float yCoord = s.midRef(index + 1, index2 - index - 1).toFloat(&yGood);
            float zCoord = s.midRef(index2 + 1).toFloat(&zGood);

            if (xGood && yGood && zGood) {
                if (ok) *ok = true;
                return QVector3D(xCoord, yCoord, zCoord);
            }
        }

        if (ok) *ok = false;
        return QVector3D();
    }
	QPair<QString, QString> RDFGraphBasic::splitToPrefixSuffix(QString const &iri)
	{
		Prefixes::iterator pi = reverse_prefixes.upperBound(iri);
		if(pi != reverse_prefixes.begin())
		{
			--pi;
			if(iri.midRef(0, pi.key().size()) == pi.key())
				return qMakePair(pi.value(), iri.mid(pi.key().size()));
		}
		return qMakePair(QString(), iri);
	}
Example #30
0
void FileInfo::splitIntoDirectoryAndFileName(const QString &filePath, QStringRef *dirPath, QStringRef *fileName)
{
    int idx = filePath.lastIndexOf(QLatin1Char('/'));
    if (idx < 0) {
        dirPath->clear();
        *fileName = QStringRef(&filePath);
        return;
    }
    *dirPath = filePath.leftRef(idx);
    *fileName = filePath.midRef(idx + 1);
}