예제 #1
0
    def datetimeAt(self, x):
        """
        Returns the datetime at the inputed x position.
        
        :return     <QDateTime>
        """
        gantt = self.ganttWidget()
        dstart = gantt.dateTimeStart()
        distance = int(x / float(gantt.cellWidth()))
        
        # calculate the time for a minute
        if scale == gantt.Timescale.Minute:
            return dstart.addSecs(distance)
        
        # calculate the time for an hour
        elif scale == gantt.Timescale.Hour:
            return dstart.addSecs(distance * 2.0)

        # calculate the time for a day
        elif scale == gantt.Timescale.Day:
            dstart = QDateTime(gantt.dateStart(), QTime(0, 0, 0))
            return dstart.addSecs(distance * (60 * 2.0))
        
        # calculate the time off the date only
        else:
            date = self.dateAt(x)
            return QDateTime(date, QTime(0, 0, 0))
예제 #2
0
 def rebuildDay(self, opt):
     """
     Rebuilds the scale for the day mode.
     
     :param      opt | <XGanttRenderOptions>
     """
     self._labels            = []
     self._hlines            = []
     self._vlines            = []
     self._weekendRects      = []
     self._alternateRects    = []
     self._topLabels         = []
     
     top_format = 'dddd MMMM dd'
     label_format = 'ha'
     increment = 60 # hour
     
     # generate vertical lines
     x           = 0
     i           = 0
     half        = opt.header_height / 2.0
     curr        = QDateTime(opt.start, QTime(0, 0, 0))
     end         = QDateTime(opt.end, QTime(23, 0, 0))
     top_label   = opt.start.toString(top_format)
     top_rect    = QRect(0, 0, 0, half)
     alt_rect    = None
     
     while curr <= end:
         # update the top rect
         new_top_label = curr.toString(top_format)
         if new_top_label != top_label:
             top_rect.setRight(x)
             self._topLabels.append((top_rect, top_label))
             top_rect  = QRect(x, 0, 0, half)
             top_label = new_top_label
             
             if alt_rect is not None:
                 alt_rect.setRight(x)
                 self._alternateRects.append(alt_rect)
                 alt_rect = None
             else:
                 alt_rect = QRect(x, 0, 0, opt.height)
         
         # create the line
         self._hlines.append(QLine(x, 0, x, opt.height))
         
         # create the header label/rect
         label = nativestring(curr.toString(label_format))[:-1]
         rect  = QRect(x, half, opt.cell_width, half)
         self._labels.append((rect, label))
         
         # increment the dates
         curr = curr.addSecs(increment * 60)
         x += opt.cell_width
         i += 1
     
     # update the top rect
     top_rect.setRight(x)
     top_label = opt.end.toString(top_format)
     self._topLabels.append((top_rect, top_label))
     
     if alt_rect is not None:
         alt_rect.setRight(x)
         self._alternateRects.append(alt_rect)
     
     # resize the width to match the last date range
     new_width = x
     self.setSceneRect(0, 0, new_width, opt.height)
     
     # generate horizontal lines
     y       = 0
     h       = opt.height
     width   = new_width
     
     while y < h:
         self._vlines.append(QLine(0, y, width, y))
         y += opt.cell_height
     
     # clear the dirty flag
     self._dirty = False