1 | /* This file is part of the KDE project |
2 | Copyright (C) 2004, 2007 Dag Andersen <danders@get2net.dk> |
3 | |
4 | This library is free software; you can redistribute it and/or |
5 | modify it under the terms of the GNU Library General Public |
6 | License as published by the Free Software Foundation; either |
7 | version 2 of the License, or (at your option) any later version. |
8 | |
9 | This library is distributed in the hope that it will be useful, |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | Library General Public License for more details. |
13 | |
14 | You should have received a copy of the GNU Library General Public License |
15 | along with this library; see the file COPYING.LIB. If not, write to |
16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
17 | * Boston, MA 02110-1301, USA. |
18 | */ |
19 | |
20 | #include "kpttaskdefaultpanel.h" |
21 | |
22 | #include "kptduration.h" |
23 | #include "kptmycombobox_p.h" |
24 | #include "plansettings.h" |
25 | |
26 | #ifdef PLAN_KDEPIMLIBS_FOUND |
27 | #include <akonadi/contact/emailaddressselectiondialog.h> |
28 | #include <akonadi/contact/emailaddressselectionwidget.h> |
29 | #include <akonadi/contact/emailaddressselection.h> |
30 | #endif |
31 | |
32 | #include <QDateTime> |
33 | #include <QDateTimeEdit> |
34 | #include <QComboBox> |
35 | |
36 | #include <kactioncollection.h> |
37 | #include <ktextedit.h> |
38 | #include <kdebug.h> |
39 | |
40 | namespace KPlato |
41 | { |
42 | |
43 | TaskDefaultPanel::TaskDefaultPanel( QWidget *parent ) |
44 | : ConfigTaskPanelImpl( parent ) |
45 | { |
46 | } |
47 | |
48 | //----------------------------- |
49 | ConfigTaskPanelImpl::ConfigTaskPanelImpl(QWidget *p ) |
50 | : QWidget(p) |
51 | { |
52 | |
53 | setupUi(this); |
54 | kcfg_ExpectedEstimate->setMinimumUnit( (Duration::Unit)KPlatoSettings::self()->minimumDurationUnit() ); |
55 | kcfg_ExpectedEstimate->setMaximumUnit( (Duration::Unit)KPlatoSettings::self()->maximumDurationUnit() ); |
56 | |
57 | #ifndef PLAN_KDEPIMLIBS_FOUND |
58 | chooseLeader->hide(); |
59 | #endif |
60 | |
61 | // FIXME |
62 | // [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 adressbook |
63 | chooseLeader->hide(); |
64 | |
65 | initDescription(); |
66 | |
67 | connect(chooseLeader, SIGNAL(clicked()), SLOT(changeLeader())); |
68 | |
69 | connect( kcfg_ConstraintStartTime, SIGNAL(dateTimeChanged(QDateTime)), SLOT(startDateTimeChanged(QDateTime)) ); |
70 | |
71 | connect( kcfg_ConstraintEndTime, SIGNAL(dateTimeChanged(QDateTime)), SLOT(endDateTimeChanged(QDateTime)) ); |
72 | |
73 | // Hack to have an interface to kcfg wo adding a custom class for this |
74 | kcfg_Unit->addItems( Duration::unitList( true ) ); |
75 | connect( kcfg_ExpectedEstimate, SIGNAL(unitChanged(int)), SLOT(unitChanged(int)) ); |
76 | kcfg_Unit->hide(); |
77 | connect( kcfg_Unit, SIGNAL(currentIndexChanged(int)), SLOT(currentUnitChanged(int)) ); |
78 | } |
79 | |
80 | void ConfigTaskPanelImpl::initDescription() |
81 | { |
82 | toolbar->setToolButtonStyle( Qt::ToolButtonIconOnly ); |
83 | |
84 | KActionCollection *collection = new KActionCollection( this ); //krazy:exclude=tipsandthis |
85 | kcfg_Description->setRichTextSupport( KRichTextWidget::SupportBold | |
86 | KRichTextWidget::SupportItalic | |
87 | KRichTextWidget::SupportUnderline | |
88 | KRichTextWidget::SupportStrikeOut | |
89 | KRichTextWidget::SupportChangeListStyle | |
90 | KRichTextWidget::SupportAlignment | |
91 | KRichTextWidget::SupportFormatPainting ); |
92 | |
93 | kcfg_Description->createActions( collection ); |
94 | |
95 | toolbar->addAction( collection->action( "format_text_bold" ) ); |
96 | toolbar->addAction( collection->action( "format_text_italic" ) ); |
97 | toolbar->addAction( collection->action( "format_text_underline" ) ); |
98 | toolbar->addAction( collection->action( "format_text_strikeout" ) ); |
99 | toolbar->addSeparator(); |
100 | |
101 | toolbar->addAction( collection->action( "format_list_style" ) ); |
102 | toolbar->addSeparator(); |
103 | |
104 | toolbar->addAction( collection->action( "format_align_left" ) ); |
105 | toolbar->addAction( collection->action( "format_align_center" ) ); |
106 | toolbar->addAction( collection->action( "format_align_right" ) ); |
107 | toolbar->addAction( collection->action( "format_align_justify" ) ); |
108 | toolbar->addSeparator(); |
109 | |
110 | // toolbar->addAction( collection->action( "format_painter" ) ); |
111 | |
112 | // kcfg_Description->append( "" ); |
113 | kcfg_Description->setReadOnly( false ); |
114 | kcfg_Description->setOverwriteMode( false ); |
115 | kcfg_Description->setLineWrapMode( KTextEdit::WidgetWidth ); |
116 | kcfg_Description->setTabChangesFocus( true ); |
117 | |
118 | } |
119 | |
120 | |
121 | void ConfigTaskPanelImpl::changeLeader() |
122 | { |
123 | #ifdef PLAN_KDEPIMLIBS_FOUND |
124 | QPointer<Akonadi::EmailAddressSelectionDialog> dlg = new Akonadi::EmailAddressSelectionDialog( this ); |
125 | if ( dlg->exec() && dlg ) { |
126 | QStringList names; |
127 | const Akonadi::EmailAddressSelection::List selections = dlg->selectedAddresses(); |
128 | foreach ( const Akonadi::EmailAddressSelection &selection, selections ) { |
129 | QString s = selection.name(); |
130 | if ( ! selection.email().isEmpty() ) { |
131 | if ( ! selection.name().isEmpty() ) { |
132 | s += " <" ; |
133 | } |
134 | s += selection.email(); |
135 | if ( ! selection.name().isEmpty() ) { |
136 | s += '>'; |
137 | } |
138 | if ( ! s.isEmpty() ) { |
139 | names << s; |
140 | } |
141 | } |
142 | } |
143 | if ( ! names.isEmpty() ) { |
144 | kcfg_Leader->setText( names.join( ", " ) ); |
145 | } |
146 | } |
147 | #endif |
148 | } |
149 | |
150 | void ConfigTaskPanelImpl::startDateTimeChanged( const QDateTime &dt ) |
151 | { |
152 | if ( dt > kcfg_ConstraintEndTime->dateTime() ) { |
153 | kcfg_ConstraintEndTime->setDateTime( dt ); |
154 | } |
155 | } |
156 | |
157 | void ConfigTaskPanelImpl::endDateTimeChanged( const QDateTime &dt ) |
158 | { |
159 | if ( kcfg_ConstraintStartTime->dateTime() > dt ) { |
160 | kcfg_ConstraintStartTime->setDateTime( dt ); |
161 | } |
162 | } |
163 | |
164 | void ConfigTaskPanelImpl::unitChanged( int unit ) |
165 | { |
166 | if ( kcfg_Unit->currentIndex() != unit ) { |
167 | kcfg_Unit->setCurrentIndex( unit ); |
168 | // kcfg uses the activated() signal to track changes |
169 | emit kcfg_Unit->emitActivated( unit ); |
170 | } |
171 | } |
172 | |
173 | void ConfigTaskPanelImpl::currentUnitChanged( int unit ) |
174 | { |
175 | // to get values set at startup |
176 | if ( unit != kcfg_ExpectedEstimate->unit() ) { |
177 | kcfg_ExpectedEstimate->setUnit( (Duration::Unit)unit ); |
178 | } |
179 | } |
180 | |
181 | } //KPlato namespace |
182 | |
183 | #include "kpttaskdefaultpanel.moc" |
184 | |