File indexing completed on 2024-05-12 16:37:20
0001 /* This file is part of the KDE project 0002 Copyright (C) 2004, 2007 Dag Andersen <danders@get2net.dk> 0003 0004 This library is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Library General Public 0006 License as published by the Free Software Foundation; either 0007 version 2 of the License, or (at your option) any later version. 0008 0009 This library is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 Library General Public License for more details. 0013 0014 You should have received a copy of the GNU Library General Public License 0015 along with this library; see the file COPYING.LIB. If not, write to 0016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 * Boston, MA 02110-1301, USA. 0018 */ 0019 0020 // clazy:excludeall=qstring-arg 0021 #include "kpttaskdefaultpanel.h" 0022 0023 #include "kptduration.h" 0024 #include "kptmycombobox_p.h" 0025 #include "calligraplansettings.h" 0026 0027 #ifdef PLAN_KDEPIMLIBS_FOUND 0028 #include <akonadi/contact/emailaddressselectiondialog.h> 0029 #include <akonadi/contact/emailaddressselectionwidget.h> 0030 #include <akonadi/contact/emailaddressselection.h> 0031 #endif 0032 0033 #include <QDateTime> 0034 0035 #include <kactioncollection.h> 0036 #include <ktextedit.h> 0037 0038 namespace KPlato 0039 { 0040 0041 TaskDefaultPanel::TaskDefaultPanel(QWidget *parent) 0042 : ConfigTaskPanelImpl(parent) 0043 { 0044 } 0045 0046 //----------------------------- 0047 ConfigTaskPanelImpl::ConfigTaskPanelImpl(QWidget *p) 0048 : QWidget(p) 0049 { 0050 0051 setupUi(this); 0052 kcfg_ExpectedEstimate->setMinimumUnit((Duration::Unit)KPlatoSettings::self()->minimumDurationUnit()); 0053 kcfg_ExpectedEstimate->setMaximumUnit((Duration::Unit)KPlatoSettings::self()->maximumDurationUnit()); 0054 0055 #ifndef PLAN_KDEPIMLIBS_FOUND 0056 chooseLeader->hide(); 0057 #endif 0058 0059 // FIXME 0060 // [Bug 311940] New: Plan crashes when typing a text in the filter textbox before the textbook is fully loaded when selecting a contact from the addressbook 0061 chooseLeader->hide(); 0062 0063 initDescription(); 0064 0065 connect(chooseLeader, &QAbstractButton::clicked, this, &ConfigTaskPanelImpl::changeLeader); 0066 0067 connect(kcfg_ConstraintStartTime, &QDateTimeEdit::dateTimeChanged, this, &ConfigTaskPanelImpl::startDateTimeChanged); 0068 0069 connect(kcfg_ConstraintEndTime, &QDateTimeEdit::dateTimeChanged, this, &ConfigTaskPanelImpl::endDateTimeChanged); 0070 0071 // Hack to have an interface to kcfg wo adding a custom class for this 0072 kcfg_Unit->addItems(Duration::unitList(true)); 0073 connect(kcfg_ExpectedEstimate, &DurationSpinBox::unitChanged, this, &ConfigTaskPanelImpl::unitChanged); 0074 kcfg_Unit->hide(); 0075 connect(kcfg_Unit, SIGNAL(currentIndexChanged(int)), SLOT(currentUnitChanged(int))); 0076 } 0077 0078 void ConfigTaskPanelImpl::initDescription() 0079 { 0080 toolbar->setToolButtonStyle(Qt::ToolButtonIconOnly); 0081 0082 KActionCollection *collection = new KActionCollection(this); //krazy:exclude=tipsandthis 0083 kcfg_Description->setRichTextSupport(KRichTextWidget::SupportBold | 0084 KRichTextWidget::SupportItalic | 0085 KRichTextWidget::SupportUnderline | 0086 KRichTextWidget::SupportStrikeOut | 0087 KRichTextWidget::SupportChangeListStyle | 0088 KRichTextWidget::SupportAlignment | 0089 KRichTextWidget::SupportFormatPainting); 0090 0091 collection->addActions(kcfg_Description->createActions()); 0092 0093 toolbar->addAction(collection->action("format_text_bold")); 0094 toolbar->addAction(collection->action("format_text_italic")); 0095 toolbar->addAction(collection->action("format_text_underline")); 0096 toolbar->addAction(collection->action("format_text_strikeout")); 0097 toolbar->addSeparator(); 0098 0099 toolbar->addAction(collection->action("format_list_style")); 0100 toolbar->addSeparator(); 0101 0102 toolbar->addAction(collection->action("format_align_left")); 0103 toolbar->addAction(collection->action("format_align_center")); 0104 toolbar->addAction(collection->action("format_align_right")); 0105 toolbar->addAction(collection->action("format_align_justify")); 0106 toolbar->addSeparator(); 0107 0108 // toolbar->addAction(collection->action("format_painter")); 0109 0110 // kcfg_Description->append(""); 0111 kcfg_Description->setReadOnly(false); 0112 kcfg_Description->setOverwriteMode(false); 0113 kcfg_Description->setLineWrapMode(KTextEdit::WidgetWidth); 0114 kcfg_Description->setTabChangesFocus(true); 0115 0116 } 0117 0118 0119 void ConfigTaskPanelImpl::changeLeader() 0120 { 0121 #ifdef PLAN_KDEPIMLIBS_FOUND 0122 QPointer<Akonadi::EmailAddressSelectionDialog> dlg = new Akonadi::EmailAddressSelectionDialog(this); 0123 if (dlg->exec() && dlg) { 0124 QStringList names; 0125 const Akonadi::EmailAddressSelection::List selections = dlg->selectedAddresses(); 0126 foreach (const Akonadi::EmailAddressSelection &selection, selections) { 0127 QString s = selection.name(); 0128 if (! selection.email().isEmpty()) { 0129 if (! selection.name().isEmpty()) { 0130 s += " <"; 0131 } 0132 s += selection.email(); 0133 if (! selection.name().isEmpty()) { 0134 s += '>'; 0135 } 0136 if (! s.isEmpty()) { 0137 names << s; 0138 } 0139 } 0140 } 0141 if (! names.isEmpty()) { 0142 kcfg_Leader->setText(names.join(", ")); 0143 } 0144 } 0145 #endif 0146 } 0147 0148 void ConfigTaskPanelImpl::startDateTimeChanged(const QDateTime &dt) 0149 { 0150 if (dt > kcfg_ConstraintEndTime->dateTime()) { 0151 kcfg_ConstraintEndTime->setDateTime(dt); 0152 } 0153 } 0154 0155 void ConfigTaskPanelImpl::endDateTimeChanged(const QDateTime &dt) 0156 { 0157 if (kcfg_ConstraintStartTime->dateTime() > dt) { 0158 kcfg_ConstraintStartTime->setDateTime(dt); 0159 } 0160 } 0161 0162 void ConfigTaskPanelImpl::unitChanged(int unit) 0163 { 0164 if (kcfg_Unit->currentIndex() != unit) { 0165 kcfg_Unit->setCurrentIndex(unit); 0166 // kcfg uses the activated() signal to track changes 0167 kcfg_Unit->emitActivated(unit); 0168 } 0169 } 0170 0171 void ConfigTaskPanelImpl::currentUnitChanged(int unit) 0172 { 0173 // to get values set at startup 0174 if (unit != kcfg_ExpectedEstimate->unit()) { 0175 kcfg_ExpectedEstimate->setUnit((Duration::Unit)unit); 0176 } 0177 } 0178 0179 } //KPlato namespace