1
# -*- coding: utf-8 -*-
3
# Copyright 2012 Canonical Ltd.
5
# This program is free software: you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License version 3, as published
7
# by the Free Software Foundation.
9
# This program is distributed in the hope that it will be useful, but
10
# WITHOUT ANY WARRANTY; without even the implied warranties of
11
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
12
# PURPOSE. See the GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License along
15
# with this program. If not, see <http://www.gnu.org/licenses/>.
16
"""Widget written in Qt that works as a GtkArrow."""
18
from PyQt4.QtGui import QPainter, QStyle, QStyleOption, QWidget
21
class QArrow(QWidget):
29
def __init__(self, direction, parent=None):
30
"""Create a new instance."""
31
super(QArrow, self).__init__(parent)
32
self._set_direction(direction)
33
self.setFixedWidth(16)
35
# pylint: disable=C0103
36
def paintEvent(self, event):
37
"""Paint the widget."""
40
painter = QPainter(self)
41
if self._direction == QArrow.UP:
42
primitive = QStyle.PE_IndicatorArrowUp
43
elif self._direction == QArrow.DOWN:
44
primitive = QStyle.PE_IndicatorArrowDown
45
elif self._direction == QArrow.LEFT:
46
primitive = QStyle.PE_IndicatorArrowLeft
48
primitive = QStyle.PE_IndicatorArrowRight
49
painter.translate(-5, 0)
50
painter.setViewTransformEnabled(True)
51
self.style().drawPrimitive(primitive, opt, painter, self)
52
# pylint: enable=C0103
54
def _get_direction(self):
55
"""Return the direction used."""
56
return self._direction
58
# pylint: disable=W0201
59
def _set_direction(self, direction):
60
"""Set the direction."""
61
if direction not in (QArrow.UP, QArrow.DOWN,
62
QArrow.LEFT, QArrow.RIGHT):
63
raise ValueError('Wrong arrow direction.')
64
self._direction = direction
66
# pylint: enable=W0201
68
direction = property(_get_direction, _set_direction)