void GlyphStringRenderer::setPenWidth(int width)
{
    mPenWidth = width;
    layout();
}
void GlyphStringRenderer::setRunArrowColor(QColor color)
{
    mRunArrowColor = color;
    layout();
}
void GlyphStringRenderer::setRendererFlags(quint32 flags)
{
    mFlags = flags;
    layout();
}
void GlyphStringRenderer::setGlyphString(const GlyphString *glyphString)
{
    mGlyphString = glyphString;
    layout();
}
void GlyphStringRenderer::setLevelArrowColor(QColor color)
{
    mLevelArrowColor = color;
    layout();
}
示例#6
0
QgsHeatmapRendererWidget::QgsHeatmapRendererWidget( QgsVectorLayer* layer, QgsStyleV2* style, QgsFeatureRendererV2* renderer )
    : QgsRendererV2Widget( layer, style )
    , mRenderer( nullptr )
{
  if ( !layer )
  {
    return;
  }
  // the renderer only applies to point vector layers
  if ( layer->geometryType() != Qgis::Point )
  {
    //setup blank dialog
    mRenderer = nullptr;
    QLabel* label = new QLabel( tr( "The heatmap renderer only applies to point and multipoint layers. \n"
                                    "'%1' is not a point layer and cannot be rendered as a heatmap." )
                                .arg( layer->name() ), this );
    layout()->addWidget( label );
    return;
  }

  setupUi( this );

  mRadiusUnitWidget->setUnits( QgsUnitTypes::RenderUnitList() << QgsUnitTypes::RenderMillimeters << QgsUnitTypes::RenderPixels << QgsUnitTypes::RenderMapUnits );
  mWeightExpressionWidget->registerGetExpressionContextCallback( &_getExpressionContext, this );

  if ( renderer )
  {
    mRenderer = QgsHeatmapRenderer::convertFromRenderer( renderer );
  }
  if ( !mRenderer )
  {
    mRenderer = new QgsHeatmapRenderer();
  }

  mRampComboBox->setShowGradientOnly( true );
  mRampComboBox->populate( QgsStyleV2::defaultStyle() );
  connect( mRampComboBox, SIGNAL( currentIndexChanged( int ) ), this, SLOT( applyColorRamp() ) );
  connect( mRampComboBox, SIGNAL( sourceRampEdited() ), this, SLOT( applyColorRamp() ) );
  connect( mButtonEditRamp, SIGNAL( clicked() ), mRampComboBox, SLOT( editSourceRamp() ) );

  if ( mRenderer->colorRamp() )
  {
    mRampComboBox->blockSignals( true );
    mRampComboBox->setSourceColorRamp( mRenderer->colorRamp() );
    mRampComboBox->blockSignals( false );
  }
  mRadiusSpinBox->blockSignals( true );
  mRadiusSpinBox->setValue( mRenderer->radius() );
  mRadiusSpinBox->blockSignals( false );
  mRadiusUnitWidget->blockSignals( true );
  mRadiusUnitWidget->setUnit( mRenderer->radiusUnit() );
  mRadiusUnitWidget->setMapUnitScale( mRenderer->radiusMapUnitScale() );
  mRadiusUnitWidget->blockSignals( false );
  mMaxSpinBox->blockSignals( true );
  mMaxSpinBox->setValue( mRenderer->maximumValue() );
  mMaxSpinBox->blockSignals( false );
  mQualitySlider->blockSignals( true );
  mQualitySlider->setValue( mRenderer->renderQuality() );
  mQualitySlider->blockSignals( false );
  mInvertCheckBox->blockSignals( true );
  mInvertCheckBox->setChecked( mRenderer->invertRamp() );
  mInvertCheckBox->blockSignals( false );

  mWeightExpressionWidget->setLayer( layer );
  mWeightExpressionWidget->setField( mRenderer->weightExpression() );
  connect( mWeightExpressionWidget, SIGNAL( fieldChanged( QString ) ), this, SLOT( weightExpressionChanged( QString ) ) );
}
示例#7
0
VCSlider::VCSlider(QWidget* parent, Doc* doc) : VCWidget(parent, doc)
{
    /* Set the class name "VCSlider" as the object name as well */
    setObjectName(VCSlider::staticMetaObject.className());

    m_hbox = NULL;
    m_topLabel = NULL;
    m_slider = NULL;
    m_knob = NULL;
    m_bottomLabel = NULL;

    m_valueDisplayStyle = ExactValue;

    m_levelLowLimit = 0;
    m_levelHighLimit = UCHAR_MAX;

    m_levelValue = 0;
    m_levelValueChanged = false;

    m_playbackFunction = Function::invalidId();
    m_playbackValue = 0;
    m_playbackValueChanged = false;

    m_submasterValue = UCHAR_MAX;

    m_widgetMode = WSlider;

    setType(VCWidget::SliderWidget);
    setCaption(QString());
    setFrameStyle(KVCFrameStyleSunken);

    /* Main VBox */
    new QVBoxLayout(this);

    /* Top label */
    m_topLabel = new QLabel(this);
    m_topLabel->setAlignment(Qt::AlignHCenter);

    layout()->addWidget(m_topLabel);

    /* Slider's HBox |stretch|slider|stretch| */
    m_hbox = new QHBoxLayout();

    /* Put stretchable space before the slider (to its left side) */
    m_hbox->addStretch();

    /* The slider */
    m_slider = new ClickAndGoSlider(this);

    m_hbox->addWidget(m_slider);
    m_slider->setRange(0, 255);
    m_slider->setPageStep(1);
    m_slider->setInvertedAppearance(false);
    m_slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
    m_slider->setMinimumWidth(32);
    m_slider->setMaximumWidth(80);
    m_slider->setStyleSheet(sliderStyleSheet);

    connect(m_slider, SIGNAL(valueChanged(int)),
            this, SLOT(slotSliderMoved(int)));
    m_externalMovement = false;

    /* Put stretchable space after the slider (to its right side) */
    m_hbox->addStretch();

    layout()->addItem(m_hbox);

    /* Click & Go button */
    m_cngType = ClickAndGoWidget::None;

    m_cngButton = new QToolButton(this);
    m_cngButton->setFixedSize(48, 48);
    m_cngButton->setIconSize(QSize(42, 42));
    m_menu = new QMenu(this);
    QWidgetAction* action = new QWidgetAction(this);
    m_cngWidget = new ClickAndGoWidget();
    action->setDefaultWidget(m_cngWidget);
    m_menu->addAction(action);
    m_cngButton->setMenu(m_menu);
    m_cngButton->setPopupMode(QToolButton::InstantPopup);
    layout()->addWidget(m_cngButton);
    layout()->setAlignment(m_cngButton, Qt::AlignHCenter);
    m_cngButton->hide();

    connect(m_cngWidget, SIGNAL(levelChanged(uchar)),
            this, SLOT(slotClickAndGoLevelChanged(uchar)));
    connect(m_cngWidget, SIGNAL(colorChanged(QRgb)),
            this, SLOT(slotClickAndGoColorChanged(QRgb)));
    connect(m_cngWidget, SIGNAL(levelAndPresetChanged(uchar,QImage)),
            this, SLOT(slotClickAndGoLevelAndPresetChanged(uchar, QImage)));

    /* Bottom label */
    m_bottomLabel = new QLabel(this);
    layout()->addWidget(m_bottomLabel);
    m_bottomLabel->setAlignment(Qt::AlignCenter);
    m_bottomLabel->setWordWrap(true);
    m_bottomLabel->hide();

    setMinimumSize(20, 20);
    QSettings settings;
    QVariant var = settings.value(SETTINGS_SLIDER_SIZE);
    if (var.isValid() == true)
        resize(var.toSize());
    else
        resize(VCSlider::defaultSize);

    /* Initialize to playback mode by default */
    setInvertedAppearance(false);
    setSliderMode(Playback);

    /* Update the slider according to current mode */
    slotModeChanged(mode());

    /* Listen to fixture removals so that LevelChannels can be removed when
       they no longer point to an existing fixture->channel */
    connect(m_doc, SIGNAL(fixtureRemoved(quint32)),
            this, SLOT(slotFixtureRemoved(quint32)));
}
示例#8
0
    setTextRunAroundContour(KoShape::ContourBox);

    // Enable auto-resizing of chart labels
    foreach(KoShape *label, labels()) {
        TextLabelData *labelData = qobject_cast<TextLabelData*>(label->userData());
        KoTextDocument doc(labelData->document());
//FIXME        doc.setResizeMethod(KoTextDocument::AutoResize);
    }

    QSharedPointer<KoColorBackground> background(new KoColorBackground(Qt::white));
    setBackground(background);

    KoShapeStroke *stroke = new KoShapeStroke(0, Qt::black);
    setStroke(stroke);

    ChartLayout *l = layout();
    l->setPosition(d->plotArea, CenterPosition);
    l->setPosition(d->title,    TopPosition, 0);
    l->setPosition(d->subTitle, TopPosition, 1);
    l->setPosition(d->footer,   BottomPosition, 1);
    l->setPosition(d->legend,   d->legend->legendPosition());
    l->layout();

    requestRepaint();
}

