mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
refactor: Move helper function in anonymus namespace
This commit is contained in:
parent
850e501acc
commit
07ceb15e01
|
@ -78,20 +78,35 @@ const QString MIC_TOOL_TIP[] = {
|
|||
ChatFormHeader::tr("Mute microphone"),
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
template <class T, class Fun>
|
||||
T* createButton(ChatFormHeader* self, const QSize& size, const QString& name, Fun slot)
|
||||
T* createButton(ChatFormHeader* self, const QSize& size, const QString& name, Fun onClickSlot)
|
||||
{
|
||||
T* btn = new T();
|
||||
btn->setFixedSize(size);
|
||||
btn->setAttribute(Qt::WA_LayoutUsesWidgetRect);
|
||||
btn->setObjectName(name);
|
||||
btn->setStyleSheet(Style::getStylesheet(STYLE_PATH));
|
||||
QObject::connect(btn, &QAbstractButton::clicked, self, slot);
|
||||
QObject::connect(btn, &QAbstractButton::clicked, self, onClickSlot);
|
||||
return btn;
|
||||
}
|
||||
|
||||
template<class State>
|
||||
void setStateToolTip(QAbstractButton* btn, State state, const QString toolTip[])
|
||||
{
|
||||
const int index = static_cast<int>(state);
|
||||
btn->setToolTip(toolTip[index]);
|
||||
}
|
||||
|
||||
template<class State>
|
||||
void setStateName(QAbstractButton* btn, State state)
|
||||
{
|
||||
const int index = static_cast<int>(state);
|
||||
btn->setProperty("state", STATE_NAME[index]);
|
||||
btn->setEnabled(index != 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ChatFormHeader::ChatFormHeader(QWidget* parent)
|
||||
: QWidget(parent)
|
||||
, mode{Mode::AV}
|
||||
|
@ -162,13 +177,6 @@ void ChatFormHeader::setMode(ChatFormHeader::Mode mode)
|
|||
}
|
||||
}
|
||||
|
||||
template<class State>
|
||||
void setStateToolTip(QAbstractButton* btn, State state, const QString toolTip[])
|
||||
{
|
||||
const int index = static_cast<int>(state);
|
||||
btn->setToolTip(toolTip[index]);
|
||||
}
|
||||
|
||||
void ChatFormHeader::retranslateUi()
|
||||
{
|
||||
setStateToolTip(callButton, callState, CALL_TOOL_TIP);
|
||||
|
@ -177,14 +185,6 @@ void ChatFormHeader::retranslateUi()
|
|||
setStateToolTip(volButton, volState, VOL_TOOL_TIP);
|
||||
}
|
||||
|
||||
template<class State>
|
||||
void setStateName(QAbstractButton* btn, State state)
|
||||
{
|
||||
const int index = static_cast<int>(state);
|
||||
btn->setProperty("state", STATE_NAME[index]);
|
||||
btn->setEnabled(index != 0);
|
||||
}
|
||||
|
||||
void ChatFormHeader::updateButtonsView()
|
||||
{
|
||||
setStateName(callButton, callState);
|
||||
|
|
Loading…
Reference in New Issue
Block a user