Exemple #1
0
//formatting helper functions
void adjustFontSize(QGraphicsTextItem *item, double itemWidth, double itemHeight, double fontSize, int fontWeight=QFont::Normal, double deltaSize = 0)
{
    QFont font;
    font.setWeight(fontWeight);
    // Determine height of text item with given width and font size
    item->setTextWidth(itemWidth);
    font = item->font();
    font.setPointSize(fontSize);
    item->setFont(font);
    int docHeight=item->document()->size().height();
    // if item is not high enough, increase font size
    if (docHeight < itemHeight) {
        // except when it was already made smaller in the previus recursion
        if (deltaSize<0)
            return;
        else
            adjustFontSize(item, itemWidth, itemHeight, fontSize+1, fontWeight, 1);
    }
    //if item is too high decrease font size
    else if (docHeight > itemHeight) {
        if (fontSize < 5)
            return;
        else
            adjustFontSize(item, itemWidth, itemHeight, fontSize-1, fontWeight, -1);
    }

    return;
}
Exemple #2
0
void StoryCardScene::setNotes(const QString & txt)
{
    theStoryNotes->setPlainText(txt.left(200));
    adjustFontSize(theStoryNotes, theNotesRect.width(), theNotesRect.height(), 10.);
    if (theStoryNotes->font().pointSize() < 6)
    {
        theStoryNotes->setPlainText("See TRAC Ticket for details.");
        adjustFontSize(theStoryNotes, theNotesRect.width(), theNotesRect.height(), 10.);
    }
}
void GrEnterArea::paint(QPainter *ppainter, const QStyleOptionGraphicsItem *, QWidget *){
    ppainter->save();
    ppainter->setBrush( brushList.at( curIndexBrush ) );
    ppainter->setPen( penList.at( curIndexPen ) );
    ppainter->drawRect( rect );
    if ( isTextValid ) ppainter->setPen( validTextPenList.at( curIndexValidPen ) );
    else ppainter->setPen( invalidTextPenList.at( curIndexInvalidPen ) );
    adjustFontSize( eaFont, textRect.width(), textRect.height() ,areaText);
    ppainter->setFont( eaFont );
    ppainter->drawText( textRect, Qt::AlignRight, areaText );
    ppainter->restore();
    update();
}
void FontSizeWidget::initWidget()
{
    setObjectName("FontSizeWidget");
    setStyleSheet(getFileContent(":/resources/qss/fontsizewidget.qss"));
    setFixedSize(86, 18);
    m_fontSizeEdit = new QLineEdit(this);
    m_fontSizeEdit->setObjectName("FontSizeEdit");
    m_fontSizeEdit->setFixedSize(LINE_EDIT_SIZE);

    m_fontSize = ConfigSettings::instance()->value("text", "fontsize").toInt();
    m_fontSizeEdit->setText(QString("%1").arg(m_fontSize));
    m_addSizeBtn = new QPushButton(this);
    m_addSizeBtn->setObjectName("AddSizeBtn");
    m_addSizeBtn->setFixedSize(BUTTON_SIZE);
    m_reduceSizeBtn = new QPushButton(this);
    m_reduceSizeBtn->setObjectName("ReduceSizeBtn");
    m_reduceSizeBtn->setFixedSize(BUTTON_SIZE);

    QHBoxLayout* layout = new QHBoxLayout;
    layout->setMargin(0);
    layout->setSpacing(0);
    layout->addSpacing(4);
    layout->addWidget(m_fontSizeEdit);
    layout->addSpacing(0);
    layout->addWidget( new Seperator(this));
    layout->addWidget(m_addSizeBtn);
    layout->addWidget( new Seperator(this));
    layout->addSpacing(0);
    layout->addWidget(m_reduceSizeBtn);
    layout->addStretch();
    setLayout(layout);

    connect(m_addSizeBtn, &QPushButton::clicked, [=]{
        adjustFontSize(true);
    });
    connect(m_reduceSizeBtn, &QPushButton::clicked, [=]{
        adjustFontSize(false);
    });
}
Exemple #5
0
void Screen::writeString(const String &output, int x, int y, int fontSize, bool centered) {
  int adjustedFontSize = !wrappingEnabled ? adjustFontSize(output, x, fontSize) : fontSize;
  int outputLength = outputLengthAsPixelLength(output, adjustedFontSize);
  int newX = centered ? centerizeX(outputLength, x) : x;

  tft.fillRect(0, y, newX, adjustedFontSize * FONT_HEIGHT_MULTIPLIER, currentBackground);
  tft.fillRect(getWidth() - (newX == x ? getWidth() - outputLength : newX), y,
               getWidth(), adjustedFontSize * FONT_HEIGHT_MULTIPLIER, currentBackground);
  
  tft.setCursor(newX, y);
  tft.setTextSize(adjustedFontSize);
  tft.setTextColor(currentTextColor, currentBackground);
  tft.print(output);
}
void LoadingWidget::setVideo(Video *video) {
    adjustFontSize();

    QString title = video->getTitle();
    // enhance legibility by splitting the title
    static const QLatin1String p("<p>");
    title.replace(QLatin1String(" - "), p);
    title.replace(QLatin1String(" | "), p);
    title.replace(QLatin1String(" — "), p);
    title.replace(QLatin1String(": "), p);
    title.replace(QLatin1String("; "), p);
    title.replace(QLatin1String("] "), QLatin1String("]<p>"));
    title.replace(QLatin1String(" ["), QLatin1String("<p>["));
    title.replace(QLatin1String(" ("), QLatin1String("<p>("));
    title.replace(QLatin1String(") "), QLatin1String(")<p>"));
    titleLabel->setText(title);
    titleLabel->setVisible(window()->height() > 100);

    const int maxDescLength = 500;

    QString videoDesc = video->getDescription();
    if (videoDesc.length() > maxDescLength) {
        videoDesc.truncate(maxDescLength);
        videoDesc = videoDesc.trimmed();
        videoDesc.append("…");
    } else if (videoDesc.endsWith(QLatin1String(" ..."))) {
        videoDesc = videoDesc.left(videoDesc.length() - 4);
        videoDesc.append("…");
    }
    static const QRegExp linkRE("(https?://\\S+)");
    videoDesc.replace(linkRE, QStringLiteral("<a style='color:white' href=\"\\1\">\\1</a>"));
    descriptionLabel->setText(videoDesc);
    bool hiddenDesc = height() < 400;
    if (hiddenDesc)
        titleLabel->setAlignment(Qt::AlignCenter);
    else
        titleLabel->setAlignment(Qt::AlignHCenter | Qt::AlignBottom);
    descriptionLabel->setVisible(!hiddenDesc);

    progressBar->setValue(0);
    startTime.start();
}
Exemple #7
0
void StoryCardScene::setHTD(const QString & txt)
{
    theStoryHTD->setPlainText(txt);
    adjustFontSize(theStoryHTD, theHTDRect.width(), theHTDRect.height(), 10.);
}
Exemple #8
0
void StoryCardScene::setDesc(const QString & txt)
{
    theStoryDesc->setPlainText(txt);
    adjustFontSize(theStoryDesc, theDescRect.width(), theDescRect.height(), 10., QFont::Bold);
}
Exemple #9
0
void StoryCardScene::setParent(const QString & txt)
{
    theParentStory->setPlainText(txt);
    adjustFontSize(theParentStory, theParentRect.width(), theParentRect.height(), 10.);
}
Exemple #10
0
void StoryCardScene::setUser(const QString & txt)
{
    theStoryUser->setPlainText(txt);
    adjustFontSize(theStoryUser, theUserRect.width(), theUserRect.height(), 10.);
    center(theStoryUser);
}
Exemple #11
0
void StoryCardScene::setEst(const QString & txt)
{
    theStoryEst->setPlainText(txt=="?"?"":txt);
    adjustFontSize(theStoryEst, theEstRect.width(), theEstRect.height(), 10.);
    center(theStoryEst);
}
Exemple #12
0
void StoryCardScene::setImp(const QString & txt)
{
    theStoryImp->setPlainText(txt=="none"?"":txt);
    adjustFontSize(theStoryImp, theImpRect.width(), theImpRect.height(), 10.);
    center(theStoryImp);
}
void LoadingWidget::resizeEvent(QResizeEvent *e) {
    Q_UNUSED(e);
    if (isVisible()) adjustFontSize();
}