Browse Source

Add new files

tags/1.9.4
falkTX 11 years ago
parent
commit
37620c9ec3
4 changed files with 3255 additions and 0 deletions
  1. +1
    -0
      .gitignore
  2. +2594
    -0
      source/patchcanvas.py
  3. +482
    -0
      source/patchcanvas_theme.py
  4. +178
    -0
      source/widgets/canvaspreviewframe.py

+ 1
- 0
.gitignore View File

@@ -30,6 +30,7 @@ ui_*.h
# Python files
*.pyc
ui_*.py
source/canvaspreviewframe.py
source/digitalpeakmeter.py
source/ledbutton.py
source/paramspinbox.py


+ 2594
- 0
source/patchcanvas.py
File diff suppressed because it is too large
View File


+ 482
- 0
source/patchcanvas_theme.py View File

@@ -0,0 +1,482 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# PatchBay Canvas Themes
# Copyright (C) 2010-2012 Filipe Coelho <falktx@falktx.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# For a full copy of the GNU General Public License see the COPYING file

# ------------------------------------------------------------------------------------------------------------
# Imports (Global)

from PyQt4.QtCore import Qt
from PyQt4.QtGui import QColor, QFont, QPen, QPixmap

# ------------------------------------------------------------------------------------------------------------
# patchcanvas-theme.cpp

class Theme(object):
# enum PortType
THEME_PORT_SQUARE = 0
THEME_PORT_POLYGON = 1

# enum List
THEME_MODERN_DARK = 0
THEME_MODERN_DARK_TINY = 1
THEME_MODERN_LIGHT = 2
THEME_CLASSIC_DARK = 3
THEME_OOSTUDIO = 4
THEME_MAX = 5

# enum BackgroundType
THEME_BG_SOLID = 0
THEME_BG_GRADIENT = 1

def __init__(self, idx):
object.__init__(self)

self.idx = idx

if idx == self.THEME_MODERN_DARK:
# Canvas
self.canvas_bg = QColor(0, 0, 0)

# Boxes
self.box_pen = QPen(QColor(76, 77, 78), 1, Qt.SolidLine)
self.box_pen_sel = QPen(QColor(206, 207, 208), 1, Qt.DashLine)
self.box_bg_1 = QColor(32, 34, 35)
self.box_bg_2 = QColor(43, 47, 48)
self.box_shadow = QColor(89, 89, 89, 180)
self.box_header_pixmap = None
self.box_header_height = 24
self.box_header_spacing = 0

self.box_text = QPen(QColor(240, 240, 240), 0)
self.box_text_sel = self.box_text
self.box_text_ypos = 16
self.box_font_name = "Deja Vu Sans"
self.box_font_size = 8
self.box_font_state = QFont.Bold

self.box_bg_type = self.THEME_BG_GRADIENT
self.box_use_icon = True

# Ports
self.port_text = QPen(QColor(250, 250, 250), 0)
self.port_text_ypos = 12
self.port_bg_pixmap = None
self.port_font_name = "Deja Vu Sans"
self.port_font_size = 8
self.port_font_state = QFont.Normal
self.port_mode = self.THEME_PORT_POLYGON

self.port_audio_jack_pen = QPen(QColor(63, 90, 126), 1)
self.port_audio_jack_pen_sel = QPen(QColor(63 + 30, 90 + 30, 126 + 30), 1)
self.port_midi_jack_pen = QPen(QColor(159, 44, 42), 1)
self.port_midi_jack_pen_sel = QPen(QColor(159 + 30, 44 + 30, 42 + 30), 1)
self.port_midi_a2j_pen = QPen(QColor(137, 76, 43), 1)
self.port_midi_a2j_pen_sel = QPen(QColor(137 + 30, 76 + 30, 43 + 30), 1)
self.port_midi_alsa_pen = QPen(QColor(93, 141, 46), 1)
self.port_midi_alsa_pen_sel = QPen(QColor(93 + 30, 141 + 30, 46 + 30), 1)

