예제 #1
0
void PushButton::paint(QPainter *painter,
                       const QStyleOptionGraphicsItem *option,
                       QWidget *widget)
{
    if (!styleSheet().isNull() || Theme::defaultTheme()->useNativeWidgetStyle()) {
        QGraphicsProxyWidget::paint(painter, option, widget);
        return;
    }

    QPixmap bufferPixmap;

    //Normal button, pressed or not
    if (isEnabled()) {
        if (nativeWidget()->isDown() || nativeWidget()->isChecked()) {
            d->background->setElementPrefix("pressed");
        } else {
            d->background->setElementPrefix("normal");
        }

    //flat or disabled
    } else if (!isEnabled() || nativeWidget()->isFlat()) {
        bufferPixmap = QPixmap(rect().size().toSize());
        bufferPixmap.fill(Qt::transparent);

        QPainter buffPainter(&bufferPixmap);
        d->background->paintFrame(&buffPainter);
        buffPainter.setCompositionMode(QPainter::CompositionMode_DestinationIn);
        buffPainter.fillRect(bufferPixmap.rect(), QColor(0, 0, 0, 128));

        painter->drawPixmap(0, 0, bufferPixmap);
    }

    //if is under mouse draw the animated glow overlay
    if (!nativeWidget()->isDown() && !nativeWidget()->isChecked() && isEnabled() && acceptHoverEvents() && d->background->hasElementPrefix("active")) {
        if (d->hoverAnimation->state() == QAbstractAnimation::Running && !isUnderMouse() && !nativeWidget()->isDefault()) {
            d->background->setElementPrefix("active");
            d->background->paintFrame(painter, d->activeRect.topLeft());
        } else {
            painter->drawPixmap(
                d->activeRect.topLeft(),
                d->hoverAnimation->property("currentPixmap").value<QPixmap>());
        }
    } else if (isEnabled()) {
        d->background->paintFrame(painter);
    }


    painter->setPen(Plasma::Theme::defaultTheme()->color(Theme::ButtonTextColor));

    if (nativeWidget()->isDown()) {
        painter->translate(QPoint(1, 1));
    }

    QRectF rect = contentsRect();

    if (!nativeWidget()->icon().isNull()) {
        const qreal iconSize = qMin(rect.width(), rect.height());
        QPixmap iconPix = nativeWidget()->icon().pixmap(iconSize);
        if (!isEnabled()) {
            KIconEffect *effect = KIconLoader::global()->iconEffect();
            iconPix = effect->apply(iconPix, KIconLoader::Toolbar, KIconLoader::DisabledState);
        }

        QRect pixmapRect;
        if (nativeWidget()->text().isEmpty()) {
            pixmapRect = nativeWidget()->style()->alignedRect(option->direction, Qt::AlignCenter, iconPix.size(), rect.toRect());
        } else {
            pixmapRect = nativeWidget()->style()->alignedRect(option->direction, Qt::AlignLeft|Qt::AlignVCenter, iconPix.size(), rect.toRect());
        }
        painter->drawPixmap(pixmapRect.topLeft(), iconPix);

        if (option->direction == Qt::LeftToRight) {
            rect.adjust(rect.height(), 0, 0, 0);
        } else {
            rect.adjust(0, 0, -rect.height(), 0);
        }
    }

    QFontMetricsF fm(font());
    // If the height is too small increase the Height of the button to shall the whole text #192988
    if (rect.height() < fm.height()) {
        rect.setHeight(fm.height());
        rect.moveTop(boundingRect().center().y() - rect.height() / 2);
    }

    // If there is not enough room for the text make it to fade out
    if (rect.width() < fm.width(nativeWidget()->text())) {
        if (bufferPixmap.isNull()) {
            bufferPixmap = QPixmap(rect.size().toSize());
        }
        bufferPixmap.fill(Qt::transparent);

        QPainter p(&bufferPixmap);
        p.setPen(painter->pen());
        p.setFont(font());

        // Create the alpha gradient for the fade out effect
        QLinearGradient alphaGradient(0, 0, 1, 0);
        alphaGradient.setCoordinateMode(QGradient::ObjectBoundingMode);
        if (option->direction == Qt::LeftToRight) {
            alphaGradient.setColorAt(0, QColor(0, 0, 0, 255));
            alphaGradient.setColorAt(1, QColor(0, 0, 0, 0));
            p.drawText(bufferPixmap.rect(), Qt::AlignLeft|Qt::AlignVCenter|Qt::TextShowMnemonic,
                       nativeWidget()->text());
        } else {
            alphaGradient.setColorAt(0, QColor(0, 0, 0, 0));
            alphaGradient.setColorAt(1, QColor(0, 0, 0, 255));
            p.drawText(bufferPixmap.rect(), Qt::AlignRight|Qt::AlignVCenter|Qt::TextShowMnemonic,
                       nativeWidget()->text());
        }

        p.setCompositionMode(QPainter::CompositionMode_DestinationIn);
        p.fillRect(bufferPixmap.rect(), alphaGradient);

        painter->drawPixmap(rect.topLeft(), bufferPixmap);
    } else {
        painter->setFont(font());
        painter->drawText(rect, Qt::AlignCenter|Qt::TextShowMnemonic, nativeWidget()->text());
    }
}
예제 #2
0
void PlListViewItemDelegate::paint( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const
{
    QString title = PLModel::getMeta( index, COLUMN_TITLE );
    QString duration = PLModel::getMeta( index, COLUMN_DURATION );
    if( !duration.isEmpty() ) title += QString(" [%1]").arg( duration );

    QString artist = PLModel::getMeta( index, COLUMN_ARTIST );
    QString album = PLModel::getMeta( index, COLUMN_ALBUM );
    QString trackNum = PLModel::getMeta( index, COLUMN_TRACK_NUMBER );
    QString artistAlbum = artist;
    if( !album.isEmpty() )
    {
        if( !artist.isEmpty() ) artistAlbum += ": ";
        artistAlbum += album;
        if( !trackNum.isEmpty() ) artistAlbum += QString( " [#%1]" ).arg( trackNum );
    }

    QPixmap artPix = PLModel::getArtPixmap( index, QSize( LISTVIEW_ART_SIZE, LISTVIEW_ART_SIZE ) );

    //Draw selection rectangle and current playing item indication
    paintBackground( painter, option, index );

    QRect artRect( artPix.rect() );
    artRect.moveCenter( QPoint( artRect.center().x() + 3,
                                option.rect.center().y() ) );
    //Draw album art
    painter->drawPixmap( artRect, artPix );

    //Start drawing text
    painter->save();

    if( option.state & QStyle::State_Selected )
        painter->setPen( option.palette.color( QPalette::HighlightedText ) );

    QTextOption textOpt( Qt::AlignVCenter | Qt::AlignLeft );
    textOpt.setWrapMode( QTextOption::NoWrap );

    QFont f( index.data( Qt::FontRole ).value<QFont>() );

    //Draw title info
    f.setItalic( true );
    painter->setFont( f );
    QFontMetrics fm( painter->fontMetrics() );

    QRect textRect = option.rect.adjusted( LISTVIEW_ART_SIZE + 10, 0, -10, 0 );
    if( !artistAlbum.isEmpty() )
    {
        textRect.setHeight( fm.height() );
        textRect.moveBottom( option.rect.center().y() - 2 );
    }

    //Draw children indicator
    if( !index.data( PLModel::IsLeafNodeRole ).toBool() )
    {
        QPixmap dirPix = QPixmap( ":/type/node" );
        painter->drawPixmap( QPoint( textRect.x(), textRect.center().y() - dirPix.height() / 2 ),
                             dirPix );
        textRect.setLeft( textRect.x() + dirPix.width() + 5 );
    }

    painter->drawText( textRect,
                       fm.elidedText( title, Qt::ElideRight, textRect.width() ),
                       textOpt );

    // Draw artist and album info
    if( !artistAlbum.isEmpty() )
    {
        f.setItalic( false );
        painter->setFont( f );
        fm = painter->fontMetrics();

        textRect.moveTop( textRect.bottom() + 4 );
        textRect.setLeft( textRect.x() + 20 );

        painter->drawText( textRect,
                           fm.elidedText( artistAlbum, Qt::ElideRight, textRect.width() ),
                           textOpt );
    }

    painter->restore();
}
예제 #3
0
void GraphicElement::setPixmap( const QPixmap &pixmap ) {
  setTransformOriginPoint( pixmap.rect().center() );
  this->pixmap = pixmap;
  update( boundingRect( ) );
}
예제 #4
0
void QBlitterPaintEngine::drawPixmap(const QPointF &pos, const QPixmap &pm)
{
    drawPixmap(QRectF(pos, pm.size()), pm, pm.rect());
}
예제 #5
0
    //________________________________________________
    void TransitionWidget::grabBackground( QPixmap& pixmap, QWidget* widget, QRect& rect ) const
    {
        if( !widget ) return;

        QWidgetList widgets;
        if( widget->autoFillBackground() )
        { widgets.append( widget ); }

        QWidget *parent(0);

        // get highest level parent
        for( parent = widget->parentWidget(); parent; parent = parent->parentWidget() )
        {

            if( !( parent->isVisible() && parent->rect().isValid() ) ) continue;

            // store in list
            widgets.append( parent );

            // stop at topLevel
            if( parent->isTopLevel() || parent->autoFillBackground() ) break;

        }

        if( !parent ) parent = widget;

        // painting
        QPainter p(&pixmap);
        p.setClipRect( rect );
        const QBrush backgroundBrush = parent->palette().brush( parent->backgroundRole());
        if( backgroundBrush.style() == Qt::TexturePattern)
        {

            p.drawTiledPixmap( rect, backgroundBrush.texture(), widget->mapTo( parent, rect.topLeft() ) );

        } else {

            p.fillRect( pixmap.rect(), backgroundBrush );

        }

        if( parent->isTopLevel() && parent->testAttribute(Qt::WA_StyledBackground))
        {
            QStyleOption option;
            option.initFrom(parent);
            option.rect = rect;
            option.rect.translate( widget->mapTo( parent, rect.topLeft() ) );
            p.translate(-option.rect.topLeft());
            parent->style()->drawPrimitive ( QStyle::PE_Widget, &option, &p, parent );
            p.translate(option.rect.topLeft());
        }

        // draw all widgets in parent list
        // backward
        QPaintEvent event(rect);
        for( int i = widgets.size() - 1; i>=0; i-- )
        {
            QWidget* w = widgets.at(i);
            w->render( &p, -widget->mapTo( w, rect.topLeft() ), rect, 0 );
        }

        // end
        p.end();

    }
예제 #6
0
void MainWindow::on_actionGamma_correction_triggered()
{
    QPixmap pixmap = pixmapItem->pixmap().copy();

    QImage image = pixmap.toImage();
    int width = image.width();
    int height = image.height();

    if (width == 0 || height == 0)
    {
        ui->statusBar->showMessage( tr("Error. Image bad size"), 3000 );
        return;
    }

    DialogGammaCorrection dialog;

    if (dialog.exec() == QDialog::Rejected)
        return;

    int maxR = -1;
    int maxG = -1;
    int maxB = -1;

    for (int y = 0; y < height; ++y)
        for (int x = 0; x < width; ++x)
        {
            QRgb oldColor = image.pixel(x, y);
            int red = qRed(oldColor);
            int green = qGreen(oldColor);
            int blue = qBlue(oldColor);
            if (red > maxR)
                maxR = red;
            if (green > maxG)
                maxG = green;
            if (blue > maxB)
                maxB = blue;
        }

    double gamma = dialog.getGamma();
    double cR = 255 / qPow(maxR, gamma);
    double cG = 255 / qPow(maxG, gamma);
    double cB = 255 / qPow(maxB, gamma);

    for (int y = 0; y < height; ++y)
        for (int x = 0; x < width; ++x)
        {
            QRgb oldColor = image.pixel(x, y);
            int red = cR * qPow(qRed(oldColor), gamma);
            int green = cG * qPow(qGreen(oldColor), gamma);
            int blue = cB * qPow(qBlue(oldColor), gamma);
            if (red < 0)
                red = 0;
            if (red > 255)
                red = 255;
            if (green < 0)
                green = 0;
            if (green > 255)
                green = 255;
            if (blue < 0)
                blue = 0;
            if (blue > 255)
                blue = 255;
            image.setPixel(x, y, qRgb(red, green, blue));
        }

    pixmap.convertFromImage(image);

    pixmapItem_2->setPixmap(pixmap);
    scene_2->setSceneRect(QRectF(pixmap.rect()));

    calcHist(pixmap, hist_2, maxLevel_2);
    drawHist(pixmapItem_4, hist_2, maxLevel_2);
}
예제 #7
0
int main(int argc, char *argv[])
{
    // Инициализируем генератор псевдослучайных чисел
    qsrand(QTime::currentTime().msec());

    QApplication app(argc, argv);

    BubbleItem::setBubblePixmap(QPixmap(":/images/bubble.png"));

    // Получаем скриншот
    QScreen *screen = QApplication::primaryScreen();
    if (!screen)
        return -1;
    QPixmap screenshot = screen->grabWindow(0);

    // QGraphicsScene - контейнер для создаваемых нами
    // объектов класса Bubble
    QGraphicsScene scene;
    scene.setSceneRect( screenshot.rect() );

    // Наполняем сцену непересекающимися элементами
    {
        const int left   = scene.sceneRect().left()   + BubbleItem::RADIUS;
        const int top    = scene.sceneRect().top()    + BubbleItem::RADIUS;
        const int right  = scene.sceneRect().right()  - BubbleItem::RADIUS;
        const int bottom = scene.sceneRect().bottom() - BubbleItem::RADIUS;

        for (int i = 0; i < BUBBLES_AMOUNT; ++i)
        {
            BubbleItem *bubble = new BubbleItem();
            scene.addItem(bubble);

            // Будем давать пузырю случайные координаты до тез пор
            // пока он не прекратит пересекаться с другими пузырями
            do
            {
                bubble->setPos(
                    left + qrand() % (right - left),
                    top  + qrand() % (bottom - top)
                );
            }
            while ( !scene.collidingItems(bubble).isEmpty() );
        }
    }

    // MainWidget - главный и единственный виджет этой программы,
    // он непосредственно рисует на экране элементы сцены, а также
    // обрабатывает нажатие клавиш и завершает выполнение программы при
    // нажатии клавиши ESC
    MainWidget view(&scene);
    view.setBackgroundPixmap(screenshot);
    view.setRenderHint(QPainter::Antialiasing);
    view.showFullScreen();

    // Используем QTimer для анимации движения пузырей. Сцена будет принудительно
    // обновляться EXPECTED_FPS раз в секунду
    QTimer timer;
    QObject::connect(&timer, SIGNAL(timeout()), &scene, SLOT(advance()));
    timer.start(1000 / EXPECTED_FPS);

    return app.exec();
}
예제 #8
0
// Draws a cached pixmap with shadow
void StyleHelper::drawIconWithShadow(const QIcon &icon, const QRect &rect,
                                     QPainter *p, QIcon::Mode iconMode, int dipRadius, const QColor &color, const QPoint &dipOffset)
{
    QPixmap cache;
    QString pixmapName = QString::fromLatin1("icon %0 %1 %2").arg(icon.cacheKey()).arg(iconMode).arg(rect.height());

    if (!QPixmapCache::find(pixmapName, cache)) {
        // High-dpi support: The in parameters (rect, radius, offset) are in
        // device-independent pixels. The call to QIcon::pixmap() below might
        // return a high-dpi pixmap, which will in that case have a devicePixelRatio
        // different than 1. The shadow drawing caluculations are done in device
        // pixels.
        QPixmap px = icon.pixmap(rect.size());
        int devicePixelRatio = qCeil(pixmapDevicePixelRatio(px));
        int radius = dipRadius * devicePixelRatio;
        QPoint offset = dipOffset * devicePixelRatio;
        cache = QPixmap(px.size() + QSize(radius * 2, radius * 2));
        cache.fill(Qt::transparent);

        QPainter cachePainter(&cache);
        if (iconMode == QIcon::Disabled) {
            QImage im = px.toImage().convertToFormat(QImage::Format_ARGB32);
            for (int y=0; y<im.height(); ++y) {
                QRgb *scanLine = (QRgb*)im.scanLine(y);
                for (int x=0; x<im.width(); ++x) {
                    QRgb pixel = *scanLine;
                    char intensity = qGray(pixel);
                    *scanLine = qRgba(intensity, intensity, intensity, qAlpha(pixel));
                    ++scanLine;
                }
            }
            px = QPixmap::fromImage(im);
        }

        // Draw shadow
        QImage tmp(px.size() + QSize(radius * 2, radius * 2 + 1), QImage::Format_ARGB32_Premultiplied);
        tmp.fill(Qt::transparent);

        QPainter tmpPainter(&tmp);
        tmpPainter.setCompositionMode(QPainter::CompositionMode_Source);
        tmpPainter.drawPixmap(QRect(radius, radius, px.width(), px.height()), px);
        tmpPainter.end();

        // blur the alpha channel
        QImage blurred(tmp.size(), QImage::Format_ARGB32_Premultiplied);
        blurred.fill(Qt::transparent);
        QPainter blurPainter(&blurred);
        qt_blurImage(&blurPainter, tmp, radius, false, true);
        blurPainter.end();

        tmp = blurred;

        // blacken the image...
        tmpPainter.begin(&tmp);
        tmpPainter.setCompositionMode(QPainter::CompositionMode_SourceIn);
        tmpPainter.fillRect(tmp.rect(), color);
        tmpPainter.end();

        tmpPainter.begin(&tmp);
        tmpPainter.setCompositionMode(QPainter::CompositionMode_SourceIn);
        tmpPainter.fillRect(tmp.rect(), color);
        tmpPainter.end();

        // draw the blurred drop shadow...
        cachePainter.drawImage(QRect(0, 0, cache.rect().width(), cache.rect().height()), tmp);

        // Draw the actual pixmap...
        cachePainter.drawPixmap(QRect(QPoint(radius, radius) + offset, QSize(px.width(), px.height())), px);
#if QT_VERSION > 0x050000
        cache.setDevicePixelRatio(devicePixelRatio);
#endif
        QPixmapCache::insert(pixmapName, cache);
    }

    QRect targetRect = cache.rect();
    targetRect.setSize(targetRect.size() / pixmapDevicePixelRatio(cache));
    targetRect.moveCenter(rect.center() - dipOffset);
    p->drawPixmap(targetRect, cache);
}
예제 #9
0
// --------------------------------------------------------------------------------
void QmvFormTool::displayDetails()
{
    
    slotSetBannerText( QString("%1").arg( fh->form_desc ) );

        // determine page data
    

        // prepare the details in the list.
    formDetail fd;
    QRect rect;
    QPixmap pm;
    QPainter pt;
    int x,y,w,h;
    QPoint pos;
    QSize size;
    QColor fill;
    
    for ( int row = 0; row < reln_fmdt->count(); row++ )
    {
        if (!fd.load( row, reln_fmdt) )
            continue;
        
        if ( fd.fmdt_field_type < formDetail::Label || fd.fmdt_field_type > formDetail::Special )
            continue;
        
            // the raw position from fmdt
        pos = QPoint( fd.fmdt_x_coord, fd.fmdt_y_coord );
        size = QSize( fd.fmdt_width, fd.fmdt_height );
        fill = QColor( Qt::gray );
        
            // special actions
        switch (fd.fmdt_field_type)
        {
            case formDetail::Label:
                break;
            case formDetail::Field:
                break;
            case formDetail::Line:
                fill = QColor( Qt::red );
                size.setHeight(2);
                break;
            case formDetail::Calc:
                break;
            case formDetail::Special:
                break;
            default:
                continue;
                break;
        }
        
        
            // adjust for section and margins
        switch (fd.fmdt_section)
        {
            case formDetail::ReportHeader:
            case formDetail::PageHeader:
                pos += QPoint( fh->form_mg_left, fh->form_mg_top );
                break;
            case formDetail::Detail:
                pos += QPoint( fh->form_mg_left, (fh->form_mg_top + fh->form_ph_height));
                break;
            case formDetail::PageFooter:
            case formDetail::ReportFooter:
                    // measure from bottom
                pos += QPoint( fh->form_mg_left, (pagesize.height() - fh->form_mg_bottom - fh->form_pf_height) );
                break;
        }

        if ( pos.x() < 0 || pos.y() < 0 || size.width() < 1 || size.height() < 1 )
            continue;
        
            // build a QRect for this detail
        rect.setSize( size );
            // reset origin, ready for drawing
        rect.moveTopLeft( QPoint(0,0) );
        
            // build a detail label using a pixmap
        pm.resize( rect.size() );
        pm.fill(getTransparentColor());
        pt.begin(&pm);

            // fill the background and draw the label
        pt.setPen( QPen( Qt::black, 2, SolidLine ) );
        pt.fillRect( rect, QBrush( fill, QBrush::SolidPattern ) );
        pt.setFont( QFont( fd.fmdt_ft_family, fd.fmdt_ft_size) );
        pt.drawText( rect, WordBreak|AlignCenter, fd.fmdt_text );

            // draw a border around the object
        pt.setBrush( Qt::NoBrush );
        pt.setPen(QPen( Qt::black, 2, SolidLine ) );
        pt.drawRect( rect );
        pt.end();

            // put the prepared pixmap on a canvas object
        QmvCanvasGrid * disp_obj = new QmvCanvasGrid( getCanvas(), rect.size(), getTransparentColor() );
            // use the canvas object as a key in list of displayed details
        canvas_details.insert( disp_obj, new int(row) );
        
            //disp_obj->setOpaqueFactor( 30 );
        disp_obj->drawPixmap( QPoint(0,0), pm, pm.rect() );

            // Move the object into place
        disp_obj->move( pos.x(), pos.y() );
        
        disp_obj->show();
            //pm.save( QString("tmp/%1.xpm").arg(row),"XPM" );
    }
    canvasView()->update();
}
예제 #10
0
void PixmapCachingSheetView::paintCells(QPainter& painter, const QRectF& paintRect, const QPointF& topLeft, CanvasBase* canvas, const QRect& visibleRect)
{
    if (!canvas) {
        SheetView::paintCells(painter, paintRect, topLeft, canvas, visibleRect);
        return;
    }
    // paintRect:   the canvas area, that should be painted; in document coordinates;
    //              no layout direction consideration; scrolling offset applied;
    //              independent from painter transformations
    // topLeft:     the document coordinate of the top left cell's top left corner;
    //              no layout direction consideration; independent from painter
    //              transformations

    QTransform t = painter.transform();

    // figure out scaling from the transformation... not really perfect, but should work as long as rotation is in 90 degree steps I think
    const qreal cos_sx = t.m11();
    const qreal sin_sx = t.m12();
    const qreal msin_sy = t.m21();
    const qreal cos_sy = t.m22();

    const qreal sx = sqrt(cos_sx*cos_sx + sin_sx*sin_sx);
    const qreal sy = sqrt(cos_sy*cos_sy + msin_sy*msin_sy);
    //const qreal cost = (sx > 1e-10 ? cos_sx / sx : cos_sy / sy);
    //const qreal ang = acos(cost);

    QPointF scale = QPointF(sx, sy);
    if (scale != d->lastScale) {
        d->tileCache.clear();
    }
    d->lastScale = scale;

    QRect tiles;
    const QRect visibleCells = paintCellRange();
    const Sheet * s = sheet();
    const QPointF bottomRight(s->columnPosition(visibleCells.right() + 1), s->rowPosition(visibleCells.bottom() + 1));
    tiles.setLeft(topLeft.x() * sx / TILESIZE);
    tiles.setTop(topLeft.y() * sy / TILESIZE);
    tiles.setRight((bottomRight.x() * sx + TILESIZE-1) / TILESIZE);
    tiles.setBottom((bottomRight.y() * sy + TILESIZE-1) / TILESIZE);

    bool rtl = s->layoutDirection() == Qt::RightToLeft;

    if (rtl) {
        for (int x = qMax(0, tiles.left()); x < tiles.right(); x++) {
            for (int y = qMax(0, tiles.top()); y < tiles.bottom(); y++) {
                QPixmap *p = d->getTile(s, x, y, canvas);
                if (p) {
                    QPointF pt(paintRect.width() - (x+1) * TILESIZE / scale.x(), y * TILESIZE / scale.y());
                    QRectF r(pt, QSizeF(TILESIZE / sx, TILESIZE / sy));
                    painter.drawPixmap(r, *p, p->rect());
                }
            }
        }
    } else {
        for (int x = qMax(0, tiles.left()); x < tiles.right(); x++) {
            for (int y = qMax(0, tiles.top()); y < tiles.bottom(); y++) {
                QPixmap *p = d->getTile(s, x, y, canvas);
                if (p) {
                    QPointF pt(x * TILESIZE / scale.x(), y * TILESIZE / scale.y());
                    QRectF r(pt, QSizeF(TILESIZE / sx, TILESIZE / sy));
                    painter.drawPixmap(r, *p, p->rect());
                }
            }
        }
    }
}
예제 #11
0
void paint_QPixmapCachedRoundedRect(QPainter &p)
{
    static bool first = true;
    static QPixmap cacheRect;
    if (first) {
        const int pw = 0;
        const int radius = 8;
        cacheRect = QPixmap(radius*2 + 3 + pw*2, radius*2 + 3 + pw*2);
        cacheRect.fill(Qt::transparent);
        QPainter paint(&cacheRect);
        paint.setRenderHint(QPainter::Antialiasing);
        paint.setPen(Qt::black);
        paint.setBrush(Qt::red);
        if (pw%2)
            paint.drawRoundedRect(QRectF(qreal(pw)/2+1, qreal(pw)/2+1, cacheRect.width()-(pw+1), cacheRect.height()-(pw+1)), radius, radius);
        else
            paint.drawRoundedRect(QRectF(qreal(pw)/2, qreal(pw)/2, cacheRect.width()-pw, cacheRect.height()-pw), radius, radius);

        first = false;
    }
    for (int i = 0; i < count; i++) {
        for (int j = 0; j < lines; ++j) {
            QSize size((j+1)*50, spacing-1);

            p.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform, true);

            const int pw = 0;

            int xOffset = (cacheRect.width()-1)/2;
            int yOffset = (cacheRect.height()-1)/2;

            QMargins margins(xOffset, yOffset, xOffset, yOffset);
            QTileRules rules(Qt::StretchTile, Qt::StretchTile);
            //NOTE: even though our item may have qreal-based width and height, qDrawBorderPixmap only supports QRects
            qDrawBorderPixmap(&p, QRect(-pw/2, j*spacing-pw/2, size.width()+pw, size.height()+pw), margins, cacheRect, cacheRect.rect(), margins, rules);
        }
    }
}
예제 #12
0
const QPixmap& PointImp::getLegendPixmap(bool bSelected) const
{
   static QPixmap pix(25, 15);
   static QPixmap selectedPix(25, 15);
   static QColor pixColor;
   static Point::PointSymbolType pixSymbol;
   static int pixWidth;
   static int pixHeight;
   static QColor selectedPixColor;
   static Point::PointSymbolType selectedPixSymbol;
   static int selectedPixWidth;
   static int selectedPixHeight;

   int iSymbolWidth = mSymbolSize;
   int iSymbolHeight = mSymbolSize;
   if (bSelected == true)
   {
      iSymbolWidth = mSymbolSize * 2;
      iSymbolHeight = mSymbolSize * 2;
   }

   int iWidth = iSymbolWidth;
   int iHeight = iSymbolHeight;

   if (iWidth < 25)
   {
      iWidth = 25;
   }

   if (iHeight < 15)
   {
      iHeight = 15;
   }

   if ((bSelected == true) && (selectedPix.isNull() == false))
   {
      if ((selectedPixColor != mColor) || (selectedPixSymbol != mSymbol) ||
         (selectedPixWidth != iWidth) || (selectedPixHeight != iHeight))
      {
         selectedPixColor = mColor;
         selectedPixSymbol = mSymbol;
         selectedPixWidth = iWidth;
         selectedPixHeight = iHeight;
         selectedPix.fill(Qt::transparent);

         QRect rcPix = selectedPix.rect();

         int iSymbolMinX = rcPix.center().x() - iSymbolWidth / 2.0;
         int iSymbolMinY = rcPix.center().y() - iSymbolHeight / 2.0;
         QRect rcSymbol(iSymbolMinX, iSymbolMinY, iSymbolWidth, iSymbolHeight);

         QPainter p(&selectedPix);
         p.setPen(QPen(mColor, 1));

         // Used with drawPolygon
         QPointF points[8];

         switch (mSymbol)
         {
            case Point::SOLID: default:
               p.fillRect(rcSymbol, mColor);
               break;

            case Point::X:
               p.drawLine(rcSymbol.topLeft(), rcSymbol.bottomRight());
               p.drawLine(rcSymbol.topRight(), rcSymbol.bottomLeft());
               break;

            case Point::CROSS_HAIR:
               p.drawLine(rcSymbol.left(), rcSymbol.center().y(), rcSymbol.right(),
                  rcSymbol.center().y());
               p.drawLine(rcSymbol.center().x(), rcSymbol.top(), rcSymbol.center().x(),
                  rcSymbol.bottom());
               break;

            case Point::ASTERISK:
               p.drawLine(rcSymbol.center().x(), rcSymbol.top(), rcSymbol.center().x(),
                  rcSymbol.bottom());
               p.drawLine(rcSymbol.left(), rcSymbol.top() + (rcSymbol.height() / 4), rcSymbol.right(),
                  rcSymbol.top() + ((rcSymbol.height() / 4) * 3));
               p.drawLine(rcSymbol.left(), rcSymbol.top() + ((rcSymbol.height() / 4) * 3),
                  rcSymbol.right(), rcSymbol.top() + (rcSymbol.height() / 4));
               break;

            case Point::VERTICAL_LINE:
               p.drawLine(rcSymbol.center().x(), rcSymbol.top(), rcSymbol.center().x(),
                  rcSymbol.bottom());
               break;

            case Point::HORIZONTAL_LINE:
               p.drawLine(rcSymbol.left(), rcSymbol.center().y(), rcSymbol.right(),
                  rcSymbol.center().y());
               break;

            case Point::FORWARD_SLASH:
               p.drawLine(rcSymbol.topRight(), rcSymbol.bottomLeft());
               break;

            case Point::BACK_SLASH:
               p.drawLine(rcSymbol.topLeft(), rcSymbol.bottomRight());
               break;

            case Point::BOX:
               p.drawRect(rcSymbol);
               break;

            case Point::BOXED_X:
               p.drawRect(rcSymbol);
               p.drawLine(rcSymbol.topLeft(), rcSymbol.bottomRight());
               p.drawLine(rcSymbol.topRight(), rcSymbol.bottomLeft());
               break;

            case Point::BOXED_CROSS_HAIR:
               p.drawRect(rcSymbol);
               p.drawLine(rcSymbol.left(), rcSymbol.center().y(), rcSymbol.right(),
                  rcSymbol.center().y());
               p.drawLine(rcSymbol.center().x(), rcSymbol.top(), rcSymbol.center().x(),
                  rcSymbol.bottom());
               break;

            case Point::BOXED_ASTERISK:
               p.drawRect(rcSymbol);
               p.drawLine(rcSymbol.center().x(), rcSymbol.top(), rcSymbol.center().x(),
                  rcSymbol.bottom());
               p.drawLine(rcSymbol.left(), rcSymbol.top() + (rcSymbol.height() / 4), rcSymbol.right(),
                  rcSymbol.top() + ((rcSymbol.height() / 4) * 3));
               p.drawLine(rcSymbol.left(), rcSymbol.top() + ((rcSymbol.height() / 4) * 3),
                  rcSymbol.right(), rcSymbol.top() + (rcSymbol.height() / 4));
               break;

            case Point::BOXED_VERTICAL_LINE:
               p.drawRect(rcSymbol);
               p.drawLine(rcSymbol.center().x(), rcSymbol.top(), rcSymbol.center().x(),
                  rcSymbol.bottom());
               break;

            case Point::BOXED_HORIZONTAL_LINE:
               p.drawRect(rcSymbol);
               p.drawLine(rcSymbol.left(), rcSymbol.center().y(), rcSymbol.right(),
                  rcSymbol.center().y());
               break;

            case Point::BOXED_FORWARD_SLASH:
               p.drawRect(rcSymbol);
               p.drawLine(rcSymbol.topRight(), rcSymbol.bottomLeft());
               break;

            case Point::BOXED_BACK_SLASH:
               p.drawRect(rcSymbol);
               p.drawLine(rcSymbol.topLeft(), rcSymbol.bottomRight());
               break;
            case Point::DIAMOND:
               p.drawLine(rcSymbol.center().x(), rcSymbol.top(), rcSymbol.right(), rcSymbol.center().y());
               p.drawLine(rcSymbol.right(), rcSymbol.center().y(), rcSymbol.center().x(), rcSymbol.bottom());
               p.drawLine(rcSymbol.center().x(), rcSymbol.bottom(), rcSymbol.left(), rcSymbol.center().y());
               p.drawLine(rcSymbol.left(), rcSymbol.center().y(), rcSymbol.center().x(), rcSymbol.top());
               break;

            case Point::DIAMOND_FILLED:
               p.setBrush(QBrush(Qt::SolidPattern));
               points[0] = QPointF(rcSymbol.center().x(), rcSymbol.top());
               points[1] = QPointF(rcSymbol.right(), rcSymbol.center().y());
               points[2] = QPointF(rcSymbol.center().x(), rcSymbol.bottom());
               points[3] = QPointF(rcSymbol.left(), rcSymbol.center().y());
               p.drawPolygon(points, 4);
               break;

            case Point::DIAMOND_CROSS_HAIR:
               p.drawLine(rcSymbol.center().x(), rcSymbol.top(), rcSymbol.right(), rcSymbol.center().y());
               p.drawLine(rcSymbol.right(), rcSymbol.center().y(), rcSymbol.center().x(), rcSymbol.bottom());
               p.drawLine(rcSymbol.center().x(), rcSymbol.bottom(), rcSymbol.left(), rcSymbol.center().y());
               p.drawLine(rcSymbol.left(), rcSymbol.center().y(), rcSymbol.center().x(), rcSymbol.top());

               p.drawLine(rcSymbol.left(), rcSymbol.center().y(), rcSymbol.right(), rcSymbol.center().y());
               p.drawLine(rcSymbol.center().x(), rcSymbol.top(), rcSymbol.center().x(), rcSymbol.bottom());
               break;

            case Point::TRIANGLE:
               p.drawLine(rcSymbol.center().x(), rcSymbol.top(), rcSymbol.right(), rcSymbol.bottom());
               p.drawLine(rcSymbol.bottomRight(), rcSymbol.bottomLeft());
               p.drawLine(rcSymbol.left(), rcSymbol.bottom(), rcSymbol.center().x(), rcSymbol.top());
               break;

            case Point::TRIANGLE_FILLED:
               p.setBrush(QBrush(Qt::SolidPattern));
               points[0] = QPointF(rcSymbol.center().x(), rcSymbol.top());
               points[1] = QPointF(rcSymbol.right(), rcSymbol.bottom());
               points[2] = QPointF(rcSymbol.left(), rcSymbol.bottom());
               p.drawPolygon(points, 3);
               break;

            case Point::RIGHT_TRIANGLE:
               p.drawLine(rcSymbol.left(), rcSymbol.top(), rcSymbol.right(), rcSymbol.center().y());
               p.drawLine(rcSymbol.right(), rcSymbol.center().y(), rcSymbol.left(), rcSymbol.bottom());
               p.drawLine(rcSymbol.left(), rcSymbol.bottom(), rcSymbol.left(), rcSymbol.top());
               break;

            case Point::RIGHT_TRIANGLE_FILLED:
               p.setBrush(QBrush(Qt::SolidPattern));
               points[0] = QPointF(rcSymbol.left(), rcSymbol.top());
               points[1] = QPointF(rcSymbol.right(), rcSymbol.center().y());
               points[2] = QPointF(rcSymbol.left(), rcSymbol.bottom());
               p.drawPolygon(points, 3);
               break;

            case Point::LEFT_TRIANGLE:
               p.drawLine(rcSymbol.right(), rcSymbol.top(), rcSymbol.right(), rcSymbol.bottom());
               p.drawLine(rcSymbol.right(), rcSymbol.bottom(), rcSymbol.left(), rcSymbol.center().y());
               p.drawLine(rcSymbol.left(), rcSymbol.center().y(), rcSymbol.right(), rcSymbol.top());
               break;

            case Point::LEFT_TRIANGLE_FILLED:
               p.setBrush(QBrush(Qt::SolidPattern));
               points[0] = QPointF(rcSymbol.right(), rcSymbol.top());
               points[1] = QPointF(rcSymbol.right(), rcSymbol.bottom());
               points[2] = QPointF(rcSymbol.left(), rcSymbol.center().y());
               p.drawPolygon(points, 3);
               break;

            case Point::DOWN_TRIANGLE:
               p.drawLine(rcSymbol.topLeft(), rcSymbol.topRight());
               p.drawLine(rcSymbol.right(), rcSymbol.top(), rcSymbol.center().x(), rcSymbol.bottom());
               p.drawLine(rcSymbol.center().x(), rcSymbol.bottom(), rcSymbol.left(), rcSymbol.top());
               break;

            case Point::DOWN_TRIANGLE_FILLED:
               p.setBrush(QBrush(Qt::SolidPattern));
               points[0] = QPointF(rcSymbol.left(), rcSymbol.top());
               points[1] = QPointF(rcSymbol.right(), rcSymbol.top());
               points[2] = QPointF(rcSymbol.center().x(), rcSymbol.bottom());
               p.drawPolygon(points, 3);
               break;

            case Point::CIRCLE:
               p.drawEllipse(rcSymbol);
               break;

            case Point::CIRCLE_FILLED:
               p.setBrush(QBrush(Qt::SolidPattern));
               p.drawEllipse(rcSymbol);
               break;

            case Point::OCTAGON:
               p.drawLine(rcSymbol.left() + (rcSymbol.width() / 4), rcSymbol.top(), rcSymbol.left() + ((rcSymbol.width() / 4) * 3), rcSymbol.top());
               p.drawLine(rcSymbol.left() + ((rcSymbol.width() / 4) * 3), rcSymbol.top(), rcSymbol.right(), rcSymbol.top() + (rcSymbol.height() / 4));
               p.drawLine(rcSymbol.right(), rcSymbol.top() + (rcSymbol.height() / 4), rcSymbol.right(), rcSymbol.top() + ((rcSymbol.height() / 4) * 3));
               p.drawLine(rcSymbol.right(), rcSymbol.top() + ((rcSymbol.height() / 4) * 3), rcSymbol.left() + ((rcSymbol.width() / 4) * 3), rcSymbol.bottom());
               p.drawLine(rcSymbol.left() + ((rcSymbol.width() / 4) * 3), rcSymbol.bottom(), rcSymbol.left() + (rcSymbol.width() / 4), rcSymbol.bottom());
               p.drawLine(rcSymbol.left() + (rcSymbol.width() / 4), rcSymbol.bottom(), rcSymbol.left(), rcSymbol.top() + ((rcSymbol.height() / 4) * 3));
               p.drawLine(rcSymbol.left(), rcSymbol.top() + ((rcSymbol.height() / 4) * 3), rcSymbol.left(), rcSymbol.top() + (rcSymbol.height() / 4));
               p.drawLine(rcSymbol.left(), rcSymbol.top() + (rcSymbol.height() / 4), rcSymbol.left() + (rcSymbol.width() / 4), rcSymbol.top());
               break;

            case Point::OCTAGON_FILLED:
               p.setBrush(QBrush(Qt::SolidPattern));
               points[0] = QPointF(rcSymbol.left() + (rcSymbol.width() / 4), rcSymbol.top());
               points[1] = QPointF(rcSymbol.left() + ((rcSymbol.width() / 4) * 3), rcSymbol.top());
               points[2] = QPointF(rcSymbol.right(), rcSymbol.top() + (rcSymbol.height() / 4));
               points[3] = QPointF(rcSymbol.right(), rcSymbol.top() + ((rcSymbol.height() / 4) * 3));
               points[4] = QPointF(rcSymbol.left() + ((rcSymbol.width() / 4) * 3), rcSymbol.bottom());
               points[5] = QPointF(rcSymbol.left() + (rcSymbol.width() / 4), rcSymbol.bottom());
               points[6] = QPointF(rcSymbol.left(), rcSymbol.top() + ((rcSymbol.height() / 4) * 3));
               points[7] = QPointF(rcSymbol.left(), rcSymbol.top() + (rcSymbol.height() / 4));
               p.drawPolygon(points, 8);
               break;

            case Point::OCTAGON_CROSS_HAIR:
               p.drawLine(rcSymbol.left() + (rcSymbol.width() / 4), rcSymbol.top(), rcSymbol.left() + ((rcSymbol.width() / 4) * 3), rcSymbol.top());
               p.drawLine(rcSymbol.left() + ((rcSymbol.width() / 4) * 3), rcSymbol.top(), rcSymbol.right(), rcSymbol.top() + (rcSymbol.height() / 4));
               p.drawLine(rcSymbol.right(), rcSymbol.top() + (rcSymbol.height() / 4), rcSymbol.right(), rcSymbol.top() + ((rcSymbol.height() / 4) * 3));
               p.drawLine(rcSymbol.right(), rcSymbol.top() + ((rcSymbol.height() / 4) * 3), rcSymbol.left() + ((rcSymbol.width() / 4) * 3), rcSymbol.bottom());
               p.drawLine(rcSymbol.left() + ((rcSymbol.width() / 4) * 3), rcSymbol.bottom(), rcSymbol.left() + (rcSymbol.width() / 4), rcSymbol.bottom());
               p.drawLine(rcSymbol.left() + (rcSymbol.width() / 4), rcSymbol.bottom(), rcSymbol.left(), rcSymbol.top() + ((rcSymbol.height() / 4) * 3));
               p.drawLine(rcSymbol.left(), rcSymbol.top() + ((rcSymbol.height() / 4) * 3), rcSymbol.left(), rcSymbol.top() + (rcSymbol.height() / 4));
               p.drawLine(rcSymbol.left(), rcSymbol.top() + (rcSymbol.height() / 4), rcSymbol.left() + (rcSymbol.width() / 4), rcSymbol.top());

               p.drawLine(rcSymbol.left(), rcSymbol.center().y(), rcSymbol.right(), rcSymbol.center().y());
               p.drawLine(rcSymbol.center().x(), rcSymbol.top(), rcSymbol.center().x(), rcSymbol.bottom());
               break;
         }

         p.end();
      }

      return selectedPix;
   }
   else if ((bSelected == false) && (pix.isNull() == false))
   {
      if ((pixColor != mColor) || (pixSymbol != mSymbol) ||
         (pixWidth != iWidth) || (pixHeight != iHeight))
      {
         pixColor = mColor;
         pixSymbol = mSymbol;
         pixWidth = iWidth;
         pixHeight = iHeight;
         pix.fill(Qt::transparent);

         QRect rcPix = pix.rect();

         int iSymbolMinX = rcPix.center().x() - iSymbolWidth / 2.0;
         int iSymbolMinY = rcPix.center().y() - iSymbolHeight / 2.0;
         QRect rcSymbol(iSymbolMinX, iSymbolMinY, iSymbolWidth, iSymbolHeight);

         QPainter p(&pix);
         p.setPen(QPen(mColor, 1));

         // Used with drawPolygon
         QPointF points[8];

         switch (mSymbol)
         {
            case Point::SOLID: default:
               p.fillRect(rcSymbol, mColor);
               break;

            case Point::X:
               p.drawLine(rcSymbol.topLeft(), rcSymbol.bottomRight());
               p.drawLine(rcSymbol.topRight(), rcSymbol.bottomLeft());
               break;

            case Point::CROSS_HAIR:
               p.drawLine(rcSymbol.left(), rcSymbol.center().y(), rcSymbol.right(),
                  rcSymbol.center().y());
               p.drawLine(rcSymbol.center().x(), rcSymbol.top(), rcSymbol.center().x(),
                  rcSymbol.bottom());
               break;

            case Point::ASTERISK:
               p.drawLine(rcSymbol.center().x(), rcSymbol.top(), rcSymbol.center().x(),
                  rcSymbol.bottom());
               p.drawLine(rcSymbol.left(), rcSymbol.top() + (rcSymbol.height() / 4), rcSymbol.right(),
                  rcSymbol.top() + ((rcSymbol.height() / 4) * 3));
               p.drawLine(rcSymbol.left(), rcSymbol.top() + ((rcSymbol.height() / 4) * 3),
                  rcSymbol.right(), rcSymbol.top() + (rcSymbol.height() / 4));
               break;

            case Point::VERTICAL_LINE:
               p.drawLine(rcSymbol.center().x(), rcSymbol.top(), rcSymbol.center().x(),
                  rcSymbol.bottom());
               break;

            case Point::HORIZONTAL_LINE:
               p.drawLine(rcSymbol.left(), rcSymbol.center().y(), rcSymbol.right(),
                  rcSymbol.center().y());
               break;

            case Point::FORWARD_SLASH:
               p.drawLine(rcSymbol.topRight(), rcSymbol.bottomLeft());
               break;

            case Point::BACK_SLASH:
               p.drawLine(rcSymbol.topLeft(), rcSymbol.bottomRight());
               break;

            case Point::BOX:
               p.drawRect(rcSymbol);
               break;

            case Point::BOXED_X:
               p.drawRect(rcSymbol);
               p.drawLine(rcSymbol.topLeft(), rcSymbol.bottomRight());
               p.drawLine(rcSymbol.topRight(), rcSymbol.bottomLeft());
               break;

            case Point::BOXED_CROSS_HAIR:
               p.drawRect(rcSymbol);
               p.drawLine(rcSymbol.left(), rcSymbol.center().y(), rcSymbol.right(),
                  rcSymbol.center().y());
               p.drawLine(rcSymbol.center().x(), rcSymbol.top(), rcSymbol.center().x(),
                  rcSymbol.bottom());
               break;

            case Point::BOXED_ASTERISK:
               p.drawRect(rcSymbol);
               p.drawLine(rcSymbol.center().x(), rcSymbol.top(), rcSymbol.center().x(),
                  rcSymbol.bottom());
               p.drawLine(rcSymbol.left(), rcSymbol.top() + (rcSymbol.height() / 4), rcSymbol.right(),
                  rcSymbol.top() + ((rcSymbol.height() / 4) * 3));
               p.drawLine(rcSymbol.left(), rcSymbol.top() + ((rcSymbol.height() / 4) * 3),
                  rcSymbol.right(), rcSymbol.top() + (rcSymbol.height() / 4));
               break;

            case Point::BOXED_VERTICAL_LINE:
               p.drawRect(rcSymbol);
               p.drawLine(rcSymbol.center().x(), rcSymbol.top(), rcSymbol.center().x(),
                  rcSymbol.bottom());
               break;

            case Point::BOXED_HORIZONTAL_LINE:
               p.drawRect(rcSymbol);
               p.drawLine(rcSymbol.left(), rcSymbol.center().y(), rcSymbol.right(),
                  rcSymbol.center().y());
               break;

            case Point::BOXED_FORWARD_SLASH:
               p.drawRect(rcSymbol);
               p.drawLine(rcSymbol.topRight(), rcSymbol.bottomLeft());
               break;

            case Point::BOXED_BACK_SLASH:
               p.drawRect(rcSymbol);
               p.drawLine(rcSymbol.topLeft(), rcSymbol.bottomRight());
               break;
            
            case Point::DIAMOND:
               p.drawLine(rcSymbol.center().x(), rcSymbol.top(), rcSymbol.right(), rcSymbol.center().y());
               p.drawLine(rcSymbol.right(), rcSymbol.center().y(), rcSymbol.center().x(), rcSymbol.bottom());
               p.drawLine(rcSymbol.center().x(), rcSymbol.bottom(), rcSymbol.left(), rcSymbol.center().y());
               p.drawLine(rcSymbol.left(), rcSymbol.center().y(), rcSymbol.center().x(), rcSymbol.top());
               break;

            case Point::DIAMOND_FILLED:
               p.setBrush(QBrush(Qt::SolidPattern));
               points[0] = QPointF(rcSymbol.center().x(), rcSymbol.top());
               points[1] = QPointF(rcSymbol.right(), rcSymbol.center().y());
               points[2] = QPointF(rcSymbol.center().x(), rcSymbol.bottom());
               points[3] = QPointF(rcSymbol.left(), rcSymbol.center().y());
               p.drawPolygon(points, 4);
               break;

            case Point::DIAMOND_CROSS_HAIR:
               p.drawLine(rcSymbol.center().x(), rcSymbol.top(), rcSymbol.right(), rcSymbol.center().y());
               p.drawLine(rcSymbol.right(), rcSymbol.center().y(), rcSymbol.center().x(), rcSymbol.bottom());
               p.drawLine(rcSymbol.center().x(), rcSymbol.bottom(), rcSymbol.left(), rcSymbol.center().y());
               p.drawLine(rcSymbol.left(), rcSymbol.center().y(), rcSymbol.center().x(), rcSymbol.top());

               p.drawLine(rcSymbol.left(), rcSymbol.center().y(), rcSymbol.right(), rcSymbol.center().y());
               p.drawLine(rcSymbol.center().x(), rcSymbol.top(), rcSymbol.center().x(), rcSymbol.bottom());
               break;

            case Point::TRIANGLE:
               p.drawLine(rcSymbol.center().x(), rcSymbol.top(), rcSymbol.right(), rcSymbol.bottom());
               p.drawLine(rcSymbol.bottomRight(), rcSymbol.bottomLeft());
               p.drawLine(rcSymbol.left(), rcSymbol.bottom(), rcSymbol.center().x(), rcSymbol.top());
               break;

            case Point::TRIANGLE_FILLED:
               p.setBrush(QBrush(Qt::SolidPattern));
               points[0] = QPointF(rcSymbol.center().x(), rcSymbol.top());
               points[1] = QPointF(rcSymbol.right(), rcSymbol.bottom());
               points[2] = QPointF(rcSymbol.left(), rcSymbol.bottom());
               p.drawPolygon(points, 3);
               break;

            case Point::RIGHT_TRIANGLE:
               p.drawLine(rcSymbol.left(), rcSymbol.top(), rcSymbol.right(), rcSymbol.center().y());
               p.drawLine(rcSymbol.right(), rcSymbol.center().y(), rcSymbol.left(), rcSymbol.bottom());
               p.drawLine(rcSymbol.left(), rcSymbol.bottom(), rcSymbol.left(), rcSymbol.top());
               break;

            case Point::RIGHT_TRIANGLE_FILLED:
               p.setBrush(QBrush(Qt::SolidPattern));
               points[0] = QPointF(rcSymbol.left(), rcSymbol.top());
               points[1] = QPointF(rcSymbol.right(), rcSymbol.center().y());
               points[2] = QPointF(rcSymbol.left(), rcSymbol.bottom());
               p.drawPolygon(points, 3);
               break;

            case Point::LEFT_TRIANGLE:
               p.drawLine(rcSymbol.right(), rcSymbol.top(), rcSymbol.right(), rcSymbol.bottom());
               p.drawLine(rcSymbol.right(), rcSymbol.bottom(), rcSymbol.left(), rcSymbol.center().y());
               p.drawLine(rcSymbol.left(), rcSymbol.center().y(), rcSymbol.right(), rcSymbol.top());
               break;

            case Point::LEFT_TRIANGLE_FILLED:
               p.setBrush(QBrush(Qt::SolidPattern));
               points[0] = QPointF(rcSymbol.right(), rcSymbol.top());
               points[1] = QPointF(rcSymbol.right(), rcSymbol.bottom());
               points[2] = QPointF(rcSymbol.left(), rcSymbol.center().y());
               p.drawPolygon(points, 3);
               break;

            case Point::DOWN_TRIANGLE:
               p.drawLine(rcSymbol.topLeft(), rcSymbol.topRight());
               p.drawLine(rcSymbol.right(), rcSymbol.top(), rcSymbol.center().x(), rcSymbol.bottom());
               p.drawLine(rcSymbol.center().x(), rcSymbol.bottom(), rcSymbol.left(), rcSymbol.top());
               break;

            case Point::DOWN_TRIANGLE_FILLED:
               p.setBrush(QBrush(Qt::SolidPattern));
               points[0] = QPointF(rcSymbol.left(), rcSymbol.top());
               points[1] = QPointF(rcSymbol.right(), rcSymbol.top());
               points[2] = QPointF(rcSymbol.center().x(), rcSymbol.bottom());
               p.drawPolygon(points, 3);
               break;

            case Point::CIRCLE:
               p.drawEllipse(rcSymbol);
               break;

            case Point::CIRCLE_FILLED:
               p.setBrush(QBrush(Qt::SolidPattern));
               p.drawEllipse(rcSymbol);
               break;

            case Point::OCTAGON:
               p.drawLine(rcSymbol.left() + (rcSymbol.width() / 4), rcSymbol.top(), rcSymbol.left() + ((rcSymbol.width() / 4) * 3), rcSymbol.top());
               p.drawLine(rcSymbol.left() + ((rcSymbol.width() / 4) * 3), rcSymbol.top(), rcSymbol.right(), rcSymbol.top() + (rcSymbol.height() / 4));
               p.drawLine(rcSymbol.right(), rcSymbol.top() + (rcSymbol.height() / 4), rcSymbol.right(), rcSymbol.top() + ((rcSymbol.height() / 4) * 3));
               p.drawLine(rcSymbol.right(), rcSymbol.top() + ((rcSymbol.height() / 4) * 3), rcSymbol.left() + ((rcSymbol.width() / 4) * 3), rcSymbol.bottom());
               p.drawLine(rcSymbol.left() + ((rcSymbol.width() / 4) * 3), rcSymbol.bottom(), rcSymbol.left() + (rcSymbol.width() / 4), rcSymbol.bottom());
               p.drawLine(rcSymbol.left() + (rcSymbol.width() / 4), rcSymbol.bottom(), rcSymbol.left(), rcSymbol.top() + ((rcSymbol.height() / 4) * 3));
               p.drawLine(rcSymbol.left(), rcSymbol.top() + ((rcSymbol.height() / 4) * 3), rcSymbol.left(), rcSymbol.top() + (rcSymbol.height() / 4));
               p.drawLine(rcSymbol.left(), rcSymbol.top() + (rcSymbol.height() / 4), rcSymbol.left() + (rcSymbol.width() / 4), rcSymbol.top());
               break;

            case Point::OCTAGON_FILLED:
               p.setBrush(QBrush(Qt::SolidPattern));
               points[0] = QPointF(rcSymbol.left() + (rcSymbol.width() / 4), rcSymbol.top());
               points[1] = QPointF(rcSymbol.left() + ((rcSymbol.width() / 4) * 3), rcSymbol.top());
               points[2] = QPointF(rcSymbol.right(), rcSymbol.top() + (rcSymbol.height() / 4));
               points[3] = QPointF(rcSymbol.right(), rcSymbol.top() + ((rcSymbol.height() / 4) * 3));
               points[4] = QPointF(rcSymbol.left() + ((rcSymbol.width() / 4) * 3), rcSymbol.bottom());
               points[5] = QPointF(rcSymbol.left() + (rcSymbol.width() / 4), rcSymbol.bottom());
               points[6] = QPointF(rcSymbol.left(), rcSymbol.top() + ((rcSymbol.height() / 4) * 3));
               points[7] = QPointF(rcSymbol.left(), rcSymbol.top() + (rcSymbol.height() / 4));
               p.drawPolygon(points, 8);
               break;

            case Point::OCTAGON_CROSS_HAIR:
               p.drawLine(rcSymbol.left() + (rcSymbol.width() / 4), rcSymbol.top(), rcSymbol.left() + ((rcSymbol.width() / 4) * 3), rcSymbol.top());
               p.drawLine(rcSymbol.left() + ((rcSymbol.width() / 4) * 3), rcSymbol.top(), rcSymbol.right(), rcSymbol.top() + (rcSymbol.height() / 4));
               p.drawLine(rcSymbol.right(), rcSymbol.top() + (rcSymbol.height() / 4), rcSymbol.right(), rcSymbol.top() + ((rcSymbol.height() / 4) * 3));
               p.drawLine(rcSymbol.right(), rcSymbol.top() + ((rcSymbol.height() / 4) * 3), rcSymbol.left() + ((rcSymbol.width() / 4) * 3), rcSymbol.bottom());
               p.drawLine(rcSymbol.left() + ((rcSymbol.width() / 4) * 3), rcSymbol.bottom(), rcSymbol.left() + (rcSymbol.width() / 4), rcSymbol.bottom());
               p.drawLine(rcSymbol.left() + (rcSymbol.width() / 4), rcSymbol.bottom(), rcSymbol.left(), rcSymbol.top() + ((rcSymbol.height() / 4) * 3));
               p.drawLine(rcSymbol.left(), rcSymbol.top() + ((rcSymbol.height() / 4) * 3), rcSymbol.left(), rcSymbol.top() + (rcSymbol.height() / 4));
               p.drawLine(rcSymbol.left(), rcSymbol.top() + (rcSymbol.height() / 4), rcSymbol.left() + (rcSymbol.width() / 4), rcSymbol.top());

               p.drawLine(rcSymbol.left(), rcSymbol.center().y(), rcSymbol.right(), rcSymbol.center().y());
               p.drawLine(rcSymbol.center().x(), rcSymbol.top(), rcSymbol.center().x(), rcSymbol.bottom());
               break;         
         }

         p.end();
      }

      return pix;
   }

   return PlotObjectImp::getLegendPixmap(bSelected);
}
예제 #13
0
void WindowsModernStyle::drawControl( ControlElement element, const QStyleOption* option,
                                      QPainter* painter, const QWidget* widget ) const
{
    switch ( element ) {
    case CE_MenuBarEmptyArea:
        return;

    case CE_MenuBarItem:
        if ( option->state & QStyle::State_Sunken && option->state & QStyle::State_Enabled ) {
            painter->setPen( m_colorMenuBorder );
            QLinearGradient gradient( option->rect.topLeft(), option->rect.bottomLeft() );
            gradient.setColorAt( 0.0, m_colorMenuTitleBegin );
            gradient.setColorAt( 1.0, m_colorMenuTitleEnd );
            painter->setBrush( gradient );
            painter->drawRect( option->rect.adjusted( 0, 0, -1, 0 ) );
        } else if ( option->state & QStyle::State_Selected && option->state & QStyle::State_Enabled ) {
            painter->setPen( m_colorItemBorder );
            QLinearGradient gradient( option->rect.topLeft(), option->rect.bottomLeft() );
            gradient.setColorAt( 0.0, m_colorItemBackgroundBegin );
            gradient.setColorAt( 1.0, m_colorItemBackgroundEnd );
            painter->setBrush( gradient );
            painter->drawRect( option->rect.adjusted( 0, 0, -1, -1 ) );
        }
        if ( const QStyleOptionMenuItem* optionItem = qstyleoption_cast<const QStyleOptionMenuItem*>( option ) ) {
            int flags = Qt::AlignCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
            if ( !styleHint( SH_UnderlineShortcut, option, widget ) )
                flags |= Qt::TextHideMnemonic;
            if ( !optionItem->icon.isNull() ) {
                QPixmap pixmap = optionItem->icon.pixmap( pixelMetric( PM_SmallIconSize, option, widget ), QIcon::Normal );
                drawItemPixmap( painter, option->rect, flags, pixmap );
            } else {
                drawItemText( painter, option->rect, flags, option->palette, true, optionItem->text, QPalette::Text );
            }
        }
        return;

    case CE_MenuEmptyArea:
        painter->fillRect( option->rect, m_colorMenuBackground );
        return;

    case CE_MenuItem: {
        if ( option->state & QStyle::State_Selected && option->state & QStyle::State_Enabled ) {
            painter->setPen( m_colorItemBorder );
            painter->setBrush( m_colorItemBackgroundBegin );
            painter->drawRect( option->rect.adjusted( 1, 0, -3, -1 ) );
        } else {
            QLinearGradient gradient( QPoint( 0, 0 ), QPoint( 25, 0 ) );
            gradient.setColorAt( 0.0, m_colorBarBegin );
            gradient.setColorAt( 1.0, m_colorBarEnd );
            QRect margin = option->rect;
            margin.setWidth( 25 );
            painter->fillRect( margin, gradient );
            QRect background = option->rect;
            background.setLeft( margin.right() + 1 );
            painter->fillRect( background, m_colorMenuBackground );
        }
        if ( const QStyleOptionMenuItem* optionItem = qstyleoption_cast<const QStyleOptionMenuItem*>( option ) ) {
            if ( optionItem->menuItemType == QStyleOptionMenuItem::Separator ) {
                painter->setPen( m_colorSeparator );
                painter->drawLine( option->rect.left() + 32, ( option->rect.top() + option->rect.bottom() ) / 2,
                                   option->rect.right(), ( option->rect.top() + option->rect.bottom() ) / 2 );
                return;
            }
            QRect checkRect = option->rect.adjusted( 2, 1, -2, -2 );
            checkRect.setWidth( 20 );
            if ( optionItem->checked && option->state & QStyle::State_Enabled ) {
                painter->setPen( m_colorItemBorder );
                if ( option->state & QStyle::State_Selected && option->state & QStyle::State_Enabled )
                    painter->setBrush( m_colorItemSunkenBegin );
                else
                    painter->setBrush( m_colorItemCheckedBegin );
                painter->drawRect( checkRect );
            }
            if ( !optionItem->icon.isNull() ) {
                QIcon::Mode mode;
                if ( optionItem->state & State_Enabled )
                    mode = ( optionItem->state & State_Selected ) ? QIcon::Active : QIcon::Normal;
                else
                    mode = QIcon::Disabled;
                QIcon::State state = optionItem->checked ? QIcon::On : QIcon::Off;
                QPixmap pixmap = optionItem->icon.pixmap( pixelMetric( PM_SmallIconSize, option, widget ), mode, state );
                QRect rect = pixmap.rect();
                rect.moveCenter( checkRect.center() );
                painter->drawPixmap( rect.topLeft(), pixmap );
            } else if ( optionItem->checked ) {
                QStyleOption optionCheckMark;
                optionCheckMark.initFrom( widget );
                optionCheckMark.rect = checkRect;
                if ( !( option->state & State_Enabled ) )
                    optionCheckMark.palette.setBrush( QPalette::Text, optionCheckMark.palette.brush( QPalette::Disabled, QPalette::Text ) );
                drawPrimitive( PE_IndicatorMenuCheckMark, &optionCheckMark, painter, widget );
            }
            QRect textRect = option->rect.adjusted( 32, 1, -16, -1 );
            int flags = Qt::AlignVCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
            if ( !styleHint( SH_UnderlineShortcut, option, widget ) )
                flags |= Qt::TextHideMnemonic;
            QString text = optionItem->text;
            int pos = text.indexOf( '\t' );
            if ( pos >= 0 ) {
                drawItemText( painter, textRect, flags | Qt::AlignRight, option->palette, option->state & State_Enabled,
                              text.mid( pos + 1 ), QPalette::Text );
                text = text.left( pos );
            }
            drawItemText( painter, textRect, flags, option->palette, option->state & State_Enabled, text, QPalette::Text );
            if ( optionItem->menuItemType == QStyleOptionMenuItem::SubMenu ) {
                QStyleOption optionArrow;
                optionArrow.initFrom( widget );
                optionArrow.rect = option->rect.adjusted( 0, 4, -4, -4 );
                optionArrow.rect.setLeft( option->rect.right() - 12 );
                optionArrow.state = option->state & State_Enabled;
                drawPrimitive( PE_IndicatorArrowRight, &optionArrow, painter, widget );
            }
        }
        return;
    }

    case CE_ToolBar: {
        QRect rect = option->rect;
        bool vertical = false;
        if ( const QToolBar* toolBar = qobject_cast<const QToolBar*>( widget ) ) {
            vertical = ( toolBar->orientation() == Qt::Vertical );
            if ( vertical )
                rect.setBottom( toolBar->childrenRect().bottom() + 2 );
            else
                rect.setRight( toolBar->childrenRect().right() + 2 );
        }
        painter->save();
        QRegion region = rect.adjusted( 2, 0, -2, 0 );
        region += rect.adjusted( 0, 2, 0, -2 );
        region += rect.adjusted( 1, 1, -1, -1 );
        painter->setClipRegion( region );
        QLinearGradient gradient;
        if ( vertical )
            gradient = QLinearGradient( rect.topLeft(), rect.topRight() );
        else
            gradient = QLinearGradient( rect.topLeft(), rect.bottomLeft() );
        gradient.setColorAt( 0.0, m_colorBarBegin );
        gradient.setColorAt( 0.4, m_colorBarMiddle );
        gradient.setColorAt( 0.6, m_colorBarMiddle );
        gradient.setColorAt( 1.0, m_colorBarEnd );
        painter->fillRect( rect, gradient );

        painter->setPen( vertical ? m_colorBorderLight : m_colorBorder );
        painter->drawLine( rect.bottomLeft() + QPoint( 2, 0 ), rect.bottomRight() - QPoint( 2, 0 ) );
        painter->setPen( vertical ? m_colorBorder : m_colorBorderLight );
        painter->drawLine( rect.topRight() + QPoint( 0, 2 ), rect.bottomRight() - QPoint( 0, 2 ) );
        painter->setPen( m_colorBorderLight );
        painter->drawPoint( rect.bottomRight() - QPoint( 1, 1 ) );
        painter->restore();
        return;
    }

    case CE_DockWidgetTitle: {
        QLinearGradient gradient( option->rect.topLeft(), option->rect.bottomLeft() );
        gradient.setColorAt( 0.0, m_colorBarBegin );
        gradient.setColorAt( 1.0, m_colorBarEnd );
        painter->fillRect( option->rect, gradient );
        if ( const QStyleOptionDockWidget* optionDockWidget = qstyleoption_cast<const QStyleOptionDockWidget*>( option ) ) {
            QRect rect = option->rect.adjusted( 6, 0, -4, 0 );
            if ( optionDockWidget->closable )
                rect.adjust( 0, 0, -16, 0 );
            if ( optionDockWidget->floatable )
                rect.adjust( 0, 0, -16, 0 );
            QString text = painter->fontMetrics().elidedText( optionDockWidget->title, Qt::ElideRight, rect.width() );
            drawItemText( painter, rect, Qt::AlignLeft | Qt::AlignVCenter, option->palette,
                          option->state & State_Enabled, text, QPalette::WindowText );
        }
        return;
    }

    case CE_TabBarTabShape:
        if ( isStyledTabBar( widget ) ) {
            bool firstTab = false;
            bool lastTab = false;
            bool bottom = false;
            if ( const QStyleOptionTab* optionTab = qstyleoption_cast<const QStyleOptionTab*>( option ) ) {
                if ( optionTab->position == QStyleOptionTab::Beginning )
                    firstTab = true;
                else if ( optionTab->position == QStyleOptionTab::End )
                    lastTab = true;
                else if ( optionTab->position == QStyleOptionTab::OnlyOneTab )
                    firstTab = lastTab = true;
                if ( optionTab->shape == QTabBar::RoundedSouth )
                    bottom = true;
            }
            QRect rect = option->rect;
            painter->save();
            if ( option->state & State_Selected ) {
                if ( bottom )
                    rect.adjust( firstTab ? 0 : -2, -1, lastTab ? -1 : 1, -1 );
                else
                    rect.adjust( firstTab ? 0 : -2, 0, lastTab ? -1 : 1, 1 );
            } else {
                if ( bottom ) {
                    rect.adjust( 0, -1, lastTab ? -1 : 0, -2 );
                    painter->setClipRect( rect.adjusted( 0, 1, 1, 1 ) );
                } else {
                    rect.adjust( 0, 1, lastTab ? -1 : 0, 0 );
                    painter->setClipRect( rect.adjusted( 0, 0, 1, 0 ) );
                }
            }
            QLinearGradient gradient;
            if ( bottom )
                gradient = QLinearGradient( rect.bottomLeft(), rect.topLeft() );
            else
                gradient = QLinearGradient( rect.topLeft(), rect.bottomLeft() );
            if ( option->state & State_Selected ) {
                gradient.setColorAt( 0.0, m_colorItemBackgroundBegin );
                gradient.setColorAt( 1.0, option->palette.window().color() );
                painter->setPen( m_colorBorder );
            } else if ( option->state & State_MouseOver && option->state & State_Enabled ) {
                gradient.setColorAt( 0.0, m_colorItemBackgroundBegin );
                gradient.setColorAt( 1.0, m_colorItemBackgroundEnd );
                painter->setPen( m_colorBorderLight );
            } else {
                gradient.setColorAt( 0.0, m_colorBarMiddle );
                gradient.setColorAt( 1.0, m_colorBarEnd );
                painter->setPen( m_colorBorderLight );
            }
            painter->setBrush( gradient );
            painter->drawRect( rect );
            painter->restore();
            return;
        }
        break;

    case CE_ToolBoxTabShape: {
        QRect rect = option->rect.adjusted( 0, 0, -1, -1 );
        QLinearGradient gradient( rect.topLeft(), rect.bottomLeft() );
        if ( option->state & QStyle::State_Sunken ) {
            gradient.setColorAt( 0.0, m_colorItemSunkenBegin );
            gradient.setColorAt( 1.0, m_colorItemSunkenEnd );
            painter->setPen( m_colorBorder );
        } else if ( option->state & State_MouseOver && option->state & State_Enabled ) {
            gradient.setColorAt( 0.0, m_colorItemBackgroundBegin );
            gradient.setColorAt( 1.0, m_colorItemBackgroundEnd );
            painter->setPen( m_colorBorder );
        } else {
            gradient.setColorAt( 0.0, m_colorBarMiddle );
            gradient.setColorAt( 1.0, m_colorBarEnd );
            painter->setPen( m_colorBorderLight );
        }
        painter->setBrush( gradient );
        painter->drawRect( rect );
        return;
    }

    case CE_Splitter:
        if ( qobject_cast<const QMainWindow*>( widget->window() ) )
            return;
        break;

    default:
        break;
    }

    if ( useVista() )
        QWindowsVistaStyle::drawControl( element, option, painter, widget );
    else
        QWindowsXPStyle::drawControl( element, option, painter, widget );
}
예제 #14
0
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
** $QT_END_LICENSE$
**
****************************************************************************/