ChartShape::~ChartShape()
{
    delete d->title;
    delete d->subTitle;
    delete d->footer;
示例#9
0
/*!
  Converts the log \a log to its textual representation and returns
  a QByteArray containing the data.
*/
QByteArray TLogger::logToByteArray(const TLog &log) const
{
    return logToByteArray(log, layout(), dateTimeFormat(), codec_);
}
示例#10
0
    void init()
    {
        /* subGrid holds global and
         * local SimulationSize and where the local SimArea is in the greater
         * scheme using Offsets from global LEFT, TOP, FRONT
         */
        const SubGrid<DIM2>& subGrid = Environment<DIM2>::get().SubGrid();

        /* The following sets up the local layout which consists of the actual
         * grid cells and some surrounding cells, called guards.
         *
         * ASCII Visualization: example taken for 1D,
         * distributed over 2 GPUs, only 1 border shown between those two GPUs
         * assuming non-periodic boundary conditions.
         * In a N-GPU or periodic example, border cells guard cells exist in each direction.
         * _______GPU 0________       _______GPU 1________
         * | 0 | 1 | 2 | 3 | 4 |      | 3 | 4 | 5 | 6 | 7 |  <-- Global (super)cell idx
         * |___|___|___|___|___|      |___|___|___|___|___|
         * |___Core____|Bor|Gua|      |Gua|Bor|___Core____|
         * |___________|der|rd_|      |rd_|der|___________|
         * |__"real" cells_|***|      |***|__"real" cells_|
         *
         * |***| Clones cells which correspond to the border cells of the neighbor GPU
         *       (sometimes also called "ghost" or "halo" cells/region)
         *
         * Recall that the following is defined:
         *     typedef MappingDescription<DIM2, math::CT::Int<16,16> > MappingDesc;
         * where math::CT::Int<16,16> is arbitrarily(!) chosen SuperCellSize
         * and DIM2 is the dimension of the grid.
         * Expression of 2nd argument translates to DataSpace<DIM3>(16,16,0).
         * This is the guard size (here set to be one Supercell wide in all
         * directions). Meaning we have 16*16*(2*grid.x+2*grid.y+4) more
         * cells in GridLayout than in the SubGrid.
         * The formula above is SuperCellSize * TotalNumGuardCells with (in this case)
         * SuperCellSize = 16*16 (16 cells in 2 dimensions)
         * TotalNumGuardCells =   2 * grid.x (top and bottom)
         *                      + 2 * grid.y (left and right)
         *                      + 4          (the corners)
         */
        GridLayout<DIM2> layout( subGrid.getLocalDomain().size,
                                 MappingDesc::SuperCellSize::toRT());

        /* getDataSpace will return DataSpace( grid.x +16+16, grid.y +16+16)  *
         * MappingDesc stores the layout regarding Core, Border and Guard     *
         * in units of SuperCells.                                            *
         * This is saved by init to be used by the kernel to identify itself. */
        evo.init(layout.getDataSpace(), Space::create(1));

        buff1 = new Buffer(layout, false);
        buff2 = new Buffer(layout, false);

        /* Set up the future data exchange. In this case we need to copy the
         * border cells of our neighbors to our guard cells, since we only read
         * from the guard cells but never write to it.
         * guardingCells holds the number of guard(super)cells in each dimension
         */
        Space guardingCells(1, 1);
        for (uint32_t i = 1; i < traits::NumberOfExchanges<DIM2>::value; ++i)
        {
            /* to check which number corresponds to which direction, you can  *
             * use the following member of class Mask like done in the two    *
             * lines below:                                                   *
             * DataSpace<DIM2>relVec = Mask::getRelativeDirections<DIM2>(i);  *
             * std::cout << "Direction:" << i << " => Vec: (" << relVec[0]    *
             *           << "," << relVec[1] << ")\n";                        *
             * The result is: 1:right(1,0), 2:left(-1,0), 3:up(0,1),          *
             *    4:up right(1,1), 5:(-1,1), 6:(0,-1), 7:(1,-1), 8:(-1,-1)    */

            /* types.hpp: enum CommunicationTags{ BUFF1 = 0u, BUFF2 = 1u };   */
            buff1->addExchange(GUARD, Mask(i), guardingCells, BUFF1);
            buff2->addExchange(GUARD, Mask(i), guardingCells, BUFF2);
        }

         /* Both next lines are defined in GatherSlice.hpp:                   *
          *  -gather saves the MessageHeader object                           *
          *  -Then do an Allgather for the gloabalRanks from GC, sort out     *
          *  -inactive processes (second/boolean ,argument in gather.init) and*
          *   save new MPI_COMMUNICATOR created from these into private var.  *
          *  -return if rank == 0                                             */
        MessageHeader header(gridSize, layout, subGrid.getLocalDomain().offset);
        isMaster = gather.init(header, true);

        /* Calls kernel to initialize random generator. Game of Life is then  *
         * initialized using uniform random numbers. With 10% (second arg)    *
         * white points. World will be written to buffer in first argument    */
        evo.initEvolution(buff1->getDeviceBuffer().getDataBox(), 0.1);

    }
void Acceleration_Calibration_Wizard::prepare_step()
{
    delete m_content;
    m_content = nullptr;

    if (m_step == Step::INTRO)
    {
        m_content = new QWidget(this);
        layout()->addWidget(m_content);

        Ui::Acceleration_Calibration_Wizard_Intro ui;
        ui.setupUi(m_content);
        ui.description->setText(q::util::format2<std::string>(
                                    "This wizard will calibrate the acceleration stream of node {}.\n"
                                    "It will ask you to hold the UAV still in various positions and will take about 1 minute.\n"
                                    "\n"
                                    "Ready?", m_node->name).c_str());

        QObject::connect(ui.buttonBox, &QDialogButtonBox::accepted, [this]() { advance(); });
        QObject::connect(ui.buttonBox, &QDialogButtonBox::rejected, [this]() { cancel(); });
    }
    else if (m_step == Step::RESET)
    {
        m_content = new QWidget(this);
        layout()->addWidget(m_content);

        Ui::Acceleration_Calibration_Wizard_Reset ui;
        ui.setupUi(m_content);
        if (m_initial_calibration.points.size() > 0)
        {
            ui.info->setText(q::util::format2<std::string>("There are currently {} calibration points.\n"
                                                           "Do you want to clear these points or keep them?", m_initial_calibration.points.size()).c_str());
            auto* clear = ui.buttonBox->addButton("Clear", QDialogButtonBox::ResetRole);
            QObject::connect(clear, &QPushButton::released, [this]() { advance(); });

            auto* keep = ui.buttonBox->addButton("Keep", QDialogButtonBox::AcceptRole);
            QObject::connect(keep, &QPushButton::released, [this]() { m_crt_calibration = m_initial_calibration; advance(); });
        }
        else
        {
            ui.info->setText("There are no existing calibration data points.\nLet's add one");
            auto* ok = ui.buttonBox->addButton("Keep", QDialogButtonBox::AcceptRole);
            QObject::connect(ok, &QPushButton::released, [this]() { advance(); });
        }


        QObject::connect(ui.buttonBox, &QDialogButtonBox::rejected, [this]() { cancel(); });
    }
    else if (m_step == Step::SHOW_INSTRUCTIONS)
    {
        static char const* direction[] =
        {
            "level",
            "on its LEFT side",
            "on its RIGHT side",
            "nose DOWN",
            "nose UP",
            "on its BACK",
        };

        m_content = new QWidget(this);
        layout()->addWidget(m_content);

        Ui::Acceleration_Calibration_Wizard_Instructions ui;
        ui.setupUi(m_content);
        ui.instructions->setText(q::util::format2<std::string>(
                                    "Please place the UAV {} for {} seconds.\n"
                                    "\n"
                                    "Done?", direction[m_collect_data_step], DATA_COLLECTION_DURATION).c_str());

        QObject::connect(ui.buttonBox, &QDialogButtonBox::accepted, [this]() { advance(); });
        QObject::connect(ui.buttonBox, &QDialogButtonBox::rejected, [this]() { cancel(); });
    }
    else if (m_step == Step::COLLECT)
    {
        m_content = new QWidget(this);
        layout()->addWidget(m_content);

        Ui::Acceleration_Calibration_Wizard_Collect ui;
        ui.setupUi(m_content);
        auto* info = ui.info;
        auto* progress = ui.progressBar;

        m_samples.clear();

        QObject::connect(ui.buttonBox, &QDialogButtonBox::rejected, [this]() { cancel(); });

        m_connection = m_stream->samples_available_signal.connect([this, info, progress](silk::stream::gs::Acceleration::Samples const& samples)
        {
            on_samples_received(samples);
            info->setText(q::util::format2<std::string>("Collected {} samples...", m_samples.size()).c_str());
            size_t needed_samples = std::chrono::seconds(DATA_COLLECTION_DURATION).count() * m_output.rate;
            progress->setValue(float(m_samples.size() * 100.f) / float(needed_samples));
            if (m_samples.size() >= needed_samples)
            {
                m_averages[m_collect_data_step].set(std::accumulate(m_samples.begin(), m_samples.end(), math::vec3f()));
                m_averages[m_collect_data_step] /= static_cast<double>(m_samples.size());

                advance();
            }
        });
    }
    else if (m_step == Step::DONE)
    {
        math::vec3<double> bias, scale;
        compute_calibration_data(m_averages, bias, scale);

        m_content = new QWidget(this);
        layout()->addWidget(m_content);

        Ui::Acceleration_Calibration_Wizard_Done ui;
        ui.setupUi(m_content);

        ui.info->setText("Done!\n"
                         "The new Bias & Scale are:");
        ui.bias->setText(q::util::format2<std::string>("{}", bias).c_str());
        ui.scale->setText(q::util::format2<std::string>("{}", scale).c_str());

        sz::calibration::Acceleration point;
        point.temperature = 0;
        point.bias = math::vec3f(bias);
        point.scale = math::vec3f(scale);
        m_crt_calibration.points.push_back(point);

        QObject::connect(ui.temperature, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), [this](double value)
        {
            m_crt_calibration.points.back().temperature = static_cast<float>(value);
        });

        QObject::connect(ui.buttonBox, &QDialogButtonBox::accepted, [this]()
        {
            set_calibration_points(m_crt_calibration);
            this->accept();
        });
        QObject::connect(ui.buttonBox, &QDialogButtonBox::rejected, [this]() { cancel(); });
    }
}
示例#12
0
static void drawTextCommon(GraphicsContext* ctx, const TextRun& run, const FloatPoint& point, int from, int to, const QFont& font, bool isComplexText)
{
    if (to < 0)
        to = run.length();

    QPainter *p = ctx->platformContext();

    QPen textFillPen;
    if (ctx->textDrawingMode() & TextModeFill) {
        if (ctx->fillGradient()) {
            QBrush brush(*ctx->fillGradient()->platformGradient());
            brush.setTransform(ctx->fillGradient()->gradientSpaceTransform());
            textFillPen = QPen(brush, 0);
        } else if (ctx->fillPattern()) {
            AffineTransform affine;
            textFillPen = QPen(QBrush(ctx->fillPattern()->createPlatformPattern(affine)), 0);
        } else
            textFillPen = QPen(QColor(ctx->fillColor()));
    }

    QPen textStrokePen;
    if (ctx->textDrawingMode() & TextModeStroke) {
        if (ctx->strokeGradient()) {
            QBrush brush(*ctx->strokeGradient()->platformGradient());
            brush.setTransform(ctx->strokeGradient()->gradientSpaceTransform());
            textStrokePen = QPen(brush, ctx->strokeThickness());
        } else if (ctx->strokePattern()) {
            AffineTransform affine;
            QBrush brush(ctx->strokePattern()->createPlatformPattern(affine));
            textStrokePen = QPen(brush, ctx->strokeThickness());
        } else
            textStrokePen = QPen(QColor(ctx->strokeColor()), ctx->strokeThickness());
    }

    String sanitized = Font::normalizeSpaces(String(run.characters(), run.length()));
    QString string = fromRawDataWithoutRef(sanitized);
    QPointF pt(point.x(), point.y());

    if (from > 0 || to < run.length()) {
        if (isComplexText) {
            QTextLayout layout(string, font);
            QTextLine line = setupLayout(&layout, run);
            float x1 = line.cursorToX(from);
            float x2 = line.cursorToX(to);
            if (x2 < x1)
                qSwap(x1, x2);

            QFontMetrics fm(font);
            int ascent = fm.ascent();
            QRectF boundingRect(point.x() + x1, point.y() - ascent, x2 - x1, fm.height());
            QRectF clip = boundingRect;

            ContextShadow* ctxShadow = ctx->contextShadow();

            if (ctxShadow->m_type != ContextShadow::NoShadow) {
                qreal dx1 = 0, dx2 = 0, dy1 = 0, dy2 = 0;
                if (ctxShadow->offset().x() > 0)
                    dx2 = ctxShadow->offset().x();
                else
                    dx1 = -ctxShadow->offset().x();
                if (ctxShadow->offset().y() > 0)
                    dy2 = ctxShadow->offset().y();
                else
                    dy1 = -ctxShadow->offset().y();
                // expand the clip rect to include the text shadow as well
                clip.adjust(dx1, dx2, dy1, dy2);
                clip.adjust(-ctxShadow->m_blurDistance, -ctxShadow->m_blurDistance, ctxShadow->m_blurDistance, ctxShadow->m_blurDistance);
            }
            p->save();
            p->setClipRect(clip.toRect(), Qt::IntersectClip);
            pt.setY(pt.y() - ascent);

            if (ctxShadow->m_type != ContextShadow::NoShadow) {
                ContextShadow* ctxShadow = ctx->contextShadow();
                if (!ctxShadow->mustUseContextShadow(p)) {
                    p->save();
                    p->setPen(ctxShadow->m_color);
                    p->translate(ctxShadow->offset());
                    line.draw(p, pt);
                    p->restore();
                } else {
                    QPainter* shadowPainter = ctxShadow->beginShadowLayer(p, boundingRect);
                    if (shadowPainter) {
                        // Since it will be blurred anyway, we don't care about render hints.
                        shadowPainter->setFont(p->font());
                        shadowPainter->setPen(ctxShadow->m_color);
                        line.draw(shadowPainter, pt);
                        ctxShadow->endShadowLayer(p);
                    }
                }
            }
            p->setPen(textFillPen);
            line.draw(p, pt);
            p->restore();
            return;
        }
#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0)
        int skipWidth = QFontMetrics(font).width(string, from, Qt::TextBypassShaping);
        pt.setX(pt.x() + skipWidth);
        string = fromRawDataWithoutRef(sanitized, from, to - from);
#endif
    }

    p->setFont(font);

    int flags = run.rtl() ? Qt::TextForceRightToLeft : Qt::TextForceLeftToRight;
#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0)
    // See QWebPagePrivate::QWebPagePrivate() where the default path is set to Complex for Qt 4.6 and earlier.
    if (!isComplexText && !(ctx->textDrawingMode() & TextModeStroke))
        flags |= Qt::TextBypassShaping;
#endif

    QPainterPath textStrokePath;
    if (ctx->textDrawingMode() & TextModeStroke)
        textStrokePath.addText(pt, font, string);

    ContextShadow* ctxShadow = ctx->contextShadow();
    if (ctxShadow->m_type != ContextShadow::NoShadow) {
        if (ctx->textDrawingMode() & TextModeFill) {
            if (ctxShadow->m_type != ContextShadow::BlurShadow) {
                p->save();
                p->setPen(ctxShadow->m_color);
                p->translate(ctxShadow->offset());
                p->drawText(pt, string, flags, run.padding());
                p->restore();
            } else {
                QFontMetrics fm(font);
#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0)
                QRectF boundingRect(pt.x(), point.y() - fm.ascent(), fm.width(string, -1, flags), fm.height());
#else
                QRectF boundingRect(pt.x(), point.y() - fm.ascent(), fm.width(string), fm.height());
#endif
                QPainter* shadowPainter = ctxShadow->beginShadowLayer(p, boundingRect);
                if (shadowPainter) {
                    // Since it will be blurred anyway, we don't care about render hints.
                    shadowPainter->setFont(p->font());
                    shadowPainter->setPen(ctxShadow->m_color);
                    shadowPainter->drawText(pt, string, flags, run.padding());
                    ctxShadow->endShadowLayer(p);
                }
            }
        } else if (ctx->textDrawingMode() & TextModeStroke) {
            if (ctxShadow->m_type != ContextShadow::BlurShadow) {
                p->translate(ctxShadow->offset());
                p->strokePath(textStrokePath, QPen(ctxShadow->m_color));
                p->translate(-ctxShadow->offset());
            } else {
                QFontMetrics fm(font);
#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0)
                QRectF boundingRect(pt.x(), point.y() - fm.ascent(), fm.width(string, -1, flags), fm.height());
#else
                QRectF boundingRect(pt.x(), point.y() - fm.ascent(), fm.width(string), fm.height());
#endif
                QPainter* shadowPainter = ctxShadow->beginShadowLayer(p, boundingRect);
                if (shadowPainter) {
                    // Since it will be blurred anyway, we don't care about render hints.
                    shadowPainter->setFont(p->font());
                    shadowPainter->strokePath(textStrokePath, QPen(ctxShadow->m_color));
                    ctxShadow->endShadowLayer(p);
                }
            }
        }
    }

    if (ctx->textDrawingMode() & TextModeStroke)
        p->strokePath(textStrokePath, textStrokePen);

    if (ctx->textDrawingMode() & TextModeFill) {
        QPen previousPen = p->pen();
        p->setPen(textFillPen);
        p->drawText(pt, string, flags, run.padding());
        p->setPen(previousPen);
    }
}
示例#13
0
void GameWall::addGame(ChessGame* game)
{
	Q_ASSERT(game != nullptr);

	QWidget* widget = new QWidget(this);

	ChessClock* clock[2] = { new ChessClock(), new ChessClock() };
	QHBoxLayout* clockLayout = new QHBoxLayout();
	for (int i = 0; i < 2; i++)
	{
		clock[i] = new ChessClock();
		clockLayout->addWidget(clock[i]);

		Chess::Side side = Chess::Side::Type(i);
		clock[i]->setPlayerName(side.toString());
	}
	clockLayout->insertSpacing(1, 20);

	BoardScene* scene = new BoardScene();
	BoardView* view = new BoardView(scene);

	QVBoxLayout* mainLayout = new QVBoxLayout();
	mainLayout->addLayout(clockLayout);
	mainLayout->addWidget(view);
	mainLayout->setContentsMargins(0, 0, 0, 0);

	widget->setLayout(mainLayout);
	layout()->addWidget(widget);

	game->lockThread();
	connect(game, SIGNAL(fenChanged(QString)),
		scene, SLOT(setFenString(QString)));
	connect(game, SIGNAL(moveMade(Chess::GenericMove, QString, QString)),
		scene, SLOT(makeMove(Chess::GenericMove)));
	connect(game, SIGNAL(humanEnabled(bool)),
		view, SLOT(setEnabled(bool)));

	for (int i = 0; i < 2; i++)
	{
		ChessPlayer* player(game->player(Chess::Side::Type(i)));

		if (player->isHuman())
			connect(scene, SIGNAL(humanMove(Chess::GenericMove, Chess::Side)),
				player, SLOT(onHumanMove(Chess::GenericMove, Chess::Side)));

		clock[i]->setPlayerName(player->name());
		connect(player, SIGNAL(nameChanged(QString)),
			clock[i], SLOT(setPlayerName(QString)));

		clock[i]->setInfiniteTime(player->timeControl()->isInfinite());

		if (player->state() == ChessPlayer::Thinking)
			clock[i]->start(player->timeControl()->activeTimeLeft());
		else
			clock[i]->setTime(player->timeControl()->timeLeft());

		connect(player, SIGNAL(startedThinking(int)),
			clock[i], SLOT(start(int)));
		connect(player, SIGNAL(stoppedThinking()),
			clock[i], SLOT(stop()));
	}

	scene->setBoard(game->pgn()->createBoard());
	scene->populate();

	foreach (const Chess::Move& move, game->moves())
		scene->makeMove(move);

	game->unlockThread();

	view->setEnabled(!game->isFinished() &&
			 game->playerToMove()->isHuman());
	m_games[game] = widget;

	cleanupWidgets();
}
示例#14
0
ChatPanel::ChatPanel(const QStringList &botNames, UsersColorsPool *colorsPool,
                        TextEditorModifier *chatInputModifier, EmojiManager *emojiManager) :
    QWidget(nullptr),
    ui(new Ui::ChatPanel),
    emojiManager(emojiManager),
    botNames(botNames),
    autoTranslating(false),
    colorsPool(colorsPool),
    unreadedMessages(0),
    on(false)
{
    ui->setupUi(this);
    QVBoxLayout *contentLayout = new QVBoxLayout(ui->scrollContent);
    contentLayout->setContentsMargins(0, 0, 0, 0);
    ui->scrollContent->setLayout(contentLayout);

    ui->topicLabel->setVisible(false);

    // disable blue border when QLineEdit has focus in mac
    ui->chatText->setAttribute(Qt::WA_MacShowFocusRect, 0);

    previousVerticalScrollBarMaxValue = ui->chatScroll->verticalScrollBar()->value();

    emojiWidget = new EmojiWidget(emojiManager, this);
    emojiWidget->setVisible(false);
    qobject_cast<QVBoxLayout *>(layout())->insertWidget(layout()->count()-2, emojiWidget);
    emojiWidget->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::MinimumExpanding);

    auto emojiIcon = IconFactory::createChatEmojiIcon(Qt::black, on);
    emojiAction = ui->chatText->addAction(emojiIcon, QLineEdit::LeadingPosition);

    if (chatInputModifier) {
        bool finishEditorPressingReturnKey = false;
        chatInputModifier->modify(ui->chatText, finishEditorPressingReturnKey);
    }

    ui->scrollContent->installEventFilter(this);

    setupSignals();

    instances.append(this);

    auto root = new QTreeWidgetItem(ui->treeWidget, QStringList());
    root->setFirstColumnSpanned(true); // the root col span
    ui->treeWidget->addTopLevelItem(root);

    connect(ui->treeWidget, &QTreeWidget::collapsed, [=](){
        ui->treeWidget->setMaximumHeight(20);
    });

    connect(ui->treeWidget, &QTreeWidget::expanded, [=](){
        auto root = ui->treeWidget->topLevelItem(0);
        Q_ASSERT(root);
        if (root->childCount() > 0)
            ui->treeWidget->setMaximumHeight(150);
    });

    connect(ui->treeWidget, &QTreeWidget::clicked, [=](QModelIndex index){
        auto root = ui->treeWidget->topLevelItem(0);
        Q_ASSERT(root);
        if (root->isExpanded())
            ui->treeWidget->collapse(index);
        else
            ui->treeWidget->expand(index);
    });

    ui->treeWidget->setMaximumHeight(20);

    ui->treeWidget->setVisible(false);

    ui->treeWidget->setContextMenuPolicy(Qt::CustomContextMenu);

    connect(ui->treeWidget, &QTreeWidget::customContextMenuRequested, this, &ChatPanel::showContextMenu);

    ui->buttonOnOff->setIcon(IconFactory::createChatOnOffIcon(Qt::black));
    ui->buttonOnOff->setChecked(on);
    connect(ui->buttonOnOff, &QPushButton::toggled, this, &ChatPanel::toggleOnOff);

    updatePlaceHolderText();
    updateEmojiIcon();

    showConnectedUsersWidget(false);
}
示例#15
0
void Box::endEdit()
      {
      editMode = false;
      layout();
      }
示例#16
0
void Bracket::editDrag(const EditData& ed)
      {
      h2 += ed.delta.y() * .5;
      layout();
      score()->setLayoutAll(false);
      }
示例#17
0
void VBox::setGrip(int, const QPointF& pt)
      {
      setBoxHeight(Spatium(pt.y()));
      layout();
      }
示例#18
0
void CWizTitleBar::setContentsMargins(QMargins margins)
{
    m_oldContentsMargin = margins;
    QWidget::setContentsMargins(margins);
    layout()->setContentsMargins(margins);
}