Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vmj-qt
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
vmj-qt
Commits
be2d6fb1
Commit
be2d6fb1
authored
Jul 19, 2010
by
Dan Pascu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved SearchBox in blink.widgets.lineedit
parent
60abae98
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
97 additions
and
106 deletions
+97
-106
lineedit.py
blink/widgets/lineedit.py
+96
-2
searchbox.py
blink/widgets/searchbox.py
+0
-103
blink.ui
resources/blink.ui
+1
-1
No files found.
blink/widgets/lineedit.py
View file @
be2d6fb1
# Copyright (c) 2010 AG Projects. See LICENSE for details.
#
__all__
=
[
'LineEdit'
,
'ValidatingLineEdit'
]
__all__
=
[
'LineEdit'
,
'ValidatingLineEdit'
,
'SearchBox'
]
import
re
from
PyQt4.QtCore
import
Qt
,
QEvent
,
pyqtSignal
from
PyQt4.QtGui
import
QLineEdit
,
QBoxLayout
,
QHBoxLayout
,
QLabel
,
QLayout
,
QPainter
,
QPalette
,
QPixmap
,
QSpacerItem
,
QSizePolicy
,
QStyle
,
QWidget
,
QStyleOptionFrameV2
from
PyQt4.QtGui
import
Q
AbstractButton
,
Q
LineEdit
,
QBoxLayout
,
QHBoxLayout
,
QLabel
,
QLayout
,
QPainter
,
QPalette
,
QPixmap
,
QSpacerItem
,
QSizePolicy
,
QStyle
,
QWidget
,
QStyleOptionFrameV2
from
blink.resources
import
Resources
from
blink.widgets.util
import
QtDynamicProperty
...
...
@@ -165,3 +165,97 @@ class ValidatingLineEdit(LineEdit):
self
.
statusChanged
.
emit
()
class
SearchIcon
(
QWidget
):
def
__init__
(
self
,
parent
=
None
,
size
=
16
):
QWidget
.
__init__
(
self
,
parent
)
self
.
setFocusPolicy
(
Qt
.
NoFocus
)
self
.
setVisible
(
True
)
self
.
setMinimumSize
(
size
+
2
,
size
+
2
)
pixmap
=
QPixmap
()
if
pixmap
.
load
(
Resources
.
get
(
"icons/search.svg"
)):
self
.
icon
=
pixmap
.
scaled
(
size
,
size
,
Qt
.
KeepAspectRatio
,
Qt
.
SmoothTransformation
)
else
:
self
.
icon
=
None
def
paintEvent
(
self
,
event
):
painter
=
QPainter
(
self
)
if
self
.
icon
is
not
None
:
x
=
(
self
.
width
()
-
self
.
icon
.
width
())
/
2
y
=
(
self
.
height
()
-
self
.
icon
.
height
())
/
2
painter
.
drawPixmap
(
x
,
y
,
self
.
icon
)
class
ClearButton
(
QAbstractButton
):
def
__init__
(
self
,
parent
=
None
,
size
=
16
):
QAbstractButton
.
__init__
(
self
,
parent
)
self
.
setCursor
(
Qt
.
ArrowCursor
)
self
.
setFocusPolicy
(
Qt
.
NoFocus
)
self
.
setToolTip
(
u"Clear"
)
self
.
setVisible
(
False
)
self
.
setMinimumSize
(
size
+
2
,
size
+
2
)
pixmap
=
QPixmap
()
if
pixmap
.
load
(
Resources
.
get
(
"icons/delete.svg"
)):
self
.
icon
=
pixmap
.
scaled
(
size
,
size
,
Qt
.
KeepAspectRatio
,
Qt
.
SmoothTransformation
)
# Use QImage because QPainter using a QPixmap does not support CompositionMode_Multiply -Dan
image
=
self
.
icon
.
toImage
()
painter
=
QPainter
(
image
)
painter
.
setRenderHint
(
QPainter
.
Antialiasing
,
True
)
painter
.
setCompositionMode
(
QPainter
.
CompositionMode_Multiply
)
painter
.
drawPixmap
(
0
,
0
,
self
.
icon
)
painter
.
end
()
self
.
icon_pressed
=
QPixmap
(
image
)
else
:
self
.
icon
=
self
.
icon_pressed
=
None
def
paintEvent
(
self
,
event
):
painter
=
QPainter
(
self
)
icon
=
self
.
icon_pressed
if
self
.
isDown
()
else
self
.
icon
if
icon
is
not
None
:
x
=
(
self
.
width
()
-
icon
.
width
())
/
2
y
=
(
self
.
height
()
-
icon
.
height
())
/
2
painter
.
drawPixmap
(
x
,
y
,
icon
)
else
:
width
=
self
.
width
()
height
=
self
.
height
()
padding
=
width
/
5
radius
=
width
-
2
*
padding
palette
=
self
.
palette
()
# Mid is darker than Dark. Go figure... -Dan
bg_color
=
palette
.
color
(
QPalette
.
Mid
)
if
self
.
isDown
()
else
palette
.
color
(
QPalette
.
Dark
)
fg_color
=
palette
.
color
(
QPalette
.
Window
)
# or QPalette.Base for white
painter
.
setRenderHint
(
QPainter
.
Antialiasing
,
True
)
painter
.
setBrush
(
bg_color
)
painter
.
setPen
(
bg_color
)
painter
.
drawEllipse
(
padding
,
padding
,
radius
,
radius
)
padding
=
padding
*
2
painter
.
setPen
(
fg_color
)
painter
.
drawLine
(
padding
,
padding
,
width
-
padding
,
height
-
padding
)
painter
.
drawLine
(
padding
,
height
-
padding
,
width
-
padding
,
padding
)
class
SearchBox
(
LineEdit
):
def
__init__
(
self
,
parent
=
None
):
LineEdit
.
__init__
(
self
,
parent
=
parent
)
self
.
search_icon
=
SearchIcon
(
self
)
self
.
clear_button
=
ClearButton
(
self
)
self
.
addHeadWidget
(
self
.
search_icon
)
self
.
addTailWidget
(
self
.
clear_button
)
option
=
QStyleOptionFrameV2
()
self
.
initStyleOption
(
option
)
frame_width
=
self
.
style
()
.
pixelMetric
(
QStyle
.
PM_DefaultFrameWidth
,
option
,
self
)
widgets_height
=
max
(
self
.
search_icon
.
minimumHeight
(),
self
.
clear_button
.
minimumHeight
())
self
.
setMinimumHeight
(
widgets_height
+
2
+
2
*
frame_width
)
self
.
clear_button
.
hide
()
self
.
clear_button
.
clicked
.
connect
(
self
.
clear
)
self
.
textChanged
.
connect
(
self
.
text_changed
)
self
.
inactiveText
=
u"Search"
def
text_changed
(
self
,
text
):
self
.
clear_button
.
setVisible
(
not
text
.
isEmpty
())
blink/widgets/searchbox.py
deleted
100644 → 0
View file @
60abae98
# Copyright (c) 2010 AG Projects. See LICENSE for details.
#
from
PyQt4.QtCore
import
Qt
from
PyQt4.QtGui
import
QAbstractButton
,
QPainter
,
QPalette
,
QPixmap
,
QStyle
,
QWidget
,
QStyleOptionFrameV2
from
blink.resources
import
Resources
from
blink.widgets.lineedit
import
LineEdit
class
SearchIcon
(
QWidget
):
def
__init__
(
self
,
parent
=
None
,
size
=
16
):
QWidget
.
__init__
(
self
,
parent
)
self
.
setFocusPolicy
(
Qt
.
NoFocus
)
self
.
setVisible
(
True
)
self
.
setMinimumSize
(
size
+
2
,
size
+
2
)
pixmap
=
QPixmap
()
if
pixmap
.
load
(
Resources
.
get
(
"icons/search.svg"
)):
self
.
icon
=
pixmap
.
scaled
(
size
,
size
,
Qt
.
KeepAspectRatio
,
Qt
.
SmoothTransformation
)
else
:
self
.
icon
=
None
def
paintEvent
(
self
,
event
):
painter
=
QPainter
(
self
)
if
self
.
icon
is
not
None
:
x
=
(
self
.
width
()
-
self
.
icon
.
width
())
/
2
y
=
(
self
.
height
()
-
self
.
icon
.
height
())
/
2
painter
.
drawPixmap
(
x
,
y
,
self
.
icon
)
class
ClearButton
(
QAbstractButton
):
def
__init__
(
self
,
parent
=
None
,
size
=
16
):
QAbstractButton
.
__init__
(
self
,
parent
)
self
.
setCursor
(
Qt
.
ArrowCursor
)
self
.
setFocusPolicy
(
Qt
.
NoFocus
)
self
.
setToolTip
(
u"Clear"
)
self
.
setVisible
(
False
)
self
.
setMinimumSize
(
size
+
2
,
size
+
2
)
pixmap
=
QPixmap
()
if
pixmap
.
load
(
Resources
.
get
(
"icons/delete.svg"
)):
self
.
icon
=
pixmap
.
scaled
(
size
,
size
,
Qt
.
KeepAspectRatio
,
Qt
.
SmoothTransformation
)
# Use QImage because QPainter using a QPixmap does not support CompositionMode_Multiply -Dan
image
=
self
.
icon
.
toImage
()
painter
=
QPainter
(
image
)
painter
.
setRenderHint
(
QPainter
.
Antialiasing
,
True
)
painter
.
setCompositionMode
(
QPainter
.
CompositionMode_Multiply
)
painter
.
drawPixmap
(
0
,
0
,
self
.
icon
)
painter
.
end
()
self
.
icon_pressed
=
QPixmap
(
image
)
else
:
self
.
icon
=
self
.
icon_pressed
=
None
def
paintEvent
(
self
,
event
):
painter
=
QPainter
(
self
)
icon
=
self
.
icon_pressed
if
self
.
isDown
()
else
self
.
icon
if
icon
is
not
None
:
x
=
(
self
.
width
()
-
icon
.
width
())
/
2
y
=
(
self
.
height
()
-
icon
.
height
())
/
2
painter
.
drawPixmap
(
x
,
y
,
icon
)
else
:
width
=
self
.
width
()
height
=
self
.
height
()
padding
=
width
/
5
radius
=
width
-
2
*
padding
palette
=
self
.
palette
()
# Mid is darker than Dark. Go figure... -Dan
bg_color
=
palette
.
color
(
QPalette
.
Mid
)
if
self
.
isDown
()
else
palette
.
color
(
QPalette
.
Dark
)
fg_color
=
palette
.
color
(
QPalette
.
Window
)
# or QPalette.Base for white
painter
.
setRenderHint
(
QPainter
.
Antialiasing
,
True
)
painter
.
setBrush
(
bg_color
)
painter
.
setPen
(
bg_color
)
painter
.
drawEllipse
(
padding
,
padding
,
radius
,
radius
)
padding
=
padding
*
2
painter
.
setPen
(
fg_color
)
painter
.
drawLine
(
padding
,
padding
,
width
-
padding
,
height
-
padding
)
painter
.
drawLine
(
padding
,
height
-
padding
,
width
-
padding
,
padding
)
class
SearchBox
(
LineEdit
):
def
__init__
(
self
,
parent
=
None
):
LineEdit
.
__init__
(
self
,
parent
=
parent
)
self
.
search_icon
=
SearchIcon
(
self
)
self
.
clear_button
=
ClearButton
(
self
)
self
.
addHeadWidget
(
self
.
search_icon
)
self
.
addTailWidget
(
self
.
clear_button
)
option
=
QStyleOptionFrameV2
()
self
.
initStyleOption
(
option
)
frame_width
=
self
.
style
()
.
pixelMetric
(
QStyle
.
PM_DefaultFrameWidth
,
option
,
self
)
widgets_height
=
max
(
self
.
search_icon
.
minimumHeight
(),
self
.
clear_button
.
minimumHeight
())
self
.
setMinimumHeight
(
widgets_height
+
2
+
2
*
frame_width
)
self
.
clear_button
.
hide
()
self
.
clear_button
.
clicked
.
connect
(
self
.
clear
)
self
.
textChanged
.
connect
(
self
.
text_changed
)
self
.
inactiveText
=
u"Search"
def
text_changed
(
self
,
text
):
self
.
clear_button
.
setVisible
(
not
text
.
isEmpty
())
resources/blink.ui
View file @
be2d6fb1
...
...
@@ -1222,7 +1222,7 @@ padding: 2px;</string>
<customwidget>
<class>
SearchBox
</class>
<extends>
QLineEdit
</extends>
<header>
blink.widgets.
searchbox
</header>
<header>
blink.widgets.
lineedit
</header>
</customwidget>
<customwidget>
<class>
ContactListView
</class>
...
...
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