Git commit 5f5848ba2b3a2148aa402fe87d8c41ba1ebdb329 by Thomas Baumgart. Committed on 31/08/2019 at 15:36. Pushed by tbaumgart into branch '5.0'.
Allow to modify the initial section of a date edit by the user This introduces a new option on the data entry tab of the ledger settings page. GUI: BUG: 374123 FIXED-IN: 4.8.1,5.0.7 M +48 -6 kmymoney/dialogs/settings/ksettingsregister.ui M +9 -0 kmymoney/settings/kmymoney.kcfg M +1 -0 kmymoney/settings/kmymoneysettings.kcfgc M +18 -5 kmymoney/widgets/kmymoneydateinput.cpp M +3 -0 kmymoney/widgets/kmymoneydateinput.h https://commits.kde.org/kmymoney/5f5848ba2b3a2148aa402fe87d8c41ba1ebdb329 diff --git a/kmymoney/dialogs/settings/ksettingsregister.ui b/kmymoney/dialogs/settings/ksettingsregister.ui index 358c81d4b..da3a1cea4 100644 --- a/kmymoney/dialogs/settings/ksettingsregister.ui +++ b/kmymoney/dialogs/settings/ksettingsregister.ui @@ -7,7 +7,7 @@ <x>0</x> <y>0</y> <width>632</width> - <height>500</height> + <height>512</height> </rect> </property> <property name="windowTitle"> @@ -17,7 +17,7 @@ <item> <widget class="QTabWidget" name="tab"> <property name="currentIndex"> - <number>2</number> + <number>0</number> </property> <widget class="QWidget" name="tab1"> <attribute name="title"> @@ -245,8 +245,50 @@ </widget> </item> <item> - <layout class="QHBoxLayout"> - <item> + <layout class="QGridLayout" name="gridLayout"> + <item row="0" column="0"> + <widget class="QLabel" name="textLabel2_1"> + <property name="text"> + <string>Initial cursor position within the date field</string> + </property> + </widget> + </item> + <item row="0" column="1"> + <widget class="QComboBox" name="kcfg_initialDateFieldCursorPosition"> + <item> + <property name="text"> + <string>Day</string> + </property> + </item> + <item> + <property name="text"> + <string>Month</string> + </property> + </item> + <item> + <property name="text"> + <string>Year</string> + </property> + </item> + </widget> + </item> + <item row="0" column="2"> + <spacer name="spacer16"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeType"> + <enum>QSizePolicy::Expanding</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>31</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item row="1" column="0"> <widget class="QLabel" name="textLabel2_2"> <property name="text"> <string>Default reconciliation state</string> @@ -256,7 +298,7 @@ </property> </widget> </item> - <item> + <item row="1" column="1"> <widget class="KComboBox" name="kcfg_defaultReconciliationState"> <property name="toolTip"> <string>Default reconciliation state for transactions entered during reconciliation of an account</string> @@ -278,7 +320,7 @@ </item> </widget> </item> - <item> + <item row="1" column="2"> <spacer name="spacer15"> <property name="orientation"> <enum>Qt::Horizontal</enum> diff --git a/kmymoney/settings/kmymoney.kcfg b/kmymoney/settings/kmymoney.kcfg index dddb670b3..3662c5add 100644 --- a/kmymoney/settings/kmymoney.kcfg +++ b/kmymoney/settings/kmymoney.kcfg @@ -327,6 +327,15 @@ <label>Sort order of register in search dialog</label> <default>1,-9,-4</default> </entry> + <entry name="initialDateFieldCursorPosition" type="Enum"> + <label>Initial cursor position within the date field</label> + <default>Day</default> + <choices name="PositionType"> + <choice name="Day"/> + <choice name="Month"/> + <choice name="Year"/> + </choices> + </entry> <entry name="defaultReconciliationState" type="Int"> <label>Default reconciliation state for transactions entered during reconciliation</label> <default>0</default> diff --git a/kmymoney/settings/kmymoneysettings.kcfgc b/kmymoney/settings/kmymoneysettings.kcfgc index ffcf13884..ea5eef567 100644 --- a/kmymoney/settings/kmymoneysettings.kcfgc +++ b/kmymoney/settings/kmymoneysettings.kcfgc @@ -7,3 +7,4 @@ IncludeFiles=\"kmm_settings_export.h\",\"kmymoneysettings_addon.h\" SourceIncludeFiles=\"kmymoneysettings_addons.cpp\" Visibility=KMM_SETTINGS_EXPORT CustomAdditions=true +UseEnumTypes=true diff --git a/kmymoney/widgets/kmymoneydateinput.cpp b/kmymoney/widgets/kmymoneydateinput.cpp index 6ecd2679d..d34e926e5 100644 --- a/kmymoney/widgets/kmymoneydateinput.cpp +++ b/kmymoney/widgets/kmymoneydateinput.cpp @@ -18,6 +18,7 @@ */ #include "kmymoneydateinput.h" +#include "kmymoneysettings.h" // ---------------------------------------------------------------------------- // QT Includes @@ -55,8 +56,9 @@ const int DATE_POPUP_TIMEOUT = 1500; const QDate INVALID_DATE = QDate(1800, 1, 1); } -KMyMoney::OldDateEdit::OldDateEdit(const QDate& date, QWidget* parent) : - QDateEdit(date, parent) +KMyMoney::OldDateEdit::OldDateEdit(const QDate& date, QWidget* parent) + : QDateEdit(date, parent) + , m_initialSection(QDateTimeEdit::DaySection) { } @@ -68,7 +70,7 @@ void KMyMoney::OldDateEdit::keyPressEvent(QKeyEvent* k) // (the same meaning as clearing the date) - in this case set the date // to the current date and let the editor do the actual work setDate(QDate::currentDate()); - setSelectedSection(QDateTimeEdit::DaySection); // start as when focused in if the date was cleared + setSelectedSection(m_initialSection); // start as when focused in if the date was cleared } QDateEdit::keyPressEvent(k); } @@ -76,7 +78,7 @@ void KMyMoney::OldDateEdit::keyPressEvent(QKeyEvent* k) void KMyMoney::OldDateEdit::focusInEvent(QFocusEvent * event) { QDateEdit::focusInEvent(event); - setSelectedSection(QDateTimeEdit::DaySection); + setSelectedSection(m_initialSection); } bool KMyMoney::OldDateEdit::event(QEvent* e) @@ -105,7 +107,7 @@ bool KMyMoney::OldDateEdit::focusNextPrevChild(bool next) } struct KMyMoneyDateInput::Private { - QDateEdit *m_dateEdit; + KMyMoney::OldDateEdit *m_dateEdit; KDatePicker *m_datePicker; QDate m_date; QDate m_prevDate; @@ -147,6 +149,17 @@ KMyMoneyDateInput::KMyMoneyDateInput(QWidget *parent, Qt::AlignmentFlag flags) d->m_dateFrame->hide(); d->m_dateEdit->setDisplayFormat(QLocale().dateFormat(QLocale::ShortFormat)); + switch(KMyMoneySettings::initialDateFieldCursorPosition()) { + case KMyMoneySettings::Day: + d->m_dateEdit->setInitialSection(QDateTimeEdit::DaySection); + break; + case KMyMoneySettings::Month: + d->m_dateEdit->setInitialSection(QDateTimeEdit::MonthSection); + break; + case KMyMoneySettings::Year: + d->m_dateEdit->setInitialSection(QDateTimeEdit::YearSection); + break; + } d->m_datePicker = new KDatePicker(d->m_date, d->m_dateFrame); dateFrameVBoxLayout->addWidget(d->m_datePicker); diff --git a/kmymoney/widgets/kmymoneydateinput.h b/kmymoney/widgets/kmymoneydateinput.h index 5f5fd751d..e1bfa37e6 100644 --- a/kmymoney/widgets/kmymoneydateinput.h +++ b/kmymoney/widgets/kmymoneydateinput.h @@ -48,6 +48,7 @@ namespace KMyMoney { Q_OBJECT public: explicit OldDateEdit(const QDate& date, QWidget* parent = nullptr); + void setInitialSection(Section section) { m_initialSection = section; } protected: /** if the date was cleared (a state which is not supported by QDateEdit) @@ -64,6 +65,8 @@ namespace KMyMoney { /** reimplemented for internal reasons */ void focusInEvent(QFocusEvent *event) final override; + private: + QDateEdit::Section m_initialSection; }; }; // namespace
