2
# -*- coding: utf-8 -*-
6
# Copyright (C) 2013 National University of Defense Technology(NUDT) & Kylin Ltd
9
# Shine Huang<shenghuang@ubuntukylin.com>
11
# Shine Huang<shenghuang@ubuntukylin.com>
13
# This program is free software: you can redistribute it and/or modify it
14
# under the terms of the GNU General Public License version 3, as published
15
# by the Free Software Foundation.
17
# This program is distributed in the hope that it will be useful, but
18
# WITHOUT ANY WARRANTY; without even the implied warranties of
19
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
20
# PURPOSE. See the GNU General Public License for more details.
22
# You should have received a copy of the GNU General Public License along
23
# with this program. If not, see <http://www.gnu.org/licenses/>.
26
from PyQt4.QtGui import *
27
from PyQt4.QtCore import *
30
from models.globals import Globals
33
class CardWidget(QWidget):
40
def __init__(self, itemwidth, itemheight, cardspacing, parent=None):
41
QWidget.__init__(self, parent)
43
self.itemwidth = itemwidth
44
self.itemheight = itemheight
45
self.cardspacing = cardspacing
47
self.scrollArea = QScrollArea(self)
48
self.cardPanel = QWidget()
49
self.scrollArea.setWidget(self.cardPanel)
50
self.scrollArea.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
51
self.scrollArea.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
53
self.verticalScrollBar().setStyleSheet("QScrollBar:vertical{margin:0px 0px 0px 0px;background-color:rgb(255,255,255,100);border:0px;width:6px;}\
54
QScrollBar::sub-line:vertical{subcontrol-origin:margin;border:1px solid red;height:13px}\
55
QScrollBar::up-arrow:vertical{subcontrol-origin:margin;background-color:blue;height:13px}\
56
QScrollBar::sub-page:vertical{background-color:#EEEDF0;}\
57
QScrollBar::handle:vertical{background-color:#D1D0D2;width:6px;} QScrollBar::handle:vertical:hover{background-color:#14ACF5;width:6px;} QScrollBar::handle:vertical:pressed{background-color:#0B95D7;width:6px;}\
58
QScrollBar::add-page:vertical{background-color:#EEEDF0;}\
59
QScrollBar::down-arrow:vertical{background-color:yellow;}\
60
QScrollBar::add-line:vertical{subcontrol-origin:margin;border:1px solid green;height:13px}")
62
# calculate card number in one page in current screen resolution
63
def calculate_software_step_num(self):
64
number_per_row = (self.width() + self.cardspacing) / (self.itemwidth + self.cardspacing)
65
number_per_column = (self.height() + self.cardspacing) / (self.itemheight + self.cardspacing)
66
Globals.SOFTWARE_STEP_NUM = number_per_row * number_per_column + number_per_row
67
# print "re calculate SOFTWARE_STEP_NUM == ", Globals.SOFTWARE_STEP_NUM
70
def calculate_data(self):
71
# the 'QScrollArea' inside area is 1px smaller than 'QWidget', fix it.
72
self.scrollArea.setGeometry(-1, -1, self.width() + 2, self.height() + 2)
73
self.cardPanel.setGeometry(0, 0, self.width(), self.height())
75
self.number_per_row = (self.width() + self.cardspacing) / (self.itemwidth + self.cardspacing)
77
def reload_cards(self):
80
cards = self.cardPanel.children()
83
for i in range(self.count()):
84
self.add_card(cards[i])
86
self.cardcount = self.count()
88
def add_card(self, card):
89
x = int(self.cardcount % self.number_per_row) * (self.itemwidth + self.cardspacing)
90
y = int(self.cardcount / self.number_per_row) * (self.itemheight + self.cardspacing)
92
# resize the widget to adapt items
93
nowHeight = y + self.itemheight
94
if(nowHeight >= self.cardPanel.height()):
95
self.cardPanel.resize(self.cardPanel.width(), nowHeight)
98
self.cardcount = self.cardcount + 1
100
def verticalScrollBar(self):
101
return self.scrollArea.verticalScrollBar()
103
def scrollToTop(self):
104
vsb = self.scrollArea.verticalScrollBar()
109
cards = self.cardPanel.children()
114
cards = self.cardPanel.children()
118
self.cardPanel.setGeometry(0, 0, self.width(), self.height())
b'\\ No newline at end of file'