self.port_audio_jack_bg = QColor(35, 61, 99)
self.port_audio_jack_bg_sel = QColor(35 + 50, 61 + 50, 99 + 50)
self.port_midi_jack_bg = QColor(120, 15, 16)
self.port_midi_jack_bg_sel = QColor(120 + 50, 15 + 50, 16 + 50)
self.port_midi_a2j_bg = QColor(101, 47, 16)
self.port_midi_a2j_bg_sel = QColor(101 + 50, 47 + 50, 16 + 50)
self.port_midi_alsa_bg = QColor(64, 112, 18)
self.port_midi_alsa_bg_sel = QColor(64 + 50, 112 + 50, 18 + 50)

self.port_audio_jack_text = self.port_text
self.port_audio_jack_text_sel = self.port_text
self.port_midi_jack_text = self.port_text
self.port_midi_jack_text_sel = self.port_text
self.port_midi_a2j_text = self.port_text
self.port_midi_a2j_text_sel = self.port_text
self.port_midi_alsa_text = self.port_text
self.port_midi_alsa_text_sel = self.port_text

self.port_height = 15
self.port_offset = 0
self.port_spacing = 3
self.port_spacingT = 2

# Lines
self.line_audio_jack = QColor(63, 90, 126)
self.line_audio_jack_sel = QColor(63 + 90, 90 + 90, 126 + 90)
self.line_audio_jack_glow = QColor(100, 100, 200)
self.line_midi_jack = QColor(159, 44, 42)
self.line_midi_jack_sel = QColor(159 + 90, 44 + 90, 42 + 90)
self.line_midi_jack_glow = QColor(200, 100, 100)
self.line_midi_a2j = QColor(137, 76, 43)
self.line_midi_a2j_sel = QColor(137 + 90, 76 + 90, 43 + 90)
self.line_midi_a2j_glow = QColor(166, 133, 133)
self.line_midi_alsa = QColor(93, 141, 46)
self.line_midi_alsa_sel = QColor(93 + 90, 141 + 90, 46 + 90)
self.line_midi_alsa_glow = QColor(100, 200, 100)

self.rubberband_pen = QPen(QColor(206, 207, 208), 1, Qt.SolidLine)
self.rubberband_brush = QColor(76, 77, 78, 100)

elif idx == self.THEME_MODERN_DARK_TINY:
# Canvas
self.canvas_bg = QColor(0, 0, 0)

# Boxes
self.box_pen = QPen(QColor(76, 77, 78), 1, Qt.SolidLine)
self.box_pen_sel = QPen(QColor(206, 207, 208), 1, Qt.DashLine)
self.box_bg_1 = QColor(32, 34, 35)
self.box_bg_2 = QColor(43, 47, 48)
self.box_shadow = QColor(89, 89, 89, 180)
self.box_header_pixmap = None
self.box_header_height = 14
self.box_header_spacing = 0

self.box_text = QPen(QColor(240, 240, 240), 0)
self.box_text_sel = self.box_text
self.box_text_ypos = 10
self.box_font_name = "Deja Vu Sans"
self.box_font_size = 7
self.box_font_state = QFont.Bold

self.box_bg_type = self.THEME_BG_GRADIENT
self.box_use_icon = False

# Ports
self.port_text = QPen(QColor(250, 250, 250), 0)
self.port_text_ypos = 9
self.port_bg_pixmap = None
self.port_font_name = "Deja Vu Sans"
self.port_font_size = 6
self.port_font_state = QFont.Normal
self.port_mode = self.THEME_PORT_POLYGON

self.port_audio_jack_pen = QPen(QColor(63, 90, 126), 1)
self.port_audio_jack_pen_sel = QPen(QColor(63 + 30, 90 + 30, 126 + 30), 1)
self.port_midi_jack_pen = QPen(QColor(159, 44, 42), 1)
self.port_midi_jack_pen_sel = QPen(QColor(159 + 30, 44 + 30, 42 + 30), 1)
self.port_midi_a2j_pen = QPen(QColor(137, 76, 43), 1)
self.port_midi_a2j_pen_sel = QPen(QColor(137 + 30, 76 + 30, 43 + 30), 1)
self.port_midi_alsa_pen = QPen(QColor(93, 141, 46), 1)
self.port_midi_alsa_pen_sel = QPen(QColor(93 + 30, 141 + 30, 46 + 30), 1)

