Browse Source

refactor: Use chatFormHead css

pull/4804/head
Diadlo 8 years ago
parent
commit
850e501acc
No known key found for this signature in database
GPG Key ID: 5AF9F2E29107C727
  1. 29
      src/widget/chatformheader.cpp

29
src/widget/chatformheader.cpp

@ -39,8 +39,10 @@ static const short HEAD_LAYOUT_SPACING = 5;
static const short MIC_BUTTONS_LAYOUT_SPACING = 4; static const short MIC_BUTTONS_LAYOUT_SPACING = 4;
static const short BUTTONS_LAYOUT_HOR_SPACING = 4; static const short BUTTONS_LAYOUT_HOR_SPACING = 4;
namespace { namespace {
const QString ObjectName[] = { const QString STYLE_PATH = QStringLiteral(":/ui/chatFormHeader/buttons.css");
const QString STATE_NAME[] = {
QString{}, QString{},
QStringLiteral("green"), QStringLiteral("green"),
QStringLiteral("red"), QStringLiteral("red"),
@ -48,7 +50,7 @@ const QString ObjectName[] = {
QStringLiteral("yellow"), QStringLiteral("yellow"),
}; };
const QString CallToolTip[] = { const QString CALL_TOOL_TIP[] = {
ChatFormHeader::tr("Can't start audio call"), ChatFormHeader::tr("Can't start audio call"),
ChatFormHeader::tr("Start audio call"), ChatFormHeader::tr("Start audio call"),
ChatFormHeader::tr("End audio call"), ChatFormHeader::tr("End audio call"),
@ -56,7 +58,7 @@ const QString CallToolTip[] = {
ChatFormHeader::tr("Accept audio call"), ChatFormHeader::tr("Accept audio call"),
}; };
const QString VideoToolTip[] = { const QString VIDEO_TOOL_TIP[] = {
ChatFormHeader::tr("Can't start video call"), ChatFormHeader::tr("Can't start video call"),
ChatFormHeader::tr("Start video call"), ChatFormHeader::tr("Start video call"),
ChatFormHeader::tr("End video call"), ChatFormHeader::tr("End video call"),
@ -64,13 +66,13 @@ const QString VideoToolTip[] = {
ChatFormHeader::tr("Accept video call"), ChatFormHeader::tr("Accept video call"),
}; };
const QString VolToolTip[] = { const QString VOL_TOOL_TIP[] = {
ChatFormHeader::tr("Sound can be disabled only during a call"), ChatFormHeader::tr("Sound can be disabled only during a call"),
ChatFormHeader::tr("Unmute call"), ChatFormHeader::tr("Unmute call"),
ChatFormHeader::tr("Mute call"), ChatFormHeader::tr("Mute call"),
}; };
const QString MicToolTip[] = { const QString MIC_TOOL_TIP[] = {
ChatFormHeader::tr("Microphone can be muted only during a call"), ChatFormHeader::tr("Microphone can be muted only during a call"),
ChatFormHeader::tr("Unmute microphone"), ChatFormHeader::tr("Unmute microphone"),
ChatFormHeader::tr("Mute microphone"), ChatFormHeader::tr("Mute microphone"),
@ -84,8 +86,8 @@ T* createButton(ChatFormHeader* self, const QSize& size, const QString& name, Fu
T* btn = new T(); T* btn = new T();
btn->setFixedSize(size); btn->setFixedSize(size);
btn->setAttribute(Qt::WA_LayoutUsesWidgetRect); btn->setAttribute(Qt::WA_LayoutUsesWidgetRect);
const QString& path = QStringLiteral(":/ui/%1/%1.css").arg(name); btn->setObjectName(name);
btn->setStyleSheet(Style::getStylesheet(path)); btn->setStyleSheet(Style::getStylesheet(STYLE_PATH));
QObject::connect(btn, &QAbstractButton::clicked, self, slot); QObject::connect(btn, &QAbstractButton::clicked, self, slot);
return btn; return btn;
} }
@ -100,6 +102,7 @@ ChatFormHeader::ChatFormHeader(QWidget* parent)
{ {
QHBoxLayout* headLayout = new QHBoxLayout(); QHBoxLayout* headLayout = new QHBoxLayout();
avatar = new MaskablePixmapWidget(this, AVATAR_SIZE, ":/img/avatar_mask.svg"); avatar = new MaskablePixmapWidget(this, AVATAR_SIZE, ":/img/avatar_mask.svg");
avatar->setObjectName("avatar");
nameLabel = new CroppingLabel(); nameLabel = new CroppingLabel();
nameLabel->setObjectName("nameLabel"); nameLabel->setObjectName("nameLabel");
@ -168,17 +171,17 @@ void setStateToolTip(QAbstractButton* btn, State state, const QString toolTip[])
void ChatFormHeader::retranslateUi() void ChatFormHeader::retranslateUi()
{ {
setStateToolTip(callButton, callState, CallToolTip); setStateToolTip(callButton, callState, CALL_TOOL_TIP);
setStateToolTip(videoButton, videoState, VideoToolTip); setStateToolTip(videoButton, videoState, VIDEO_TOOL_TIP);
setStateToolTip(micButton, micState, MicToolTip); setStateToolTip(micButton, micState, MIC_TOOL_TIP);
setStateToolTip(volButton, volState, VolToolTip); setStateToolTip(volButton, volState, VOL_TOOL_TIP);
} }
template<class State> template<class State>
void setStateName(QAbstractButton* btn, State state) void setStateName(QAbstractButton* btn, State state)
{ {
const int index = static_cast<int>(state); const int index = static_cast<int>(state);
btn->setObjectName(ObjectName[index]); btn->setProperty("state", STATE_NAME[index]);
btn->setEnabled(index != 0); btn->setEnabled(index != 0);
} }

Loading…
Cancel
Save