//! [0]
static const char * const start_xpm[]={
    "16 15 8 1",
    "a c #cec6bd",
....
//! [0]


//! [1]
QPixmap myPixmap;
myPixmap->setMask(myPixmap->createHeuristicMask());
//! [1]

//! [2]
QPixmap pixmap("background.png");
QRegion exposed;
pixmap.scroll(10, 10, pixmap.rect(), &exposed);
//! [2]
예제 #15
0
void MainWindow::on_actionGray_world_triggered()
{
    QPixmap pixmap = pixmapItem->pixmap().copy();

    QImage image = pixmap.toImage();
    int width = image.width();
    int height = image.height();

    if (width == 0 || height == 0)
    {
        ui->statusBar->showMessage( tr("Error. Image bad size"), 3000 );
        return;
    }

    double avgRed = 0.0;
    double avgGreen = 0.0;
    double avgBlue = 0.0;
    for (int y = 0; y < height; ++y)
        for (int x = 0; x < width; ++x)
        {
            QRgb oldColor = image.pixel(x, y);
            avgRed += qRed(oldColor);
            avgGreen += qGreen(oldColor);
            avgBlue += qBlue(oldColor);
        }

    int length = width * height;
    avgRed /= length;
    avgGreen /= length;
    avgBlue /= length;
    double avg = (avgRed + avgGreen + avgBlue) / 3;

    for (int y = 0; y < height; ++y)
        for (int x = 0; x < width; ++x)
        {
            QRgb oldColor = image.pixel(x, y);
            double red = qRed(oldColor) * avg / avgRed;
            double green = qGreen(oldColor) * avg / avgGreen;
            double blue = qBlue(oldColor) * avg / avgBlue;
            if (red < 0)
                red = 0;
            if (red > 255)
                red = 255;
            if (green < 0)
                green = 0;
            if (green > 255)
                green = 255;
            if (blue < 0)
                blue = 0;
            if (blue > 255)
                blue = 255;
            image.setPixel(x, y, qRgb(red, green, blue));
        }

    pixmap.convertFromImage(image);

    pixmapItem_2->setPixmap(pixmap);
    scene_2->setSceneRect(QRectF(pixmap.rect()));

    calcHist(pixmap, hist_2, maxLevel_2);
    drawHist(pixmapItem_4, hist_2, maxLevel_2);
}
예제 #16
0
void BoardDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    // Проверки
    if (!index.isValid())
        return;
    int row = index.row();
    if (row <= 0 || row >= model_->rowCount() - 1)
        return;
    int col = index.column();
    if (col <= 0 || col >= model_->columnCount() - 1)
        return;
    painter->save();
    QRectF rect(option.rect);
    // Отрисовка фона
    if (skin == 0) {
        QBrush fill_brush(QColor(220, 179, 92, 255), Qt::SolidPattern);
        painter->fillRect(rect, fill_brush);
    } else {
        QPixmap *pixmap = pixmaps->getBoardPixmap(col - 1, row - 1, rect.width(), rect.height());
        painter->drawPixmap(rect, *pixmap, pixmap->rect());
    }
    QBrush brush1(Qt::SolidPattern);
    int row_min = 2;
    int row_max = model_->rowCount() - 3;
    int col_min = 2;
    int col_max = model_->columnCount() - 3;
    if (row >= row_min && row <= row_max && col >= col_min && col <= col_max) {
        // Отрисовка центральных линий
        qreal x = rect.left() + rect.width() / 2.0;
        qreal y = rect.top() + rect.height() / 2.0;
        painter->setPen(Qt::darkGray);
        painter->drawLine(rect.left(), y - 1, rect.right(), y - 1);
        painter->drawLine(x - 1, rect.top(), x - 1, rect.bottom());
        painter->setPen(Qt::lightGray);
        painter->drawLine(rect.left(), y, rect.right(), y);
        painter->drawLine(x, rect.top(), x, rect.bottom());
        // Отрисовка разделителя
        if (row == row_min || col == col_min || row == row_max || col == col_max) {
            painter->setPen(Qt::black);
            if (row == row_min) {
                painter->drawLine(rect.topLeft(), rect.topRight());
            } else if (row == row_max) {
                QPointF p1 = rect.bottomLeft();
                p1.setY(p1.y() - 1.0);
                QPointF p2 = rect.bottomRight();
                p2.setY(p2.y() - 1.0);
                painter->drawLine(p1, p2);
            }
            if (col == col_min) {
                painter->drawLine(rect.topLeft(), rect.bottomLeft());
            } else if (col == col_max) {
                QPointF p1 = rect.topRight();
                p1.setX(p1.x() - 1);
                QPointF p2 = rect.bottomRight();
                p2.setX(p2.x() - 1);
                painter->drawLine(p1, p2);
            }
        }
        if (model_->selectX == col && model_->selectY == row) {
            brush1.setColor(QColor(0, 255, 0, 64));
            painter->fillRect(rect, brush1);
        }
        // Отрисовка если курсор мыши над клеткой
        if (option.state & QStyle::State_MouseOver) {
            brush1.setColor(QColor(0, 0, 0, 32));
            painter->fillRect(rect, brush1);
        }
        rect.setWidth(rect.width() - 1);
        rect.setHeight(rect.height() - 1);
        // Отрисовка если клетка выбрана
        if (option.state & QStyle::State_Selected) {
            QRectF rect2(rect);
            rect2.setLeft(rect2.left() + 1);
            rect2.setTop(rect2.top() + 1);
            rect2.setWidth(rect2.width() - 1);
            rect2.setHeight(rect2.height() - 1);
            painter->setPen(Qt::gray);
            painter->drawRect(rect2);
        }
        // Отрисовка элемента
        const GameElement *el = model_->getGameElement(col, row);
        if (el) {
            el->paint(painter, rect);
        }
    } else {
        // Рисуем координаты
        if ((row == 1 || row == model_->columnCount() - 2) && col >= 2 && col <= model_->columnCount() - 3) {
            // Буквы
            QString text = horHeaderString.at(col - 2);
            painter->drawText(rect, Qt::AlignCenter,text, nullptr);
        } else if ((col == 1 || model_->rowCount() - 2) && row >= 2 && row <= model_->rowCount() - 3) {
            // Цифры
            QString text = QString::number(row - 1);
            painter->drawText(rect, Qt::AlignCenter,text, nullptr);
        }
    }
    painter->restore();
}
예제 #17
0
void MainWindow::on_actionLinear_triggered()
{
    QPixmap pixmap = pixmapItem->pixmap().copy();

    QImage image = pixmap.toImage();
    int width = image.width();
    int height = image.height();

    if (width == 0 || height == 0)
    {
        ui->statusBar->showMessage( tr("Error. Image bad size"), 3000 );
        return;
    }

    int minR = 256;
    int maxR = -1;
    int minG = 256;
    int maxG = -1;
    int minB = 256;
    int maxB = -1;

    for (int y = 0; y < height; ++y)
        for (int x = 0; x < width; ++x)
        {
            QRgb oldColor = image.pixel(x, y);
            int red = qRed(oldColor);
            int green = qGreen(oldColor);
            int blue = qBlue(oldColor);
            if (red < minR)
                minR = red;
            if (red > maxR)
                maxR = red;
            if (green < minG)
                minG = green;
            if (green > maxG)
                maxG = green;
            if (blue < minB)
                minB = blue;
            if (blue > maxB)
                maxB = blue;
        }

    for (int y = 0; y < height; ++y)
        for (int x = 0; x < width; ++x)
        {
            QRgb oldColor = image.pixel(x, y);
            int red = ( qRed(oldColor) - minR) * 255 / (maxR - minR);
            int green = ( qGreen(oldColor) - minG) * 255 / (maxG - minG);
            int blue = ( qBlue(oldColor) - minB) * 255 / (maxB - minB);
            if (red < 0)
                red = 0;
            if (red > 255)
                red = 255;
            if (green < 0)
                green = 0;
            if (green > 255)
                green = 255;
            if (blue < 0)
                blue = 0;
            if (blue > 255)
                blue = 255;
            image.setPixel(x, y, qRgb(red, green, blue));
        }

    pixmap.convertFromImage(image);

    pixmapItem_2->setPixmap(pixmap);
    scene_2->setSceneRect(QRectF(pixmap.rect()));

    calcHist(pixmap, hist_2, maxLevel_2);
    drawHist(pixmapItem_4, hist_2, maxLevel_2);
}
예제 #18
0
//--------------------------------------------------------------------------------------------
void MGyrohorizon::paintEvent(QPaintEvent * event)
{
//--
  QImage imgagePaint(size(), QImage::Format_ARGB32_Premultiplied);
  QPainter painter;
  painter.begin(&imgagePaint);
//--

  painter.setRenderHint(QPainter::Antialiasing, true);

  QLinearGradient linearGrad;
  QPointF mpointsF[5];
  qreal yh;

//=============================

  bool isUpDawn = false;
  while(PitchAngle < -90.0)
  {
    PitchAngle += 180.0;
    isUpDawn = !isUpDawn; //true;
  }
  while(PitchAngle > 90.0)
  {
    PitchAngle -= 180.0;
    isUpDawn = !isUpDawn; //true;
  }


  if(isUpDawn)
  {
      RollAngle += 180.0;

  }
  while(RollAngle < -180.0)
  {
    RollAngle += 360.0;
  }
  while(RollAngle > 180.0)
  {
     RollAngle -= 360.0;
  }


  qreal hPitchAngle = HeightHalf/AngleHeightHalf*PitchAngle;//здвиг по пикселям в соответсвии с градусами
  if(isUpDawn) {
    hPitchAngle = -hPitchAngle;
  }


  painter.translate(WidthHalf,HeightHalf);//переместили цент с 0,0 на центр
  painter.rotate(-RollAngle);

//=====  Pitch:  =====
  painter.setPen(Qt::NoPen);


//-Sky:

// 0:
  yh = hPitchAngle;
  linearGrad.setStart(0.0,     yh);
  linearGrad.setFinalStop(0.0, yh-H1);
  linearGrad.setColorAt(0, ColorSky0);
  linearGrad.setColorAt(1, ColorSky1);
  QBrush brushSky1(linearGrad);   painter.setBrush(brushSky1);
  painter.drawRect(-MaxDimHalf,yh+0.5, MaxDim,-H1-2.0);//первый верхний четерехугольник

  yh -= H1;
  linearGrad.setStart(0.0,     yh);
  linearGrad.setFinalStop(0.0, yh-H2);
  linearGrad.setColorAt(0, ColorSky1);
  linearGrad.setColorAt(1, ColorSky2);
  QBrush brushSky2(linearGrad);   painter.setBrush(brushSky2);
  painter.drawRect(QRectF(-MaxDimHalf,yh, MaxDim,-H2-2.0));

//90
  yh -= H2;
  linearGrad.setStart(0.0,     yh);
  linearGrad.setFinalStop(0.0, yh-H2);
  linearGrad.setColorAt(0, ColorSky2);
  linearGrad.setColorAt(1, ColorSky1);
  QBrush brushSky3(linearGrad);   painter.setBrush(brushSky3);
  painter.drawRect(QRectF(-MaxDimHalf,yh, MaxDim,-H2-2.0));

  yh -= H2;
  linearGrad.setStart(0.0,     yh);
  linearGrad.setFinalStop(0.0, yh-H1);
  linearGrad.setColorAt(0, ColorSky1);
  linearGrad.setColorAt(1, ColorSky0);
  QBrush brushSky4(linearGrad);   painter.setBrush(brushSky4);
  painter.drawRect(QRectF(-MaxDimHalf,yh+0.5, MaxDim,-H1-2.0));

//180

//-Ground:

// 0:
  yh = hPitchAngle;
  linearGrad.setStart(0.0,     yh);
  linearGrad.setFinalStop(0.0, yh+H1);
  linearGrad.setColorAt(0, ColorGround0);
  linearGrad.setColorAt(1, ColorGround1);
  QBrush brushGround1(linearGrad);   painter.setBrush(brushGround1);
  painter.drawRect(QRectF(-MaxDimHalf,yh-0.5, MaxDim,H1+2.0));

  yh += H1;
  linearGrad.setStart(0.0,     yh);
  linearGrad.setFinalStop(0.0, yh+H2);
  linearGrad.setColorAt(0, ColorGround1);
  linearGrad.setColorAt(1, ColorGround2);
  QBrush brushGround2(linearGrad);   painter.setBrush(brushGround2);
  painter.drawRect(QRectF(-MaxDimHalf,yh, MaxDim,H2+2.0));

//90:
  yh += H2;
  linearGrad.setStart(0.0,     yh);
  linearGrad.setFinalStop(0.0, yh+H2);
  linearGrad.setColorAt(0, ColorGround2);
  linearGrad.setColorAt(1, ColorGround1);
  QBrush brushGround3(linearGrad);   painter.setBrush(brushGround3);
  painter.drawRect(QRectF(-MaxDimHalf,yh, MaxDim,H2+2.0));

  yh += H2;
  linearGrad.setStart(0.0,     yh);
  linearGrad.setFinalStop(0.0, yh+H1);
  linearGrad.setColorAt(0, ColorGround1);
  linearGrad.setColorAt(1, ColorGround0);
  QBrush brushGround4(linearGrad);   painter.setBrush(brushGround4);
  painter.drawRect(QRectF(-MaxDimHalf,yh, MaxDim,H1+2));
//180

//== Pitch Scale:

  QPen pen(ColorPitch);  pen.setWidthF(1.0);
  painter.setPen(pen);

  QVector<QLineF> lines;

//- (2)-degrees:
  qreal y;  bool isHas = false;
  for(int k = -1; k <= 1; k += 2)
  {
    y = hPitchAngle;
    while(y >=   2.0*(H1+H2)-2.0*HeightHalfVisible)  { y -= 2.0*(H1+H2); }
    while(y <= -(2.0*(H1+H2)-2.0*HeightHalfVisible)) { y += 2.0*(H1+H2); }
    for(int i = 1; i <= 4; i++)
    {
      y += -2.0*HOneDegreeAngle*k;
      if(qAbs(y) <= HeightHalfVisible)
      {
        isHas = true;
        lines << QLineF(-8.0,y, 8.0,y);
      }
    }
  }
  if(isHas)  painter.drawLines(lines);
  lines.clear();

  pen.setWidthF(1.5);   painter.setPen(pen);

  qreal xoff, yoff;
  qreal angle;

//- 10-degrees:
  mpointsF[0].setX(-24.0);
  mpointsF[1].setX(-24.0);
  mpointsF[2].setX(24.0);
  mpointsF[3].setX(24.0);
  for(int k = -1; k <= 1; k += 2)
  {
    for(int i = 0; i <= 9; i++)
    {
      angle = 10.0*i;
      y = hPitchAngle - angle*HOneDegreeAngle*k;
      while(y >=   2.0*(H1+H2)-2.0*HeightHalfVisible)  { y -= 2.0*(H1+H2); }
      while(y <= -(2.0*(H1+H2)-2.0*HeightHalfVisible)) { y += 2.0*(H1+H2); }
      if(qAbs(y) <= HeightHalfVisible)
      {
        if(i == 0)
        {
          painter.drawLine(QLineF(-48.0,y, 48.0,y));
        }
        else if(i < 9)
        {
          mpointsF[0].setY(y + 5.0*k);
          mpointsF[1].setY(y);
          mpointsF[2].setY(y);
          mpointsF[3].setY(y + 5.0*k);
          painter.drawPolyline(mpointsF, 4); //int pointCount)
          DrawText(painter, -24.0-12.0+0.5, y+5.0/2.0*k, angle);
          DrawText(painter,  24.0+12.0+1.0, y+5.0/2.0*k, angle);
        }
        else
        {
          lines << QLineF(-36.0,y-7.0, -36.0,y+7.0);
          lines << QLineF(-36.0,y,      36.0,y);
          lines << QLineF( 36.0,y-7.0,  36.0,y+7.0);
          painter.drawLines(lines);  lines.clear();
          DrawText(painter, -36.0-12.0+1.0, y, angle);
          DrawText(painter,  36.0+12.0+1.0, y, angle);
        }
      }
    }

  }
//- (15)-degrees:
  for(int k = -1; k <= 1; k += 2) {
    y = hPitchAngle - 10.0*HOneDegreeAngle*(1.0+0.5)*k;
    while(y >=   2.0*(H1+H2)-2.0*HeightHalfVisible)  { y -= 2.0*(H1+H2); }
    while(y <= -(2.0*(H1+H2)-2.0*HeightHalfVisible)) { y += 2.0*(H1+H2); }
    if(qAbs(y) <= HeightHalfVisible)
      painter.drawLine(QLineF(-16.0,y, 16.0,y));
  }

//=====  Roll:  =====
  painter.setBrush(QBrush(ColorRoll));

//- Triangle:
  painter.setPen(Qt::NoPen);
  mpointsF[0].setX(0.0);   mpointsF[0].setY(-rRoll);
  mpointsF[1].setX(-6.5);  mpointsF[1].setY(-rRoll - 11.258); //  11.258 = sqrt(3.0)/2.0 * 13.0
  mpointsF[2].setX(6.5);   mpointsF[2].setY(-rRoll - 11.258);
  painter.drawPolygon(mpointsF,3);

//- Arc:
  pen.setColor(ColorRoll);  pen.setWidthF(1.5);   painter.setPen(pen);
  painter.drawArc(QRectF(-rRoll, -rRoll, 2.0*rRoll, 2.0*rRoll), 30*16, 120*16);

//для крючочков
  qreal hs1 = 5.0;
  qreal hs2 = 12.0;  qreal ws2 = 5.0;
  qreal hs3 = 10.0;
  yoff = -rRoll - hs2 - 10.0; //  - 5.0
  angle = 0.0;

  qreal dopangle;  // QString text;

  for(int k = -1; k <= 1; k += 2)
  {
    xoff = ws2/2.0*k;
//- (5), (10):
    dopangle = 10.0*k;  painter.rotate(dopangle);
    for(int i = 1; i <= 2; i++)
    {
      painter.drawLine(QPointF(0.0,-rRoll), QPointF(0.0,-rRoll-hs1));
      painter.rotate(dopangle);
    }

//- 30, (45), 60, (75):
    dopangle = 15.0*k;  angle = 15.0;
    for(int i = 1; i <= 2; i++)
    {
// 30, 60:
      angle += dopangle*k;  //  text.sprintf(("%.0f"),angle);
      DrawText(painter, xoff, yoff, angle); //text);
      mpointsF[0].setX(0.0);  mpointsF[0].setY(-rRoll);
      mpointsF[1].setX(0.0);  mpointsF[1].setY(-rRoll-hs2);
      mpointsF[2].setX(ws2*k);  mpointsF[2].setY(-rRoll-hs2);
      painter.drawPolyline(mpointsF, 3);
// (45), (75):
      painter.rotate(dopangle);
      painter.drawLine(QPointF(0.0,-rRoll), QPointF(0.0,-rRoll-hs3));

      painter.rotate(dopangle);
      angle += dopangle*k;
    }

//- 90:
    xoff = 1.0;
    angle += dopangle*k;  //  text.sprintf(("%.0f"),angle);
    DrawText(painter, xoff, yoff, angle); //text);
    lines << QLineF(0.0,-rRoll, 0.0,-rRoll-hs2);
    lines << QLineF(-4.0,-rRoll-hs2, 4.0,-rRoll-hs2);
    painter.drawLines(lines);  lines.clear();

//- 120, 150:
    xoff = -ws2/2.0*k;
    dopangle = 30.0*k;    painter.rotate(dopangle);
    for(int i = 1; i <= 2; i++)
    {
      angle += dopangle*k;  //  text.sprintf(("%.0f"),angle);
      DrawText(painter, xoff, yoff, angle); //text);
      mpointsF[0].setX(0.0);  mpointsF[0].setY(-rRoll);
      mpointsF[1].setX(0.0);  mpointsF[1].setY(-rRoll-hs2);
      mpointsF[2].setX(-ws2*k);  mpointsF[2].setY(-rRoll-hs2);
      painter.drawPolyline(mpointsF, 3);

      painter.rotate(dopangle);
    }

    if(k == -1)  painter.rotate(180.0);
  }

//- 180:
  xoff = -1.0;
  angle += dopangle;  //  text.sprintf(("%.0f"),angle);
  DrawText(painter, xoff, yoff, angle); //text);
  lines << QLineF(0.0,-rRoll, 0.0,-rRoll-hs2);
  lines << QLineF(-3.0,-rRoll-hs2+4.0, 3.0,-rRoll-hs2+4.0);
  lines << QLineF(-6.0,-rRoll-hs2, 6.0,-rRoll-hs2);
  painter.drawLines(lines);  lines.clear();
  painter.rotate(-180.0);

//=====  Static:  =====

  painter.rotate(RollAngle);

//==Balance:

  pen.setColor(ColorStaticBalanceOutline);  pen.setWidthF(0.5);   painter.setPen(pen);

  linearGrad.setStart(0.0,    -3.5+1.5);
  linearGrad.setFinalStop(0.0, 3.5);
  linearGrad.setColorAt(0, ColorStaticBalance0);
  linearGrad.setColorAt(1, ColorStaticBalance1);
  QBrush brushBalance(linearGrad);   painter.setBrush(brushBalance);

//-Left:
  mpointsF[0].setX(-48.0-1.0);           mpointsF[0].setY(0.0);
  mpointsF[1].setX(-48.0-1.0-8.0);       mpointsF[1].setY(-3.5);
  mpointsF[2].setX(-48.0-1.0-8.0-24.0);  mpointsF[2].setY(-3.5);
  mpointsF[3].setX(-48.0-1.0-8.0-24.0);  mpointsF[3].setY(3.5);
  mpointsF[4].setX(-48.0-1.0-8.0);       mpointsF[4].setY(3.5);
  painter.drawPolygon(mpointsF,5);

//-Right:
  mpointsF[0].setX(48.0+1.0);
  mpointsF[1].setX(48.0+1.0+8.0);
  mpointsF[2].setX(48.0+1.0+8.0+24.0);
  mpointsF[3].setX(48.0+1.0+8.0+24.0);
  mpointsF[4].setX(48.0+1.0+8.0);
  painter.drawPolygon(mpointsF,5);

//-Center:
  linearGrad.setStart(0.0,    0.0);
  linearGrad.setFinalStop(0.0, 12.0+6.0);
  linearGrad.setColorAt(0, ColorStaticBalance0);
  linearGrad.setColorAt(1, ColorStaticBalance1);
  QBrush brushBalanceCenter(linearGrad);   painter.setBrush(brushBalanceCenter);
  mpointsF[0].setX(0.0);            mpointsF[0].setY(0.0);
  mpointsF[1].setX(-30.0);          mpointsF[1].setY(12.0);
  mpointsF[2].setX(0.0);            mpointsF[2].setY(6.0);
  mpointsF[3].setX(30.0);           mpointsF[3].setY(12.0);
  painter.drawPolygon(mpointsF,4);

//- Triangle:
  painter.setBrush(QBrush(ColorStaticTriangle));
  mpointsF[0].setX(0.0);   mpointsF[0].setY(-rRoll);
  mpointsF[1].setX(6.5);   mpointsF[1].setY(-rRoll + 11.258); //  11.258 = sqrt(3.0)/2.0 * 13.0
  mpointsF[2].setX(-6.5);  mpointsF[2].setY(-rRoll + 11.258);
  painter.drawPolygon(mpointsF,3);


//=============================
  painter.setOpacity(0.6);

  QPixmap pixmap = PEkranoplanGL->renderPixmap(); //80,80);//,false);
  pixmap.setMask(pixmap.createMaskFromColor(QColor(0,0,0, 255)));
  painter.drawPixmap(-WidthHalf+1,HeightHalf-pixmap.rect().height()-1, pixmap);
//--
  painter.end();
  QPainter paint(this);
  paint.drawImage(0,0, imgagePaint);
}
예제 #19
0
// Draws a cached pixmap with shadow
void StyleHelper::drawIconWithShadow(const QIcon& icon, const QRect& rect,
                                     QPainter* p, QIcon::Mode iconMode,
                                     int radius, const QColor& color,
                                     const QPoint& offset) {
  QPixmap cache;
  QString pixmapName =
      QString("icon %0 %1 %2").arg(icon.cacheKey()).arg(iconMode).arg(
          rect.height());

  if (!QPixmapCache::find(pixmapName, cache)) {
    QPixmap px = icon.pixmap(rect.size());
    cache = QPixmap(px.size() + QSize(radius * 2, radius * 2));
    cache.fill(Qt::transparent);

    QPainter cachePainter(&cache);
    if (iconMode == QIcon::Disabled) {
      QImage im = px.toImage().convertToFormat(QImage::Format_ARGB32);
      for (int y = 0; y < im.height(); ++y) {
        QRgb* scanLine = (QRgb*)im.scanLine(y);
        for (int x = 0; x < im.width(); ++x) {
          QRgb pixel = *scanLine;
          char intensity = qGray(pixel);
          *scanLine = qRgba(intensity, intensity, intensity, qAlpha(pixel));
          ++scanLine;
        }
      }
      px = QPixmap::fromImage(im);
    }

    // Draw shadow
    QImage tmp(px.size() + QSize(radius * 2, radius * 2 + 1),
               QImage::Format_ARGB32_Premultiplied);
    tmp.fill(Qt::transparent);

    QPainter tmpPainter(&tmp);
    tmpPainter.setCompositionMode(QPainter::CompositionMode_Source);
    tmpPainter.drawPixmap(QPoint(radius, radius), px);
    tmpPainter.end();

    // blur the alpha channel
    QImage blurred(tmp.size(), QImage::Format_ARGB32_Premultiplied);
    blurred.fill(Qt::transparent);
    QPainter blurPainter(&blurred);
    qt_blurImage(&blurPainter, tmp, radius, false, true);
    blurPainter.end();

    tmp = blurred;

    // blacken the image...
    tmpPainter.begin(&tmp);
    tmpPainter.setCompositionMode(QPainter::CompositionMode_SourceIn);
    tmpPainter.fillRect(tmp.rect(), color);
    tmpPainter.end();

    tmpPainter.begin(&tmp);
    tmpPainter.setCompositionMode(QPainter::CompositionMode_SourceIn);
    tmpPainter.fillRect(tmp.rect(), color);
    tmpPainter.end();

    // draw the blurred drop shadow...
    cachePainter.drawImage(
        QRect(0, 0, cache.rect().width(), cache.rect().height()), tmp);

    // Draw the actual pixmap...
    cachePainter.drawPixmap(QPoint(radius, radius) + offset, px);
    QPixmapCache::insert(pixmapName, cache);
  }

  QRect targetRect = cache.rect();
  targetRect.moveCenter(rect.center());
  p->drawPixmap(targetRect.topLeft() - offset, cache);
}
예제 #20
0
void MainWindow::on_actionPiecewise_linear_triggered()
{
    QPixmap pixmap = pixmapItem->pixmap().copy();

    QImage image = pixmap.toImage();
    int width = image.width();
    int height = image.height();

    if (width == 0 || height == 0)
    {
        ui->statusBar->showMessage( tr("Error. Image bad size"), 3000 );
        return;
    }

    DialogPiecewiseLinear dialog;
    dialog.setText(pieceWiseLinearText);

    if (dialog.exec() == QDialog::Rejected)
        return;

    std::vector<double> nums = dialog.getNums();

    pieceWiseLinearText = dialog.getString();

    bool normalize = dialog.isNormalize();
    std::vector<double> csR(nums.size() / 4);
    std::vector<double> csG(nums.size() / 4);
    std::vector<double> csB(nums.size() / 4);
    if (normalize)
    {
        int maxR = -1;
        int maxG = -1;
        int maxB = -1;

        for (int y = 0; y < height; ++y)
            for (int x = 0; x < width; ++x)
            {
                QRgb oldColor = image.pixel(x, y);
                int red = qRed(oldColor);
                int green = qGreen(oldColor);
                int blue = qBlue(oldColor);
                if (red > maxR)
                    maxR = red;
                if (green > maxG)
                    maxG = green;
                if (blue > maxB)
                    maxB = blue;
            }

        for (unsigned int i = 0; i < nums.size(); i += 4)
        {
            csR[i/4] = 255 / (nums[i] * maxR + nums[i+1]);
            csG[i/4] = 255 / (nums[i] * maxG + nums[i+1]);
            csB[i/4] = 255 / (nums[i] * maxB + nums[i+1]);
        }
    }

    for (int y = 0; y < height; ++y)
        for (int x = 0; x < width; ++x)
        {
            QRgb oldColor = image.pixel(x, y);
            int red = qRed(oldColor);
            int green = qGreen(oldColor);
            int blue = qBlue(oldColor);
            double cR = 1.0;
            double cG = 1.0;
            double cB = 1.0;
            for (unsigned int i = 0; i < nums.size(); i += 4)
            {
                double k = nums[i];
                double b = nums[i+1];
                int left = qFloor(nums[i+2]);
                int right = qFloor(nums[i+3]);
                if (left <= red && red <= right)
                {
                    if (normalize)
                        cR = csR[i/4];
                    red = cR * (k * red + b);
                    if (red < 0)
                        red = 0;
                    if (red > 255)
                        red = 255;
                }
                if (left <= green && green <= right)
                {
                    if (normalize)
                        cG = csG[i/4];
                    green = cG * (k * green + b);
                    if (green < 0)
                        green = 0;
                    if (green > 255)
                        green = 255;
                }
                if (left <= blue && blue <= right)
                {
                    if (normalize)
                        cB = csB[i/4];
                    blue = cB * (k * blue + b);
                    if (blue < 0)
                        blue = 0;
                    if (blue > 255)
                        blue = 255;
                }
            }
            image.setPixel(x, y, qRgb(red, green, blue));
        }

    pixmap.convertFromImage(image);

    pixmapItem_2->setPixmap(pixmap);
    scene_2->setSceneRect(QRectF(pixmap.rect()));

    calcHist(pixmap, hist_2, maxLevel_2);
    drawHist(pixmapItem_4, hist_2, maxLevel_2);
}
예제 #21
0
파일: node.cpp 프로젝트: Novynn/Adamant
Node::Node(const QJsonObject& source, bool root)
    : _flags(root ? Root : None)
    , _active(false) {
    _id         = source.value("id").toInt();
    _group      = source.value("g").toInt();
    _orbit      = source.value("o").toInt();
    _orbitIndex = source.value("oidx").toInt();

    if (source.value("not").toBool())
        _flags = _flags | Notable;

    if (source.value("ks").toBool())
        _flags = _flags | KeyStone;

    if (source.value("m").toBool())
        _flags = _flags | Mastery;

    if (source.value("isJewelSocket").toBool())
        _flags = _flags | JewelSocket;

    if (source.value("isAscendancyStart").toBool())
        _flags = _flags | AscendancyRoot;

    if (source.value("isMultipleChoice").toBool())
        _flags = _flags | MultiChoiceRoot;

    if (source.value("isMultipleChoiceOption").toBool())
        _flags = _flags | MultiChoiceOption;

    _name       = source.value("dn").toString();
    _icon       = source.value("icon").toString();
    _ascendancy = source.value("ascendancyName").toString();
    _detail     = source.value("sd").toVariant().toStringList();

    _grantedPassivePoints   = source.value("passivePointsGranted").toInt();
    _grantedStrength        = source.value("sa").toInt();
    _grantedIntelligence    = source.value("ia").toInt();
    _grantedDexterity       = source.value("da").toInt();

    auto outNodesArray = source.value("out").toArray();
    for (const QJsonValue &val : outNodesArray) {
        _outNodes << val.toInt();
    }

    if (hasNodeFlag(AscendancyRoot)) {
        setZValue(1.0f);
        _pixmap = QPixmap(":/static/PassiveSkillScreenAscendancyMiddle.png");
    }
    else {
        setZValue(2.0f);

        NodeAsset* asset = NodeAsset::getAsset(_icon);
        if (asset) {
            _pixmap = asset->getPixmap(this);

            if (!hasNodeFlag(Mastery)) {
                QPixmap frame;
                if (hasNodeFlag(Notable)) {
                    frame = QPixmap(_ascendancy.isEmpty() ? ":/static/NotableFrameUnallocated.png" : ":/static/PassiveSkillScreenAscendancyFrameLargeNormal.png");
                }
                else if (hasNodeFlag(KeyStone)) {
                    frame = QPixmap(":/static/KeystoneFrameUnallocated.png");
                }
                else if (hasNodeFlag(JewelSocket)) {
                    frame = QPixmap(":/static/JewelFrameUnallocated.png");
                }
                else {
                    frame = QPixmap(_ascendancy.isEmpty() ? ":/static/Skill_Frame_Unallocated.png" : ":/static/PassiveSkillScreenAscendancyFrameSmallNormal.png");
                }
                QPixmap result(frame.width(), frame.height());
                result.fill(Qt::transparent);
                QPainter painter(&result);
                painter.drawPixmap((frame.width() / 2) - (_pixmap.width() / 2),
                                   (frame.height() / 2) - (_pixmap.height() / 2),
                                   _pixmap);
                painter.drawPixmap(frame.rect(), frame);
                _pixmap = result;
            }
        }
        else {
            qDebug() << "Failed to find asset for " << _icon;
        }
    }
}
예제 #22
0
void MainWindow::on_actionZoom_triggered()
{
    QPixmap oldPixmap = pixmapItem->pixmap();

    QImage oldImage = oldPixmap.toImage();
    int oldWidth = oldImage.width();
    int oldHeight = oldImage.height();

    if (oldWidth == 0 || oldHeight == 0)
    {
        ui->statusBar->showMessage( tr("Error. Image bad size"), 3000 );
        return;
    }

    DialogZoom dialog;
    if (dialog.exec() == QDialog::Rejected)
        return;

    double value = dialog.getValue();
    int choice = dialog.getChoice();

    int width = oldWidth * value;
    int height = oldHeight * value;

    QImage image(width, height, QImage::Format_ARGB32);
    image.fill( QColor(255, 255, 255) );
    if (choice == 1)
    {
        for (int i = 0; i < width; ++i)
            for (int j = 0; j < height; ++j)
            {
                int srcX = i / value;
                int srcY = j / value;
                image.setPixel(i, j, oldImage.pixel(srcX, srcY));
            }
    }
    else if (choice == 2)
    {
        int h, w;
        double t;
        double u;
        double tmp;
        double d1, d2, d3, d4;
        QRgb p1, p2, p3, p4;

        int red, green, blue;

        for (int j = 0; j < height; ++j)
        {
            tmp = j / (double) (height - 1) * (oldHeight - 1);
            h = qFloor(tmp);
            h = h < 0? 0: (h >= oldHeight - 1? oldHeight - 2: h);

            u = tmp - h;

            for (int i = 0; i < width; ++i)
            {

                tmp = i / (double) (width - 1) * (oldWidth - 1);
                w = qFloor(tmp);
                w = w < 0? 0: (w >= oldWidth - 1? oldWidth - 2: w);

                t = tmp - w;

                d1 = (1 - t) * (1 - u);
                d2 = t * (1 - u);
                d3 = t * u;
                d4 = (1 - t) * u;

                p1 = oldImage.pixel(w, h);
                p2 = oldImage.pixel(w + 1, h);
                p3 = oldImage.pixel(w + 1, h + 1);
                p4 = oldImage.pixel(w, h + 1);


                red = (int)(qRed(p1) * d1) + (int)(qRed(p2) * d2) + (int)(qRed(p3) * d3) + (int)(qRed(p4) * d4);
                blue = (int)(qBlue(p1) * d1) + (int)(qBlue(p2) * d2) + (int)(qBlue(p3) * d3) + (int)(qBlue(p4) * d4);
                green = (int)(qGreen(p1) * d1) + (int)(qGreen(p2) * d2) + (int)(qGreen(p3) * d3) + (int)(qGreen(p4) * d4);

                image.setPixel(i, j, qRgb(red, green, blue));
            }
        }
    }
    else if (choice == 3)
    {
        int scale = qCeil(value);
        for (int j = scale; j < height - 2 * value; ++j)
        {
//            int h = qFloor(j / value);
//            h = h < 0? 0: (h >= oldHeight - 1? oldHeight - 2: h);
            for (int i = scale; i < width - 2 * value; ++i)
            {
//                int w = qFloor(i / value);
//                w = w < 0? 0: (w >= oldWidth - 1? oldWidth - 2: w);

                int srcX = qFloor(i / value);
                int srcY = qFloor(j / value);

                double relativeX = (i / value) - qFloor((i / value));
                double relativeY = (j / value) - qFloor((j / value));

                QRgb p00 = oldImage.pixel(srcX - 1, srcY - 1);
                QRgb p10 = oldImage.pixel(srcX, srcY - 1);
                QRgb p20 = oldImage.pixel(srcX + 1, srcY - 1);
                QRgb p30 = oldImage.pixel(srcX + 2, srcY - 1);
                QRgb p01 = oldImage.pixel(srcX - 1, srcY);
                QRgb p11 = oldImage.pixel(srcX, srcY);
                QRgb p21 = oldImage.pixel(srcX + 1, srcY);
                QRgb p31 = oldImage.pixel(srcX + 2, srcY);
                QRgb p02 = oldImage.pixel(srcX - 1, srcY + 1);
                QRgb p12 = oldImage.pixel(srcX, srcY + 1);
                QRgb p22 = oldImage.pixel(srcX + 1, srcY + 1);
                QRgb p32 = oldImage.pixel(srcX + 2, srcY + 1);
                QRgb p03 = oldImage.pixel(srcX - 1, srcY + 2);
                QRgb p13 = oldImage.pixel(srcX, srcY + 2);
                QRgb p23 = oldImage.pixel(srcX + 1, srcY + 2);
                QRgb p33 = oldImage.pixel(srcX + 2, srcY + 2);

                double r0 = CubicInterpolation( relativeX, qRed(p00), qRed(p10), qRed(p20), qRed(p30) );
                double r1 = CubicInterpolation( relativeX, qRed(p01), qRed(p11), qRed(p21), qRed(p31) );
                double r2 = CubicInterpolation( relativeX, qRed(p02), qRed(p12), qRed(p22), qRed(p32) );
                double r3 = CubicInterpolation( relativeX, qRed(p03), qRed(p13), qRed(p23), qRed(p33) );
                int r = qMax(0.0, qMin(255.0, CubicInterpolation(relativeY, r0, r1, r2, r3)));
                double g0 = CubicInterpolation( relativeX, qGreen(p00), qGreen(p10), qGreen(p20), qGreen(p30) );
                double g1 = CubicInterpolation( relativeX, qGreen(p01), qGreen(p11), qGreen(p21), qGreen(p31) );
                double g2 = CubicInterpolation( relativeX, qGreen(p02), qGreen(p12), qGreen(p22), qGreen(p32) );
                double g3 = CubicInterpolation( relativeX, qGreen(p03), qGreen(p13), qGreen(p23), qGreen(p33) );
                int g = qMax(0.0, qMin(255.0, CubicInterpolation(relativeY, g0, g1, g2, g3)));
                double b0 = CubicInterpolation( relativeX, qBlue(p00), qBlue(p10), qBlue(p20), qBlue(p30) );
                double b1 = CubicInterpolation( relativeX, qBlue(p01), qBlue(p11), qBlue(p21), qBlue(p31) );
                double b2 = CubicInterpolation( relativeX, qBlue(p02), qBlue(p12), qBlue(p22), qBlue(p32) );
                double b3 = CubicInterpolation( relativeX, qBlue(p03), qBlue(p13), qBlue(p23), qBlue(p33) );
                int b = qMax(0.0, qMin(255.0, CubicInterpolation(relativeY, b0, b1, b2, b3)));

                image.setPixel(i, j, qRgb(r, g, b));
            }
        }
    }

    QPixmap pixmap;
    pixmap.convertFromImage(image);

    pixmapItem_2->setPixmap(pixmap);
    scene_2->setSceneRect(QRectF(pixmap.rect()));

    calcHist(pixmap, hist_2, maxLevel_2);
    drawHist(pixmapItem_4, hist_2, maxLevel_2);
}
예제 #23
0
//--------------------------------------------------------------------------------------------
void MGyrohorizon::paintEvent(QPaintEvent * event)
{
//setStyleSheet(QLatin1String("background: transparent;"));

//  QPixmap pixmap(400,300);  pixmap.fill(Qt::white);
//  QPainter paint(&pixmap);
  QPainter painter(this);
  painter.setRenderHint(QPainter::Antialiasing, true);

qreal Width = 320.0;
qreal Height = 320.0;
qreal rRoll = 125.0;

qreal WidthHalf = Width/2.0;
qreal HeightHalf = Height/2.0;  qreal AngleHeightHalf = 40.0;   qreal AngleHeightHalfVisible = 25.0;
qreal HOneDegreeAngle = HeightHalf/AngleHeightHalf;

qreal MaxDim = qMax(Width,Height)*qSqrt(2.0);  qreal MaxDimHalf = MaxDim/2.0;

qreal HeightHalfVisible = HeightHalf/AngleHeightHalf*AngleHeightHalfVisible;

qreal h1 = HOneDegreeAngle*AngleHeightHalf;
qreal h2 = HOneDegreeAngle*(90.0-AngleHeightHalf);

  QLinearGradient linearGrad;
  QPointF mpointsF[5];
  qreal yh;


/*===========  First Variant  ===========

  qreal hPitchAngle = HeightHalf/AngleHeightHalf*PitchAngle;


//qreal cs = qCos(RollAngle/180.0*M_PI);   qreal acs = qAbs(cs);
//qreal hPitchAngleCos = hPitchAngle*cs;

//qreal HeightHemiSphere = Height/AngleHeight*90.0;


  painter.translate(WidthHalf,HeightHalf);

//painter.translate(0.0,-hPitchAngle);

  painter.rotate(-RollAngle);

//painter.translate(0.0,hPitchAngle);

//=====  Pitch:  =====


  painter.setPen(Qt::NoPen);

//  bool isUpDawn = false;

//-Sky:

// 0:
  yh = hPitchAngle;
  while(yh <= -(4.0*(h1+h2)-2.0*qSqrt(2.0)*h1)) { yh += 4.0*(h1+h2); }
  while(yh >=   4.0*(h1+h2)-2.0*qSqrt(2.0)*h1)  { yh -= 4.0*(h1+h2); }
  linearGrad.setStart(0.0,     yh);
  linearGrad.setFinalStop(0.0, yh-h1);
  linearGrad.setColorAt(0, QColor(80,180,255, 255));
  linearGrad.setColorAt(1, QColor(0,0,100, 255));
  QBrush brushSky1(linearGrad);   painter.setBrush(brushSky1);
  painter.drawRect(-MaxDimHalf,yh+0.5, MaxDim,-h1-1.0);

  yh = hPitchAngle-h1;
  while(yh <= -(4.0*(h1+h2)-2.0*qSqrt(2.0)*h2)) { yh += 4.0*(h1+h2); }
  while(yh >=   4.0*(h1+h2)-2.0*qSqrt(2.0)*h2)  { yh -= 4.0*(h1+h2); }
  linearGrad.setStart(0.0,     yh);
  linearGrad.setFinalStop(0.0, yh-h2);
  linearGrad.setColorAt(0, QColor(0,0,100, 255));
  linearGrad.setColorAt(1, QColor(0,0,80, 255));
  QBrush brushSky2(linearGrad);   painter.setBrush(brushSky2);
  painter.drawRect(-MaxDimHalf,yh, MaxDim,-h2-1.0);

//90
  yh = hPitchAngle-h1-h2;
  while(yh <= -(4.0*(h1+h2)-2.0*qSqrt(2.0)*h2)) { yh += 4.0*(h1+h2); }
  while(yh >=   4.0*(h1+h2)-2.0*qSqrt(2.0)*h2)  { yh -= 4.0*(h1+h2); }
  linearGrad.setStart(0.0,     yh);
  linearGrad.setFinalStop(0.0, yh-h2);
  linearGrad.setColorAt(0, QColor(0,0,80, 255));
  linearGrad.setColorAt(1, QColor(0,0,100, 255));
  QBrush brushSky3(linearGrad);   painter.setBrush(brushSky3);
  painter.drawRect(-MaxDimHalf,yh, MaxDim,-h2-1.0);

  yh = hPitchAngle-h1-h2-h2;
  while(yh <= -(4.0*(h1+h2)-2.0*qSqrt(2.0)*h1)) { yh += 4.0*(h1+h2); }
  while(yh >=   4.0*(h1+h2)-2.0*qSqrt(2.0)*h1)  { yh -= 4.0*(h1+h2); }
  linearGrad.setStart(0.0,     yh);
  linearGrad.setFinalStop(0.0, yh-h1);
  linearGrad.setColorAt(0, QColor(0,0,100, 255));
  linearGrad.setColorAt(1, QColor(80,180,255, 255));
  QBrush brushSky4(linearGrad);   painter.setBrush(brushSky4);
  painter.drawRect(-MaxDimHalf,yh+0.5, MaxDim,-h1-1.0);
//180

//-Ground:

// 0:
  yh = hPitchAngle;
  while(yh >=   4.0*(h1+h2)-2.0*qSqrt(2.0)*h1)  { yh -= 4.0*(h1+h2); }
  while(yh <= -(4.0*(h1+h2)-2.0*qSqrt(2.0)*h1)) { yh += 4.0*(h1+h2); }
  linearGrad.setStart(0.0,     yh);
  linearGrad.setFinalStop(0.0, yh+h1);
  linearGrad.setColorAt(0, QColor(90,170,110, 255));
  linearGrad.setColorAt(1, QColor(90,17,11, 255));
  QBrush brushGround1(linearGrad);   painter.setBrush(brushGround1);
  painter.drawRect(-MaxDimHalf,yh-0.5, MaxDim,h1+1.0);

  yh = hPitchAngle+h1;
  while(yh >=   4.0*(h1+h2)-2.0*qSqrt(2.0)*h2)  { yh -= 4.0*(h1+h2); }
  while(yh <= -(4.0*(h1+h2)-2.0*qSqrt(2.0)*h2)) { yh += 4.0*(h1+h2); }
  linearGrad.setStart(0.0,     yh);
  linearGrad.setFinalStop(0.0, yh+h2);
  linearGrad.setColorAt(0, QColor(90,17,11, 255));
  linearGrad.setColorAt(1, QColor(0,17,11, 255));
  QBrush brushGround2(linearGrad);   painter.setBrush(brushGround2);
  painter.drawRect(-MaxDimHalf,yh, MaxDim,h2+1.0);

//90:
  yh = hPitchAngle+h1+h2;
  while(yh >=   4.0*(h1+h2)-2.0*qSqrt(2.0)*h2)  { yh -= 4.0*(h1+h2); }
  while(yh <= -(4.0*(h1+h2)-2.0*qSqrt(2.0)*h2)) { yh += 4.0*(h1+h2); }
  linearGrad.setStart(0.0,     yh);
  linearGrad.setFinalStop(0.0, yh+h2);
  linearGrad.setColorAt(0, QColor(0,17,11, 255));
  linearGrad.setColorAt(1, QColor(90,17,11, 255));
  QBrush brushGround3(linearGrad);   painter.setBrush(brushGround3);
  painter.drawRect(-MaxDimHalf,yh, MaxDim,h2+1.0);

  yh = hPitchAngle+h1+h2+h2;
  while(yh >=   4.0*(h1+h2)-2.0*qSqrt(2.0)*h1)  { yh -= 4.0*(h1+h2); }
  while(yh <= -(4.0*(h1+h2)-2.0*qSqrt(2.0)*h1)) { yh += 4.0*(h1+h2); }
  linearGrad.setStart(0.0,     yh);
  linearGrad.setFinalStop(0.0, yh+h1);
  linearGrad.setColorAt(0, QColor(90,17,11, 255));
  linearGrad.setColorAt(1, QColor(90,170,110, 255));
  QBrush brushGround4(linearGrad);   painter.setBrush(brushGround4);
  painter.drawRect(-MaxDimHalf,yh, MaxDim,h1);
//180


//  if(isUpDawn) { PSliderRoll->setValue(RollAngle+180); }


//painter.translate(0.0,-hPitchAngle);

//painter.rotate(RollAngle);

//painter.translate(0.0,hPitchAngle);


//= Pitch Scale:


  QPen pen(QColor(255,255,255, 255));
  pen.setWidthF(1.0);
//  pen.setCapStyle(Qt::RoundCap);
//  pen.setJoinStyle(Qt::SvgMiterJoin); //Qt::RoundJoin); //Qt::BevelJoin); //Qt::MiterJoin);
  painter.setPen(pen);

//  qreal x,y;
  QVector<QLineF> lines;

//- (2)-degrees:
  qreal y;  bool isHas = false;
  for(int k = -1; k <= 1; k += 2) {
    y = hPitchAngle;
    while(y >=   2.0*(h1+h2)-2.0*HeightHalfVisible)  { y -= 2.0*(h1+h2); }
    while(y <= -(2.0*(h1+h2)-2.0*HeightHalfVisible)) { y += 2.0*(h1+h2); }
    for(int i = 1; i <= 4; i++) {
      y += -2.0*HOneDegreeAngle*k;
      if(qAbs(y) <= HeightHalfVisible) {  isHas = true;
        lines << QLineF(-8.0,y, 8.0,y);
      }
    }
  }
  if(isHas)  painter.drawLines(lines);
  lines.clear();

  pen.setWidthF(1.5);   painter.setPen(pen);

  qreal xoff, yoff;
  qreal angle;

//- 10-degrees:
  mpointsF[0].setX(-24.0);
  mpointsF[1].setX(-24.0);
  mpointsF[2].setX(24.0);
  mpointsF[3].setX(24.0);
  for(int k = -1; k <= 1; k += 2) {
    for(int i = 0; i <= 9; i++) {
      angle = 10.0*i;
      y = hPitchAngle - angle*HOneDegreeAngle*k;
      while(y >=   2.0*(h1+h2)-2.0*HeightHalfVisible)  { y -= 2.0*(h1+h2); }
      while(y <= -(2.0*(h1+h2)-2.0*HeightHalfVisible)) { y += 2.0*(h1+h2); }
      if(qAbs(y) <= HeightHalfVisible) {
        if(i == 0) {
          painter.drawLine(QLineF(-48.0,y, 48.0,y));
        }
        else if(i < 9) {
          mpointsF[0].setY(y + 5.0*k);
          mpointsF[1].setY(y);
          mpointsF[2].setY(y);
          mpointsF[3].setY(y + 5.0*k);
          painter.drawPolyline(mpointsF, 4); //int pointCount)
          DrawText(painter, -24.0-12.0+0.5, y+5.0/2.0*k, angle);
          DrawText(painter,  24.0+12.0+1.0, y+5.0/2.0*k, angle);
        }
        else {
          lines << QLineF(-36.0,y-7.0, -36.0,y+7.0);
          lines << QLineF(-36.0,y,      36.0,y);
          lines << QLineF( 36.0,y-7.0,  36.0,y+7.0);
          painter.drawLines(lines);  lines.clear();
          DrawText(painter, -36.0-12.0+1.0, y, angle);
          DrawText(painter,  36.0+12.0+1.0, y, angle);
        }
      }
    }

  }
//- (15)-degrees:
  for(int k = -1; k <= 1; k += 2) {
    y = hPitchAngle - 10.0*HOneDegreeAngle*(1.0+0.5)*k;
    while(y >=   2.0*(h1+h2)-2.0*HeightHalfVisible)  { y -= 2.0*(h1+h2); }
    while(y <= -(2.0*(h1+h2)-2.0*HeightHalfVisible)) { y += 2.0*(h1+h2); }
    if(qAbs(y) <= HeightHalfVisible)
      painter.drawLine(QLineF(-16.0,y, 16.0,y));
  }


//  QFont font(font());   // font.setStyleStrategy(QFont::NoAntialias);
//  painter.setFont(font);



//=====  Roll:  =====

//painter.rotate(-RollAngle);

  painter.setBrush(QBrush(QColor(255,255,255, 255)));

//- Triangle:
  painter.setPen(Qt::NoPen);
  mpointsF[0].setX(0.0);   mpointsF[0].setY(-rRoll);
  mpointsF[1].setX(-6.5);  mpointsF[1].setY(-rRoll - 11.258); //  11.258 = sqrt(3.0)/2.0 * 13.0
  mpointsF[2].setX(6.5);   mpointsF[2].setY(-rRoll - 11.258);
  painter.drawPolygon(mpointsF,3);

//- Arc:
  pen.setWidthF(1.5);   painter.setPen(pen);
  painter.drawArc(QRectF(-rRoll, -rRoll, 2.0*rRoll, 2.0*rRoll), 30*16, 120*16);


  qreal hs1 = 5.0;
  qreal hs2 = 12.0;  qreal ws2 = 5.0;
  qreal hs3 = 10.0;
  yoff = -rRoll - hs2 - 10.0; //  - 5.0
  angle = 0.0;

  qreal dopangle;  // QString text;

  for(int k = -1; k <= 1; k += 2) {
    xoff = ws2/2.0*k;
//- (5), (10):
    dopangle = 10.0*k;  painter.rotate(dopangle);
    for(int i = 1; i <= 2; i++) {
      painter.drawLine(QPointF(0.0,-rRoll), QPointF(0.0,-rRoll-hs1));
      painter.rotate(dopangle);
    }

//- 30, (45), 60, (75):
    dopangle = 15.0*k;  angle = 15.0;
    for(int i = 1; i <= 2; i++) {
// 30, 60:
      angle += dopangle*k;  //  text.sprintf(("%.0f"),angle);
      DrawText(painter, xoff, yoff, angle); //text);
      mpointsF[0].setX(0.0);  mpointsF[0].setY(-rRoll);
      mpointsF[1].setX(0.0);  mpointsF[1].setY(-rRoll-hs2);
      mpointsF[2].setX(ws2*k);  mpointsF[2].setY(-rRoll-hs2);
      painter.drawPolyline(mpointsF, 3);
// (45), (75):
      painter.rotate(dopangle);
      painter.drawLine(QPointF(0.0,-rRoll), QPointF(0.0,-rRoll-hs3));

      painter.rotate(dopangle);
      angle += dopangle*k;
    }

//- 90:
    xoff = 1.0;
    angle += dopangle*k;  //  text.sprintf(("%.0f"),angle);
    DrawText(painter, xoff, yoff, angle); //text);
//    painter.drawLine(QPointF(0.0,-rRoll), QPointF(0.0, -rRoll-hs2));
//    painter.drawLine(QPointF(-4.0, -rRoll-hs2), QPointF(4.0, -rRoll-hs2));
    lines << QLineF(0.0,-rRoll, 0.0,-rRoll-hs2);
    lines << QLineF(-4.0,-rRoll-hs2, 4.0,-rRoll-hs2);
    painter.drawLines(lines);  lines.clear();

//- 120, 150:
    xoff = -ws2/2.0*k;
    dopangle = 30.0*k;    painter.rotate(dopangle);
    for(int i = 1; i <= 2; i++) {
      angle += dopangle*k;  //  text.sprintf(("%.0f"),angle);
      DrawText(painter, xoff, yoff, angle); //text);
      mpointsF[0].setX(0.0);  mpointsF[0].setY(-rRoll);
      mpointsF[1].setX(0.0);  mpointsF[1].setY(-rRoll-hs2);
      mpointsF[2].setX(-ws2*k);  mpointsF[2].setY(-rRoll-hs2);
      painter.drawPolyline(mpointsF, 3);

      painter.rotate(dopangle);
    }

    if(k == -1)  painter.rotate(180.0);
  }

//- 180:
  xoff = -1.0;
  angle += dopangle;  //  text.sprintf(("%.0f"),angle);
  DrawText(painter, xoff, yoff, angle); //text);
//  painter.drawLine(QPointF(0.0,-rRoll), QPointF(0.0,-rRoll-hs2));
//  painter.drawLine(QPointF(-3.0, -rRoll-hs2+4.0), QPointF(3.0, -rRoll-hs2+4.0));
//  painter.drawLine(QPointF(-6.0, -rRoll-hs2), QPointF(6.0, -rRoll-hs2));
  lines << QLineF(0.0,-rRoll, 0.0,-rRoll-hs2);
  lines << QLineF(-3.0,-rRoll-hs2+4.0, 3.0,-rRoll-hs2+4.0);
  lines << QLineF(-6.0,-rRoll-hs2, 6.0,-rRoll-hs2);
  painter.drawLines(lines);  lines.clear();
  painter.rotate(-180.0);

//=====  Static:  =====

  painter.rotate(RollAngle);

  painter.setPen(Qt::NoPen);

//-Balance:

  pen.setColor(Qt::black);
  pen.setWidthF(0.5);   painter.setPen(pen);

  linearGrad.setStart(0.0,    -3.5+1.5);
  linearGrad.setFinalStop(0.0, 3.5);
  linearGrad.setColorAt(0, QColor(255,255,0, 255));
  linearGrad.setColorAt(1, QColor(88,88,0, 255));
  QBrush brushBalance(linearGrad);   painter.setBrush(brushBalance);

//-Left:
  mpointsF[0].setX(-48.0-1.0);           mpointsF[0].setY(0.0);
  mpointsF[1].setX(-48.0-1.0-8.0);       mpointsF[1].setY(-3.5);
  mpointsF[2].setX(-48.0-1.0-8.0-24.0);  mpointsF[2].setY(-3.5);
  mpointsF[3].setX(-48.0-1.0-8.0-24.0);  mpointsF[3].setY(3.5);
  mpointsF[4].setX(-48.0-1.0-8.0);       mpointsF[4].setY(3.5);
  painter.drawPolygon(mpointsF,5);

//-Right:
  mpointsF[0].setX(48.0+1.0);          // mpointsF[0].setY(0.0);
  mpointsF[1].setX(48.0+1.0+8.0);      // mpointsF[1].setY(-3.5);
  mpointsF[2].setX(48.0+1.0+8.0+24.0); // mpointsF[2].setY(-3.5);
  mpointsF[3].setX(48.0+1.0+8.0+24.0); // mpointsF[3].setY(3.5);
  mpointsF[4].setX(48.0+1.0+8.0);      // mpointsF[4].setY(3.5);
  painter.drawPolygon(mpointsF,5);

//-Center:
  linearGrad.setStart(0.0,    0.0);
  linearGrad.setFinalStop(0.0, 12.0+6.0);
  linearGrad.setColorAt(0, QColor(255,255,0, 255));
  linearGrad.setColorAt(1, QColor(88,88,0, 255));
  QBrush brushBalanceCenter(linearGrad);   painter.setBrush(brushBalanceCenter);
  mpointsF[0].setX(0.0);            mpointsF[0].setY(0.0);
  mpointsF[1].setX(-30.0);          mpointsF[1].setY(12.0);
  mpointsF[2].setX(0.0);            mpointsF[2].setY(6.0);
  mpointsF[3].setX(30.0);           mpointsF[3].setY(12.0);
  painter.drawPolygon(mpointsF,4);

//- Triangle:
  painter.setBrush(QBrush(QColor(255,255,0, 255)));
  mpointsF[0].setX(0.0);   mpointsF[0].setY(-rRoll);
  mpointsF[1].setX(6.5);   mpointsF[1].setY(-rRoll + 11.258); //  11.258 = sqrt(3.0)/2.0 * 13.0
  mpointsF[2].setX(-6.5);  mpointsF[2].setY(-rRoll + 11.258);
  painter.drawPolygon(mpointsF,3);
*/

//=============================

PitchAngle = PitchAngle0;
  bool isUpDawn = false;
  while(PitchAngle < -90.0) { PitchAngle += 180.0;
//  while(PitchAngle < -90.0) { PitchAngle = -180.0 - PitchAngle;
//    PSliderPitch->setValue(PitchAngle);
    isUpDawn = !isUpDawn; //true;
//    IsUpDawn = isUpDawn;
  } //PitchAngle += 180.0; } // hPitchAngle += 2.0*(h1+h2); }
  while(PitchAngle > 90.0)  { PitchAngle -= 180.0;
//  while(PitchAngle > 90.0)  { PitchAngle = 180.0 - PitchAngle;
//    PSliderPitch->setValue(PitchAngle); // PSliderPitch->setTracking(true);
    isUpDawn = !isUpDawn; //true;
//    IsUpDawn = isUpDawn;
  } //PitchAngle -= 180.0; } // hPitchAngle -= 2.0*(h1+h2); }

RollAngle = RollAngle0;
  if(isUpDawn) {  RollAngle += 180.0;
//    PSliderRoll->setValue(RollAngle);
  }
  while(RollAngle < -180.0) {
    RollAngle += 360.0;
//    PSliderRoll->setValue(RollAngle);
  } //PitchAngle += 180.0; } // hPitchAngle += 2.0*(h1+h2); }
  while(RollAngle > 180.0)  { RollAngle -= 360.0;
//    PSliderRoll->setValue(RollAngle);
  } //PitchAngle -= 180.0; } // hPitchAngle -= 2.0*(h1+h2); }


  qreal hPitchAngle = HeightHalf/AngleHeightHalf*PitchAngle;
  if(isUpDawn) {
//    painter.translate(0.0,-2.0*hPitchAngle);
    hPitchAngle = -hPitchAngle;
  }


//qreal cs = qCos(RollAngle/180.0*M_PI);   qreal acs = qAbs(cs);
//qreal hPitchAngleCos = hPitchAngle*cs;

//qreal HeightHemiSphere = Height/AngleHeight*90.0;


  painter.translate(WidthHalf,HeightHalf);

//  painter.translate(0.0,hPitchAngle);


  painter.rotate(-RollAngle);

//painter.translate(0.0,hPitchAngle);

//=====  Pitch:  =====


  painter.setPen(Qt::NoPen);


//-Sky:

// 0:
  yh = hPitchAngle;
//  yh = 0.0;
//  while(yh <= -(4.0*(h1+h2)-2.0*qSqrt(2.0)*h1)) { yh += 4.0*(h1+h2); }
//  while(yh >=   4.0*(h1+h2)-2.0*qSqrt(2.0)*h1)  { yh -= 4.0*(h1+h2); }
//  while(yh <= -(2.0*(h1+h2)-qSqrt(2.0)*h1)) { yh += 2.0*(h1+h2); }
//  while(yh >=   2.0*(h1+h2)-qSqrt(2.0)*h1)  { yh -= 2.0*(h1+h2); }
  linearGrad.setStart(0.0,     yh);
  linearGrad.setFinalStop(0.0, yh-h1);
  linearGrad.setColorAt(0, ColorSky0);
  linearGrad.setColorAt(1, ColorSky1);
  QBrush brushSky1(linearGrad);   painter.setBrush(brushSky1);
  painter.drawRect(-MaxDimHalf,yh+0.5, MaxDim,-h1-1.0);

  yh = hPitchAngle-h1;
//  yh = -h1;
//  while(yh <= -(4.0*(h1+h2)-2.0*qSqrt(2.0)*h2)) { yh += 4.0*(h1+h2); }
//  while(yh >=   4.0*(h1+h2)-2.0*qSqrt(2.0)*h2)  { yh -= 4.0*(h1+h2); }
//  while(yh <= -(2.0*(h1+h2)-qSqrt(2.0)*h2)) { yh += 2.0*(h1+h2); }
//  while(yh >=   2.0*(h1+h2)-qSqrt(2.0)*h2)  { yh -= 2.0*(h1+h2); }
  linearGrad.setStart(0.0,     yh);
  linearGrad.setFinalStop(0.0, yh-h2);
  linearGrad.setColorAt(0, ColorSky1);
  linearGrad.setColorAt(1, ColorSky2);
  QBrush brushSky2(linearGrad);   painter.setBrush(brushSky2);
  painter.drawRect(-MaxDimHalf,yh, MaxDim,-h2-1.0);

//90
  yh = hPitchAngle-h1-h2;
//  yh = -h1-h2;
//  while(yh <= -(4.0*(h1+h2)-2.0*qSqrt(2.0)*h2)) { yh += 4.0*(h1+h2); }
//  while(yh >=   4.0*(h1+h2)-2.0*qSqrt(2.0)*h2)  { yh -= 4.0*(h1+h2); }
//  while(yh <= -(2.0*(h1+h2)-qSqrt(2.0)*h2)) { yh += 2.0*(h1+h2); }
//  while(yh >=   2.0*(h1+h2)-qSqrt(2.0)*h2)  { yh -= 2.0*(h1+h2); }
  linearGrad.setStart(0.0,     yh);
  linearGrad.setFinalStop(0.0, yh-h2);
  linearGrad.setColorAt(0, ColorSky2);
  linearGrad.setColorAt(1, ColorSky1);
  QBrush brushSky3(linearGrad);   painter.setBrush(brushSky3);
  painter.drawRect(-MaxDimHalf,yh, MaxDim,-h2-1.0);

  yh = hPitchAngle-h1-h2-h2;
//  yh = -h1-h2-h2;
//  while(yh <= -(4.0*(h1+h2)-2.0*qSqrt(2.0)*h1)) { yh += 4.0*(h1+h2); }
//  while(yh >=   4.0*(h1+h2)-2.0*qSqrt(2.0)*h1)  { yh -= 4.0*(h1+h2); }
//  while(yh <= -(2.0*(h1+h2)-qSqrt(2.0)*h1)) { yh += 2.0*(h1+h2); }
//  while(yh >=   2.0*(h1+h2)-qSqrt(2.0)*h1)  { yh -= 2.0*(h1+h2); }
  linearGrad.setStart(0.0,     yh);
  linearGrad.setFinalStop(0.0, yh-h1);
  linearGrad.setColorAt(0, ColorSky1);
  linearGrad.setColorAt(1, ColorSky0);
  QBrush brushSky4(linearGrad);   painter.setBrush(brushSky4);
  painter.drawRect(-MaxDimHalf,yh+0.5, MaxDim,-h1-1.0);
//180


//-Ground:

// 0:
  yh = hPitchAngle;
//  yh = 0.0;
//  while(yh >=   4.0*(h1+h2)-2.0*qSqrt(2.0)*h1)  { yh -= 4.0*(h1+h2); }
//  while(yh <= -(4.0*(h1+h2)-2.0*qSqrt(2.0)*h1)) { yh += 4.0*(h1+h2); }
//  while(yh >=   2.0*(h1+h2)-qSqrt(2.0)*h1)  { yh -= 2.0*(h1+h2); }
//  while(yh <= -(2.0*(h1+h2)-qSqrt(2.0)*h1)) { yh += 2.0*(h1+h2); }
  linearGrad.setStart(0.0,     yh);
  linearGrad.setFinalStop(0.0, yh+h1);
  linearGrad.setColorAt(0, ColorGround0);
  linearGrad.setColorAt(1, ColorGround1);
  QBrush brushGround1(linearGrad);   painter.setBrush(brushGround1);
  painter.drawRect(-MaxDimHalf,yh-0.5, MaxDim,h1+1.0);

  yh = hPitchAngle+h1;
//  yh = h1;
//  while(yh >=   4.0*(h1+h2)-2.0*qSqrt(2.0)*h2)  { yh -= 4.0*(h1+h2); }
//  while(yh <= -(4.0*(h1+h2)-2.0*qSqrt(2.0)*h2)) { yh += 4.0*(h1+h2); }
//  while(yh >=   2.0*(h1+h2)-qSqrt(2.0)*h2)  { yh -= 2.0*(h1+h2); }
//  while(yh <= -(2.0*(h1+h2)-qSqrt(2.0)*h2)) { yh += 2.0*(h1+h2); }
  linearGrad.setStart(0.0,     yh);
  linearGrad.setFinalStop(0.0, yh+h2);
  linearGrad.setColorAt(0, ColorGround1);
  linearGrad.setColorAt(1, ColorGround2);
  QBrush brushGround2(linearGrad);   painter.setBrush(brushGround2);
  painter.drawRect(-MaxDimHalf,yh, MaxDim,h2+1.0);

//90:
  yh = hPitchAngle+h1+h2;
//  yh = h1+h2;
//  while(yh >=   4.0*(h1+h2)-2.0*qSqrt(2.0)*h2)  { yh -= 4.0*(h1+h2); }
//  while(yh <= -(4.0*(h1+h2)-2.0*qSqrt(2.0)*h2)) { yh += 4.0*(h1+h2); }
//  while(yh >=   2.0*(h1+h2)-qSqrt(2.0)*h2)  { yh -= 2.0*(h1+h2); }
//  while(yh <= -(2.0*(h1+h2)-qSqrt(2.0)*h2)) { yh += 2.0*(h1+h2); }
  linearGrad.setStart(0.0,     yh);
  linearGrad.setFinalStop(0.0, yh+h2);
  linearGrad.setColorAt(0, ColorGround2);
  linearGrad.setColorAt(1, ColorGround1);
  QBrush brushGround3(linearGrad);   painter.setBrush(brushGround3);
  painter.drawRect(-MaxDimHalf,yh, MaxDim,h2+1.0);

  yh = hPitchAngle+h1+h2+h2;
//  yh = h1+h2+h2;
//  while(yh >=   4.0*(h1+h2)-2.0*qSqrt(2.0)*h1)  { yh -= 4.0*(h1+h2); }
//  while(yh <= -(4.0*(h1+h2)-2.0*qSqrt(2.0)*h1)) { yh += 4.0*(h1+h2); }
//  while(yh >=   2.0*(h1+h2)-qSqrt(2.0)*h1)  { yh -= 2.0*(h1+h2); }
//  while(yh <= -(2.0*(h1+h2)-qSqrt(2.0)*h1)) { yh += 2.0*(h1+h2); }
  linearGrad.setStart(0.0,     yh);
  linearGrad.setFinalStop(0.0, yh+h1);
  linearGrad.setColorAt(0, ColorGround1);
  linearGrad.setColorAt(1, ColorGround0);
  QBrush brushGround4(linearGrad);   painter.setBrush(brushGround4);
  painter.drawRect(-MaxDimHalf,yh, MaxDim,h1);
//180


//  painter.translate(0.0,hPitchAngle);
//
//  if(isUpDawn) {
//    painter.translate(0.0,2.0*hPitchAngle);
//    hPitchAngle = -hPitchAngle;
//  }


//  if(isUpDawn) { PSliderRoll->setValue(RollAngle+180); }


//painter.translate(0.0,-hPitchAngle);

//painter.rotate(RollAngle);

//painter.translate(0.0,hPitchAngle);


//== Pitch Scale:

  QPen pen(ColorPitch);  pen.setWidthF(1.0);
//  pen.setCapStyle(Qt::RoundCap);
//  pen.setJoinStyle(Qt::SvgMiterJoin); //Qt::RoundJoin); //Qt::BevelJoin); //Qt::MiterJoin);
  painter.setPen(pen);

//  qreal x,y;
  QVector<QLineF> lines;

//- (2)-degrees:
  qreal y;  bool isHas = false;
  for(int k = -1; k <= 1; k += 2) {
    y = hPitchAngle;
    while(y >=   2.0*(h1+h2)-2.0*HeightHalfVisible)  { y -= 2.0*(h1+h2); }
    while(y <= -(2.0*(h1+h2)-2.0*HeightHalfVisible)) { y += 2.0*(h1+h2); }
    for(int i = 1; i <= 4; i++) {
      y += -2.0*HOneDegreeAngle*k;
      if(qAbs(y) <= HeightHalfVisible) {  isHas = true;
        lines << QLineF(-8.0,y, 8.0,y);
      }
    }
  }
  if(isHas)  painter.drawLines(lines);
  lines.clear();

  pen.setWidthF(1.5);   painter.setPen(pen);

  qreal xoff, yoff;
  qreal angle;

//- 10-degrees:
  mpointsF[0].setX(-24.0);
  mpointsF[1].setX(-24.0);
  mpointsF[2].setX(24.0);
  mpointsF[3].setX(24.0);
  for(int k = -1; k <= 1; k += 2) {
    for(int i = 0; i <= 9; i++) {
      angle = 10.0*i;
      y = hPitchAngle - angle*HOneDegreeAngle*k;
      while(y >=   2.0*(h1+h2)-2.0*HeightHalfVisible)  { y -= 2.0*(h1+h2); }
      while(y <= -(2.0*(h1+h2)-2.0*HeightHalfVisible)) { y += 2.0*(h1+h2); }
      if(qAbs(y) <= HeightHalfVisible) {
        if(i == 0) {
          painter.drawLine(QLineF(-48.0,y, 48.0,y));
        }
        else if(i < 9) {
          mpointsF[0].setY(y + 5.0*k);
          mpointsF[1].setY(y);
          mpointsF[2].setY(y);
          mpointsF[3].setY(y + 5.0*k);
          painter.drawPolyline(mpointsF, 4); //int pointCount)
          DrawText(painter, -24.0-12.0+0.5, y+5.0/2.0*k, angle);
          DrawText(painter,  24.0+12.0+1.0, y+5.0/2.0*k, angle);
        }
        else {
          lines << QLineF(-36.0,y-7.0, -36.0,y+7.0);
          lines << QLineF(-36.0,y,      36.0,y);
          lines << QLineF( 36.0,y-7.0,  36.0,y+7.0);
          painter.drawLines(lines);  lines.clear();
          DrawText(painter, -36.0-12.0+1.0, y, angle);
          DrawText(painter,  36.0+12.0+1.0, y, angle);
        }
      }
    }

  }
//- (15)-degrees:
  for(int k = -1; k <= 1; k += 2) {
    y = hPitchAngle - 10.0*HOneDegreeAngle*(1.0+0.5)*k;
    while(y >=   2.0*(h1+h2)-2.0*HeightHalfVisible)  { y -= 2.0*(h1+h2); }
    while(y <= -(2.0*(h1+h2)-2.0*HeightHalfVisible)) { y += 2.0*(h1+h2); }
    if(qAbs(y) <= HeightHalfVisible)
      painter.drawLine(QLineF(-16.0,y, 16.0,y));
  }


//  QFont font(font());   // font.setStyleStrategy(QFont::NoAntialias);
//  painter.setFont(font);



//=====  Roll:  =====

//painter.rotate(-RollAngle);

  painter.setBrush(QBrush(ColorRoll));

//- Triangle:
  painter.setPen(Qt::NoPen);
  mpointsF[0].setX(0.0);   mpointsF[0].setY(-rRoll);
  mpointsF[1].setX(-6.5);  mpointsF[1].setY(-rRoll - 11.258); //  11.258 = sqrt(3.0)/2.0 * 13.0
  mpointsF[2].setX(6.5);   mpointsF[2].setY(-rRoll - 11.258);
  painter.drawPolygon(mpointsF,3);

//- Arc:
  pen.setColor(ColorRoll);  pen.setWidthF(1.5);   painter.setPen(pen);
  painter.drawArc(QRectF(-rRoll, -rRoll, 2.0*rRoll, 2.0*rRoll), 30*16, 120*16);


  qreal hs1 = 5.0;
  qreal hs2 = 12.0;  qreal ws2 = 5.0;
  qreal hs3 = 10.0;
  yoff = -rRoll - hs2 - 10.0; //  - 5.0
  angle = 0.0;

  qreal dopangle;  // QString text;

  for(int k = -1; k <= 1; k += 2) {
    xoff = ws2/2.0*k;
//- (5), (10):
    dopangle = 10.0*k;  painter.rotate(dopangle);
    for(int i = 1; i <= 2; i++) {
      painter.drawLine(QPointF(0.0,-rRoll), QPointF(0.0,-rRoll-hs1));
      painter.rotate(dopangle);
    }

//- 30, (45), 60, (75):
    dopangle = 15.0*k;  angle = 15.0;
    for(int i = 1; i <= 2; i++) {
// 30, 60:
      angle += dopangle*k;  //  text.sprintf(("%.0f"),angle);
      DrawText(painter, xoff, yoff, angle); //text);
      mpointsF[0].setX(0.0);  mpointsF[0].setY(-rRoll);
      mpointsF[1].setX(0.0);  mpointsF[1].setY(-rRoll-hs2);
      mpointsF[2].setX(ws2*k);  mpointsF[2].setY(-rRoll-hs2);
      painter.drawPolyline(mpointsF, 3);
// (45), (75):
      painter.rotate(dopangle);
      painter.drawLine(QPointF(0.0,-rRoll), QPointF(0.0,-rRoll-hs3));

      painter.rotate(dopangle);
      angle += dopangle*k;
    }

//- 90:
    xoff = 1.0;
    angle += dopangle*k;  //  text.sprintf(("%.0f"),angle);
    DrawText(painter, xoff, yoff, angle); //text);
//    painter.drawLine(QPointF(0.0,-rRoll), QPointF(0.0, -rRoll-hs2));
//    painter.drawLine(QPointF(-4.0, -rRoll-hs2), QPointF(4.0, -rRoll-hs2));
    lines << QLineF(0.0,-rRoll, 0.0,-rRoll-hs2);
    lines << QLineF(-4.0,-rRoll-hs2, 4.0,-rRoll-hs2);
    painter.drawLines(lines);  lines.clear();

//- 120, 150:
    xoff = -ws2/2.0*k;
    dopangle = 30.0*k;    painter.rotate(dopangle);
    for(int i = 1; i <= 2; i++) {
      angle += dopangle*k;  //  text.sprintf(("%.0f"),angle);
      DrawText(painter, xoff, yoff, angle); //text);
      mpointsF[0].setX(0.0);  mpointsF[0].setY(-rRoll);
      mpointsF[1].setX(0.0);  mpointsF[1].setY(-rRoll-hs2);
      mpointsF[2].setX(-ws2*k);  mpointsF[2].setY(-rRoll-hs2);
      painter.drawPolyline(mpointsF, 3);

      painter.rotate(dopangle);
    }

    if(k == -1)  painter.rotate(180.0);
  }

//- 180:
  xoff = -1.0;
  angle += dopangle;  //  text.sprintf(("%.0f"),angle);
  DrawText(painter, xoff, yoff, angle); //text);
//  painter.drawLine(QPointF(0.0,-rRoll), QPointF(0.0,-rRoll-hs2));
//  painter.drawLine(QPointF(-3.0, -rRoll-hs2+4.0), QPointF(3.0, -rRoll-hs2+4.0));
//  painter.drawLine(QPointF(-6.0, -rRoll-hs2), QPointF(6.0, -rRoll-hs2));
  lines << QLineF(0.0,-rRoll, 0.0,-rRoll-hs2);
  lines << QLineF(-3.0,-rRoll-hs2+4.0, 3.0,-rRoll-hs2+4.0);
  lines << QLineF(-6.0,-rRoll-hs2, 6.0,-rRoll-hs2);
  painter.drawLines(lines);  lines.clear();
  painter.rotate(-180.0);


//=====  Static:  =====

  painter.rotate(RollAngle);

//  painter.setPen(Qt::NoPen);

//==Balance:

  pen.setColor(ColorStaticBalanceOutline);  pen.setWidthF(0.5);   painter.setPen(pen);

  linearGrad.setStart(0.0,    -3.5+1.5);
  linearGrad.setFinalStop(0.0, 3.5);
  linearGrad.setColorAt(0, ColorStaticBalance0);
  linearGrad.setColorAt(1, ColorStaticBalance1);
  QBrush brushBalance(linearGrad);   painter.setBrush(brushBalance);

//-Left:
  mpointsF[0].setX(-48.0-1.0);           mpointsF[0].setY(0.0);
  mpointsF[1].setX(-48.0-1.0-8.0);       mpointsF[1].setY(-3.5);
  mpointsF[2].setX(-48.0-1.0-8.0-24.0);  mpointsF[2].setY(-3.5);
  mpointsF[3].setX(-48.0-1.0-8.0-24.0);  mpointsF[3].setY(3.5);
  mpointsF[4].setX(-48.0-1.0-8.0);       mpointsF[4].setY(3.5);
  painter.drawPolygon(mpointsF,5);

//-Right:
  mpointsF[0].setX(48.0+1.0);          // mpointsF[0].setY(0.0);
  mpointsF[1].setX(48.0+1.0+8.0);      // mpointsF[1].setY(-3.5);
  mpointsF[2].setX(48.0+1.0+8.0+24.0); // mpointsF[2].setY(-3.5);
  mpointsF[3].setX(48.0+1.0+8.0+24.0); // mpointsF[3].setY(3.5);
  mpointsF[4].setX(48.0+1.0+8.0);      // mpointsF[4].setY(3.5);
  painter.drawPolygon(mpointsF,5);

//-Center:
  linearGrad.setStart(0.0,    0.0);
  linearGrad.setFinalStop(0.0, 12.0+6.0);
  linearGrad.setColorAt(0, ColorStaticBalance0);
  linearGrad.setColorAt(1, ColorStaticBalance1);
  QBrush brushBalanceCenter(linearGrad);   painter.setBrush(brushBalanceCenter);
  mpointsF[0].setX(0.0);            mpointsF[0].setY(0.0);
  mpointsF[1].setX(-30.0);          mpointsF[1].setY(12.0);
  mpointsF[2].setX(0.0);            mpointsF[2].setY(6.0);
  mpointsF[3].setX(30.0);           mpointsF[3].setY(12.0);
  painter.drawPolygon(mpointsF,4);

//- Triangle:
  painter.setBrush(QBrush(ColorStaticTriangle));
  mpointsF[0].setX(0.0);   mpointsF[0].setY(-rRoll);
  mpointsF[1].setX(6.5);   mpointsF[1].setY(-rRoll + 11.258); //  11.258 = sqrt(3.0)/2.0 * 13.0
  mpointsF[2].setX(-6.5);  mpointsF[2].setY(-rRoll + 11.258);
  painter.drawPolygon(mpointsF,3);


//=============================


/*
qreal cs = qCos(RollAngle/180.0*M_PI);   qreal acs = qAbs(cs);
qreal hPitchAngleCos = hPitchAngle*cs;

//qreal HeightHemiSphere = Height/AngleHeight*90.0;


  painter.translate(WidthHalf,HeightHalf);

while(hPitchAngle <= -(2.0*(h1+h2)-h2)) { hPitchAngle += 4.0*(h1+h2); }
while(hPitchAngle >=  (2.0*(h1+h2)-h2)) { hPitchAngle -= 4.0*(h1+h2); }

//if(hPitchAngle <= -(2.0*(h1+h2))) { hPitchAngle += 2.0*(h1+h2); }
//if(hPitchAngle >=  (2.0*(h1+h2))) { hPitchAngle -= 2.0*(h1+h2); }


painter.translate(0.0,hPitchAngle);

//while(hPitchAngle <= -(4.0*(h1+h2))) { hPitchAngle += 4.0*(h1+h2); }
//while(hPitchAngle >=  (4.0*(h1+h2))) { hPitchAngle -= 4.0*(h1+h2); }


  painter.rotate(-RollAngle);

//painter.translate(0.0,hPitchAngle);

//=====  Pitch:  =====


  painter.setPen(Qt::NoPen);

//-Sky:

// 0:
//  yh = hPitchAngle;
//yh = hPitchAngleCos; //*cs;
yh = 0.0;
//  while(yh <= -(4.0*(h1+h2)-2.0*qSqrt(2.0)*h1)) { yh += 4.0*(h1+h2); }
//  while(yh >=   4.0*(h1+h2)-2.0*qSqrt(2.0)*h1)  { yh -= 4.0*(h1+h2); }
//while(yh <= -(4.0*(h1+h2)-2.0*qSqrt(2.0)*h1)) { yh += 4.0*(h1+h2); }
//while(yh >=  (4.0*(h1+h2)-2.0*qSqrt(2.0)*h1))  { yh -= 4.0*(h1+h2); }
//yh += -hPitchAngle + hPitchAngleCos; //*cs;
//yh *= cs;
  linearGrad.setStart(0.0,     yh);
  linearGrad.setFinalStop(0.0, yh-h1);
  linearGrad.setColorAt(0, QColor(80,180,255, 255));
  linearGrad.setColorAt(1, QColor(0,0,100, 255));
  QBrush brushSky1(linearGrad);   painter.setBrush(brushSky1);
  painter.drawRect(-MaxDimHalf,yh+0.5, MaxDim,-h1-1.0);

//  yh = hPitchAngle-h1;
//yh = hPitchAngleCos-h1; //)*cs;
yh = -h1; //)*cs;
//  while(yh <= -(4.0*(h1+h2)-2.0*qSqrt(2.0)*h2)) { yh += 4.0*(h1+h2); }
//  while(yh >=   4.0*(h1+h2)-2.0*qSqrt(2.0)*h2)  { yh -= 4.0*(h1+h2); }
//while(yh <= -(4.0*(h1+h2)-2.0*qSqrt(2.0)*h2)) { yh += 4.0*(h1+h2); }
//while(yh >=  (4.0*(h1+h2)-2.0*qSqrt(2.0)*h2))  { yh -= 4.0*(h1+h2); }
//yh += -hPitchAngle + hPitchAngleCos; //*cs;
//yh *= cs;
  linearGrad.setStart(0.0,     yh);
  linearGrad.setFinalStop(0.0, yh-h2);
  linearGrad.setColorAt(0, QColor(0,0,100, 255));
  linearGrad.setColorAt(1, QColor(0,0,80, 255));
  QBrush brushSky2(linearGrad);   painter.setBrush(brushSky2);
  painter.drawRect(-MaxDimHalf,yh, MaxDim,-h2-1.0);

//90
//  yh = hPitchAngle-h1-h2;
//yh = hPitchAngleCos-h1-h2; //)*cs;
yh = -h1-h2; //)*cs;
//  while(yh <= -(4.0*(h1+h2)-2.0*qSqrt(2.0)*h2)) { yh += 4.0*(h1+h2); }
//  while(yh >=   4.0*(h1+h2)-2.0*qSqrt(2.0)*h2)  { yh -= 4.0*(h1+h2); }
//while(yh <= -(4.0*(h1+h2)-2.0*qSqrt(2.0)*h2)) { yh += 4.0*(h1+h2); }
//while(yh >=  (4.0*(h1+h2)-2.0*qSqrt(2.0)*h2))  { yh -= 4.0*(h1+h2); }
//yh += -hPitchAngle + hPitchAngleCos; //*cs;
//yh *= cs;
  linearGrad.setStart(0.0,     yh);
  linearGrad.setFinalStop(0.0, yh-h2);
  linearGrad.setColorAt(0, QColor(0,0,80, 255));
  linearGrad.setColorAt(1, QColor(0,0,100, 255));
  QBrush brushSky3(linearGrad);   painter.setBrush(brushSky3);
  painter.drawRect(-MaxDimHalf,yh, MaxDim,-h2-1.0);

//  yh = hPitchAngle-h1-h2-h2;
//yh = hPitchAngleCos-h1-h2-h2; //)*cs;
yh = -h1-h2-h2; //)*cs;
//  while(yh <= -(4.0*(h1+h2)-2.0*qSqrt(2.0)*h1)) { yh += 4.0*(h1+h2); }
//  while(yh >=   4.0*(h1+h2)-2.0*qSqrt(2.0)*h1)  { yh -= 4.0*(h1+h2); }
//while(yh <= -(4.0*(h1+h2)-2.0*qSqrt(2.0)*h1)) { yh += 4.0*(h1+h2); }
//while(yh >=  (4.0*(h1+h2)-2.0*qSqrt(2.0)*h1))  { yh -= 4.0*(h1+h2); }
//yh += -hPitchAngle + hPitchAngleCos; //*cs;
//yh *= cs;
  linearGrad.setStart(0.0,     yh);
  linearGrad.setFinalStop(0.0, yh-h1);
  linearGrad.setColorAt(0, QColor(0,0,100, 255));
  linearGrad.setColorAt(1, QColor(80,180,255, 255));
  QBrush brushSky4(linearGrad);   painter.setBrush(brushSky4);
  painter.drawRect(-MaxDimHalf,yh+0.5, MaxDim,-h1-1.0);
//180

//-Ground:

// 0:
//  yh = hPitchAngle;
//yh = hPitchAngleCos; //*cs;
yh = 0.0;//hPitchAngleCos; //*cs;
//  while(yh >=   4.0*(h1+h2)-2.0*qSqrt(2.0)*h1)  { yh -= 4.0*(h1+h2); }
//  while(yh <= -(4.0*(h1+h2)-2.0*qSqrt(2.0)*h1)) { yh += 4.0*(h1+h2); }
//while(yh >=  (4.0*(h1+h2)-2.0*qSqrt(2.0)*h1))  { yh -= 4.0*(h1+h2); }
//while(yh <= -(4.0*(h1+h2)-2.0*qSqrt(2.0)*h1)) { yh += 4.0*(h1+h2); }
//yh += -hPitchAngle + hPitchAngleCos; //*cs;
//yh *= cs;
  linearGrad.setStart(0.0,     yh);
  linearGrad.setFinalStop(0.0, yh+h1);
  linearGrad.setColorAt(0, QColor(90,170,110, 255));
  linearGrad.setColorAt(1, QColor(90,17,11, 255));
  QBrush brushGround1(linearGrad);   painter.setBrush(brushGround1);
  painter.drawRect(-MaxDimHalf,yh-0.5, MaxDim,h1+1.0);

//  yh = hPitchAngle+h1;
//yh = hPitchAngleCos+h1; //)*cs;
yh = h1; //)*cs;
//  while(yh >=   4.0*(h1+h2)-2.0*qSqrt(2.0)*h2)  { yh -= 4.0*(h1+h2); }
//  while(yh <= -(4.0*(h1+h2)-2.0*qSqrt(2.0)*h2)) { yh += 4.0*(h1+h2); }
//while(yh >=  (4.0*(h1+h2)-2.0*qSqrt(2.0)*h2))  { yh -= 4.0*(h1+h2); }
//while(yh <= -(4.0*(h1+h2)-2.0*qSqrt(2.0)*h2)) { yh += 4.0*(h1+h2); }
//yh += -hPitchAngle + hPitchAngleCos; //*cs;
//yh *= cs;
  linearGrad.setStart(0.0,     yh);
  linearGrad.setFinalStop(0.0, yh+h2);
  linearGrad.setColorAt(0, QColor(90,17,11, 255));
  linearGrad.setColorAt(1, QColor(0,17,11, 255));
  QBrush brushGround2(linearGrad);   painter.setBrush(brushGround2);
  painter.drawRect(-MaxDimHalf,yh, MaxDim,h2+1.0);

//90:
//  yh = hPitchAngle+h1+h2;
//yh = hPitchAngleCos+h1+h2; //)*cs;
yh = h1+h2; //)*cs;
//  while(yh >=   4.0*(h1+h2)-2.0*qSqrt(2.0)*h2)  { yh -= 4.0*(h1+h2); }
//  while(yh <= -(4.0*(h1+h2)-2.0*qSqrt(2.0)*h2)) { yh += 4.0*(h1+h2); }
//while(yh >=  (4.0*(h1+h2)-2.0*qSqrt(2.0)*h2))  { yh -= 4.0*(h1+h2); }
//while(yh <= -(4.0*(h1+h2)-2.0*qSqrt(2.0)*h2)) { yh += 4.0*(h1+h2); }
//yh += -hPitchAngle + hPitchAngleCos; //*cs;
//yh *= cs;
  linearGrad.setStart(0.0,     yh);
  linearGrad.setFinalStop(0.0, yh+h2);
  linearGrad.setColorAt(0, QColor(0,17,11, 255));
  linearGrad.setColorAt(1, QColor(90,17,11, 255));
  QBrush brushGround3(linearGrad);   painter.setBrush(brushGround3);
  painter.drawRect(-MaxDimHalf,yh, MaxDim,h2+1.0);

//  yh = hPitchAngle+h1+h2+h2;
//yh = hPitchAngleCos+h1+h2+h2; //)*cs;
yh = h1+h2+h2; //)*cs;
//  while(yh >=   4.0*(h1+h2)-2.0*qSqrt(2.0)*h1)  { yh -= 4.0*(h1+h2); }
//  while(yh <= -(4.0*(h1+h2)-2.0*qSqrt(2.0)*h1)) { yh += 4.0*(h1+h2); }
//while(yh >=  (4.0*(h1+h2)-2.0*qSqrt(2.0)*h1))  { yh -= 4.0*(h1+h2); }
//while(yh <= -(4.0*(h1+h2)-2.0*qSqrt(2.0)*h1)) { yh += 4.0*(h1+h2); }
//yh += -hPitchAngle + hPitchAngleCos; //*cs;
//yh *= cs;
  linearGrad.setStart(0.0,     yh);
  linearGrad.setFinalStop(0.0, yh+h1);
  linearGrad.setColorAt(0, QColor(90,17,11, 255));
  linearGrad.setColorAt(1, QColor(90,170,110, 255));
  QBrush brushGround4(linearGrad);   painter.setBrush(brushGround4);
  painter.drawRect(-MaxDimHalf,yh, MaxDim,h1);
//180



//painter.translate(0.0,-hPitchAngle);

painter.rotate(RollAngle);

painter.translate(0.0,-hPitchAngle);


//= Pitch Scale:


  QPen pen(QColor(255,255,255, 255));
  pen.setWidthF(1.0);
//  pen.setCapStyle(Qt::RoundCap);
//  pen.setJoinStyle(Qt::SvgMiterJoin); //Qt::RoundJoin); //Qt::BevelJoin); //Qt::MiterJoin);
  painter.setPen(pen);

//  qreal x,y;
  QVector<QLineF> lines;

//- (2)-degrees:
  qreal y;  bool isHas = false;
  for(int k = -1; k <= 1; k += 2) {
    y = hPitchAngle;
    while(y >=   2.0*(h1+h2)-2.0*HeightHalfVisible)  { y -= 2.0*(h1+h2); }
    while(y <= -(2.0*(h1+h2)-2.0*HeightHalfVisible)) { y += 2.0*(h1+h2); }
    for(int i = 1; i <= 4; i++) {
      y += -2.0*HOneDegreeAngle*k;
      if(qAbs(y) <= HeightHalfVisible) {  isHas = true;
        lines << QLineF(-8.0,y, 8.0,y);
      }
    }
  }
  if(isHas)  painter.drawLines(lines);
  lines.clear();

  pen.setWidthF(1.5);   painter.setPen(pen);

  qreal xoff, yoff;
  qreal angle;

//- 10-degrees:
  mpointsF[0].setX(-24.0);
  mpointsF[1].setX(-24.0);
  mpointsF[2].setX(24.0);
  mpointsF[3].setX(24.0);
  for(int k = -1; k <= 1; k += 2) {
    for(int i = 0; i <= 9; i++) {
      angle = 10.0*i;
      y = hPitchAngle - angle*HOneDegreeAngle*k;
      while(y >=   2.0*(h1+h2)-2.0*HeightHalfVisible)  { y -= 2.0*(h1+h2); }
      while(y <= -(2.0*(h1+h2)-2.0*HeightHalfVisible)) { y += 2.0*(h1+h2); }
      if(qAbs(y) <= HeightHalfVisible) {
        if(i == 0) {
          painter.drawLine(QLineF(-48.0,y, 48.0,y));
        }
        else if(i < 9) {
          mpointsF[0].setY(y + 5.0*k);
          mpointsF[1].setY(y);
          mpointsF[2].setY(y);
          mpointsF[3].setY(y + 5.0*k);
          painter.drawPolyline(mpointsF, 4); //int pointCount)
          DrawText(painter, -24.0-12.0+0.5, y+5.0/2.0*k, angle);
          DrawText(painter,  24.0+12.0+1.0, y+5.0/2.0*k, angle);
        }
        else {
          lines << QLineF(-36.0,y-7.0, -36.0,y+7.0);
          lines << QLineF(-36.0,y,      36.0,y);
          lines << QLineF( 36.0,y-7.0,  36.0,y+7.0);
          painter.drawLines(lines);  lines.clear();
          DrawText(painter, -36.0-12.0+1.0, y, angle);
          DrawText(painter,  36.0+12.0+1.0, y, angle);
        }
      }
    }

  }
//- (15)-degrees:
  for(int k = -1; k <= 1; k += 2) {
    y = hPitchAngle - 10.0*HOneDegreeAngle*(1.0+0.5)*k;
    while(y >=   2.0*(h1+h2)-2.0*HeightHalfVisible)  { y -= 2.0*(h1+h2); }
    while(y <= -(2.0*(h1+h2)-2.0*HeightHalfVisible)) { y += 2.0*(h1+h2); }
    if(qAbs(y) <= HeightHalfVisible)
      painter.drawLine(QLineF(-16.0,y, 16.0,y));
  }


//  QFont font(font());   // font.setStyleStrategy(QFont::NoAntialias);
//  painter.setFont(font);



//=====  Roll:  =====

painter.rotate(-RollAngle);

  painter.setBrush(QBrush(QColor(255,255,255, 255)));

//- Triangle:
  painter.setPen(Qt::NoPen);
  mpointsF[0].setX(0.0);   mpointsF[0].setY(-rRoll);
  mpointsF[1].setX(-6.5);  mpointsF[1].setY(-rRoll - 11.258); //  11.258 = sqrt(3.0)/2.0 * 13.0
  mpointsF[2].setX(6.5);   mpointsF[2].setY(-rRoll - 11.258);
  painter.drawPolygon(mpointsF,3);

//- Arc:
  pen.setWidthF(1.5);   painter.setPen(pen);
  painter.drawArc(QRectF(-rRoll, -rRoll, 2.0*rRoll, 2.0*rRoll), 30*16, 120*16);


  qreal hs1 = 5.0;
  qreal hs2 = 12.0;  qreal ws2 = 5.0;
  qreal hs3 = 10.0;
  yoff = -rRoll - hs2 - 10.0; //  - 5.0
  angle = 0.0;

  qreal dopangle;  // QString text;

  for(int k = -1; k <= 1; k += 2) {
    xoff = ws2/2.0*k;
//- (5), (10):
    dopangle = 10.0*k;  painter.rotate(dopangle);
    for(int i = 1; i <= 2; i++) {
      painter.drawLine(QPointF(0.0,-rRoll), QPointF(0.0,-rRoll-hs1));
      painter.rotate(dopangle);
    }

//- 30, (45), 60, (75):
    dopangle = 15.0*k;  angle = 15.0;
    for(int i = 1; i <= 2; i++) {
// 30, 60:
      angle += dopangle*k;  //  text.sprintf(("%.0f"),angle);
      DrawText(painter, xoff, yoff, angle); //text);
      mpointsF[0].setX(0.0);  mpointsF[0].setY(-rRoll);
      mpointsF[1].setX(0.0);  mpointsF[1].setY(-rRoll-hs2);
      mpointsF[2].setX(ws2*k);  mpointsF[2].setY(-rRoll-hs2);
      painter.drawPolyline(mpointsF, 3);
// (45), (75):
      painter.rotate(dopangle);
      painter.drawLine(QPointF(0.0,-rRoll), QPointF(0.0,-rRoll-hs3));

      painter.rotate(dopangle);
      angle += dopangle*k;
    }

//- 90:
    xoff = 1.0;
    angle += dopangle*k;  //  text.sprintf(("%.0f"),angle);
    DrawText(painter, xoff, yoff, angle); //text);
//    painter.drawLine(QPointF(0.0,-rRoll), QPointF(0.0, -rRoll-hs2));
//    painter.drawLine(QPointF(-4.0, -rRoll-hs2), QPointF(4.0, -rRoll-hs2));
    lines << QLineF(0.0,-rRoll, 0.0,-rRoll-hs2);
    lines << QLineF(-4.0,-rRoll-hs2, 4.0,-rRoll-hs2);
    painter.drawLines(lines);  lines.clear();

//- 120, 150:
    xoff = -ws2/2.0*k;
    dopangle = 30.0*k;    painter.rotate(dopangle);
    for(int i = 1; i <= 2; i++) {
      angle += dopangle*k;  //  text.sprintf(("%.0f"),angle);
      DrawText(painter, xoff, yoff, angle); //text);
      mpointsF[0].setX(0.0);  mpointsF[0].setY(-rRoll);
      mpointsF[1].setX(0.0);  mpointsF[1].setY(-rRoll-hs2);
      mpointsF[2].setX(-ws2*k);  mpointsF[2].setY(-rRoll-hs2);
      painter.drawPolyline(mpointsF, 3);

      painter.rotate(dopangle);
    }

    if(k == -1)  painter.rotate(180.0);
  }

//- 180:
  xoff = -1.0;
  angle += dopangle;  //  text.sprintf(("%.0f"),angle);
  DrawText(painter, xoff, yoff, angle); //text);
//  painter.drawLine(QPointF(0.0,-rRoll), QPointF(0.0,-rRoll-hs2));
//  painter.drawLine(QPointF(-3.0, -rRoll-hs2+4.0), QPointF(3.0, -rRoll-hs2+4.0));
//  painter.drawLine(QPointF(-6.0, -rRoll-hs2), QPointF(6.0, -rRoll-hs2));
  lines << QLineF(0.0,-rRoll, 0.0,-rRoll-hs2);
  lines << QLineF(-3.0,-rRoll-hs2+4.0, 3.0,-rRoll-hs2+4.0);
  lines << QLineF(-6.0,-rRoll-hs2, 6.0,-rRoll-hs2);
  painter.drawLines(lines);  lines.clear();
  painter.rotate(-180.0);

//=====  Static:  =====

  painter.rotate(RollAngle);

  painter.setPen(Qt::NoPen);

//-Balance:

  pen.setColor(Qt::black);
  pen.setWidthF(0.5);   painter.setPen(pen);

  linearGrad.setStart(0.0,    -3.5+1.5);
  linearGrad.setFinalStop(0.0, 3.5);
  linearGrad.setColorAt(0, QColor(255,255,0, 255));
  linearGrad.setColorAt(1, QColor(88,88,0, 255));
  QBrush brushBalance(linearGrad);   painter.setBrush(brushBalance);

//-Left:
  mpointsF[0].setX(-48.0-1.0);           mpointsF[0].setY(0.0);
  mpointsF[1].setX(-48.0-1.0-8.0);       mpointsF[1].setY(-3.5);
  mpointsF[2].setX(-48.0-1.0-8.0-24.0);  mpointsF[2].setY(-3.5);
  mpointsF[3].setX(-48.0-1.0-8.0-24.0);  mpointsF[3].setY(3.5);
  mpointsF[4].setX(-48.0-1.0-8.0);       mpointsF[4].setY(3.5);
  painter.drawPolygon(mpointsF,5);

//-Right:
  mpointsF[0].setX(48.0+1.0);          // mpointsF[0].setY(0.0);
  mpointsF[1].setX(48.0+1.0+8.0);      // mpointsF[1].setY(-3.5);
  mpointsF[2].setX(48.0+1.0+8.0+24.0); // mpointsF[2].setY(-3.5);
  mpointsF[3].setX(48.0+1.0+8.0+24.0); // mpointsF[3].setY(3.5);
  mpointsF[4].setX(48.0+1.0+8.0);      // mpointsF[4].setY(3.5);
  painter.drawPolygon(mpointsF,5);

//-Center:
  linearGrad.setStart(0.0,    0.0);
  linearGrad.setFinalStop(0.0, 12.0+6.0);
  linearGrad.setColorAt(0, QColor(255,255,0, 255));
  linearGrad.setColorAt(1, QColor(88,88,0, 255));
  QBrush brushBalanceCenter(linearGrad);   painter.setBrush(brushBalanceCenter);
  mpointsF[0].setX(0.0);            mpointsF[0].setY(0.0);
  mpointsF[1].setX(-30.0);          mpointsF[1].setY(12.0);
  mpointsF[2].setX(0.0);            mpointsF[2].setY(6.0);
  mpointsF[3].setX(30.0);           mpointsF[3].setY(12.0);
  painter.drawPolygon(mpointsF,4);

//- Triangle:
  painter.setBrush(QBrush(QColor(255,255,0, 255)));
  mpointsF[0].setX(0.0);   mpointsF[0].setY(-rRoll);
  mpointsF[1].setX(6.5);   mpointsF[1].setY(-rRoll + 11.258); //  11.258 = sqrt(3.0)/2.0 * 13.0
  mpointsF[2].setX(-6.5);  mpointsF[2].setY(-rRoll + 11.258);
  painter.drawPolygon(mpointsF,3);
*/
//==========================

  painter.setOpacity(0.6);
//  QPixmap pixmap = PEkranoplanGLWidget->renderPixmap(); //80,80);//,false);
//  bool b = pixmap.save("d:\\Progs\\WIGTS\\__TT.png", "PNG");
//  painter.drawPixmap(-40,-40, pixmap);
//  bool b2 = pixmap2.save("d:\\Progs\\WIGTS\\__TT2.png", "PNG");
//  QImage image = PEkranoplanGLWidget->grabFrameBuffer();
  QPixmap pixmap = QPixmap::fromImage(PEkranoplanGL->grabFrameBuffer());
  pixmap.setMask(pixmap.createMaskFromColor(QColor(0,0,0, 255)));
  painter.drawPixmap(-WidthHalf+1,HeightHalf-pixmap.rect().height()-1, pixmap);

/*
//GetPMainWnd()->statusBar()->hide();
//GetPMainWnd()->statusBar()->repaint();
QString s; s.sprintf("PitchAngle0 = %.1f,  RollAngle0 = %.1f;    PitchAngle = %.1f,  RollAngle = %.1f;", PitchAngle0,RollAngle0, PitchAngle,RollAngle);
GetPMainWnd()->statusBar()->showMessage(s);
GetPMainWnd()->statusBar()->repaint();
*/
}
예제 #24
0
void MainWindow::on_actionBrightness_gradient_triggered()
{
    QPixmap pixmap = pixmapItem->pixmap().copy();

    QImage image = pixmap.toImage();
    int width = image.width();
    int height = image.height();

    if (width == 0 || height == 0)
    {
        ui->statusBar->showMessage( tr("Error. Image bad size"), 3000 );
        return;
    }

    std::vector< std::vector<int> > grays( width, std::vector<int>(height) );
    for (int y = 0; y < height; ++y)
        for (int x = 0; x < width; ++x)
        {
            QRgb oldColor = image.pixel(x, y);
            int gray = qPow(
                       0.2126 * qPow(qRed(oldColor), 2.2) +
                       0.7152 * qPow(qGreen(oldColor), 2.2) +
                       0.0722 * qPow(qBlue(oldColor), 2.2),
                       1/2.2
                       );
            grays[x][y] = gray;
        }

    int G_x;
    int G_y;
    int G;
    unsigned long int dividend = 0;
    unsigned int divisor = 0;
    for (int y = 0; y < height; ++y)
        for (int x = 0; x < width; ++x)
        {
            if (x == 0)
                G_x = grays[x+1][y];
            else if (x == width - 1)
                G_x = grays[x-1][y];
            else
                G_x = grays[x+1][y] - grays[x-1][y];
            if (y == 0)
                G_y = grays[x][y+1];
            else if (y == height - 1)
                G_y = grays[x][y-1];
            else
                G_y = grays[x][y+1] - grays[x][y-1];
            G = qMax( qAbs(G_x), qAbs(G_y) );
            dividend += grays[x][y] * G;
            divisor += G;
        }

    int threshold = dividend / divisor;

    if (0 <= threshold && threshold <= 255)
    {
        QRgb black = qRgb(0,0,0);
        QRgb white = qRgb(255,255,255);
        QRgb newColor;
        for (int y = 0; y < height; ++y)
            for (int x = 0; x < width; ++x)
            {
                int gray = grays[x][y];
                if ( gray < threshold )
                    newColor = black;
                else
                    newColor = white;
                image.setPixel(x, y, newColor);
            }
    }
    else
        ui->statusBar->showMessage(tr("Error. Invalid threshold"), 3000);

    pixmap.convertFromImage(image);

    pixmapItem_2->setPixmap(pixmap);
    scene_2->setSceneRect(QRectF(pixmap.rect()));

    calcHist(pixmap, hist_2, maxLevel_2);
    drawHist(pixmapItem_4, hist_2, maxLevel_2);
}
예제 #25
0
 //________________________________________________
 void TransitionWidget::grabWidget( QPixmap& pixmap, QWidget* widget, QRect& rect ) const
 { widget->render( &pixmap, pixmap.rect().topLeft(), rect, QWidget::DrawChildren ); }