self.port_audio_jack_bg = QColor(35, 61, 99)
self.port_audio_jack_bg_sel = QColor(35 + 50, 61 + 50, 99 + 50)
self.port_midi_jack_bg = QColor(120, 15, 16)
self.port_midi_jack_bg_sel = QColor(120 + 50, 15 + 50, 16 + 50)
self.port_midi_a2j_bg = QColor(101, 47, 16)
self.port_midi_a2j_bg_sel = QColor(101 + 50, 47 + 50, 16 + 50)
self.port_midi_alsa_bg = QColor(64, 112, 18)
self.port_midi_alsa_bg_sel = QColor(64 + 50, 112 + 50, 18 + 50)

self.port_audio_jack_text = self.port_text
self.port_audio_jack_text_sel = self.port_text
self.port_midi_jack_text = self.port_text
self.port_midi_jack_text_sel = self.port_text
self.port_midi_a2j_text = self.port_text
self.port_midi_a2j_text_sel = self.port_text
self.port_midi_alsa_text = self.port_text
self.port_midi_alsa_text_sel = self.port_text

self.port_height = 11
self.port_offset = 0
self.port_spacing = 2
self.port_spacingT = 1

# Lines
self.line_audio_jack = QColor(63, 90, 126)
self.line_audio_jack_sel = QColor(63 + 90, 90 + 90, 126 + 90)
self.line_audio_jack_glow = QColor(100, 100, 200)
self.line_midi_jack = QColor(159, 44, 42)
self.line_midi_jack_sel = QColor(159 + 90, 44 + 90, 42 + 90)
self.line_midi_jack_glow = QColor(200, 100, 100)
self.line_midi_a2j = QColor(137, 76, 43)
self.line_midi_a2j_sel = QColor(137 + 90, 76 + 90, 43 + 90)
self.line_midi_a2j_glow = QColor(166, 133, 133)
self.line_midi_alsa = QColor(93, 141, 46)
self.line_midi_alsa_sel = QColor(93 + 90, 141 + 90, 46 + 90)
self.line_midi_alsa_glow = QColor(100, 200, 100)

self.rubberband_pen = QPen(QColor(206, 207, 208), 1, Qt.SolidLine)
self.rubberband_brush = QColor(76, 77, 78, 100)

elif idx == self.THEME_MODERN_LIGHT:
# Canvas
self.canvas_bg = QColor(248, 249, 250)

# Boxes
self.box_pen = QPen(QColor(176, 177, 178), 1, Qt.SolidLine)
self.box_pen_sel = QPen(QColor(1, 2, 3), 2, Qt.DashLine)
self.box_bg_1 = QColor(250, 250, 250)
self.box_bg_2 = QColor(200, 200, 200)
self.box_shadow = QColor(1, 1, 1, 100)
self.box_header_pixmap = None
self.box_header_height = 24
self.box_header_spacing = 0

self.box_text = QPen(QColor(1, 1, 1), 0)
self.box_text_sel = self.box_text
self.box_text_ypos = 16
self.box_font_name = "Ubuntu"
self.box_font_size = 11
self.box_font_state = QFont.Bold

self.box_bg_type = self.THEME_BG_GRADIENT
self.box_use_icon = True

# Ports
self.port_text = QPen(QColor(255, 255, 255), 1)
self.port_text_ypos = 12
self.port_bg_pixmap = None
self.port_font_name = "Ubuntu"
self.port_font_size = 10
self.port_font_state = QFont.Bold
self.port_mode = self.THEME_PORT_POLYGON

self.port_audio_jack_pen = QPen(QColor(103, 130, 166), 2)
self.port_audio_jack_pen_sel = QPen(QColor(103 + 136, 190 + 130, 226 + 130), 1)
self.port_midi_jack_pen = QPen(QColor(159, 44, 42), 1)
self.port_midi_jack_pen_sel = QPen(QColor(90 + 30, 44 + 30, 42 + 30), 1)
self.port_midi_a2j_pen = QPen(QColor(137, 76, 43), 1)
self.port_midi_a2j_pen_sel = QPen(QColor(137 + 30, 76 + 30, 43 + 30), 1)
self.port_midi_alsa_pen = QPen(QColor(93, 141, 46), 1)
self.port_midi_alsa_pen_sel = QPen(QColor(93 + 30, 141 + 30, 46 + 30), 1)

