コード例 #1
0
class Color(QWidget):
    changed = Signal(object, object, object)

    def __init__(self, parent=None):
        QWidget.__init__(self, parent)

        self.hue = QSlider()
        self.hue.setMaximum(100)
        self.hue.setOrientation(Qt.Horizontal)
        self.hue.valueChanged.connect(self._changed)

        self.saturation = QSlider()
        self.saturation.setMaximum(100)
        self.saturation.setOrientation(Qt.Horizontal)
        self.saturation.valueChanged.connect(self._changed)

        self.value = QSlider()
        self.value.setMaximum(100)
        self.value.setOrientation(Qt.Horizontal)
        self.value.valueChanged.connect(self._changed)

        layout = QGridLayout(self)
        layout.addWidget(QLabel("H"))
        layout.addWidget(QLabel("S"))
        layout.addWidget(QLabel("V"))
        layout.addWidget(self.hue, 0, 1)
        layout.addWidget(self.saturation, 1, 1)
        layout.addWidget(self.value, 2, 1)

    def set_rgb(self, r, g, b):
        h, s, v = colorsys.rgb_to_hsv(r / 255.0, g / 255.0, b / 255.0)
        self.hue.setValue(h * 100)
        self.saturation.setValue(s * 100)
        self.value.setValue(v * 100)

    def _changed(self):
        r, g, b = colorsys.hsv_to_rgb(
            self.hue.value() / 100.0,
            self.saturation.value() / 100.0,
            self.value.value() / 100.0,
        )
        self.changed.emit(int(r * 255), int(g * 255), int(b * 255))
コード例 #2
0
class ViewerToolbar(QWidget):
    thumb_size_changed = Signal()

    def __init__(self, *args, **kwargs):
        super(ViewerToolbar, self).__init__(*args, **kwargs)

        self._thumb_size = QSlider()

        self._build_ui()
        self._build_connections()
        self._setup_ui()

    def _build_ui(self):
        self._thumb_size.setRange(100, 400)
        self._thumb_size.setValue(settings.thumb_size)
        self._thumb_size.setOrientation(Qt.Horizontal)
        self._thumb_size.setFixedWidth(300)

        lyt_main = QHBoxLayout()
        lyt_main.setContentsMargins(0, 0, 0, 0)
        lyt_main.setSpacing(0)
        lyt_main.addStretch()
        lyt_main.addWidget(QLabel('%d %%' % self._thumb_size.minimum()))
        lyt_main.addSpacing(5)
        lyt_main.addWidget(self._thumb_size)
        lyt_main.addSpacing(5)
        lyt_main.addWidget(QLabel('%d %%' % self._thumb_size.maximum()))
        self.setLayout(lyt_main)

    def _build_connections(self):
        self._thumb_size.valueChanged.connect(self._thumb_size_changed)

    def _setup_ui(self):
        pass

    def _thumb_size_changed(self):
        settings.thumb_size = self._thumb_size.value()
        self.thumb_size_changed.emit()
