示例#1
0
Checkbox::Checkbox(QWidget *parent, const QString &text, bool checked, const style::Checkbox &st) : Button(parent),
_st(st),
a_over(0), a_checked(checked ? 1 : 0),
_a_over(animFunc(this, &Checkbox::animStep_over)), _a_checked(animFunc(this, &Checkbox::animStep_checked)),
_text(text), _fullText(text), _textWidth(st.font->width(text)),
_checked(checked) {
	if (_st.width <= 0) {
		resize(_textWidth - _st.width, _st.height);
	} else {
		if (_st.width < _st.textPosition.x() + _textWidth + (_st.textPosition.x() - _st.diameter)) {
			_text = _st.font->elided(_fullText, qMax(_st.width - (_st.textPosition.x() + (_st.textPosition.x() - _st.diameter)), 1.));
			_textWidth = _st.font->width(_text);
		}
		resize(_st.width, _st.height);
	}
	_checkRect = myrtlrect(0, 0, _st.diameter, _st.diameter);

	connect(this, SIGNAL(clicked()), this, SLOT(onClicked()));
	connect(this, SIGNAL(stateChanged(int, ButtonStateChangeSource)), this, SLOT(onStateChange(int, ButtonStateChangeSource)));

	setCursor(style::cur_pointer);

	setAttribute(Qt::WA_OpaquePaintEvent);
}
示例#2
0
void MaxInviteBox::resizeEvent(QResizeEvent *e) {
    _close.moveToRight(st::boxButtonPadding.right(), height() - st::boxButtonPadding.bottom() - _close.height());
    _invitationLink = myrtlrect(st::boxPadding.left(), st::boxPadding.top() + _textHeight + st::boxTextFont->height, width() - st::boxPadding.left() - st::boxPadding.right(), 2 * st::boxTextFont->height);
    AbstractBox::resizeEvent(e);
}
示例#3
0
void PlayerWidget::paintEvent(QPaintEvent *e) {
	Painter p(this);

	QRect r(e->rect()), checkr(myrtlrect(r));
	p.fillRect(r, st::playerBg->b);

	if (!_playbackRect.contains(checkr)) {
		if (_fullAvailable && checkr.intersects(_prevRect)) {
			if (_prevAvailable) {
				float64 o = _stateHovers[OverPrev];
				p.setOpacity(o * 1. + (1. - o) * st::playerInactiveOpacity);
			} else {
				p.setOpacity(st::playerUnavailableOpacity);
			}
			p.drawSpriteCenterLeft(_prevRect, width(), st::playerPrev);
		}
		if (checkr.intersects(_playRect)) {
			float64 o = _stateHovers[OverPlay];
			p.setOpacity(o * 1. + (1. - o) * st::playerInactiveOpacity);
			p.drawSpriteCenterLeft(_playRect, width(), (_showPause || _down == OverPlayback) ? st::playerPause : st::playerPlay);
		}
		if (_fullAvailable && checkr.intersects(_nextRect)) {
			if (_nextAvailable) {
				float64 o = _stateHovers[OverNext];
				p.setOpacity(o * 1. + (1. - o) * st::playerInactiveOpacity);
			} else {
				p.setOpacity(st::playerUnavailableOpacity);
			}
			p.drawSpriteCenterLeft(_nextRect, width(), st::playerNext);
		}
		if (checkr.intersects(_closeRect)) {
			float64 o = _stateHovers[OverClose];
			p.setOpacity(o * 1. + (1. - o) * st::playerInactiveOpacity);
			p.drawSpriteCenterLeft(_closeRect, width(), st::playerClose);
		}
		if (checkr.intersects(_volumeRect)) {
			float64 o = _stateHovers[OverVolume];
			p.setOpacity(o * 1. + (1. - o) * st::playerInactiveOpacity);
			int32 top = _volumeRect.y() + (_volumeRect.height() - st::playerVolume.pxHeight()) / 2;
			int32 left = _volumeRect.x() + (_volumeRect.width() - st::playerVolume.pxWidth()) / 2;
			int32 mid = left + qRound(st::playerVolume.pxWidth() * cSongVolume());
			int32 right = left + st::playerVolume.pxWidth();
			if (rtl()) {
				left = width() - left;
				mid = width() - mid;
				right = width() - right;
				if (mid < left) {
					p.drawPixmap(QRect(mid, top, left - mid, st::playerVolume.pxHeight()), App::sprite(), QRect(st::playerVolume.x() + (mid - right) * cIntRetinaFactor(), st::playerVolume.y(), (left - mid) * cIntRetinaFactor(), st::playerVolume.pxHeight() * cIntRetinaFactor()));
				}
				if (right < mid) {
					p.setOpacity(st::playerUnavailableOpacity);
					p.drawPixmap(QRect(right, top, mid - right, st::playerVolume.pxHeight()), App::sprite(), QRect(st::playerVolume.x(), st::playerVolume.y(), (mid - right) * cIntRetinaFactor(), st::playerVolume.pxHeight() * cIntRetinaFactor()));
				}
			} else {
				if (mid > left) {
					p.drawPixmap(QRect(left, top, mid - left, st::playerVolume.pxHeight()), App::sprite(), QRect(st::playerVolume.x(), st::playerVolume.y(), (mid - left) * cIntRetinaFactor(), st::playerVolume.pxHeight() * cIntRetinaFactor()));
				}
				if (right > mid) {
					p.setOpacity(st::playerUnavailableOpacity);
					p.drawPixmap(QRect(mid, top, right - mid, st::playerVolume.pxHeight()), App::sprite(), QRect(st::playerVolume.x() + (mid - left) * cIntRetinaFactor(), st::playerVolume.y(), (right - mid) * cIntRetinaFactor(), st::playerVolume.pxHeight() * cIntRetinaFactor()));
				}
			}
		}
		if (_fullAvailable && checkr.intersects(_fullRect)) {
			float64 o = _stateHovers[OverFull];
			p.setOpacity(o * 1. + (1. - o) * st::playerInactiveOpacity);
			p.drawSpriteCenterLeft(_fullRect, width(), st::playerFull);
		}
		if (checkr.intersects(_repeatRect)) {
			float64 o = _stateHovers[OverRepeat];
			p.setOpacity(_repeat ? 1. : (o * st::playerInactiveOpacity + (1. - o) * st::playerUnavailableOpacity));
			p.drawSpriteCenterLeft(_repeatRect, width(), st::playerRepeat);
		}
		p.setOpacity(1.);

		p.setPen(st::playerTimeFg->p);
		p.setFont(st::linkFont->f);
		p.drawTextLeft(_infoRect.x() + _infoRect.width() - _timeWidth, _infoRect.y() + (_infoRect.height() - st::linkFont->height) / 2, width(), _time, _timeWidth);

		textstyleSet(&st::playerNameStyle);
		p.setPen(st::playerFg->p);
		_name.drawElided(p, _infoRect.x() + (rtl() ? (_timeWidth + st::playerSkip) : 0), _infoRect.y() + (_infoRect.height() - st::linkFont->height) / 2, _infoRect.width() - _timeWidth - st::playerSkip);
		textstyleRestore();
	}

	if (_duration) {
		float64 prg = (_down == OverPlayback) ? _downProgress : a_progress.current();
		int32 from = _playbackRect.x(), mid = qRound(_playbackRect.x() + prg * _playbackRect.width()), end = _playbackRect.x() + _playbackRect.width();
		if (mid > from) {
			p.fillRect(rtl() ? (width() - mid) : from, height() - st::playerLineHeight, mid - from, _playbackRect.height(), st::playerLineActive->b);
		}
		if (end > mid) {
			p.fillRect(rtl() ? (width() - end) : mid, height() - st::playerLineHeight, end - mid, st::playerLineHeight, st::playerLineInactive->b);
		}
		if (_stateHovers[OverPlayback] > 0) {
			p.setOpacity(_stateHovers[OverPlayback]);

			int32 x = mid - (st::playerMoverSize.width() / 2);
			p.fillRect(rtl() ? (width() - x - st::playerMoverSize.width()) : x, height() - st::playerMoverSize.height(), st::playerMoverSize.width(), st::playerMoverSize.height(), st::playerLineActive->b);
		}
	} else if (a_loadProgress.current() > 0) {
		int32 from = _playbackRect.x(), mid = qRound(_playbackRect.x() + a_loadProgress.current() * _playbackRect.width());
		if (mid > from) {
			p.fillRect(rtl() ? (width() - mid) : from, height() - st::playerLineHeight, mid - from, _playbackRect.height(), st::playerLineInactive->b);
		}
	}
}
示例#4
0
文件: title.cpp 项目: 2asoft/tdesktop
QRect TitleWidget::iconRect() const {
	return myrtlrect(QRect(st::titleIconPosition, st::titleIcon.size()));
}