self.port_audio_jack_bg = QColor(0, 0, 180)
self.port_audio_jack_bg_sel = QColor(135 + 150, 161 + 150, 199 + 150)
self.port_midi_jack_bg = QColor(130, 15, 16)
self.port_midi_jack_bg_sel = QColor(90 + 30, 15 + 50, 16 + 50)
self.port_midi_a2j_bg = QColor(101, 47, 16)
self.port_midi_a2j_bg_sel = QColor(101 + 50, 47 + 50, 16 + 50)
self.port_midi_alsa_bg = QColor(64, 112, 18)
self.port_midi_alsa_bg_sel = QColor(64 + 50, 112 + 50, 18 + 50)

self.port_audio_jack_text = self.port_text
self.port_audio_jack_text_sel = self.port_text
self.port_midi_jack_text = self.port_text
self.port_midi_jack_text_sel = self.port_text
self.port_midi_a2j_text = self.port_text
self.port_midi_a2j_text_sel = self.port_text
self.port_midi_alsa_text = self.port_text
self.port_midi_alsa_text_sel = self.port_text

self.port_height = 15
self.port_offset = 0
self.port_spacing = 3
self.port_spacingT = 2

# Lines
self.line_audio_jack = QColor(63, 90, 126)
self.line_audio_jack_sel = QColor(63 + 63, 90 + 90, 126 + 90)
self.line_audio_jack_glow = QColor(100, 100, 200)
self.line_midi_jack = QColor(159, 44, 42)
self.line_midi_jack_sel = QColor(159 + 44, 44 + 90, 42 + 90)
self.line_midi_jack_glow = QColor(200, 100, 100)
self.line_midi_a2j = QColor(137, 43, 43)
self.line_midi_a2j_sel = QColor(137 + 90, 76 + 90, 43 + 90)
self.line_midi_a2j_glow = QColor(166, 133, 133)
self.line_midi_alsa = QColor(93, 141, 46)
self.line_midi_alsa_sel = QColor(93 + 90, 141 + 90, 46 + 90)
self.line_midi_alsa_glow = QColor(100, 200, 100)

self.rubberband_pen = QPen(QColor(206, 207, 208), 1, Qt.SolidLine)
self.rubberband_brush = QColor(76, 77, 78, 100)

elif idx == self.THEME_CLASSIC_DARK:
# Canvas
self.canvas_bg = QColor(0, 0, 0)

# Boxes
self.box_pen = QPen(QColor(147 - 70, 151 - 70, 143 - 70), 2, Qt.SolidLine)
self.box_pen_sel = QPen(QColor(147, 151, 143), 2, Qt.DashLine)
self.box_bg_1 = QColor(30, 34, 36)
self.box_bg_2 = QColor(30, 34, 36)
self.box_shadow = QColor(89, 89, 89, 180)
self.box_header_pixmap = None
self.box_header_height = 19
self.box_header_spacing = 0

self.box_text = QPen(QColor(255, 255, 255), 0)
self.box_text_sel = self.box_text
self.box_text_ypos = 12
self.box_font_name = "Sans"
self.box_font_size = 9
self.box_font_state = QFont.Normal

self.box_bg_type = self.THEME_BG_GRADIENT
self.box_use_icon = False

# Ports
self.port_text = QPen(QColor(250, 250, 250), 0)
self.port_text_ypos = 11
self.port_bg_pixmap = None
self.port_font_name = "Sans"
self.port_font_size = 8
self.port_font_state = QFont.Normal
self.port_mode = self.THEME_PORT_SQUARE

self.port_audio_jack_pen = QPen(QColor(35, 61, 99), 0)
self.port_audio_jack_pen_sel = QPen(QColor(255, 0, 0), 0)
self.port_midi_jack_pen = QPen(QColor(120, 15, 16), 0)
self.port_midi_jack_pen_sel = QPen(QColor(255, 0, 0), 0)
self.port_midi_a2j_pen = QPen(QColor(101, 47, 17), 0)
self.port_midi_a2j_pen_sel = QPen(QColor(255, 0, 0), 0)
self.port_midi_alsa_pen = QPen(QColor(63, 112, 19), 0)
self.port_midi_alsa_pen_sel = QPen(QColor(255, 0, 0), 0)