コード例 #3
0
ファイル: qt.py プロジェクト: renemilk/pyMor
    class PlotMainWindow(QWidget):
        """Base class for plot main windows."""

        def __init__(self, U, plot, length=1, title=None):
            super().__init__()

            layout = QVBoxLayout()

            if title:
                title = QLabel('<b>' + title + '</b>')
                title.setAlignment(Qt.AlignHCenter)
                layout.addWidget(title)
            layout.addWidget(plot)

            plot.set(U, 0)

            if length > 1:
                hlayout = QHBoxLayout()

                self.slider = QSlider(Qt.Horizontal)
                self.slider.setMinimum(0)
                self.slider.setMaximum(length - 1)
                self.slider.setTickPosition(QSlider.TicksBelow)
                hlayout.addWidget(self.slider)

                lcd = QLCDNumber(m.ceil(m.log10(length)))
                lcd.setDecMode()
                lcd.setSegmentStyle(QLCDNumber.Flat)
                hlayout.addWidget(lcd)

                layout.addLayout(hlayout)

                hlayout = QHBoxLayout()

                toolbar = QToolBar()
                self.a_play = QAction(self.style().standardIcon(QStyle.SP_MediaPlay), 'Play', self)
                self.a_play.setCheckable(True)
                self.a_rewind = QAction(self.style().standardIcon(QStyle.SP_MediaSeekBackward), 'Rewind', self)
                self.a_toend = QAction(self.style().standardIcon(QStyle.SP_MediaSeekForward), 'End', self)
                self.a_step_backward = QAction(self.style().standardIcon(QStyle.SP_MediaSkipBackward),
                                               'Step Back', self)
                self.a_step_forward = QAction(self.style().standardIcon(QStyle.SP_MediaSkipForward), 'Step', self)
                self.a_loop = QAction(self.style().standardIcon(QStyle.SP_BrowserReload), 'Loop', self)
                self.a_loop.setCheckable(True)
                toolbar.addAction(self.a_play)
                toolbar.addAction(self.a_rewind)
                toolbar.addAction(self.a_toend)
                toolbar.addAction(self.a_step_backward)
                toolbar.addAction(self.a_step_forward)
                toolbar.addAction(self.a_loop)
                if hasattr(self, 'save'):
                    self.a_save = QAction(self.style().standardIcon(QStyle.SP_DialogSaveButton), 'Save', self)
                    toolbar.addAction(self.a_save)
                    self.a_save.triggered.connect(self.save)
                hlayout.addWidget(toolbar)

                self.speed = QSlider(Qt.Horizontal)
                self.speed.setMinimum(0)
                self.speed.setMaximum(100)
                hlayout.addWidget(QLabel('Speed:'))
                hlayout.addWidget(self.speed)

                layout.addLayout(hlayout)

                self.timer = QTimer()
                self.timer.timeout.connect(self.update_solution)

                self.slider.valueChanged.connect(self.slider_changed)
                self.slider.valueChanged.connect(lcd.display)
                self.speed.valueChanged.connect(self.speed_changed)
                self.a_play.toggled.connect(self.toggle_play)
                self.a_rewind.triggered.connect(self.rewind)
                self.a_toend.triggered.connect(self.to_end)
                self.a_step_forward.triggered.connect(self.step_forward)
                self.a_step_backward.triggered.connect(self.step_backward)

                self.speed.setValue(50)

            elif hasattr(self, 'save'):
                hlayout = QHBoxLayout()
                toolbar = QToolBar()
                self.a_save = QAction(self.style().standardIcon(QStyle.SP_DialogSaveButton), 'Save', self)
                toolbar.addAction(self.a_save)
                hlayout.addWidget(toolbar)
                layout.addLayout(hlayout)
                self.a_save.triggered.connect(self.save)

            self.setLayout(layout)
            self.plot = plot
            self.U = U
            self.length = length

        def slider_changed(self, ind):
            self.plot.set(self.U, ind)

        def speed_changed(self, val):
            self.timer.setInterval(val * 20)

        def update_solution(self):
            ind = self.slider.value() + 1
            if ind >= self.length:
                if self.a_loop.isChecked():
                    ind = 0
                else:
                    self.a_play.setChecked(False)
                    return
            self.slider.setValue(ind)

        def toggle_play(self, checked):
            if checked:
                if self.slider.value() + 1 == self.length:
                    self.slider.setValue(0)
                self.timer.start()
            else:
                self.timer.stop()

        def rewind(self):
            self.slider.setValue(0)

        def to_end(self):
            self.a_play.setChecked(False)
            self.slider.setValue(self.length - 1)

        def step_forward(self):
            self.a_play.setChecked(False)
            ind = self.slider.value() + 1
            if ind == self.length and self.a_loop.isChecked():
                ind = 0
            if ind < self.length:
                self.slider.setValue(ind)

        def step_backward(self):
            self.a_play.setChecked(False)
            ind = self.slider.value() - 1
            if ind == -1 and self.a_loop.isChecked():
                ind = self.length - 1
            if ind >= 0:
                self.slider.setValue(ind)
