def setTimeEnd( self, timeEnd ): """ Sets the end time for this item. This method will only affect the start time if the end time is set to occur before its start, in which case it will set the start time as 60 minutes before. Otherwise, this method will scale the duration of the event. :param timeEnd | <QTime> """ timeEnd = QTime(timeEnd) if ( timeEnd < self._timeStart ): self._timeStart = timeEnd.addSecs(-60 * 60) self._timeEnd = timeEnd self.markForRebuild()
def setTimeEnd(self, timeEnd): """ Sets the end time for this item. This method will only affect the start time if the end time is set to occur before its start, in which case it will set the start time as 60 minutes before. Otherwise, this method will scale the duration of the event. :param timeEnd | <QTime> """ timeEnd = QTime(timeEnd) if (timeEnd < self._timeStart): self._timeStart = timeEnd.addSecs(-60 * 60) self._timeEnd = timeEnd self.markForRebuild()
def setTimeStart( self, timeStart ): """ Sets the start time for this item. This will automatically push the end time to match the length for this item. So if the item starts at 11a and ends on 1p, and the start time is changed to 12p the end time will change to 2p. To affect the length of the item, use either setLength, or setTimeEnd. :param timeStart | <QDate> """ timeStart = QTime(timeStart) length = self.length() # in minutes self._timeStart = timeStart self._timeEnd = timeStart.addSecs(length * 60) self.markForRebuild()
def setTimeStart(self, timeStart): """ Sets the start time for this item. This will automatically push the end time to match the length for this item. So if the item starts at 11a and ends on 1p, and the start time is changed to 12p the end time will change to 2p. To affect the length of the item, use either setLength, or setTimeEnd. :param timeStart | <QDate> """ timeStart = QTime(timeStart) length = self.length() # in minutes self._timeStart = timeStart self._timeEnd = timeStart.addSecs(length * 60) self.markForRebuild()
def __init__( self ): super(XCalendarItem, self).__init__() curr_dtime = QDateTime.currentDateTime() curr_date = curr_dtime.date() curr_time = curr_dtime.time() self.setFlags(self.flags() | self.ItemIsSelectable) self.setAcceptHoverEvents(True) # round to the nearest 15 minute segment curr_time = QTime(curr_time.hour(), curr_time.minute() - curr_time.minute() % 30, 0) self._rebuildBlocked = False self._textData = [] self._customData = {} self._textColor = QColor('white') self._fillColor = QColor('blue') self._borderColor = QColor('blue') self._highlightColor = QColor('blue') self._title = 'No Title' self._description = '' self._dateStart = curr_date self._dateEnd = curr_date self._timeStart = curr_time self._timeEnd = curr_time.addSecs(60 * 60) self._allDay = True self._rebuildRequired = False if ( QTime(23, 0, 0) <= self._timeStart ): self._timeEnd = QTime(23, 59, 0) self.setColor('blue')
def __init__(self): super(XCalendarItem, self).__init__() curr_dtime = QDateTime.currentDateTime() curr_date = curr_dtime.date() curr_time = curr_dtime.time() self.setFlags(self.flags() | self.ItemIsSelectable) self.setAcceptHoverEvents(True) # round to the nearest 15 minute segment curr_time = QTime(curr_time.hour(), curr_time.minute() - curr_time.minute() % 30, 0) self._rebuildBlocked = False self._textData = [] self._customData = {} self._textColor = QColor('white') self._fillColor = QColor('blue') self._borderColor = QColor('blue') self._highlightColor = QColor('blue') self._title = 'No Title' self._description = '' self._dateStart = curr_date self._dateEnd = curr_date self._timeStart = curr_time self._timeEnd = curr_time.addSecs(60 * 60) self._allDay = True self._rebuildRequired = False if (QTime(23, 0, 0) <= self._timeStart): self._timeEnd = QTime(23, 59, 0) self.setColor('blue')
def rebuildDays( self ): """ Rebuilds the interface as a week display. """ time = QTime(0, 0, 0) hour = True x = 6 y = 6 + 24 w = self.width() - 12 - 25 dh = 48 indent = 58 text_data = [] vlines = [] hlines = [QLine(x, y, w, y)] time_grids = [] for i in range(48): if ( hour ): hlines.append(QLine(x, y, w, y)) text_data.append((x, y + 6, indent - 6, dh, Qt.AlignRight | Qt.AlignTop, time.toString('hap'))) else: hlines.append(QLine(x + indent, y, w, y)) time_grids.append((time, y, dh / 2)) # move onto the next line hour = not hour time = time.addSecs(30 * 60) y += dh / 2 hlines.append(QLine(x, y, w, y)) h = y y = 6 + 24 # load the grid vlines.append(QLine(x, y, x, h)) vlines.append(QLine(x + indent, y, x + indent, h)) vlines.append(QLine(w, y, w, h)) today = QDate.currentDate() curr_date = self.currentDate() # load the days if ( self.currentMode() == XCalendarScene.Mode.Week ): date = self.currentDate() day_of_week = date.dayOfWeek() if ( day_of_week == 7 ): day_of_week = 0 min_date = date.addDays(-day_of_week) max_date = date.addDays(6-day_of_week) self._minimumDate = min_date self._maximumDate = max_date dw = (w - (x + indent)) / 7.0 vx = x + indent date = min_date for i in range(7): vlines.append(QLine(vx, y, vx, h)) text_data.append((vx + 6, 6, dw, 24, Qt.AlignCenter, date.toString('ddd MM/dd'))) self._dateGrid[date.toJulianDay()] = ((0, i), QRectF(vx, y, dw, h - y)) # create the date grid for date time options for r, data in enumerate(time_grids): time, ty, th = data dtime = QDateTime(date, time) key = dtime.toTime_t() self._dateTimeGrid[key] = ((r, i), QRectF(vx, ty, dw, th)) if ( date == curr_date ): self._buildData['curr_date'] = QRectF(vx, y, dw, h - 29) elif ( date == today ): self._buildData['today'] = QRectF(vx, y, dw, h - 29) date = date.addDays(1) vx += dw # load a single day else: date = self.currentDate() self._maximumDate = date self._minimumDate = date text_data.append((x + indent, 6, w, 24, Qt.AlignCenter, date.toString('ddd MM/dd'))) self._dateGrid[date.toJulianDay()] = ((0, 0), QRectF(x, y, w - x, h - y)) # create the date grid for date time options for r, data in enumerate(time_grids): time, ty, th = data dtime = QDateTime(date, time) key = dtime.toTime_t() rect = QRectF(x + indent, ty, w - (x + indent), th) self._dateTimeGrid[key] = ((r, 0), rect) self._buildData['grid'] = hlines + vlines self._buildData['regular_text'] = text_data rect = self.sceneRect() rect.setHeight(h + 6) super(XCalendarScene, self).setSceneRect(rect)