예제 #26
0
void MainWindow::on_actionOtsu_local_triggered()
{
    QPixmap pixmap = pixmapItem->pixmap().copy();

    QImage image = pixmap.toImage();
    int width = image.width();
    int height = image.height();

    if (width == 0 || height == 0)
    {
        ui->statusBar->showMessage( tr("Error. Image bad size"), 3000 );
        return;
    }

    DialogOtsuLocal dialog;
    dialog.setSpinBoxes(pixmapItem->pixmap().width(), pixmapItem->pixmap().height());

    if (dialog.exec() == QDialog::Rejected)
        return;

    std::vector<int> grays(width * height, 0);

    int countX = dialog.gridX();
    int countY = dialog.gridY();

    double shiftY = ( (double) height ) / countY;
    double shiftX = ( (double) width ) / countX;

    double curX = 0.0;
    double curY = 0.0;
    double nextX = 0.0;
    double nextY = 0.0;

    int cX;
    int cY;
    int nX;
    int nY;

    QRgb black = qRgb(0,0,0);
    QRgb white = qRgb(255,255,255);
    QRgb newColor;

    for (int i = 0; i < countY; ++i)
    {
        nextY += shiftY;
        cY = qFloor(curY);
        nY = qFloor(nextY);
        curX = 0.0;
        nextX = 0.0;
        for (int j = 0; j < countX; ++j)
        {
            nextX += shiftX;
            cX = qFloor(curX);
            nX = qFloor(nextX);

            int threshold = otsu(image, grays, cX, cY, nX, nY);

            for (int y = cY; y < nY; ++y)
                for (int x = cX; x < nX; ++x)
                {
                    int gray = grays[x + y * (nX - cX)];
                    if ( gray < threshold )
                        newColor = black;
                    else
                        newColor = white;
                    image.setPixel(x, y, newColor);
                }

            curX = nextX;
        }
        curY = nextY;
    }

    pixmap.convertFromImage(image);

    pixmapItem_2->setPixmap(pixmap);
    scene_2->setSceneRect(QRectF(pixmap.rect()));

    calcHist(pixmap, hist_2, maxLevel_2);
    drawHist(pixmapItem_4, hist_2, maxLevel_2);
}
예제 #27
0
void KniftyClient::update_captionBuffer()
{
    if (!KniftyHandler::initialized()) return;

    const uint maxCaptionLength = 300; // truncate captions longer than this!
    QString captionText(caption() );
    if (captionText.length() > maxCaptionLength) {
        captionText.truncate(maxCaptionLength);
        captionText.append(" [...]");
    }

    QFontMetrics fm(s_titleFont);
    int captionWidth  = fm.width(captionText);

    QPixmap textPixmap;
    QPainter painter;
    if(KniftyHandler::titleShadow())
    {
        // prepare the shadow
        textPixmap = QPixmap(captionWidth+2*2, s_titleHeight ); // 2*2 px shadow space
        textPixmap.fill(QColor(0,0,0));
        textPixmap.setMask( textPixmap.createHeuristicMask(TRUE) );
        painter.begin(&textPixmap);
        painter.setFont(s_titleFont);
        painter.setPen(white);
        painter.drawText(textPixmap.rect(), AlignCenter, captionText );
        painter.end();
    }

    QImage shadow;
    ShadowEngine se;

    // active
    aCaptionBuffer->resize(captionWidth+4, s_titleHeight ); // 4 px shadow
    painter.begin(aCaptionBuffer);
    painter.drawTiledPixmap(aCaptionBuffer->rect(), *aTitleBarTile);
    if(KniftyHandler::titleShadow())
    {
        shadow = se.makeShadow(textPixmap, QColor(0, 0, 0));
        painter.drawImage(1, 1, shadow);
    }
    painter.setFont(s_titleFont);
    painter.setPen(options()->color(KDecoration::ColorFont, true));
    painter.drawText(aCaptionBuffer->rect(), AlignCenter, captionText );
    painter.end();


    // inactive
    iCaptionBuffer->resize(captionWidth+4, s_titleHeight );
    painter.begin(iCaptionBuffer);
    painter.drawTiledPixmap(iCaptionBuffer->rect(), *iTitleBarTile);
    if(KniftyHandler::titleShadow())
    {
        painter.drawImage(1, 1, shadow);
    }
    painter.setFont(s_titleFont);
    painter.setPen(options()->color(KDecoration::ColorFont, false));
    painter.drawText(iCaptionBuffer->rect(), AlignCenter, captionText );
    painter.end();

    captionBufferDirty = false;
}
예제 #28
0
void MainWindow::on_actionBrightness_quantization_triggered()
{
    QPixmap pixmap = pixmapItem->pixmap().copy();

    QImage image = pixmap.toImage();
    int width = image.width();
    int height = image.height();

    if (width == 0 || height == 0)
    {
        ui->statusBar->showMessage( tr("Error. Image bad size"), 3000 );
        return;
    }

    std::vector<int> grays(width * height);

    for (int y = 0; y < height; ++y)
        for (int x = 0; x < width; ++x)
        {
            QRgb oldColor = image.pixel(x, y);
            int gray = qPow(
                       0.2126 * qPow(qRed(oldColor), 2.2) +
                       0.7152 * qPow(qGreen(oldColor), 2.2) +
                       0.0722 * qPow(qBlue(oldColor), 2.2),
                       1/2.2
                       );
            grays[x + y * width] = gray;
        }

    std::vector<unsigned int> Rs(256, 0);
    std::vector<unsigned int> Gs(256, 0);
    std::vector<unsigned int> Bs(256, 0);
    std::vector<int> hist(256, 0);
    for (int y = 0; y < height; ++y)
        for (int x = 0; x < width; ++x)
        {
            int num = grays[x + y * width];
            Rs[num] += qRed( image.pixel(x, y) );
            Gs[num] += qGreen( image.pixel(x, y) );
            Bs[num] += qBlue( image.pixel(x, y) );
            ++hist[num];
        }

    int quantsCountMaximum = 0;
    std::map<int, QRgb> colors;
    for (int i = 0; i < 256; ++i)
    {
        if (hist[i] == 0)
            continue;
        Rs[i] /= hist[i];
        Gs[i] /= hist[i];
        Bs[i] /= hist[i];
        colors[i] = qRgb(Rs[i], Gs[i], Bs[i]);
        ++quantsCountMaximum;
    }

    DialogQuantization dialog;
    dialog.setQuantCountMaximum(quantsCountMaximum);

    if (dialog.exec() == QDialog::Rejected)
        return;

    int quantsCount = dialog.quantsCount();

    double shift = 256 / quantsCount;
    double cur = 0.0;
    double next = 0.0;

    for (int i = 0; i < quantsCount; ++i)
    {
        next += shift;
        int c = qFloor(cur);
        int n = qFloor(next);

        int minC = 256;
        for (std::map<int, QRgb>::iterator it = colors.begin(); it != colors.end(); ++it)
            if (c <= (it->first) && (it->first) < n)
                if (it->first < minC)
                    minC = it->first;
        QRgb newColor = colors[minC];

        for (int y = 0; y < height; ++y)
            for (int x = 0; x < width; ++x)
            {
                int num = grays[x + y * width];
                if (c <= num && num < n)
                    image.setPixel(x, y, newColor);
                else
                    continue;
            }
        cur = next;
    }

    pixmap.convertFromImage(image);

    pixmapItem_2->setPixmap(pixmap);
    scene_2->setSceneRect(QRectF(pixmap.rect()));
    //ui->graphicsView_2->fitInView(scene_2->itemsBoundingRect(), Qt::KeepAspectRatio);

    calcHist(pixmap, hist_2, maxLevel_2);
    drawHist(pixmapItem_4, hist_2, maxLevel_2);
}
예제 #29
0
/******************************************************************************
*  Paint one value in one of the columns in the list view.
*/
void AlarmListViewItem::paintCell(QPainter *painter, const QColorGroup &cg, int column, int width, int /*align*/)
{
    const AlarmListView *listView = alarmListView();
    int    margin = listView->itemMargin();
    QRect  box(margin, margin, width - margin * 2, height() - margin * 2); // area within which to draw
    bool   selected = isSelected();
    QColor bgColour = selected ? cg.highlight() : cg.base();
    QColor fgColour = selected ? cg.highlightedText()
                      : !event().enabled() ? Preferences::disabledColour()
                      : event().expired() ? Preferences::expiredColour() : cg.text();
    painter->setPen(fgColour);
    painter->fillRect(0, 0, width, height(), bgColour);

    if(column == listView->column(AlarmListView::TIME_COLUMN))
    {
        int i = -1;
        QString str = text(column);
        if(mTimeHourPos >= 0)
        {
            // Need to pad out spacing to align times without leading zeroes
            i = str.find(" ~");
            if(i >= 0)
            {
                if(mDigitWidth < 0)
                    mDigitWidth = painter->fontMetrics().width("0");
                QString date = str.left(i + 1);
                int w = painter->fontMetrics().width(date) + mDigitWidth;
                painter->drawText(box, AlignVCenter, date);
                box.setLeft(box.left() + w);
                painter->drawText(box, AlignVCenter, str.mid(i + 2));
            }
        }
        if(i < 0)
            painter->drawText(box, AlignVCenter, str);
    }
    else if(column == listView->column(AlarmListView::TIME_TO_COLUMN))
        painter->drawText(box, AlignVCenter | AlignRight, text(column));
    else if(column == listView->column(AlarmListView::REPEAT_COLUMN))
        painter->drawText(box, AlignVCenter | AlignHCenter, text(column));
    else if(column == listView->column(AlarmListView::COLOUR_COLUMN))
    {
        // Paint the cell the colour of the alarm message
        if(event().action() == KAEvent::MESSAGE || event().action() == KAEvent::FILE)
            painter->fillRect(box, event().bgColour());
    }
    else if(column == listView->column(AlarmListView::TYPE_COLUMN))
    {
        // Display the alarm type icon, horizontally and vertically centred in the cell
        QPixmap *pixmap = eventIcon();
        QRect pixmapRect = pixmap->rect();
        int diff = box.height() - pixmap->height();
        if(diff < 0)
        {
            pixmapRect.setTop(-diff / 2);
            pixmapRect.setHeight(box.height());
        }
        QPoint iconTopLeft(box.left() + (box.width() - pixmapRect.width()) / 2,
                           box.top() + (diff > 0 ? diff / 2 : 0));
        painter->drawPixmap(iconTopLeft, *pixmap, pixmapRect);
    }
    else if(column == listView->column(AlarmListView::MESSAGE_COLUMN))
    {
        if(!selected  &&  listView->drawMessageInColour())
        {
            painter->fillRect(box, event().bgColour());
            painter->setBackgroundColor(event().bgColour());
            //			painter->setPen(event().fgColour());
        }
        QString txt = text(column);
        painter->drawText(box, AlignVCenter, txt);
        mMessageColWidth = listView->fontMetrics().boundingRect(txt).width();
    }
}
예제 #30
0
void AreaDialog::paintEvent(QPaintEvent* e)
{
  Q_UNUSED(e);

  if (mGrabbing) // grabWindow() should just get the background
    return;

  QPainter painter(this);

  QPalette pal = palette();
  QFont font   = QToolTip::font();

  QColor handleColor(85, 160, 188, 220);
  QColor overlayColor(0, 0, 0, mOverlayAlpha);
  QColor textColor = pal.color(QPalette::Active, QPalette::Text);
  QColor textBackgroundColor = pal.color(QPalette::Active, QPalette::Base);
  painter.drawPixmap(0, 0, mScreenshot->pixmap());
  painter.setFont(font);

  QRect r = mSelection.normalized().adjusted(0, 0, -1, -1);

  QRegion grey(rect());
  grey = grey.subtracted(r);
  painter.setPen(handleColor);
  painter.setBrush(overlayColor);
  painter.setClipRegion(grey);
  painter.drawRect(-1, -1, rect().width() + 1, rect().height() + 1);
  painter.setClipRect(rect());
  painter.setBrush(Qt::NoBrush);
  painter.drawRect(r);

  if (mShowHelp) {
    //Drawing the explanatory text.
    QRect helpRect = qApp->desktop()->screenGeometry(qApp->desktop()->primaryScreen());
    QString helpTxt = tr("Lightscreen area mode:\nUse your mouse to draw a rectangle to capture.\nPress any key or right click to exit.");

    helpRect.setHeight(qRound((float)(helpRect.height() / 10))); // We get a decently sized rect where the text should be drawn (centered)

    // We draw the white contrasting background for the text, using the same text and options to get the boundingRect that the text will have.
    painter.setPen(QPen(Qt::white));
    painter.setBrush(QBrush(QColor(255, 255, 255, 180), Qt::SolidPattern));
    QRectF bRect = painter.boundingRect(helpRect, Qt::AlignCenter, helpTxt);

    // These four calls provide padding for the rect
    bRect.setWidth(bRect.width() + 12);
    bRect.setHeight(bRect.height() + 10);
    bRect.setX(bRect.x() - 12);
    bRect.setY(bRect.y() - 10);

    painter.drawRoundedRect(bRect, 8, 8);

    // Draw the text:
    painter.setPen(QPen(Qt::black));
    painter.drawText(helpRect, Qt::AlignCenter, helpTxt);
  }

  if (!mSelection.isNull()) {
    // The grabbed region is everything which is covered by the drawn
    // rectangles (border included). This means that there is no 0px
    // selection, since a 0px wide rectangle will always be drawn as a line.
    QString txt = QString("%1x%2").arg(mSelection.width() == 0 ? 2 : mSelection.width())
        .arg(mSelection.height() == 0 ? 2 : mSelection.height());
    QRect textRect = painter.boundingRect(rect(), Qt::AlignLeft, txt);
    QRect boundingRect = textRect.adjusted(-4, 0, 0, 0);

    if (textRect.width() < r.width() - 2*mHandleSize &&
       textRect.height() < r.height() - 2*mHandleSize &&
       (r.width() > 100 && r.height() > 100)) // center, unsuitable for small selections
    {
      boundingRect.moveCenter(r.center());
      textRect.moveCenter(r.center());
    }
    else if (r.y() - 3 > textRect.height() &&
      r.x() + textRect.width() < rect().right()) // on top, left aligned
    {
      boundingRect.moveBottomLeft(QPoint(r.x(), r.y() - 3));
      textRect.moveBottomLeft(QPoint(r.x() + 2, r.y() - 3));
    }
    else if (r.x() - 3 > textRect.width()) // left, top aligned
    {
      boundingRect.moveTopRight(QPoint(r.x() - 3, r.y()));
      textRect.moveTopRight(QPoint(r.x() - 5, r.y()));
    }
    else if (r.bottom() + 3 + textRect.height() < rect().bottom() &&
      r.right() > textRect.width()) // at bottom, right aligned
    {
      boundingRect.moveTopRight(QPoint(r.right(), r.bottom() + 3));
      textRect.moveTopRight(QPoint(r.right() - 2, r.bottom() + 3));
    }
    else if (r.right() + textRect.width() + 3 < rect().width()) // right, bottom aligned
    {
      boundingRect.moveBottomLeft(QPoint(r.right() + 3, r.bottom()));
      textRect.moveBottomLeft(QPoint(r.right() + 5, r.bottom()));
    }
    // if the above didn't catch it, you are running on a very tiny screen...
    painter.setPen(textColor);
    painter.setBrush(textBackgroundColor);
    painter.drawRect(boundingRect);
    painter.drawText(textRect, txt);

    if ((r.height() > mHandleSize*2 && r.width() > mHandleSize*2)
      || !mMouseDown)
    {
      updateHandles();
      painter.setPen(handleColor);
      handleColor.setAlpha(80);
      painter.setBrush(handleColor);
      painter.drawRects(handleMask().rects());
    }
  }

  if (!mScreenshot->options().magnify)
    return;

  // Drawing the magnified version
  QPoint magStart, magEnd, drawPosition;
  QRect newRect;

  QRect pixmapRect = mScreenshot->pixmap().rect();

  if (mMouseMagnifier) {
    drawPosition = mMousePos - QPoint(100, 100);

    magStart = mMousePos - QPoint(50, 50);
    magEnd = mMousePos + QPoint(50, 50);

    newRect = QRect(magStart, magEnd);
  }
  else {
    // So pretty.. oh so pretty.
    if (mMouseOverHandle == &mTLHandle)
      magStart = mSelection.topLeft();
    else if (mMouseOverHandle == &mTRHandle)
      magStart = mSelection.topRight();
    else if (mMouseOverHandle == &mBLHandle)
      magStart = mSelection.bottomLeft();
    else if (mMouseOverHandle == &mBRHandle)
      magStart = mSelection.bottomRight();
    else if (mMouseOverHandle == &mLHandle)
      magStart = QPoint(mSelection.left(), mSelection.center().y());
    else if (mMouseOverHandle == &mTHandle)
      magStart = QPoint(mSelection.center().x(), mSelection.top());
    else if (mMouseOverHandle == &mRHandle)
      magStart = QPoint(mSelection.right(), mSelection.center().y());
    else if (mMouseOverHandle == &mBHandle)
      magStart =  QPoint(mSelection.center().x(), mSelection.bottom());
    else if (mMouseOverHandle == 0)
      magStart = mMousePos;

    magEnd = magStart;
    drawPosition = mSelection.bottomRight();

    magStart -= QPoint(50, 50);
    magEnd   += QPoint(50, 50);

    newRect = QRect(magStart, magEnd);

    if ((drawPosition.x()+newRect.width()*2) > pixmapRect.width())
      drawPosition.setX(drawPosition.x()-newRect.width()*2);

    if ((drawPosition.y()+newRect.height()*2) > pixmapRect.height())
      drawPosition.setY(drawPosition.y()-newRect.height()*2);

    if (drawPosition.y() == mSelection.bottomRight().y()-newRect.height()*2
     && drawPosition.x() == mSelection.bottomRight().x()-newRect.width()*2)
      painter.setOpacity(0.7);
  }

  if (!pixmapRect.contains(newRect, true) || drawPosition.x() <= 0 || drawPosition.y() <= 0)  {
    return;
  }

  QPixmap magnified = mScreenshot->pixmap().copy(newRect).scaled(QSize(newRect.width()*2, newRect.height()*2));

  QPainter magPainter(&magnified);
  magPainter.setPen(QPen(QBrush(QColor(35, 35, 35)), 2)); // Same border pen
  magPainter.drawRect(magnified.rect());

  if (!mMouseMagnifier) {
    magPainter.drawText(magnified.rect().center()-QPoint(4, -4), "+"); //Center minus the 4 pixels wide and across of the "+" -- TODO: Test alternative DPI settings.
  }

  painter.drawPixmap(drawPosition, magnified);
}