コード例 #4
0
class BaseColorDialog(BaseDialog, object):

    def_title = 'Select Color'

    maya_colors = [(.467, .467, .467), (.000, .000, .000), (.247, .247, .247),
                   (.498, .498, .498), (0.608, 0, 0.157), (0, 0.016, 0.373),
                   (0, 0, 1), (0, 0.275, 0.094), (0.145, 0, 0.263),
                   (0.78, 0, 0.78), (0.537, 0.278, 0.2), (0.243, 0.133, 0.122),
                   (0.6, 0.145, 0), (1, 0, 0), (0, 1, 0), (0, 0.255, 0.6),
                   (1, 1, 1), (1, 1, 0), (0.388, 0.863, 1), (0.263, 1, 0.635),
                   (1, 0.686, 0.686), (0.89, 0.675, 0.475), (1, 1, 0.384),
                   (0, 0.6, 0.325), (0.627, 0.412, 0.188),
                   (0.62, 0.627, 0.188), (0.408, 0.627, 0.188),
                   (0.188, 0.627, 0.365), (0.188, 0.627, 0.627),
                   (0.188, 0.404, 0.627), (0.435, 0.188, 0.627),
                   (0.627, 0.188, 0.404)]

    def __init__(self, name='MayaColorDialog', parent=None, **kwargs):
        parent = parent or dcc.get_main_window()

        super(BaseColorDialog, self).__init__(name=name,
                                              parent=parent,
                                              **kwargs)

        self._color = None

    def get_color(self):
        return self._color

    color = property(get_color)

    def ui(self):

        self.color_buttons = list()

        super(BaseColorDialog, self).ui()

        grid_layout = layouts.GridLayout()
        grid_layout.setAlignment(Qt.AlignTop)
        self.main_layout.addLayout(grid_layout)
        color_index = 0
        for i in range(0, 4):
            for j in range(0, 8):
                color_btn = QPushButton()
                color_btn.setMinimumHeight(35)
                color_btn.setMinimumWidth(35)
                self.color_buttons.append(color_btn)
                color_btn.setStyleSheet(
                    'background-color:rgb(%s,%s,%s);' %
                    (self.maya_colors[color_index][0] * 255,
                     self.maya_colors[color_index][1] * 255,
                     self.maya_colors[color_index][2] * 255))
                grid_layout.addWidget(color_btn, i, j)
                color_index += 1
        selected_color_layout = layouts.HorizontalLayout()
        self.main_layout.addLayout(selected_color_layout)
        self.color_slider = QSlider(Qt.Horizontal)
        self.color_slider.setMinimum(0)
        self.color_slider.setMaximum(31)
        self.color_slider.setValue(2)
        self.color_slider.setStyleSheet(
            "QSlider::groove:horizontal {border: 1px solid #999999;height: 25px; /* the groove expands "
            "to the size of the slider by default. by giving it a height, it has a fixed size */background: "
            "qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 #B1B1B1, stop:1 #c4c4c4);margin: 2px 0;}"
            "QSlider::handle:horizontal {background: qlineargradient(x1:0, y1:0, x2:1, y2:1, stop:0 #b4b4b4,"
            " stop:1 #8f8f8f);border: 1px solid #5c5c5c;width: 10px;margin: -2px 0; /* handle is placed by "
            "default on the contents rect of the groove. Expand outside the groove */border-radius: 1px;}"
        )
        selected_color_layout.addWidget(self.color_slider)

        color_label_layout = layouts.HorizontalLayout(margins=(10, 10, 10, 10))
        self.main_layout.addLayout(color_label_layout)

        self.color_lbl = QLabel()
        self.color_lbl.setStyleSheet(
            "border: 1px solid black; background-color:rgb(0, 0, 0);")
        self.color_lbl.setMinimumWidth(45)
        self.color_lbl.setMaximumWidth(80)
        self.color_lbl.setMinimumHeight(80)
        self.color_lbl.setAlignment(Qt.AlignCenter)
        color_label_layout.addWidget(self.color_lbl)

        bottom_layout = layouts.HorizontalLayout()
        bottom_layout.setAlignment(Qt.AlignRight)
        self.main_layout.addLayout(bottom_layout)

        self.ok_btn = QPushButton('Ok')
        self.cancel_btn = QPushButton('Cancel')
        bottom_layout.addLayout(dividers.DividerLayout())
        bottom_layout.addWidget(self.ok_btn)
        bottom_layout.addWidget(self.cancel_btn)

    def setup_signals(self):

        for i, btn in enumerate(self.color_buttons):
            btn.clicked.connect(partial(self._on_set_color, i))
        self.color_slider.valueChanged.connect(self._on_set_color)

        self.ok_btn.clicked.connect(self._on_ok_btn)
        self.cancel_btn.clicked.connect(self._on_cancel_btn)

    def _on_set_color(self, color_index):
        self.color_lbl.setStyleSheet('background-color:rgb(%s,%s,%s);' %
                                     (self.maya_colors[color_index][0] * 255,
                                      self.maya_colors[color_index][1] * 255,
                                      self.maya_colors[color_index][2] * 255))
        self.color_slider.setValue(color_index)

    def _on_set_slider(self, color_index):
        self._set_color(color_index=color_index)

    def _on_ok_btn(self):
        self._color = self.color_slider.value()
        self.close()

    def _on_cancel_btn(self):
        self._color = None
        self.close()
