4 # Copyright (C) 2010 Stefanos Harhalakis
6 # This file is part of maegirls.
8 # maegirls is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # maegirls is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with maegirls. If not, see <http://www.gnu.org/licenses/>.
21 # $Id: 0.py 2265 2010-02-21 19:16:26Z v13 $
23 __version__ = "$Id: 0.py 2265 2010-02-21 19:16:26Z v13 $"
25 from PyQt4.QtGui import *
26 from PyQt4.QtCore import *
32 class DaysGraph(QWidget):
33 def __init__(self, algo_, *args, **kwargs):
34 QWidget.__init__(self, *args, **kwargs)
41 self.first_day=algo.today()
46 def setAlgo(self, algo_):
50 self.first_day=algo.today()
53 def paintEvent(self, event):
59 days=int(w0/self.day_width)
60 days=int((days)/2)*2 + 3
63 # Now calculate the x0
66 painter=QPainter(self)
68 # This makes it sloooooooooooow
69 # painter.setRenderHints(painter.Antialiasing \
70 # | painter.TextAntialiasing \
71 # | painter.HighQualityAntialiasing
75 colol=QColor(0x66,0x66,0x66)
78 # outline of the small block
80 penblockol=QPen(colblockol)
84 pencur=QPen(colcur, 3)
92 fontdate.setPointSizeF(fontdate.pointSizeF()*0.5)
93 fontdate_m=QFontMetrics(fontdate)
95 # Last bounding rectagle of the text
96 last_br=QRect(0,0,4,4)
100 for d in xrange(days):
101 # This will cause the first_day to be at the center
102 curday=self.first_day+d - int(days/2)
103 x=x0+d*self.day_width
108 st=self.algo.status(curday)
110 if st['status']=='ok':
111 colbg=QColor(gray, gray, gray)
114 painter.setPen(penol)
115 painter.fillRect(x, y, self.day_width-1, h2-1, brbg)
116 elif st['status']=='red' or \
117 st['status']=='blue' or \
118 st['status']=='green':
119 if st['status']=='red':
120 perc=1.0*st['day'] / (st['len'])
122 0xff - int((0xff - gray - gray) * perc),
126 elif st['status']=='blue':
127 perc=1.0*(st['day']+1) / (st['len'])
131 gray + ((0xff-gray) * perc))
133 elif st['status']=='green':
134 perc=1.0*(st['day']+1) / (st['len'])
137 gray + ((0xff-gray) * perc),
141 painter.fillRect(x, y, self.day_width-1, h2-1, brbg)
143 # Show a nice small box for interesting days
147 # Ensure that boxw is sane - e.g. not larger than
148 # the current day_width
149 boxw2=self.day_width-10
150 boxw=min(boxw, boxw2)
152 x1=x+int((self.day_width-boxw)/2)
154 if st['status']=='red':
155 y1=y + int(perc * h2*2/3) + 20
156 elif st['status']=='blue' or st['status']=='green':
157 y1=y + int(h2*2/3) - int(perc * h2*2/3) + 20
159 brbg=QBrush(colblock)
160 painter.fillRect(x1, y1, boxw, boxh, brbg)
161 painter.setPen(colblockol)
162 painter.drawRect(x1, y1, boxw, boxh)
164 painter.setPen(colol)
165 painter.drawRect(x, y, self.day_width, h2-1)
169 painter.setPen(pencur)
170 painter.drawRect(x+2,y+2,self.day_width-4, h2-5)
172 date=time.localtime(curday*86400+30000)
176 txt="%d.%02d\n%d" % (date.tm_mday, date.tm_mon, date.tm_year)
178 # br is used to determine overlaps
179 br=fontdate_m.boundingRect(txt)
183 while colnum*self.day_width < br.width():
186 # If this intersects with the previous day then it is ok
187 if br.intersects(last_br):
191 # br2 is the true bounding rectangle
192 # The width calculation helps with alignment
193 br2=QRect(x-((colnum-1)/2 * self.day_width), y2,
194 self.day_width*colnum, fontdate_m.height()*2)
197 painter.setFont(fontdate)
198 painter.setPen(pentxt)
199 painter.drawText(br2, Qt.AlignCenter | Qt.AlignTop, txt)
201 # Handle both horizontal and vertical movement
202 def mouseMoveEvent(self, event):
209 if self.last_x==None:
213 # Vertical movement - that much pixels account for one zoom
216 # First look horizontal movement
217 # If there was movement the reset vertical movement
220 days=int(dx/self.day_width)
222 days=-int(abs(dx)/self.day_width)
226 self.last_x+=(days*self.day_width)
227 self.last_y=y # Reset vertical movement
230 # Now look for vertical movement
235 zoom=-int(abs(dy)/y_step)
238 t=self.day_width+zoom
239 if t<self.min_day_width:
241 elif t>self.max_day_width:
243 #self.day_width-=zoom
246 self.last_y+=zoom*y_step
247 self.last_x=x # Reset horizontal movement
253 def mousePressEvent(self, event):
259 return(QSize(100,50))
261 # vim: set ts=8 sts=4 sw=4 noet formatoptions=r ai nocindent: