forked from qt-creator/qt-creator
Utils: add tooltip parameter for info bar controls
Change-Id: I395dea4240d09b3721a24e04016c6db4076449b5 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -85,9 +85,11 @@ InfoBarEntry::InfoBarEntry(Id _id, const QString &_infoText, GlobalSuppression _
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void InfoBarEntry::addCustomButton(const QString &buttonText, CallBack callBack)
|
void InfoBarEntry::addCustomButton(const QString &buttonText,
|
||||||
|
CallBack callBack,
|
||||||
|
const QString &tooltip)
|
||||||
{
|
{
|
||||||
m_buttons.append({buttonText, callBack});
|
m_buttons.append({buttonText, callBack, tooltip});
|
||||||
}
|
}
|
||||||
|
|
||||||
void InfoBarEntry::setCancelButtonInfo(CallBack callBack)
|
void InfoBarEntry::setCancelButtonInfo(CallBack callBack)
|
||||||
@@ -103,20 +105,26 @@ void InfoBarEntry::setCancelButtonInfo(const QString &_cancelButtonText, CallBac
|
|||||||
m_cancelButtonCallBack = callBack;
|
m_cancelButtonCallBack = callBack;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InfoBarEntry::setComboInfo(const QStringList &list, ComboCallBack callBack, int currentIndex)
|
void InfoBarEntry::setComboInfo(const QStringList &list,
|
||||||
|
ComboCallBack callBack,
|
||||||
|
const QString &tooltip,
|
||||||
|
int currentIndex)
|
||||||
{
|
{
|
||||||
m_comboInfo = Utils::transform(list, [](const QString &string) {
|
auto comboInfos = Utils::transform(list, [](const QString &string) {
|
||||||
return ComboInfo{string, string};
|
return ComboInfo{string, string};
|
||||||
});
|
});
|
||||||
m_comboCallBack = callBack;
|
setComboInfo(comboInfos, callBack, tooltip, currentIndex);
|
||||||
m_currentComboIndex = currentIndex;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void InfoBarEntry::setComboInfo(const QList<ComboInfo> &list, ComboCallBack callBack, int currentIndex)
|
void InfoBarEntry::setComboInfo(const QList<ComboInfo> &list,
|
||||||
|
ComboCallBack callBack,
|
||||||
|
const QString &tooltip,
|
||||||
|
int currentIndex)
|
||||||
{
|
{
|
||||||
m_comboCallBack = callBack;
|
m_combo.entries = list;
|
||||||
m_comboInfo = list;
|
m_combo.callback = callBack;
|
||||||
m_currentComboIndex = currentIndex;
|
m_combo.tooltip = tooltip;
|
||||||
|
m_combo.currentIndex = currentIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InfoBarEntry::removeCancelButton()
|
void InfoBarEntry::removeCancelButton()
|
||||||
@@ -316,14 +324,15 @@ void InfoBarDisplay::update()
|
|||||||
m_isShowingDetailsWidget = false;
|
m_isShowingDetailsWidget = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!info.m_comboInfo.isEmpty()) {
|
if (!info.m_combo.entries.isEmpty()) {
|
||||||
auto cb = new QComboBox();
|
auto cb = new QComboBox();
|
||||||
for (const InfoBarEntry::ComboInfo &comboInfo : qAsConst(info.m_comboInfo))
|
cb->setToolTip(info.m_combo.tooltip);
|
||||||
|
for (const InfoBarEntry::ComboInfo &comboInfo : qAsConst(info.m_combo.entries))
|
||||||
cb->addItem(comboInfo.displayText, comboInfo.data);
|
cb->addItem(comboInfo.displayText, comboInfo.data);
|
||||||
if (info.m_currentComboIndex >= 0 && info.m_currentComboIndex < cb->count())
|
if (info.m_combo.currentIndex >= 0 && info.m_combo.currentIndex < cb->count())
|
||||||
cb->setCurrentIndex(info.m_currentComboIndex);
|
cb->setCurrentIndex(info.m_combo.currentIndex);
|
||||||
connect(cb, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [cb, info]() {
|
connect(cb, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [cb, info]() {
|
||||||
info.m_comboCallBack({cb->currentText(), cb->currentData()});
|
info.m_combo.callback({cb->currentText(), cb->currentData()});
|
||||||
}, Qt::QueuedConnection);
|
}, Qt::QueuedConnection);
|
||||||
|
|
||||||
hbox->addWidget(cb);
|
hbox->addWidget(cb);
|
||||||
@@ -332,6 +341,7 @@ void InfoBarDisplay::update()
|
|||||||
for (const InfoBarEntry::Button &button : qAsConst(info.m_buttons)) {
|
for (const InfoBarEntry::Button &button : qAsConst(info.m_buttons)) {
|
||||||
auto infoWidgetButton = new QToolButton;
|
auto infoWidgetButton = new QToolButton;
|
||||||
infoWidgetButton->setText(button.text);
|
infoWidgetButton->setText(button.text);
|
||||||
|
infoWidgetButton->setToolTip(button.tooltip);
|
||||||
connect(infoWidgetButton, &QAbstractButton::clicked, [button]() { button.callback(); });
|
connect(infoWidgetButton, &QAbstractButton::clicked, [button]() { button.callback(); });
|
||||||
hbox->addWidget(infoWidgetButton);
|
hbox->addWidget(infoWidgetButton);
|
||||||
}
|
}
|
||||||
|
@@ -57,7 +57,7 @@ public:
|
|||||||
InfoBarEntry(Id _id, const QString &_infoText, GlobalSuppression _globalSuppression = GlobalSuppression::Disabled);
|
InfoBarEntry(Id _id, const QString &_infoText, GlobalSuppression _globalSuppression = GlobalSuppression::Disabled);
|
||||||
|
|
||||||
using CallBack = std::function<void()>;
|
using CallBack = std::function<void()>;
|
||||||
void addCustomButton(const QString &_buttonText, CallBack callBack);
|
void addCustomButton(const QString &_buttonText, CallBack callBack, const QString &tooltip = {});
|
||||||
void setCancelButtonInfo(CallBack callBack);
|
void setCancelButtonInfo(CallBack callBack);
|
||||||
void setCancelButtonInfo(const QString &_cancelButtonText, CallBack callBack);
|
void setCancelButtonInfo(const QString &_cancelButtonText, CallBack callBack);
|
||||||
struct ComboInfo
|
struct ComboInfo
|
||||||
@@ -66,8 +66,8 @@ public:
|
|||||||
QVariant data;
|
QVariant data;
|
||||||
};
|
};
|
||||||
using ComboCallBack = std::function<void(const ComboInfo &)>;
|
using ComboCallBack = std::function<void(const ComboInfo &)>;
|
||||||
void setComboInfo(const QStringList &list, ComboCallBack callBack, int currentIndex = -1);
|
void setComboInfo(const QStringList &list, ComboCallBack callBack, const QString &tooltip = {}, int currentIndex = -1);
|
||||||
void setComboInfo(const QList<ComboInfo> &infos, ComboCallBack callBack, int currentIndex = -1);
|
void setComboInfo(const QList<ComboInfo> &infos, ComboCallBack callBack, const QString &tooltip = {}, int currentIndex = -1);
|
||||||
void removeCancelButton();
|
void removeCancelButton();
|
||||||
|
|
||||||
using DetailsWidgetCreator = std::function<QWidget*()>;
|
using DetailsWidgetCreator = std::function<QWidget*()>;
|
||||||
@@ -78,6 +78,15 @@ private:
|
|||||||
{
|
{
|
||||||
QString text;
|
QString text;
|
||||||
CallBack callback;
|
CallBack callback;
|
||||||
|
QString tooltip;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Combo
|
||||||
|
{
|
||||||
|
ComboCallBack callback;
|
||||||
|
QList<ComboInfo> entries;
|
||||||
|
QString tooltip;
|
||||||
|
int currentIndex = -1;
|
||||||
};
|
};
|
||||||
|
|
||||||
Id m_id;
|
Id m_id;
|
||||||
@@ -88,9 +97,7 @@ private:
|
|||||||
GlobalSuppression m_globalSuppression;
|
GlobalSuppression m_globalSuppression;
|
||||||
DetailsWidgetCreator m_detailsWidgetCreator;
|
DetailsWidgetCreator m_detailsWidgetCreator;
|
||||||
bool m_useCancelButton = true;
|
bool m_useCancelButton = true;
|
||||||
ComboCallBack m_comboCallBack;
|
Combo m_combo;
|
||||||
QList<ComboInfo> m_comboInfo;
|
|
||||||
int m_currentComboIndex = -1;
|
|
||||||
friend class InfoBar;
|
friend class InfoBar;
|
||||||
friend class InfoBarDisplay;
|
friend class InfoBarDisplay;
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user