コード例 #5
0
    class PlotMainWindow(QWidget):
        """Base class for plot main windows."""
        def __init__(self, U, plot, length=1, title=None):
            super().__init__()

            layout = QVBoxLayout()

            if title:
                title = QLabel('<b>' + title + '</b>')
                title.setAlignment(Qt.AlignHCenter)
                layout.addWidget(title)
            layout.addWidget(plot)

            plot.set(U, 0)

            if length > 1:
                hlayout = QHBoxLayout()

                self.slider = QSlider(Qt.Horizontal)
                self.slider.setMinimum(0)
                self.slider.setMaximum(length - 1)
                self.slider.setTickPosition(QSlider.TicksBelow)
                hlayout.addWidget(self.slider)

                lcd = QLCDNumber(m.ceil(m.log10(length)))
                lcd.setDecMode()
                lcd.setSegmentStyle(QLCDNumber.Flat)
                hlayout.addWidget(lcd)

                layout.addLayout(hlayout)

                hlayout = QHBoxLayout()

                toolbar = QToolBar()
                self.a_play = QAction(
                    self.style().standardIcon(QStyle.SP_MediaPlay), 'Play',
                    self)
                self.a_play.setCheckable(True)
                self.a_rewind = QAction(
                    self.style().standardIcon(QStyle.SP_MediaSeekBackward),
                    'Rewind', self)
                self.a_toend = QAction(
                    self.style().standardIcon(QStyle.SP_MediaSeekForward),
                    'End', self)
                self.a_step_backward = QAction(
                    self.style().standardIcon(QStyle.SP_MediaSkipBackward),
                    'Step Back', self)
                self.a_step_forward = QAction(
                    self.style().standardIcon(QStyle.SP_MediaSkipForward),
                    'Step', self)
                self.a_loop = QAction(
                    self.style().standardIcon(QStyle.SP_BrowserReload), 'Loop',
                    self)
                self.a_loop.setCheckable(True)
                toolbar.addAction(self.a_play)
                toolbar.addAction(self.a_rewind)
                toolbar.addAction(self.a_toend)
                toolbar.addAction(self.a_step_backward)
                toolbar.addAction(self.a_step_forward)
                toolbar.addAction(self.a_loop)
                if hasattr(self, 'save'):
                    self.a_save = QAction(
                        self.style().standardIcon(QStyle.SP_DialogSaveButton),
                        'Save', self)
                    toolbar.addAction(self.a_save)
                    self.a_save.triggered.connect(self.save)
                hlayout.addWidget(toolbar)

                self.speed = QSlider(Qt.Horizontal)
                self.speed.setMinimum(0)
                self.speed.setMaximum(100)
                hlayout.addWidget(QLabel('Speed:'))
                hlayout.addWidget(self.speed)

                layout.addLayout(hlayout)

                self.timer = QTimer()
                self.timer.timeout.connect(self.update_solution)

                self.slider.valueChanged.connect(self.slider_changed)
                self.slider.valueChanged.connect(lcd.display)
                self.speed.valueChanged.connect(self.speed_changed)
                self.a_play.toggled.connect(self.toggle_play)
                self.a_rewind.triggered.connect(self.rewind)
                self.a_toend.triggered.connect(self.to_end)
                self.a_step_forward.triggered.connect(self.step_forward)
                self.a_step_backward.triggered.connect(self.step_backward)

                self.speed.setValue(50)

            elif hasattr(self, 'save'):
                hlayout = QHBoxLayout()
                toolbar = QToolBar()
                self.a_save = QAction(
                    self.style().standardIcon(QStyle.SP_DialogSaveButton),
                    'Save', self)
                toolbar.addAction(self.a_save)
                hlayout.addWidget(toolbar)
                layout.addLayout(hlayout)
                self.a_save.triggered.connect(self.save)

            self.setLayout(layout)
            self.plot = plot
            self.U = U
            self.length = length

        def slider_changed(self, ind):
            self.plot.set(self.U, ind)

        def speed_changed(self, val):
            self.timer.setInterval(val * 20)

        def update_solution(self):
            ind = self.slider.value() + 1
            if ind >= self.length:
                if self.a_loop.isChecked():
                    ind = 0
                else:
                    self.a_play.setChecked(False)
                    return
            self.slider.setValue(ind)

        def toggle_play(self, checked):
            if checked:
                if self.slider.value() + 1 == self.length:
                    self.slider.setValue(0)
                self.timer.start()
            else:
                self.timer.stop()

        def rewind(self):
            self.slider.setValue(0)

        def to_end(self):
            self.a_play.setChecked(False)
            self.slider.setValue(self.length - 1)

        def step_forward(self):
            self.a_play.setChecked(False)
            ind = self.slider.value() + 1
            if ind == self.length and self.a_loop.isChecked():
                ind = 0
            if ind < self.length:
                self.slider.setValue(ind)

        def step_backward(self):
            self.a_play.setChecked(False)
            ind = self.slider.value() - 1
            if ind == -1 and self.a_loop.isChecked():
                ind = self.length - 1
            if ind >= 0:
                self.slider.setValue(ind)
