diff --git a/qt/aqt/forms/__init__.py b/qt/aqt/forms/__init__.py index cfae51e1c..424a1f314 100644 --- a/qt/aqt/forms/__init__.py +++ b/qt/aqt/forms/__init__.py @@ -42,4 +42,5 @@ from . import ( synclog, taglimit, template, + widgets, ) diff --git a/qt/aqt/forms/widgets.py b/qt/aqt/forms/widgets.py new file mode 100644 index 000000000..b2542fc8b --- /dev/null +++ b/qt/aqt/forms/widgets.py @@ -0,0 +1,6 @@ +from aqt.qt import qtmajor + +if qtmajor > 5: + from _aqt.forms.widgets_qt6 import * +else: + from _aqt.forms.widgets_qt5 import * # type: ignore diff --git a/qt/aqt/forms/widgets.ui b/qt/aqt/forms/widgets.ui new file mode 100644 index 000000000..491583083 --- /dev/null +++ b/qt/aqt/forms/widgets.ui @@ -0,0 +1,385 @@ + + + Dialog + + + + 0 + 0 + 925 + 822 + + + + Qt Widget Gallery + + + + + + + + Style + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + + + + Force Style + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Disable Widgets + + + + + + + + + + + + Check Buttons + + + + + + RadioButton (not checkable) + + + false + + + + + + + RadioButton (checked) + + + true + + + + + + + RadioButton (unchecked) + + + + + + + CheckBox (tristate) + + + true + + + true + + + + + + + + + + Buttons + + + + + + PushButton + + + + + + + PushButton (checkable) + + + true + + + true + + + + + + + PushButton (flat) + + + true + + + true + + + + + + + + + + CalendarWidget + + + + + + + + + + + + Text Inputs + + + + + + true + + + ComboBox (editable) + + + + + + + + + + + + + LineEdit + + + + + + + Qt::Horizontal + + + + + + + PlainTextEdit + + + + + + + + TextEdit + + + + + + + + + + + Other Inputs + + + + + + + + + + + + + + + + + + + 1 + + + + + + + KeySequenceEdit + + + + + + + DateTimeEdit + + + + + + + SpinBox + + + + + + + + + Slider + + + + + + + Qt::Horizontal + + + + + + + Dial + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + + + + + + + + 0 + + + + ListWidget + + + + + + + + + + TreeWidget + + + + + + + 1 + + + + + + + + + TableWidget + + + + + + 0 + + + 0 + + + + + + + + + + + + + ProgressBar + + + + + + + 24 + + + + + + + + + + + + + diff --git a/qt/aqt/widgetgallery.py b/qt/aqt/widgetgallery.py new file mode 100644 index 000000000..840db84b9 --- /dev/null +++ b/qt/aqt/widgetgallery.py @@ -0,0 +1,51 @@ +# Copyright: Ankitects Pty Ltd and contributors +# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html + +import aqt +import aqt.main +from aqt.qt import QDialog, qconnect +from aqt.theme import AnkiStyles +from aqt.utils import is_mac, restoreGeom, saveGeom + + +class WidgetGallery(QDialog): + silentlyClose = True + + def __init__(self, mw: aqt.main.AnkiQt) -> None: + super().__init__(mw) + self.mw = mw.weakref() + + self.form = aqt.forms.widgets.Ui_Dialog() + self.form.setupUi(self) + restoreGeom(self, "WidgetGallery") + + qconnect( + self.form.disableCheckBox.stateChanged, + lambda: self.form.testGrid.setEnabled( + not self.form.disableCheckBox.isChecked() + ), + ) + + self.form.styleComboBox.addItems( + [member.name.lower().capitalize() for member in AnkiStyles] + ) + self.form.styleComboBox.setCurrentIndex( + 1 + if self.mw.pm.force_fusion_styles() + else 2 + if self.mw.pm.force_native_styles() or is_mac + else 0 + ) + self.form.forceCheckBox.setChecked(self.mw.pm.has_forced_style()) + + qconnect( + self.form.styleComboBox.currentIndexChanged, + self.mw.pm.set_forced_style, + ) + + def reject(self) -> None: + super().reject() + if not self.form.forceCheckBox.isChecked(): + self.mw.pm.unset_forced_styles() + + saveGeom(self, "WidgetGallery")