void RegionGrabber::paintEvent( QPaintEvent* e )
{
    Q_UNUSED( e );
    if ( grabbing ) // grabWindow() should just get the background
        return;

    QPainter painter( this );

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

    QColor handleColor = pal.color( QPalette::Active, QPalette::Highlight );
    handleColor.setAlpha( 160 );
    QColor overlayColor( 0, 0, 0, 160 );
    QColor textColor = pal.color( QPalette::Active, QPalette::Text );
    QColor textBackgroundColor = pal.color( QPalette::Active, QPalette::Base );
    painter.drawPixmap(0, 0, pixmap);
    painter.setFont(font);

    QRect r = selection;
    if ( !selection.isNull() )
    {
        QRegion grey( rect() );
        grey = grey.subtracted( r );
        painter.setClipRegion( grey );
        painter.setPen( Qt::NoPen );
        painter.setBrush( overlayColor );
        painter.drawRect( rect() );
        painter.setClipRect( rect() );
        drawRect( &painter, r, handleColor );
    }

    if ( showHelp )
    {
        painter.setPen( textColor );
        painter.setBrush( textBackgroundColor );
        QString helpText = "Select a region using the mouse. To take the snapshot, press the Enter key or double click. Press Esc to quit.";
        helpTextRect = painter.boundingRect( rect().adjusted( 2, 2, -2, -2 ), Qt::TextWordWrap, helpText );
        helpTextRect.adjust( -2, -2, 4, 2 );
        drawRect( &painter, helpTextRect, textColor, textBackgroundColor );
        painter.drawText( helpTextRect.adjusted( 3, 3, -3, -3 ), helpText );
    }

    if ( selection.isNull() )
    {
        return;
    }

    // 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( selection.width() )
                  .arg( selection.height() );
    QRect textRect = painter.boundingRect( rect(), Qt::AlignLeft, txt );
    QRect boundingRect = textRect.adjusted( -4, 0, 0, 0);

    if ( textRect.width() < r.width() - 2*handleSize &&
            textRect.height() < r.height() - 2*handleSize &&
            ( 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...
    drawRect( &painter, boundingRect, textColor, textBackgroundColor );

    painter.drawText( textRect, txt );

    if ( ( r.height() > handleSize*2 && r.width() > handleSize*2 )
            || !mouseDown )
    {
        updateHandles();
        painter.setPen( Qt::NoPen );
        painter.setBrush( handleColor );
        painter.setClipRegion( handleMask( StrokeMask ) );
        painter.drawRect( rect() );
        handleColor.setAlpha( 60 );
        painter.setBrush( handleColor );
        painter.setClipRegion( handleMask( FillMask ) );
        painter.drawRect( rect() );
    }
}
Example #2
0
Revrsi::Revrsi(QWidget *parent):
    QMainWindow(parent),
    ui(new Ui::Revrsi){
    ui->setupUi(this);

    // Init Windows
    this->ais             = new AI_settings(this);
    this->ngs             = new new_game_settings(this);
    this->serverInterface = new server_gui(this);
    this->clientInterface = new client_gui(this);
    this->winInterface    = new win_gui(this);
    this->ueber_gui       = new ueber(this);

    // Init GraphicsScene
    this->frame_scene = new QGraphicsScene(this);
    this->scene       = new QGraphicsScene(this);

    this->frame_scene->setSceneRect(0,0,1000,1000);
    this->scene->setSceneRect(00,000,700,500);
    ui->graphicsView->setScene(scene);
    ui->graphicsView->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
    this->sceneOffset_scale   = 1;
    this->sceneOffset_x       = 0;
    this->sceneOffset_y       = 0;

    //Init FieldSpecs
    this->height        = 8;
    this->width         = 8;
    this->player_num    = 2;
    this->player_act    = 1;

    //Init Booleans
    this->animatedPlayer= 0;
    this->direction     = 1;
    this->animationPlaying = false;
    this->FieldBackSet  = false;
    this->firstRun      = true;
    this->NetGameStart  = false;
    this->NetMode       = false;
    this->NewGame       = false;
    this->clientInit    = false;
    this->serverInit    = false;
    this->serverMode    = false;
    this->skipTurn      = false;

    //Do the Rest
    this->setupBackgroundTheme();
    this->seqGroup = new QSequentialAnimationGroup;

    //Init Logic here is mandatory
    this->logic = new Logic(this->width,this->width,this->player_num);
    this->logic->setInitStones();
    this->new_array = logic->getFields();

    // Zentriere Fenster
    QRect frect = frameGeometry();
    frect.moveCenter(QDesktopWidget().availableGeometry().center());
    move(frect.topLeft());

    ui->actionBeenden->setShortcut( QKeySequence("Ctrl+X") );
    ui->actionNeu->setShortcut(QKeySequence("F2"));
    ui->actionServer->setShortcut(QKeySequence("Ctrl+S"));
    ui->actionClient->setShortcut(QKeySequence("Ctrl+C"));
    ui->actionKI_Einstellungen->setShortcut(QKeySequence("Ctrl+A"));

    // Connections
    // Connect Menu Items
    connect(ui->actionNeu,              SIGNAL(triggered()), this,      SLOT(new_game_slot()));
    connect(ui->actionServer,           SIGNAL(triggered()), this,      SLOT(server_gui_slot()));
    connect(ui->actionClient,           SIGNAL(triggered()), this,      SLOT(client_gui_slot()));
    connect(ui->actionClient,           SIGNAL(triggered()), this,      SLOT(setNetModeEnabled()));
    connect(ui->actionKI_Einstellungen, SIGNAL(triggered()), this->ais, SLOT(show()));
    connect(ui->actionBeenden,          SIGNAL(triggered()), this,      SLOT(close()));
    connect(ui->action_ber,             SIGNAL(triggered()), this->ueber_gui,      SLOT(exec()));

    connect(this->ngs,  SIGNAL(accepted()),     this,   SLOT(set_proceed_newGame_true()));

    // Connect Toolbar Items
    connect(ui->actionZoom,     SIGNAL(triggered()), this, SLOT(zoom_in()));
    connect(ui->actionShrink,   SIGNAL(triggered()), this, SLOT(zoom_out()));

    // Connect Win Vector
    connect(this, SIGNAL(win(QVector<int>, QVector<QString>)),this->winInterface, SLOT(win_slot(QVector<int>, QVector<QString>)));

    // Connect Network
    connect(this->serverInterface, SIGNAL(startServer()),      this, SLOT(runServer()));
    connect(this->clientInterface, SIGNAL(send_startClient()), this, SLOT(runClient()));
    connect(this->clientInterface, SIGNAL(destroyed()),        this, SLOT(setNetModeDisabled()));

    this->new_game();
}
void NavigationDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    const NavigationModel::EdgeFlags edgeFlags = index.data(NavigationModel::ItemEdgeRole).value<NavigationModel::EdgeFlags>();
    const int r = 5;
    const int ox = option.rect.topLeft().x();
    const int oy = option.rect.topLeft().y();
    const int w = option.rect.width();
    const int h = option.rect.height();

    QPainterPath path(option.rect.topLeft());
    path.addRect(option.rect);

    if (edgeFlags.testFlag(NavigationModel::Top))
    {
        if (edgeFlags.testFlag(NavigationModel::Left))
        {
            // top-left
            QPainterPath sub(option.rect.topLeft());
            sub.lineTo(ox + r, oy);
            sub.arcTo(ox, oy, r * 2, r * 2, 90, 90);
            sub.closeSubpath();

            path = path.subtracted(sub);
        }
        else if (edgeFlags.testFlag(NavigationModel::Right))
        {
            // top-right
            QPainterPath sub(QPoint(ox + w, oy));
            sub.lineTo(ox + w - r, oy);
            sub.arcTo(ox + w - r * 2, oy, r * 2, r * 2, 90, -90);
            sub.closeSubpath();

            path = path.subtracted(sub);
        }
    }
    else if (edgeFlags.testFlag(NavigationModel::Bottom))
    {
        if (edgeFlags.testFlag(NavigationModel::Left))
        {
            // bottom-left
            QPainterPath sub(QPoint(ox, oy + h));
            sub.lineTo(ox, oy + h - r);
            sub.arcTo(ox, oy + h - r * 2, r * 2, r * 2, 180, 90);
            sub.closeSubpath();

            path = path.subtracted(sub);
        }
        else if (edgeFlags.testFlag(NavigationModel::Right))
        {
            // bottom-right
            QPainterPath sub(QPoint(ox + w, oy + h));
            sub.lineTo(ox + w, oy + h - r);
            sub.arcTo(ox + w - r * 2, oy + h - r * 2, r * 2, r * 2, 0, -90);
            sub.closeSubpath();

            path = path.subtracted(sub);
        }
    }

    painter->setPen(Qt::NoPen);
    painter->setRenderHint(QPainter::Antialiasing);
    if (index.data(NavigationModel::ItemHoveredRole).toBool())
        painter->fillPath(path, QColor::fromRgbF(1, 1, 1, 0.3));
    else
        painter->fillPath(path, QColor::fromRgbF(1, 1, 1, 0.2));

    const QString module = index.data().toString();
    if (module.isEmpty())
        return;

    const QString picFile = QString(":/%1/themes/dark/icons/nav_%1.svg").arg(module);

    QRect pixRect;
    QPixmap pixmap(loadPixmap(picFile));
    const qreal devicePixelRatio = qApp->devicePixelRatio();

    if (devicePixelRatio > 1.0) {
        pixRect = QRect(0, 0, pixmap.width() / devicePixelRatio, pixmap.height() / devicePixelRatio);
    } else {
        pixRect = pixmap.rect();
    }

    pixRect.moveCenter(option.rect.center());

    painter->drawPixmap(pixRect, pixmap);
}
Example #4
0
void LoginDialog::showEvent(QShowEvent *) {
	QRect geo = subwindow->geometry();
	geo.moveCenter(emarea->parentWidget()->rect().center());
	subwindow->setGeometry(geo);
}
Example #5
0
void QMapViewWidget::mouseMoveEvent(QMouseEvent *event) {
	switch (pMode) {
		case 0: {
				if (pSelectedItem >= -1)
					return;

				QRect rect = pBackBuffer.rect();
				rect.moveCenter(QPoint(width()/2-1, height()/2-1));
				if (rect.contains(event->pos())) {
					QPoint scenePos = event->pos() - rect.topLeft();
					scenePos.setX(scenePos.x() / pRectSize);
					scenePos.setY(scenePos.y() / pRectSize);

					switch (pSelectedItem) {
					case -2: // ice
						if (!QChar(pMap[scenePos.y()][scenePos.x()]).isLetter())
							pMap[scenePos.y()][scenePos.x()] = '.';
						redrawMap(scenePos.y(),scenePos.x(), 1, 1);
						break;
					case -3: // wall
						pMap[scenePos.y()][scenePos.x()] = '#';
						redrawMap(scenePos.y(),scenePos.x(), 1, 1);
						break;
					case -4: // red token
					case -5: // green token
					case -6: // blue token					
					case -7: // red dest
					case -8: // green dest
					case -9: // blue dest
						pNewToken = scenePos;
						break;
					default:
						break;
					}

					update();
					emit mapEdited();
				}
			}
			break;
		case 1: {
				if (pIsAnimationRun)
					return;

				QRect rect = pBackBuffer.rect();
				rect.moveCenter(QPoint(width()/2-1, height()/2-1));
				QPoint tokenMousePoint(pSelToken.x()*24+ 12 + rect.left(), pSelToken.y()*24 + 12 + rect.top());

				QLineF mouseVector(tokenMousePoint, event->pos());

				pNewTokenType = (mouseVector.length() <= 12) ? 0 : pSelTokenType;
			
				if (pNewTokenType)
					calculateSelDirArrow(tokenMousePoint, mouseVector.angle());
				else
					pSelDir = 0;


				update();
			}
			break;
		default:
			break;
	}
}
Example #6
0
void ProgressBar::paintEvent(QPaintEvent *)
{
    // TODO move font into Utils::StyleHelper
    // TODO use Utils::StyleHelper white

    if (bar.isNull())
        bar.load(StyleHelper::dpiSpecificImageFile(QLatin1String(":/core/images/progressbar.png")));

    double range = maximum() - minimum();
    double percent = 0.;
    if (range != 0)
        percent = (value() - minimum()) / range;
    if (percent > 1)
        percent = 1;
    else if (percent < 0)
        percent = 0;

    if (finished())
        percent = 1;

    QPainter p(this);
    QFont fnt(titleFont());
    p.setFont(fnt);
    QFontMetrics fm(fnt);

    int titleHeight = m_titleVisible ? fm.height() : 0;

    // Draw separator
    int separatorHeight = m_separatorVisible ? SEPARATOR_HEIGHT : 0;
    if (m_separatorVisible) {
        p.setPen(StyleHelper::sidebarShadow());
        p.drawLine(0,0, size().width(), 0);

        p.setPen(StyleHelper::sidebarHighlight());
        p.drawLine(1, 1, size().width(), 1);
    }

    if (m_titleVisible) {
        QRect textBounds = fm.boundingRect(m_title);
        textBounds.moveCenter(rect().center());
        int alignment = Qt::AlignHCenter;

        int textSpace = rect().width() - 8;
        // If there is not enough room when centered, we left align and
        // elide the text
        QString elidedtitle  = fm.elidedText(m_title, Qt::ElideRight, textSpace);

        QRect textRect = rect().adjusted(3, separatorHeight - 1, -3, 0);
        textRect.setHeight(titleHeight+5);

        p.setPen(QColor(0, 0, 0, 120));
        p.drawText(textRect, alignment | Qt::AlignBottom, elidedtitle);
        p.translate(0, -1);
        p.setPen(creatorTheme()->color(Theme::ProgressBarTitleColor));
        p.drawText(textRect, alignment | Qt::AlignBottom, elidedtitle);
        p.translate(0, 1);
    }

    m_progressHeight = PROGRESSBAR_HEIGHT;
    m_progressHeight += ((m_progressHeight % 2) + 1) % 2; // make odd
    // draw outer rect
    const QRect rect(INDENT - 1, titleHeight + separatorHeight + (m_titleVisible ? 4 : 3),
                     size().width() - 2 * INDENT + 1, m_progressHeight);

    if (creatorTheme()->flag(Theme::DrawProgressBarSunken))
        StyleHelper::drawCornerImage(bar, &p, rect, 3, 3, 3, 3);

    // draw inner rect
    QColor c = creatorTheme()->color(Theme::ProgressBarColorNormal);
    p.setPen(Qt::NoPen);

    QRectF inner = rect.adjusted(2, 2, -2, -2);
    inner.adjust(0, 0, qRound((percent - 1) * inner.width()), 0);
    if (m_error) {
        c = creatorTheme()->color(Theme::ProgressBarColorError);
        // avoid too small red bar
        if (inner.width() < 10)
            inner.adjust(0, 0, 10 - inner.width(), 0);
    } else if (m_finished) {
        c = creatorTheme()->color(Theme::ProgressBarColorFinished);
    }

    // Draw line and shadow after the gradient fill
    if (value() > 0 && value() < maximum()) {
        p.fillRect(QRect(inner.right(), inner.top(), 2, inner.height()), QColor(0, 0, 0, 20));
        p.fillRect(QRect(inner.right(), inner.top(), 1, inner.height()), QColor(0, 0, 0, 60));
    }
    p.setPen(Qt::NoPen);
    if (creatorTheme()->widgetStyle() == Theme::StyleFlat) {
        //draw the progress bar
        p.setBrush (c);
    } else {
        QLinearGradient grad(inner.topLeft(), inner.bottomLeft());
        grad.setColorAt(0, c.lighter(130));
        grad.setColorAt(0.4, c.lighter(106));
        grad.setColorAt(0.41, c.darker(106));
        grad.setColorAt(1, c.darker(130));
        p.setBrush(grad);
    }
    p.drawRect(inner);
    p.setBrush(Qt::NoBrush);
    p.setPen(QPen(QColor(0, 0, 0, 30), 1));

    p.drawLine(inner.topLeft() + QPointF(0.5, 0.5), inner.topRight() + QPointF(-0.5, 0.5));
    p.drawLine(inner.topLeft() + QPointF(0.5, 0.5), inner.bottomLeft() + QPointF(0.5, -0.5));
    p.drawLine(inner.topRight() + QPointF(-0.5, 0.5), inner.bottomRight() + QPointF(-0.5, -0.5));
    p.drawLine(inner.bottomLeft() + QPointF(0.5, -0.5), inner.bottomRight() + QPointF(-0.5, -0.5));

    if (m_cancelEnabled) {
        // Draw cancel button
        p.setOpacity(m_cancelButtonFader);

        if (value() < maximum() && !m_error) {
            m_cancelRect = QRect(rect.adjusted(rect.width() - CANCELBUTTON_WIDTH + 2, 1, 0, 0));
            const bool hover = m_cancelRect.contains(mapFromGlobal(QCursor::pos()));
            const QRectF cancelVisualRect(m_cancelRect.adjusted(0, 1, -2, -2));
            QLinearGradient grad(cancelVisualRect.topLeft(), cancelVisualRect.bottomLeft());
            int intensity = hover ? 90 : 70;
            QColor buttonColor(intensity, intensity, intensity, 255);
            grad.setColorAt(0, buttonColor.lighter(130));
            grad.setColorAt(1, buttonColor.darker(130));
            p.setPen(Qt::NoPen);
            p.setBrush(grad);
            p.drawRect(cancelVisualRect);

            p.setPen(QPen(QColor(0, 0, 0, 30)));
            p.drawLine(cancelVisualRect.topLeft() + QPointF(-0.5, 0.5), cancelVisualRect.bottomLeft() + QPointF(-0.5, -0.5));
            p.setPen(QPen(QColor(0, 0, 0, 120)));
            p.drawLine(cancelVisualRect.topLeft() + QPointF(0.5, 0.5), cancelVisualRect.bottomLeft() + QPointF(0.5, -0.5));
            p.setPen(QPen(QColor(255, 255, 255, 30)));
            p.drawLine(cancelVisualRect.topLeft() + QPointF(1.5, 0.5), cancelVisualRect.bottomLeft() + QPointF(1.5, -0.5));
            p.setPen(QPen(hover ? StyleHelper::panelTextColor() : QColor(180, 180, 180), 1.2, Qt::SolidLine, Qt::FlatCap));
            p.setRenderHint(QPainter::Antialiasing, true);
            p.drawLine(cancelVisualRect.topLeft() + QPointF(4.0, 2.0), cancelVisualRect.bottomRight() + QPointF(-3.0, -2.0));
            p.drawLine(cancelVisualRect.bottomLeft() + QPointF(4.0, -2.0), cancelVisualRect.topRight() + QPointF(-3.0, 2.0));
        }
    }
}
Example #7
0
QRect PopupDrawHelper::subControlRect(ComplexControl control, const QStyleOptionComplex* opt, SubControl subControl, const QWidget* widget) const
{
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
    QRect rect = QCommonStyle::subControlRect(control, opt, subControl, widget);
#else
    QRect rect = QWindowsStyle::subControlRect(control, opt, subControl, widget);
#endif

    switch (control) 
    {
        case CC_TitleBar:
            if (const StyleOptionPopupTitleBar* bar = qstyleoption_cast<const StyleOptionPopupTitleBar*>(opt)) 
            {
                const int controlMargin = 2;
                const int controlHeight = bar->rect.height() - controlMargin/* *2*/;
                const int delta = controlHeight + controlMargin;
                switch (subControl) 
                {
                    case SC_TitleBarLabel: 
                        {
                            QRect rc = opt->rect;
                            QRect labelRect = bar->fontMetrics.boundingRect(bar->text);
                            int titleBarHeight = proxy()->pixelMetric(PM_TitleBarHeight, opt, widget);
                            rc.setHeight(titleBarHeight); 
                            int width = labelRect.width();
                            labelRect.moveCenter(rc.center());
                            labelRect.setLeft(0);
                            labelRect.setWidth(qMax(rc.width(), width));

                            if (bar->subControls & SC_TitleBarCloseButton)
                            {
                              QRect ir = proxy()->subControlRect(CC_TitleBar, bar, SC_TitleBarCloseButton, widget);
                              labelRect.adjust(bar->subControls & SC_TitleBarSysMenu ? delta : controlMargin, 0, -ir.width(), controlMargin);
                            }
                            else
                              labelRect.adjust(bar->subControls & SC_TitleBarSysMenu ? delta : controlMargin, 0, controlMargin, controlMargin);
                            rect = labelRect;
                            break;
                        }
                    case SC_TitleBarCloseButton:
                        {
                            QRect rc = opt->rect;
                            QRect rcButton;
                            rcButton.setHeight(13);
                            rcButton.setWidth(13);
                            int titleBarHeight = proxy()->pixelMetric(PM_TitleBarHeight, opt, widget);
                            rc.setHeight(titleBarHeight); 
                            int offsetX = rc.right() - 13 - 2;
                            int offsetY = (rc.height() - rcButton.height())/2;
                            rcButton.translate(offsetX, offsetY);
                            rect = rcButton;
                            break;
                        }
                    case SC_TitleBarSysMenu :
                        {
                            QRect rc = opt->rect;
                            rc.setRect(bar->rect.left() + controlMargin, bar->rect.top() + controlMargin,
                                controlHeight, controlHeight);
                            rect = rc;
                            break;
                        }
                    default:
                        break;
                }
            }
            break;
        default:
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
            return QCommonStyle::subControlRect(control, opt, subControl, widget);
#else
            return QWindowsStyle::subControlRect(control, opt, subControl, widget);
#endif
    }

    return rect;
}
QRect CannonField::targetRect() const
{
	QRect result (0, 0, 20, 10);
	result.moveCenter (QPoint (target.x(), height() - 1 - target.y()));
	return result;
}
Example #9
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 );
}
Example #10
0
void AboutWindow::center()
{
    QRect frect = frameGeometry();
    frect.moveCenter(QDesktopWidget().availableGeometry().center());
    move(frect.topLeft());
}
Example #11
0
void CDisplay::drawFilter(QPainter *p)
{
    QRect size = this->geometry();
    int grid = 4;
    QPen penaxis(Qt::white, 1.0, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
    QPen pen(Qt::cyan, 2.0, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
    // Draw axis 1
    qreal axisx1 = (size.width()*1.75/grid);
    qreal axisx2 = (size.width()*1.25/grid);
    qreal axiswidth = axisx1 - axisx2;
    qreal axisy1 = size.height()*2/3;
    qreal axisy2 = size.height()*2.5/3 ;
    qreal axisheight = axisy2 -axisy1;
    qreal axismid = axisx1 + (axisx2 - axisx1)/2.0;
    qreal pos = 128*axiswidth/255.0;
    // Draw center axis
    p->setPen(penaxis);
    //draw bottom axis
    p->drawLine(QPointF(axisx1,axisy2), QPointF(axisx2,axisy2));
    penaxis.setStyle(Qt::DashLine);
    p->drawLine(QPointF(axismid, axisy1 ), QPointF(axismid,axisy2));
    penaxis.setStyle(Qt::SolidLine);

    // Draw Filter1 band
    p->setPen(pen);
    //top
    p->drawLine(QPointF(axisx2 + pos + (Filter1*axiswidth/460000.0) , axisy1 + axisheight * 2 /8), QPointF(axisx2 + pos - (Filter1*axiswidth/460000.0), axisy1 + axisheight * 2 /8));
    //left
    p->drawLine(QPointF(axisx2 + pos + (Filter1*axiswidth/460000.0) , axisy1 + axisheight * 2 /8), QPointF(axisx2 + pos + (Filter1*axiswidth/460000.0) + axiswidth/16.0 , axisy2));
    //right
    p->drawLine(QPointF(axisx2 + pos - (Filter1*axiswidth/460000.0) , axisy1 + axisheight * 2 /8), QPointF(axisx2 + pos - (Filter1*axiswidth/460000.0) - axiswidth/16.0 , axisy2));

    // Selection
    QColor cyan(Qt::cyan);
    QBrush brush(cyan);
    p->setBrush(brush);

    pen.setWidth(1.0);
    QFont font("Times", 8, QFont::Bold);
    QFontMetrics    fm(font);
    QRect           r = fm.boundingRect(QString("%1k").arg(Filter1/1000.0));
    r.moveCenter(QPoint(axismid,axisy2 +13.0));
    p->setFont(font);
    p->drawRoundRect(QRectF(axismid - axiswidth/4.0, axisy2 +8.0, axiswidth * 2 / 4, 10.0));
    pen.setColor(QColor(Qt::black));
    p->setPen(pen);
    p->drawText(r, QString("%1k").arg(Filter1/1000));
    pen.setColor(QColor(Qt::cyan));
    pen.setWidth(2.0);
    p->setPen(pen);

    // Draw axis 2
    axisx1 = (size.width()*3.75/grid);
    axisx2 = (size.width()*3.25/grid);
    axismid = axisx1 + (axisx2 - axisx1)/2.0;
    pos = 128*axiswidth/255.0;
    p->setPen(penaxis);
    //draw bottom axis
    p->drawLine(QPointF(axisx1,axisy2), QPointF(axisx2,axisy2));
    penaxis.setStyle(Qt::DashLine);
    p->drawLine(QPointF(axismid, axisy1 ), QPointF(axismid,axisy2));
    penaxis.setStyle(Qt::SolidLine);

    // Draw Filter2 band
    p->setPen(pen);
    // top
    p->drawLine(QPointF(axisx2 + pos - (Filter2*axiswidth/460000.0) , axisy1 + axisheight * 2 /8), QPointF(axisx2 + pos +  (Filter2*axiswidth/460000.0), axisy1 + axisheight * 2 /8));
    //left
    p->drawLine(QPointF(axisx2 + pos - (Filter2*axiswidth/460000.0) , axisy1 + axisheight * 2 /8), QPointF(axisx2 + pos - (Filter2*axiswidth/460000.0) - axiswidth/16.0 , axisy2));
    //right
    p->drawLine(QPointF(axisx2 + pos + (Filter2*axiswidth/460000.0) , axisy1 + axisheight * 2 /8), QPointF(axisx2 + pos + (Filter2*axiswidth/460000.0) + axiswidth/16.0 , axisy2));

    // Selection
    pen.setWidth(1.0);
    p->setPen(pen);
    r = fm.boundingRect(QString("%1k").arg(Filter2/1000.0));
    r.moveCenter(QPoint(axismid,axisy2 +13.0));
    p->setFont(font);
    p->drawRoundRect(QRectF(axismid - axiswidth/4.0, axisy2 +8.0, axiswidth * 2 / 4, 10.0));
    pen.setColor(QColor(Qt::black));
    p->setPen(pen);
    p->drawText(r, QString("%1k").arg(Filter2/1000));
    pen.setColor(QColor(Qt::cyan));

}
Example #12
0
void FreeRotationFilter::filterImage()
{
    int          progress;
    register int w, h, nw, nh, j, i = 0;
    int          nNewHeight, nNewWidth;
    int          nhdx, nhdy, nhsx, nhsy;
    double       lfSin, lfCos, lfx, lfy;

    int nWidth  = m_orgImage.width();
    int nHeight = m_orgImage.height();

    uchar* pBits            = m_orgImage.bits();
    unsigned short* pBits16 = (unsigned short*)m_orgImage.bits();

    // first of all, we need to calculate the sin and cos of the given angle

    lfSin = sin(d->settings.angle * -d->DEG2RAD);
    lfCos = cos(d->settings.angle * -d->DEG2RAD);

    // now, we have to calc the new size for the destination image

    if ((lfSin * lfCos) < 0)
    {
        nNewWidth  = lround (fabs (nWidth * lfCos - nHeight * lfSin));
        nNewHeight = lround (fabs (nWidth * lfSin - nHeight * lfCos));
    }
    else
    {
        nNewWidth  = lround (fabs (nWidth * lfCos + nHeight * lfSin));
        nNewHeight = lround (fabs (nWidth * lfSin + nHeight * lfCos));
    }

    // getting the destination's center position

    nhdx = nNewWidth  / 2;
    nhdy = nNewHeight / 2;

    // getting the source's center position

    nhsx = nWidth  / 2;
    nhsy = nHeight / 2;

    // now, we have to alloc a new image

    bool sixteenBit = m_orgImage.sixteenBit();
    m_destImage     = DImg(nNewWidth, nNewHeight, sixteenBit, m_orgImage.hasAlpha());

    if (m_destImage.isNull())
    {
        return;
    }

    m_destImage.fill( DColor(d->settings.backgroundColor.rgb(), sixteenBit) );

    uchar* pResBits            = m_destImage.bits();
    unsigned short* pResBits16 = (unsigned short*)m_destImage.bits();

    PixelsAliasFilter alias;

    // main loop

    for (h = 0; runningFlag() && (h < nNewHeight); ++h)
    {
        nh = h - nhdy;

        for (w = 0; runningFlag() && (w < nNewWidth); ++w)
        {
            nw = w - nhdx;

            i = setPosition (nNewWidth, w, h);

            lfx = (double)nw * lfCos - (double)nh * lfSin + nhsx;
            lfy = (double)nw * lfSin + (double)nh * lfCos + nhsy;

            if (isInside (nWidth, nHeight, (int)lfx, (int)lfy))
            {
                if (d->settings.antiAlias)
                {
                    if (!sixteenBit)
                        alias.pixelAntiAliasing(pBits, nWidth, nHeight, lfx, lfy,
                                                &pResBits[i+3], &pResBits[i+2],
                                                &pResBits[i+1], &pResBits[i]);
                    else
                        alias.pixelAntiAliasing16(pBits16, nWidth, nHeight, lfx, lfy,
                                                  &pResBits16[i+3], &pResBits16[i+2],
                                                  &pResBits16[i+1], &pResBits16[i]);
                }
                else
                {
                    j = setPosition (nWidth, (int)lfx, (int)lfy);

                    for (int p = 0 ; p < 4 ; ++p)
                    {
                        if (!sixteenBit)
                        {
                            pResBits[i] = pBits[j];
                        }
                        else
                        {
                            pResBits16[i] = pBits16[j];
                        }

                        ++i;
                        ++j;
                    }
                }
            }
        }

        // Update the progress bar in dialog.
        progress = (int) (((double) h * 100.0) / nNewHeight);

        if (progress % 5 == 0)
        {
            postProgress(progress);
        }
    }

    // Compute the rotated destination image size using original image dimensions.
    int    W, H;
    double absAngle = fabs(d->settings.angle);

    // stop here when no angle was set
    if (absAngle == 0.0)
    {
        return;
    }

    if (absAngle < 90.0)
    {
        W = (int)(d->settings.orgW * cos(absAngle * d->DEG2RAD) + d->settings.orgH * sin(absAngle * d->DEG2RAD));
        H = (int)(d->settings.orgH * cos(absAngle * d->DEG2RAD) + d->settings.orgW * sin(absAngle * d->DEG2RAD));
    }
    else
    {
        H = (int)(d->settings.orgW * cos((absAngle-90.0) * d->DEG2RAD) + d->settings.orgH * sin((absAngle-90.0) * d->DEG2RAD));
        W = (int)(d->settings.orgH * cos((absAngle-90.0) * d->DEG2RAD) + d->settings.orgW * sin((absAngle-90.0) * d->DEG2RAD));
    }

    // Auto-cropping destination image without black holes around.
    QRect autoCrop;

    switch (d->settings.autoCrop)
    {
        case FreeRotationContainer::WidestArea:
        {
            // 'Widest Area' method (by Renchi Raju).

            autoCrop.setX((int) (nHeight * sin(absAngle * d->DEG2RAD)));
            autoCrop.setY((int) (nWidth  * sin(absAngle * d->DEG2RAD)));
            autoCrop.setWidth((int)  (nNewWidth  - 2* nHeight * sin(absAngle * d->DEG2RAD)));
            autoCrop.setHeight((int) (nNewHeight - 2* nWidth  * sin(absAngle * d->DEG2RAD)));

            if (!autoCrop.isValid())
            {
                m_destImage = DImg(m_orgImage.width(), m_orgImage.height(), m_orgImage.sixteenBit(),
                                   m_orgImage.hasAlpha());
                m_destImage.fill(DColor(d->settings.backgroundColor.rgb(), sixteenBit));
                d->settings.newSize   = QSize();
            }
            else
            {
                m_destImage = m_destImage.copy(autoCrop);
                d->settings.newSize.setWidth((int)  (W - 2* d->settings.orgH * sin(absAngle * d->DEG2RAD)));
                d->settings.newSize.setHeight((int) (H - 2* d->settings.orgW * sin(absAngle * d->DEG2RAD)));
            }

            break;
        }

        case FreeRotationContainer::LargestArea:
        {
            // 'Largest Area' method (by Gerhard Kulzer).

            float gamma = 0.0f;

            if (nHeight > nWidth)
            {
                gamma = atan((float) nWidth / (float) nHeight);

                if (absAngle < 90.0)
                {
                    autoCrop.setHeight((int) ((float) nWidth / cos(absAngle * d->DEG2RAD) / (tan(gamma) +
                                              tan(absAngle * d->DEG2RAD))));
                    autoCrop.setWidth((int) ((float) autoCrop.height() * tan(gamma)));
                }
                else
                {
                    autoCrop.setWidth((int) ((float) nWidth / cos((absAngle - 90.0) * d->DEG2RAD) / (tan(gamma) +
                                             tan((absAngle - 90.0) * d->DEG2RAD))));
                    autoCrop.setHeight((int) ((float) autoCrop.width() * tan(gamma)));
                }
            }
            else
            {
                gamma = atan((float) nHeight / (float) nWidth);

                if (absAngle < 90.0)
                {
                    autoCrop.setWidth((int) ((float) nHeight / cos(absAngle * d->DEG2RAD) / (tan(gamma) +
                                             tan(absAngle * d->DEG2RAD))));
                    autoCrop.setHeight((int) ((float) autoCrop.width() * tan(gamma)));
                }
                else
                {
                    autoCrop.setHeight((int) ((float) nHeight / cos((absAngle - 90.0) * d->DEG2RAD) /
                                              (tan(gamma) + tan((absAngle - 90.0) * d->DEG2RAD))));
                    autoCrop.setWidth((int) ((float) autoCrop.height() * tan(gamma)));
                }
            }

            autoCrop.moveCenter(QPoint(nNewWidth / 2, nNewHeight / 2));

            if (!autoCrop.isValid())
            {
                m_destImage = DImg(m_orgImage.width(), m_orgImage.height(), m_orgImage.sixteenBit(),
                                   m_orgImage.hasAlpha());
                m_destImage.fill(DColor(d->settings.backgroundColor.rgb(), sixteenBit));
                d->settings.newSize   = QSize();
            }
            else
            {
                m_destImage = m_destImage.copy(autoCrop);
                gamma       = atan((float) d->settings.orgH / (float) d->settings.orgW);

                if (absAngle < 90.0)
                {
                    d->settings.newSize.setWidth((int) ((float) d->settings.orgH / cos(absAngle * d->DEG2RAD) / (tan(gamma) +
                                                        tan(absAngle * d->DEG2RAD))));
                    d->settings.newSize.setHeight((int) ((float) d->settings.newSize.width() * tan(gamma)));
                }
                else
                {
                    d->settings.newSize.setHeight((int) ((float) d->settings.orgH / cos((absAngle - 90.0) * d->DEG2RAD) /
                                                         (tan(gamma) + tan((absAngle - 90.0) * d->DEG2RAD))));
                    d->settings.newSize.setWidth((int) ((float) d->settings.newSize.height() * tan(gamma)));
                }
            }

            break;
        }

        default: // No auto cropping.
        {
            d->settings.newSize.setWidth(W);
            d->settings.newSize.setHeight(H);
            break;
        }
    }
}
Example #13
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);
}
Example #14
0
void RegionGrab::paintEvent(QPaintEvent *event)
{
  Q_UNUSED( event );
  if (m_grabbing)
    return;

  QPainter painter( this );

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

  QColor handleColor = pal.color(QPalette::Active, QPalette::Highlight);
  handleColor.setAlpha(160);
  QColor overlayColor(0, 0, 0, 100);
  QColor textColor = pal.color(QPalette::Active, QPalette::Text);
  QColor textBackgroundColor = pal.color(QPalette::Active, QPalette::Base);
  painter.drawPixmap(0, 0, m_pixmap);
  painter.setFont(font);

  const QRect& r = m_selection;

  if (r.isNull()) {
    painter.setClipRegion(QRegion(rect()));
    painter.setPen(Qt::NoPen);
    painter.setBrush(overlayColor);
    painter.drawRect(rect());
  }
  else {
    painter.setClipRegion(QRegion(rect()).subtracted(r));
    painter.setPen(Qt::NoPen);
    painter.setBrush(overlayColor);
    painter.drawRect(rect());
    painter.setClipRect(rect());
    drawRect(&painter, r, handleColor);
  }

  // \bug Подсказка центрируется не правильно в многомониторной конфигурации.
  if (m_showHelp) {
    painter.setPen(textColor);
    painter.setBrush(textBackgroundColor);
    QString helpText = tr("Select a region using the mouse. To take the snapshot, press the Enter key or double click. Press Esc to quit.");
    QRect scrRect    = QApplication::desktop()->screenGeometry(QApplication::desktop()->primaryScreen());

    m_helpTextRect = painter.boundingRect(scrRect.adjusted(20, 20, -20, -20), Qt::AlignHCenter, helpText);
    m_helpTextRect.adjust(-4, -4, 8, 4);
    drawRect(&painter, m_helpTextRect, textColor, textBackgroundColor);
    painter.drawText(m_helpTextRect.adjusted(3, 3, -3, -3), helpText);
  }

  if (r.isNull())
    return;

  // 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(r.width()).arg(r.height());
  QRect textRect = painter.boundingRect(rect(), Qt::AlignLeft, txt);
  QRect boundingRect = textRect.adjusted(-4, 0, 0, 0);

  // center, unsuitable for small selections
  if (textRect.width() < r.width() - 2 * m_handleSize && textRect.height() < r.height() - 2 * m_handleSize && (r.width() > 100 && r.height() > 100)) {
    boundingRect.moveCenter(r.center());
    textRect.moveCenter(r.center());
  }
  // on top, left aligned
  else if (r.y() - 3 > textRect.height() && r.x() + textRect.width() < rect().right()) {
    boundingRect.moveBottomLeft(QPoint(r.x(), r.y() - 3));
    textRect.moveBottomLeft(QPoint(r.x() + 2, r.y() - 3));
  }
  // left, top aligned
  else if (r.x() - 3 > textRect.width()) {
    boundingRect.moveTopRight(QPoint(r.x() - 3, r.y()));
    textRect.moveTopRight(QPoint(r.x() - 5, r.y()));
  }
  // at bottom, right aligned
  else if (r.bottom() + 3 + textRect.height() < rect().bottom() && r.right() > textRect.width()) {
    boundingRect.moveTopRight(QPoint(r.right(), r.bottom() + 3));
    textRect.moveTopRight(QPoint(r.right() - 2, r.bottom() + 3));
  }
  // right, bottom aligned
  else if (r.right() + textRect.width() + 3 < rect().width()) {
    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...
  drawRect(&painter, boundingRect, textColor, textBackgroundColor);

  painter.drawText(textRect, txt);

  if ((r.height() > m_handleSize * 2 && r.width() > m_handleSize * 2) || !m_mouseDown) {
    updateHandles();
    painter.setPen(Qt::NoPen);
    painter.setBrush(handleColor);
    painter.setClipRegion(handleMask(StrokeMask));
    painter.drawRect(rect());
    handleColor.setAlpha(60);
    painter.setBrush(handleColor);
    painter.setClipRegion(handleMask(FillMask));
    painter.drawRect(rect());
  }
}
Example #15
0
Tomatime::Tomatime(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::Tomatime)
{
    QCoreApplication::setOrganizationName("Tomatime");
    QCoreApplication::setOrganizationDomain("github.com");
    QCoreApplication::setApplicationName("tomatime");

    ui->setupUi(this);

    // Don't forget to define this
    timer = new QTimer(this);
    timeValue = new QTime();
    restoreAction = new QAction(this);
    quitAction = new QAction(this);
    trayIcon = new QSystemTrayIcon(this);
    trayIconMenu = new QMenu(this);

    // Init Child Dialog
    settingDialog = new Settings(this);
    aboutWidget = new About(this);

    // Initialize value from setting
    QSettings setting;

    setWorkingTime( (setting.value("time/working").isNull() == true ) ? setting.value("time/break", 25).toInt() : setting.value("time/working").toInt() );
    setBreakTime( (setting.value("time/break").isNull() == true ) ? setting.value("time/break", 5).toInt() : setting.value("time/break").toInt() );
    setLongBreakTime( (setting.value("time/longbreak").isNull() ) ? setting.value("time/longbreak", 10).toInt() : setting.value("time/longbreak").toInt() );


    connect(ui->start_button, SIGNAL(clicked()),this, SLOT(clickedStartButton()));
    connect(ui->settings_button, SIGNAL(clicked()),this, SLOT(clickedSettingsButton()));
    connect(ui->stop_button, SIGNAL(clicked()),this, SLOT(clickedStopButton()));

    connect(ui->actionSettings, SIGNAL(triggered()),this,SLOT(settingsMenu()));
    connect(ui->actionAbout, SIGNAL(triggered()),this,SLOT(aboutMenu()));

    // Listen signal from setting
    connect(settingDialog,SIGNAL(emitWorkingTimeValue(int)),this,SLOT(setWorkingTime(int)));
    connect(settingDialog,SIGNAL(emitBreakTimeValue(int)),this,SLOT(setBreakTime(int)));
    connect(settingDialog,SIGNAL(emitLongBreakTimeValue(int)),this,SLOT(setLongBreakTime(int)));
    connect(settingDialog,SIGNAL(emitSetTimer(int,int)),this,SLOT(setTimer(int,int)));

    // Recenter form
    QRect position = frameGeometry();
    position.moveCenter(QDesktopWidget().availableGeometry().center());
    move(position.topLeft());

    // Init LCD
    ui->lcdNumber->display(QTime(0,getWorkingTime(),0).toString());

    // Init working count
    workingCount = 0;

    // Init Timer mode
    // 0 = Working
    // 1 = Short Break
    // 2 = Long Break
    timerMode = 0;

    // Init System tray
    createActions();
    createTrayIcon();
    trayIcon->show();

}
Example #16
0
void
Style::drawDial(const QStyleOptionComplex *option, QPainter *painter, const QWidget *) const
{
    ASSURE_OPTION(dial, Slider);

    OPT_ENABLED OPT_HOVER OPT_FOCUS
    SAVE_PAINTER(Pen|Brush|Alias|Font);

    QRect rect = RECT;
    if (rect.width() > rect.height()) {
        rect.setLeft(rect.x()+(rect.width()-rect.height())/2);
        rect.setWidth(rect.height());
    } else {
        rect.setTop(rect.y()+(rect.height()-rect.width())/2);
        rect.setHeight(rect.width());
    }

    int d = qMin(2*rect.width()/5, config.slider.thickness);
    int r = (rect.width()-d)/2;

    // angle calculation from qcommonstyle.cpp (c) Trolltech 1992-2007, ASA.
    float a;
    if (dial->maximum == dial->minimum)
        a = M_PI / 2;
    else if (dial->dialWrapping)
        a = M_PI * 3 / 2 - (dial->sliderValue - dial->minimum) * 2 * M_PI / (dial->maximum - dial->minimum);
    else
        a = (M_PI * 8 - (dial->sliderValue - dial->minimum) * 10 * M_PI / (dial->maximum - dial->minimum)) / 6;

    QPoint cp = rect.center() + QPoint(qRound(r * cos(a)), -qRound(r * sin(a)));

    // the huge ring =======================================
    r = d/2+1; rect.adjust(r,r,-r,-r);

    painter->setBrush(Qt::NoBrush);
    painter->setRenderHint( QPainter::Antialiasing );
    const int start = -(dial->dialWrapping ? 90 : 120)*16;
    const int span = -16*(dial->dialWrapping ? 360 : 300)*(dial->sliderValue - dial->minimum)/(dial->maximum - dial->minimum);
    QPen pen;
    if (dial->sliderValue != dial->maximum) {
        QPen pen(GROOVE_COLOR, d);
        pen.setCapStyle(Qt::RoundCap);
        painter->setPen(pen);
        painter->drawArc(rect, start + span, -((dial->dialWrapping ? 360 : 300)*16 + span));
    }
    if (dial->sliderValue != dial->minimum) {
        QPen pen(THERMOMETER_COLOR, d - 2*(d/THERMOMETER_FACTOR));
        pen.setCapStyle(Qt::RoundCap);
        painter->setPen(pen);
        painter->drawArc(rect, start, span);
    }

    // the value ==============================================
    QFont fnt = painter->font();
    int h = rect.height()/2;
    h -= 2 * (h - qMin(h, painter->fontMetrics().xHeight())) / 3;
    fnt.setPixelSize( h );
    painter->setFont(fnt);
    painter->setPen(FX::blend(PAL.background().color(), PAL.foreground().color(),!hasFocus,2));
    drawItemText(painter, rect,  Qt::AlignCenter, PAL, isEnabled, QString::number(dial->sliderValue));

    // the drop ===========================
    if (isEnabled) {
        rect = QRect(0,0,d,d);
        rect.moveCenter(cp);
        drawSliderHandle(rect, option, painter, hover * 6);
    }

    RESTORE_PAINTER
}
Example #17
0
void Score::paintEvent( QPaintEvent *e)
{
    if (rect(1, 0, tr("  1UP ")).intersects(e->rect())) {
        QPixmap pix;
        QColor fg = BLACK;
        if (cursor.on || paused || lastPlayer != 0)
            fg = WHITE;
        pix = bitfont->text(tr("  1UP "), fg, BLACK);
        bitBlt(this, x(1), y(0), &pix);
    }

    if (rect(8, 0, tr(" HIGH SCORE ")).intersects(e->rect())) {
            QPixmap pix = bitfont->text(tr(" HIGH SCORE "), WHITE, BLACK);
        bitBlt(this, x(8), y(0), &pix);
    }

    if (maxPlayer > 1 && rect(21, 0, tr("  2UP ")).intersects(e->rect())) {
        QPixmap pix;
        QColor fg = BLACK;
        if (cursor.on || paused || lastPlayer != 1)
            fg = WHITE;
        pix = bitfont->text(tr("  2UP "), fg, BLACK);
        bitBlt(this, x(21), y(0), &pix);
    }

    QString s;

    s.sprintf("%6d0", playerScore[0]/10);
    if (rect(0, 1, s).intersects(e->rect())) {
            QPixmap pix = bitfont->text(s, WHITE, BLACK);
            bitBlt(this, x(0), y(1), &pix);
    }

    s.sprintf("%8d0", HighScore/10);
    if (rect(8, 1, s).intersects(e->rect())) {
            QPixmap pix = bitfont->text(s, WHITE, BLACK);
            bitBlt(this, x(8), y(1), &pix);
    }

    if (lastScore >= 0) {
        if (rect(1, 4*1.25, tr("     CONGRATULATIONS      ")).intersects(e->rect())) {
            QPixmap pix = bitfont->text(tr("     CONGRATULATIONS      "), YELLOW, BLACK);
            bitBlt(this, x(1), y(4*1.25), &pix);
        }
        if (rect(1, 6*1.25, tr("    YOU HAVE ARCHIEVED    ")).intersects(e->rect())) {
            QPixmap pix = bitfont->text(tr("    YOU HAVE ARCHIEVED    "), CYAN, BLACK);
            bitBlt(this, x(1), y(6*1.25), &pix);
        }
        if (rect(1, 7*1.25, tr("  A SCORE IN THE TOP 10.  ")).intersects(e->rect())) {
            QPixmap pix = bitfont->text(tr("  A SCORE IN THE TOP 10.  "), CYAN, BLACK);
            bitBlt(this, x(1), y(7*1.25), &pix);
        }
        if (rect(1, 8*1.25, tr("                          ")).intersects(e->rect())) {
            QPixmap pix = bitfont->text(tr("                          "), CYAN, BLACK);
            bitBlt(this, x(1), y(8*1.25), &pix);
        }
    }

    if (rect(1, 9.5*1.25, tr("RNK   SCORE  NAME   DATE")).intersects(e->rect())) {
            QPixmap pix = bitfont->text(tr("RNK   SCORE  NAME   DATE"), WHITE, BLACK);
        bitBlt(this, x(1), y(9.5*1.25), &pix);
    }

    for (int i = 0; i < 10; i++) {
        s.sprintf("%2d%9d  %-3.3s  %-8.8s",
            i+1, hallOfFame[i].points, hallOfFame[i].name.utf8().data(),
            formatDate(hallOfFame[i].moment.date()).data());
        if (rect(1, (11+i)*1.25, s).intersects(e->rect())) {
            QPixmap pix = bitfont->text(s, (i == lastScore) ? YELLOW : WHITE, BLACK);
            bitBlt(this, x(1), y((11+i)*1.25), &pix);
        }
    }

    if (cursor.x != -1 && cursor.y != -1 && cursor.on) {
        if (rect(cursor.x, (cursor.y*1.25), cursor.chr).intersects(e->rect())) {
            QPixmap pix = bitfont->text(cursor.chr, BLACK, YELLOW);
            bitBlt(this, x(cursor.x), y(cursor.y*1.25), &pix);
        }
    }

    if (paused) {

        QPixmap pix = bitfont->text(tr("PAUSED"), RED, BLACK);
        QRect r = bitfont->rect(tr("PAUSED"));
        r.moveCenter(QPoint(this->width()/2, this->height()/2));

        bitBlt(this, r.x(), r.y(), &pix);
    }
}
Example #18
0
void QMapViewWidget::paintEvent(QPaintEvent *event) {
	QPainter painter(this);

	painter.setBrush(QBrush(Qt::white));
	painter.setPen(QPen(Qt::black));
	painter.drawRect(0,0,width()-1, height()-1);

	QRect rect = pBackBuffer.rect();
	rect.moveCenter(QPoint(width()/2-1, height()/2-1));
	painter.drawPixmap(rect.topLeft(), pBackBuffer);

	if (pNewTokenType) {
		QRect paintRect(pNewToken.x()*pRectSize + rect.left(), pNewToken.y()*pRectSize + rect.top(), pRectSize-1, pRectSize-1);

		switch (pNewTokenType) {
				case 'r':
					painter.setRenderHint(QPainter::Antialiasing);
					painter.setBrush(QBrush("#FF0000"));
					paintRect.adjust(1,1,-1,-1);
					painter.drawEllipse(paintRect);
					break;
				case 'g':
					painter.setRenderHint(QPainter::Antialiasing);
					painter.setBrush(QBrush("#00FF00"));
					paintRect.adjust(1,1,-1,-1);
					painter.drawEllipse(paintRect);
					break;
				case 'b':
					painter.setRenderHint(QPainter::Antialiasing);
					painter.setBrush(QBrush("#0000FF"));
					paintRect.adjust(1,1,-1,-1);
					painter.drawEllipse(paintRect);
					break;
				case 'R':
					painter.setBrush(QBrush("#FF0000"));
					painter.drawRect(paintRect);
					break;
				case 'G':
					painter.setBrush(QBrush("#00FF00"));
					painter.drawRect(paintRect);
					break;
				case 'B':
					painter.setBrush(QBrush("#0000FF"));
					painter.drawRect(paintRect);
					break;
				default:
					break;
			}
	}

	if (pSelDir) {
		QPen pen(Qt::black);
		pen.setWidth(3);

		painter.setRenderHint(QPainter::Antialiasing);
		painter.setPen(pen);
		painter.setBrush(QBrush(Qt::black));
		painter.drawLine(pArrow[0], pArrow[1]);
		painter.drawPolygon(&pArrow[1], 3);
	}
}
Example #19
0
void DateTimeGroup::paintInterface(QPainter *p, const QStyleOptionGraphicsItem *option, const QRect &contentsRect)
{
	Q_UNUSED(option);
	if (dtg.isEmpty()) {
		return;
	}
	
	p->setPen(QPen(m_plainDateTimeGroupColor));
	p->setRenderHint(QPainter::SmoothPixmapTransform);
	p->setRenderHint(QPainter::Antialiasing);
	
	QFont smallFont = KGlobalSettings::smallestReadableFont();
	
	dtgRect = contentsRect;
	
	m_plainDateTimeGroupFont.setPointSizeF(qMax(dtgRect.height(), KGlobalSettings::smallestReadableFont().pointSize()));
	preparePainter(p, dtgRect, m_plainDateTimeGroupFont, dtg, true);
	
	if (m_useCustomColor || !m_svgExistsInTheme) {
		QFontMetrics fm(p->font());
		
		QPointF timeTextOrigin(QPointF(qMax(0, (dtgRect.center().x() - fm.width(dtg) / 2)),
						(dtgRect.center().y() + fm.height() / 3)));
		p->translate(-0.5, -0.5);
		
		if (m_drawShadow) {
			QPen tmpPen = p->pen();
			
			qreal shadowOffset = 1.0;
			QPen shadowPen;
			QColor shadowColor = m_plainDateTimeGroupShadowColor;
			shadowColor.setAlphaF(.4);
			shadowPen.setColor(shadowColor);
			p->setPen(shadowPen);
			QPointF shadowTimeTextOrigin = QPointF(timeTextOrigin.x() + shadowOffset,
								timeTextOrigin.y() + shadowOffset);
			p->drawText(shadowTimeTextOrigin, dtg);
			
			p->setPen(tmpPen);
			
			QLinearGradient gradient = QLinearGradient(QPointF(0, 0), QPointF(0, fm.height()));
			
			QColor startColor = m_plainDateTimeGroupColor;
			startColor.setAlphaF(.95);
			QColor stopColor = m_plainDateTimeGroupColor;
			stopColor.setAlphaF(.7);
			
			gradient.setColorAt(0.0, startColor);
			gradient.setColorAt(0.5, stopColor);
			gradient.setColorAt(1.0, startColor);
			QBrush gradientBrush(gradient);
			
			QPen gradientPen(gradientBrush, tmpPen.width());
			p->setPen(gradientPen);
		}
		p->drawText(timeTextOrigin, dtg);
	} else {
		QRect adjustedTimeRect = m_pixmap.rect();
		adjustedTimeRect.moveCenter(dtgRect.center());
		p->drawPixmap(adjustedTimeRect, m_pixmap);
	}
}
Example #20
0
void QMapViewWidget::mousePressEvent(QMouseEvent *event) {

	switch (pMode) {
		case 0: {
				QRect rect = pBackBuffer.rect();
				rect.moveCenter(QPoint(width()/2-1, height()/2-1));
				if (rect.contains(event->pos())) {
					QPoint scenePos = event->pos() - rect.topLeft();
					scenePos.setX(scenePos.x() / pRectSize);
					scenePos.setY(scenePos.y() / pRectSize);

					QPoint pos;
					switch (pSelectedItem) {
						case -4: // red token
							pos = findMapItem('r');
							pNewTokenType = 'r';
							break;
						case -5: // green token
							pos = findMapItem('g');
							pNewTokenType = 'g';
							break;
						case -6: // blue token
							pos = findMapItem('b');
							pNewTokenType = 'b';
							break;					
						case -7: // red dest
							pos = findMapItem('R');
							pNewTokenType = 'R';
							break;
						case -8: // green dest
							pos = findMapItem('G');
							pNewTokenType = 'G';
							break;
						case -9: // blue dest
							pos = findMapItem('B');
							pNewTokenType = 'B';
							break;
						default:
							pos = QPoint(-1, -1);
							pNewTokenType = 0;
							break;
					}

					if ((pos.x() != -1) && (pos.y() != -1))
						pMap[pos.y()][pos.x()] = '.';

					redrawMap();
					update();
				}
				mouseMoveEvent(event);
			}
			break;
		case 1: {
				if (pIsAnimationRun)
					return;

				QRect rect = pBackBuffer.rect();
				rect.moveCenter(QPoint(width()/2-1, height()/2-1));
				if (rect.contains(event->pos())) {
					
					QPoint scenePos = event->pos() - rect.topLeft();
					scenePos.setX(scenePos.x() / pRectSize);
					scenePos.setY(scenePos.y() / pRectSize);

					char c = getTokenType(pMap[scenePos.y()][scenePos.x()]);
					if ( (c == 'r') || (c == 'g') || (c == 'b') ) {
						pSelToken = scenePos;
						pSelTokenType = c;

						pNewToken = scenePos;
						pNewTokenType = c;

						pSelDir = 0;
						update();
					}
					else
						pSelTokenType = 0;
				}
			}
			break;
		default:
			break;
	}
}
Example #21
0
void ProgressBar::paintEvent(QPaintEvent *)
{
    // TODO move font into Utils::StyleHelper
    // TODO use Utils::StyleHelper white

    if (bar.isNull())
        bar.load(QLatin1String(":/core/images/progressbar.png"));

    double range = maximum() - minimum();
    double percent = 0.;
    if (range != 0)
        percent = (value() - minimum()) / range;
    if (percent > 1)
        percent = 1;
    else if (percent < 0)
        percent = 0;

    if (finished())
        percent = 1;

    QPainter p(this);
    QFont boldFont(p.font());
    boldFont.setPointSizeF(Utils::StyleHelper::sidebarFontSize());
    boldFont.setBold(true);
    p.setFont(boldFont);
    QFontMetrics fm(boldFont);

    // Draw separator
    int h = fm.height();
    p.setPen(Utils::StyleHelper::sidebarShadow());
    p.drawLine(0,0, size().width(), 0);

    p.setPen(Utils::StyleHelper::sidebarHighlight());
    p.drawLine(1, 1, size().width(), 1);

    QRect textBounds = fm.boundingRect(m_title);
    textBounds.moveCenter(rect().center());
    int alignment = Qt::AlignHCenter;

    int textSpace = rect().width() - 8;
    // If there is not enough room when centered, we left align and
    // elide the text
    QString elidedtitle  = fm.elidedText(m_title, Qt::ElideRight, textSpace);

    QRect textRect = rect().adjusted(3, 1, -3, 0);
    textRect.setHeight(h+5);

    p.setPen(QColor(0, 0, 0, 120));
    p.drawText(textRect, alignment | Qt::AlignBottom, elidedtitle);
    p.translate(0, -1);
    p.setPen(Utils::StyleHelper::panelTextColor());
    p.drawText(textRect, alignment | Qt::AlignBottom, elidedtitle);
    p.translate(0, 1);

    m_progressHeight = PROGRESSBAR_HEIGHT;
    m_progressHeight += ((m_progressHeight % 2) + 1) % 2; // make odd
    // draw outer rect
    QRect rect(INDENT - 1, h+6, size().width()-2*INDENT + 1, m_progressHeight-1);
    p.setPen(Utils::StyleHelper::panelTextColor());
    Utils::StyleHelper::drawCornerImage(bar, &p, rect, 2, 2, 2, 2);

    // draw inner rect
    QColor c = Utils::StyleHelper::panelTextColor();
    c.setAlpha(180);
    p.setPen(Qt::NoPen);


    QRect inner = rect.adjusted(3, 2, -2, -2);
    inner.adjust(0, 0, qRound((percent - 1) * inner.width()), 0);
    if (m_error) {
        QColor red(255, 60, 0, 210);
        c = red;
        // avoid too small red bar
        if (inner.width() < 10)
            inner.adjust(0, 0, 10 - inner.width(), 0);
    } else if (m_finished) {
        c = QColor(90, 170, 60);
    }

    // Draw line and shadow after the gradient fill
    if (value() > 0 && value() < maximum()) {
        p.fillRect(QRect(inner.right() + 1, inner.top(), 2, inner.height()), QColor(0, 0, 0, 20));
        p.fillRect(QRect(inner.right() + 1, inner.top(), 1, inner.height()), QColor(0, 0, 0, 60));
    }
    QLinearGradient grad(inner.topLeft(), inner.bottomLeft());
    grad.setColorAt(0, c.lighter(130));
    grad.setColorAt(0.5, c.lighter(106));
    grad.setColorAt(0.51, c.darker(106));
    grad.setColorAt(1, c.darker(130));
    p.setPen(Qt::NoPen);
    p.setBrush(grad);
    p.drawRect(inner);
    p.setBrush(Qt::NoBrush);
    p.setPen(QPen(QColor(0, 0, 0, 30), 1));
    p.drawLine(inner.topLeft(), inner.topRight());
    p.drawLine(inner.topLeft(), inner.bottomLeft());
    p.drawLine(inner.topRight(), inner.bottomRight());
    p.drawLine(inner.bottomLeft(), inner.bottomRight());
    p.drawPoint(inner.bottomLeft());
    p.drawPoint(inner.bottomRight());

    // Draw cancel button
    p.setOpacity(m_cancelButtonFader);

    if (value() < maximum() && !m_error) {
        QRect cancelRect(rect.adjusted(rect.width() - CANCELBUTTON_SIZE, 1, -1, 0));
        bool hover = cancelRect.contains(mapFromGlobal(QCursor::pos()));
        QLinearGradient grad(cancelRect.topLeft(), cancelRect.bottomLeft());
        int intensity = hover ? 90 : 70;
        QColor buttonColor(intensity, intensity, intensity, 255);
        grad.setColorAt(0, buttonColor.lighter(130));
        grad.setColorAt(1, buttonColor.darker(130));
        p.setPen(Qt::NoPen);
        p.setBrush(grad);
        p.drawRect(cancelRect.adjusted(1, 1, -1, -1));

        p.setPen(QPen(QColor(0, 0, 0, 30)));
        p.drawLine(cancelRect.topLeft() + QPoint(0,1), cancelRect.bottomLeft() + QPoint(0,-1));
        p.setPen(QPen(QColor(0, 0, 0, 120)));
        p.drawLine(cancelRect.topLeft() + QPoint(1,1), cancelRect.bottomLeft() + QPoint(1,-1));
        p.setPen(QPen(QColor(255, 255, 255, 30)));
        p.drawLine(cancelRect.topLeft() + QPoint(2,1), cancelRect.bottomLeft() + QPoint(2,-1));
        p.setPen(QPen(hover ? Utils::StyleHelper::panelTextColor() : QColor(180, 180, 180), 1));
        p.setRenderHint(QPainter::Antialiasing);
        p.translate(0.5, 0.5);
        p.drawLine(cancelRect.center()+QPoint(-1,-2), cancelRect.center()+QPoint(+3,+2));
        p.drawLine(cancelRect.center()+QPoint(+3,-2), cancelRect.center()+QPoint(-1,+2));
    }
}
Example #22
0
void MainWindow::centerWindow()
{
    QRect position = this->frameGeometry();
    position.moveCenter(QDesktopWidget().availableGeometry().center());
    this->move(position.topLeft());
}
Example #23
0
/*!
  Resize the given window to fit the screen geometry
*/
void QBBScreen::resizeTopLevelWindow(QBBWindow *w, const QRect &previousScreenGeometry) const
{
    QRect windowGeometry = w->geometry();

    const qreal relativeCenterX = static_cast<qreal>(w->geometry().center().x()) / previousScreenGeometry.width();
    const qreal relativeCenterY = static_cast<qreal>(w->geometry().center().y()) / previousScreenGeometry.height();
    const QPoint newCenter(relativeCenterX * geometry().width(), relativeCenterY * geometry().height());

    windowGeometry.moveCenter(newCenter);

    // adjust center position in case the window
    // is clipped
    if (!geometry().contains(windowGeometry)) {
        const int x1 = windowGeometry.x();
        const int y1 = windowGeometry.y();
        const int x2 = x1 + windowGeometry.width();
        const int y2 = y1 + windowGeometry.height();

        if (x1 < 0) {
            const int centerX = qMin(qAbs(x1) + windowGeometry.center().x(),
                                        geometry().center().x());

            windowGeometry.moveCenter(QPoint(centerX, windowGeometry.center().y()));
        }

        if (y1 < 0) {
            const int centerY = qMin(qAbs(y1) + windowGeometry.center().y(),
                                        geometry().center().y());

            windowGeometry.moveCenter(QPoint(windowGeometry.center().x(), centerY));
        }

        if (x2 > geometry().width()) {
            const int centerX = qMax(windowGeometry.center().x() - (x2 - geometry().width()),
                                        geometry().center().x());

            windowGeometry.moveCenter(QPoint(centerX, windowGeometry.center().y()));
        }

        if (y2 > geometry().height()) {
            const int centerY = qMax(windowGeometry.center().y() - (y2 - geometry().height()),
                                        geometry().center().y());

            windowGeometry.moveCenter(QPoint(windowGeometry.center().x(), centerY));
        }
    }

    // at this point, if the window is still clipped,
    // it means that it's too big to fit on the screen,
    // so we need to proportionally shrink it
    if (!geometry().contains(windowGeometry)) {
        QSize newSize = windowGeometry.size();
        newSize.scale(geometry().size(), Qt::KeepAspectRatio);
        windowGeometry.setSize(newSize);

        if (windowGeometry.x() < 0)
            windowGeometry.moveCenter(QPoint(geometry().center().x(), windowGeometry.center().y()));

        if (windowGeometry.y() < 0)
            windowGeometry.moveCenter(QPoint(windowGeometry.center().x(), geometry().center().y()));
    }

    w->widget()->setGeometry(windowGeometry);
}
Example #24
0
// Draws a cached pixmap with shadow
void FancyTabBar::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());
        //jassuncao int devicePixelRatio = qCeil(px.devicePixelRatio());
        int devicePixelRatio = 1;
        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);
        //jassuncao: cache.setDevicePixelRatio(devicePixelRatio);
        QPixmapCache::insert(pixmapName, cache);
    }

    QRect targetRect = cache.rect();
    //jassuncao targetRect.setSize(targetRect.size() / cache.devicePixelRatio());
    targetRect.moveCenter(rect.center() - dipOffset);
    p->drawPixmap(targetRect, cache);
}
Example #25
0
void frmConnect::moveWindowToCenter()
{
    QRect frect = frameGeometry();
    frect.moveCenter(QDesktopWidget().availableGeometry().center());
    move(frect.topLeft());
}
Example #26
0
bool ArrowMarker::eventFilter(QObject *, QEvent *e)
{
	switch(e->type()) {
		case QEvent::MouseButtonPress:
			{
				const QMouseEvent *me = (const QMouseEvent *)e;
				if (me->button() != Qt::LeftButton)
					return false;
				QRect handler = QRect (QPoint(0,0), QSize(10, 10));
				handler.moveCenter (startPoint());
				if (handler.contains(me->pos()))
				{
					QApplication::setOverrideCursor(QCursor(Qt::SizeAllCursor), true);
					d_op = MoveStart;
					return true;
				}
				handler.moveCenter (endPoint());
				if (handler.contains(me->pos()))
				{
					QApplication::setOverrideCursor(QCursor(Qt::SizeAllCursor), true);
					d_op = MoveEnd;
					return true;
				}
				int d = width()+(int)floor(headLength()*tan(M_PI*headAngle()/180.0)+0.5);
				if (dist(me->pos().x(),me->pos().y()) <= d)
				{
					QApplication::setOverrideCursor(QCursor(Qt::SizeAllCursor), true);
					d_op = MoveBoth;
					d_op_startat = me->pos()-startPoint();
					return true;
				}
				return false;
			}
		case QEvent::MouseMove:
			{
				const QMouseEvent *me = (const QMouseEvent *)e;
				switch(d_op) {
					case MoveStart:
						setStartPoint(me->pos());
						plot()->replot();
						return true;
					case MoveEnd:
						setEndPoint(me->pos());
						plot()->replot();
						return true;
					case MoveBoth:
						setEndPoint(endPoint()+me->pos()-d_op_startat-startPoint());
						setStartPoint(me->pos()-d_op_startat);
						plot()->replot();
						return true;
					default:
						return false;
				}
			}
		case QEvent::MouseButtonRelease:
			{
				const QMouseEvent *me = (const QMouseEvent *)e;
				switch(d_op) {
					case MoveStart:
						setStartPoint(me->pos());
						plot()->replot();
						d_op = None;
						QApplication::restoreOverrideCursor();
						return true;
					case MoveEnd:
						setEndPoint(me->pos());
						plot()->replot();
						d_op = None;
						QApplication::restoreOverrideCursor();
						return true;
					case MoveBoth:
						setXValue(plot()->invTransform(xAxis(), me->pos().x()-d_op_startat.x()));
						setYValue(plot()->invTransform(yAxis(), me->pos().y()-d_op_startat.y()));
						plot()->replot();
						d_op = None;
						QApplication::restoreOverrideCursor();
						return true;
					default:
						d_op = None;
						QApplication::restoreOverrideCursor();
						return false;
				}
			}
		case QEvent::MouseButtonDblClick:
			{
				const QMouseEvent *me = (const QMouseEvent *)e;
				if (me->button() != Qt::LeftButton)
					return false;
				LineDialog *ld = new LineDialog(this, plot()->window());
				ld->setAttribute(Qt::WA_DeleteOnClose);
				ld->exec();
				return true;
			}
		default:
			return false;
	}
}
Example #27
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);
}
Example #28
0
AboutDlg::AboutDlg(QWidget *parent) : QDialog(parent) {
    this->setWindowTitle(tr("About QtRptDesigner"));
    QSize MaxSize(420, 450);
    QSize MinSize(420, 450);
    setMaximumSize(MaxSize);
    setMinimumSize(MinSize);

    QRect gry = geometry();
    gry.moveCenter(qApp->desktop()->availableGeometry().center());
    setGeometry(gry);

    QPushButton *btnOK = new QPushButton(this);
    btnOK->setText("OK");
    QObject::connect(btnOK, SIGNAL(clicked()), this, SLOT(close()));

    QLabel *labImg = new QLabel(this);
    labImg->setPixmap(QPixmap(":/new/prefix1/images/Logo128.png"));
    QString lbl1 = "<h2><b><p style='color:#0033FF'>"+QApplication::applicationName()+"</p></b></h2>"+
                  tr("Version: ")+QApplication::applicationVersion()+"<br>"+
                  tr("Programmer: Aleksey Osipov")+"<br>"+
                  "WebSite: <a href='http://www.aliks-os.tk'>http://www.aliks-os.tk</a>"+"<br>"+
                  "E-mail: [email protected]"+"<br>"+
                  "<a href='http://www.qtrpt.tk'>http://www.qtrpt.tk</a>"+"<br>"+
                  tr("2012-2015 years")+"<br><br>";
    QString lbl2 = "<b>"+tr("Thanks for donation:")+"</b>"+
                  "<ul>"+
                  "<li>"+tr("Sailendram")+"</li>"+
                  "</ul>"+
                  "<b>"+tr("Thanks for project developing:")+"</b>"+
                  "<ul>"+
                  "<li>"+tr("Lukas Lalinsky for DBmodel")+"</li>"+
                  "<li>"+tr("Norbert Schlia for help in developing")+"</li>"+
                  "<li>"+tr("Muhamad Bashir Al-Noimi for Arabic translation")+"</li>"+
                  "<li>"+tr("Luis Brochado for Portuguese translation")+"</li>"+
                  "<li>"+tr("Li Wei for Chinese translation")+"</li>"+
                  "<li>"+tr("Laurent Guilbert for French translation")+"</li>"+
                  "<li>"+tr("David Heremans for Dutch translation")+"</li>"+
                  "<li>"+tr("Mirko Marx for German translation")+"</li>"+
                  "<li>"+tr("Manuel Soriano for Spanish translation")+"</li>"+
                  "</ul>";
    QLabel *lab1 = new QLabel(lbl1, this);
    QObject::connect(lab1, SIGNAL(linkActivated(const QString)), this, SLOT(openLink(const QString)));
    QLabel *lab2 = new QLabel(lbl2, this);

    QHBoxLayout *hLayout2 = new QHBoxLayout;
    hLayout2->addWidget(labImg);
    hLayout2->addWidget(lab1);
    hLayout2->addStretch();

    QHBoxLayout *hLayout1 = new QHBoxLayout;
    //hLayout->addSpacerItem(spacer1);
    hLayout1->addStretch();
    hLayout1->addWidget(btnOK);
    //hLayout->addSpacerItem(spacer2);
    hLayout1->addStretch();

    QVBoxLayout *vLayout = new QVBoxLayout;
    //vLayout->addSpacerItem(spacer3);
    vLayout->addLayout(hLayout2);
    vLayout->addWidget(lab2);
    vLayout->addStretch();
    vLayout->addLayout(hLayout1);
    this->setLayout(vLayout);
}
Example #29
0
void DeckButtonsLayout::setGeometry( const QRect& _r )
{
    QLayout::setGeometry( _r );

    int left; int top; int right; int bottom;
    getContentsMargins( &left, &top, &right, &bottom );

    const QRect r = _r.adjusted( left, top, right, bottom );
    const QAbstractButton* button = backwardButton ? backwardButton : forwardButton;
    qreal factor = 1;

    if ( !button ) {
        if ( RoundButton ) {
            const int min = qMin( r.height(), r.width() );
            QRect rect = QRect( QPoint(), QSize( min, min ) );

            rect.moveCenter( r.center() );
            RoundButton->setGeometry( rect );
        }

        return;
    }
    else if ( backwardButton && forwardButton ) {
        factor = (qreal)r.width() /(qreal)( button->sizeHint().width() *2 );
    }
    else if ( RoundButton ) {
        factor = (qreal)r.width() /(qreal)( button->sizeHint().width() +( RoundButton->sizeHint().width() /2 ) );
    }
    else {
        factor = (qreal)r.width() /(qreal)( button->sizeHint().width() );
    }

    if ( RoundButton ) {
        int height = (qreal)RoundButton->sizeHint().height() *factor;

        while ( height > r.height() ) {
            factor -= 0.1;
            height = (qreal)RoundButton->sizeHint().height() *factor;
        }

        QRect rect( QPoint(), QSize( height, height ) );
        rect.moveCenter( r.center() );

        if ( backwardButton && forwardButton ) {
            // nothing to do
        }
        else if ( backwardButton ) {
            rect.moveRight( r.right() );
        }
        else if ( forwardButton ) {
            rect.moveLeft( r.left() );
        }

        RoundButton->setGeometry( rect );
    }
    else {
        int height = (qreal)button->sizeHint().height() *factor;

        while ( height > r.height() ) {
            factor -= 0.1;
            height = (qreal)button->sizeHint().height() *factor;
        }
    }

    const QSize bs = QSize( (qreal)button->sizeHint().width() *factor, (qreal)button->sizeHint().height() *factor );

    if ( backwardButton ) {
        QRect gr = RoundButton ? QRect( QPoint(), RoundButton->size() ) : r;
        QRect rect = QRect( QPoint(), bs );

        if ( RoundButton ) {
            gr.moveTopLeft( RoundButton->pos() );
        }

        rect.moveCenter( gr.center() );
        rect.moveRight( gr.center().x() +1 );

        backwardButton->setGeometry( rect );
    }

    if ( forwardButton ) {
        QRect gr = RoundButton ? QRect( QPoint(), RoundButton->size() ) : r;
        QRect rect = QRect( QPoint(), bs );

        if ( RoundButton ) {
            gr.moveTopLeft( RoundButton->pos() );
        }

        rect.moveCenter( gr.center() );
        rect.moveLeft( gr.center().x() );

        forwardButton->setGeometry( rect );
    }

    if ( RoundButton ) {
        RoundButton->raise();
    }
}