forked from qt-creator/qt-creator
TextEditor: make the format of completion item detail text adjustable
Instead of always assuming content in the form of rich text allow each item individually to define it's text format for the detail text that is shown as a tooltip of a completion item. Fixes: QTCREATORBUG-22429 Change-Id: I9fa71373a743c26fa06d48acc5f0509584830ca0 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -70,6 +70,7 @@ public:
|
||||
int rowCount(const QModelIndex &) const override;
|
||||
QVariant data(const QModelIndex &index, int role) const override;
|
||||
|
||||
enum UserRoles{ FixItRole = Qt::UserRole, DetailTextFormatRole };
|
||||
private:
|
||||
GenericProposalModelPtr m_completionModel;
|
||||
};
|
||||
@@ -99,7 +100,9 @@ QVariant ModelAdapter::data(const QModelIndex &index, int role) const
|
||||
return m_completionModel->icon(index.row());
|
||||
} else if (role == Qt::WhatsThisRole) {
|
||||
return m_completionModel->detail(index.row());
|
||||
} else if (role == Qt::UserRole) {
|
||||
} else if (role == DetailTextFormatRole) {
|
||||
return m_completionModel->detailFormat(index.row());
|
||||
} else if (role == FixItRole) {
|
||||
return m_completionModel->proposalItem(index.row())->requiresFixIts();
|
||||
}
|
||||
|
||||
@@ -123,7 +126,6 @@ public:
|
||||
// Limit horizontal width
|
||||
m_label->setSizePolicy(QSizePolicy::Fixed, m_label->sizePolicy().verticalPolicy());
|
||||
|
||||
m_label->setTextFormat(Qt::RichText);
|
||||
m_label->setForegroundRole(QPalette::ToolTipText);
|
||||
m_label->setBackgroundRole(QPalette::ToolTipBase);
|
||||
}
|
||||
@@ -133,6 +135,11 @@ public:
|
||||
m_label->setText(text);
|
||||
}
|
||||
|
||||
void setTextFormat(Qt::TextFormat format)
|
||||
{
|
||||
m_label->setTextFormat(format);
|
||||
}
|
||||
|
||||
// Workaround QTCREATORBUG-11653
|
||||
void calculateMaximumWidth()
|
||||
{
|
||||
@@ -189,7 +196,7 @@ public:
|
||||
|
||||
QStyledItemDelegate::paint(painter, option, index);
|
||||
|
||||
if (m_parent->model()->data(index, Qt::UserRole).toBool()) {
|
||||
if (m_parent->model()->data(index, ModelAdapter::FixItRole).toBool()) {
|
||||
const QRect itemRect = m_parent->rectForIndex(index);
|
||||
const QScrollBar *verticalScrollBar = m_parent->verticalScrollBar();
|
||||
|
||||
@@ -205,7 +212,7 @@ public:
|
||||
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override
|
||||
{
|
||||
QSize size(QStyledItemDelegate::sizeHint(option, index));
|
||||
if (m_parent->model()->data(index, Qt::UserRole).toBool())
|
||||
if (m_parent->model()->data(index, ModelAdapter::FixItRole).toBool())
|
||||
size.setWidth(size.width() + m_parent->rectForIndex(index).height() - 5);
|
||||
return size;
|
||||
}
|
||||
@@ -313,6 +320,8 @@ void GenericProposalWidgetPrivate::maybeShowInfoTip()
|
||||
m_infoFrame = new GenericProposalInfoFrame(m_completionListView);
|
||||
|
||||
m_infoFrame->move(m_completionListView->infoFramePos());
|
||||
m_infoFrame->setTextFormat(
|
||||
current.data(ModelAdapter::DetailTextFormatRole).value<Qt::TextFormat>());
|
||||
m_infoFrame->setText(infoTip);
|
||||
m_infoFrame->calculateMaximumWidth();
|
||||
m_infoFrame->adjustSize();
|
||||
|
||||
Reference in New Issue
Block a user