self.port_audio_jack_bg = QColor(35, 61, 99)
self.port_audio_jack_bg_sel = QColor(255, 0, 0)
self.port_midi_jack_bg = QColor(120, 15, 16)
self.port_midi_jack_bg_sel = QColor(255, 0, 0)
self.port_midi_a2j_bg = QColor(101, 47, 17)
self.port_midi_a2j_bg_sel = QColor(255, 0, 0)
self.port_midi_alsa_bg = QColor(63, 112, 19)
self.port_midi_alsa_bg_sel = QColor(255, 0, 0)

self.port_audio_jack_text = self.port_text
self.port_audio_jack_text_sel = self.port_text
self.port_midi_jack_text = self.port_text
self.port_midi_jack_text_sel = self.port_text
self.port_midi_a2j_text = self.port_text
self.port_midi_a2j_text_sel = self.port_text
self.port_midi_alsa_text = self.port_text
self.port_midi_alsa_text_sel = self.port_text

self.port_height = 14
self.port_offset = -1
self.port_spacing = 1
self.port_spacingT = 0

# Lines
self.line_audio_jack = QColor(53, 78, 116)
self.line_audio_jack_sel = QColor(255, 0, 0)
self.line_audio_jack_glow = QColor(255, 0, 0)
self.line_midi_jack = QColor(139, 32, 32)
self.line_midi_jack_sel = QColor(255, 0, 0)
self.line_midi_jack_glow = QColor(255, 0, 0)
self.line_midi_a2j = QColor(120, 65, 33)
self.line_midi_a2j_sel = QColor(255, 0, 0)
self.line_midi_a2j_glow = QColor(255, 0, 0)
self.line_midi_alsa = QColor(81, 130, 36)
self.line_midi_alsa_sel = QColor(255, 0, 0)
self.line_midi_alsa_glow = QColor(255, 0, 0)

self.rubberband_pen = QPen(QColor(147, 151, 143), 2, Qt.SolidLine)
self.rubberband_brush = QColor(35, 61, 99, 100)

elif idx == self.THEME_OOSTUDIO:
# Canvas
self.canvas_bg = QColor(11, 11, 11)

# Boxes
self.box_pen = QPen(QColor(76, 77, 78), 1, Qt.SolidLine)
self.box_pen_sel = QPen(QColor(189, 122, 214), 1, Qt.DashLine)
self.box_bg_1 = QColor(46, 46, 46)
self.box_bg_2 = QColor(23, 23, 23)
self.box_shadow = QColor(89, 89, 89, 180)
self.box_header_pixmap = QPixmap(":/bitmaps/canvas/frame_node_header.png")
self.box_header_height = 22
self.box_header_spacing = 6

self.box_text = QPen(QColor(144, 144, 144), 0)
self.box_text_sel = QPen(QColor(189, 122, 214), 0)
self.box_text_ypos = 16
self.box_font_name = "Deja Vu Sans"
self.box_font_size = 8
self.box_font_state = QFont.Bold

self.box_bg_type = self.THEME_BG_SOLID
self.box_use_icon = False

# Ports
normalPortBG = QColor(46, 46, 46)
selPortBG = QColor(23, 23, 23)

self.port_text = QPen(QColor(155, 155, 155), 0)
self.port_text_ypos = 14
self.port_bg_pixmap = QPixmap(":/bitmaps/canvas/frame_port_bg.png")
self.port_font_name = "Deja Vu Sans"
self.port_font_size = 8
self.port_font_state = QFont.Normal
self.port_mode = self.THEME_PORT_SQUARE

self.port_audio_jack_pen = QPen(selPortBG, 2)
self.port_audio_jack_pen_sel = QPen(QColor(1, 230, 238), 1)
self.port_midi_jack_pen = QPen(selPortBG, 2)
self.port_midi_jack_pen_sel = QPen(QColor(252, 118, 118), 1)
self.port_midi_a2j_pen = QPen(selPortBG, 2)
self.port_midi_a2j_pen_sel = QPen(QColor(137, 76, 43), 1)
self.port_midi_alsa_pen = QPen(selPortBG, 2)
self.port_midi_alsa_pen_sel = QPen(QColor(129, 244, 118), 0)

self.port_audio_jack_bg = normalPortBG
self.port_audio_jack_bg_sel = selPortBG
self.port_midi_jack_bg = normalPortBG
self.port_midi_jack_bg_sel = selPortBG
self.port_midi_a2j_bg = normalPortBG
self.port_midi_a2j_bg_sel = selPortBG
self.port_midi_alsa_bg = normalPortBG
self.port_midi_alsa_bg_sel = selPortBG

