/**
 * @brief 마우스 커서가 MainWindow의 탭영역(1,2,3)에 올라가있는지 확인한다.
 *
 *   +-------------------------------+-+-+-+
 *   |   TITLE BAR                   |_|O|X|
 *   +----------+----------+---------+-+-+-+
 *   |##1(Tab)##|##2(Tab)##|###3(Empty)####|
 *   +----------+----------+---------------+
 *   |                                     |
 *   |                   4                 |
 *   |                                     |
 *   +-------------------------------------+
 *
 *   TabBar::geometry()는 1,2영역을 나타내고, TabWidget::geometry()는 1,2,3,4영역을 나타낸다.
 *   이 두 geometry()를 연산해서 1,2,3 영역을 찾는다.
 *
 * @param mainWindow 대상 메인 윈도
 * @return bool
 *
 */
bool CWindowManager::isCursorOnTabWithEmptyArea(MainWindow *mainWindow)
{
    QRect barRect;
    QRect barRectG;
    QRect widgetRect;
    QRect widgetRectG;

    QTabBar* tabBar = 0;
    QTabWidget* tabWidget = 0;

    if(!mainWindow)
        return false;

    tabBar = mainWindow->getTabBar();
    tabWidget = mainWindow->getTabWidget();

    barRect = tabBar->geometry();
    widgetRect = tabWidget->geometry();

    barRectG.setTopLeft(tabBar->mapToGlobal(barRect.topLeft()));
    barRectG.setBottomRight(tabBar->mapToGlobal(barRect.bottomRight()));

    widgetRectG.setTopLeft(tabWidget->mapToGlobal(widgetRect.topLeft()));
    widgetRectG.setBottomRight(tabWidget->mapToGlobal(widgetRect.bottomRight()));

    widgetRectG.setTopLeft(QPoint(widgetRectG.topLeft().x(), barRectG.topLeft().y()));
    widgetRectG.setBottomRight(QPoint(widgetRectG.bottomRight().x(), barRectG.bottomRight().y()));

    return widgetRectG.contains(QCursor::pos());
}
Example #2
0
void rkBtnSw::paintEvent(QPaintEvent *)
{
	QPainter painter(this);
	painter.drawPixmap(QPoint(0,0), pixmapBackground); /* Background */
	QPoint ptFore;

	/* Set Font */
	QFont font = painter.font();
	font.setPointSize(12);
	painter.setFont(font);

	if (buttonOn) {
		ptFore = rect().topLeft();
	} else {
		ptFore = QPoint(this->width() - pixmapForeground.width(),this->rect().top());
	}
	QRect rcOn;
	rcOn.setTopLeft(rect().topLeft());
	rcOn.setBottomRight(QPoint(pixmapForeground.width(), pixmapForeground.height()));
	painter.drawText(rcOn, Qt::AlignCenter, "OFF"); /* Text "OFF" */

	QRect rcOff;
	rcOff.setTopLeft(QPoint(rect().width() - pixmapForeground.width(), rect().top()));
	rcOff.setBottomRight(rect().bottomRight());
	painter.drawText(rcOff, Qt::AlignCenter, "ON"); /* Text "ON" */

	painter.drawPixmap(ptFore, pixmapForeground); /* Foreground */
}
Example #3
0
void TimeLineCells::paintOnionSkin( QPainter& painter )
{
    Layer* layer = mEditor->layers()->currentLayer();
    if (layer == nullptr) {
        return;
    }

    int frameNumber = mEditor->currentFrame();

    int prevOnionSkinCount = mEditor->preference()->getInt(SETTING::ONION_PREV_FRAMES_NUM);
    int nextOnionSkinCount = mEditor->preference()->getInt(SETTING::ONION_NEXT_FRAMES_NUM);

    bool isAbsolute = (mEditor->preference()->getString(SETTING::ONION_TYPE) == "absolute");

    if (mEditor->preference()->isOn(SETTING::PREV_ONION) && prevOnionSkinCount > 0) {


        int onionFrameNumber = layer->getPreviousFrameNumber(frameNumber, isAbsolute);
        int onionPosition = 0;

        while (onionPosition < prevOnionSkinCount && onionFrameNumber > 0)
        {
            painter.setBrush( QColor( 128, 128, 128, 128 ) );
            painter.setPen( Qt::NoPen );
            QRect onionRect;
            onionRect.setTopLeft( QPoint( getFrameX( onionFrameNumber - 1 ), 0 ) );
            onionRect.setBottomRight( QPoint( getFrameX( onionFrameNumber ), height() ) );
            onionRect.setBottomRight( QPoint( getFrameX( onionFrameNumber ), 19 ) );
            painter.drawRect( onionRect );

            onionFrameNumber = layer->getPreviousFrameNumber(onionFrameNumber, isAbsolute);
            onionPosition++;
        }
    }

    if (mEditor->preference()->isOn(SETTING::NEXT_ONION) && nextOnionSkinCount > 0) {

        int onionFrameNumber = layer->getNextFrameNumber(frameNumber, isAbsolute);
        int onionPosition = 0;

        while (onionPosition < nextOnionSkinCount && onionFrameNumber > 0)
        {
            painter.setBrush( QColor( 128, 128, 128, 128 ) );
            painter.setPen( Qt::NoPen );
            QRect onionRect;
            onionRect.setTopLeft( QPoint( getFrameX( onionFrameNumber - 1 ), 0 ) );
            onionRect.setBottomRight( QPoint( getFrameX( onionFrameNumber ), height() ) );
            onionRect.setBottomRight( QPoint( getFrameX( onionFrameNumber ), 19 ) );
            painter.drawRect( onionRect );

            onionFrameNumber = layer->getNextFrameNumber(onionFrameNumber, isAbsolute);
            onionPosition++;
        }
    }
}
/*!
 * \param[in] aPos point to insert into the polygon
 * \param[in] aPoly polygon
 */
