More progress on worklog

This commit is contained in:
Fabian 2021-11-26 23:41:13 +01:00
parent 1ee3471e4c
commit 35a884ea1e

View File

@ -11,14 +11,43 @@ import fime.icons
class Worklog(QtWidgets.QDialog):
class TabTable(QtWidgets.QTableWidget):
def __init__(self, parent, *args, **kwargs):
super().__init__(parent, *args, **kwargs)
def focusNextPrevChild(self, next):
if self.currentColumn() == 1:
event = QtGui.QKeyEvent(QtCore.QEvent.KeyPress,
QtCore.Qt.Key_Down if next else QtCore.Qt.Key_Up,
QtCore.Qt.NoModifier)
self.keyPressEvent(event)
if event.isAccepted():
return True
return super().focusNextPrevChild(next)
class ClickWidget(QtWidgets.QWidget):
def __init__(self, item, table, parent, *args, **kwargs):
super().__init__(parent, *args, **kwargs)
self.item = item
self.table = table
def mouseDoubleClickEvent(self, event):
self.table.removeCellWidget(self.item.row(), self.item.column())
self.table.openPersistentEditor(self.item)
editor = self.table.cellWidget(self.table.currentRow(), self.table.currentColumn())
editor.setFocus()
def __init__(self, parent, *args, **kwargs):
super().__init__(parent, *args, **kwargs)
self.setWindowTitle("Worklog")
self.tableWidget = QtWidgets.QTableWidget()
self._changing_items = False
self.tableWidget = Worklog.TabTable(self)
self.tableWidget.setColumnCount(3)
self.tableWidget.setHorizontalHeaderLabels(["Task", "Comment", "Duration"])
self.tableWidget.cellChanged.connect(self.cell_changed)
self.hheader = QtWidgets.QHeaderView(QtCore.Qt.Orientation.Horizontal)
self.hheader.setMinimumSectionSize(1)
self.hheader.setSectionResizeMode(QtWidgets.QHeaderView.ResizeToContents)
@ -35,7 +64,7 @@ class Worklog(QtWidgets.QDialog):
self.refresh_table()
class TableTextEdit(QtWidgets.QTextEdit):
def __init__(self, text, start_height, parent, *args, **kwargs):
def __init__(self, text, parent, *args, **kwargs):
super().__init__(parent, *args, **kwargs)
self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
self.setLineWrapMode(QtWidgets.QTextEdit.WidgetWidth)
@ -52,6 +81,7 @@ class Worklog(QtWidgets.QDialog):
self.setFixedHeight(self.document().size().toSize().height())
def refresh_table(self):
self._changing_items = True
self._report_data = [
["ASG-8690 Ansible - Debian 11 Support", "Impl\nMore impl", "01:23"],
["ASG-8342 Ansible - MariaDB Rolle überarbeiten ", "Test", "03:57"],
@ -61,45 +91,39 @@ class Worklog(QtWidgets.QDialog):
for row, _ in enumerate(self._report_data):
item0 = QtWidgets.QTableWidgetItem(self._report_data[row][0])
item0.setToolTip("something has gone wrong")
self.tableWidget.setItem(row, 0, item0)
size = self.tableWidget.rowHeight(row)
if row == 1:
qpi = ProgressIndicator(self)
qpi.setMaximumSize(QtCore.QSize(size * 0.75, size * 0.75))
qpi.setAnimationDelay(70)
qpi.startAnimation()
layout = QtWidgets.QVBoxLayout()
layout.addWidget(qpi, alignment=QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
layout.setContentsMargins(size * 0.1, size * 0.1, size * 0.1, size * 0.1)
wdgt = QtWidgets.QWidget()
wdgt.setLayout(layout)
#label.setAlignment(Qt.AlignRight | Qt.AlignVCenter)
#label.setMargin(size * 0.1)
label = wdgt
icon = ProgressIndicator(self)
icon.setMaximumSize(QtCore.QSize(size * 0.75, size * 0.75))
icon.setAnimationDelay(70)
icon.startAnimation()
else:
label = QtWidgets.QLabel()
if row == 0:
item_name = "dialog-ok"
elif row == 2:
item_name = "edit-delete-remove"
label.setPixmap(QtGui.QIcon.fromTheme(item_name).pixmap(size * 0.75, size * 0.75))
label.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
label.setMargin(size*0.1)
self.tableWidget.setCellWidget(row, 0, label)
icon = QtWidgets.QLabel()
icon.setPixmap(QtGui.QIcon.fromTheme(item_name).pixmap(size * 0.75, size * 0.75))
icon.setToolTip("something has gone wrong")
layout = QtWidgets.QHBoxLayout()
layout.addWidget(icon, alignment=QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
layout.setContentsMargins(size * 0.1, size * 0.1, size * 0.1, size * 0.1)
wdgt = Worklog.ClickWidget(item0, self.tableWidget, self)
wdgt.setLayout(layout)
self.tableWidget.setCellWidget(row, 0, wdgt)
#item1 = QtWidgets.QTableWidgetItem(self._report_data[row][1])
#self.tableWidget.setItem(row, 1, item1)
#print(self.tableWidget.cellWidget(0, 0).height())
text_edit = Worklog.TableTextEdit(self._report_data[row][1],
self.tableWidget.cellWidget(0, 0).height(),
self)
text_edit = Worklog.TableTextEdit(self._report_data[row][1], self)
text_edit.textChanged.connect(self.on_resize)
text_edit.setFrameStyle(QtWidgets.QFrame.NoFrame)
self.tableWidget.setCellWidget(row, 1, text_edit)
if row == 0:
text_edit.setFocus()
item2 = QtWidgets.QTableWidgetItem(self._report_data[row][2])
self.tableWidget.setItem(row, 2, item2)
#item2.setFlags(item2.flags() & QtCore.Qt.ItemIsEnabled)
item2.setFlags(item2.flags() & QtCore.Qt.ItemIsEnabled)
self.tableWidget.resizeColumnToContents(0)
# TODO integrate entered text and max screen width
comment_width = get_screen_width(self) * 0.2
@ -107,6 +131,8 @@ class Worklog(QtWidgets.QDialog):
self.tableWidget.setColumnWidth(0, self.tableWidget.columnWidth(0) * 1.05)
# broken
#self.tableWidget.setTabOrder(self.tableWidget.cellWidget(0, 1), self.tableWidget.cellWidget(1, 1))
QtWidgets.QWidget.setTabOrder(self.tableWidget.cellWidget(0, 1), self.tableWidget.cellWidget(1, 1))
self._changing_items = False
@QtCore.Slot()
def on_resize(self):
@ -119,3 +145,10 @@ class Worklog(QtWidgets.QDialog):
@QtCore.Slot()
def enable_buttons(self):
pass
@QtCore.Slot()
def cell_changed(self, row, column):
if self._changing_items:
return
print(f"cell changed: {row}, {column}")
self.refresh_table()