mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
When editing dates such as published, allow pressing the minus key to clear the date and the = key to set the date to today. Fixes #1181449 ([enhance] Now & Clear for Date Cells)
This commit is contained in:
parent
fa227be4dd
commit
861d1ff53e
@ -9,7 +9,7 @@ import sys
|
||||
|
||||
from PyQt4.Qt import (Qt, QApplication, QStyle, QIcon, QDoubleSpinBox,
|
||||
QVariant, QSpinBox, QStyledItemDelegate, QComboBox, QTextDocument,
|
||||
QAbstractTextDocumentLayout, QFont, QFontInfo, QDate)
|
||||
QAbstractTextDocumentLayout, QFont, QFontInfo, QDate, QDateTimeEdit, QDateTime)
|
||||
|
||||
from calibre.gui2 import UNDEFINED_QDATETIME, error_dialog, rating_font
|
||||
from calibre.constants import iswindows
|
||||
@ -23,6 +23,26 @@ from calibre.gui2.dialogs.comments_dialog import CommentsDialog
|
||||
from calibre.gui2.dialogs.template_dialog import TemplateDialog
|
||||
from calibre.gui2.languages import LanguagesEdit
|
||||
|
||||
class DateTimeEdit(QDateTimeEdit): # {{{
|
||||
|
||||
def __init__(self, parent, format):
|
||||
QDateTimeEdit.__init__(self, parent)
|
||||
self.setFrame(False)
|
||||
self.setMinimumDateTime(UNDEFINED_QDATETIME)
|
||||
self.setSpecialValueText(_('Undefined'))
|
||||
self.setCalendarPopup(True)
|
||||
self.setDisplayFormat(format)
|
||||
|
||||
def keyPressEvent(self, ev):
|
||||
if ev.key() == Qt.Key_Minus:
|
||||
ev.accept()
|
||||
self.setDateTime(self.minimumDateTime())
|
||||
elif ev.key() == Qt.Key_Equal:
|
||||
ev.accept()
|
||||
self.setDateTime(QDateTime.currentDateTime())
|
||||
else:
|
||||
return QDateTimeEdit.keyPressEvent(self, ev)
|
||||
# }}}
|
||||
|
||||
class RatingDelegate(QStyledItemDelegate): # {{{
|
||||
|
||||
@ -77,12 +97,7 @@ class DateDelegate(QStyledItemDelegate): # {{{
|
||||
return format_date(qt_to_dt(d, as_utc=False), self.format)
|
||||
|
||||
def createEditor(self, parent, option, index):
|
||||
qde = QStyledItemDelegate.createEditor(self, parent, option, index)
|
||||
qde.setDisplayFormat(self.format)
|
||||
qde.setMinimumDateTime(UNDEFINED_QDATETIME)
|
||||
qde.setSpecialValueText(_('Undefined'))
|
||||
qde.setCalendarPopup(True)
|
||||
return qde
|
||||
return DateTimeEdit(parent, self.format)
|
||||
|
||||
# }}}
|
||||
|
||||
@ -101,12 +116,7 @@ class PubDateDelegate(QStyledItemDelegate): # {{{
|
||||
return format_date(qt_to_dt(d, as_utc=False), self.format)
|
||||
|
||||
def createEditor(self, parent, option, index):
|
||||
qde = QStyledItemDelegate.createEditor(self, parent, option, index)
|
||||
qde.setDisplayFormat(self.format)
|
||||
qde.setMinimumDateTime(UNDEFINED_QDATETIME)
|
||||
qde.setSpecialValueText(_('Undefined'))
|
||||
qde.setCalendarPopup(True)
|
||||
return qde
|
||||
return DateTimeEdit(parent, self.format)
|
||||
|
||||
def setEditorData(self, editor, index):
|
||||
val = index.data(Qt.EditRole).toDate()
|
||||
@ -230,12 +240,7 @@ class CcDateDelegate(QStyledItemDelegate): # {{{
|
||||
return format_date(qt_to_dt(d, as_utc=False), self.format)
|
||||
|
||||
def createEditor(self, parent, option, index):
|
||||
qde = QStyledItemDelegate.createEditor(self, parent, option, index)
|
||||
qde.setDisplayFormat(self.format)
|
||||
qde.setMinimumDateTime(UNDEFINED_QDATETIME)
|
||||
qde.setSpecialValueText(_('Undefined'))
|
||||
qde.setCalendarPopup(True)
|
||||
return qde
|
||||
return DateTimeEdit(parent, self.format)
|
||||
|
||||
def setEditorData(self, editor, index):
|
||||
m = index.model()
|
||||
|
@ -13,7 +13,7 @@ from PyQt4.Qt import (Qt, QDateTimeEdit, pyqtSignal, QMessageBox, QIcon,
|
||||
QToolButton, QWidget, QLabel, QGridLayout, QApplication,
|
||||
QDoubleSpinBox, QListWidgetItem, QSize, QPixmap, QDialog, QMenu,
|
||||
QPushButton, QSpinBox, QLineEdit, QSizePolicy, QDialogButtonBox,
|
||||
QAction, QCalendarWidget, QDate)
|
||||
QAction, QCalendarWidget, QDate, QDateTime)
|
||||
|
||||
from calibre.gui2.widgets import EnLineEdit, FormatList as _FormatList, ImageView
|
||||
from calibre.utils.icu import sort_key
|
||||
@ -1472,6 +1472,16 @@ class DateEdit(QDateTimeEdit):
|
||||
o, c = self.original_val, self.current_val
|
||||
return o != c
|
||||
|
||||
def keyPressEvent(self, ev):
|
||||
if ev.key() == Qt.Key_Minus:
|
||||
ev.accept()
|
||||
self.setDateTime(self.minimumDateTime())
|
||||
elif ev.key() == Qt.Key_Equal:
|
||||
ev.accept()
|
||||
self.setDateTime(QDateTime.currentDateTime())
|
||||
else:
|
||||
return QDateTimeEdit.keyPressEvent(self, ev)
|
||||
|
||||
class PubdateEdit(DateEdit):
|
||||
LABEL = _('Publishe&d:')
|
||||
FMT = 'MMM yyyy'
|
||||
|
Loading…
x
Reference in New Issue
Block a user