コード例 #6
0
ファイル: attributes.py プロジェクト: tpDcc/tpDcc-libs-qt
class ColorPicker(BaseEditor, object):

    attr_type = 'color'

    def __init__(self, parent=None, **kwargs):
        super(ColorPicker, self).__init__(parent=parent, **kwargs)

        self._default_value = (125, 125, 125)
        self.attr = None

        self.normalized = kwargs.get('normalized', False)
        self.min = kwargs.get('min', 0)
        self.max = kwargs.get('max', 99)
        self.color = kwargs.get('color', QColor(1.0, 1.0, 1.0))
        self.mult = kwargs.get('mult', 0.1)

        self.color_swatch = color.ColorSwatch(parent=self,
                                              color=self.color,
                                              normalized=self.normalized)
        self.color_swatch.setMaximumSize(QSize(75, 20))
        self.color_swatch.setMinimumSize(QSize(75, 20))
        self.color_swatch.set_color(color=self.color)
        self.main_layout.addWidget(self.color_swatch)

        self.slider = QSlider(self)
        self.slider.setOrientation(Qt.Horizontal)
        self.slider.setValue(self.max)
        self.main_layout.addWidget(self.slider)

        self.set_max(self.max)
        self.set_min(self.min)

        self.slider.valueChanged.connect(self.OnSliderChanged)
        self.slider.sliderReleased.connect(self.OnSliderReleased)
        self.color_swatch.clicked.connect(self.OnColorPicked)

    # region Properties
    def get_rgb(self):
        return self.color_swatch.qcolor.getRgb()[0:3]

    def get_rgbF(self):
        return self.color_swatch.qcolor.getRgbF()[0:3]

    def get_hsv(self):
        return self.color_swatch.qcolor.getHsv()[0:3]

    def get_hsvF(self):
        return self.color_swatch.qcolor.getHsvF()[0:3]

    rgb = property(get_rgb)
    rgbF = property(get_rgbF)
    hsv = property(get_hsv)
    gsvF = property(get_hsvF)

    def OnSliderChanged(self):
        slider_value = float(self.slider.value())
        if not self._current_value:
            LOGGER.debug(
                'Caching color: (%d, %d, %d)' %
                (self.color_swatch.color[0], self.color_swatch.color[1],
                 self.color_swatch.color[2]))
            self._current_value = self.color_swatch.color
        current_color = QColor(*self._current_value)
        darker = 200 - slider_value
        new_color = current_color.darker(darker)
        self.color_swatch.qcolor = new_color
        self.color_swatch._update()

    def OnSliderReleased(self):
        """
        Updates items color when the slider handle is released
        """

        color = self.color_swatch.color
        self.color_swatch._update()
        self.OnValueUpdated()

    def OnColorPicked(self):
        """
        Event to call color picker
        """

        dialog = QColorDialog(self.color_swatch.qcolor, self)
        if dialog.exec_():
            self.color_swatch.setPalette(QPalette(dialog.currentColor()))
            self.color_swatch.qcolor = dialog.currentColor()
            self.color_swatch._update()
            self.OnValueUpdated()

    def get_value(self):
        return self.color_swatch.color

    def initialize_editor(self):
        editor_value = self.default_value

        node_values = self.values
        if node_values:
            if len(node_values) > 1:
                pass
            elif len(node_values) == 1:
                if node_values[0]:
                    editor_value = node_values[0]

                self.color_swatch.set_color(editor_value)

    def set_connected(self, conn):
        if conn != self._connection:
            self._connection = conn
            self.value_line.setText(conn)
            self.color_swatch.setEnabled(False)

    def sizeHint(self):
        return QSize(350, 27)

    def set_attr(self, value):
        self.attr = value
        return self.attr

    def get_attr(self):
        return self.attr

    def set_min(self, value):
        """
        Sets the slider minimum value
        :param value: int, slider minimum value
        """

        self.min = value
        self.slider.setMinimum(value)

    def set_max(self, value):
        """
        Sets the silder maximum value
        :param value: int, slider maximum value
        """

        self.max = value
        self.slider.setMaximum(value)

    def get_qcolor(self):
        return self.color_swatch.qcolor

    def set_color(self, value):
        return self.color_swatch.set_color(color=value)

    def _update(self):
        return self.color_swatch._update()