int
ImageHolder::posInPolygon(QPoint *aPos, QPolygon *aPoly) const
{
	if (!aPos || !aPoly || aPoly->count() < 2 || aPos->isNull()) {
		return -1;
		/* NOTREACHED */
	}

	int x = aPos->x();
	int y = aPos->y();

	int index = 0;
	int dist = 100000;
	int temp = 0;
	int count = aPoly->count();
	QRect rect;

	for (int i = 0; i < count - 1; i++) {
		temp = pointToLineDistance(
			QLine(aPoly->at(i), aPoly->at(i + 1)),
			*aPos
			);
		rect.setTopLeft(aPoly->at(i));
		rect.setBottomRight(aPoly->at(i + 1));
		rect = rect.normalized();
		if (temp < dist &&
			((x < rect.right() && rect.left() < x) ||
			(y < rect.bottom() && rect.top() < y)))
		{
			dist = temp;
			index = i + 1;
		}
	}

	/* first and last points */
	temp = pointToLineDistance(
		QLine(aPoly->at(0), aPoly->at(count - 1)),
		*aPos
		);

	rect.setTopLeft(aPoly->at(0));
	rect.setBottomRight(aPoly->at(count - 1));
	rect = rect.normalized();
	if (temp < dist &&
		((x < rect.right() && rect.left() < x) ||
		(y < rect.bottom() && rect.top() < y)))
	{
		index = 0;
	}

	return index;
}
void ImageCropDialog::accept(){
    QFileInfo info(filename_);
    QString croppedFileName = info.dir().filePath(info.baseName() + "_cropped.png");

    QRect cropRect;

    int x = -imgItem_->x() + cropItem_->x() - cropItem_->rect().width()/2;
    int y = -imgItem_->y() + cropItem_->y() - cropItem_->rect().height()/2;

    cropRect.setTopLeft(QPoint(x,y));
    cropRect.setSize(cropItem_->rect().size().toSize());

    QImage toSave(cropRect.size(), QImage::Format_ARGB32);

    toSave.fill(Qt::transparent);

    QPainter p(&toSave);

    QPainterPath path;
    path.addEllipse(QRectF(0, 0, cropRect.width(), cropRect.height()));
    p.setClipPath(path);
    p.setClipping(true);

    p.drawPixmap(0, 0, imgItem_->pixmap().copy(cropRect));

    if(toSave.save(croppedFileName))
        emit imageCropped(croppedFileName);

    QDialog::accept();
}
Example #6
0
static QRect drawText(QPainter *painter,
                     const QStyleOptionViewItem &styleOption,
                     const QModelIndex &modelIndex,
                     int iconOffset)
{
    QString displayString = modelIndex.data(Qt::DisplayRole).toString();
    if (displayString.isEmpty())
        displayString = modelIndex.data(NavigatorTreeModel::SimplifiedTypeNameRole).toString();
    QPoint displayStringOffset;
    int width = 0;

    if (modelIndex.data(NavigatorTreeModel::InvisibleRole).toBool())
        painter->setOpacity(0.5);

    // Check text length does not exceed available space
    int extraSpace = 12 + iconOffset;

    displayString = styleOption.fontMetrics.elidedText(displayString, Qt::ElideMiddle, styleOption.rect.width() - extraSpace);
    displayStringOffset = QPoint(5 + iconOffset, -5);
    width = styleOption.fontMetrics.width(displayString);

    QPoint textPosition = styleOption.rect.bottomLeft() + displayStringOffset;
    painter->drawText(textPosition, displayString);

    QRect textFrame;
    textFrame.setTopLeft(textPosition);
    textFrame.setWidth(width);

    return textFrame;
}
void UIGraphicsZoomButton::paint(QPainter *pPainter, const QStyleOptionGraphicsItem *pOption, QWidget*)
{
    /* Save painter: */
    pPainter->save();

    /* Prepare variables: */
    int iMargin = data(GraphicsButton_Margin).toInt();
    QRect paintRect = pOption->rect;
    paintRect.setTopLeft(paintRect.topLeft() + QPoint(iMargin, iMargin));
    paintRect.setBottomRight(paintRect.bottomRight() - QPoint(iMargin, iMargin));
    QIcon icon = data(GraphicsButton_Icon).value<QIcon>();
    QSize iconSize = data(GraphicsButton_IconSize).toSize();

    /* Make painter beauty: */
    pPainter->setRenderHint(QPainter::SmoothPixmapTransform);

    /* Draw pixmap: */
    pPainter->drawPixmap(/* Pixmap rectangle: */
                         paintRect,
                         /* Pixmap size: */
                         icon.pixmap(iconSize));

    /* Restore painter: */
    pPainter->restore();
}
bool FSTaskDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index)
{

    if (event->type() == QEvent::MouseButtonPress || QEvent::MouseButtonRelease)
    {

        QMouseEvent * mouseEvent  = static_cast<QMouseEvent*>(event);

        QRect buttonRect;
        buttonRect.setTopLeft(QPoint(option.rect.right() -20,  option.rect.center().y()-8));
        buttonRect.setWidth(16);
        buttonRect.setHeight(16);

        if (buttonRect.contains(mouseEvent->pos()) && event->type() == QEvent::MouseButtonPress )
            mClicked.append(index);

        if (buttonRect.contains(mouseEvent->pos()) && event->type() == QEvent::MouseButtonRelease )
            mClicked.removeAll(index);
        return QStyledItemDelegate::editorEvent(event,model,option,index);

    }

    return QStyledItemDelegate::editorEvent(event,model,option,index);

}
Example #9
0
bool QLinuxFbScreen::initialize()
{
    QRegularExpression ttyRx(QLatin1String("tty=(.*)"));
    QRegularExpression fbRx(QLatin1String("fb=(.*)"));
    QRegularExpression mmSizeRx(QLatin1String("mmsize=(\\d+)x(\\d+)"));
    QRegularExpression sizeRx(QLatin1String("size=(\\d+)x(\\d+)"));
    QRegularExpression offsetRx(QLatin1String("offset=(\\d+)x(\\d+)"));

    QString fbDevice, ttyDevice;
    QSize userMmSize;
    QRect userGeometry;
    bool doSwitchToGraphicsMode = true;

    // Parse arguments
    foreach (const QString &arg, mArgs) {
        QRegularExpressionMatch match;
        if (arg == QLatin1String("nographicsmodeswitch"))
            doSwitchToGraphicsMode = false;
        else if (arg.contains(mmSizeRx, &match))
            userMmSize = QSize(match.captured(1).toInt(), match.captured(2).toInt());
        else if (arg.contains(sizeRx, &match))
            userGeometry.setSize(QSize(match.captured(1).toInt(), match.captured(2).toInt()));
        else if (arg.contains(offsetRx, &match))
            userGeometry.setTopLeft(QPoint(match.captured(1).toInt(), match.captured(2).toInt()));
        else if (arg.contains(ttyRx, &match))
            ttyDevice = match.captured(1);
        else if (arg.contains(fbRx, &match))
            fbDevice = match.captured(1);
    }
void DisplayItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    painter->setRenderHints(QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform);
    painter->setPen(QColor::fromRgbF(1, 1, 1, 0.1));

    if (!index.data(DisplayControlModel::ItemIsLastRole).toBool())
        painter->drawLine(QPoint(60, option.rect.bottom()), QPoint(option.rect.right() - 30, option.rect.bottom()));

    const int icon_x = 15;
    const int icon_y = option.rect.top() + (option.rect.height() - 36) / 2;
    painter->drawPixmap(icon_x, icon_y, index.data(DisplayControlModel::ItemIconRole).value<QPixmap>());

    if (index.data(DisplayControlModel::ItemSelectedRole).toBool())
    {
        const int x = option.rect.right() - 24;
        const int y = option.rect.top() + (option.rect.height() - 16) / 2;

        painter->drawPixmap(x, y, loadPixmap(":/frame/themes/dark/icons/select.svg"));
    }

    const int name_x = 65;
    const int name_y = option.rect.top() + 20;
    painter->setPen(Qt::white);
    painter->drawText(name_x, name_y, index.data(DisplayControlModel::ItemTitleRole).toString());

    QRect descRect = option.rect;
    descRect.setTopLeft(QPoint(name_x, name_y + 5));
    descRect.setRight(option.rect.right() - 30);
    painter->setPen(QColor(255, 255, 255, .6 * 255));
    painter->drawText(descRect, Qt::AlignLeft | Qt::TextWordWrap, index.data(DisplayControlModel::ItemDescriptionRole).toString());
}
void ShockSectorLabel::update() {
	QRect boundary;
	boundary.setTopLeft(QPoint(10, 10));
	boundary.setBottomRight(QPoint(SIZE - 10, SIZE - 10));

	QPixmap pixmap(SIZE, SIZE);
	pixmap.fill(Qt::white);

	QPainter painter(&pixmap);

	// Arena
	painter.setPen(Qt::black);
	painter.drawEllipse(boundary);


	// Shock sector
	int a = angle - (range / 2);
	int alen = range;

	painter.setBrush(QBrush(Qt::yellow, Qt::FDiagPattern));
	painter.drawPie(boundary, a, alen);


	setPixmap(pixmap);
}
Example #12
0
void MapWidget::clipCellRect(QRect & r) const
{
    QPoint topLeft = r.topLeft();
    QPoint bottomRight = r.bottomRight();
    clipCellCoord(topLeft);
    clipCellCoord(bottomRight);
    r.setTopLeft(topLeft);
    r.setBottomRight(bottomRight);
}
Example #13
0
void OneToOneRoom::stackedWidgetCurrentChanged(int index)
{
	auto widget = stackedWidget->currentWidget();
	QRect rc;
	rc.setBottomRight(stackedWidget->geometry().bottomRight());
	rc.setTopLeft(QPoint(rc.bottom() - widget->height(), rc.right() - widget->width()));
	stackedWidget->setGeometry(rc);
	updateGeometry();
}
Example #14
0
QRect ControlRuler::mapItemToWidget(QRectF *rect)
{
    QRect newrect;

    newrect.setTopLeft(QPoint(mapXToWidget(rect->left()),mapYToWidget(rect->top())));
    newrect.setBottomRight(QPoint(mapXToWidget(rect->right()),mapYToWidget(rect->bottom())));

    return newrect;
}
Example #15
0
QRect CWndControl::GetClientRect(bool parent) const
{
    QRect rect = m_clientRect;
    if (!parent)
    {
        rect.setTopLeft(rect.topLeft() - m_windowRect.topLeft());
        rect.setBottomRight(rect.bottomRight() - m_windowRect.topLeft());
    }
    return rect;
}
Example #16
0
void QuickItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
                              const QModelIndex &index) const
{
  int flags = index.data(QuickItemModelRole::ItemFlags).value<int>();

  QStyleOptionViewItem opt = option;
  initStyleOption(&opt, index);

  // Disable foreground painting so we can do ourself
  opt.text = "";
  opt.icon = QIcon();

  QApplication::style()->drawControl(QStyle::CE_ItemViewItem, &opt, painter);

  QRect drawRect = option.rect;

  QColor base = option.state & QStyle::State_Selected ?
                  option.palette.highlightedText().color() :
                  index.data(Qt::ForegroundRole).value<QColor>();

  if (m_colors.contains(index.sibling(index.row(), 0))) {
    QColor blend = m_colors.value(index.sibling(index.row(), 0));
    QColor blended =
      QColor::fromRgbF(base.redF()   * (1 - blend.alphaF()) + blend.redF()   * blend.alphaF(),
                       base.greenF() * (1 - blend.alphaF()) + blend.greenF() * blend.alphaF(),
                       base.blueF()  * (1 - blend.alphaF()) + blend.blueF()  * blend.alphaF());
    painter->setPen(blended);
  } else {
    painter->setPen(base);
  }

  if (index.column() == 0) {
    QVector<QPixmap> icons;
    icons << index.data(Qt::DecorationRole).value<QPixmap>();

    if ((flags & QuickItemModelRole::OutOfView) && (~flags & QuickItemModelRole::Invisible)) {
      icons << QIcon(":/gammaray/plugins/quickinspector/warning.png").pixmap(16, 16);
    }

    if (flags & QuickItemModelRole::HasActiveFocus) {
      icons << QIcon(":/gammaray/plugins/quickinspector/active-focus.png").pixmap(16, 16);
    }

    if (flags & QuickItemModelRole::HasFocus && ~flags & QuickItemModelRole::HasActiveFocus) {
      icons << QIcon(":/gammaray/plugins/quickinspector/focus.png").pixmap(16, 16);
    }

    for (int i = 0; i < icons.size(); i++) {
      painter->drawPixmap(drawRect.topLeft(), icons.at(i));
      drawRect.setTopLeft(drawRect.topLeft() + QPoint(20, 0));
    }
  }

  painter->drawText(drawRect, Qt::AlignVCenter, index.data(Qt::DisplayRole).toString());
}
Example #17
0
QRect CWndControl::GetWindowRect(bool parent) const
{
    QRect rect = m_windowRect;
    if (!parent)
    {
        const QPoint topLeft = rect.topLeft();
        rect.setTopLeft(QPoint(0, 0));
        rect.setBottomRight(rect.bottomRight() - topLeft);
    }
    return rect;
}
Example #18
0
void TimeLineCells::paintEvent( QPaintEvent* event )
{
    Q_UNUSED( event );

    Object* object = mEditor->object();
    Layer* layer = mEditor->layers()->currentLayer();

    Q_ASSUME( object != nullptr && layer != nullptr );

    QPainter painter( this );

    bool isPlaying = mEditor->playback()->isPlaying();
    if ( ( !isPlaying && !timeLine->scrubbing ) || m_pCache == NULL )
    {
        drawContent();
    }
    if ( m_pCache )
    {
        painter.drawPixmap( QPoint( 0, 0 ), *m_pCache );
    }

    if ( m_eType == TIMELINE_CELL_TYPE::Tracks )
    {
        if (!isPlaying) {
            paintOnionSkin(painter);
        }

        // --- draw the position of the current frame
        if ( mEditor->currentFrame() > frameOffset )
        {
            painter.setBrush( QColor( 255, 0, 0, 128 ) );
            painter.setPen( Qt::NoPen );
            painter.setFont( QFont( "helvetica", 10 ) );
            //painter.setCompositionMode(QPainter::CompositionMode_Source); // this causes the message: QPainter::setCompositionMode: PorterDuff modes not supported on device
            QRect scrubRect;
            scrubRect.setTopLeft( QPoint( getFrameX( mEditor->currentFrame() - 1 ), 0 ) );
            scrubRect.setBottomRight( QPoint( getFrameX( mEditor->currentFrame() ), height() ) );
            if ( shortScrub )
            {
                scrubRect.setBottomRight( QPoint( getFrameX( mEditor->currentFrame() ), 19 ) );
            }
            painter.drawRect( scrubRect );
            painter.setPen( QColor( 70, 70, 70, 255 ) );
            int incr = 0;
            if ( mEditor->currentFrame() < 10 )
            {
                incr = 4;
            }
            else { incr = 0; }
            painter.drawText( QPoint( getFrameX( mEditor->currentFrame() - 1 ) + incr, 15 ),
                              QString::number( mEditor->currentFrame() ) );
        }
    }
}
QRect ByteArrayColumnViewPrivate::cursorRect() const
{
    Q_Q( const ByteArrayColumnView );

    QRect cursorRect = mActiveColumn->byteRect( mTableCursor->coord() );
    const QPoint viewportPoint( cursorRect.x() - q->xOffset(), cursorRect.y() - q->yOffset() );
    const QPoint globalPoint = q->viewport()->mapToParent( viewportPoint ); // TODO: seems still missing some offset
    cursorRect.setTopLeft( globalPoint );

    return cursorRect;
}
Example #20
0
void RegionGrabber::resizeEvent( QResizeEvent* e )
{
    Q_UNUSED( e );
    if ( selection.isNull() )
        return;
    QRect r = selection;
    r.setTopLeft( limitPointToRect( r.topLeft(), rect() ) );
    r.setBottomRight( limitPointToRect( r.bottomRight(), rect() ) );
    if ( r.width() <= 1 || r.height() <= 1 ) //this just results in ugly drawing...
        r = QRect();
    selection = r;
}
/** Stores the settings of the mainwindow in the profile p */
void BibleTime::storeProfileSettings( CProfile* p ) {
	Q_ASSERT(p && m_windowFullscreen_action);
	if (!p || !m_windowFullscreen_action) return;
	
	p->setFullscreen( m_windowFullscreen_action->isChecked() );
	p->setMaximized( this->KMainWindow::isMaximized() );

	QRect geometry;
	geometry.setTopLeft(pos());
	geometry.setSize(size());
	p->setGeometry(geometry);
}
Example #22
0
/**
 * @brief Draw the world.
 * @param painter
 */
