Exemple #1
0
void pLineEdit::paintEvent( QPaintEvent* event )
{
	QLineEdit::paintEvent( event );
	
	if ( !mPromptText.isEmpty() && text().isEmpty() && isEnabled() ) {
		QStyleOptionFrameV3 option;
		initStyleOption( &option );
		
		int left;
		int top;
		int right;
		int bottom;
		
		getTextMargins( &left, &top, &right, &bottom );
		
		const Qt::Alignment va = style()->visualAlignment( layoutDirection(), alignment() );
		const QRect rect = style()->subElementRect( QStyle::SE_LineEditContents, &option, this ).adjusted( 2, 0, 0, 0 ).adjusted( left, top, -right, -bottom );
		const QFontMetrics fm( font() );
		const QString text = fm.elidedText( mPromptText, Qt::ElideRight, rect.width() );
		QPainter painter( this );
		
		painter.setPen( palette().color( QPalette::Disabled, QPalette::Text ) );
		painter.drawText( rect, va, text );
	}
}
void TextInput::paintEvent(QPaintEvent* event)
{
    QLineEdit::paintEvent(event);

    if (!d.hint.isEmpty()) {
        QStyleOptionFrameV2 option;
        initStyleOption(&option);

        QRect r = style()->subElementRect(QStyle::SE_LineEditContents, &option, this);
        int left, top, right, bottom;
        getTextMargins(&left, &top, &right, &bottom);
        left += qMax(0, -fontMetrics().minLeftBearing());
        r.adjust(left, top, -right, -bottom);
        r.adjust(hMargin, vMargin, -hMargin, -vMargin);

        QString txt = text();
        if (!txt.isEmpty()) {
            if (!txt.endsWith(" "))
                txt += " ";
            r.adjust(fontMetrics().width(txt), 0, 0, 0);
        }

        QPainter painter(this);
        QColor color = palette().text().color();
        color.setAlpha(128);
        painter.setPen(color);

        QString hint = fontMetrics().elidedText(d.hint, Qt::ElideRight, r.width());
        painter.drawText(r, alignment(), hint);
    }
}
Exemple #3
0
void PlaceholderEdit46::paintEvent(QPaintEvent *evt) {
    QLineEdit::paintEvent(evt);
    if(text().isEmpty() && !hasFocus() && !m_placeholderText.isEmpty()) {
        QPainter p(this);
        QStyleOptionFrameV2 panel;
        QLineEdit::initStyleOption(&panel);
        QRect r = style()->subElementRect(QStyle::SE_LineEditContents, &panel, this);
        int leftMgn, topMgn, rightMgn, bottomMgn;
        getTextMargins(&leftMgn, &topMgn, &rightMgn, &bottomMgn);
        r.setX(r.x() + leftMgn);
        r.setY(r.y() + topMgn);
        r.setRight(r.right() - rightMgn);
        r.setBottom(r.bottom() - bottomMgn);
        p.setClipRect(r);
        QFontMetrics fm = fontMetrics();

        QRect lineRect(r.x() + 2,
                       r.y() + (r.height() - fm.height() + 1) / 2,
                       r.width() - 4,
                       fm.height());

        QColor col(palette().text().color());
        col.setAlpha(128);
        QPen oldpen = p.pen();
        p.setPen(col);
        p.drawText(lineRect, m_placeholderText);
        p.setPen(oldpen);
    }
}
Exemple #4
0
void LocationBar::paintEvent(QPaintEvent* event)
{
    LineEdit::paintEvent(event);

    // Show loading progress
    if (qzSettings->showLoadingProgress && m_progressVisible) {
        QStyleOptionFrame option;
        initStyleOption(&option);

        int lm, tm, rm, bm;
        getTextMargins(&lm, &tm, &rm, &bm);

        QRect contentsRect = style()->subElementRect(QStyle::SE_LineEditContents, &option, this);
        contentsRect.adjust(lm, tm, -rm, -bm);

        QColor bg = m_progressColor;
        if (!bg.isValid() || bg.alpha() == 0) {
            bg = Colors::mid(palette().color(QPalette::Base), palette().color(QPalette::Text), m_progressStyle > 0 ? 4 : 8, 1);
        }

        QPainter p(this);
        p.setBrush(QBrush(bg));

        // We are painting over text, make sure the text stays visible
        p.setOpacity(0.5);

        QPen outlinePen(bg.darker(110), 0.8);
        p.setPen(outlinePen);

        switch (m_progressStyle) {
        case ProgressFilled: {
            QRect bar = contentsRect.adjusted(0, 1, 0, -1);
            bar.setWidth(bar.width() * m_loadProgress / 100);
            const int roundness = bar.height() / 4.0;
            p.drawRoundedRect(bar, roundness, roundness);
            break;
        }
        case ProgressBottom: {
            outlinePen.setWidthF(0.3);
            outlinePen.setColor(outlinePen.color().darker(130));
            p.setPen(outlinePen);
            QRect bar(contentsRect.x(), contentsRect.bottom() - 3,
                      contentsRect.width() * m_loadProgress / 100.0, 3);
            p.drawRoundedRect(bar, 1, 1);
            break;
        }
        case ProgressTop: {
            outlinePen.setWidthF(0.3);
            outlinePen.setColor(outlinePen.color().darker(130));
            p.setPen(outlinePen);
            QRect bar(contentsRect.x(), contentsRect.top() + 1, contentsRect.width() * m_loadProgress / 100.0, 3);
            p.drawRoundedRect(bar, 1, 1);
            break;
        }
        default:
            break;
        }
    }
}
Exemple #5
0
EditableLabel::EditableLabel(QWidget *parent)
    : QLineEdit(parent)
{
    getTextMargins(&originalMargins.left, &originalMargins.top,
                   &originalMargins.right, &originalMargins.bottom);
    originalPalette = palette();
    setFocusPolicy(Qt::NoFocus);

    stopEditing();

    connect(this, SIGNAL(editingFinished()), SLOT(stopEditing()));
}
Exemple #6
0
void QExpandingLineEdit::updateMinimumWidth()
{
    int left, right;
    getTextMargins(&left, 0, &right, 0);
    int width = left + right + 4 /*horizontalMargin in qlineedit.cpp*/;
    getContentsMargins(&left, 0, &right, 0);
    width += left + right;

    QStyleOptionFrameV2 opt;
    initStyleOption(&opt);

    int minWidth = style()->sizeFromContents(QStyle::CT_LineEdit, &opt, QSize(width, 0).
                   expandedTo(QApplication::globalStrut()), this).width();
    setMinimumWidth(minWidth);
}
SearchEdit::SearchEdit(QWidget *parent) : QLineEdit(parent)
{
	setAttribute(Qt::WA_MacShowFocusRect, false);
	setMouseTracking(true);
	int padding_left, padding_top, padding_right, padding_bottom;
	getTextMargins(&padding_left, &padding_top, &padding_right, &padding_bottom);
	setTextMargins(padding_left, padding_top, padding_right, padding_bottom);
	connect(this, SIGNAL(textChanged(const QString &)), SLOT(onTextChanged(const QString &)));
	iconStorage = IconStorage::staticStorage(RSR_STORAGE_MENUICONS);
	iconLabel = new QLabel(this);
	iconLabel->setFixedSize(16, 16);
	iconLabel->setMouseTracking(true);
	iconLabel->setProperty(CBC_IGNORE_FILTER, true);
	//currentIcon = iconStorage->getIcon(MNI_ROSTERSEARCH_ICON_GLASS);
	//if (!currentIcon.isNull())
	//	iconLabel->setPixmap(currentIcon.pixmap(16, QIcon::Normal, QIcon::On));
}
KviThemedLineEdit::KviThemedLineEdit(QWidget * par, KviWindow * pWindow, const char * name)
    : QLineEdit(par)
{
	setObjectName(name);
	m_pKviWindow = pWindow;

	setFrame(false);

	int l, t, r, b;
	getTextMargins(&l, &t, &r, &b);
	if(l < 4)
		l = 4;
	if(r < 4)
		r = 4;
	setTextMargins(l, t, r, b);

	setAutoFillBackground(false);
	applyOptions();
}
Exemple #9
0
void JishoLookupEdit::paintEvent(QPaintEvent *event)
{
   QLineEdit::paintEvent(event);

   if (text().isEmpty())
   {
      QPainter painter(this);
      QRect r = event->rect();
      int marginLeft, marginTop, marginRight, marginBottom;
      getTextMargins(
            &marginLeft,
            &marginTop,
            &marginRight,
            &marginBottom);
      r.adjust(marginLeft + 15, marginTop, -marginRight - 15, -marginBottom);
      painter.setPen(palette().color(QPalette::Dark));
      painter.drawText(r, Qt::AlignHCenter | Qt::AlignVCenter, tr("Enter search phrase here"));
   }
}
Exemple #10
0
void pLineEdit::setSearchButtonVisible( bool visible )
{
	tbSearch->setVisible( visible );
	
	int left;
	int top;
	int right;
	int bottom;
	
	getTextMargins( &left, &top, &right, &bottom );
	
	if ( visible ) {
		left = mMargin +mSpacing;
	}
	else {
		left = 0;
	}
	
	setTextMargins( left, top, right, bottom );
}
Exemple #11
0
void ActionLineEdit::actionEvent ( QActionEvent * event )
{
	QHBoxLayout *lo = (QHBoxLayout *)layout();
	QAction *act = event->action();
	ActionLineEditButton *btn;
	if (event->type() == QEvent::ActionAdded) {
		btn = new ActionLineEditButton(this);
		QAction *before = event->before();
		int beforeInd;
		if (before && (beforeInd = actions().indexOf(before)) >= 0) { //TODO test it
			lo->insertWidget(beforeInd + 1, btn); //1 - first item is spacer. skip it
		}
		else {
			lo->addWidget(btn);
		}
		btn->setDefaultAction(act);
	}
	else if (event->type() == QEvent::ActionRemoved) {
		for (int i=1, count=lo->count(); i<count; i++) {
			btn = (ActionLineEditButton *)lo->itemAt(i)->widget();
			if (btn->defaultAction() == act) {
				lo->removeWidget(btn);
				delete btn;
				break;
			}
		}
	}
	int sumWidth = 0;
	for (int i=1, count=lo->count(); i<count; i++) {
		btn = (ActionLineEditButton *)lo->itemAt(i)->widget();
		if (btn->defaultAction()->isVisible()) {
			sumWidth += btn->width();
		}
	}
	sumWidth += 4; //+4px padding between text and buttons. should looks better (magic number)
	int mLeft, mTop, mRight, mBottom;
	getTextMargins(&mLeft, &mTop, &mRight, &mBottom);
	setTextMargins(mLeft, mTop, sumWidth, mBottom);
}