self.port_audio_jack_text = self.port_text
self.port_audio_jack_text_sel = self.port_audio_jack_pen_sel
self.port_midi_jack_text = self.port_text
self.port_midi_jack_text_sel = self.port_midi_jack_pen_sel
self.port_midi_a2j_text = self.port_text
self.port_midi_a2j_text_sel = self.port_midi_a2j_pen_sel
self.port_midi_alsa_text = self.port_text
self.port_midi_alsa_text_sel = self.port_midi_alsa_pen_sel

# missing, ports 2
self.port_height = 19
self.port_offset = 1
self.port_spacing = 5
self.port_spacingT = 0

# Lines
self.line_audio_jack = QColor(64, 64, 64)
self.line_audio_jack_sel = QColor(1, 230, 238)
self.line_audio_jack_glow = QColor(100, 200, 100)
self.line_midi_jack = QColor(64, 64, 64)
self.line_midi_jack_sel = QColor(252, 118, 118)
self.line_midi_jack_glow = QColor(200, 100, 100)
self.line_midi_a2j = QColor(64, 64, 64)
self.line_midi_a2j_sel = QColor(137+90, 76+90, 43+90)
self.line_midi_a2j_glow = QColor(166, 133, 133)
self.line_midi_alsa = QColor(64, 64, 64)
self.line_midi_alsa_sel = QColor(129, 244, 118)
self.line_midi_alsa_glow = QColor(100, 200, 100)

self.rubberband_pen = QPen(QColor(1, 230, 238), 2, Qt.SolidLine)
self.rubberband_brush = QColor(90, 90, 90, 100)

def getDefaultTheme():
return Theme.THEME_MODERN_DARK

def getThemeName(idx):
if idx == Theme.THEME_MODERN_DARK:
return "Modern Dark"
elif idx == Theme.THEME_MODERN_DARK_TINY:
return "Modern Dark (Tiny)"
elif idx == Theme.THEME_MODERN_LIGHT:
return "Modern Light"
elif idx == Theme.THEME_CLASSIC_DARK:
return "Classic Dark"
elif idx == Theme.THEME_OOSTUDIO:
return "OpenOctave Studio"
else:
return ""

def getDefaultThemeName():
return "Modern Dark"

+ 178
- 0
source/widgets/canvaspreviewframe.py View File

@@ -0,0 +1,178 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Custom Mini Canvas Preview, a custom Qt4 widget
# Copyright (C) 2011-2013 Filipe Coelho <falktx@falktx.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# For a full copy of the GNU General Public License see the COPYING file

# ------------------------------------------------------------------------------------------------------------
# Imports (Global)

from PyQt4.QtCore import Qt, QRectF, QTimer, SIGNAL, SLOT
from PyQt4.QtGui import QBrush, QColor, QCursor, QFrame, QPainter, QPen

# ------------------------------------------------------------------------------------------------------------
# Static Variables

iX = 0
iY = 1
iWidth = 2
iHeight = 3

# ------------------------------------------------------------------------------------------------------------
# Widget Class

class CanvasPreviewFrame(QFrame):
def __init__(self, parent):
QFrame.__init__(self, parent)

self.fMouseDown = False

self.fViewBrush = QBrush(QColor(75, 75, 255, 30))
self.fViewPen = QPen(Qt.blue, 1)

self.fScale = 1.0
self.fScene = None
self.fRealParent = None
self.fFakeWidth = 0
self.fFakeHeight = 0

self.fRenderSource = self.getRenderSource()
self.fRenderTarget = QRectF(0, 0, 0, 0)

self.fViewPadX = 0.0
self.fViewPadY = 0.0
self.fViewRect = [0.0, 0.0, 10.0, 10.0]

def init(self, scene, realWidth, realHeight):
padding = 6

self.fScene = scene
self.fFakeWidth = float(realWidth) / 15
self.fFakeHeight = float(realHeight) / 15

self.setMinimumSize(self.fFakeWidth+padding, self.fFakeHeight+padding)
self.setMaximumSize(self.fFakeWidth*4+padding, self.fFakeHeight+padding)

self.fRenderTarget.setWidth(realWidth)
self.fRenderTarget.setHeight(realHeight)

