C++ (Cpp) QRect Examples

C++ (Cpp) QRect - 30 examples found. These are the top rated real world C++ (Cpp) examples of QRect extracted from open source projects. You can rate examples to help us improve the quality of examples.
Example #1
0
bool RadioItemDelegate::editorEvent(QEvent *event, QAbstractItemModel *model,
                                    const QStyleOptionViewItem &option, const QModelIndex &index)
{
    if (event->type() == QEvent::MouseButtonRelease || event->type() == QEvent::KeyPress)
    {
        if (hasRadioButton(index))
        {
            if(event->type() == QEvent::MouseButtonRelease)
            {
                QRect checkRect = qApp->style()->subElementRect(QStyle::SE_RadioButtonIndicator, &option);

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

                if(!checkRect.contains(mouseEvent->pos()))
                    return true;
            }

            if (!index.data(Qt::CheckStateRole).toBool())
            {
                model->setData(index, Qt::Checked, Qt::CheckStateRole);
                QModelIndex parentItem = index.parent();
                for (int i = 0; i < model->rowCount(parentItem); ++i)
                {
                    QModelIndex childIndex = parentItem.child(i,0);
                    if (childIndex != index)
                        model->setData(childIndex, Qt::Unchecked, Qt::CheckStateRole);
                }
            }
            return true;
        }
    }
    return QStyledItemDelegate::editorEvent(event,model,option,index);
}
void QDeclarative1PaintedItem::setPixelCacheSize(int pixels)
{
    Q_D(QDeclarative1PaintedItem);
    if (pixels < d->max_imagecache_size) {
        int cachesize=0;
        for (int i=0; i<d->imagecache.count(); ++i) {
            QRect area = d->imagecache[i]->area;
            cachesize += area.width()*area.height();
        }
        while (d->imagecache.count() && cachesize > pixels) {
            int oldest=-1;
            int age=-1;
            for (int i=0; i<d->imagecache.count(); ++i) {
                int a = d->imagecache[i]->age;
                if (a > age) {
                    oldest = i;
                    age = a;
                }
            }
            cachesize -= d->imagecache[oldest]->area.width()*d->imagecache[oldest]->area.height();
            delete d->imagecache.takeAt(oldest);
        }
    }
    d->max_imagecache_size = pixels;
}
Example #3
0
/*!
    Wrapper for QPainter::fillRect()
*/
void QwtPainter::fillRect(QPainter *painter,
                          const QRect &rect, const QBrush &brush)
{
    if ( !rect.isValid() )
        return;

    QRect clipRect;
    const bool deviceClipping = isClippingNeeded(painter, clipRect);

#if QT_VERSION >= 0x040000
    /*
      Performance of Qt4 is horrible for non trivial brushs. Without
      clipping expect minutes or hours for repainting large rects
      (might result from zooming)
    */

    if ( deviceClipping )
        clipRect &= painter->window();
    else
        clipRect = painter->window();

    if ( painter->hasClipping() )
        clipRect &= painter->clipRegion().boundingRect();
#endif

    QRect r = d_metricsMap.layoutToDevice(rect, painter);
    if ( deviceClipping )
        r = r.intersected(clipRect);

    if ( r.isValid() )
        painter->fillRect(r, brush);
}
Example #4
0
void CWizNoteStyle::drawMultiLineItemBackground(const QStyleOptionViewItemV4* vopt, QPainter* pt, const CWizMultiLineListWidget* view) const
{
    if (const CWizAttachmentListView *attachView = dynamic_cast<const CWizAttachmentListView *>(view))
    {
        const CWizAttachmentListViewItem* item = attachView->attachmentItemFromIndex(vopt->index);
        if (item && (item->isDownloading() || item->isUploading()))
        {
            pt->save();
            pt->setPen(Qt::NoPen);
            pt->setBrush(QColor("#5990EF"));
            QRect rect = vopt->rect;
            rect.setWidth(rect.width() * item->loadProgress() / 100);
            pt->drawRect(rect);
            pt->restore();

            return;
        }
    }

    if (vopt->state.testFlag(State_Selected))
    {
//        m_multiLineListSelectedItemBackground.Draw(pt, vopt->rect, 0);
        pt->save();

        QPen pen(QColor("#3177EE"));
//        pen.setWidth(2);
        pt->setPen(pen);
        pt->setBrush(Qt::NoBrush);
        pt->drawRect(vopt->rect.adjusted(1, 1, -1, -2));

        pt->restore();
    }
}
Example #5
0
void QtDNDTabBar::dropEvent(QDropEvent* dropEvent) {
    QtDNDTabBar* sourceTabBar = dynamic_cast<QtDNDTabBar*>(dropEvent->source());
    if (sourceTabBar && dropEvent->mimeData() && dropEvent->mimeData()->data("action") == QByteArray("application/tab-detach")) {
        QtDNDTabBar* source = dynamic_cast<QtDNDTabBar*>(dropEvent->source());

        int targetTabIndex = tabAt(dropEvent->pos());
        QRect rect = tabRect(targetTabIndex);
        if (targetTabIndex >= 0 && (dropEvent->pos().x() - rect.left() - rect.width()/2 > 0)) {
            targetTabIndex++;
        }

        QWidget* tab = source->getDragWidget();
        assert(tab);
        QTabWidget* targetTabWidget = dynamic_cast<QTabWidget*>(parentWidget());

        QString tabText = source->getDragText();

        /*
         * When you add a widget to an empty QTabWidget, it's automatically made the current widget.
         * Making the widget the current widget, widget->show() is called for the widget. Directly reacting
         * to that event, and adding the widget again to the QTabWidget results in undefined behavior. For
         * example the tab label is shown but the widget is neither has the old nor in the new QTabWidget as
         * parent. Blocking signals on the QWidget to be added to a QTabWidget prevents this behavior.
         */
        targetTabWidget->setUpdatesEnabled(false);
        tab->blockSignals(true);
        targetTabWidget->insertTab(targetTabIndex, tab, tabText);
        dropEvent->acceptProposedAction();
        tab->blockSignals(false);
        targetTabWidget->setUpdatesEnabled(true);
        onDropSucceeded();
    }
}
void DocsetListItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
                                   const QModelIndex &index) const
{
    QItemDelegate::paint(painter, option, index);

    if (!index.model()->data(index, Zeal::ListModel::UpdateAvailableRole).toBool())
        return;

    const QString text = tr("Update available");

    QFont font(painter->font());
    font.setItalic(true);

    const QFontMetrics fontMetrics(font);

    QRect textRect = option.rect;
    textRect.setLeft(textRect.right() - fontMetrics.width(text) - 2);

    painter->save();

    if (option.state & QStyle::State_Selected)
        painter->setPen(QPen(option.palette.highlightedText(), 1));

    painter->setFont(font);
    painter->drawText(textRect, text);

    painter->restore();
}