void AddressWidget::optionChanged(const QString &option, const QVariant &value) { if (option == QLatin1String("AddressField/ShowBookmarkIcon")) { if (value.toBool() && !m_bookmarkLabel) { m_bookmarkLabel = new QLabel(this); m_bookmarkLabel->setObjectName(QLatin1String("Bookmark")); m_bookmarkLabel->setAutoFillBackground(false); m_bookmarkLabel->setFixedSize(16, 16); m_bookmarkLabel->move((width() - 22), 4); m_bookmarkLabel->setPixmap(Utils::getIcon(QLatin1String("bookmarks")).pixmap(m_bookmarkLabel->size(), QIcon::Disabled)); m_bookmarkLabel->setCursor(Qt::ArrowCursor); m_bookmarkLabel->installEventFilter(this); } else if (!value.toBool() && m_bookmarkLabel) { m_bookmarkLabel->deleteLater(); m_bookmarkLabel = NULL; } } else if (option == QLatin1String("AddressField/ShowUrlIcon")) { if (value.toBool() && !m_urlIconLabel) { m_urlIconLabel = new QLabel(this); m_urlIconLabel->setObjectName(QLatin1String("Url")); m_urlIconLabel->setAutoFillBackground(false); m_urlIconLabel->setFixedSize(16, 16); m_urlIconLabel->setPixmap((m_window ? m_window->getIcon() : Utils::getIcon(QLatin1String("tab"))).pixmap(m_urlIconLabel->size())); m_urlIconLabel->move(36, 4); m_urlIconLabel->installEventFilter(this); QMargins margins = textMargins(); margins.setLeft(52); setTextMargins(margins); } else { if (!value.toBool() && m_urlIconLabel) { m_urlIconLabel->deleteLater(); m_urlIconLabel = NULL; } QMargins margins = textMargins(); margins.setLeft(30); setTextMargins(margins); } } }
void FancyLineEdit::resizeEvent(QResizeEvent *) { QRect contentRect = rect(); Side iconpos = m_d->m_side; if (layoutDirection() == Qt::RightToLeft) iconpos = (iconpos == Left ? Right : Left); if (iconpos == FancyLineEdit::Right) { const int iconoffset = textMargins().right() + 4; m_d->m_iconbutton->setGeometry(contentRect.adjusted(width() - iconoffset, 0, 0, 0)); } else { const int iconoffset = textMargins().left() + 4; m_d->m_iconbutton->setGeometry(contentRect.adjusted(0, 0, -width() + iconoffset, 0)); } }
void LineEdit::paintEvent(QPaintEvent* event) { QLineEdit::paintEvent(event); if(hasIcon()) { QPainter painter(this); painter.drawPixmap(3, 2, icon_); } QPainter painter(this); QFontMetrics fm(font()); QMargins margins = textMargins(); if(!prefix_.isEmpty()) { int x = margins.left() - fm.width(prefix_) + 4; int y = margins.top() + fm.height(); painter.setPen(prefixColor_); painter.drawText(x, y, prefix_); } if(!suffix_.isEmpty()) { int x = width() - margins.right(); int y = margins.top() + fm.height(); painter.setPen(suffixColor_); painter.drawText(x, y, suffix_); } }
void LineEdit::paintEvent(QPaintEvent * event) { QLineEdit::paintEvent(event); QPainter p(this); // draw the default text if needed bool showDefaultText = text().isEmpty() && !infoText_.isEmpty(); if (showDefaultText) { p.setPen(Qt::gray); const QMargins margins = textMargins(); p.drawText(QRect(margins.left() + 8, margins.top(), width() - margins.left() - margins.right() - 8, height() - margins.top() - margins.bottom()), infoText_, Qt::AlignLeft | Qt::AlignVCenter); } // draw left icon if (!leftIcon_.isNull()) { int offset = 1 + (height() - leftIcon_.height() ) / 2; p.drawPixmap(offset, offset, leftIcon_); } // draw right icon if (!showDefaultText && !rightIcon_.isNull()) { p.drawPixmap(width() - rightIcon_.width() - 7, 1 + (height() - rightIcon_.height()) / 2, rightIcon_); } }
void FancyLineEdit::updateButtonPositions() { QRect contentRect = rect(); for (int i = 0; i < 2; ++i) { Side iconpos = (Side)i; if (layoutDirection() == Qt::RightToLeft) iconpos = (iconpos == Left ? Right : Left); if (iconpos == FancyLineEdit::Right) { const int iconoffset = textMargins().right() + 4; d->m_iconbutton[i]->setGeometry(contentRect.adjusted(width() - iconoffset, 0, 0, 0)); } else { const int iconoffset = textMargins().left() + 4; d->m_iconbutton[i]->setGeometry(contentRect.adjusted(0, 0, -width() + iconoffset, 0)); } } }
void LineEdit::setRightIcon(const QPixmap & icon) { rightIcon_ = icon; QMargins margins = textMargins(); margins.setRight(icon.width() + 6); setTextMargins(margins); }
void LineEdit::setLeftIcon(const QPixmap & icon) { leftIcon_ = icon; QMargins margins = textMargins(); margins.setLeft(icon.width() + 2); setTextMargins(margins); }
QRect PrimerLineEdit::placeHolderRect() const { QStyleOptionFrame panel; initStyleOption(&panel); QRect r = style()->subElementRect(QStyle::SE_LineEditContents, &panel, this); r.setX(r.x() + textMargins().left()); r.setY(r.y() + textMargins().top()); r.setRight(r.right() - textMargins().right()); r.setBottom(r.bottom() - textMargins().bottom()); QFontMetrics fm = fontMetrics(); int minLB = qMax(0, -fm.minLeftBearing()); int minRB = qMax(0, -fm.minRightBearing()); int vscroll = r.y() + (r.height() - fm.height() + 1) / 2; static const int horizontalMargin = 2; // QLineEditPrivate::horizontalMargin QRect lineRect(r.x() + horizontalMargin, vscroll, r.width() - 2*horizontalMargin, fm.height()); return lineRect.adjusted(minLB, 0, -minRB, 0); }
void ColorEditor::resizeEvent( QResizeEvent* event ) { // Do the normal line-edit-with-button thing LineEditWithButton::resizeEvent( event ); // Then add text padding on the left to make room for the color swatch QMargins marge = textMargins(); setTextMargins( height(), marge.top(), marge.right(), marge.bottom() ); }
QSize LineEditWidget::sizeHint() const { QSize size; size = QLineEdit::sizeHint(); int width = 0; if(_optimalLength) { width += fontMetrics().width(QStringLiteral("0")) * _optimalLength; } else { width += size.width(); } width += textMargins().right(); size.setWidth(width); return size; }
void ProgressLineEdit::RepaintButtons () { const int frameWidth = style ()->pixelMetric (QStyle::PM_DefaultFrameWidth); int rightBorder = 0; int realBorder = 0; for (int i = VisibleButtons_.count () - 1; i >= 0; --i) { QToolButton *btn = VisibleButtons_ [i]; const QSize& bmSz = btn->sizeHint (); rightBorder += bmSz.width (); if (i > 0) realBorder += bmSz.width (); btn->move (rect ().right () - frameWidth - rightBorder, (rect ().bottom () + 1 - bmSz.height ()) / 2); } const QMargins& margins = textMargins (); setTextMargins (margins.left (), margins.top (), realBorder + frameWidth, margins.bottom ()); }