Exemplo n.º 1
0
void ShowColRow::slotOk()
{
    Region region;
    for (unsigned int i = 0; i < (unsigned int)list->count(); i++) {
        if (list->item(i)->isSelected()) {
            if (typeShow == Column) {
                region.add(QRect(listInt.at(i), 1, 1, KS_rowMax));
            }
            if (typeShow == Row) {
                region.add(QRect(1, listInt.at(i), KS_colMax, 1));
            }
        }
    }

    HideShowManipulator* manipulator = new HideShowManipulator();
    manipulator->setSheet(m_selection->activeSheet());
    if (typeShow == Column) {
        manipulator->setManipulateColumns(true);
    }
    if (typeShow == Row) {
        manipulator->setManipulateRows(true);
    }
    manipulator->setReverse(true);
    manipulator->add(region);
    manipulator->execute(m_selection->canvas());

    accept();
}
bool HideShowManipulator::preProcessing()
{
    if (m_firstrun)
        setText(name());
    Region region;
    ConstIterator endOfList = cells().constEnd();
    for (ConstIterator it = cells().constBegin(); it != endOfList; ++it) {
        if (m_reverse) {
            QRect range = (*it)->rect();
            if (m_manipulateColumns) {
                if (range.left() > 1) {
                    int col;
                    for (col = 1; col < range.left(); ++col) {
                        if (!m_sheet->columnFormat(col)->isHidden())
                            break;
                    }
                    if (col == range.left()) {
                        region.add(QRect(1, 1, range.left() - 1, KS_rowMax));
                    }
                }
                for (int col = range.left(); col <= range.right(); ++col) {
                    if (m_sheet->columnFormat(col)->isHidden()) {
                        region.add(QRect(col, 1, 1, KS_rowMax));
                    }
                }
            }
            if (m_manipulateRows) {
                if (range.top() > 1) {
                    int row;
                    for (row = 1; row < range.top(); ++row) {
                        if (!m_sheet->rowFormats()->isHidden(row)) {
                            break;
                        }
                    }
                    if (row == range.top()) {
                        region.add(QRect(1, 1, KS_colMax, range.top() - 1));
                    }
                }
                for (int row = range.top(); row <= range.bottom(); ++row) {
                    if (!m_sheet->rowFormats()->isHidden(row)) {
                        region.add(QRect(1, row, KS_colMax, 1));
                    }
                }
            }
        }

        if (((*it)->isRow() && m_manipulateColumns) ||
                ((*it)->isColumn() && m_manipulateRows)) {
            /*      KMessageBox::error( this, i18n( "Area is too large." ) );*/
            return false;
        }
    }

    if (m_reverse) {
        clear();
        add(region);
    }

    return AbstractRegionCommand::preProcessing();
}
Exemplo n.º 3
0
void Selection::extend(const QPoint& point, Sheet* sheet)
{
    if (!isValid(point))
        return;

    if (isEmpty() || d->selectionMode == SingleCell) {
        initialize(point, sheet);
        return;
    }

    kDebug() ;

    if (!sheet) {
        if (d->originSheet) {
            sheet = d->originSheet;
        } else {
            sheet = d->activeSheet;
        }
    }

    Region changedRegion = Region(extendToMergedAreas(QRect(d->marker, d->marker)));

    // for the case of a merged cell
    QPoint topLeft(point);
    Cell cell(d->activeSheet, point);
    if (cell.isPartOfMerged()) {
        cell = cell.masterCell();
        topLeft = QPoint(cell.column(), cell.row());
    }

    if (d->multipleOccurences) {
        const int subRegionEnd = d->activeSubRegionStart + d->activeSubRegionLength;
        const bool prepend = d->activeSubRegionLength == 0;
        const bool atEnd = d->activeElement == subRegionEnd;
        // Insert the new location after the active element, if possible.
        const int index = d->activeElement + ((prepend || atEnd) ? 0 : 1);
        insert(index, topLeft, sheet, true);
        ++d->activeSubRegionLength;
        ++d->activeElement;
        d->anchor = topLeft;
        d->marker = topLeft;
    } else {
        // TODO Replace for normal selection and resizing of any range.
        // The new point may split an existing range. Anyway, the new
        // location/range is appended and the last element becomes active.
        const int count = cells().count();
        eor(topLeft, sheet);
        d->activeSubRegionLength += cells().count() - count;
        d->activeElement = cells().count() - 1;
        d->anchor = cells()[d->activeElement]->rect().topLeft();
        d->marker = cells()[d->activeElement]->rect().bottomRight();
    }
    d->cursor = d->marker;

    changedRegion.add(topLeft, sheet);
    changedRegion.add(*this);

    emitChanged(changedRegion);
}
Exemplo n.º 4
0
void UpdateFilter::filter(UpdateContainer *updateContainer)
{
  AutoLock al(m_fbMutex);

  FrameBuffer *screenFrameBuffer = m_screenDriver->getScreenBuffer();

  // Checking for buffers equal
  if (!screenFrameBuffer->isEqualTo(m_frameBuffer)) {
    return;
  }

  Region toCheck = updateContainer->changedRegion;
  toCheck.add(&updateContainer->copiedRegion);

  std::vector<Rect> rects;
  std::vector<Rect>::iterator iRect;

  // Reproduce CopyRect operations in m_frameBuffer.
  updateContainer->copiedRegion.getRectVector(&rects);
  Point *src = &updateContainer->copySrc;
  for (iRect = rects.begin(); iRect < rects.end(); iRect++) {
    m_frameBuffer->move(&(*iRect), src->x, src->y);
  }


  toCheck.getRectVector(&rects);
  // Grabbing
  m_log->debug(_T("grabbing region, %d rectangles"), (int)rects.size());
  try {
    m_grabOptimizator.grab(&toCheck, m_screenDriver);
  } catch (...) {
    return;
  }
  m_log->debug(_T("end of grabbing region"));

  // Filtering
  updateContainer->changedRegion.clear();
  Rect *rect;
  for (iRect = rects.begin(); iRect < rects.end(); iRect++) {
    rect = &(*iRect);
    getChangedRegion(&updateContainer->changedRegion, rect);
  }

  // Copy actually changed pixels into m_frameBuffer.
  updateContainer->changedRegion.getRectVector(&rects);
  for (iRect = rects.begin(); iRect < rects.end(); iRect++) {
    rect = &(*iRect);
    m_frameBuffer->copyFrom(rect, screenFrameBuffer, rect->left, rect->top);
  }
}
Exemplo n.º 5
0
bool LocalUpdateHandler::checkForUpdates(Region *region)
{
  UpdateContainer updateContainer;
  m_updateKeeper->getUpdateContainer(&updateContainer);

  Region resultRegion = updateContainer.changedRegion;
  resultRegion.add(&updateContainer.copiedRegion);
  resultRegion.intersect(region);

  bool result = updateContainer.cursorPosChanged ||
                updateContainer.cursorShapeChanged ||
                updateContainer.screenSizeChanged ||
                !resultRegion.isEmpty();

  return result;
}
Exemplo n.º 6
0
void Binding::update(const Region& region)
{
    QRect rect;
    Region changedRegion;
    const QPoint offset = d->model->region().firstRange().topLeft();
    const QRect range = d->model->region().firstRange();
    const Sheet* sheet = d->model->region().firstSheet();
    Region::ConstIterator end(region.constEnd());
    for (Region::ConstIterator it = region.constBegin(); it != end; ++it) {
        if (sheet != (*it)->sheet())
            continue;
        rect = range & (*it)->rect();
        rect.translate(-offset.x(), -offset.y());
        if (rect.isValid()) {
            d->model->emitDataChanged(rect);
            changedRegion.add(rect, (*it)->sheet());
        }
    }
    d->model->emitChanged(changedRegion);
}
Exemplo n.º 7
0
bool MergeCommand::preProcessing()
{
    if (isColumnOrRowSelected()) {
        KMessageBox::information(0, i18n("Merging of columns or rows is not supported."));
        return false;
    }

    if (m_firstrun) {
        setText(name());

        // reduce the region to the region occupied by merged cells
        Region mergedCells;
        ConstIterator endOfList = constEnd();
        for (ConstIterator it = constBegin(); it != endOfList; ++it) {
            Element* element = *it;
            QRect range = element->rect();
            int right = range.right();
            int bottom = range.bottom();
            for (int row = range.top(); row <= bottom; ++row) {
                for (int col = range.left(); col <= right; ++col) {
                    Cell cell = Cell(m_sheet, col, row);
                    if (cell.doesMergeCells()) {
                        QRect rect(col, row, cell.mergedXCells() + 1, cell.mergedYCells() + 1);
                        mergedCells.add(rect);
                    }
                }
            }
        }

        if (m_merge) { // MergeCommand
            // we're in the manipulator's first execution
            // initialize the undo manipulator
            m_unmerger = new MergeCommand();
            if (!m_mergeHorizontal && !m_mergeVertical) {
                m_unmerger->setReverse(true);
            }
            m_unmerger->setSheet(m_sheet);
            m_unmerger->setRegisterUndo(false);
            m_unmerger->add(mergedCells);
        } else { // DissociateManipulator
            clear();
            add(mergedCells);
        }
    }

    if (m_merge) { // MergeCommand
        if (m_reverse) { // dissociate
        } else { // merge
            // Dissociate cells before merging the whole region.
            // For horizontal/vertical merging the cells stay
            // as they are. E.g. the region contains a merged cell
            // occupying two rows. Then the horizontal merge should
            // keep the height of two rows and extend the merging to the
            // region's width. In this case the unmerging is done while
            // processing each region element.
            if (!m_mergeHorizontal && !m_mergeVertical) {
                m_unmerger->redo();
            }
        }
    }
    // Clear the associated selection, if any. The merge/dissociate process will restore
    // selections. This ensures that the selection isn't broken after merging.
    if (m_selection) m_selection->Region::clear();

    return AbstractRegionCommand::preProcessing();
}
Exemplo n.º 8
0
int main(int argc, char *argv[])
{
  Mat mat = Mat::zeros(Size(4,4), CV_8U);
  Mat btmleft(mat, Rect(0,0,2,2));
  Mat btmright(mat, Rect(2,0,2,2));
  Mat topleft(mat, Rect(0,2,2,2));
  Mat topright(mat, Rect(2,2,2,2));

  btmright.setTo(80);
  topleft.setTo(160);
  topright.setTo(255);

  printMatrix(mat);

  Region rbl(btmleft);
  Region rbr(btmright);
  Region rtl(topleft);
  Region rtr(topright);
  rbl.print();
  printMatrix(rbl.toMask(mat));
  rbr.print();
  printMatrix(rbr.toMask(mat));
  rtl.print();
  printMatrix(rtl.toMask(mat));
  rtr.print();
  printMatrix(rtr.toMask(mat));

  printf("\nBottom / top:\n\n");

  Region btm = rbl;
  btm.add(rbr);
  btm.print();
  printMatrix(btm.toMask(mat));
  Region top = rtl;
  top.add(rtr);
  top.print();
  printMatrix(top.toMask(mat));

  printf("\nWhole:\n\n");

  Region whole = top;
  whole.add(btm);
  whole.print();
  printMatrix(whole.toMask(mat));


  printf("\nBottom line:\n\n");

  Mat m00(btmleft, Rect(0,0,1,1));
  Mat m10(btmleft, Rect(1,0,1,1));
  Mat m20(btmright, Rect(0,0,1,1));
  Mat m30(btmright, Rect(1,0,1,1));

  Region btmline(m00);
  btmline.add(Region(m10));
  btmline.add(Region(m20));
  btmline.add(Region(m30));

  btmline.print();

  printMatrix(btmline.toMask(mat));

  printf("\nOutline:\n\n");

  Mat m31(mat, Rect(3,1,1,1));
  Mat m32(mat, Rect(3,2,1,1));
  Mat m33(mat, Rect(3,3,1,1));
  Mat m23(mat, Rect(2,3,1,1));
  Mat m13(mat, Rect(1,3,1,1));
  Mat m03(mat, Rect(0,3,1,1));
  Mat m02(mat, Rect(0,2,1,1));
  Mat m01(mat, Rect(0,1,1,1));


  Region outline = btmline;
  outline.add(Region(m31));
  outline.add(Region(m32));
  outline.add(Region(m33));
  outline.add(Region(m23));
  outline.add(Region(m13));
  outline.add(Region(m03));
  outline.add(Region(m02));
  outline.add(Region(m01));

  outline.print();
  printMatrix(outline.toMask(mat));
}
Exemplo n.º 9
0
void Selection::update(const QPoint& point)
{
    if (d->selectionMode == SingleCell) {
        initialize(point);
        d->activeElement = 1;
        d->activeSubRegionStart = 0;
        d->activeSubRegionLength = 1;
        return;
    }

    // A length of 0 means inserting at the position d->activeSubRegionStart.
    if (d->activeSubRegionLength == 0) {
        extend(point);
        return;
    }

    if (cells().isEmpty()) {
        initialize(point);
        d->activeElement = 1;
        d->activeSubRegionStart = 0;
        d->activeSubRegionLength = 1;
        return;
    }

    // Take the last range, if pointing beyond the sub-region's end.
    const int subRegionEnd = d->activeSubRegionStart + d->activeSubRegionLength;
    const bool atEnd = d->activeElement >= subRegionEnd;
    if (atEnd) {
        // d->activeSubRegionLength == 0 is already excluded.
        d->activeElement = subRegionEnd - 1;
    }

    Sheet* sheet = cells()[d->activeElement]->sheet();
    if (sheet != d->activeSheet) {
        extend(point);
        d->activeElement = cells().count();
        d->activeSubRegionStart = cells().count() - 1;
        d->activeSubRegionLength = 1;
        return;
    }

    // for the case of a merged cell
    QPoint topLeft(point);
    Cell cell(d->activeSheet, point);
    if (cell.isPartOfMerged()) {
        cell = cell.masterCell();
        topLeft = QPoint(cell.column(), cell.row());
    }

    if (topLeft == d->marker) {
        return;
    }

    QRect area1 = cells()[d->activeElement]->rect();
    QRect newRange = extendToMergedAreas(QRect(d->anchor, topLeft));

    // If the updated range is bigger, it may cover already existing ranges.
    // These get removed, if multiple occurrences are not allowed. Store the old
    // amount of ranges, to figure out how many ranges have been removed later.
    const int count = cells().count();
    // The update may have shrunk the range, which would be containend in
    // the former range. Remove the latter before inserting the new range.
    delete cells().takeAt(d->activeElement);
    insert(d->activeElement, newRange, sheet, d->multipleOccurences);
    const int delta = cells().count() - count;
    d->activeSubRegionLength += delta;
    if (atEnd) {
        d->activeElement = d->activeSubRegionStart + d->activeSubRegionLength;
    } else {
        d->activeElement += delta;
    }

    QRect area2 = newRange;
    Region changedRegion;

    bool newLeft   = area1.left() != area2.left();
    bool newTop    = area1.top() != area2.top();
    bool newRight  = area1.right() != area2.right();
    bool newBottom = area1.bottom() != area2.bottom();

    /* first, calculate some numbers that we'll use a few times */
    int farLeft = qMin(area1.left(), area2.left());
    int innerLeft = qMax(area1.left(), area2.left());

    int farTop = qMin(area1.top(), area2.top());
    int innerTop = qMax(area1.top(), area2.top());

    int farRight = qMax(area1.right(), area2.right());
    int innerRight = qMin(area1.right(), area2.right());

    int farBottom = qMax(area1.bottom(), area2.bottom());
    int innerBottom = qMin(area1.bottom(), area2.bottom());

    if (newLeft) {
        changedRegion.add(QRect(QPoint(farLeft, innerTop),
                                QPoint(innerLeft - 1, innerBottom)));
        if (newTop) {
            changedRegion.add(QRect(QPoint(farLeft, farTop),
                                    QPoint(innerLeft - 1, innerTop - 1)));
        }
        if (newBottom) {
            changedRegion.add(QRect(QPoint(farLeft, innerBottom + 1),
                                    QPoint(innerLeft - 1, farBottom)));
        }
    }

    if (newTop) {
        changedRegion.add(QRect(QPoint(innerLeft, farTop),
                                QPoint(innerRight, innerTop - 1)));
    }

    if (newRight) {
        changedRegion.add(QRect(QPoint(innerRight + 1, innerTop),
                                QPoint(farRight, innerBottom)));
        if (newTop) {
            changedRegion.add(QRect(QPoint(innerRight + 1, farTop),
                                    QPoint(farRight, innerTop - 1)));
        }
        if (newBottom) {
            changedRegion.add(QRect(QPoint(innerRight + 1, innerBottom + 1),
                                    QPoint(farRight, farBottom)));
        }
    }

    if (newBottom) {
        changedRegion.add(QRect(QPoint(innerLeft, innerBottom + 1),
                                QPoint(innerRight, farBottom)));
    }

    d->marker = topLeft;
    d->cursor = point;

    emitChanged(changedRegion);
}
Exemplo n.º 10
0
void Selection::emitChanged(const Region& region)
{
    Sheet * const sheet = d->activeSheet;
    if(!sheet) // no sheet no update needed
        return;
    Region extendedRegion;
    ConstIterator end(region.constEnd());
    for (ConstIterator it = region.constBegin(); it != end; ++it) {
        Element* element = *it;
        QRect area = element->rect();

        const ColumnFormat *col;
        //look at if column is hiding.
        //if it's hiding refreshing column+1 (or column -1 )
        int left = area.left();
        int right = area.right();
        int top = area.top();
        int bottom = area.bottom();

        // a merged cells is selected
        if (element->type() == Region::Element::Point) {
            Cell cell(sheet, left, top);
            if (cell.doesMergeCells()) {
                // extend to the merged region
                // prevents artefacts of the selection rectangle
                right += cell.mergedXCells();
                bottom += cell.mergedYCells();
            }
        }

        if (right < KS_colMax) {
            do {
                right++;
                col = sheet->columnFormat(right);
            } while (col->isHiddenOrFiltered() && right != KS_colMax);
        }
        if (left > 1) {
            do {
                left--;
                col = sheet->columnFormat(left);
            } while (col->isHiddenOrFiltered() && left != 1);
        }

        if (bottom < KS_rowMax) {
            do {
                bottom++;
                int lastHidden;
                if (sheet->rowFormats()->isHiddenOrFiltered(bottom, &lastHidden)) {
                    bottom = lastHidden;
                } else {
                    break;
                }
            } while (bottom != KS_rowMax);
        }

        if (top > 1) {
            do {
                top--;
                int firstHidden;
                if (sheet->rowFormats()->isHiddenOrFiltered(top, 0, &firstHidden)) {
                    top = firstHidden;
                } else {
                    break;
                }
            } while (top != 1);
        }

        area.setLeft(left);
        area.setRight(right);
        area.setTop(top);
        area.setBottom(bottom);

        extendedRegion.add(area, element->sheet());
    }

    const QList<Cell> masterCells = sheet->cellStorage()->masterCells(extendedRegion);
    for (int i = 0; i < masterCells.count(); ++i)
        extendedRegion.add(masterCells[i].cellPosition(), sheet);

    emit changed(extendedRegion);
}