Пример #1
0
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::setSide(Side side)
{
    m_d->m_side = side;

    Side iconpos = side;
    if (layoutDirection() == Qt::RightToLeft)
        iconpos = (side == Left ? Right : Left);

    // Make room for icon

    // Let the style determine minimum height for our widget
    QSize size(ICONBUTTON_SIZE + 6, ICONBUTTON_SIZE + 2);

    // Note KDE does not reserve space for the highlight color
    if (style()->inherits("OxygenStyle")) {
        size = size.expandedTo(QSize(24, 0));
    }

    QMargins margins;
    if (iconpos == Right)
        margins.setRight(size.width());
    else
        margins.setLeft(size.width());

    setTextMargins(margins);
}
Пример #3
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);
}
Пример #4
0
/*!
 * Constructs a file chooser with a given \a parent.
 * 
 */
QwwFileChooser::QwwFileChooser(QWidget *parent) : QwwButtonLineEdit(*new QwwFileChooserPrivate(this), parent) {
    Q_D(QwwFileChooser);
#if QT_VERSION >= 0x040200 && !defined(QT_NO_COMPLETER)
    d->completer = new QCompleter(this);
    setCompleter(d->completer);
    QStyleOption opt;
    opt.initFrom(this);
    int mar = style()->pixelMetric(QStyle::PM_DefaultFrameWidth, &opt, this);
    int siz = style()->pixelMetric(QStyle::PM_SmallIconSize, &opt, this);
#if QT_VERSION >=0x040500
    setTextMargins(siz+2, 0, 0, 0);
#else
    setStyleSheet(QString("QwwFileChooser {padding-left: %1px;}").arg(mar+siz+2));
#endif

//     connect(this, SIGNAL(textEdited(const QString&)), d->completer, SLOT(setCompletionPrefix(const QString&)));
#endif
    setModel(new QDirModel(this));
    setButtonPosition(RightOutside);
    connect(this, SIGNAL(buttonClicked()), this, SLOT(chooseFile()));
    setAutoRaise(true);
    setAcceptMode(QFileDialog::AcceptOpen);

    QShortcut *sc = new QShortcut(QKeySequence("Ctrl+Space"), this);
    connect(sc, SIGNAL(activated()), d->completer, SLOT(complete()));
    connect(this, SIGNAL(textChanged(const QString&)), this, SLOT(_q_textChanged(const QString&)));
}
Пример #5
0
void LineEdit::setRightIcon(const QPixmap & icon)
{
	rightIcon_ = icon;
	QMargins margins = textMargins();
	margins.setRight(icon.width() + 6);
	setTextMargins(margins);
}
Пример #6
0
void LineEdit::setLeftIcon(const QPixmap & icon)
{
	leftIcon_ = icon;
	QMargins margins = textMargins();
	margins.setLeft(icon.width() + 2);
	setTextMargins(margins);
}
Пример #7
0
FlatInput::FlatInput(QWidget *parent, const style::flatInput &st, const QString &pholder, const QString &v) : QLineEdit(v, parent),
_fullph(pholder), _oldtext(v), _fastph(false), _kev(0), _customUpDown(false), _phVisible(!v.length()),
	a_phLeft(_phVisible ? 0 : st.phShift), a_phAlpha(_phVisible ? 1 : 0), a_phColor(st.phColor->c),
    a_borderColor(st.borderColor->c), a_bgColor(st.bgColor->c), _notingBene(0), _st(st) {
	resize(_st.width, _st.height);
	
	setFont(_st.font->f);
	setAlignment(_st.align);

	QPalette p(palette());
	p.setColor(QPalette::Text, _st.textColor->c);
	setPalette(p);

	connect(this, SIGNAL(textChanged(const QString &)), this, SLOT(onTextChange(const QString &)));
	connect(this, SIGNAL(textEdited(const QString &)), this, SLOT(onTextEdited()));
	if (App::wnd()) connect(this, SIGNAL(selectionChanged()), App::wnd(), SLOT(updateGlobalMenu()));

	setStyle(&_flatInputStyle);
	setTextMargins(0, 0, 0, 0);
	setContentsMargins(0, 0, 0, 0);

	setAttribute(Qt::WA_AcceptTouchEvents);
	_touchTimer.setSingleShot(true);
	connect(&_touchTimer, SIGNAL(timeout()), this, SLOT(onTouchTimer()));
}
Пример #8
0
void EditableLabel::startEditing()
{
    setReadOnly(false);
    setFrame(true);
    setTextMargins(originalMargins.left, originalMargins.top, originalMargins.right,
                   originalMargins.bottom);
    QLineEdit::setPalette(originalPalette);
}
void LineEditWithSlider::resizeEvent( QResizeEvent* event )
{
  int padding = 0;
  int textMinimalWidth = 45;
  int sliderWidth = width() - textMinimalWidth - 2;
  setTextMargins(padding, 0, sliderWidth, 0);
  QLineEdit::resizeEvent(event);
  slider_->setGeometry(textMinimalWidth, padding, sliderWidth, height());
}
Пример #10
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() );
}
Пример #11
0
void LineEdit::updateTextMargins()
{
    int left = textMargin(LineEdit::LeftSide);
    int right = textMargin(LineEdit::RightSide);
    int top = 0;
    int bottom = 0;
    setTextMargins(left, top, right, bottom);
    updateSideWidgetLocations();
}
Пример #12
0
void EditableLabel::stopEditing()
{
    QPalette p = originalPalette;
    p.setBrush(QPalette::Base, p.window());
    p.setBrush(QPalette::Text, p.windowText());
    QLineEdit::setPalette(p);

    setReadOnly(true);
    setFrame(false);
    setTextMargins(-2, 0, 0, 0);
    deselect();
}
Пример #13
0
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));
}
Пример #14
0
void LineEditWidget::showEvent(QShowEvent *e)
{
    // Width of standard QLineEdit plus extended tool buttons
    int width = 0;
    for (QWidget *w: _toolbuttons) {
        if (w->isVisible()) {
            width += w->width();
            QAbstractButton *bt = qobject_cast<QAbstractButton*>(w);
            if (bt && bt->iconSize().height() > bt->height()) {
                bt->setIconSize(QSize(bt->height(), bt->height()));
            }
        }
    }

    setTextMargins(0, 0, width, 0);
    QLineEdit::showEvent(e);
}
Пример #15
0
void FancyLineEdit::updateMargins() {
    bool leftToRight = (layoutDirection() == Qt::LeftToRight);
    Side realLeft = (leftToRight ? Left : Right);
    Side realRight = (leftToRight ? Right : Left);

    int leftMargin = d->m_iconbutton[realLeft]->pixmap().width() + 8;
    int rightMargin = d->m_iconbutton[realRight]->pixmap().width() + 8;
    // Note KDE does not reserve space for the highlight color
    if (style()->inherits("OxygenStyle")) {
        leftMargin = qMax(24, leftMargin);
        rightMargin = qMax(24, rightMargin);
    }

    QMargins margins((d->m_iconEnabled[realLeft] ? leftMargin : 0), 0,
                     (d->m_iconEnabled[realRight] ? rightMargin : 0), 0);

    setTextMargins(margins);
}
Пример #16
0
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();
}
Пример #17
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 );
}
Пример #18
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);
}
Пример #19
0
	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 ());
	}
Пример #20
0
void SkeletalAnimationSample::createHUD()
{
    hud_.setName("HUD");
    hud_.setIs2D(true);

    // Logo texture
    auto logo = hud_.addEntity<Sprite>("Logo", 64.0f, 64.0f);
    logo->setSpriteTexture("CarbonLogo.png");
    logo->alignToScreen(GUIWindow::ScreenTopLeft, Vec2(5.0f, -5.0f));

    // Crosshair
    auto crosshair = hud_.addEntity<Sprite>("Crosshair", 31.0f, 31.0f);
    crosshair->setSpriteTexture("Crosshair.png");
    crosshair->alignToScreen(GUIWindow::ScreenMiddle);

    // Add info label
    auto info = hud_.addEntity<GUIWindow>("Info", 300.0f, 35.0f);
    info->move({5.0f, 30.0f});
    info->setText("Press the left mouse button to switch between animations.\n\n"
                  "Press R to toggle ragdoll, or K to toggle rendering of the skeleton.\n"
                  "Press B to toggle display of the bounding volume.");
    info->setTextMargins(7.0f);
    info->autosize();
}