Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Marco Bubke
flatpak-qt-creator
Commits
8eedde33
Commit
8eedde33
authored
Apr 09, 2010
by
mae
Browse files
Implement tooltips for snippets
parent
2ff9c905
Changes
4
Hide whitespace changes
Inline
Side-by-side
share/qtcreator/snippets/qml.xml
View file @
8eedde33
...
...
@@ -65,9 +65,9 @@
</snippet>
<snippet>
PropertyChanges {
target:
<tab>
name
</tab>
<tab/>
}
target:
<tab>
name
</tab>
<tab/>
}
</snippet>
<snippet
description=
"with targets"
>
NumberAnimation { targets: [
<tab>
name
</tab>
]; properties: "
<tab>
name
</tab>
"; duration:
<tab>
200
</tab>
}
...
...
src/plugins/qmljseditor/qmljscodecompletion.cpp
View file @
8eedde33
...
...
@@ -888,26 +888,31 @@ void CodeCompletion::updateSnippets()
item
.
data
=
QVariant
::
fromValue
(
data
);
QString
tooltip
=
data
;
tooltip
.
replace
(
QRegExp
(
"
\n\\
s*"
),
QLatin1String
(
" "
));
QString
infotip
=
data
;
while
(
infotip
.
size
()
&&
infotip
.
at
(
infotip
.
size
()
-
1
).
isSpace
())
infotip
.
chop
(
1
);
infotip
.
replace
(
QLatin1Char
(
'\n'
),
QLatin1String
(
"<br>"
));
infotip
.
replace
(
QLatin1Char
(
' '
),
QLatin1String
(
" "
));
{
QString
s
=
QLatin1String
(
"<nobr>"
);
int
count
=
0
;
for
(
int
i
=
0
;
i
<
tool
tip
.
count
();
++
i
)
{
if
(
tool
tip
.
at
(
i
)
!=
QChar
::
ObjectReplacementCharacter
)
{
s
+=
tool
tip
.
at
(
i
);
for
(
int
i
=
0
;
i
<
info
tip
.
count
();
++
i
)
{
if
(
info
tip
.
at
(
i
)
!=
QChar
::
ObjectReplacementCharacter
)
{
s
+=
info
tip
.
at
(
i
);
continue
;
}
if
(
++
count
%
2
)
{
s
+=
QLatin1String
(
"<b>"
);
}
else
{
if
(
infotip
.
at
(
i
-
1
)
==
QChar
::
ObjectReplacementCharacter
)
s
+=
QLatin1String
(
"..."
);
s
+=
QLatin1String
(
"</b>"
);
}
}
tool
tip
=
s
;
info
tip
=
s
;
}
item
.
details
=
tooltip
;
// ###TODO this should not be the normal tool
tip
item
.
details
=
info
tip
;
item
.
icon
=
icon
;
m_snippets
.
append
(
item
);
...
...
src/plugins/texteditor/completionwidget.cpp
View file @
8eedde33
...
...
@@ -40,6 +40,8 @@
#include <QtGui/QKeyEvent>
#include <QtGui/QVBoxLayout>
#include <QtGui/QScrollBar>
#include <QtGui/QLabel>
#include <QtGui/QStylePainter>
#include <limits.h>
...
...
@@ -68,6 +70,41 @@ private:
QList
<
CompletionItem
>
m_items
;
};
class
CompletionInfoFrame
:
public
QLabel
{
public:
CompletionInfoFrame
(
QWidget
*
parent
=
0
)
:
QLabel
(
parent
,
Qt
::
ToolTip
|
Qt
::
WindowStaysOnTopHint
)
{
setFocusPolicy
(
Qt
::
NoFocus
);
setAttribute
(
Qt
::
WA_DeleteOnClose
);
setAutoFillBackground
(
true
);
setBackgroundRole
(
QPalette
::
ToolTipBase
);
setMargin
(
1
+
style
()
->
pixelMetric
(
QStyle
::
PM_ToolTipLabelFrameWidth
,
0
,
this
));
setIndent
(
1
);
}
void
paintEvent
(
QPaintEvent
*
e
)
{
QStylePainter
p
(
this
);
QStyleOptionFrame
opt
;
opt
.
init
(
this
);
p
.
drawPrimitive
(
QStyle
::
PE_PanelTipLabel
,
opt
);
p
.
end
();
QLabel
::
paintEvent
(
e
);
}
void
resizeEvent
(
QResizeEvent
*
e
)
{
QStyleHintReturnMask
frameMask
;
QStyleOption
option
;
option
.
init
(
this
);
if
(
style
()
->
styleHint
(
QStyle
::
SH_ToolTip_Mask
,
&
option
,
this
,
&
frameMask
))
setMask
(
frameMask
.
region
);
QLabel
::
resizeEvent
(
e
);
}
};
}
// namespace Internal
}
// namespace TextEditor
...
...
@@ -97,7 +134,7 @@ QVariant AutoCompletionModel::data(const QModelIndex &index, int role) const
return
itemAt
(
index
).
text
;
}
else
if
(
role
==
Qt
::
DecorationRole
)
{
return
itemAt
(
index
).
icon
;
}
else
if
(
role
==
Qt
::
ToolTip
Role
)
{
}
else
if
(
role
==
Qt
::
WhatsThis
Role
)
{
return
itemAt
(
index
).
details
;
}
...
...
@@ -211,7 +248,6 @@ void CompletionWidget::updatePositionAndSize(int startPos)
setGeometry
(
pos
.
x
(),
pos
.
y
(),
width
,
height
);
}
CompletionListView
::
CompletionListView
(
CompletionSupport
*
support
,
ITextEditable
*
editor
,
CompletionWidget
*
completionWidget
)
:
QListView
(
completionWidget
),
m_blockFocusOut
(
false
),
...
...
@@ -237,14 +273,56 @@ CompletionListView::CompletionListView(CompletionSupport *support, ITextEditable
if
(
verticalScrollBar
())
verticalScrollBar
()
->
setAttribute
(
Qt
::
WA_MacMiniSize
);
#endif
}
CompletionListView
::~
CompletionListView
()
{
}
void
CompletionListView
::
maybeShowInfoTip
()
{
QModelIndex
current
=
currentIndex
();
if
(
!
current
.
isValid
())
return
;
QString
infoTip
=
current
.
data
(
Qt
::
WhatsThisRole
).
toString
();
if
(
infoTip
.
isEmpty
())
{
delete
m_infoFrame
.
data
();
return
;
}
if
(
m_infoFrame
.
isNull
())
m_infoFrame
=
new
CompletionInfoFrame
(
this
);
QRect
r
=
rectForIndex
(
current
);
m_infoFrame
->
move
(
(
parentWidget
()
->
mapToGlobal
(
parentWidget
()
->
rect
().
topRight
()
+
QPoint
(
2
,
0
))).
x
(),
mapToGlobal
(
r
.
topRight
()).
y
()
-
verticalOffset
()
);
m_infoFrame
->
setText
(
infoTip
);
m_infoFrame
->
adjustSize
();
m_infoFrame
->
show
();
}
void
CompletionListView
::
currentChanged
(
const
QModelIndex
&
current
,
const
QModelIndex
&
previous
)
{
QListView
::
currentChanged
(
current
,
previous
);
if
(
isVisible
())
maybeShowInfoTip
();
}
bool
CompletionListView
::
event
(
QEvent
*
e
)
{
if
(
e
->
type
()
==
QEvent
::
Show
)
{
bool
b
=
QListView
::
event
(
e
);
maybeShowInfoTip
();
return
b
;
}
if
(
m_blockFocusOut
)
return
QListView
::
event
(
e
);
...
...
src/plugins/texteditor/completionwidget.h
View file @
8eedde33
...
...
@@ -43,6 +43,7 @@ namespace Internal {
class
AutoCompletionModel
;
class
CompletionSupport
;
class
CompletionListView
;
class
CompletionInfoFrame
;
/* The completion widget is responsible for showing a list of possible completions.
It is only used by the CompletionSupport.
...
...
@@ -89,6 +90,8 @@ signals:
protected:
bool
event
(
QEvent
*
e
);
void
currentChanged
(
const
QModelIndex
&
current
,
const
QModelIndex
&
previous
);
private:
friend
class
CompletionWidget
;
...
...
@@ -98,6 +101,7 @@ private:
void
setCompletionItems
(
const
QList
<
TextEditor
::
CompletionItem
>
&
completionitems
);
void
keyboardSearch
(
const
QString
&
search
);
void
closeList
(
const
QModelIndex
&
index
);
void
maybeShowInfoTip
();
bool
m_blockFocusOut
;
bool
m_quickFix
;
...
...
@@ -106,6 +110,7 @@ private:
CompletionWidget
*
m_completionWidget
;
AutoCompletionModel
*
m_model
;
CompletionSupport
*
m_support
;
QPointer
<
CompletionInfoFrame
>
m_infoFrame
;
};
}
// namespace Internal
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment