示例#1
0
void QLineEdit::mouseMoveEvent( QMouseEvent *e )
{
    int margin = frame() ? 4 : 2;

    if ( e->pos().x() < margin || e->pos().x() > width() - margin ) {
	scrollingLeft = ( e->pos().x() < margin );
	if ( !dragScrolling ) {
	    dragScrolling = TRUE;
	    if ( scrollingLeft )
		newMark( offset, FALSE );
	    else
		newMark( lastCharVisible(), FALSE );
	    d->dragTimer.start( scrollTime );
	} else {
	    if ( scrollingLeft ) {
		int steps = -(e->pos().x() + margin) / 15 + 2;
		cursorLeft( TRUE, steps );
	    } else {
		int steps = (e->pos().x() - width() +  margin) / 15 + 2;
		cursorRight( TRUE, steps );
	    }
	}
    } else {
	dragScrolling = FALSE;
	int mousePos = offset + xPosToCursorPos( &tbuf[(int)offset],
						 fontMetrics(),
						 e->pos().x() - margin,
						 width() - margin - margin );
	int m1 = markDrag;
	newMark( mousePos, FALSE );
	repaintArea( m1, mousePos );
    }
}
示例#2
0
void QLineEdit::end( bool mark )
{
    int tlen = strlen( tbuf );
    if ( cursorPos != tlen || (!mark && hasMarkedText()) ) {
	int mo = showLastPartOffset( &tbuf[offset], fontMetrics(),
				     width() - (frame() ? 8 : 4) );
	int markStart = cursorPos;
	cursorPos = tlen;
	cursorOn = FALSE;
	blinkSlot();
	if ( mark ) {
	    markStart = QMIN( markStart, markDrag );
	    newMark( cursorPos );
	} else {
	    markStart = QMIN( markStart, minMark() );
	    markAnchor = markDrag = cursorPos;
	}
	d->pmDirty = TRUE;
	if ( mo > 0 ) {
	    offset += mo;
	    repaint( FALSE );
	} else {
	    repaintArea( markStart, tlen );
	}
    }
}
示例#3
0
void QLineEdit::mouseReleaseEvent( QMouseEvent * e )
{
    if ( d->inDoubleClick ) {
	d->inDoubleClick = FALSE;
	return;
    }

#if defined(_WS_X11_)
    if ( hasMarkedText() && echoMode() == Normal )
	copyText();
#else
    if ( style() == MotifStyle && hasMarkedText() && echoMode() == Normal )
	copyText();
#endif
    if ( dragScrolling )
	dragScrolling = FALSE;
    if ( e->button() != LeftButton )
	return;

    int margin = frame() ? 4 : 2;
    if ( !QRect( margin, margin,
		 width() - 2*margin,
		 height() - 2*margin ).contains( e->pos() ) )
	return;

    int mousePos = offset + xPosToCursorPos( &tbuf[(int)offset],
					     fontMetrics(),
					     e->pos().x() - margin,
					     width() - margin - margin );
    int m1 = markDrag;
    newMark( mousePos, FALSE );
    repaintArea( m1, mousePos );
}
示例#4
0
void QLineEdit::mousePressEvent( QMouseEvent *e )
{
    killTimers();
    d->inDoubleClick = FALSE;
    int margin = frame() ? 4 : 2;
    cursorPos = offset + xPosToCursorPos( &tbuf[(int)offset], fontMetrics(),
					  e->pos().x() - margin,
					  width() - 2*margin );
    if ( e->button() == MidButton ) {
#if defined(_WS_X11_)
	insert( QApplication::clipboard()->text() );
#else
	if ( style() == MotifStyle )
	    insert( QApplication::clipboard()->text() );
#endif
	return;
#if 0 // it works, but it's wait until we have an API
    } else if ( hasMarkedText() &&
		e->button() == LeftButton &&
		( (markAnchor > cursorPos && markDrag < cursorPos) ||
		  (markAnchor < cursorPos && markDrag > cursorPos) ) ) {
	QTextDrag * tdo = new QTextDrag( this );
	tdo->setText( markedText() );
	tdo->dragCopy();
	delete tdo;
	return;
#endif
    }

    int m1 = minMark();
    int m2 = maxMark();
    markAnchor = cursorPos;
    newMark( markAnchor, FALSE );
    if ( cursorPos > m2 )
	m2 = cursorPos;
    else if ( cursorPos < m1 )
	m1 = cursorPos;
    repaintArea( m1, m2 );
    dragScrolling = FALSE;
}
示例#5
0
void QLineEdit::cursorLeft( bool mark, int steps )
{
    if ( steps < 0 ) {
	cursorRight( mark, -steps );
	return;
    }
    if ( cursorPos > 0 || (!mark && hasMarkedText()) ) {
	cursorPos -= steps;
	if ( cursorPos < 0 )
	    cursorPos = 0;
	cursorOn = FALSE;
	blinkSlot();
	int minP = QMIN( minMark(), cursorPos );
	int maxP = QMAX( maxMark(), cursorPos );
	if ( mark )
	    newMark( cursorPos );
	else
	    markAnchor = markDrag = cursorPos;
	d->pmDirty = TRUE;
	repaintArea( minP, maxP );
    }
}
示例#6
0
void QLineEdit::home( bool mark )
{
    if ( cursorPos != 0 || (!mark && hasMarkedText()) ) {
	int m = cursorPos;
	cursorPos = 0;
	cursorOn = FALSE;
	blinkSlot();
	if ( mark ) {
	    m = QMAX( minMark(), m );
	    newMark( cursorPos );
	} else {
	    m = QMAX( maxMark(), m );
	    markDrag = markAnchor = 0;
	}
	d->pmDirty = TRUE;
	if ( offset ) {
	    offset = 0;
	    repaint( FALSE );
	} else {
	    repaintArea( 0, m );
	}
    }
}
示例#7
0
void QLineEdit::cursorRight( bool mark, int steps )
{
    if ( steps < 0 ) {
	cursorLeft( mark, -steps );
	return;
    }
    int len = (int)strlen( tbuf );
    if ( cursorPos < len || (!mark && hasMarkedText()) ) {
	int minP = QMIN( cursorPos, minMark() );
	cursorPos += steps;
	if ( cursorPos > len )
	    cursorPos = len;
	cursorOn = FALSE;
	blinkSlot();
	int maxP = QMAX( cursorPos, maxMark() );
	if ( mark )
	    newMark( cursorPos );
	else
	    markAnchor = markDrag = cursorPos;
	d->pmDirty = TRUE;
	repaintArea( minP, maxP );
    }
}
bool FilterDefaultResponseJSON::parseJson(const QByteArray& data)
{
  clearContainers();

  QJson::Parser parser;
  bool ok;
  QVariantMap result = parser.parse(data, &ok).toMap();

  if (!ok) return false;

  result["errno"].toInt(&ok);
  if (!ok) return false;
  m_errno = result["errno"].toInt(&ok);

  //QVariantMap channelVariant = result["channels"].toMap();
  QVariantList channelsList = result["channels"].toList();
  int size = channelsList.size();

  for (int i = 0; i < size; i++)
  {
    QVariantMap channelDesc = channelsList.at(i).toMap();
    QVariantMap channelInternal = channelDesc["channel"].toMap();
    QVariantList markList = channelInternal["items"].toList();
    QString channelName = channelInternal["name"].toString();

    QSharedPointer<Channel> channel(new JsonChannel(channelName,"dummy channel[LoadTagsResponse]"));

    for(int j=0; j<markList.size(); j++)
    {
      QVariantMap markMap = markList.at(j).toMap();

      int id = markMap["id"].toInt();
      QString title = markMap["title"].toString();
      QString link = markMap["link"].toString();
      QString description = markMap["description"].toString();
      double altitude = markMap["altitude"].toString().toDouble(&ok);
      if (!ok) return false;
      double latitude = markMap["latitude"].toString().toDouble(&ok);
      if (!ok) return false;
      double longitude = markMap["longitude"].toString().toDouble(&ok);
      if (!ok) return false;

      QString userName = markMap["user"].toString();
      QString timeStr =  markMap["pubDate"].toString();
      QDateTime time = QDateTime::fromString(timeStr, "dd MM yyyy HH:mm:ss.zzz");
      time.setTimeSpec(Qt::UTC);

      QVector<QSharedPointer<common::User> > v = m_usersContainer->vector();
      QSharedPointer<common::User> user(new JsonUser(userName));
      m_usersContainer->push_back(user);

      QSharedPointer<JsonDataMark> newMark(new JsonDataMark(altitude,
        latitude,
        longitude,
        title,
        description,
        link,
        time));
      newMark->setId(id);
      newMark->setUser(user);
      m_hashMap.insert(channel, newMark);
    }
  }
  return true;
}