void RenderArea::drawField(QPainter &painter)
{
    painter.save();
    painter.setRenderHint(QPainter::Antialiasing);
    QRect field;
    field.setTopLeft(QPoint(this->x(), this->y()));
    field.setBottomRight(QPoint(this->width()-1, this->height()-1));
    painter.setPen(Qt::black);
    painter.setBrush(QBrush(Qt::green));
    painter.drawRect(field);
    painter.restore();
}
Example #23
0
static QRect getBoundingRect(const GH_List &list){
    GH_List::const_iterator n = list.begin();
    if (n != list.end()){
        QRect rect = (*n)->box;
        for (++n; n!=list.end(); ++n){
            rect = rect.united((*n)->box);
        }
        rect.setTopLeft(rect.topLeft() - QPoint(g_border, g_border));
        rect.setBottomRight(rect.topLeft() + QPoint(rect.width() + 2 * g_border, rect.height() + 2 * g_border));
        return rect;
    }
    return QRect();
}
void KomposeDesktopWidget::focusOutEvent ( QFocusEvent * )
{
  // Unset highlight if cursor moves out of our rect
  // but not if it enters a child widget
  QRect deskRect;
  deskRect.setTopLeft(mapToGlobal( QPoint(0,0) ));
  deskRect.setWidth(width());
  deskRect.setHeight(height());
  if ( !deskRect.contains( QCursor::pos() ) )
    highlight = false;

  repaint();
}
Example #25
0
void Receiver::drawBorderRect()
{
    if(isDrawBorder){
        QPainter painter(this);
        QRect rect;
        QPen pen;

        pen.setColor(QColor(211, 211, 211));
        rect.setTopLeft(QPoint(10, 20));
        rect.setBottomRight(QPoint(this->width() - 15, this->height() - 20));
        painter.setPen(pen);
        painter.drawRect(rect);
    }
}
Example #26
0
void RectMarker::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    Q_UNUSED(option);
    Q_UNUSED(widget);
    QPen pn;
    pn.setColor(color);
    pn.setWidth(width/currentScale);
    painter->setPen(pn);
    QRect rect;
    rect.setTopLeft(firstPoint);
    rect.setBottomRight(secondPoint);
    painter->drawRect(rect);

}
QRect KstGfxMouseHandlerUtils::resizeRectFromCorner(const QPoint& anchorPoint, const QPoint& movePoint, const QPoint& pos, const QRect& bounds, bool maintainAspect) {
  QRect newSize;
  QPoint npos = pos;

  if (maintainAspect) {
    QPoint fakeMovePoint = anchorPoint + QPoint(quadrantSign(pos,anchorPoint)*abs((movePoint - anchorPoint).x()),abs((movePoint - anchorPoint).y())); // allow the rectangle to flip.
    npos = findNearestPtOnLine(anchorPoint, fakeMovePoint, pos, bounds);
  }

  newSize.setTopLeft(anchorPoint);
  newSize.setBottomRight(npos);

  return bounds.intersect(newSize.normalize());
}
Example #28
0
void StatsWidgetElement::paintEvent(QPaintEvent * /*ev*/)
{
    QPen pen;
    pen.setColor(QColor(0, 0, 0, 255));

    QRect rect;
    rect.setTopLeft(QPoint(BORDER_X, BORDER_Y));
    rect.setWidth(frameRect().width()   - BORDER_WIDTH);
    rect.setHeight(frameRect().height() - BORDER_WIDTH);

    QPainter p(this);
    p.setPen(pen);
    p.setRenderHint(QPainter::Antialiasing);
    p.drawRoundRect(rect, 1000 / rect.width(), 1000 / rect.height());
}
Example #29
0
KasItem* KasBar::itemAt(const QPoint &p)
{
   KasItem *i;
   QRect cr;

   for (i = items.first(); i; i = items.next()) {
       cr.setTopLeft( i->pos() );
       cr.setSize( QSize( itemExtent(), itemExtent() ) );

       if(cr.contains(p))
	   return i;
   }

   return 0;
}
Example #30
0
void RegionGrab::resizeEvent(QResizeEvent *event)
{
  Q_UNUSED( event );
  if (m_selection.isNull())
    return;

  QRect r = m_selection;
  r.setTopLeft(limitPointToRect(r.topLeft(), rect()));
  r.setBottomRight(limitPointToRect(r.bottomRight(), rect()));

  if (r.width() <= 1 || r.height() <= 1) //this just results in ugly drawing...
    m_selection = QRect();
  else
    m_selection = normalizeSelection(r);
}