def setRealParent(self, parent):
self.fRealParent = parent

def getRenderSource(self):
xPadding = (self.width() - self.fFakeWidth) / 2
yPadding = (self.height() - self.fFakeHeight) / 2
return QRectF(xPadding, yPadding, self.fFakeWidth, self.fFakeHeight)

def setViewPosX(self, xp):
x = xp * self.fFakeWidth
xRatio = (x / self.fFakeWidth) * self.fViewRect[iWidth] / self.fScale
self.fViewRect[iX] = x - xRatio + self.fRenderSource.x()
self.update()

def setViewPosY(self, yp):
y = yp * self.fFakeHeight
yRatio = (y / self.fFakeHeight) * self.fViewRect[iHeight] / self.fScale
self.fViewRect[iY] = y - yRatio + self.fRenderSource.y()
self.update()

def setViewScale(self, scale):
self.fScale = scale
QTimer.singleShot(0, self.fRealParent, SLOT("slot_miniCanvasCheckAll()"))

def setViewSize(self, width, height):
self.fViewRect[iWidth] = width * self.fFakeWidth
self.fViewRect[iHeight] = height * self.fFakeHeight
self.update()

def setViewTheme(self, brushColor, penColor):
brushColor.setAlpha(40)
penColor.setAlpha(100)
self.fViewBrush = QBrush(brushColor)
self.fViewPen = QPen(penColor, 1)

def handleMouseEvent(self, event_x, event_y):
x = float(event_x) - self.fRenderSource.x() - (self.fViewRect[iWidth] / self.fScale / 2)
y = float(event_y) - self.fRenderSource.y() - (self.fViewRect[iHeight] / self.fScale / 2)

maxWidth = self.fViewRect[iWidth] / self.fScale
maxHeight = self.fViewRect[iHeight] / self.fScale

if maxWidth > self.fFakeWidth:
maxWidth = self.fFakeWidth
if maxHeight > self.fFakeHeight:
maxHeight = self.fFakeHeight

if x < 0.0:
x = 0.0
elif x > self.fFakeWidth - maxWidth:
x = self.fFakeWidth - maxWidth

if y < 0.0:
y = 0.0
elif y > self.fFakeHeight - maxHeight:
y = self.fFakeHeight - maxHeight

self.fViewRect[iX] = x + self.fRenderSource.x()
self.fViewRect[iY] = y + self.fRenderSource.y()
self.update()

self.emit(SIGNAL("miniCanvasMoved(double, double)"), x * self.fScale / self.fFakeWidth, y * self.fScale / self.fFakeHeight)

def mousePressEvent(self, event):
if event.button() == Qt.LeftButton:
self.fMouseDown = True
self.setCursor(QCursor(Qt.SizeAllCursor))
self.handleMouseEvent(event.x(), event.y())
event.accept()

def mouseMoveEvent(self, event):
if self.fMouseDown:
self.handleMouseEvent(event.x(), event.y())
event.accept()

def mouseReleaseEvent(self, event):
if self.fMouseDown:
self.setCursor(QCursor(Qt.ArrowCursor))
self.fMouseDown = False
QFrame.mouseReleaseEvent(self, event)

def paintEvent(self, event):
painter = QPainter(self)

painter.setBrush(QBrush(Qt.darkBlue, Qt.DiagCrossPattern))
painter.drawRect(0, 0, self.width(), self.height())

self.fScene.render(painter, self.fRenderSource, self.fRenderTarget, Qt.KeepAspectRatio)

maxWidth = self.fViewRect[iWidth] / self.fScale
maxHeight = self.fViewRect[iHeight] / self.fScale

if maxWidth > self.fFakeWidth:
maxWidth = self.fFakeWidth
if maxHeight > self.fFakeHeight:
maxHeight = self.fFakeHeight

painter.setBrush(self.fViewBrush)
painter.setPen(self.fViewPen)
painter.drawRect(self.fViewRect[iX], self.fViewRect[iY], maxWidth, maxHeight)

QFrame.paintEvent(self, event)

def resizeEvent(self, event):
self.fRenderSource = self.getRenderSource()
if self.fRealParent:
QTimer.singleShot(0, self.fRealParent, SLOT("slot_miniCanvasCheckAll()"))
QFrame.resizeEvent(self, event)

Loading…
Cancel
Save