Beispiel #1
0
void ChatScene::updateSceneRect(qreal width) {
  if(_lines.isEmpty()) {
    updateSceneRect(QRectF(0, 0, width, 0));
    return;
  }

  // we hide day change messages at the top by making the scene rect smaller
  // and by calling QGraphicsItem::hide() on all leading day change messages
  // the first one is needed to ensure proper scrollbar ranges
  // the second for cases where the viewport is larger then the set scenerect
  //  (in this case the items are shown anyways)
  if(_firstLineRow == -1) {
    int numRows = model()->rowCount();
    _firstLineRow = 0;
    QModelIndex firstLineIdx;
    while(_firstLineRow < numRows) {
      firstLineIdx = model()->index(_firstLineRow, 0);
      if((Message::Type)(model()->data(firstLineIdx, MessageModel::TypeRole).toInt()) != Message::DayChange)
        break;
      _lines.at(_firstLineRow)->hide();
      _firstLineRow++;
    }
  }

  // the following call should be safe. If it crashes something went wrong during insert/remove
  if(_firstLineRow < _lines.count()) {
    ChatLine *firstLine = _lines.at(_firstLineRow);
    ChatLine *lastLine = _lines.last();
    updateSceneRect(QRectF(0, firstLine->pos().y(), width, lastLine->pos().y() + lastLine->height() - firstLine->pos().y()));
  } else {
    // empty scene rect
    updateSceneRect(QRectF(0, 0, width, 0));
  }
}
void UIGChooserView::resizeEvent(QResizeEvent*)
{
    /* Update scene-rect: */
    updateSceneRect();
    /* Notify listeners: */
    emit sigResized();
}
Beispiel #3
0
void ChatScene::secondHandlePositionChanged(qreal xpos) {
  if(_secondColHandlePos == xpos)
    return;

  _secondColHandlePos = xpos;
  ChatViewSettings viewSettings(this);
  viewSettings.setValue("SecondColumnHandlePos", _secondColHandlePos);
  ChatViewSettings defaultSettings;
  defaultSettings.setValue("SecondColumnHandlePos", _secondColHandlePos);

  // clock_t startT = clock();

  // disabling the index while doing this complex updates is about
  // 2 to 10 times faster!
  //setItemIndexMethod(QGraphicsScene::NoIndex);

  QList<ChatLine *>::iterator lineIter = _lines.end();
  QList<ChatLine *>::iterator lineIterBegin = _lines.begin();
  qreal linePos = _sceneRect.y() + _sceneRect.height();
  qreal senderWidth = secondColumnHandle()->sceneLeft() - firstColumnHandle()->sceneRight();
  qreal contentsWidth = _sceneRect.width() - secondColumnHandle()->sceneRight();
  QPointF contentsPos(secondColumnHandle()->sceneRight(), 0);
  while(lineIter != lineIterBegin) {
    lineIter--;
    (*lineIter)->setSecondColumn(senderWidth, contentsWidth, contentsPos, linePos);
  }
  //setItemIndexMethod(QGraphicsScene::BspTreeIndex);

  updateSceneRect();
  setHandleXLimits();
  emit layoutChanged();

//   clock_t endT = clock();
//   qDebug() << "resized" << _lines.count() << "in" << (float)(endT - startT) / CLOCKS_PER_SEC << "sec";
}
bool QgsComposerNodesItem::removeNode( const int index )
{
  bool rc = _removeNode( index );
  if ( rc )
    updateSceneRect();
  return rc;
}
Beispiel #5
0
void ScopeviewForm::setupUI()
{
    _showFormAct = UIUtil::createWidgetWithName<QAction>("ScopeView Pannel");
    connect(_showFormAct, SIGNAL(triggered()), this, SLOT(onShowForm()));

    _graphView = new QGraphicsView();
    QGraphicsScene* scene = new QGraphicsScene(_graphView);
    scene->setItemIndexMethod(QGraphicsScene::NoIndex);
    scene->setSceneRect(this->rect());
    _graphView->setScene(scene);
    _graphView->setCacheMode(QGraphicsView::CacheBackground);
    _graphView->setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
    _graphView->setBackgroundBrush(QBrush(QColor(195,195,195)));

    QVBoxLayout* vv = new QVBoxLayout();
    vv->addWidget(_graphView);
    vv->setContentsMargins(0,0,0,0);

    this->setLayout(vv);
   /* for (int i = 0; i < 8; ++i)
    {
        QGroupBox* gbox = createGroupBox(i + 1);
        _groupboxs.append(gbox);

        this->scene()->addWidget(gbox);
    }*/

    updateSceneRect();
    updateSceneItemPos();
}
Beispiel #6
0
void ChatLog::scrollToLine(ChatLine::Ptr line)
{
    if (!line.get())
        return;

    updateSceneRect();
    verticalScrollBar()->setValue(line->sceneBoundingRect().top());
}
void QGraphicsSceneIndexPrivate::init()
{
    if (!scene)
        return;

    QObject::connect(scene, SIGNAL(sceneRectChanged(QRectF)),
                     q_func(), SLOT(updateSceneRect(QRectF)));
}
Beispiel #8
0
void GameView::resizeEvent(QResizeEvent *event)
{
	QGraphicsView::resizeEvent(event);

	GameScene *s = dynamic_cast<GameScene *>(scene());
	if (s) {
		s->processViewSizeChange(event->size());
	}
	updateSceneRect(scene()->sceneRect());
}
void UIGChooserView::sltMinimumHeightHintChanged(int iMinimumHeightHint)
{
    /* Is there something changed? */
    if (m_iMinimumHeightHint == iMinimumHeightHint)
        return;

    /* Remember new value: */
    m_iMinimumHeightHint = iMinimumHeightHint;

    /* Update scene-rect: */
    updateSceneRect();
}
Beispiel #10
0
void ChatLog::clear()
{
    clearSelection();

    for (ChatLine::Ptr l : lines)
        l->removeFromScene();

    lines.clear();
    visibleLines.clear();

    updateSceneRect();
}
Beispiel #11
0
void QgsLayoutItemPolyline::refreshSymbol()
{
  if ( layout() )
  {
    QgsRenderContext rc = QgsLayoutUtils::createRenderContextForLayout( layout(), nullptr, layout()->renderContext().dpi() );
    mMaxSymbolBleed = ( 25.4 / layout()->renderContext().dpi() ) * QgsSymbolLayerUtils::estimateMaxSymbolBleed( mPolylineStyleSymbol.get(), rc );
  }

  updateSceneRect();

  emit frameChanged();
}
void UIToolsView::sltMinimumHeightHintChanged(int iHint)
{
    /* Is there something changed? */
    if (m_iMinimumHeightHint == iHint)
        return;

    /* Remember new value: */
    m_iMinimumHeightHint = iHint;

    /* Set minimum view height according passed height-hint: */
    setMinimumHeight(2 * frameWidth() + m_iMinimumHeightHint);

    /* Update scene-rect: */
    updateSceneRect();
}
void UIGChooserView::sltMinimumWidthHintChanged(int iMinimumWidthHint)
{
    /* Is there something changed? */
    if (m_iMinimumWidthHint == iMinimumWidthHint)
        return;

    /* Remember new value: */
    m_iMinimumWidthHint = iMinimumWidthHint;

    /* Set minimum view width according passed width-hint: */
    setMinimumWidth(2 * frameWidth() + iMinimumWidthHint + verticalScrollBar()->sizeHint().width());

    /* Update scene-rect: */
    updateSceneRect();
}
Beispiel #14
0
bool QgsComposerNodesItem::moveNode( const int index, const QPointF &pt )
{
  bool rc( false );

  if ( index >= 0 && index < mPolygon.size() )
  {
    QPointF nodeItem = mapFromScene( pt );
    mPolygon.replace( index, nodeItem );
    updateSceneRect();

    rc = true;
  }

  return rc;
}
Beispiel #15
0
void TmultiScore::resizeEvent(QResizeEvent* event) {
  int hh = height(), ww = width();
  if (event) {
    hh = event->size().height();
    ww = event->size().width();
  }
  if (m_inMode == e_single) {
    if (ww < 300 || hh < 200)
      return;
    TsimpleScore::resizeEvent(event);
  } else {
    if (ww < 400 || hh < 200)
      return;

    qreal factor = getScaleFactor(hh, m_scale);
    scoreScene()->prepareToChangeRect();
    scale(factor, factor);
    qreal oldStaffWidth = staff()->viewWidth();
    for (int i = 0; i < m_staves.size(); i++)
      adjustStaffWidth(m_staves[i]);

    if (oldStaffWidth != staff()->viewWidth()) {
    // TODO: another routine for non-rhythms
      for (int i = 0; i < m_staves.size(); i++) {
        qreal staffContentWidth = m_staves[i]->contentWidth(m_staves[i]->gapFactor());
        if (staffContentWidth != m_staves[i]->width()) {
          qDebug() << debug() << "staff width changed about" << qAbs(staffContentWidth - m_staves[i]->width()) << "- fitting";
          m_staves[i]->fit();
          m_staves[i]->updateNotesPos();
        }
      }
      for (int i = 0; i < m_staves.size(); i++) {
        if (m_staves[i]->count() == 0)
          deleteLastStaff();
      }
    }

    qreal staffOff = staff()->isPianoStaff() ? 1.1 : 0.0;
    for (int i = 0; i < m_staves.size(); i++) {
      if (i == 0)
        m_staves[i]->setPos(staffOff, 0.0);
      else
        m_staves[i]->setPos(staffOff, m_staves[i - 1]->pos().y() + m_staves[i - 1]->loNotePos() - m_staves[i]->hiNotePos() +
                            ((staff()->hasScordature() && i == 1) ? 7.0 : 4.0));
    }
    updateSceneRect();
  }
}
UIGChooserView::UIGChooserView(QWidget *pParent)
    : QGraphicsView(pParent)
    , m_iMinimumWidthHint(0)
    , m_iMinimumHeightHint(0)
{
    /* Setup frame: */
    setFrameShape(QFrame::NoFrame);
    setFrameShadow(QFrame::Plain);
    setAlignment(Qt::AlignLeft | Qt::AlignTop);

    /* Setup scroll-bars policy: */
    setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);

    /* Update scene-rect: */
    updateSceneRect();
}
Beispiel #17
0
void TmultiScore::deleteNotes() {
  if (!staff()->count())
      return; // nothing to delete
  m_currentIndex = 0;
  while (staffCount() > 1)
    deleteLastStaff();
  if (staff()->count() > 1) {
    QList<TscoreNote*> notesToDel;
    staff()->takeNotes(notesToDel, 1, staff()->count() - 1);
    for (int i = 0; i <notesToDel.size(); i++)
      delete notesToDel[i];
  }
  removeCurrentNote();
  updateSceneRect();
  m_currentIndex = -1;
}
Beispiel #18
0
void ScopeviewForm::loadData()
{
    //暂时
    _graphView->scene()->clear();
    _groupboxs.clear();

    for (int i = 0; i < 8; ++i)
    {
        QGroupBox* gbox = createGroupBox(i + 1);
        _groupboxs.append(gbox);

        _graphView->scene()->addWidget(gbox);
    }

    updateSceneRect();
    updateSceneItemPos();
}
GraphicStoryView::GraphicStoryView(GraphicStoryScene * _currentScene,QGraphicsView * parent)
	:QGraphicsView(parent)
{
	this->setMouseTracking(true);
	this->setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
	this->setAcceptDrops(true);
	this->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
	this->current_scene=_currentScene;
	connect(this->current_scene,SIGNAL(sceneRectChanged(QRectF)),this,SLOT(updateSceneRect(QRectF)));
	//connect(this->current_scene,SIGNAL(itemInserted(StoryItem*)),this,SLOT(add_story(StoryItem*)));
	this->setScene(this->current_scene);
	//this->setSceneRect(-150,-150,1200,1200);
	connect(this,SIGNAL(story_split_added(QString,StoryBase*)),this->current_scene,SLOT(add_split_story(QString, StoryBase*)));
	connect(this,SIGNAL(story_root_added(QString,StoryBase*)),this->current_scene,SLOT(add_root_story(QString,StoryBase*)));
	//connect(this,SIGNAL(event_added(Event*,int)),this->current_scene,SLOT(add_event(Event*,int)));
	connect(this,SIGNAL(obsPoint_added(ObservationPoint*, int)),this->current_scene,SLOT(add_Obs_point(ObservationPoint*,int)));
	this->setRenderHints(QPainter::Antialiasing);
	this->init=true;

}
Beispiel #20
0
void ChatLog::insertChatlineAtBottom(ChatLine::Ptr l)
{
    if (!l.get())
        return;

    bool stickToBtm = stickToBottom();

    //insert
    l->setRow(lines.size());
    l->addToScene(scene);
    lines.append(l);

    //partial refresh
    layout(lines.last()->getRow(), lines.size(), useableWidth());
    updateSceneRect();

    if (stickToBtm)
        scrollToBottom();

    checkVisibility();
    updateTypingNotification();
}
void UIToolsView::prepare()
{
    /* Install Tools-view accessibility interface factory: */
    QAccessible::installFactory(UIAccessibilityInterfaceForUIToolsView::pFactory);

    /* Prepare palette: */
    preparePalette();

    /* Setup frame: */
    setFrameShape(QFrame::NoFrame);
    setFrameShadow(QFrame::Plain);
    setAlignment(Qt::AlignLeft | Qt::AlignTop);

    /* Setup scroll-bars policy: */
    setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);

    /* Update scene-rect: */
    updateSceneRect();

    /* Apply language settings: */
    retranslateUi();
}
Beispiel #22
0
void ChatScene::layout(int start, int end, qreal width) {
  // clock_t startT = clock();

  // disabling the index while doing this complex updates is about
  // 2 to 10 times faster!
  //setItemIndexMethod(QGraphicsScene::NoIndex);

  if(end >= 0) {
    int row = end;
    qreal linePos = _lines.at(row)->scenePos().y() + _lines.at(row)->height();
    qreal contentsWidth = width - secondColumnHandle()->sceneRight();
    while(row >= start) {
      _lines.at(row--)->setGeometryByWidth(width, contentsWidth, linePos);
    }

    if(row >= 0) {
      // remaining items don't need geometry changes, but maybe repositioning?
      ChatLine *line = _lines.at(row);
      qreal offset = linePos - (line->scenePos().y() + line->height());
      if(offset != 0) {
        while(row >= 0) {
          line = _lines.at(row--);
          line->setPos(0, line->scenePos().y() + offset);
        }
      }
    }
  }

  //setItemIndexMethod(QGraphicsScene::BspTreeIndex);

  updateSceneRect(width);
  setHandleXLimits();
  emit layoutChanged();

//   clock_t endT = clock();
//   qDebug() << "resized" << _lines.count() << "in" << (float)(endT - startT) / CLOCKS_PER_SEC << "sec";
}
Beispiel #23
0
void ChatLog::onWorkerTimeout()
{
    // Fairly arbitrary but
    // large values will make the UI unresponsive
    const int stepSize = 50;

    layout(workerLastIndex, workerLastIndex+stepSize, useableWidth());
    workerLastIndex += stepSize;

    // done?
    if (workerLastIndex >= lines.size())
    {
        workerTimer->stop();

        // switch back to the scene containing the chat messages
        setScene(scene);

        // make sure everything gets updated
        updateSceneRect();
        checkVisibility();
        updateTypingNotification();
        updateMultiSelectionRect();

        // scroll
        if (workerStb)
            scrollToBottom();
        else
            scrollToLine(workerAnchorLine);

        // don't keep a Ptr to the anchor line
        workerAnchorLine = ChatLine::Ptr();

        // hidden during busy screen
        verticalScrollBar()->show();
    }
}
Beispiel #24
0
bool QgsComposerNodesItem::addNode( const QPointF &pt,
                                    const bool checkArea,
                                    const double radius )
{
  const QPointF start = mapFromScene( pt );
  double minDistance = std::numeric_limits<double>::max();
  double maxDistance = ( checkArea ) ? radius : minDistance;
  bool rc = false;
  int idx = -1;

  for ( int i = 0; i != mPolygon.size(); i++ )
  {
    // get nodes of polyline
    const QPointF pt1 = mPolygon.at( i );
    QPointF pt2 = mPolygon.first();
    if (( i + 1 ) != mPolygon.size() )
      pt2 = mPolygon.at( i + 1 );

    // compute line eq
    const double coef = ( pt2.y() - pt1.y() ) / ( pt2.x() - pt1.x() );
    const double b = pt1.y() - coef * pt1.x();

    double distance = std::numeric_limits<double>::max();
    if ( qIsInf( coef ) )
      distance = qAbs( pt1.x() - start.x() );
    else
    {
      const double coef2 = ( -1 / coef );
      const double b2 = start.y() - coef2 * start.x();

      QPointF inter;
      if ( qIsInf( coef2 ) )
      {
        distance = qAbs( pt1.y() - start.y() );
        inter.setX( start.x() );
        inter.setY( pt1.y() );
      }
      else
      {
        const double interx = ( b - b2 ) / ( coef2 - coef );
        const double intery = interx * coef2 + b2;
        inter.setX( interx );
        inter.setY( intery );
      }

      // check if intersection is within the line
      const double length1 = computeDistance( inter, pt1 );
      const double length2 = computeDistance( inter, pt2 );
      const double length3 = computeDistance( pt1, pt2 );
      const double length4 = length1 + length2;

      if ( qAbs( length3 - length4 ) < std::numeric_limits<float>::epsilon() )
        distance = computeDistance( inter, start );
    }

    if ( distance < minDistance && distance < maxDistance )
    {
      minDistance = distance;
      idx = i;
    }
  }

  if ( idx >= 0 )
  {
    rc = _addNode( idx, start, maxDistance );
    updateSceneRect();
  }

  return rc;
}
Beispiel #25
0
void ChatScene::rowsInserted(const QModelIndex &index, int start, int end) {
  Q_UNUSED(index);


//   QModelIndex sidx = model()->index(start, 2);
//   QModelIndex eidx = model()->index(end, 2);
//   qDebug() << "rowsInserted:";
//   if(start > 0) {
//     QModelIndex ssidx = model()->index(start - 1, 2);
//     qDebug() << "Start--:" << start - 1 << ssidx.data(MessageModel::MsgIdRole).value<MsgId>()
// 	     << ssidx.data(Qt::DisplayRole).toString();
//   }
//   qDebug() << "Start:" << start << sidx.data(MessageModel::MsgIdRole).value<MsgId>()
// 	   << sidx.data(Qt::DisplayRole).toString();
//   qDebug() << "End:" << end << eidx.data(MessageModel::MsgIdRole).value<MsgId>()
// 	   << eidx.data(Qt::DisplayRole).toString();
//   if(end + 1 < model()->rowCount()) {
//     QModelIndex eeidx = model()->index(end + 1, 2);
//     qDebug() << "End++:" << end + 1 << eeidx.data(MessageModel::MsgIdRole).value<MsgId>()
// 	     << eeidx.data(Qt::DisplayRole).toString();
//   }

  qreal h = 0;
  qreal y = 0;
  qreal width = _sceneRect.width();
  bool atBottom = (start == _lines.count());
  bool atTop = !atBottom && (start == 0);
  bool moveTop = false;

  if(start < _lines.count()) {
    y = _lines.value(start)->y();
  } else if(atBottom && !_lines.isEmpty()) {
    y = _lines.last()->y() + _lines.last()->height();
  }

  qreal contentsWidth = width - secondColumnHandle()->sceneRight();
  qreal senderWidth = secondColumnHandle()->sceneLeft() - firstColumnHandle()->sceneRight();
  qreal timestampWidth = firstColumnHandle()->sceneLeft();
  QPointF contentsPos(secondColumnHandle()->sceneRight(), 0);
  QPointF senderPos(firstColumnHandle()->sceneRight(), 0);

  if(atTop) {
    for(int i = end; i >= start; i--) {
      ChatLine *line = new ChatLine(i, model(),
                                    width,
                                    timestampWidth, senderWidth, contentsWidth,
                                    senderPos, contentsPos);
      h += line->height();
      line->setPos(0, y-h);
      _lines.insert(start, line);
      addItem(line);
    }
  } else {
    for(int i = start; i <= end; i++) {
      ChatLine *line = new ChatLine(i, model(),
                                    width,
                                    timestampWidth, senderWidth, contentsWidth,
                                    senderPos, contentsPos);
      line->setPos(0, y+h);
      h += line->height();
      _lines.insert(i, line);
      addItem(line);
    }
  }

  // update existing items
  for(int i = end+1; i < _lines.count(); i++) {
    _lines[i]->setRow(i);
  }

  // update selection
  if(_selectionStart >= 0) {
    int offset = end - start + 1;
    int oldStart = _selectionStart;
    if(_selectionStart >= start)
      _selectionStart += offset;
    if(_selectionEnd >= start) {
      _selectionEnd += offset;
      if(_selectionStart == oldStart)
        for(int i = start; i < start + offset; i++)
          _lines[i]->setSelected(true);
    }
    if(_firstSelectionRow >= start)
      _firstSelectionRow += offset;
  }

  // neither pre- or append means we have to do dirty work: move items...
  int moveStart = 0;
  int moveEnd = _lines.count() - 1;
  qreal offset = h;
  if(!(atTop || atBottom)) {
    // move top means: moving 0 to end (aka: end + 1)
    // move top means: moving end + 1 to _lines.count() - 1 (aka: _lines.count() - (end + 1)
    if(end + 1 < _lines.count() - end - 1) {
      // move top part
      moveTop = true;
      offset = -offset;
      moveEnd = end;
    } else {
      // move bottom part
      moveStart = end + 1;
    }
    ChatLine *line = 0;
    for(int i = moveStart; i <= moveEnd; i++) {
      line = _lines.at(i);
      line->setPos(0, line->pos().y() + offset);
    }
  }

  // check if all went right
  Q_ASSERT(start == 0 || _lines.at(start - 1)->pos().y() + _lines.at(start - 1)->height() == _lines.at(start)->pos().y());
//   if(start != 0) {
//     if(_lines.at(start - 1)->pos().y() + _lines.at(start - 1)->height() != _lines.at(start)->pos().y()) {
//       qDebug() << "lines:" << _lines.count() << "start:" << start << "end:" << end;
//       qDebug() << "line[start - 1]:" << _lines.at(start - 1)->pos().y() << "+" << _lines.at(start - 1)->height() << "=" << _lines.at(start - 1)->pos().y() + _lines.at(start - 1)->height();
//       qDebug() << "line[start]" << _lines.at(start)->pos().y();
//       qDebug() << "needed moving:" << !(atTop || atBottom) << moveTop << moveStart << moveEnd << offset;
//       Q_ASSERT(false)
//     }
//   }
  Q_ASSERT(end + 1 == _lines.count() || _lines.at(end)->pos().y() + _lines.at(end)->height() == _lines.at(end + 1)->pos().y());
//   if(end + 1 < _lines.count()) {
//     if(_lines.at(end)->pos().y() + _lines.at(end)->height() != _lines.at(end + 1)->pos().y()) {
//       qDebug() << "lines:" << _lines.count() << "start:" << start << "end:" << end;
//       qDebug() << "line[end]:" << _lines.at(end)->pos().y() << "+" << _lines.at(end)->height() << "=" << _lines.at(end)->pos().y() + _lines.at(end)->height();
//       qDebug() << "line[end+1]" << _lines.at(end + 1)->pos().y();
//       qDebug() << "needed moving:" << !(atTop || atBottom) << moveTop << moveStart << moveEnd << offset;
//       Q_ASSERT(false);
//     }
//   }

  if(!atBottom) {
    if(start < _firstLineRow) {
      int prevFirstLineRow = _firstLineRow + (end - start + 1);
      for(int i = end + 1; i < prevFirstLineRow; i++) {
        _lines.at(i)->show();
      }
    }
    // force new search for first proper line
    _firstLineRow = -1;
  }
  updateSceneRect();
  if(atBottom || (!atTop && !moveTop)) {
    emit lastLineChanged(_lines.last(), h);
  }
}
Beispiel #26
0
void ChatScene::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) {
  Q_UNUSED(parent);

  qreal h = 0; // total height of removed items;

  bool atTop = (start == 0);
  bool atBottom = (end == _lines.count() - 1);
  bool moveTop = false;

  // clear selection
  if(_selectingItem) {
    int row = _selectingItem->row();
    if(row >= start && row <= end)
      setSelectingItem(0);
  }

  // remove items from scene
  QList<ChatLine *>::iterator lineIter = _lines.begin() + start;
  int lineCount = start;
  while(lineIter != _lines.end() && lineCount <= end) {
    h += (*lineIter)->height();
    delete *lineIter;
    lineIter = _lines.erase(lineIter);
    lineCount++;
  }

  // update rows of remaining chatlines
  for(int i = start; i < _lines.count(); i++) {
    _lines.at(i)->setRow(i);
  }

  // update selection
  if(_selectionStart >= 0) {
    int offset = end - start + 1;
    if(_selectionStart >= start)
      _selectionStart = qMax(_selectionStart -= offset, start);
    if(_selectionEnd >= start)
      _selectionEnd -= offset;
    if(_firstSelectionRow >= start)
      _firstSelectionRow -= offset;

    if(_selectionEnd < _selectionStart) {
      _isSelecting = false;
      _selectionStart = -1;
    }
  }

  // neither removing at bottom or top means we have to move items...
  if(!(atTop || atBottom)) {
    qreal offset = h;
    int moveStart = 0;
    int moveEnd = _lines.count() - 1;
    if(start < _lines.count() - start) {
      // move top part
      moveTop = true;
      moveEnd = start - 1;
    } else {
      // move bottom part
      moveStart = start;
      offset = -offset;
    }
    ChatLine *line = 0;
    for(int i = moveStart; i <= moveEnd; i++) {
      line = _lines.at(i);
      line->setPos(0, line->pos().y() + offset);
    }
  }

  Q_ASSERT(start == 0 || start >= _lines.count() || _lines.at(start - 1)->pos().y() + _lines.at(start - 1)->height() == _lines.at(start)->pos().y());

  // update sceneRect
  // when searching for the first non-date-line we have to take into account that our
  // model still contains the just removed lines so we cannot simply call updateSceneRect()
  int numRows = model()->rowCount();
  QModelIndex firstLineIdx;
  _firstLineRow = -1;
  bool needOffset = false;
  do {
    _firstLineRow++;
    if(_firstLineRow >= start && _firstLineRow <= end) {
      _firstLineRow = end + 1;
      needOffset = true;
    }
    firstLineIdx = model()->index(_firstLineRow, 0);
  } while((Message::Type)(model()->data(firstLineIdx, MessageModel::TypeRole).toInt()) == Message::DayChange && _firstLineRow < numRows);

  if(needOffset)
    _firstLineRow -= end - start + 1;
  updateSceneRect();
}
Beispiel #27
0
void ChatLog::scrollToBottom()
{
    updateSceneRect();
    verticalScrollBar()->setValue(verticalScrollBar()->maximum());
}
Beispiel #28
0
void ScopeviewForm::resizeEvent(QResizeEvent* evt)
{
    updateSceneRect();
    updateSceneItemPos();
    QWidget::resizeEvent(evt);
}