예제 #1
0
bool MatrixModel::insertColumns(int column, int count,
                                const QModelIndex &parent) {
  if (!canResize(d_rows, d_cols + count))
    return false;

  beginInsertColumns(parent, column, column + count - 1);

  int offset = column + count;
  int oldCell = d_rows * d_cols - 1;
  d_cols += count;
  int cell = d_rows * d_cols - 1;
  for (int i = d_rows - 1; i >= 0; i--) {
    for (int j = d_cols - 1; j >= offset; j--)
      d_data[cell--] = d_data[oldCell--];

    for (int j = offset - 1; j >= column; j--)
      d_data[cell--] = GSL_NAN;

    for (int j = column - 1; j >= 0; j--)
      d_data[cell--] = d_data[oldCell--];
  }

  endInsertColumns();
  return true;
}
예제 #2
0
void MatrixModel::setImage(const QImage &image) {
  if (!canResize(image.height(), image.width()))
    return;

  d_rows = image.height();
  d_cols = image.width();
  int cell = 0;
  for (int i = 0; i < d_rows; i++) {
    for (int j = 0; j < d_cols; j++)
      d_data[cell++] = qGray(image.pixel(j, i));
  }
}
예제 #3
0
void RenderWidget::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
{
    ANNOTATE_GRAPHICS_CONTEXT(paintInfo, this);

    if (!shouldPaint(paintInfo, paintOffset))
        return;

    LayoutPoint adjustedPaintOffset = paintOffset + location();

    if (hasBoxDecorationBackground() && (paintInfo.phase == PaintPhaseForeground || paintInfo.phase == PaintPhaseSelection))
        paintBoxDecorationBackground(paintInfo, adjustedPaintOffset);

    if (paintInfo.phase == PaintPhaseMask) {
        paintMask(paintInfo, adjustedPaintOffset);
        return;
    }

    if ((paintInfo.phase == PaintPhaseOutline || paintInfo.phase == PaintPhaseSelfOutline) && style()->hasOutline())
        paintOutline(paintInfo, LayoutRect(adjustedPaintOffset, size()));

    if (paintInfo.phase != PaintPhaseForeground)
        return;

    if (style()->hasBorderRadius()) {
        LayoutRect borderRect = LayoutRect(adjustedPaintOffset, size());

        if (borderRect.isEmpty())
            return;

        // Push a clip if we have a border radius, since we want to round the foreground content that gets painted.
        paintInfo.context->save();
        RoundedRect roundedInnerRect = style()->getRoundedInnerBorderFor(borderRect,
            paddingTop() + borderTop(), paddingBottom() + borderBottom(), paddingLeft() + borderLeft(), paddingRight() + borderRight(), true, true);
        BoxPainter::clipRoundedInnerRect(paintInfo.context, borderRect, roundedInnerRect);
    }

    Widget* widget = this->widget();
    if (widget)
        paintContents(paintInfo, paintOffset);

    if (style()->hasBorderRadius())
        paintInfo.context->restore();

    // Paint a partially transparent wash over selected widgets.
    if (isSelected() && !document().printing()) {
        LayoutRect rect = localSelectionRect();
        rect.moveBy(adjustedPaintOffset);
        paintInfo.context->fillRect(pixelSnappedIntRect(rect), selectionBackgroundColor());
    }

    if (canResize())
        layer()->scrollableArea()->paintResizer(paintInfo.context, roundedIntPoint(adjustedPaintOffset), paintInfo.rect);
}
예제 #4
0
BOOL LLResizeBar::handleMouseDown(S32 x, S32 y, MASK mask)
{
	if (!canResize()) return FALSE;

	// Route future Mouse messages here preemptively.  (Release on mouse up.)
	// No handler needed for focus lost since this clas has no state that depends on it.
	gFocusMgr.setMouseCapture( this );

	localPointToScreen(x, y, &mDragLastScreenX, &mDragLastScreenY);
	mLastMouseScreenX = mDragLastScreenX;
	mLastMouseScreenY = mDragLastScreenY;

	return TRUE;
}
예제 #5
0
파일: item.cpp 프로젝트: ktechlab/ktechlab
void Item::restoreFromItemData( const ItemData &itemData )
{
	move( itemData.x, itemData.y );
	if ( canResize() )
		setSize( itemData.size );
	
	Item *parentItem = p_itemDocument->itemWithID( itemData.parentId );
	if (parentItem)
		setParentItem(parentItem);
	else
		m_baseZ = itemData.z;
	
	//BEGIN Restore data
	const QStringMap::const_iterator stringEnd = itemData.dataString.end();
	for ( QStringMap::const_iterator it = itemData.dataString.begin(); it != stringEnd; ++it )
	{
		if ( hasProperty(it.key()) )
			property( it.key() )->setValue( it.value() );
	}
	
	const DoubleMap::const_iterator numberEnd = itemData.dataNumber.end();
	for ( DoubleMap::const_iterator it = itemData.dataNumber.begin(); it != numberEnd; ++it )
	{
		if ( hasProperty(it.key()) )
			property( it.key() )->setValue( it.value() );
	}
	
	const QColorMap::const_iterator colorEnd = itemData.dataColor.end();
	for ( QColorMap::const_iterator it = itemData.dataColor.begin(); it != colorEnd; ++it )
	{
		if ( hasProperty(it.key()) )
			property( it.key() )->setValue( it.value() );
	}
	
	const BoolMap::const_iterator boolEnd = itemData.dataBool.end();
	for ( BoolMap::const_iterator it = itemData.dataBool.begin(); it != boolEnd; ++it )
	{
		if ( hasProperty(it.key()) )
			property( it.key() )->setValue( QVariant( it.value() /*, 0*/ ) );
	}
	
	const QBitArrayMap::const_iterator rawEnd = itemData.dataRaw.end();
	for ( QBitArrayMap::const_iterator it = itemData.dataRaw.begin(); it != rawEnd; ++it )
	{
		if ( hasProperty(it.key()) )
			property( it.key() )->setValue( it.value() );
	}
	//END Restore Data
}
BOOL LLScrollColumnHeader::handleDoubleClick(S32 x, S32 y, MASK mask)
{
	if (canResize() && mResizeBar->getRect().pointInRect(x, y))
	{
		// reshape column to max content width
		LLRect column_rect = getRect();
		column_rect.mRight = column_rect.mLeft + mColumn->mMaxContentWidth;
		setShape(column_rect, true);
	}
	else
	{
		onClick(LLSD());
	}
	return TRUE;
}
예제 #7
0
bool RenderFrameSet::nodeAtPoint(const HitTestRequest& request, HitTestResult& result,
    int x, int y, int tx, int ty, HitTestAction action)
{
    if (action != HitTestForeground)
        return false;

    bool inside = RenderContainer::nodeAtPoint(request, result, x, y, tx, ty, action)
        || m_isResizing || canResize(IntPoint(x, y));

    if (inside && frameSet()->noResize()
            && !request.readonly && !result.innerNode()) {
        result.setInnerNode(node());
        result.setInnerNonSharedNode(node());
    }

    return inside || m_isChildResizing;
}
예제 #8
0
MatrixModel::MatrixModel(int rows, int cols, QObject *parent)
    : QAbstractTableModel(parent), d_matrix(dynamic_cast<Matrix *>(parent)) {
  init();

  if (d_matrix) {
    d_txt_format = d_matrix->textFormat().toAscii();
    d_num_precision = d_matrix->precision();
    d_locale = d_matrix->locale();
  }

  if (canResize(rows, cols)) {
    d_rows = rows;
    d_cols = cols;
    int cell = 0;
    int size = rows * cols;
    for (int i = 0; i < size; i++)
      d_data[cell++] = GSL_NAN;
  }
}
예제 #9
0
bool MatrixModel::insertRows(int row, int count, const QModelIndex &parent) {
  if (!canResize(d_rows + count, d_cols))
    return false;

  beginInsertRows(parent, row, row + count - 1);

  int oldSize = d_rows * d_cols;
  d_rows += count;

  int insertedCells = count * d_cols;
  int startCell = row * d_cols;
  for (int i = oldSize - 1; i >= startCell; i--)
    d_data[i + insertedCells] = d_data[i];
  for (int i = 0; i < insertedCells; i++)
    d_data[startCell++] = GSL_NAN;

  endInsertRows();
  return true;
}
예제 #10
0
bool MatrixModel::muParserCalculate(int startRow, int endRow, int startCol,
                                    int endCol) {
  ScriptingEnv *scriptEnv = d_matrix->scriptingEnv();
  muParserScript *mup = new muParserScript(
      scriptEnv, QString("<%1>").arg(d_matrix->objectName()), d_matrix);
  connect(mup, SIGNAL(error(const QString &, const QString &, int)), scriptEnv,
          SIGNAL(error(const QString &, const QString &, int)));
  connect(mup, SIGNAL(print(const QString &)), scriptEnv,
          SIGNAL(print(const QString &)));

  if (endRow < 0)
    endRow = d_rows - 1;
  if (endCol < 0)
    endCol = d_cols - 1;

  if (!canResize(endRow - startRow + 1, endCol - startCol + 1))
    return false;

  if (endCol >= d_cols)
    setColumnCount(endCol + 1);
  if (endRow >= d_rows)
    setRowCount(endRow + 1);

  double dx = d_matrix->dx();
  double dy = d_matrix->dy();
  double *ri = mup->defineVariable("i");
  double *rr = mup->defineVariable("row");
  double *cj = mup->defineVariable("j");
  double *cc = mup->defineVariable("col");
  double *x = mup->defineVariable("x");
  double *y = mup->defineVariable("y");

  if (!mup->compile(ScriptCode(d_matrix->formula()))) {
    QApplication::restoreOverrideCursor();
    return false;
  }

  QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));

  double x_start = d_matrix->xStart();
  double y_start = d_matrix->yStart();
  if (mup->codeLines() == 1) {
    for (int row = startRow; row <= endRow; row++) {
      double r = row + 1.0;
      *ri = r;
      *rr = r;
      *y = y_start + row *dy;
      int aux = row * d_cols + startCol;
      for (int col = startCol; col <= endCol; col++) {
        double c = col + 1.0;
        *cj = c;
        *cc = c;
        *x = x_start + col *dx;
        d_data[aux++] = mup->evalSingleLine();
      }
    }
  } else {
    QVariant res;
    for (int row = startRow; row <= endRow; row++) {
      double r = row + 1.0;
      *ri = r;
      *rr = r;
      *y = y_start + row *dy;
      int aux = row * d_cols + startCol;
      for (int col = startCol; col <= endCol; col++) {
        double c = col + 1.0;
        *cj = c;
        *cc = c;
        *x = x_start + col *dx;
        res = mup->evaluate(ScriptCode(d_matrix->formula()));
        if (res.canConvert(QVariant::Double))
          d_data[aux++] = res.toDouble();
        else
          d_data[aux++] = GSL_NAN;
        qApp->processEvents();
      }
    }
  }
  QApplication::restoreOverrideCursor();
  return true;
}
예제 #11
0
파일: item.cpp 프로젝트: ktechlab/ktechlab
ItemData Item::itemData() const
{
	ItemData itemData;
	
	itemData.type = m_type;
	itemData.x = x();
	itemData.y = y();
	
	if ( !parentItem() )
		itemData.z = m_baseZ;
	
	itemData.size = m_sizeRect;
	itemData.setSize = canResize();
	
	if (p_parentItem)
		itemData.parentId = p_parentItem->id();
	
	const VariantDataMap::const_iterator end = m_variantData.end();
	for ( VariantDataMap::const_iterator it = m_variantData.begin(); it != end; ++it )
	{
		switch( it.value()->type() )
		{
			case Variant::Type::String:
			case Variant::Type::FileName:
			case Variant::Type::Port:
			case Variant::Type::Pin:
			case Variant::Type::VarName:
			case Variant::Type::Combo:
			case Variant::Type::Select:
			case Variant::Type::Multiline:
			case Variant::Type::RichText:
			case Variant::Type::SevenSegment:
			case Variant::Type::KeyPad:
			{
				itemData.dataString[it.key()] = it.value()->value().toString();
				break;
			}
			case Variant::Type::Int:
			case Variant::Type::Double:
			{
				itemData.dataNumber[it.key()] = it.value()->value().toDouble();
				break;
			}
			case Variant::Type::Color:
			{
				itemData.dataColor[it.key()] = it.value()->value().value<QColor>();
				break;
			}
			case Variant::Type::Bool:
			{
				itemData.dataBool[it.key()] = it.value()->value().toBool();
				break;
			}
			case Variant::Type::Raw:
			{
				itemData.dataRaw[it.key()] = it.value()->value().toBitArray();
				break;
			}
			case Variant::Type::PenStyle:
			case Variant::Type::PenCapStyle:
			{
				// These types are only created from DrawPart, and that class
				// deals with these, so we can ignore them
				break;
			}
			case Variant::Type::None:
			{
				// ? Maybe obsoleted data...
				break;
			}
		}
	}
	
	return itemData;
}
예제 #12
0
BOOL LLResizeBar::handleHover(S32 x, S32 y, MASK mask)
{
	BOOL	handled = FALSE;

	// We only handle the click if the click both started and ended within us
	if( hasMouseCapture() )
	{
		S32 screen_x;
		S32 screen_y;
		localPointToScreen(x, y, &screen_x, &screen_y);
		
		S32 delta_x = screen_x - mDragLastScreenX;
		S32 delta_y = screen_y - mDragLastScreenY;
				
		LLCoordGL mouse_dir;
		// use hysteresis on mouse motion to preserve user intent when mouse stops moving
		mouse_dir.mX = (screen_x == mLastMouseScreenX) ? mLastMouseDir.mX : screen_x - mLastMouseScreenX;
		mouse_dir.mY = (screen_y == mLastMouseScreenY) ? mLastMouseDir.mY : screen_y - mLastMouseScreenY;
		mLastMouseDir = mouse_dir;
		mLastMouseScreenX = screen_x;
		mLastMouseScreenY = screen_y;

		// Make sure the mouse in still over the application.  We don't want to make the parent
		// so big that we can't see the resize handle any more.
		LLRect valid_rect = getRootView()->getRect();
		
		if( valid_rect.localPointInRect( screen_x, screen_y ) && mResizingView )
		{
			// undock floater when user resize it
			LLFloater* parent = dynamic_cast<LLFloater*>( getParent());
			if (parent && parent->isDocked())
			{
				parent->setDocked( false, false);
			}

			// Resize the parent
			LLRect orig_rect = mResizingView->getRect();
			LLRect scaled_rect = orig_rect;
				
			S32 new_width = orig_rect.getWidth();
			S32 new_height = orig_rect.getHeight();

			switch( mSide )
			{
			case LEFT:
				new_width = llclamp(orig_rect.getWidth() - delta_x, mMinSize, mMaxSize);
				delta_x = orig_rect.getWidth() - new_width;
				scaled_rect.translate(delta_x, 0);
				break;

			case TOP:
				new_height = llclamp(orig_rect.getHeight() + delta_y, mMinSize, mMaxSize);
				delta_y = new_height - orig_rect.getHeight();
				break;
			
			case RIGHT:
				new_width = llclamp(orig_rect.getWidth() + delta_x, mMinSize, mMaxSize);
				delta_x = new_width - orig_rect.getWidth();
				break;
		
			case BOTTOM:
				new_height = llclamp(orig_rect.getHeight() - delta_y, mMinSize, mMaxSize);
				delta_y = orig_rect.getHeight() - new_height;
				scaled_rect.translate(0, delta_y);
				break;
			}

			notifyParent(LLSD().with("action", "resize")
				.with("view_name", mResizingView->getName())
				.with("new_height", new_height)
				.with("new_width", new_width));

			scaled_rect.mTop = scaled_rect.mBottom + new_height;
			scaled_rect.mRight = scaled_rect.mLeft + new_width;
			mResizingView->setRect(scaled_rect);

			LLView* snap_view = NULL;

			if (mSnappingEnabled)
			{
				static LLUICachedControl<S32> snap_margin ("SnapMargin", 0);
				switch( mSide )
				{
				case LEFT:
					snap_view = mResizingView->findSnapEdge(scaled_rect.mLeft, mouse_dir, SNAP_LEFT, SNAP_PARENT_AND_SIBLINGS, snap_margin);
					break;
				case TOP:
					snap_view = mResizingView->findSnapEdge(scaled_rect.mTop, mouse_dir, SNAP_TOP, SNAP_PARENT_AND_SIBLINGS, snap_margin);
					break;
				case RIGHT:
					snap_view = mResizingView->findSnapEdge(scaled_rect.mRight, mouse_dir, SNAP_RIGHT, SNAP_PARENT_AND_SIBLINGS, snap_margin);
					break;
				case BOTTOM:
					snap_view = mResizingView->findSnapEdge(scaled_rect.mBottom, mouse_dir, SNAP_BOTTOM, SNAP_PARENT_AND_SIBLINGS, snap_margin);
					break;
				}
			}

			// register "snap" behavior with snapped view
			mResizingView->setSnappedTo(snap_view);

			// restore original rectangle so the appropriate changes are detected
			mResizingView->setRect(orig_rect);
			// change view shape as user operation
			mResizingView->setShape(scaled_rect, true);

			// update last valid mouse cursor position based on resized view's actual size
			LLRect new_rect = mResizingView->getRect();
			switch(mSide)
			{
			case LEFT:
				mDragLastScreenX += new_rect.mLeft - orig_rect.mLeft;
				break;
			case RIGHT:
				mDragLastScreenX += new_rect.mRight - orig_rect.mRight;
				break;
			case TOP:
				mDragLastScreenY += new_rect.mTop - orig_rect.mTop;
				break;
			case BOTTOM:
				mDragLastScreenY += new_rect.mBottom- orig_rect.mBottom;
				break;
			default:
				break;
			}
		}

		handled = TRUE;
	}
	else
	{
		handled = TRUE;
	}

	if( handled && canResize() )
	{
		switch( mSide )
		{
		case LEFT:
		case RIGHT:
			getWindow()->setCursor(UI_CURSOR_SIZEWE);
			break;

		case TOP:
		case BOTTOM:
			getWindow()->setCursor(UI_CURSOR_SIZENS);
			break;
		}
	}

	return handled;
} // end LLResizeBar::handleHover