Exemple #1
0
Parser::Arg Parser::verbatimStuff(string const & end_string, bool const allow_linebreak)
{
	if (!good())
		return Arg(false, string());

	pushPosition();
	ostringstream oss;
	size_t match_index = 0;
	setCatcodes(VERBATIM_CATCODES);
	for (Token t = get_token(); good(); t = get_token()) {
		// FIXME t.asInput() might be longer than we need ?
		if (t.asInput() == end_string.substr(match_index,
						     t.asInput().length())) {
			match_index += t.asInput().length();
			if (match_index >= end_string.length())
				break;
		} else {
			if (!allow_linebreak && t.asInput() == "\n") {
				cerr << "unexpected end of input" << endl;
				popPosition();
				setCatcodes(NORMAL_CATCODES);
				return Arg(false, string());
			}
			if (match_index) {
				oss << end_string.substr(0, match_index)
				    << t.asInput();
				match_index = 0;
			} else
				oss << t.asInput();
		}
	}

	if (!good()) {
		cerr << "unexpected end of input" << endl;
		popPosition();
		setCatcodes(NORMAL_CATCODES);
		return Arg(false, string());
	}
	setCatcodes(NORMAL_CATCODES);
	dropPosition();
	return Arg(true, oss.str());
}
void KNMusicTreeViewBase::dragMoveEvent(QDragMoveEvent *event)
{
    //Ignore the event by default.
    event->ignore();
    //Check the model.
    if(musicModel()==nullptr || m_notAcceptDragMove)
    {
        //Ignore the drag event when the music model is null.
        return;
    }
    //Check mime type.
    const QMimeData *dragMimeData=event->mimeData();
    //Check whether this data is from another music model.
    if(dragMimeData->hasFormat(ModelMimeType))
    {
        //Accept this format drag and drop.
        event->accept();
    }
    else
    {
        //Check whether we have urls from file viewers, like Explorer(Windows)
        //or Finder(Mac OS X).
        if(dragMimeData->hasUrls())
        {
            //Accept it first.
            event->accept();
            //Set it to the end of the whole model.
            //Set the drag move row to the last row.
            m_dragMoveRow=proxyModel()->rowCount()-1;
            //Update the drag indicator position to below item.
            m_dragIndicatorPos=QAbstractItemView::BelowItem;
            //Update the widget.
            viewport()->update();
            //Mission complete.
            return;
        }
    }
    //Check the event state.
    if(!event->isAccepted())
    {
        //Ignore the cannot accepted event.
        return;
    }
    //Get the current Y position index.
    QModelIndex dropIndex=indexAt(QPoint(0, event->pos().y()));
    //Check whether the index is valid or not.
    if(dropIndex.isValid())
    {
        //Save the new drag move index.
        m_dragMoveRow=dropIndex.row();
        //Update the drag indicator position.
        m_dragIndicatorPos=dropPosition(event->pos(), visualRect(dropIndex));
    }
    else
    {
        //Set it to the end of the whole model.
        //Set the drag move row to the last row.
        m_dragMoveRow=proxyModel()->rowCount()-1;
        //Update the drag indicator position to below item.
        m_dragIndicatorPos=QAbstractItemView::BelowItem;
    }
    //Update the widget.
    viewport()->update();
}