コード例 #7
0
ファイル: view4.py プロジェクト: charlesli640/pyqt5
class View(QFrame):
    graphicsView = None
    label = None
    label2 = None
    selectModeButton = None
    dragModeButton = None
    openGlButton = None
    antialiasButton = None
    resetButton = None
    zoomSlider = None
    rotateSlider = None

    def __init__(self, name, parent=None):
        super(View, self).__init__(parent)
        self.init_ui(name)

    def init_ui(self, name):
        self.setFrameStyle(QFrame.Sunken | QFrame.StyledPanel)
        self.graphicsView = GraphicsView(self)
        self.graphicsView.setRenderHint(QPainter.Antialiasing, False)
        self.graphicsView.setDragMode(QGraphicsView.RubberBandDrag)
        self.graphicsView.setOptimizationFlags(QGraphicsView.DontSavePainterState)
        self.graphicsView.setViewportUpdateMode(QGraphicsView.SmartViewportUpdate)
        self.graphicsView.setTransformationAnchor(QGraphicsView.AnchorUnderMouse)

        size = self.style().pixelMetric(QStyle.PM_ToolBarIconSize)
        iconSize = QSize(size, size)

        zoomInIcon = QToolButton()
        zoomInIcon.setAutoRepeat(True)
        zoomInIcon.setAutoRepeatInterval(33)
        zoomInIcon.setAutoRepeatDelay(0)
        zoomInIcon.setIcon(QIcon(":/zoomin.png"))
        zoomInIcon.setIconSize(iconSize)
        zoomOutIcon = QToolButton()
        zoomOutIcon.setAutoRepeat(True)
        zoomOutIcon.setAutoRepeatInterval(33)
        zoomOutIcon.setAutoRepeatDelay(0)
        zoomOutIcon.setIcon(QIcon(":/zoomout.png"))
        zoomOutIcon.setIconSize(iconSize)
        self.zoomSlider = QSlider()
        self.zoomSlider.setMinimum(0)
        self.zoomSlider.setMaximum(500)
        self.zoomSlider.setValue(250)
        self.zoomSlider.setTickPosition(QSlider.TicksRight)

        # Zoom slider layout
        zoomSliderLayout = QVBoxLayout()
        zoomSliderLayout.addWidget(zoomInIcon)
        zoomSliderLayout.addWidget(self.zoomSlider)
        zoomSliderLayout.addWidget(zoomOutIcon)

        rotateLeftIcon = QToolButton()
        rotateLeftIcon.setIcon(QIcon(":/rotateleft.png"))
        rotateLeftIcon.setIconSize(iconSize)
        rotateRightIcon = QToolButton()
        rotateRightIcon.setIcon(QIcon(":/rotateright.png"))
        rotateRightIcon.setIconSize(iconSize)
        self.rotateSlider = QSlider()
        self.rotateSlider.setOrientation(Qt.Horizontal)
        self.rotateSlider.setMinimum(-360)
        self.rotateSlider.setMaximum(360)
        self.rotateSlider.setValue(0)
        self.rotateSlider.setTickPosition(QSlider.TicksBelow)

        # Rotate slider layout
        rotateSliderLayout = QHBoxLayout()
        rotateSliderLayout.addWidget(rotateLeftIcon)
        rotateSliderLayout.addWidget(self.rotateSlider)
        rotateSliderLayout.addWidget(rotateRightIcon)

        self.resetButton = QToolButton()
        self.resetButton.setText("0")
        self.resetButton.setEnabled(False)

        # Label layout
        labelLayout = QHBoxLayout()
        self.label = QLabel(name)
        self.label2 = QLabel("Pointer Mode")
        self.selectModeButton = QToolButton()
        self.selectModeButton.setText("Select")
        self.selectModeButton.setCheckable(True)
        self.selectModeButton.setChecked(True)
        self.dragModeButton = QToolButton()
        self.dragModeButton.setText("Drag")
        self.dragModeButton.setCheckable(True)
        self.dragModeButton.setChecked(False)
        self.antialiasButton = QToolButton()
        self.antialiasButton.setText("Antialiasing")
        self.antialiasButton.setCheckable(True)
        self.antialiasButton.setChecked(False)
        self.openGlButton = QToolButton()
        self.openGlButton.setText("OpenGL")
        self.openGlButton.setCheckable(True)
        self.openGlButton.setEnabled(QGLFormat.hasOpenGL())

        pointerModeGroup = QButtonGroup()
        pointerModeGroup.setExclusive(True)
        pointerModeGroup.addButton(self.selectModeButton)
        pointerModeGroup.addButton(self.dragModeButton)

        labelLayout.addWidget(self.label)
        labelLayout.addStretch()
        labelLayout.addWidget(self.label2)
        labelLayout.addWidget(self.selectModeButton)
        labelLayout.addWidget(self.dragModeButton)
        labelLayout.addStretch()
        labelLayout.addWidget(self.antialiasButton)
        labelLayout.addWidget(self.openGlButton)

        topLayout = QGridLayout()
        topLayout.addLayout(labelLayout, 0, 0)
        topLayout.addWidget(self.graphicsView, 1, 0)
        topLayout.addLayout(zoomSliderLayout, 1, 1)
        topLayout.addLayout(rotateSliderLayout, 2, 0)
        topLayout.addWidget(self.resetButton, 2, 1)
        self.setLayout(topLayout)

        self.resetButton.clicked.connect(self.resetView)
        self.zoomSlider.valueChanged.connect(self.setupTransform)
        self.rotateSlider.valueChanged.connect(self.setupTransform)

        self.graphicsView.verticalScrollBar().valueChanged.connect(self.setResetButtonEnabled)
        self.graphicsView.horizontalScrollBar().valueChanged.connect(self.setResetButtonEnabled)
        self.selectModeButton.toggled.connect(self.togglePointerMode)
        self.dragModeButton.toggled.connect(self.togglePointerMode)
        self.antialiasButton.toggled.connect(self.toggleAntialiasing)
        self.openGlButton.toggled.connect(self.toggleOpenGL)
        rotateLeftIcon.clicked.connect(self.rotateLeft)
        rotateRightIcon.clicked.connect(self.rotateRight)
        zoomInIcon.clicked.connect(self.zoomIn)
        zoomOutIcon.clicked.connect(self.zoomOut)

        self.setupTransform()

    def view(self):
        return self.graphicsView

    @Slot()
    def zoomIn(self):
        self.zoomSlider.setValue(self.zoomSlider.value() + 1)

    @Slot()
    def zoomOut(self):
        self.zoomSlider.setValue(self.zoomSlider.value() - 1)

    @Slot()
    def resetView(self):
        self.zoomSlider.setValue(250)
        self.rotateSlider.setValue(0)
        self.setupTransform()
        self.graphicsView.ensureVisible(QRectF(0, 0, 0, 0))

        self.resetButton.setEnabled(False)

    @Slot()
    def setResetButtonEnabled(self):
        self.resetButton.setEnabled(True)

    @Slot()
    def setupTransform(self):
        scale = pow(2.0, (self.zoomSlider.value() - 250) / 50.0)
        trans = QTransform()
        trans.scale(scale, scale)
        trans.rotate(self.rotateSlider.value())

        self.graphicsView.setTransform(trans)
        self.setResetButtonEnabled()

    @Slot()
    def togglePointerMode(self):
        self.graphicsView.setDragMode(
            QGraphicsView.RubberBandDrag if self.selectModeButton.isChecked() else QGraphicsView.ScrollHandDrag)
        self.graphicsView.setInteractive(self.selectModeButton.isChecked())

    @Slot()
    def toggleOpenGL(self):
        self.graphicsView.setViewport(
            QGLWidget(QGLFormat(QGL.SampleBuffers)) if self.openGlButton.isChecked() else QWidget())

    @Slot()
    def toggleAntialiasing(self):
        self.graphicsView.setRenderHint(QPainter.Antialiasing, self.antialiasButton.isChecked())

    @Slot()
    def rotateLeft(self):
        self.rotateSlider.setValue(self.rotateSlider.value() - 10)

    @Slot()
    def rotateRight(self):
        self.rotateSlider.setValue(self.rotateSlider.value() + 10)