Exemplo n.º 1
0
void LineEdit::updateLayout()
{
	int size = height();
	int leftMargin = 0;
	int rightMargin = 0;

	if(hasButton()) {
		rightMargin = size;
		button_->setGeometry(width() - size + 1, 1, size - 2, size - 2);
	}

	if(hasIcon())
		leftMargin = 16;

	if(!prefix_.isEmpty()) {
		QFontMetrics fm(font());
		leftMargin += fm.width(prefix_);
	}

	if(!suffix_.isEmpty()) {
		QFontMetrics fm(font());
		rightMargin += fm.width(suffix_);
	}

	setTextMargins(leftMargin, 0, rightMargin, 0);
}
Exemplo n.º 2
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_);
	}
}
Exemplo n.º 3
0
void TKAction::updateLayout(QWidget* base)
{
  QLabel* textLabel = (QLabel*)base->child("text");
  QLabel* pixLabel = (QLabel*)base->child("pixmap");
  QWidget* w = (QWidget*)base->child("widget");

  if (!textLabel || !pixLabel || !w)
    return;

  if (!text().isEmpty() && m_imode != TK::IconOnly ) {
    textLabel->setText(text());
    textLabel->show();
  } else
    textLabel->hide();

  QPixmap pix;
  if (hasIcon())
    pix = iconSet(KIcon::Small).pixmap();

  if (!icon().isEmpty())
    pix = BarIcon(icon());

  if (!pix.isNull() && m_imode != TK::TextOnly) {
    pixLabel->setPixmap(pix);
    pixLabel->show();
  } else
    pixLabel->hide();

  base->setFixedWidth( w->sizeHint().width() +
                       (textLabel->isVisible() ? textLabel->sizeHint().width():0) +
                       (pixLabel->isVisible() ? pixLabel->sizeHint().width():0) );
}
Exemplo n.º 4
0
void LineEdit::mouseMoveEvent(QMouseEvent* event)
{
	QLineEdit::mouseMoveEvent(event);

	if(hasIcon()) {
		if(event->x() < 16 + 2) {
			setCursor(Qt::PointingHandCursor);
		}
		else {
			setCursor(Qt::IBeamCursor);
		}
	}
}