summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2005-03-30 23:17:42 (UTC)
committer zautrix <zautrix>2005-03-30 23:17:42 (UTC)
commit529c0fb8a8bf15e7bd375ddeb355c5802baf4c93 (patch) (unidiff)
tree72ebca6de7e54f2cf89d3d6df61d3b40aa66a444
parent28ac86e2efbc10f210dbd2d5ac0053f4e6198d57 (diff)
downloadkdepimpi-529c0fb8a8bf15e7bd375ddeb355c5802baf4c93.zip
kdepimpi-529c0fb8a8bf15e7bd375ddeb355c5802baf4c93.tar.gz
kdepimpi-529c0fb8a8bf15e7bd375ddeb355c5802baf4c93.tar.bz2
key fix
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/kaddressbookview.cpp4
-rw-r--r--kaddressbook/kaddressbookview.h6
-rw-r--r--kaddressbook/views/cardview.cpp31
-rw-r--r--kaddressbook/views/cardview.h7
-rw-r--r--kaddressbook/views/contactlistview.cpp29
-rw-r--r--kaddressbook/views/contactlistview.h4
-rw-r--r--kaddressbook/views/kaddressbookcardview.cpp4
-rw-r--r--kaddressbook/views/kaddressbooktableview.cpp4
-rw-r--r--korganizer/komonthview.cpp19
-rw-r--r--korganizer/komonthview.h3
-rw-r--r--korganizer/mainwindow.cpp26
-rw-r--r--korganizer/mainwindow.h1
12 files changed, 129 insertions, 9 deletions
diff --git a/kaddressbook/kaddressbookview.cpp b/kaddressbook/kaddressbookview.cpp
index 09859c2..86898e2 100644
--- a/kaddressbook/kaddressbookview.cpp
+++ b/kaddressbook/kaddressbookview.cpp
@@ -1,186 +1,188 @@
1/* 1/*
2 This file is part of KAddressBook. 2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com> 3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23 23
24#ifndef KAB_EMBEDDED 24#ifndef KAB_EMBEDDED
25#include <qapplication.h> 25#include <qapplication.h>
26 26
27#include <kabc/distributionlistdialog.h> 27#include <kabc/distributionlistdialog.h>
28#include <kconfig.h> 28#include <kconfig.h>
29#include <klocale.h> 29#include <klocale.h>
30 30
31#include "viewmanager.h" 31#include "viewmanager.h"
32 32
33#endif //KAB_EMBEDDED 33#endif //KAB_EMBEDDED
34#include <qlayout.h> 34#include <qlayout.h>
35 35
36#include <kabc/distributionlistdialog.h> 36#include <kabc/distributionlistdialog.h>
37#include <kabc/addressbook.h> 37#include <kabc/addressbook.h>
38#include <kdebug.h> 38#include <kdebug.h>
39 39
40#include "kaddressbookview.h" 40#include "kaddressbookview.h"
41 41
42KAddressBookView::KAddressBookView( KABC::AddressBook *ab, QWidget *parent, 42KAddressBookView::KAddressBookView( KABC::AddressBook *ab, QWidget *parent,
43 const char *name ) 43 const char *name )
44 : QWidget( parent, name ), mAddressBook( ab ), mFieldList() 44 : QWidget( parent, name ), mAddressBook( ab ), mFieldList()
45{ 45{
46 46
47 initGUI(); 47 initGUI();
48} 48}
49 49
50KAddressBookView::~KAddressBookView() 50KAddressBookView::~KAddressBookView()
51{ 51{
52 52
53} 53}
54 54
55QRegExp KAddressBookView::getRegExp( const QString s ) 55QRegExp KAddressBookView::getRegExp( const QString s )
56{ 56{
57 QRegExp re; 57 QRegExp re;
58 58
59 if ( s.length() == 3 && s.mid(1,1) == "-" ) { 59 if ( s.length() == 3 && s.mid(1,1) == "-" ) {
60 QString pattern = "^[" + s.lower() +"]"; 60 QString pattern = "^[" + s.lower() +"]";
61 re.setCaseSensitive(false); 61 re.setCaseSensitive(false);
62 re.setPattern( pattern ); 62 re.setPattern( pattern );
63 } else { 63 } else {
64 QString pattern = s.lower()+"*"; 64 QString pattern = s.lower()+"*";
65 re.setWildcard(true); // most people understand these better. 65 re.setWildcard(true); // most people understand these better.
66 re.setCaseSensitive(false); 66 re.setCaseSensitive(false);
67 re.setPattern( pattern ); 67 re.setPattern( pattern );
68 } 68 }
69 return re; 69 return re;
70} 70}
71 71
72void KAddressBookView::readConfig( KConfig *config ) 72void KAddressBookView::readConfig( KConfig *config )
73{ 73{
74 mFieldList = KABC::Field::restoreFields( config, "KABCFields" ); 74 mFieldList = KABC::Field::restoreFields( config, "KABCFields" );
75 75
76 if ( mFieldList.isEmpty() ) 76 if ( mFieldList.isEmpty() )
77 mFieldList = KABC::Field::defaultFields(); 77 mFieldList = KABC::Field::defaultFields();
78 78
79 mDefaultFilterType = (DefaultFilterType)config->readNumEntry( "DefaultFilterType", 1 ); 79 mDefaultFilterType = (DefaultFilterType)config->readNumEntry( "DefaultFilterType", 1 );
80 mDefaultFilterName = config->readEntry( "DefaultFilterName", QString::null ); 80 mDefaultFilterName = config->readEntry( "DefaultFilterName", QString::null );
81} 81}
82 82
83void KAddressBookView::writeConfig( KConfig* ) 83void KAddressBookView::writeConfig( KConfig* )
84{ 84{
85 // Most of writing the config is handled by the ConfigureViewDialog 85 // Most of writing the config is handled by the ConfigureViewDialog
86} 86}
87 87
88QString KAddressBookView::selectedEmails() 88QString KAddressBookView::selectedEmails()
89{ 89{
90 bool first = true; 90 bool first = true;
91 QString emailAddrs; 91 QString emailAddrs;
92 QStringList uidList = selectedUids(); 92 QStringList uidList = selectedUids();
93 KABC::Addressee addr; 93 KABC::Addressee addr;
94 QString email; 94 QString email;
95 95
96 QStringList::Iterator it; 96 QStringList::Iterator it;
97 for ( it = uidList.begin(); it != uidList.end(); ++it ) { 97 for ( it = uidList.begin(); it != uidList.end(); ++it ) {
98 addr = mAddressBook->findByUid( *it ); 98 addr = mAddressBook->findByUid( *it );
99 99
100 if ( !addr.isEmpty() ) { 100 if ( !addr.isEmpty() ) {
101 QString m = QString::null; 101 QString m = QString::null;
102 102
103 if ( addr.emails().count() > 1 ) 103 if ( addr.emails().count() > 1 )
104 m = KABC::EmailSelector::getEmail( addr.emails(), addr.preferredEmail(), this ); 104 m = KABC::EmailSelector::getEmail( addr.emails(), addr.preferredEmail(), this );
105 105
106 email = addr.fullEmail( m ); 106 email = addr.fullEmail( m );
107 107
108 if ( !first ) 108 if ( !first )
109 emailAddrs += ", "; 109 emailAddrs += ", ";
110 else 110 else
111 first = false; 111 first = false;
112 112
113 emailAddrs += email; 113 emailAddrs += email;
114 } 114 }
115 } 115 }
116 116
117 return emailAddrs; 117 return emailAddrs;
118} 118}
119 119
120KABC::Addressee::List KAddressBookView::addressees() 120KABC::Addressee::List KAddressBookView::addressees()
121{ 121{
122 KABC::Addressee::List addresseeList; 122 KABC::Addressee::List addresseeList;
123 123
124 KABC::AddressBook::Iterator it; 124 KABC::AddressBook::Iterator it;
125 for (it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) { 125 for (it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) {
126 if ( mFilter.filterAddressee( *it ) ) 126 if ( mFilter.filterAddressee( *it ) )
127 addresseeList.append( *it ); 127 addresseeList.append( *it );
128 } 128 }
129 129
130 return addresseeList; 130 return addresseeList;
131} 131}
132 132
133void KAddressBookView::initGUI() 133void KAddressBookView::initGUI()
134{ 134{
135 // Create the layout 135 // Create the layout
136 QVBoxLayout *layout = new QVBoxLayout( this ); 136 QVBoxLayout *layout = new QVBoxLayout( this );
137 137
138 // Add the view widget 138 // Add the view widget
139 mViewWidget = new QWidget( this ); 139 mViewWidget = new QWidget( this );
140 layout->addWidget( mViewWidget ); 140 layout->addWidget( mViewWidget );
141} 141}
142 142
143KABC::Field::List KAddressBookView::fields() const 143KABC::Field::List KAddressBookView::fields() const
144{ 144{
145 return mFieldList; 145 return mFieldList;
146} 146}
147KABC::Field::List KAddressBookView::allFields() const 147KABC::Field::List KAddressBookView::allFields() const
148{ 148{
149 return KABC::Field::allFields(); 149 return KABC::Field::allFields();
150} 150}
151 151
152void KAddressBookView::setFilter( const Filter &filter ) 152void KAddressBookView::setFilter( const Filter &filter )
153{ 153{
154 mFilter = filter; 154 mFilter = filter;
155} 155}
156 156
157KAddressBookView::DefaultFilterType KAddressBookView::defaultFilterType() const 157KAddressBookView::DefaultFilterType KAddressBookView::defaultFilterType() const
158{ 158{
159 return mDefaultFilterType; 159 return mDefaultFilterType;
160} 160}
161 161
162const QString &KAddressBookView::defaultFilterName() const 162const QString &KAddressBookView::defaultFilterName() const
163{ 163{
164 return mDefaultFilterName; 164 return mDefaultFilterName;
165} 165}
166 166
167KABC::AddressBook *KAddressBookView::addressBook() const 167KABC::AddressBook *KAddressBookView::addressBook() const
168{ 168{
169 return mAddressBook; 169 return mAddressBook;
170} 170}
171 171
172QWidget *KAddressBookView::viewWidget() 172QWidget *KAddressBookView::viewWidget()
173{ 173{
174 return mViewWidget; 174 return mViewWidget;
175} 175}
176 176
177ViewConfigureWidget *ViewFactory::configureWidget( KABC::AddressBook *ab, 177ViewConfigureWidget *ViewFactory::configureWidget( KABC::AddressBook *ab,
178 QWidget *parent, 178 QWidget *parent,
179 const char *name ) 179 const char *name )
180{ 180{
181 return new ViewConfigureWidget( ab, parent, name ); 181 return new ViewConfigureWidget( ab, parent, name );
182} 182}
183 183
184
185
184#ifndef KAB_EMBEDDED 186#ifndef KAB_EMBEDDED
185#include "kaddressbookview.moc" 187#include "kaddressbookview.moc"
186#endif //KAB_EMBEDDED 188#endif //KAB_EMBEDDED
diff --git a/kaddressbook/kaddressbookview.h b/kaddressbook/kaddressbookview.h
index 6bbb9c2..3a3f71a 100644
--- a/kaddressbook/kaddressbookview.h
+++ b/kaddressbook/kaddressbookview.h
@@ -1,312 +1,314 @@
1/* 1/*
2 This file is part of KAddressBook. 2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com> 3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23 23
24#ifndef KADDRESSBOOKVIEW_H 24#ifndef KADDRESSBOOKVIEW_H
25#define KADDRESSBOOKVIEW_H 25#define KADDRESSBOOKVIEW_H
26 26
27#ifndef KAB_EMBEDDED 27#ifndef KAB_EMBEDDED
28#include <klibloader.h> 28#include <klibloader.h>
29#endif //KAB_EMBEDDED 29#endif //KAB_EMBEDDED
30 30
31class KConfig; 31class KConfig;
32class QDropEvent; 32class QDropEvent;
33 33
34#include <qstringlist.h> 34#include <qstringlist.h>
35#include <kabc/field.h> 35#include <kabc/field.h>
36#include <qwidget.h> 36#include <qwidget.h>
37#include <qregexp.h> 37#include <qregexp.h>
38 38
39#include "viewconfigurewidget.h" 39#include "viewconfigurewidget.h"
40#include "filter.h" 40#include "filter.h"
41 41
42#ifdef DESKTOP_VERSION 42#ifdef DESKTOP_VERSION
43#include <qpaintdevicemetrics.h> 43#include <qpaintdevicemetrics.h>
44#include <qprinter.h> 44#include <qprinter.h>
45#include <qpainter.h> 45#include <qpainter.h>
46#endif 46#endif
47 47
48namespace KABC { class AddressBook; } 48namespace KABC { class AddressBook; }
49 49
50/** 50/**
51 Base class for all views in kaddressbook. This class implements 51 Base class for all views in kaddressbook. This class implements
52 all the common methods needed to provide a view to the user. 52 all the common methods needed to provide a view to the user.
53 53
54 To implement a specific view (table, card, etc), just inherit from 54 To implement a specific view (table, card, etc), just inherit from
55 this class and implement all the pure virtuals. 55 this class and implement all the pure virtuals.
56 56
57 @author Mike Pilone <mpilone@slac.com> 57 @author Mike Pilone <mpilone@slac.com>
58 */ 58 */
59class KAddressBookView : public QWidget 59class KAddressBookView : public QWidget
60{ 60{
61 Q_OBJECT 61 Q_OBJECT
62 62
63 public: 63 public:
64 enum DefaultFilterType { None = 0, Active = 1, Specific = 2 }; 64 enum DefaultFilterType { None = 0, Active = 1, Specific = 2 };
65 65
66 KAddressBookView( KABC::AddressBook *ab, QWidget *parent, const char *name ); 66 KAddressBookView( KABC::AddressBook *ab, QWidget *parent, const char *name );
67 virtual ~KAddressBookView(); 67 virtual ~KAddressBookView();
68 68
69 /** 69 /**
70 Must be overloaded in subclasses. Should return a list of 70 Must be overloaded in subclasses. Should return a list of
71 all the uids of selected contacts. 71 all the uids of selected contacts.
72 */ 72 */
73 virtual QStringList selectedUids() = 0; 73 virtual QStringList selectedUids() = 0;
74 virtual void doSearch( const QString& s ,KABC::Field *field ) = 0; 74 virtual void doSearch( const QString& s ,KABC::Field *field ) = 0;
75 virtual void scrollUP() = 0; 75 virtual void scrollUP() = 0;
76 virtual void scrollDOWN() = 0; 76 virtual void scrollDOWN() = 0;
77 virtual void setFocusAV() = 0; 77 virtual void setFocusAV() = 0;
78 78
79 /** 79 /**
80 Called whenever this view should read the config. This can be used 80 Called whenever this view should read the config. This can be used
81 as a sign that the config has changed, therefore the view should 81 as a sign that the config has changed, therefore the view should
82 assume the worst and rebuild itself if necessary. For example, 82 assume the worst and rebuild itself if necessary. For example,
83 in a table view this method may be called when the user adds or 83 in a table view this method may be called when the user adds or
84 removes columns from the view. 84 removes columns from the view.
85 85
86 If overloaded in the subclass, do not forget to call super class's 86 If overloaded in the subclass, do not forget to call super class's
87 method. 87 method.
88 88
89 @param config The KConfig object to read from. The group will already 89 @param config The KConfig object to read from. The group will already
90 be set, so do not change the group. 90 be set, so do not change the group.
91 */ 91 */
92 virtual void readConfig( KConfig *config ); 92 virtual void readConfig( KConfig *config );
93 93
94 /** 94 /**
95 Called whenever this view should write the config. The view should not 95 Called whenever this view should write the config. The view should not
96 write out information handled by the application, such as which fields 96 write out information handled by the application, such as which fields
97 are visible. The view should only write out information specific 97 are visible. The view should only write out information specific
98 to itself (i.e.: All information in the ViewConfigWidget) 98 to itself (i.e.: All information in the ViewConfigWidget)
99 99
100 If overloaded in the subclass, do not forget to call the super class's 100 If overloaded in the subclass, do not forget to call the super class's
101 method. 101 method.
102 102
103 @param config The KConfig object to read from. The group will already 103 @param config The KConfig object to read from. The group will already
104 be set, so do not change the group. 104 be set, so do not change the group.
105 */ 105 */
106 virtual void writeConfig( KConfig *config ); 106 virtual void writeConfig( KConfig *config );
107 107
108 /** 108 /**
109 Returns a QString with all the selected email addresses concatenated 109 Returns a QString with all the selected email addresses concatenated
110 together with a ',' seperator. 110 together with a ',' seperator.
111 */ 111 */
112 virtual QString selectedEmails(); 112 virtual QString selectedEmails();
113 113
114 /** 114 /**
115 Return the type of the view: Icon, Table, etc. Please make sure that 115 Return the type of the view: Icon, Table, etc. Please make sure that
116 this is the same value that ViewWrapper::type() will return for your 116 this is the same value that ViewWrapper::type() will return for your
117 view. 117 view.
118 */ 118 */
119 virtual QString type() const = 0; 119 virtual QString type() const = 0;
120 120
121 /** 121 /**
122 Returns a list of the fields that should be displayed. The list 122 Returns a list of the fields that should be displayed. The list
123 is composed of the fields proper names (ie: Home Address), so 123 is composed of the fields proper names (ie: Home Address), so
124 the view may need to translate them in order to get the 124 the view may need to translate them in order to get the
125 value from the addressee. 125 value from the addressee.
126 126
127 This list is generated from the config file, so it is advisable to call 127 This list is generated from the config file, so it is advisable to call
128 this method whenever a readConfig() is called in order to get the newest 128 this method whenever a readConfig() is called in order to get the newest
129 list of fields. 129 list of fields.
130 */ 130 */
131 KABC::Field::List fields() const; 131 KABC::Field::List fields() const;
132 132
133 KABC::Field::List allFields() const; 133 KABC::Field::List allFields() const;
134 134
135 /** 135 /**
136 Sets the active filter. This filter will be used for filtering 136 Sets the active filter. This filter will be used for filtering
137 the list of addressees to display. The view will <b>not</b> 137 the list of addressees to display. The view will <b>not</b>
138 automatically refresh itself, so in most cases you will want to call 138 automatically refresh itself, so in most cases you will want to call
139 KAddressBookView::refresh() after this method. 139 KAddressBookView::refresh() after this method.
140 */ 140 */
141 void setFilter( const Filter& ); 141 void setFilter( const Filter& );
142 142
143 /** 143 /**
144 @return The default filter type selection. If the selection 144 @return The default filter type selection. If the selection
145 is SpecificFilter, the name of the filter can be retrieved with 145 is SpecificFilter, the name of the filter can be retrieved with
146 defaultFilterName() 146 defaultFilterName()
147 */ 147 */
148 DefaultFilterType defaultFilterType() const; 148 DefaultFilterType defaultFilterType() const;
149 149
150 /** 150 /**
151 @return The name of the default filter. This string is 151 @return The name of the default filter. This string is
152 only valid if defaultFilterType() is returning SpecificFilter. 152 only valid if defaultFilterType() is returning SpecificFilter.
153 */ 153 */
154 const QString &defaultFilterName() const; 154 const QString &defaultFilterName() const;
155 155
156 /** 156 /**
157 @return The address book. 157 @return The address book.
158 */ 158 */
159 KABC::AddressBook *addressBook() const; 159 KABC::AddressBook *addressBook() const;
160 void printMyView() { emit printView() ;} 160 void printMyView() { emit printView() ;}
161 161
162 public slots: 162 public slots:
163 /** 163 /**
164 Must be overloaded in subclasses to refresh the view. 164 Must be overloaded in subclasses to refresh the view.
165 Refreshing includes updating the view to ensure that only items 165 Refreshing includes updating the view to ensure that only items
166 in the document are visible. If <i>uid</i> is valid, only the 166 in the document are visible. If <i>uid</i> is valid, only the
167 addressee with uid needs to be refreshed. This is an optimization 167 addressee with uid needs to be refreshed. This is an optimization
168 only. 168 only.
169 */ 169 */
170 virtual void refresh( QString uid = QString::null ) = 0; 170 virtual void refresh( QString uid = QString::null ) = 0;
171 171
172 /** 172 /**
173 This method must be overloaded in subclasses. Select (highlight) 173 This method must be overloaded in subclasses. Select (highlight)
174 the addressee matching <i>uid</i>. If uid 174 the addressee matching <i>uid</i>. If uid
175 is equal to QString::null, then all addressees should be selected. 175 is equal to QString::null, then all addressees should be selected.
176 */ 176 */
177#ifndef KAB_EMBEDDED 177#ifndef KAB_EMBEDDED
178//MOC_SKIP_BEGIN 178//MOC_SKIP_BEGIN
179 virtual void setSelected( QString uid = QString::null, bool selected = true ) = 0; 179 virtual void setSelected( QString uid = QString::null, bool selected = true ) = 0;
180//MOC_SKIP_END 180//MOC_SKIP_END
181#else //KAB_EMBEDDED 181#else //KAB_EMBEDDED
182 //US my moc can not handle the default parameters. Is this a problem ??? 182 //US my moc can not handle the default parameters. Is this a problem ???
183 virtual void setSelected( QString uid, bool selected) = 0; 183 virtual void setSelected( QString uid, bool selected) = 0;
184#endif //KAB_EMBEDDED 184#endif //KAB_EMBEDDED
185 185
186 signals: 186 signals:
187 187
188 void printView(); 188 void printView();
189 /** 189 /**
190 This signal should be emitted by a subclass whenever an addressee 190 This signal should be emitted by a subclass whenever an addressee
191 is modified. 191 is modified.
192 */ 192 */
193 void modified(); 193 void modified();
194 194
195 /** 195 /**
196 This signal should be emitted by a subclass whenever an addressee 196 This signal should be emitted by a subclass whenever an addressee
197 is selected. Selected means that the addressee was given the focus. 197 is selected. Selected means that the addressee was given the focus.
198 Some widgets may call this 'highlighted'. The view is responsible for 198 Some widgets may call this 'highlighted'. The view is responsible for
199 emitting this signal multiple times if multiple items are selected, 199 emitting this signal multiple times if multiple items are selected,
200 with the last item selected being the last emit. 200 with the last item selected being the last emit.
201 201
202 @param uid The uid of the selected addressee. 202 @param uid The uid of the selected addressee.
203 203
204 @see KListView 204 @see KListView
205 */ 205 */
206 void selected( const QString &uid ); 206 void selected( const QString &uid );
207 void deleteRequest(); 207 void deleteRequest();
208 /** 208 /**
209 This signal should be emitted by a subclass whenever an addressee 209 This signal should be emitted by a subclass whenever an addressee
210 is executed. This is defined by the KDE system wide config, but it 210 is executed. This is defined by the KDE system wide config, but it
211 either means single or doubleclicked. 211 either means single or doubleclicked.
212 212
213 @param ui The uid of the selected addressee 213 @param ui The uid of the selected addressee
214 214
215 @see KListView 215 @see KListView
216 */ 216 */
217 void executed( const QString &uid ); 217 void executed( const QString &uid );
218 218
219 /** 219 /**
220 This signal is emitted whenever a user attempts to start a drag 220 This signal is emitted whenever a user attempts to start a drag
221 in the view. The slot connected to this signal would usually want 221 in the view. The slot connected to this signal would usually want
222 to create a QDragObject. 222 to create a QDragObject.
223 */ 223 */
224 void startDrag(); 224 void startDrag();
225 225
226 /** 226 /**
227 This signal is emitted whenever the user drops something on the 227 This signal is emitted whenever the user drops something on the
228 view. The individual view should handle checking if the item is 228 view. The individual view should handle checking if the item is
229 droppable (ie: if it is a vcard). 229 droppable (ie: if it is a vcard).
230 */ 230 */
231 void dropped( QDropEvent* ); 231 void dropped( QDropEvent* );
232 232
233 protected: 233 protected:
234
234 /** 235 /**
235 Returns a list of the addressees that should be displayed. This method 236 Returns a list of the addressees that should be displayed. This method
236 should always be used by the subclass to get a list of addressees. This 237 should always be used by the subclass to get a list of addressees. This
237 method internally takes many factors into account, including the current 238 method internally takes many factors into account, including the current
238 filter. 239 filter.
239 */ 240 */
240 KABC::Addressee::List addressees(); 241 KABC::Addressee::List addressees();
241 242
242 /** 243 /**
243 This method returns the widget that should be used as the parent for 244 This method returns the widget that should be used as the parent for
244 all view components. By using this widget as the parent and not 245 all view components. By using this widget as the parent and not
245 'this', the view subclass has the option of placing other widgets 246 'this', the view subclass has the option of placing other widgets
246 around the view (ie: search fields, etc). Do not delete this widget! 247 around the view (ie: search fields, etc). Do not delete this widget!
247 */ 248 */
248 QWidget *viewWidget(); 249 QWidget *viewWidget();
249 QRegExp getRegExp( const QString ); 250 QRegExp getRegExp( const QString );
250 251
251 private: 252 private:
252 void initGUI(); 253 void initGUI();
253 254
254 DefaultFilterType mDefaultFilterType; 255 DefaultFilterType mDefaultFilterType;
255 Filter mFilter; 256 Filter mFilter;
256 QString mDefaultFilterName; 257 QString mDefaultFilterName;
257 KABC::AddressBook *mAddressBook; 258 KABC::AddressBook *mAddressBook;
258 KABC::Field::List mFieldList; 259 KABC::Field::List mFieldList;
259 260
260 QWidget *mViewWidget; 261 QWidget *mViewWidget;
261}; 262};
262 263
263#ifndef KAB_EMBEDDED 264#ifndef KAB_EMBEDDED
264//MOC_SKIP_BEGIN 265//MOC_SKIP_BEGIN
265class ViewFactory : public KLibFactory 266class ViewFactory : public KLibFactory
266//MOC_SKIP_END 267//MOC_SKIP_END
267#else //KAB_EMBEDDED 268#else //KAB_EMBEDDED
268class ViewFactory 269class ViewFactory
269#endif //KAB_EMBEDDED 270#endif //KAB_EMBEDDED
270{ 271{
271 272
272 public: 273 public:
273 virtual KAddressBookView *view( KABC::AddressBook *ab, QWidget *parent, 274 virtual KAddressBookView *view( KABC::AddressBook *ab, QWidget *parent,
274 const char *name = 0 ) = 0; 275 const char *name = 0 ) = 0;
275 276
276 /** 277 /**
277 @return The type of the view. This is normally a small one word 278 @return The type of the view. This is normally a small one word
278 string (ie: Table, Icon, Tree, etc). 279 string (ie: Table, Icon, Tree, etc).
279 */ 280 */
280 virtual QString type() const = 0; 281 virtual QString type() const = 0;
281 282
282 /** 283 /**
283 @return The description of the view. This should be a 3 to 284 @return The description of the view. This should be a 3 to
284 4 line string (don't actually use return characters in the string) 285 4 line string (don't actually use return characters in the string)
285 describing the features offered by the view. 286 describing the features offered by the view.
286 */ 287 */
287 virtual QString description() const = 0; 288 virtual QString description() const = 0;
288 289
289 /** 290 /**
290 Creates a config dialog for the view type. The default 291 Creates a config dialog for the view type. The default
291 implementation will return a ViewConfigDialog. This default 292 implementation will return a ViewConfigDialog. This default
292 dialog will allow the user to set the visible fields only. If 293 dialog will allow the user to set the visible fields only. If
293 you need more config options (as most views will), this method 294 you need more config options (as most views will), this method
294 can be overloaded to return your sublcass of ViewConfigDialog. 295 can be overloaded to return your sublcass of ViewConfigDialog.
295 If this method is over loaded the base classes method should 296 If this method is over loaded the base classes method should
296 <B>not</B> be called. 297 <B>not</B> be called.
297 */ 298 */
298 virtual ViewConfigureWidget *configureWidget( KABC::AddressBook *ab, 299 virtual ViewConfigureWidget *configureWidget( KABC::AddressBook *ab,
299 QWidget *parent, 300 QWidget *parent,
300 const char *name = 0 ); 301 const char *name = 0 );
301 302
302 protected: 303 protected:
303 virtual QObject* createObject( QObject*, const char*, const char*, 304 virtual QObject* createObject( QObject*, const char*, const char*,
304 const QStringList & ) 305 const QStringList & )
305 { 306 {
306 return 0; 307 return 0;
307 } 308 }
309
308 310
309}; 311};
310 312
311 313
312#endif 314#endif
diff --git a/kaddressbook/views/cardview.cpp b/kaddressbook/views/cardview.cpp
index 03df444..84d3116 100644
--- a/kaddressbook/views/cardview.cpp
+++ b/kaddressbook/views/cardview.cpp
@@ -1,291 +1,292 @@
1/* 1/*
2 This file is part of KAddressBook. 2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com> 3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23 23
24//BEGIN Includes 24//BEGIN Includes
25#include "cardview.h" 25#include "cardview.h"
26 26
27#include <limits.h> 27#include <limits.h>
28 28
29#include <qpainter.h> 29#include <qpainter.h>
30#include <qtimer.h> 30#include <qtimer.h>
31#include <qdatetime.h> 31#include <qdatetime.h>
32#include <qlabel.h> 32#include <qlabel.h>
33#include <qstyle.h> 33#include <qstyle.h>
34#include <qcursor.h> 34#include <qcursor.h>
35#include <qtooltip.h> 35#include <qtooltip.h>
36#include <qapplication.h>
36 37
37#include "kabprefs.h" 38#include "kabprefs.h"
38#include <kdebug.h> 39#include <kdebug.h>
39#include <kglobalsettings.h> 40#include <kglobalsettings.h>
40//END includes 41//END includes
41 42
42#define MIN_ITEM_WIDTH 80 43#define MIN_ITEM_WIDTH 80
43 44
44//BEGIN Helpers 45//BEGIN Helpers
45////////////////////////////////////// 46//////////////////////////////////////
46// CardViewTip 47// CardViewTip
47class CardViewTip : public QLabel { 48class CardViewTip : public QLabel {
48 public: 49 public:
49 CardViewTip(QWidget *parent=0, const char *name=0) : QLabel( parent, name ) 50 CardViewTip(QWidget *parent=0, const char *name=0) : QLabel( parent, name )
50 { 51 {
51 setPalette( QToolTip::palette() ); 52 setPalette( QToolTip::palette() );
52 setFrameStyle( Panel|Plain ); 53 setFrameStyle( Panel|Plain );
53 setMidLineWidth(0); 54 setMidLineWidth(0);
54 setIndent(1); 55 setIndent(1);
55 } 56 }
56 57
57 ~CardViewTip() {}; 58 ~CardViewTip() {};
58 protected: 59 protected:
59 void leaveEvent( QEvent * ) 60 void leaveEvent( QEvent * )
60 { 61 {
61 hide(); 62 hide();
62 } 63 }
63}; 64};
64 65
65////////////////////////////////////// 66//////////////////////////////////////
66// CardViewItemList 67// CardViewItemList
67 68
68 69
69// 70//
70// Warning: make sure you use findRef() instead of find() to find an 71// Warning: make sure you use findRef() instead of find() to find an
71// item! Only the pointer value is unique in the list. 72// item! Only the pointer value is unique in the list.
72// 73//
73class CardViewItemList : public QPtrList<CardViewItem> 74class CardViewItemList : public QPtrList<CardViewItem>
74{ 75{
75 protected: 76 protected:
76 virtual int compareItems(QPtrCollection::Item item1, 77 virtual int compareItems(QPtrCollection::Item item1,
77 QPtrCollection::Item item2) 78 QPtrCollection::Item item2)
78 { 79 {
79 CardViewItem *cItem1 = (CardViewItem*)item1; 80 CardViewItem *cItem1 = (CardViewItem*)item1;
80 CardViewItem *cItem2 = (CardViewItem*)item2; 81 CardViewItem *cItem2 = (CardViewItem*)item2;
81 82
82 if ( cItem1 == cItem2 ) 83 if ( cItem1 == cItem2 )
83 return 0; 84 return 0;
84 85
85 if ((cItem1 == 0) || (cItem2 == 0)) 86 if ((cItem1 == 0) || (cItem2 == 0))
86 return cItem1 ? -1 : 1; 87 return cItem1 ? -1 : 1;
87 88
88 if (cItem1->caption() < cItem2->caption()) 89 if (cItem1->caption() < cItem2->caption())
89 return -1; 90 return -1;
90 91
91 else if (cItem1->caption() > cItem2->caption()) 92 else if (cItem1->caption() > cItem2->caption())
92 return 1; 93 return 1;
93 94
94 return 0; 95 return 0;
95 } 96 }
96 97
97 private: 98 private:
98 /*int find( const CardViewItem * ) 99 /*int find( const CardViewItem * )
99 { 100 {
100 qDebug("DON'T USE CardViewItemList::find( item )! Use findRef( item )!"); 101 qDebug("DON'T USE CardViewItemList::find( item )! Use findRef( item )!");
101 }*/ 102 }*/
102}; 103};
103 104
104////////////////////////////////////// 105//////////////////////////////////////
105// CardViewSeparator 106// CardViewSeparator
106class CardViewSeparator 107class CardViewSeparator
107{ 108{
108 friend class CardView; 109 friend class CardView;
109 110
110 public: 111 public:
111 CardViewSeparator(CardView *view) 112 CardViewSeparator(CardView *view)
112 : mView(view) 113 : mView(view)
113 { 114 {
114 mRect = QRect(0, 0, view->separatorWidth(), 0); 115 mRect = QRect(0, 0, view->separatorWidth(), 0);
115 } 116 }
116 117
117 ~CardViewSeparator() {} 118 ~CardViewSeparator() {}
118 119
119 void paintSeparator(QPainter *p, QColorGroup &cg) 120 void paintSeparator(QPainter *p, QColorGroup &cg)
120 { 121 {
121 p->fillRect(0, 0, mRect.width(), mRect.height(), 122 p->fillRect(0, 0, mRect.width(), mRect.height(),
122 cg.brush(QColorGroup::Button)); 123 cg.brush(QColorGroup::Button));
123 } 124 }
124 125
125 void repaintSeparator() 126 void repaintSeparator()
126 { 127 {
127 mView->repaintContents(mRect); 128 mView->repaintContents(mRect);
128 } 129 }
129 130
130 private: 131 private:
131 CardView *mView; 132 CardView *mView;
132 QRect mRect; 133 QRect mRect;
133}; 134};
134 135
135//END Helpers 136//END Helpers
136 137
137//BEGIN Private Data 138//BEGIN Private Data
138 139
139class CardViewPrivate 140class CardViewPrivate
140{ 141{
141 public: 142 public:
142 CardViewPrivate() 143 CardViewPrivate()
143 : mSelectionMode( CardView::Multi ), 144 : mSelectionMode( CardView::Multi ),
144 mDrawCardBorder( true ), 145 mDrawCardBorder( true ),
145 mDrawFieldLabels( true ), 146 mDrawFieldLabels( true ),
146 mDrawSeparators( true), 147 mDrawSeparators( true),
147 mSepWidth( 2 ), 148 mSepWidth( 2 ),
148 mShowEmptyFields( false ), 149 mShowEmptyFields( false ),
149 mLayoutDirty( true ), 150 mLayoutDirty( true ),
150 mLastClickOnItem( false ), 151 mLastClickOnItem( false ),
151 mItemMargin( 0 ), 152 mItemMargin( 0 ),
152 mItemSpacing( 10 ), 153 mItemSpacing( 10 ),
153 mItemWidth( 200 ), 154 mItemWidth( 200 ),
154 mMaxFieldLines( INT_MAX ), 155 mMaxFieldLines( INT_MAX ),
155 mCurrentItem( 0L ), 156 mCurrentItem( 0L ),
156 mLastClickPos( QPoint(0, 0) ), 157 mLastClickPos( QPoint(0, 0) ),
157 mResizeAnchor(0), 158 mResizeAnchor(0),
158 mRubberBandAnchor( 0 ), 159 mRubberBandAnchor( 0 ),
159 mCompText( QString::null ) 160 mCompText( QString::null )
160 {}; 161 {};
161 162
162 CardViewItemList mItemList; 163 CardViewItemList mItemList;
163 QPtrList<CardViewSeparator> mSeparatorList; 164 QPtrList<CardViewSeparator> mSeparatorList;
164 QFontMetrics *mFm; 165 QFontMetrics *mFm;
165 QFontMetrics *mBFm; // bold font 166 QFontMetrics *mBFm; // bold font
166 QFont mHeaderFont; // custom header font 167 QFont mHeaderFont; // custom header font
167 CardView::SelectionMode mSelectionMode; 168 CardView::SelectionMode mSelectionMode;
168 bool mDrawCardBorder; 169 bool mDrawCardBorder;
169 bool mDrawFieldLabels; 170 bool mDrawFieldLabels;
170 bool mDrawSeparators; 171 bool mDrawSeparators;
171 int mSepWidth; 172 int mSepWidth;
172 bool mShowEmptyFields; 173 bool mShowEmptyFields;
173 bool mLayoutDirty; 174 bool mLayoutDirty;
174 bool mLastClickOnItem; 175 bool mLastClickOnItem;
175 uint mItemMargin; // internal margin in items 176 uint mItemMargin; // internal margin in items
176 uint mItemSpacing; // spacing between items, column seperators and border 177 uint mItemSpacing; // spacing between items, column seperators and border
177 int mItemWidth; // width of all items 178 int mItemWidth; // width of all items
178 uint mMaxFieldLines; // Max lines to dispaly pr field 179 uint mMaxFieldLines; // Max lines to dispaly pr field
179 CardViewItem *mCurrentItem; 180 CardViewItem *mCurrentItem;
180 QPoint mLastClickPos; 181 QPoint mLastClickPos;
181 QTimer *mTimer; // times out if mouse rests for more than 500 msecs 182 QTimer *mTimer; // times out if mouse rests for more than 500 msecs
182 CardViewTip *mTip; // passed to the item under a resting cursor to display full text 183 CardViewTip *mTip; // passed to the item under a resting cursor to display full text
183 bool mOnSeparator; // set/reset on mouse movement 184 bool mOnSeparator; // set/reset on mouse movement
184 // for resizing by dragging the separators 185 // for resizing by dragging the separators
185 int mResizeAnchor; // uint, ulong? the mouse down separator left 186 int mResizeAnchor; // uint, ulong? the mouse down separator left
186 int mRubberBandAnchor; // for erasing rubber bands 187 int mRubberBandAnchor; // for erasing rubber bands
187 // data used for resizing. 188 // data used for resizing.
188 // as they are beeded by each mouse move while resizing, we store them here, 189 // as they are beeded by each mouse move while resizing, we store them here,
189 // saving 8 calculations in each mouse move. 190 // saving 8 calculations in each mouse move.
190 int colspace; // amount of space between items pr column 191 int colspace; // amount of space between items pr column
191 uint first; // the first col to anchor at for painting rubber bands 192 uint first; // the first col to anchor at for painting rubber bands
192 int firstX; // X position of first in pixel 193 int firstX; // X position of first in pixel
193 int pressed; // the colummn that was pressed on at resizing start 194 int pressed; // the colummn that was pressed on at resizing start
194 int span; // pressed - first 195 int span; // pressed - first
195 // key completion 196 // key completion
196 QString mCompText; // current completion string 197 QString mCompText; // current completion string
197 QDateTime mCompUpdated; // ...was updated at this time 198 QDateTime mCompUpdated; // ...was updated at this time
198}; 199};
199 200
200class CardViewItemPrivate 201class CardViewItemPrivate
201{ 202{
202 public: 203 public:
203 CardViewItemPrivate() : 204 CardViewItemPrivate() :
204 mSelected( false ), 205 mSelected( false ),
205 x( 0 ), 206 x( 0 ),
206 y( 0 ){}; 207 y( 0 ){};
207 208
208 209
209 QString mCaption; 210 QString mCaption;
210 QPtrList< CardViewItem::Field > mFieldList; 211 QPtrList< CardViewItem::Field > mFieldList;
211 bool mSelected; 212 bool mSelected;
212 int x; // horizontal position, set by the view 213 int x; // horizontal position, set by the view
213 int y; // vertical position, set by the view 214 int y; // vertical position, set by the view
214 int maxLabelWidth; // the width of the widest label, according to the view font. 215 int maxLabelWidth; // the width of the widest label, according to the view font.
215 int hcache; // height cache 216 int hcache; // height cache
216}; 217};
217//END Private Data 218//END Private Data
218 219
219//BEGIN CardViewItem 220//BEGIN CardViewItem
220 221
221CardViewItem::CardViewItem(CardView *parent, QString caption) 222CardViewItem::CardViewItem(CardView *parent, QString caption)
222 : d(new CardViewItemPrivate()), mView(parent) 223 : d(new CardViewItemPrivate()), mView(parent)
223{ 224{
224 d->mCaption = caption; 225 d->mCaption = caption;
225 226
226 initialize(); 227 initialize();
227} 228}
228 229
229CardViewItem::~CardViewItem() 230CardViewItem::~CardViewItem()
230{ 231{
231 // Remove ourself from the view 232 // Remove ourself from the view
232 if (mView != 0) 233 if (mView != 0)
233 mView->takeItem(this); 234 mView->takeItem(this);
234 235
235 delete d; 236 delete d;
236 d = 0; 237 d = 0;
237} 238}
238 239
239void CardViewItem::initialize() 240void CardViewItem::initialize()
240{ 241{
241 d->mSelected = false; 242 d->mSelected = false;
242 d->mFieldList.setAutoDelete(true); 243 d->mFieldList.setAutoDelete(true);
243 d->maxLabelWidth = 0; 244 d->maxLabelWidth = 0;
244 d->hcache=0; 245 d->hcache=0;
245 246
246 //calcRect(); 247 //calcRect();
247 248
248 // Add ourself to the view 249 // Add ourself to the view
249 if (mView != 0) 250 if (mView != 0)
250 mView->insertItem(this); 251 mView->insertItem(this);
251} 252}
252 253
253void CardViewItem::paintCard(QPainter *p, QColorGroup &cg) 254void CardViewItem::paintCard(QPainter *p, QColorGroup &cg)
254{ 255{
255 256
256 if (!mView) 257 if (!mView)
257 return; 258 return;
258 259
259 QPen pen; 260 QPen pen;
260 QBrush brush; 261 QBrush brush;
261 QFontMetrics fm = *(mView->d->mFm); 262 QFontMetrics fm = *(mView->d->mFm);
262 QFontMetrics bFm = *(mView->d->mBFm); 263 QFontMetrics bFm = *(mView->d->mBFm);
263 bool drawLabels = mView->d->mDrawFieldLabels; 264 bool drawLabels = mView->d->mDrawFieldLabels;
264 bool drawBorder = mView->d->mDrawCardBorder; 265 bool drawBorder = mView->d->mDrawCardBorder;
265 int mg = mView->itemMargin(); 266 int mg = mView->itemMargin();
266 int w = mView->itemWidth() - (mg*2); 267 int w = mView->itemWidth() - (mg*2);
267 int h = height() - (mg*2); 268 int h = height() - (mg*2);
268 const int colonWidth( fm.width(":") ); 269 const int colonWidth( fm.width(":") );
269 int labelXPos = 2 + mg; 270 int labelXPos = 2 + mg;
270 int labelWidth = QMIN( w/2 - 4 - mg, d->maxLabelWidth + colonWidth + 4 ); 271 int labelWidth = QMIN( w/2 - 4 - mg, d->maxLabelWidth + colonWidth + 4 );
271 int valueXPos = labelWidth + 4 + mg; 272 int valueXPos = labelWidth + 4 + mg;
272 int valueWidth = w - labelWidth - 4 - mg; 273 int valueWidth = w - labelWidth - 4 - mg;
273 274
274 p->setFont( mView->font() ); 275 p->setFont( mView->font() );
275 labelWidth -= colonWidth; // extra space for the colon 276 labelWidth -= colonWidth; // extra space for the colon
276 277
277 if (!drawLabels) 278 if (!drawLabels)
278 { 279 {
279 valueXPos = labelXPos; 280 valueXPos = labelXPos;
280 valueWidth = w - 4; 281 valueWidth = w - 4;
281 } 282 }
282 283
283 // Draw a simple box 284 // Draw a simple box
284 if (isSelected()) 285 if (isSelected())
285 pen = QPen(cg.highlight(), 1); 286 pen = QPen(cg.highlight(), 1);
286 else 287 else
287 pen = QPen(cg.button(), 1); 288 pen = QPen(cg.button(), 1);
288 p->setPen(pen); 289 p->setPen(pen);
289 290
290 // Draw the border - this is only draw if the user asks for it. 291 // Draw the border - this is only draw if the user asks for it.
291 if (drawBorder) 292 if (drawBorder)
@@ -386,512 +387,514 @@ const QString &CardViewItem::caption() const
386int CardViewItem::height( bool allowCache ) const 387int CardViewItem::height( bool allowCache ) const
387{ 388{
388 // use cache 389 // use cache
389 if ( allowCache && d->hcache ) 390 if ( allowCache && d->hcache )
390 return d->hcache; 391 return d->hcache;
391 392
392 // Base height: 393 // Base height:
393 // 2 for line width 394 // 2 for line width
394 // 2 for top caption pad 395 // 2 for top caption pad
395 // 2 for bottom caption pad 396 // 2 for bottom caption pad
396 // 2 pad for the end 397 // 2 pad for the end
397 // + 2 times the advised margin 398 // + 2 times the advised margin
398 int baseHeight = 8 + ( 2 * mView->itemMargin() ); 399 int baseHeight = 8 + ( 2 * mView->itemMargin() );
399 400
400 // size of font for each field 401 // size of font for each field
401 // 2 pad for each field 402 // 2 pad for each field
402 403
403 // anders: if the view does not show empty fields, check for value 404 // anders: if the view does not show empty fields, check for value
404 bool sef = mView->showEmptyFields(); 405 bool sef = mView->showEmptyFields();
405 int fh = mView->d->mFm->height();//lineSpacing(); // font height 406 int fh = mView->d->mFm->height();//lineSpacing(); // font height
406 //int sp = QMAX( 0, 2- mView->d->mFm->leading() ); // field spacing NOTE make a property 407 //int sp = QMAX( 0, 2- mView->d->mFm->leading() ); // field spacing NOTE make a property
407 int fieldHeight = 0; 408 int fieldHeight = 0;
408 int lines; 409 int lines;
409 int maxLines( mView->maxFieldLines() ); 410 int maxLines( mView->maxFieldLines() );
410 QPtrListIterator< CardViewItem::Field > iter(d->mFieldList); 411 QPtrListIterator< CardViewItem::Field > iter(d->mFieldList);
411 for (iter.toFirst(); iter.current(); ++iter) 412 for (iter.toFirst(); iter.current(); ++iter)
412 { 413 {
413 if ( !sef && (*iter)->second.isEmpty() ) 414 if ( !sef && (*iter)->second.isEmpty() )
414 continue; 415 continue;
415 lines = QMIN( (*iter)->second.contains('\n') + 1, maxLines ); 416 lines = QMIN( (*iter)->second.contains('\n') + 1, maxLines );
416 fieldHeight += ( lines * fh ) + 2;//sp; 417 fieldHeight += ( lines * fh ) + 2;//sp;
417 } 418 }
418 419
419 // height of caption font (bold) 420 // height of caption font (bold)
420 fieldHeight += mView->d->mBFm->height(); 421 fieldHeight += mView->d->mBFm->height();
421 d->hcache = baseHeight + fieldHeight; 422 d->hcache = baseHeight + fieldHeight;
422 return d->hcache; 423 return d->hcache;
423} 424}
424 425
425bool CardViewItem::isSelected() const 426bool CardViewItem::isSelected() const
426{ 427{
427 return d->mSelected; 428 return d->mSelected;
428} 429}
429 430
430void CardViewItem::setSelected(bool selected) 431void CardViewItem::setSelected(bool selected)
431{ 432{
432 d->mSelected = selected; 433 d->mSelected = selected;
433} 434}
434 435
435void CardViewItem::insertField(const QString &label, const QString &value) 436void CardViewItem::insertField(const QString &label, const QString &value)
436{ 437{
437 CardViewItem::Field *f = new CardViewItem::Field(label, value); 438 CardViewItem::Field *f = new CardViewItem::Field(label, value);
438 d->mFieldList.append(f); 439 d->mFieldList.append(f);
439 d->hcache=0; 440 d->hcache=0;
440 441
441 if (mView) 442 if (mView)
442 { 443 {
443 mView->setLayoutDirty(true); 444 mView->setLayoutDirty(true);
444 d->maxLabelWidth = QMAX( mView->d->mFm->width( label ), d->maxLabelWidth ); 445 d->maxLabelWidth = QMAX( mView->d->mFm->width( label ), d->maxLabelWidth );
445 } 446 }
446} 447}
447 448
448void CardViewItem::removeField(const QString &label) 449void CardViewItem::removeField(const QString &label)
449{ 450{
450 CardViewItem::Field *f; 451 CardViewItem::Field *f;
451 452
452 QPtrListIterator< CardViewItem::Field > iter(d->mFieldList); 453 QPtrListIterator< CardViewItem::Field > iter(d->mFieldList);
453 for (iter.toFirst(); iter.current(); ++iter) 454 for (iter.toFirst(); iter.current(); ++iter)
454 { 455 {
455 f = *iter; 456 f = *iter;
456 if (f->first == label) 457 if (f->first == label)
457 break; 458 break;
458 } 459 }
459 460
460 if (*iter) 461 if (*iter)
461 d->mFieldList.remove(*iter); 462 d->mFieldList.remove(*iter);
462 d->hcache = 0; 463 d->hcache = 0;
463 464
464 if (mView) 465 if (mView)
465 mView->setLayoutDirty(true); 466 mView->setLayoutDirty(true);
466} 467}
467 468
468void CardViewItem::clearFields() 469void CardViewItem::clearFields()
469{ 470{
470 d->mFieldList.clear(); 471 d->mFieldList.clear();
471 d->hcache = 0; 472 d->hcache = 0;
472 473
473 if (mView) 474 if (mView)
474 mView->setLayoutDirty(true); 475 mView->setLayoutDirty(true);
475} 476}
476 477
477QString CardViewItem::trimString(const QString &text, int width, 478QString CardViewItem::trimString(const QString &text, int width,
478 QFontMetrics &fm) 479 QFontMetrics &fm)
479{ 480{
480 if (fm.width(text) <= width) 481 if (fm.width(text) <= width)
481 return text; 482 return text;
482 483
483 QString dots = "..."; 484 QString dots = "...";
484 int dotWidth = fm.width(dots); 485 int dotWidth = fm.width(dots);
485 QString trimmed; 486 QString trimmed;
486 int charNum = 0; 487 int charNum = 0;
487 488
488 while (fm.width(trimmed) + dotWidth < width) 489 while (fm.width(trimmed) + dotWidth < width)
489 { 490 {
490 trimmed += text[charNum]; 491 trimmed += text[charNum];
491 charNum++; 492 charNum++;
492 } 493 }
493 494
494 // Now trim the last char, since it put the width over the top 495 // Now trim the last char, since it put the width over the top
495 trimmed = trimmed.left(trimmed.length()-1); 496 trimmed = trimmed.left(trimmed.length()-1);
496 trimmed += dots; 497 trimmed += dots;
497 498
498 return trimmed; 499 return trimmed;
499} 500}
500 501
501CardViewItem *CardViewItem::nextItem() 502CardViewItem *CardViewItem::nextItem()
502{ 503{
503 CardViewItem *item = 0; 504 CardViewItem *item = 0;
504 505
505 if (mView) 506 if (mView)
506 item = mView->itemAfter(this); 507 item = mView->itemAfter(this);
507 508
508 return item; 509 return item;
509} 510}
510 511
511void CardViewItem::repaintCard() 512void CardViewItem::repaintCard()
512{ 513{
513 if (mView) 514 if (mView)
514 mView->repaintItem(this); 515 mView->repaintItem(this);
515} 516}
516 517
517void CardViewItem::setCaption(const QString &caption) 518void CardViewItem::setCaption(const QString &caption)
518{ 519{
519 d->mCaption = caption; 520 d->mCaption = caption;
520 repaintCard(); 521 repaintCard();
521} 522}
522 523
523QString CardViewItem::fieldValue(const QString &label) 524QString CardViewItem::fieldValue(const QString &label)
524{ 525{
525 QPtrListIterator< CardViewItem::Field > iter(d->mFieldList); 526 QPtrListIterator< CardViewItem::Field > iter(d->mFieldList);
526 for (iter.toFirst(); iter.current(); ++iter) 527 for (iter.toFirst(); iter.current(); ++iter)
527 if ((*iter)->first == label) 528 if ((*iter)->first == label)
528 return (*iter)->second; 529 return (*iter)->second;
529 530
530 return QString(); 531 return QString();
531} 532}
532 533
533 534
534void CardViewItem::showFullString( const QPoint &itempos, CardViewTip *tip ) 535void CardViewItem::showFullString( const QPoint &itempos, CardViewTip *tip )
535{ 536{
536 bool trimmed( false ); 537 bool trimmed( false );
537 QString s; 538 QString s;
538 int mrg = mView->itemMargin(); 539 int mrg = mView->itemMargin();
539 int y = mView->d->mBFm->height() + 6 + mrg; 540 int y = mView->d->mBFm->height() + 6 + mrg;
540 int w = mView->itemWidth() - (2*mrg); 541 int w = mView->itemWidth() - (2*mrg);
541 int lw; 542 int lw;
542 bool drawLabels = mView->drawFieldLabels(); 543 bool drawLabels = mView->drawFieldLabels();
543 bool isLabel = drawLabels && itempos.x() < w/2 ? true : false; 544 bool isLabel = drawLabels && itempos.x() < w/2 ? true : false;
544 545
545 if ( itempos.y() < y ) 546 if ( itempos.y() < y )
546 { 547 {
547 if ( itempos.y() < 8 + mrg || itempos.y() > y - 4 ) 548 if ( itempos.y() < 8 + mrg || itempos.y() > y - 4 )
548 return; 549 return;
549 // this is the caption 550 // this is the caption
550 s = caption(); 551 s = caption();
551 trimmed = mView->d->mBFm->width( s ) > w - 4; 552 trimmed = mView->d->mBFm->width( s ) > w - 4;
552 y = 2 + mrg; 553 y = 2 + mrg;
553 lw = 0; 554 lw = 0;
554 isLabel=true; 555 isLabel=true;
555 } else { 556 } else {
556 // find the field 557 // find the field
557 Field *f = fieldAt( itempos ); 558 Field *f = fieldAt( itempos );
558 if ( !f || ( !mView->showEmptyFields() && f->second.isEmpty() ) ) 559 if ( !f || ( !mView->showEmptyFields() && f->second.isEmpty() ) )
559 return; 560 return;
560 561
561 // y position: 562 // y position:
562 // header font height + 4px hader margin + 2px leading + item margin 563 // header font height + 4px hader margin + 2px leading + item margin
563 // + actual field index * (fontheight + 2px leading) 564 // + actual field index * (fontheight + 2px leading)
564 int maxLines = mView->maxFieldLines(); 565 int maxLines = mView->maxFieldLines();
565 bool se = mView->showEmptyFields(); 566 bool se = mView->showEmptyFields();
566 int fh = mView->d->mFm->height(); 567 int fh = mView->d->mFm->height();
567// { 568// {
568 Field *_f; 569 Field *_f;
569 for (_f = d->mFieldList.first(); _f != f; _f = d->mFieldList.next()) 570 for (_f = d->mFieldList.first(); _f != f; _f = d->mFieldList.next())
570 if ( se || ! _f->second.isEmpty() ) 571 if ( se || ! _f->second.isEmpty() )
571 y += ( QMIN(_f->second.contains('\n')+1, maxLines) * fh ) + 2; 572 y += ( QMIN(_f->second.contains('\n')+1, maxLines) * fh ) + 2;
572// } 573// }
573 if ( isLabel && itempos.y() > y + fh ) 574 if ( isLabel && itempos.y() > y + fh )
574 return; 575 return;
575 // label or data? 576 // label or data?
576 s = isLabel ? f->first : f->second; 577 s = isLabel ? f->first : f->second;
577 // trimmed? 578 // trimmed?
578 int colonWidth = mView->d->mFm->width(":"); 579 int colonWidth = mView->d->mFm->width(":");
579 lw = drawLabels ? // label width 580 lw = drawLabels ? // label width
580 QMIN( w/2 - 4 - mrg, d->maxLabelWidth + colonWidth + 4 ) : 581 QMIN( w/2 - 4 - mrg, d->maxLabelWidth + colonWidth + 4 ) :
581 0; 582 0;
582 int mw = isLabel ? lw - colonWidth : w - lw - (mrg*2); // max width for string 583 int mw = isLabel ? lw - colonWidth : w - lw - (mrg*2); // max width for string
583 if ( isLabel ) 584 if ( isLabel )
584 { 585 {
585 trimmed = mView->d->mFm->width( s ) > mw - colonWidth; 586 trimmed = mView->d->mFm->width( s ) > mw - colonWidth;
586 } else { 587 } else {
587 QRect r( mView->d->mFm->boundingRect( 0, 0, INT_MAX, INT_MAX, Qt::AlignTop|Qt::AlignLeft, s ) ); 588 QRect r( mView->d->mFm->boundingRect( 0, 0, INT_MAX, INT_MAX, Qt::AlignTop|Qt::AlignLeft, s ) );
588 trimmed = r.width() > mw || r.height()/fh > QMIN(s.contains('\n') + 1, maxLines); 589 trimmed = r.width() > mw || r.height()/fh > QMIN(s.contains('\n') + 1, maxLines);
589 } 590 }
590 } 591 }
591 if ( trimmed ) 592 if ( trimmed )
592 { 593 {
593 tip->setFont( (isLabel && !lw) ? mView->headerFont() : mView->font() ); // if condition is true, a header 594 tip->setFont( (isLabel && !lw) ? mView->headerFont() : mView->font() ); // if condition is true, a header
594 tip->setText( s ); 595 tip->setText( s );
595 tip->adjustSize(); 596 tip->adjustSize();
596 // find a proper position 597 // find a proper position
597 int lx; 598 int lx;
598 lx = isLabel || !drawLabels ? mrg : lw + mrg + 2 /*-1*/; 599 lx = isLabel || !drawLabels ? mrg : lw + mrg + 2 /*-1*/;
599 QPoint pnt(mView->contentsToViewport( QPoint(d->x, d->y) )); 600 QPoint pnt(mView->contentsToViewport( QPoint(d->x, d->y) ));
600 pnt += QPoint(lx, y); 601 pnt += QPoint(lx, y);
601 if ( pnt.x() < 0 ) 602 if ( pnt.x() < 0 )
602 pnt.setX( 0 ); 603 pnt.setX( 0 );
603 if ( pnt.x() + tip->width() > mView->visibleWidth() ) 604 if ( pnt.x() + tip->width() > mView->visibleWidth() )
604 pnt.setX( mView->visibleWidth() - tip->width() ); 605 pnt.setX( mView->visibleWidth() - tip->width() );
605 if ( pnt.y() + tip->height() > mView->visibleHeight() ) 606 if ( pnt.y() + tip->height() > mView->visibleHeight() )
606 pnt.setY( QMAX( 0, mView->visibleHeight() - tip->height() ) ); 607 pnt.setY( QMAX( 0, mView->visibleHeight() - tip->height() ) );
607 // show 608 // show
608 tip->move( pnt ); 609 tip->move( pnt );
609 tip->show(); 610 tip->show();
610 } 611 }
611} 612}
612 613
613CardViewItem::Field *CardViewItem::fieldAt( const QPoint & itempos ) const 614CardViewItem::Field *CardViewItem::fieldAt( const QPoint & itempos ) const
614{ 615{
615 int ypos = mView->d->mBFm->height() + 7 + mView->d->mItemMargin; 616 int ypos = mView->d->mBFm->height() + 7 + mView->d->mItemMargin;
616 int iy = itempos.y(); 617 int iy = itempos.y();
617 // skip below caption 618 // skip below caption
618 if ( iy <= ypos ) 619 if ( iy <= ypos )
619 return 0; 620 return 0;
620 // try find a field 621 // try find a field
621 bool showEmpty = mView->showEmptyFields(); 622 bool showEmpty = mView->showEmptyFields();
622 int fh = mView->d->mFm->height(); 623 int fh = mView->d->mFm->height();
623 int maxLines = mView->maxFieldLines(); 624 int maxLines = mView->maxFieldLines();
624 Field *f; 625 Field *f;
625 for ( f = d->mFieldList.first(); f; f = d->mFieldList.next() ) 626 for ( f = d->mFieldList.first(); f; f = d->mFieldList.next() )
626 { 627 {
627 if ( showEmpty || !f->second.isEmpty() ) 628 if ( showEmpty || !f->second.isEmpty() )
628 ypos += ( QMIN( f->second.contains('\n')+1, maxLines ) *fh)+2; 629 ypos += ( QMIN( f->second.contains('\n')+1, maxLines ) *fh)+2;
629 if ( iy <= ypos ) 630 if ( iy <= ypos )
630 break; 631 break;
631 } 632 }
632 return f ? f : 0; 633 return f ? f : 0;
633} 634}
634//END CardViewItem 635//END CardViewItem
635 636
636//BEGIN CardView 637//BEGIN CardView
637 638
638CardView::CardView(QWidget *parent, const char *name) 639CardView::CardView(QWidget *parent, const char *name)
639 : QScrollView(parent, name), 640 : QScrollView(parent, name),
640 d(new CardViewPrivate()) 641 d(new CardViewPrivate())
641{ 642{
643 mFlagKeyPressed = false;
644 mFlagBlockKeyPressed = false;
642 d->mItemList.setAutoDelete(true); 645 d->mItemList.setAutoDelete(true);
643 d->mSeparatorList.setAutoDelete(true); 646 d->mSeparatorList.setAutoDelete(true);
644 647
645 QFont f = font(); 648 QFont f = font();
646 d->mFm = new QFontMetrics(f); 649 d->mFm = new QFontMetrics(f);
647 f.setBold(true); 650 f.setBold(true);
648 d->mHeaderFont = f; 651 d->mHeaderFont = f;
649 d->mBFm = new QFontMetrics(f); 652 d->mBFm = new QFontMetrics(f);
650 d->mTip = ( new CardViewTip( viewport() ) ), 653 d->mTip = ( new CardViewTip( viewport() ) ),
651 d->mTip->hide(); 654 d->mTip->hide();
652 d->mTimer = ( new QTimer(this, "mouseTimer") ), 655 d->mTimer = ( new QTimer(this, "mouseTimer") ),
653 656
654 viewport()->setMouseTracking( true ); 657 viewport()->setMouseTracking( true );
655 viewport()->setFocusProxy(this); 658 viewport()->setFocusProxy(this);
656 viewport()->setFocusPolicy(WheelFocus); 659 viewport()->setFocusPolicy(WheelFocus);
657 viewport()->setBackgroundMode(PaletteBase); 660 viewport()->setBackgroundMode(PaletteBase);
658 661
659 connect( d->mTimer, SIGNAL(timeout()), this, SLOT(tryShowFullText()) ); 662 connect( d->mTimer, SIGNAL(timeout()), this, SLOT(tryShowFullText()) );
660 663
661//US setBackgroundMode(PaletteBackground, PaletteBase); 664//US setBackgroundMode(PaletteBackground, PaletteBase);
662 setBackgroundMode(PaletteBackground); 665 setBackgroundMode(PaletteBackground);
663 666
664 // no reason for a vertical scrollbar 667 // no reason for a vertical scrollbar
665 setVScrollBarMode(AlwaysOff); 668 setVScrollBarMode(AlwaysOff);
666} 669}
667 670
668CardView::~CardView() 671CardView::~CardView()
669{ 672{
670 delete d->mFm; 673 delete d->mFm;
671 delete d->mBFm; 674 delete d->mBFm;
672 delete d; 675 delete d;
673 d = 0; 676 d = 0;
674} 677}
675 678
676void CardView::insertItem(CardViewItem *item) 679void CardView::insertItem(CardViewItem *item)
677{ 680{
678 d->mItemList.inSort(item); 681 d->mItemList.inSort(item);
679 setLayoutDirty(true); 682 setLayoutDirty(true);
680} 683}
681 684
682void CardView::takeItem(CardViewItem *item) 685void CardView::takeItem(CardViewItem *item)
683{ 686{
684 if ( d->mCurrentItem == item ) 687 if ( d->mCurrentItem == item )
685 d->mCurrentItem = item->nextItem(); 688 d->mCurrentItem = item->nextItem();
686 d->mItemList.take(d->mItemList.findRef(item)); 689 d->mItemList.take(d->mItemList.findRef(item));
687 690
688 setLayoutDirty(true); 691 setLayoutDirty(true);
689} 692}
690 693
691void CardView::clear() 694void CardView::clear()
692{ 695{
693 d->mItemList.clear(); 696 d->mItemList.clear();
694 697
695 setLayoutDirty(true); 698 setLayoutDirty(true);
696} 699}
697 700
698CardViewItem *CardView::currentItem() 701CardViewItem *CardView::currentItem()
699{ 702{
700 if ( ! d->mCurrentItem && d->mItemList.count() ) 703 if ( ! d->mCurrentItem && d->mItemList.count() )
701 d->mCurrentItem = d->mItemList.first(); 704 d->mCurrentItem = d->mItemList.first();
702 return d->mCurrentItem; 705 return d->mCurrentItem;
703} 706}
704 707
705void CardView::setCurrentItem( CardViewItem *item ) 708void CardView::setCurrentItem( CardViewItem *item )
706{ 709{
707 if ( !item ) 710 if ( !item )
708 return; 711 return;
709 else if ( item->cardView() != this ) 712 else if ( item->cardView() != this )
710 { 713 {
711 kdDebug(5720)<<"CardView::setCurrentItem: Item ("<<item<<") not owned! Backing out.."<<endl; 714 kdDebug(5720)<<"CardView::setCurrentItem: Item ("<<item<<") not owned! Backing out.."<<endl;
712 return; 715 return;
713 } 716 }
714 else if ( item == currentItem() ) 717 else if ( item == currentItem() )
715 { 718 {
716 return; 719 return;
717 } 720 }
718 721
719 if ( d->mSelectionMode == Single ) 722 if ( d->mSelectionMode == Single )
720 { 723 {
721 setSelected( item, true ); 724 setSelected( item, true );
722 } 725 }
723 else 726 else
724 { 727 {
725 CardViewItem *it = d->mCurrentItem; 728 CardViewItem *it = d->mCurrentItem;
726 d->mCurrentItem = item; 729 d->mCurrentItem = item;
727 if ( it ) 730 if ( it )
728 it->repaintCard(); 731 it->repaintCard();
729 item->repaintCard(); 732 item->repaintCard();
730 } 733 }
731 if ( ! d->mOnSeparator ) 734 if ( ! d->mOnSeparator )
732 ensureItemVisible( item ); 735 ensureItemVisible( item );
733 emit currentChanged( item ); 736 emit currentChanged( item );
734} 737}
735 738
736CardViewItem *CardView::itemAt(const QPoint &viewPos) 739CardViewItem *CardView::itemAt(const QPoint &viewPos)
737{ 740{
738 CardViewItem *item = 0; 741 CardViewItem *item = 0;
739 QPtrListIterator<CardViewItem> iter(d->mItemList); 742 QPtrListIterator<CardViewItem> iter(d->mItemList);
740 bool found = false; 743 bool found = false;
741 for (iter.toFirst(); iter.current() && !found; ++iter) 744 for (iter.toFirst(); iter.current() && !found; ++iter)
742 { 745 {
743 item = *iter; 746 item = *iter;
744 //if (item->d->mRect.contains(viewPos)) 747 //if (item->d->mRect.contains(viewPos))
745 if (QRect(item->d->x, item->d->y, d->mItemWidth, item->height()).contains(viewPos)) 748 if (QRect(item->d->x, item->d->y, d->mItemWidth, item->height()).contains(viewPos))
746 found = true; 749 found = true;
747 } 750 }
748 751
749 if (found) 752 if (found)
750 return item; 753 return item;
751 754
752 return 0; 755 return 0;
753} 756}
754 757
755QRect CardView::itemRect(const CardViewItem *item) 758QRect CardView::itemRect(const CardViewItem *item)
756{ 759{
757 //return item->d->mRect; 760 //return item->d->mRect;
758 return QRect(item->d->x, item->d->y, d->mItemWidth, item->height()); 761 return QRect(item->d->x, item->d->y, d->mItemWidth, item->height());
759} 762}
760 763
761void CardView::ensureItemVisible(const CardViewItem *item) 764void CardView::ensureItemVisible(const CardViewItem *item)
762{ 765{
763 ensureVisible(item->d->x , item->d->y, d->mItemSpacing, 0); 766 ensureVisible(item->d->x , item->d->y, d->mItemSpacing, 0);
764 ensureVisible(item->d->x + d->mItemWidth, item->d->y, d->mItemSpacing, 0); 767 ensureVisible(item->d->x + d->mItemWidth, item->d->y, d->mItemSpacing, 0);
765} 768}
766 769
767void CardView::repaintItem(const CardViewItem *item) 770void CardView::repaintItem(const CardViewItem *item)
768{ 771{
769 //repaintContents(item->d->mRect); 772 //repaintContents(item->d->mRect);
770 repaintContents( QRect(item->d->x, item->d->y, d->mItemWidth, item->height()) ); 773 repaintContents( QRect(item->d->x, item->d->y, d->mItemWidth, item->height()) );
771} 774}
772 775
773void CardView::setSelectionMode(CardView::SelectionMode mode) 776void CardView::setSelectionMode(CardView::SelectionMode mode)
774{ 777{
775 selectAll(false); 778 selectAll(false);
776 779
777 d->mSelectionMode = mode; 780 d->mSelectionMode = mode;
778} 781}
779 782
780CardView::SelectionMode CardView::selectionMode() const 783CardView::SelectionMode CardView::selectionMode() const
781{ 784{
782 return d->mSelectionMode; 785 return d->mSelectionMode;
783} 786}
784 787
785void CardView::selectAll(bool state) 788void CardView::selectAll(bool state)
786{ 789{
787 QPtrListIterator<CardViewItem> iter(d->mItemList); 790 QPtrListIterator<CardViewItem> iter(d->mItemList);
788 if (!state) 791 if (!state)
789 { 792 {
790 for (iter.toFirst(); iter.current(); ++iter) 793 for (iter.toFirst(); iter.current(); ++iter)
791 { 794 {
792 if ((*iter)->isSelected()) 795 if ((*iter)->isSelected())
793 { 796 {
794 (*iter)->setSelected(false); 797 (*iter)->setSelected(false);
795 (*iter)->repaintCard(); 798 (*iter)->repaintCard();
796 } 799 }
797 } 800 }
798 //emit selectionChanged(); // WARNING FIXME 801 //emit selectionChanged(); // WARNING FIXME
799 emit selectionChanged(0); 802 emit selectionChanged(0);
800 } 803 }
801 else if (d->mSelectionMode != CardView::Single) 804 else if (d->mSelectionMode != CardView::Single)
802 { 805 {
803 for (iter.toFirst(); iter.current(); ++iter) 806 for (iter.toFirst(); iter.current(); ++iter)
804 { 807 {
805 (*iter)->setSelected(true); 808 (*iter)->setSelected(true);
806 } 809 }
807 810
808 if (d->mItemList.count() > 0) 811 if (d->mItemList.count() > 0)
809 { 812 {
810 // emit, since there must have been at least one selected 813 // emit, since there must have been at least one selected
811 emit selectionChanged(); 814 emit selectionChanged();
812 //repaint();//??? 815 //repaint();//???
813 viewport()->update(); 816 viewport()->update();
814 } 817 }
815 } 818 }
816} 819}
817 820
818void CardView::setSelected(CardViewItem *item, bool selected) 821void CardView::setSelected(CardViewItem *item, bool selected)
819{ 822{
820 if ((item == 0) || (item->isSelected() == selected)) 823 if ((item == 0) || (item->isSelected() == selected))
821 return; 824 return;
822 825
823 if ( selected && d->mCurrentItem != item ) 826 if ( selected && d->mCurrentItem != item )
824 { 827 {
825 CardViewItem *it = d->mCurrentItem; 828 CardViewItem *it = d->mCurrentItem;
826 d->mCurrentItem = item; 829 d->mCurrentItem = item;
827 if ( it ) 830 if ( it )
828 it->repaintCard(); 831 it->repaintCard();
829 } 832 }
830 833
831 if (d->mSelectionMode == CardView::Single) 834 if (d->mSelectionMode == CardView::Single)
832 { 835 {
833 bool b = signalsBlocked(); 836 bool b = signalsBlocked();
834 blockSignals(true); 837 blockSignals(true);
835 selectAll(false); 838 selectAll(false);
836 blockSignals(b); 839 blockSignals(b);
837 840
838 if (selected) 841 if (selected)
839 { 842 {
840 item->setSelected(selected); 843 item->setSelected(selected);
841 item->repaintCard(); 844 item->repaintCard();
842 emit selectionChanged(); 845 emit selectionChanged();
843 emit selectionChanged(item); 846 emit selectionChanged(item);
844 } 847 }
845 else 848 else
846 { 849 {
847 emit selectionChanged(); 850 emit selectionChanged();
848 emit selectionChanged(0); 851 emit selectionChanged(0);
849 } 852 }
850 } 853 }
851 else if (d->mSelectionMode == CardView::Multi) 854 else if (d->mSelectionMode == CardView::Multi)
852 { 855 {
853 item->setSelected(selected); 856 item->setSelected(selected);
854 item->repaintCard(); 857 item->repaintCard();
855 emit selectionChanged(); 858 emit selectionChanged();
856 } 859 }
857 else if (d->mSelectionMode == CardView::Extended) 860 else if (d->mSelectionMode == CardView::Extended)
858 { 861 {
859 bool b = signalsBlocked(); 862 bool b = signalsBlocked();
860 blockSignals(true); 863 blockSignals(true);
861 selectAll(false); 864 selectAll(false);
862 blockSignals(b); 865 blockSignals(b);
863 866
864 item->setSelected(selected); 867 item->setSelected(selected);
865 item->repaintCard(); 868 item->repaintCard();
866 emit selectionChanged(); 869 emit selectionChanged();
867 } 870 }
868} 871}
869 872
870bool CardView::isSelected(CardViewItem *item) const 873bool CardView::isSelected(CardViewItem *item) const
871{ 874{
872 return (item && item->isSelected()); 875 return (item && item->isSelected());
873} 876}
874 877
875CardViewItem *CardView::selectedItem() const 878CardViewItem *CardView::selectedItem() const
876{ 879{
877 // find the first selected item 880 // find the first selected item
878 QPtrListIterator<CardViewItem> iter(d->mItemList); 881 QPtrListIterator<CardViewItem> iter(d->mItemList);
879 for (iter.toFirst(); iter.current(); ++iter) 882 for (iter.toFirst(); iter.current(); ++iter)
880 { 883 {
881 if ((*iter)->isSelected()) 884 if ((*iter)->isSelected())
882 return *iter; 885 return *iter;
883 } 886 }
884 887
885 return 0; 888 return 0;
886} 889}
887 890
888CardViewItem *CardView::firstItem() const 891CardViewItem *CardView::firstItem() const
889{ 892{
890 return d->mItemList.first(); 893 return d->mItemList.first();
891} 894}
892 895
893int CardView::childCount() const 896int CardView::childCount() const
894{ 897{
895 return d->mItemList.count(); 898 return d->mItemList.count();
896} 899}
897/*US 900/*US
@@ -1098,625 +1101,651 @@ void CardView::setItemSpacing( uint spacing )
1098} 1101}
1099 1102
1100void CardView::contentsMousePressEvent(QMouseEvent *e) 1103void CardView::contentsMousePressEvent(QMouseEvent *e)
1101{ 1104{
1102 QScrollView::contentsMousePressEvent(e); 1105 QScrollView::contentsMousePressEvent(e);
1103 1106
1104 QPoint pos = e->pos(); 1107 QPoint pos = e->pos();
1105 d->mLastClickPos = pos; 1108 d->mLastClickPos = pos;
1106 1109
1107 CardViewItem *item = itemAt(pos); 1110 CardViewItem *item = itemAt(pos);
1108 1111
1109 if (item == 0) 1112 if (item == 0)
1110 { 1113 {
1111 d->mLastClickOnItem = false; 1114 d->mLastClickOnItem = false;
1112 if ( d->mOnSeparator) 1115 if ( d->mOnSeparator)
1113 { 1116 {
1114 d->mResizeAnchor = e->x()+contentsX(); 1117 d->mResizeAnchor = e->x()+contentsX();
1115 d->colspace = (2*d->mItemSpacing) /*+ (2*d->mItemMargin)*/; 1118 d->colspace = (2*d->mItemSpacing) /*+ (2*d->mItemMargin)*/;
1116 int ccw = d->mItemWidth + d->colspace + d->mSepWidth; 1119 int ccw = d->mItemWidth + d->colspace + d->mSepWidth;
1117 d->first = (contentsX()+d->mSepWidth)/ccw; 1120 d->first = (contentsX()+d->mSepWidth)/ccw;
1118 d->pressed = (d->mResizeAnchor+d->mSepWidth)/ccw; 1121 d->pressed = (d->mResizeAnchor+d->mSepWidth)/ccw;
1119 d->span = d->pressed - d->first; 1122 d->span = d->pressed - d->first;
1120 d->firstX = d->first * ccw; 1123 d->firstX = d->first * ccw;
1121 if ( d->firstX ) d->firstX -= d->mSepWidth; // (no sep in col 0) 1124 if ( d->firstX ) d->firstX -= d->mSepWidth; // (no sep in col 0)
1122 } 1125 }
1123 else 1126 else
1124 { 1127 {
1125 selectAll(false); 1128 selectAll(false);
1126 } 1129 }
1127 return; 1130 return;
1128 } 1131 }
1129 1132
1130 d->mLastClickOnItem = true; 1133 d->mLastClickOnItem = true;
1131 1134
1132 CardViewItem *other = d->mCurrentItem; 1135 CardViewItem *other = d->mCurrentItem;
1133 setCurrentItem( item ); 1136 setCurrentItem( item );
1134 1137
1135 // Always emit the selection 1138 // Always emit the selection
1136 emit clicked(item); 1139 emit clicked(item);
1137 1140
1138 // Check the selection type and update accordingly 1141 // Check the selection type and update accordingly
1139 if (d->mSelectionMode == CardView::Single) 1142 if (d->mSelectionMode == CardView::Single)
1140 { 1143 {
1141 // make sure it isn't already selected 1144 // make sure it isn't already selected
1142 if (item->isSelected()) 1145 if (item->isSelected())
1143 return; 1146 return;
1144 1147
1145 bool b = signalsBlocked(); 1148 bool b = signalsBlocked();
1146 blockSignals(true); 1149 blockSignals(true);
1147 selectAll(false); 1150 selectAll(false);
1148 blockSignals(b); 1151 blockSignals(b);
1149 1152
1150 item->setSelected(true); 1153 item->setSelected(true);
1151 item->repaintCard(); 1154 item->repaintCard();
1152 emit selectionChanged(item); 1155 emit selectionChanged(item);
1153 } 1156 }
1154 1157
1155 else if (d->mSelectionMode == CardView::Multi) 1158 else if (d->mSelectionMode == CardView::Multi)
1156 { 1159 {
1157 // toggle the selection 1160 // toggle the selection
1158 item->setSelected(!item->isSelected()); 1161 item->setSelected(!item->isSelected());
1159 item->repaintCard(); 1162 item->repaintCard();
1160 emit selectionChanged(); 1163 emit selectionChanged();
1161 } 1164 }
1162 1165
1163 else if (d->mSelectionMode == CardView::Extended) 1166 else if (d->mSelectionMode == CardView::Extended)
1164 { 1167 {
1165 if ((e->button() & Qt::LeftButton) && 1168 if ((e->button() & Qt::LeftButton) &&
1166 (e->state() & Qt::ShiftButton)) 1169 (e->state() & Qt::ShiftButton))
1167 { 1170 {
1168 if ( item == other ) return; 1171 if ( item == other ) return;
1169 1172
1170 bool s = ! item->isSelected(); 1173 bool s = ! item->isSelected();
1171 1174
1172 if ( s && ! (e->state() & ControlButton) ) 1175 if ( s && ! (e->state() & ControlButton) )
1173 { 1176 {
1174 bool b = signalsBlocked(); 1177 bool b = signalsBlocked();
1175 blockSignals(true); 1178 blockSignals(true);
1176 selectAll(false); 1179 selectAll(false);
1177 blockSignals(b); 1180 blockSignals(b);
1178 } 1181 }
1179 1182
1180 int from, to, a, b; 1183 int from, to, a, b;
1181 a = d->mItemList.findRef( item ); 1184 a = d->mItemList.findRef( item );
1182 b = d->mItemList.findRef( other ); 1185 b = d->mItemList.findRef( other );
1183 from = a < b ? a : b; 1186 from = a < b ? a : b;
1184 to = a > b ? a : b; 1187 to = a > b ? a : b;
1185 //kdDebug()<<"selecting items "<<from<<" - "<<to<<" ( "<<s<<" )"<<endl; 1188 //kdDebug()<<"selecting items "<<from<<" - "<<to<<" ( "<<s<<" )"<<endl;
1186 CardViewItem *aItem; 1189 CardViewItem *aItem;
1187 for ( ; from <= to; from++ ) 1190 for ( ; from <= to; from++ )
1188 { 1191 {
1189 aItem = d->mItemList.at( from ); 1192 aItem = d->mItemList.at( from );
1190 aItem->setSelected( s ); 1193 aItem->setSelected( s );
1191 repaintItem( aItem ); 1194 repaintItem( aItem );
1192 } 1195 }
1193 emit selectionChanged(); 1196 emit selectionChanged();
1194 } 1197 }
1195 else if ((e->button() & Qt::LeftButton) && 1198 else if ((e->button() & Qt::LeftButton) &&
1196 (e->state() & Qt::ControlButton)) 1199 (e->state() & Qt::ControlButton))
1197 { 1200 {
1198 item->setSelected(!item->isSelected()); 1201 item->setSelected(!item->isSelected());
1199 item->repaintCard(); 1202 item->repaintCard();
1200 emit selectionChanged(); 1203 emit selectionChanged();
1201 } 1204 }
1202 1205
1203 else if (e->button() & Qt::LeftButton) 1206 else if (e->button() & Qt::LeftButton)
1204 { 1207 {
1205 bool b = signalsBlocked(); 1208 bool b = signalsBlocked();
1206 blockSignals(true); 1209 blockSignals(true);
1207 selectAll(false); 1210 selectAll(false);
1208 blockSignals(b); 1211 blockSignals(b);
1209 1212
1210 item->setSelected(true); 1213 item->setSelected(true);
1211 item->repaintCard(); 1214 item->repaintCard();
1212 emit selectionChanged(); 1215 emit selectionChanged();
1213 } 1216 }
1214 } 1217 }
1215 1218
1216} 1219}
1217 1220
1218void CardView::contentsMouseReleaseEvent(QMouseEvent *e) 1221void CardView::contentsMouseReleaseEvent(QMouseEvent *e)
1219{ 1222{
1220 QScrollView::contentsMouseReleaseEvent(e); 1223 QScrollView::contentsMouseReleaseEvent(e);
1221 1224
1222 if ( d->mResizeAnchor ) 1225 if ( d->mResizeAnchor )
1223 { 1226 {
1224 // finish the resizing: 1227 // finish the resizing:
1225 unsetCursor(); 1228 unsetCursor();
1226 // hide rubber bands 1229 // hide rubber bands
1227 int newiw = d->mItemWidth - ((d->mResizeAnchor - d->mRubberBandAnchor)/d->span); 1230 int newiw = d->mItemWidth - ((d->mResizeAnchor - d->mRubberBandAnchor)/d->span);
1228 drawRubberBands( 0 ); 1231 drawRubberBands( 0 );
1229 // we should move to reflect the new position if we are scrolled. 1232 // we should move to reflect the new position if we are scrolled.
1230 if ( contentsX() ) 1233 if ( contentsX() )
1231 { 1234 {
1232 int newX = QMAX( 0, ( d->pressed * ( newiw + d->colspace + d->mSepWidth ) ) - e->x() ); 1235 int newX = QMAX( 0, ( d->pressed * ( newiw + d->colspace + d->mSepWidth ) ) - e->x() );
1233 setContentsPos( newX, contentsY() ); 1236 setContentsPos( newX, contentsY() );
1234 } 1237 }
1235 // set new item width 1238 // set new item width
1236 setItemWidth( newiw ); 1239 setItemWidth( newiw );
1237 // reset anchors 1240 // reset anchors
1238 d->mResizeAnchor = 0; 1241 d->mResizeAnchor = 0;
1239 d->mRubberBandAnchor = 0; 1242 d->mRubberBandAnchor = 0;
1240 return; 1243 return;
1241 } 1244 }
1242 1245
1243 // If there are accel keys, we will not emit signals 1246 // If there are accel keys, we will not emit signals
1244 if ((e->state() & Qt::ShiftButton) || (e->state() & Qt::ControlButton)) 1247 if ((e->state() & Qt::ShiftButton) || (e->state() & Qt::ControlButton))
1245 return; 1248 return;
1246 1249
1247 // Get the item at this position 1250 // Get the item at this position
1248 CardViewItem *item = itemAt(e->pos()); 1251 CardViewItem *item = itemAt(e->pos());
1249 1252
1250 if (item && KABPrefs::instance()->mHonorSingleClick) 1253 if (item && KABPrefs::instance()->mHonorSingleClick)
1251 { 1254 {
1252 emit executed(item); 1255 emit executed(item);
1253 } 1256 }
1254} 1257}
1255 1258
1256void CardView::contentsMouseDoubleClickEvent(QMouseEvent *e) 1259void CardView::contentsMouseDoubleClickEvent(QMouseEvent *e)
1257{ 1260{
1258 QScrollView::contentsMouseDoubleClickEvent(e); 1261 QScrollView::contentsMouseDoubleClickEvent(e);
1259 1262
1260 CardViewItem *item = itemAt(e->pos()); 1263 CardViewItem *item = itemAt(e->pos());
1261 1264
1262 if (item) 1265 if (item)
1263 { 1266 {
1264 d->mCurrentItem = item; 1267 d->mCurrentItem = item;
1265 } 1268 }
1266 1269
1267 if (item && !KABPrefs::instance()->mHonorSingleClick) 1270 if (item && !KABPrefs::instance()->mHonorSingleClick)
1268 { 1271 {
1269 emit executed(item); 1272 emit executed(item);
1270 } else 1273 } else
1271 emit doubleClicked(item); 1274 emit doubleClicked(item);
1272} 1275}
1273 1276
1274void CardView::contentsMouseMoveEvent( QMouseEvent *e ) 1277void CardView::contentsMouseMoveEvent( QMouseEvent *e )
1275{ 1278{
1276 // resizing 1279 // resizing
1277 if ( d->mResizeAnchor ) 1280 if ( d->mResizeAnchor )
1278 { 1281 {
1279 int x = e->x(); 1282 int x = e->x();
1280 if ( x != d->mRubberBandAnchor ) 1283 if ( x != d->mRubberBandAnchor )
1281 drawRubberBands( x ); 1284 drawRubberBands( x );
1282 return; 1285 return;
1283 } 1286 }
1284 1287
1285 if (d->mLastClickOnItem && (e->state() & Qt::LeftButton) && 1288 if (d->mLastClickOnItem && (e->state() & Qt::LeftButton) &&
1286 ((e->pos() - d->mLastClickPos).manhattanLength() > 4)) { 1289 ((e->pos() - d->mLastClickPos).manhattanLength() > 4)) {
1287 1290
1288 startDrag(); 1291 startDrag();
1289 return; 1292 return;
1290 } 1293 }
1291 1294
1292 d->mTimer->start( 500 ); 1295 d->mTimer->start( 500 );
1293 1296
1294 // see if we are over a separator 1297 // see if we are over a separator
1295 // only if we actually have them painted? 1298 // only if we actually have them painted?
1296 if ( d->mDrawSeparators ) 1299 if ( d->mDrawSeparators )
1297 { 1300 {
1298 int colcontentw = d->mItemWidth + (2*d->mItemSpacing); 1301 int colcontentw = d->mItemWidth + (2*d->mItemSpacing);
1299 int colw = colcontentw + d->mSepWidth; 1302 int colw = colcontentw + d->mSepWidth;
1300 int m = e->x()%colw; 1303 int m = e->x()%colw;
1301 if ( m >= colcontentw && m > 0 ) 1304 if ( m >= colcontentw && m > 0 )
1302 { 1305 {
1303 setCursor( SplitVCursor ); // Why does this fail sometimes? 1306 setCursor( SplitVCursor ); // Why does this fail sometimes?
1304 d->mOnSeparator = true; 1307 d->mOnSeparator = true;
1305 } 1308 }
1306 else 1309 else
1307 { 1310 {
1308 setCursor( ArrowCursor ); 1311 setCursor( ArrowCursor );
1309 d->mOnSeparator = false; 1312 d->mOnSeparator = false;
1310 } 1313 }
1311 } 1314 }
1312} 1315}
1313 1316
1314void CardView::enterEvent( QEvent * ) 1317void CardView::enterEvent( QEvent * )
1315{ 1318{
1316 d->mTimer->start( 500 ); 1319 d->mTimer->start( 500 );
1317} 1320}
1318 1321
1319void CardView::leaveEvent( QEvent * ) 1322void CardView::leaveEvent( QEvent * )
1320{ 1323{
1321 d->mTimer->stop(); 1324 d->mTimer->stop();
1322 if (d->mOnSeparator) 1325 if (d->mOnSeparator)
1323 { 1326 {
1324 d->mOnSeparator = false; 1327 d->mOnSeparator = false;
1325 setCursor( ArrowCursor ); 1328 setCursor( ArrowCursor );
1326 } 1329 }
1327} 1330}
1328 1331
1329void CardView::focusInEvent( QFocusEvent * ) 1332void CardView::focusInEvent( QFocusEvent * )
1330{ 1333{
1331 if (!d->mCurrentItem && d->mItemList.count() ) 1334 if (!d->mCurrentItem && d->mItemList.count() )
1332 { 1335 {
1333 setCurrentItem( d->mItemList.first() ); 1336 setCurrentItem( d->mItemList.first() );
1334 } 1337 }
1335 else if ( d->mCurrentItem ) 1338 else if ( d->mCurrentItem )
1336 { 1339 {
1337 d->mCurrentItem->repaintCard(); 1340 d->mCurrentItem->repaintCard();
1338 } 1341 }
1339} 1342}
1340 1343
1341void CardView::focusOutEvent( QFocusEvent * ) 1344void CardView::focusOutEvent( QFocusEvent * )
1342{ 1345{
1343 if (d->mCurrentItem) 1346 if (d->mCurrentItem)
1344 d->mCurrentItem->repaintCard(); 1347 d->mCurrentItem->repaintCard();
1345} 1348}
1346 1349
1347void CardView::keyPressEvent( QKeyEvent *e ) 1350void CardView::keyPressEvent( QKeyEvent *e )
1348{ 1351{
1349 if ( ! ( childCount() && d->mCurrentItem ) ) 1352 if ( ! ( childCount() && d->mCurrentItem ) )
1350 { 1353 {
1351 e->ignore(); 1354 e->ignore();
1352 return; 1355 return;
1353 } 1356 }
1354 1357 if ( mFlagBlockKeyPressed )
1358 return;
1359 qApp->processEvents();
1360 if ( e->isAutoRepeat() && !mFlagKeyPressed ) {
1361 e->accept();
1362 return;
1363 }
1364 if (! e->isAutoRepeat() )
1365 mFlagKeyPressed = true;
1355 uint pos = d->mItemList.findRef( d->mCurrentItem ); 1366 uint pos = d->mItemList.findRef( d->mCurrentItem );
1356 CardViewItem *aItem = 0L; // item that gets the focus 1367 CardViewItem *aItem = 0L; // item that gets the focus
1357 CardViewItem *old = d->mCurrentItem; 1368 CardViewItem *old = d->mCurrentItem;
1358 1369
1359 switch ( e->key() ) 1370 switch ( e->key() )
1360 { 1371 {
1361 case Key_Up: 1372 case Key_Up:
1362 if ( pos > 0 ) 1373 if ( pos > 0 )
1363 { 1374 {
1364 aItem = d->mItemList.at( pos - 1 ); 1375 aItem = d->mItemList.at( pos - 1 );
1365 setCurrentItem( aItem ); 1376 setCurrentItem( aItem );
1366 } 1377 }
1367 break; 1378 break;
1368 case Key_Down: 1379 case Key_Down:
1369 if ( pos < d->mItemList.count() - 1 ) 1380 if ( pos < d->mItemList.count() - 1 )
1370 { 1381 {
1371 aItem = d->mItemList.at( pos + 1 ); 1382 aItem = d->mItemList.at( pos + 1 );
1372 setCurrentItem( aItem ); 1383 setCurrentItem( aItem );
1373 } 1384 }
1374 break; 1385 break;
1375 case Key_Left: 1386 case Key_Left:
1376 { 1387 {
1377 // look for an item in the previous/next column, starting from 1388 // look for an item in the previous/next column, starting from
1378 // the vertical middle of the current item. 1389 // the vertical middle of the current item.
1379 // FIXME use nice calculatd measures!!! 1390 // FIXME use nice calculatd measures!!!
1380 QPoint aPoint( d->mCurrentItem->d->x, d->mCurrentItem->d->y ); 1391 QPoint aPoint( d->mCurrentItem->d->x, d->mCurrentItem->d->y );
1381 aPoint -= QPoint( 30,-(d->mCurrentItem->height()/2) ); 1392 aPoint -= QPoint( 30,-(d->mCurrentItem->height()/2) );
1382 aItem = itemAt( aPoint ); 1393 aItem = itemAt( aPoint );
1383 // maybe we hit some space below an item 1394 // maybe we hit some space below an item
1384 while ( !aItem && aPoint.y() > 27 ) 1395 while ( !aItem && aPoint.y() > 27 )
1385 { 1396 {
1386 aPoint -= QPoint( 0, 16 ); 1397 aPoint -= QPoint( 0, 16 );
1387 aItem = itemAt( aPoint ); 1398 aItem = itemAt( aPoint );
1388 } 1399 }
1389 if ( aItem ) 1400 if ( aItem )
1390 setCurrentItem( aItem ); 1401 setCurrentItem( aItem );
1391 } 1402 }
1392 break; 1403 break;
1393 case Key_Right: 1404 case Key_Right:
1394 { 1405 {
1395 // FIXME use nice calculated measures!!! 1406 // FIXME use nice calculated measures!!!
1396 QPoint aPoint( d->mCurrentItem->d->x + d->mItemWidth, d->mCurrentItem->d->y ); 1407 QPoint aPoint( d->mCurrentItem->d->x + d->mItemWidth, d->mCurrentItem->d->y );
1397 aPoint += QPoint( 30,(d->mCurrentItem->height()/2) ); 1408 aPoint += QPoint( 30,(d->mCurrentItem->height()/2) );
1398 aItem = itemAt( aPoint ); 1409 aItem = itemAt( aPoint );
1399 while ( !aItem && aPoint.y() > 27 ) 1410 while ( !aItem && aPoint.y() > 27 )
1400 { 1411 {
1401 aPoint -= QPoint( 0, 16 ); 1412 aPoint -= QPoint( 0, 16 );
1402 aItem = itemAt( aPoint ); 1413 aItem = itemAt( aPoint );
1403 } 1414 }
1404 if ( aItem ) 1415 if ( aItem )
1405 setCurrentItem( aItem ); 1416 setCurrentItem( aItem );
1406 } 1417 }
1407 break; 1418 break;
1408 case Key_Home: 1419 case Key_Home:
1409 aItem = d->mItemList.first(); 1420 aItem = d->mItemList.first();
1410 setCurrentItem( aItem ); 1421 setCurrentItem( aItem );
1411 break; 1422 break;
1412 case Key_End: 1423 case Key_End:
1413 aItem = d->mItemList.last(); 1424 aItem = d->mItemList.last();
1414 setCurrentItem( aItem ); 1425 setCurrentItem( aItem );
1415 break; 1426 break;
1416 case Key_Prior: // PageUp 1427 case Key_Prior: // PageUp
1417 { 1428 {
1418 // QListView: "Make the item above the top visible and current" 1429 // QListView: "Make the item above the top visible and current"
1419 // TODO if contentsY(), pick the top item of the leftmost visible column 1430 // TODO if contentsY(), pick the top item of the leftmost visible column
1420 if ( contentsX() <= 0 ) 1431 if ( contentsX() <= 0 )
1421 return; 1432 return;
1422 int cw = columnWidth(); 1433 int cw = columnWidth();
1423 int theCol = ( QMAX( 0, ( contentsX()/cw) * cw ) ) + d->mItemSpacing; 1434 int theCol = ( QMAX( 0, ( contentsX()/cw) * cw ) ) + d->mItemSpacing;
1424 aItem = itemAt( QPoint( theCol + 1, d->mItemSpacing + 1 ) ); 1435 aItem = itemAt( QPoint( theCol + 1, d->mItemSpacing + 1 ) );
1425 if ( aItem ) 1436 if ( aItem )
1426 setCurrentItem( aItem ); 1437 setCurrentItem( aItem );
1427 } 1438 }
1428 break; 1439 break;
1429 case Key_Next: // PageDown 1440 case Key_Next: // PageDown
1430 { 1441 {
1431 // QListView: "Make the item below the bottom visible and current" 1442 // QListView: "Make the item below the bottom visible and current"
1432 // find the first not fully visible column. 1443 // find the first not fully visible column.
1433 // TODO: consider if a partly visible (or even hidden) item at the 1444 // TODO: consider if a partly visible (or even hidden) item at the
1434 // bottom of the rightmost column exists 1445 // bottom of the rightmost column exists
1435 int cw = columnWidth(); 1446 int cw = columnWidth();
1436 int theCol = ( (( contentsX() + visibleWidth() )/cw) * cw ) + d->mItemSpacing + 1; 1447 int theCol = ( (( contentsX() + visibleWidth() )/cw) * cw ) + d->mItemSpacing + 1;
1437 // if separators are on, we may need to we may be one column further right if only the spacing/sep is hidden 1448 // if separators are on, we may need to we may be one column further right if only the spacing/sep is hidden
1438 if ( d->mDrawSeparators && cw - (( contentsX() + visibleWidth() )%cw) <= int( d->mItemSpacing + d->mSepWidth ) ) 1449 if ( d->mDrawSeparators && cw - (( contentsX() + visibleWidth() )%cw) <= int( d->mItemSpacing + d->mSepWidth ) )
1439 theCol += cw; 1450 theCol += cw;
1440 1451
1441 // make sure this is not too far right 1452 // make sure this is not too far right
1442 while ( theCol > contentsWidth() ) 1453 while ( theCol > contentsWidth() )
1443 theCol -= columnWidth(); 1454 theCol -= columnWidth();
1444 1455
1445 aItem = itemAt( QPoint( theCol, d->mItemSpacing + 1 ) ); 1456 aItem = itemAt( QPoint( theCol, d->mItemSpacing + 1 ) );
1446 1457
1447 if ( aItem ) 1458 if ( aItem )
1448 setCurrentItem( aItem ); 1459 setCurrentItem( aItem );
1449 } 1460 }
1450 break; 1461 break;
1451 case Key_Space: 1462 case Key_Space:
1452 setSelected( d->mCurrentItem, !d->mCurrentItem->isSelected() ); 1463 setSelected( d->mCurrentItem, !d->mCurrentItem->isSelected() );
1453 emit selectionChanged(); 1464 emit selectionChanged();
1454 break; 1465 break;
1455 case Key_Return: 1466 case Key_Return:
1456 case Key_Enter: 1467 case Key_Enter:
1457 { 1468 {
1458 emit returnPressed( d->mCurrentItem ); 1469 emit returnPressed( d->mCurrentItem );
1459 emit executed( d->mCurrentItem ); 1470 emit executed( d->mCurrentItem );
1460 } 1471 }
1461 break; 1472 break;
1462 default: 1473 default:
1463 if ( (e->state() & ControlButton) && e->key() == Key_A ) 1474 if ( (e->state() & ControlButton) && e->key() == Key_A )
1464 { 1475 {
1465 // select all 1476 // select all
1466 selectAll( true ); 1477 selectAll( true );
1467 break; 1478 break;
1468 } 1479 }
1469 // if we have a string, do autosearch 1480 // if we have a string, do autosearch
1470 else if ( ! e->text().isEmpty() && e->text()[0].isPrint() ) 1481 else if ( ! e->text().isEmpty() && e->text()[0].isPrint() )
1471 { 1482 {
1472 1483
1473 } 1484 }
1474 break; 1485 break;
1475 } 1486 }
1476 // handle selection 1487 // handle selection
1477 if ( aItem ) 1488 if ( aItem )
1478 { 1489 {
1479 if ( d->mSelectionMode == CardView::Extended ) 1490 if ( d->mSelectionMode == CardView::Extended )
1480 { 1491 {
1481 if ( (e->state() & ShiftButton) ) 1492 if ( (e->state() & ShiftButton) )
1482 { 1493 {
1483 // shift button: toggle range 1494 // shift button: toggle range
1484 // if control button is pressed, leave all items 1495 // if control button is pressed, leave all items
1485 // and toggle selection current->old current 1496 // and toggle selection current->old current
1486 // otherwise, ?????? 1497 // otherwise, ??????
1487 bool s = ! aItem->isSelected(); 1498 bool s = ! aItem->isSelected();
1488 int from, to, a, b; 1499 int from, to, a, b;
1489 a = d->mItemList.findRef( aItem ); 1500 a = d->mItemList.findRef( aItem );
1490 b = d->mItemList.findRef( old ); 1501 b = d->mItemList.findRef( old );
1491 from = a < b ? a : b; 1502 from = a < b ? a : b;
1492 to = a > b ? a : b; 1503 to = a > b ? a : b;
1493 1504
1494 if ( to - from > 1 ) 1505 if ( to - from > 1 )
1495 { 1506 {
1496 bool b = signalsBlocked(); 1507 bool b = signalsBlocked();
1497 blockSignals(true); 1508 blockSignals(true);
1498 selectAll(false); 1509 selectAll(false);
1499 blockSignals(b); 1510 blockSignals(b);
1500 } 1511 }
1501 1512
1502 //kdDebug()<<"selecting items "<<from<<" - "<<to<<" ( "<<s<<" )"<<endl; 1513 //kdDebug()<<"selecting items "<<from<<" - "<<to<<" ( "<<s<<" )"<<endl;
1503 CardViewItem *item; 1514 CardViewItem *item;
1504 for ( ; from <= to; from++ ) 1515 for ( ; from <= to; from++ )
1505 { 1516 {
1506 item = d->mItemList.at( from ); 1517 item = d->mItemList.at( from );
1507 item->setSelected( s ); 1518 item->setSelected( s );
1508 repaintItem( item ); 1519 repaintItem( item );
1509 } 1520 }
1510 emit selectionChanged(); 1521 emit selectionChanged();
1511 } 1522 }
1512 else if ( (e->state() & ControlButton) ) 1523 else if ( (e->state() & ControlButton) )
1513 { 1524 {
1514 // control button: do nothing 1525 // control button: do nothing
1515 } 1526 }
1516 else 1527 else
1517 { 1528 {
1518 // no button: move selection to this item 1529 // no button: move selection to this item
1519 bool b = signalsBlocked(); 1530 bool b = signalsBlocked();
1520 blockSignals(true); 1531 blockSignals(true);
1521 selectAll(false); 1532 selectAll(false);
1522 blockSignals(b); 1533 blockSignals(b);
1523 1534
1524 setSelected( aItem, true ); 1535 setSelected( aItem, true );
1525 emit selectionChanged(); 1536 emit selectionChanged();
1526 } 1537 }
1527 } 1538 }
1528 } 1539 }
1529} 1540}
1530 1541
1531void CardView::contentsWheelEvent( QWheelEvent * e ) 1542void CardView::contentsWheelEvent( QWheelEvent * e )
1532{ 1543{
1533 scrollBy(2*e->delta()/-3, 0); 1544 scrollBy(2*e->delta()/-3, 0);
1534} 1545}
1535 1546
1536void CardView::setLayoutDirty(bool dirty) 1547void CardView::setLayoutDirty(bool dirty)
1537{ 1548{
1538 if (d->mLayoutDirty != dirty) 1549 if (d->mLayoutDirty != dirty)
1539 { 1550 {
1540 d->mLayoutDirty = dirty; 1551 d->mLayoutDirty = dirty;
1541 repaint(); 1552 repaint();
1542 } 1553 }
1543} 1554}
1544 1555
1545void CardView::setDrawCardBorder(bool enabled) 1556void CardView::setDrawCardBorder(bool enabled)
1546{ 1557{
1547 if (enabled != d->mDrawCardBorder) 1558 if (enabled != d->mDrawCardBorder)
1548 { 1559 {
1549 d->mDrawCardBorder = enabled; 1560 d->mDrawCardBorder = enabled;
1550 repaint(); 1561 repaint();
1551 } 1562 }
1552} 1563}
1553 1564
1554bool CardView::drawCardBorder() const 1565bool CardView::drawCardBorder() const
1555{ 1566{
1556 return d->mDrawCardBorder; 1567 return d->mDrawCardBorder;
1557} 1568}
1558 1569
1559void CardView::setDrawColSeparators(bool enabled) 1570void CardView::setDrawColSeparators(bool enabled)
1560{ 1571{
1561 if (enabled != d->mDrawSeparators) 1572 if (enabled != d->mDrawSeparators)
1562 { 1573 {
1563 d->mDrawSeparators = enabled; 1574 d->mDrawSeparators = enabled;
1564 setLayoutDirty(true); 1575 setLayoutDirty(true);
1565 } 1576 }
1566} 1577}
1567 1578
1568bool CardView::drawColSeparators() const 1579bool CardView::drawColSeparators() const
1569{ 1580{
1570 return d->mDrawSeparators; 1581 return d->mDrawSeparators;
1571} 1582}
1572 1583
1573void CardView::setDrawFieldLabels(bool enabled) 1584void CardView::setDrawFieldLabels(bool enabled)
1574{ 1585{
1575 if (enabled != d->mDrawFieldLabels) 1586 if (enabled != d->mDrawFieldLabels)
1576 { 1587 {
1577 d->mDrawFieldLabels = enabled; 1588 d->mDrawFieldLabels = enabled;
1578 repaint(); 1589 repaint();
1579 } 1590 }
1580} 1591}
1581 1592
1582bool CardView::drawFieldLabels() const 1593bool CardView::drawFieldLabels() const
1583{ 1594{
1584 return d->mDrawFieldLabels; 1595 return d->mDrawFieldLabels;
1585} 1596}
1586 1597
1587void CardView::setShowEmptyFields(bool show) 1598void CardView::setShowEmptyFields(bool show)
1588{ 1599{
1589 if (show != d->mShowEmptyFields) 1600 if (show != d->mShowEmptyFields)
1590 { 1601 {
1591 d->mShowEmptyFields = show; 1602 d->mShowEmptyFields = show;
1592 setLayoutDirty(true); 1603 setLayoutDirty(true);
1593 } 1604 }
1594} 1605}
1595 1606
1596bool CardView::showEmptyFields() const 1607bool CardView::showEmptyFields() const
1597{ 1608{
1598 return d->mShowEmptyFields; 1609 return d->mShowEmptyFields;
1599} 1610}
1600 1611
1601void CardView::startDrag() 1612void CardView::startDrag()
1602{ 1613{
1603 // The default implementation is a no-op. It must be 1614 // The default implementation is a no-op. It must be
1604 // reimplemented in a subclass to be useful 1615 // reimplemented in a subclass to be useful
1605} 1616}
1606void CardView::tryShowFullText() 1617void CardView::tryShowFullText()
1607{ 1618{
1608 d->mTimer->stop(); 1619 d->mTimer->stop();
1609 // if we have an item 1620 // if we have an item
1610 QPoint cpos = viewportToContents( viewport()->mapFromGlobal( QCursor::pos() ) ); 1621 QPoint cpos = viewportToContents( viewport()->mapFromGlobal( QCursor::pos() ) );
1611 CardViewItem *item = itemAt( cpos ); 1622 CardViewItem *item = itemAt( cpos );
1612 if ( item ) 1623 if ( item )
1613 { 1624 {
1614 // query it for a value to display 1625 // query it for a value to display
1615 //QString s = item ? item->caption() : "(no item)"; 1626 //QString s = item ? item->caption() : "(no item)";
1616 //kdDebug()<<"MOUSE REST: "<<s<<endl; 1627 //kdDebug()<<"MOUSE REST: "<<s<<endl;
1617 QPoint ipos = cpos - itemRect( item ).topLeft(); 1628 QPoint ipos = cpos - itemRect( item ).topLeft();
1618 item->showFullString( ipos, d->mTip ); 1629 item->showFullString( ipos, d->mTip );
1619 } 1630 }
1620} 1631}
1621 1632
1622void CardView::drawRubberBands( int pos ) 1633void CardView::drawRubberBands( int pos )
1623{ 1634{
1624 if ( pos && ((pos-d->firstX)/d->span) - d->colspace - d->mSepWidth < MIN_ITEM_WIDTH ) return; 1635 if ( pos && ((pos-d->firstX)/d->span) - d->colspace - d->mSepWidth < MIN_ITEM_WIDTH ) return;
1625 1636
1626 int tmpcw = (d->mRubberBandAnchor-d->firstX)/d->span; 1637 int tmpcw = (d->mRubberBandAnchor-d->firstX)/d->span;
1627 int x = d->firstX + tmpcw - d->mSepWidth - contentsX(); 1638 int x = d->firstX + tmpcw - d->mSepWidth - contentsX();
1628 int h = visibleHeight(); 1639 int h = visibleHeight();
1629 1640
1630 QPainter p( viewport() ); 1641 QPainter p( viewport() );
1631 p.setRasterOp( XorROP ); 1642 p.setRasterOp( XorROP );
1632 p.setPen( gray ); 1643 p.setPen( gray );
1633 p.setBrush( gray ); 1644 p.setBrush( gray );
1634 uint n = d->first; 1645 uint n = d->first;
1635 // erase 1646 // erase
1636 if ( d->mRubberBandAnchor ) 1647 if ( d->mRubberBandAnchor )
1637 do { 1648 do {
1638 p.drawRect( x, 0, 2, h ); 1649 p.drawRect( x, 0, 2, h );
1639 x += tmpcw; 1650 x += tmpcw;
1640 n++; 1651 n++;
1641 } while ( x < visibleWidth() && n < d->mSeparatorList.count() ); 1652 } while ( x < visibleWidth() && n < d->mSeparatorList.count() );
1642 // paint new 1653 // paint new
1643 if ( ! pos ) return; 1654 if ( ! pos ) return;
1644 tmpcw = (pos - d->firstX)/d->span; 1655 tmpcw = (pos - d->firstX)/d->span;
1645 n = d->first; 1656 n = d->first;
1646 x = d->firstX + tmpcw - d->mSepWidth - contentsX(); 1657 x = d->firstX + tmpcw - d->mSepWidth - contentsX();
1647 do { 1658 do {
1648 p.drawRect( x, 0, 2, h ); 1659 p.drawRect( x, 0, 2, h );
1649 x += tmpcw; 1660 x += tmpcw;
1650 n++; 1661 n++;
1651 } while ( x < visibleWidth() && n < d->mSeparatorList.count() ); 1662 } while ( x < visibleWidth() && n < d->mSeparatorList.count() );
1652 d->mRubberBandAnchor = pos; 1663 d->mRubberBandAnchor = pos;
1653} 1664}
1654 1665
1655 1666
1656int CardView::itemWidth() const 1667int CardView::itemWidth() const
1657{ 1668{
1658 return d->mItemWidth; 1669 return d->mItemWidth;
1659} 1670}
1660 1671
1661void CardView::setItemWidth( int w ) 1672void CardView::setItemWidth( int w )
1662{ 1673{
1663 if ( w == d->mItemWidth ) 1674 if ( w == d->mItemWidth )
1664 return; 1675 return;
1665 if ( w < MIN_ITEM_WIDTH ) 1676 if ( w < MIN_ITEM_WIDTH )
1666 w = MIN_ITEM_WIDTH; 1677 w = MIN_ITEM_WIDTH;
1667 d->mItemWidth = w; 1678 d->mItemWidth = w;
1668 setLayoutDirty( true ); 1679 setLayoutDirty( true );
1669#ifndef KAB_EMBEDDED 1680#ifndef KAB_EMBEDDED
1670 updateContents(); 1681 updateContents();
1671#else //KAB_EMBEDDED 1682#else //KAB_EMBEDDED
1672//US updateContents( d->contentsX(), d->contentsY(), visibleWidth(), visibleHeight() ); 1683//US updateContents( d->contentsX(), d->contentsY(), visibleWidth(), visibleHeight() );
1673qDebug("CardView::setItemWidth has to be verified"); 1684qDebug("CardView::setItemWidth has to be verified");
1674 updateContents( contentsX(), contentsY(), visibleWidth(), visibleHeight() ); 1685 updateContents( contentsX(), contentsY(), visibleWidth(), visibleHeight() );
1675#endif //KAB_EMBEDDED 1686#endif //KAB_EMBEDDED
1676} 1687}
1677 1688
1678void CardView::setHeaderFont( const QFont &fnt ) 1689void CardView::setHeaderFont( const QFont &fnt )
1679{ 1690{
1680 d->mHeaderFont = fnt; 1691 d->mHeaderFont = fnt;
1681 delete d->mBFm; 1692 delete d->mBFm;
1682 d->mBFm = new QFontMetrics( fnt ); 1693 d->mBFm = new QFontMetrics( fnt );
1683} 1694}
1684 1695
1685QFont CardView::headerFont() const 1696QFont CardView::headerFont() const
1686{ 1697{
1687 return d->mHeaderFont; 1698 return d->mHeaderFont;
1688} 1699}
1689 1700
1690void CardView::setFont( const QFont &fnt ) 1701void CardView::setFont( const QFont &fnt )
1691{ 1702{
1692 QScrollView::setFont( fnt ); 1703 QScrollView::setFont( fnt );
1693 delete d->mFm; 1704 delete d->mFm;
1694 d->mFm = new QFontMetrics( fnt ); 1705 d->mFm = new QFontMetrics( fnt );
1695} 1706}
1696 1707
1697int CardView::separatorWidth() 1708int CardView::separatorWidth()
1698{ 1709{
1699 return d->mSepWidth; 1710 return d->mSepWidth;
1700} 1711}
1701 1712
1702void CardView::setSeparatorWidth( int width ) 1713void CardView::setSeparatorWidth( int width )
1703{ 1714{
1704 d->mSepWidth = width; 1715 d->mSepWidth = width;
1705 setLayoutDirty( true ); // hmm, actually I could just adjust the x'es... 1716 setLayoutDirty( true ); // hmm, actually I could just adjust the x'es...
1706} 1717}
1707 1718
1708int CardView::maxFieldLines() const 1719int CardView::maxFieldLines() const
1709{ 1720{
1710 return d->mMaxFieldLines; 1721 return d->mMaxFieldLines;
1711} 1722}
1712 1723
1713void CardView::setMaxFieldLines( int howmany ) 1724void CardView::setMaxFieldLines( int howmany )
1714{ 1725{
1715 d->mMaxFieldLines = howmany ? howmany : INT_MAX; 1726 d->mMaxFieldLines = howmany ? howmany : INT_MAX;
1716 // FIXME update, forcing the items to recalc height!! 1727 // FIXME update, forcing the items to recalc height!!
1717} 1728}
1729
1730void CardView::keyReleaseEvent ( QKeyEvent * e )
1731{
1732 if ( mFlagBlockKeyPressed )
1733 return;
1734 if ( !e->isAutoRepeat() ) {
1735 mFlagBlockKeyPressed = true;
1736 qApp->processEvents();
1737 mFlagBlockKeyPressed = false;
1738 mFlagKeyPressed = false;
1739 }
1740 QScrollView::keyReleaseEvent ( e );
1741}
1742
1743
1744
1745
1746
1718//END Cardview 1747//END Cardview
1719 1748
1720#ifndef KAB_EMBEDDED 1749#ifndef KAB_EMBEDDED
1721#include "cardview.moc" 1750#include "cardview.moc"
1722#endif //KAB_EMBEDDED 1751#endif //KAB_EMBEDDED
diff --git a/kaddressbook/views/cardview.h b/kaddressbook/views/cardview.h
index 37dddb6..2ea3771 100644
--- a/kaddressbook/views/cardview.h
+++ b/kaddressbook/views/cardview.h
@@ -152,322 +152,325 @@ class CardView : public QScrollView
152{ 152{
153 friend class CardViewItem; 153 friend class CardViewItem;
154 154
155 Q_OBJECT 155 Q_OBJECT
156 156
157 public: 157 public:
158 /** Constructor. 158 /** Constructor.
159 */ 159 */
160 CardView(QWidget *parent, const char *name); 160 CardView(QWidget *parent, const char *name);
161 virtual ~CardView(); 161 virtual ~CardView();
162 162
163 /** Inserts the item into the card view. This method does not have 163 /** Inserts the item into the card view. This method does not have
164 * to be called if you created the item with a proper parent. Once 164 * to be called if you created the item with a proper parent. Once
165 * inserted, the CardView takes ownership of the item. 165 * inserted, the CardView takes ownership of the item.
166 */ 166 */
167 void insertItem(CardViewItem *item); 167 void insertItem(CardViewItem *item);
168 168
169 /** Takes the item from the view. The item will not be deleted and 169 /** Takes the item from the view. The item will not be deleted and
170 * ownership of the item is returned to the caller. 170 * ownership of the item is returned to the caller.
171 */ 171 */
172 void takeItem(CardViewItem *item); 172 void takeItem(CardViewItem *item);
173 173
174 /** Clears the view and deletes all card view items 174 /** Clears the view and deletes all card view items
175 */ 175 */
176 void clear(); 176 void clear();
177 177
178 /** @return The current item, the item that has the focus. 178 /** @return The current item, the item that has the focus.
179 * Whenever the view has focus, this item has a focus rectangle painted 179 * Whenever the view has focus, this item has a focus rectangle painted
180 * at it's border. 180 * at it's border.
181 * @sa setCurrentItem() 181 * @sa setCurrentItem()
182 */ 182 */
183 CardViewItem *currentItem(); 183 CardViewItem *currentItem();
184 184
185 /** Sets the CardViewItem @p item to the current item in the view. 185 /** Sets the CardViewItem @p item to the current item in the view.
186 */ 186 */
187 void setCurrentItem( CardViewItem *item ); 187 void setCurrentItem( CardViewItem *item );
188 188
189 /** @return The item found at the given point, or 0 if there is no item 189 /** @return The item found at the given point, or 0 if there is no item
190 * at that point. 190 * at that point.
191 */ 191 */
192 CardViewItem *itemAt(const QPoint &viewPos); 192 CardViewItem *itemAt(const QPoint &viewPos);
193 193
194 /** @return The bounding rect of the given item. 194 /** @return The bounding rect of the given item.
195 */ 195 */
196 QRect itemRect(const CardViewItem *item); 196 QRect itemRect(const CardViewItem *item);
197 197
198 /** Ensures that the given item is in the viewable area of the widget 198 /** Ensures that the given item is in the viewable area of the widget
199 */ 199 */
200 void ensureItemVisible(const CardViewItem *item); 200 void ensureItemVisible(const CardViewItem *item);
201 201
202 /** Repaints the given item. 202 /** Repaints the given item.
203 */ 203 */
204 void repaintItem(const CardViewItem *item); 204 void repaintItem(const CardViewItem *item);
205 205
206 enum SelectionMode { Single, Multi, Extended, NoSelection }; 206 enum SelectionMode { Single, Multi, Extended, NoSelection };
207 207
208 /** Sets the selection mode. 208 /** Sets the selection mode.
209 * 209 *
210 * @see QListView 210 * @see QListView
211 */ 211 */
212 void setSelectionMode(SelectionMode mode); 212 void setSelectionMode(SelectionMode mode);
213 213
214 /** @return The current selection mode. 214 /** @return The current selection mode.
215 */ 215 */
216 SelectionMode selectionMode() const; 216 SelectionMode selectionMode() const;
217 217
218 /** Selects or deselects the given item. This method honors the current 218 /** Selects or deselects the given item. This method honors the current
219 * selection mode, so if other items are selected, they may be unselected. 219 * selection mode, so if other items are selected, they may be unselected.
220 */ 220 */
221 void setSelected(CardViewItem *item, bool selected); 221 void setSelected(CardViewItem *item, bool selected);
222 222
223 /** Selects or deselects all items. 223 /** Selects or deselects all items.
224 */ 224 */
225 void selectAll(bool state); 225 void selectAll(bool state);
226 226
227 /** @return True if the given item is selected, false otherwise. 227 /** @return True if the given item is selected, false otherwise.
228 */ 228 */
229 bool isSelected(CardViewItem *item) const; 229 bool isSelected(CardViewItem *item) const;
230 230
231 /** @return The first selected item. In single select mode, this will be 231 /** @return The first selected item. In single select mode, this will be
232 * the only selected item, in other modes this will be the first selected 232 * the only selected item, in other modes this will be the first selected
233 * item, but others may exist. 0 if no item is selected. 233 * item, but others may exist. 0 if no item is selected.
234 */ 234 */
235 CardViewItem *selectedItem() const; 235 CardViewItem *selectedItem() const;
236 236
237 /** @return The first item in the view. This may be 0 if no items have 237 /** @return The first item in the view. This may be 0 if no items have
238 * been inserted. This method combined with CardViewItem::nextItem() 238 * been inserted. This method combined with CardViewItem::nextItem()
239 * can be used to iterator through the list of items. 239 * can be used to iterator through the list of items.
240 */ 240 */
241 CardViewItem *firstItem() const; 241 CardViewItem *firstItem() const;
242 242
243 /** @return The item after the given item or 0 if the item is the last 243 /** @return The item after the given item or 0 if the item is the last
244 * item. 244 * item.
245 */ 245 */
246 CardViewItem *itemAfter(CardViewItem *item); 246 CardViewItem *itemAfter(CardViewItem *item);
247 247
248 /** @return The number of items in the view. 248 /** @return The number of items in the view.
249 */ 249 */
250 int childCount() const; 250 int childCount() const;
251 251
252 /** Attempts to find the first item matching the params. 252 /** Attempts to find the first item matching the params.
253 * 253 *
254 * @param text The text to match. 254 * @param text The text to match.
255 * @param label The label of the field to match against. 255 * @param label The label of the field to match against.
256 * @param compare The compare method to use in doing the search. 256 * @param compare The compare method to use in doing the search.
257 * 257 *
258 * @return The first matching item, or 0 if no items match. 258 * @return The first matching item, or 0 if no items match.
259 */ 259 */
260/*US 260/*US
261 CardViewItem *findItem(const QString &text, const QString &label, 261 CardViewItem *findItem(const QString &text, const QString &label,
262 Qt::StringComparisonMode compare = Qt::BeginsWith); 262 Qt::StringComparisonMode compare = Qt::BeginsWith);
263*/ 263*/
264 264
265 /** Returns the amounts of pixels required for one column. 265 /** Returns the amounts of pixels required for one column.
266 * This depends on wheather drawSeparators is enabled: 266 * This depends on wheather drawSeparators is enabled:
267 * If so, it is itemWidth + 2*itemSpacing + separatorWidth 267 * If so, it is itemWidth + 2*itemSpacing + separatorWidth
268 * If not, it is itemWidth + itemSpacing 268 * If not, it is itemWidth + itemSpacing
269 * @see itemWidth(), setItemWidth(), itemSpacing() and setItemSpacing() 269 * @see itemWidth(), setItemWidth(), itemSpacing() and setItemSpacing()
270 */ 270 */
271 uint columnWidth(); 271 uint columnWidth();
272 272
273 /** Sets if the border around a card should be draw. The border is a thing 273 /** Sets if the border around a card should be draw. The border is a thing
274 * (1 or 2 pixel) line that bounds the card. When drawn, it shows when 274 * (1 or 2 pixel) line that bounds the card. When drawn, it shows when
275 * a card is highlighted and when it isn't. 275 * a card is highlighted and when it isn't.
276 */ 276 */
277 void setDrawCardBorder(bool enabled); 277 void setDrawCardBorder(bool enabled);
278 278
279 /** @return True if borders are drawn, false otherwise. 279 /** @return True if borders are drawn, false otherwise.
280 */ 280 */
281 bool drawCardBorder() const; 281 bool drawCardBorder() const;
282 282
283 /** Sets if the column separator should be drawn. The column separator 283 /** Sets if the column separator should be drawn. The column separator
284 * is a thin verticle line (1 or 2 pixels) that is used to separate the 284 * is a thin verticle line (1 or 2 pixels) that is used to separate the
285 * columns in the list view. The separator is just for esthetics and it 285 * columns in the list view. The separator is just for esthetics and it
286 * does not serve a functional purpose. 286 * does not serve a functional purpose.
287 */ 287 */
288 void setDrawColSeparators(bool enabled); 288 void setDrawColSeparators(bool enabled);
289 289
290 /** @return True if column separators are drawn, false otherwise. 290 /** @return True if column separators are drawn, false otherwise.
291 */ 291 */
292 bool drawColSeparators() const; 292 bool drawColSeparators() const;
293 293
294 /** Sets if the field labels should be drawn. The field labels are the 294 /** Sets if the field labels should be drawn. The field labels are the
295 * unique strings used to identify the fields. Sometimes drawing these 295 * unique strings used to identify the fields. Sometimes drawing these
296 * labels makes sense as a source of clarity for the user, othertimes they 296 * labels makes sense as a source of clarity for the user, othertimes they
297 * waste too much space and do not assist the user. 297 * waste too much space and do not assist the user.
298 */ 298 */
299 void setDrawFieldLabels(bool enabled); 299 void setDrawFieldLabels(bool enabled);
300 300
301 /** @return True if the field labels are drawn, false otherwise. 301 /** @return True if the field labels are drawn, false otherwise.
302 */ 302 */
303 bool drawFieldLabels() const; 303 bool drawFieldLabels() const;
304 304
305 /** Sets if fields with no value should be drawn (of cause the label only, 305 /** Sets if fields with no value should be drawn (of cause the label only,
306 * but it allows for embedded editing sometimes...) 306 * but it allows for embedded editing sometimes...)
307 */ 307 */
308 void setShowEmptyFields(bool show); 308 void setShowEmptyFields(bool show);
309 309
310 /** @return Wheather empty fields should be shown 310 /** @return Wheather empty fields should be shown
311 */ 311 */
312 bool showEmptyFields() const; 312 bool showEmptyFields() const;
313 313
314 /** @return the advisory internal margin in items. Setting a value above 1 means 314 /** @return the advisory internal margin in items. Setting a value above 1 means
315 * a space between the item contents and the focus recttangle drawn around 315 * a space between the item contents and the focus recttangle drawn around
316 * the current item. The default value is 0. 316 * the current item. The default value is 0.
317 * The value should be used by CardViewItem and derived classes. 317 * The value should be used by CardViewItem and derived classes.
318 * Note that this should not be greater than half of the minimal item width, 318 * Note that this should not be greater than half of the minimal item width,
319 * which is 80. It is currently not checked, so setting a value greater than 40 319 * which is 80. It is currently not checked, so setting a value greater than 40
320 * will probably mean a crash in the items painting routine. 320 * will probably mean a crash in the items painting routine.
321 * @private Note: I looked for a value in QStyle::PixelMetric to use, but I could 321 * @private Note: I looked for a value in QStyle::PixelMetric to use, but I could
322 * not see a usefull one. One may turn up in a future version of Qt. 322 * not see a usefull one. One may turn up in a future version of Qt.
323 */ 323 */
324 uint itemMargin(); 324 uint itemMargin();
325 325
326 /** Sets the internal item margin. @see itemMargin(). 326 /** Sets the internal item margin. @see itemMargin().
327 */ 327 */
328 void setItemMargin( uint margin ); 328 void setItemMargin( uint margin );
329 329
330 /** @return the item spacing. 330 /** @return the item spacing.
331 * The item spacing is the space (in pixels) between each item in a 331 * The item spacing is the space (in pixels) between each item in a
332 * column, between the items and column separators if drawn, and between 332 * column, between the items and column separators if drawn, and between
333 * the items and the borders of the widget. The default value is set to 333 * the items and the borders of the widget. The default value is set to
334 * 10. 334 * 10.
335 * @private Note: There is no usefull QStyle::PixelMetric to use for this atm. 335 * @private Note: There is no usefull QStyle::PixelMetric to use for this atm.
336 * An option would be using KDialog::spacingHint(). 336 * An option would be using KDialog::spacingHint().
337 */ 337 */
338 uint itemSpacing(); 338 uint itemSpacing();
339 339
340 /** Sets the item spacing. 340 /** Sets the item spacing.
341 * @see itemSpacing() 341 * @see itemSpacing()
342 */ 342 */
343 void setItemSpacing( uint spacing ); 343 void setItemSpacing( uint spacing );
344 344
345 /** @return the width made available to the card items. */ 345 /** @return the width made available to the card items. */
346 int itemWidth() const; 346 int itemWidth() const;
347 347
348 /** Sets the width made available to card items. */ 348 /** Sets the width made available to card items. */
349 void setItemWidth( int width ); 349 void setItemWidth( int width );
350 350
351 /** Sets the header font */ 351 /** Sets the header font */
352 void setHeaderFont( const QFont &fnt ); 352 void setHeaderFont( const QFont &fnt );
353 353
354 /** @return the header font */ 354 /** @return the header font */
355 QFont headerFont() const; 355 QFont headerFont() const;
356 356
357 /** @reimp */ 357 /** @reimp */
358 void setFont( const QFont &fnt ); 358 void setFont( const QFont &fnt );
359 359
360 /** Sets the column separator width */ 360 /** Sets the column separator width */
361 void setSeparatorWidth( int width ); 361 void setSeparatorWidth( int width );
362 362
363 /** @return the column separator width */ 363 /** @return the column separator width */
364 int separatorWidth(); 364 int separatorWidth();
365 365
366 /** Sets the maximum number of lines to display pr field. 366 /** Sets the maximum number of lines to display pr field.
367 If set to 0 (the default) all lines will be displayed. 367 If set to 0 (the default) all lines will be displayed.
368 */ 368 */
369 void setMaxFieldLines( int howmany ); 369 void setMaxFieldLines( int howmany );
370 370
371 /** @return the maximum number of lines pr field */ 371 /** @return the maximum number of lines pr field */
372 int maxFieldLines() const; 372 int maxFieldLines() const;
373 373
374 signals: 374 signals:
375 /** Emitted whenever the selection changes. This means a user highlighted 375 /** Emitted whenever the selection changes. This means a user highlighted
376 * a new item or unhighlighted a currently selected item. 376 * a new item or unhighlighted a currently selected item.
377 */ 377 */
378 void selectionChanged(); 378 void selectionChanged();
379 379
380 /** Same as above method, only it carries the item that was selected. This 380 /** Same as above method, only it carries the item that was selected. This
381 * method will only be emitted in single select mode, since it defineds 381 * method will only be emitted in single select mode, since it defineds
382 * which item was selected. 382 * which item was selected.
383 */ 383 */
384 void selectionChanged(CardViewItem *); 384 void selectionChanged(CardViewItem *);
385 385
386 /** This method is emitted whenever an item is clicked. 386 /** This method is emitted whenever an item is clicked.
387 */ 387 */
388 void clicked(CardViewItem *); 388 void clicked(CardViewItem *);
389 389
390 /** Emitted whenever the user 'executes' an item. This is dependant on 390 /** Emitted whenever the user 'executes' an item. This is dependant on
391 * the KDE global config. This could be a single click or a doubleclick. 391 * the KDE global config. This could be a single click or a doubleclick.
392 * Also emitted when the return key is pressed on an item. 392 * Also emitted when the return key is pressed on an item.
393 */ 393 */
394 void executed(CardViewItem *); 394 void executed(CardViewItem *);
395 395
396 /** Emitted whenever the user double clicks on an item. 396 /** Emitted whenever the user double clicks on an item.
397 */ 397 */
398 void doubleClicked(CardViewItem *); 398 void doubleClicked(CardViewItem *);
399 399
400 /** Emitted when the current item changes 400 /** Emitted when the current item changes
401 */ 401 */
402 void currentChanged( CardViewItem * ); 402 void currentChanged( CardViewItem * );
403 403
404 /** Emitted when the return key is pressed in an item. 404 /** Emitted when the return key is pressed in an item.
405 */ 405 */
406 void returnPressed( CardViewItem * ); 406 void returnPressed( CardViewItem * );
407 407
408 protected: 408 protected:
409 bool mFlagKeyPressed;
410 bool mFlagBlockKeyPressed;
411 virtual void keyPressEvent ( QKeyEvent * );
412 virtual void keyReleaseEvent ( QKeyEvent * );
409 /** Determines which cards intersect that region and tells them to paint 413 /** Determines which cards intersect that region and tells them to paint
410 * themselves. 414 * themselves.
411 */ 415 */
412 void drawContents(QPainter *p, int clipx, int clipy, int clipw, int cliph); 416 void drawContents(QPainter *p, int clipx, int clipy, int clipw, int cliph);
413 417
414 /** Sets the layout to dirty and repaints. 418 /** Sets the layout to dirty and repaints.
415 */ 419 */
416 void resizeEvent(QResizeEvent *e); 420 void resizeEvent(QResizeEvent *e);
417 421
418 /** Changes the direction the canvas scolls. 422 /** Changes the direction the canvas scolls.
419 */ 423 */
420 void contentsWheelEvent(QWheelEvent *e); 424 void contentsWheelEvent(QWheelEvent *e);
421 425
422 /** Sets the layout to dirty and calls for a repaint. 426 /** Sets the layout to dirty and calls for a repaint.
423 */ 427 */
424 void setLayoutDirty(bool dirty); 428 void setLayoutDirty(bool dirty);
425 429
426 /** Does the math based on the bounding rect of the cards to properly 430 /** Does the math based on the bounding rect of the cards to properly
427 * lay the cards out on the screen. This is only done if the layout is 431 * lay the cards out on the screen. This is only done if the layout is
428 * marked as dirty. 432 * marked as dirty.
429 */ 433 */
430 void calcLayout(); 434 void calcLayout();
431 435
432// virtual void mousePressEvent(QMouseEvent *e); 436// virtual void mousePressEvent(QMouseEvent *e);
433// virtual void mouseReleaseEvent(QMouseEvent *e); 437// virtual void mouseReleaseEvent(QMouseEvent *e);
434// virtual void mouseMoveEvent(QMouseEvent *e); 438// virtual void mouseMoveEvent(QMouseEvent *e);
435 439
436 virtual void contentsMousePressEvent(QMouseEvent *e); 440 virtual void contentsMousePressEvent(QMouseEvent *e);
437 virtual void contentsMouseMoveEvent(QMouseEvent *e); 441 virtual void contentsMouseMoveEvent(QMouseEvent *e);
438 virtual void contentsMouseReleaseEvent(QMouseEvent *e); 442 virtual void contentsMouseReleaseEvent(QMouseEvent *e);
439 virtual void contentsMouseDoubleClickEvent(QMouseEvent *e); 443 virtual void contentsMouseDoubleClickEvent(QMouseEvent *e);
440 444
441 virtual void enterEvent( QEvent * ); 445 virtual void enterEvent( QEvent * );
442 virtual void leaveEvent( QEvent * ); 446 virtual void leaveEvent( QEvent * );
443 447
444 virtual void focusInEvent( QFocusEvent * ); 448 virtual void focusInEvent( QFocusEvent * );
445 virtual void focusOutEvent( QFocusEvent * ); 449 virtual void focusOutEvent( QFocusEvent * );
446 450
447 virtual void keyPressEvent( QKeyEvent * );
448 451
449 /** Overload this method to be told when a drag should be started. 452 /** Overload this method to be told when a drag should be started.
450 * In most cases you will want to start a drag event with the currently 453 * In most cases you will want to start a drag event with the currently
451 * selected item. 454 * selected item.
452 */ 455 */
453 virtual void startDrag(); 456 virtual void startDrag();
454 457
455 private slots: 458 private slots:
456 /** Called by a timer to display a label with truncated text. 459 /** Called by a timer to display a label with truncated text.
457 * Pop up a label, if there is a field with obscured text or 460 * Pop up a label, if there is a field with obscured text or
458 * label at the cursor position. 461 * label at the cursor position.
459 */ 462 */
460 void tryShowFullText(); 463 void tryShowFullText();
461 464
462 private: 465 private:
463 /** draws and erases the rubber bands while columns are resized. 466 /** draws and erases the rubber bands while columns are resized.
464 * @p pos is the horizontal position inside the viewport to use as 467 * @p pos is the horizontal position inside the viewport to use as
465 * the anchor. 468 * the anchor.
466 * If pos is 0, only erase is done. 469 * If pos is 0, only erase is done.
467 */ 470 */
468 void drawRubberBands( int pos ); 471 void drawRubberBands( int pos );
469 472
470 CardViewPrivate *d; 473 CardViewPrivate *d;
471}; 474};
472 475
473#endif 476#endif
diff --git a/kaddressbook/views/contactlistview.cpp b/kaddressbook/views/contactlistview.cpp
index e75810e..09d9c03 100644
--- a/kaddressbook/views/contactlistview.cpp
+++ b/kaddressbook/views/contactlistview.cpp
@@ -1,400 +1,429 @@
1/* 1/*
2 This file is part of KAddressBook. 2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com> 3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23 23
24#include <qheader.h> 24#include <qheader.h>
25#include <qiconset.h> 25#include <qiconset.h>
26#include <qimage.h> 26#include <qimage.h>
27#include <qdragobject.h> 27#include <qdragobject.h>
28#include <qcombobox.h> 28#include <qcombobox.h>
29#include <qpainter.h> 29#include <qpainter.h>
30#include <qbrush.h> 30#include <qbrush.h>
31#include <qevent.h> 31#include <qevent.h>
32#include <qapplication.h>
32 33
33#include <klocale.h> 34#include <klocale.h>
34#include <kglobalsettings.h> 35#include <kglobalsettings.h>
35#include <kiconloader.h> 36#include <kiconloader.h>
36#include <kdebug.h> 37#include <kdebug.h>
37#include <kconfig.h> 38#include <kconfig.h>
38#include <kapplication.h> 39#include <kapplication.h>
39#include <kurl.h> 40#include <kurl.h>
40 41
41#include "kaddressbooktableview.h" 42#include "kaddressbooktableview.h"
42 43
43#include "contactlistview.h" 44#include "contactlistview.h"
44 45
45///////////////////////////////// 46/////////////////////////////////
46// DynamicTip Methods 47// DynamicTip Methods
47 48
48DynamicTip::DynamicTip( ContactListView *parent) 49DynamicTip::DynamicTip( ContactListView *parent)
49 : QToolTip( parent ) 50 : QToolTip( parent )
50{ 51{
51} 52}
52 53
53void DynamicTip::maybeTip( const QPoint &pos ) 54void DynamicTip::maybeTip( const QPoint &pos )
54{ 55{
55 static bool ishidden = true; 56 static bool ishidden = true;
56 if (!parentWidget()->inherits( "ContactListView" )) 57 if (!parentWidget()->inherits( "ContactListView" ))
57 return; 58 return;
58 59
59 ContactListView *plv = (ContactListView*)parentWidget(); 60 ContactListView *plv = (ContactListView*)parentWidget();
60 if (!plv->tooltips()) 61 if (!plv->tooltips())
61 return; 62 return;
62 63
63 QPoint posVp = plv->viewport()->pos(); 64 QPoint posVp = plv->viewport()->pos();
64 65
65 QListViewItem *lvi = plv->itemAt( pos - posVp ); 66 QListViewItem *lvi = plv->itemAt( pos - posVp );
66 if (!lvi) 67 if (!lvi)
67 return; 68 return;
68 69
69#ifndef KAB_EMBEDDED 70#ifndef KAB_EMBEDDED
70 ContactListViewItem *plvi = dynamic_cast< ContactListViewItem* >(lvi); 71 ContactListViewItem *plvi = dynamic_cast< ContactListViewItem* >(lvi);
71#else //KAB_EMBEDDED 72#else //KAB_EMBEDDED
72 ContactListViewItem *plvi = (ContactListViewItem*)(lvi); 73 ContactListViewItem *plvi = (ContactListViewItem*)(lvi);
73#endif //KAB_EMBEDDED 74#endif //KAB_EMBEDDED
74 75
75 if (!plvi) 76 if (!plvi)
76 return; 77 return;
77 78
78 if (ishidden) { 79 if (ishidden) {
79 QString s; 80 QString s;
80 QRect r = plv->itemRect( lvi ); 81 QRect r = plv->itemRect( lvi );
81 r.moveBy( posVp.x(), posVp.y() ); 82 r.moveBy( posVp.x(), posVp.y() );
82 83
83 //kdDebug() << "Tip rec: " << r.x() << "," << r.y() << "," << r.width() 84 //kdDebug() << "Tip rec: " << r.x() << "," << r.y() << "," << r.width()
84 // << "," << r.height() << endl; 85 // << "," << r.height() << endl;
85 86
86 KABC::Addressee a = plvi->addressee(); 87 KABC::Addressee a = plvi->addressee();
87 if (a.isEmpty()) 88 if (a.isEmpty())
88 return; 89 return;
89 90
90 s += i18n("label: value", "%1: %2").arg(a.formattedNameLabel()) 91 s += i18n("label: value", "%1: %2").arg(a.formattedNameLabel())
91 .arg(a.formattedName()); 92 .arg(a.formattedName());
92 93
93 s += '\n'; 94 s += '\n';
94 s += i18n("label: value", "%1: %2").arg(a.organizationLabel()) 95 s += i18n("label: value", "%1: %2").arg(a.organizationLabel())
95 .arg(a.organization()); 96 .arg(a.organization());
96 97
97 QString notes = a.note().stripWhiteSpace(); 98 QString notes = a.note().stripWhiteSpace();
98 if ( !notes.isEmpty() ) { 99 if ( !notes.isEmpty() ) {
99 notes += '\n'; 100 notes += '\n';
100 s += '\n' + i18n("label: value", "%1: \n").arg(a.noteLabel()); 101 s += '\n' + i18n("label: value", "%1: \n").arg(a.noteLabel());
101 QFontMetrics fm( font() ); 102 QFontMetrics fm( font() );
102 103
103 // Begin word wrap code based on QMultiLineEdit code 104 // Begin word wrap code based on QMultiLineEdit code
104 int i = 0; 105 int i = 0;
105 bool doBreak = false; 106 bool doBreak = false;
106 int linew = 0; 107 int linew = 0;
107 int lastSpace = -1; 108 int lastSpace = -1;
108 int a = 0; 109 int a = 0;
109 int lastw = 0; 110 int lastw = 0;
110 111
111 while ( i < int(notes.length()) ) { 112 while ( i < int(notes.length()) ) {
112 doBreak = FALSE; 113 doBreak = FALSE;
113 if ( notes[i] != '\n' ) 114 if ( notes[i] != '\n' )
114 linew += fm.width( notes[i] ); 115 linew += fm.width( notes[i] );
115 116
116 if ( lastSpace >= a && notes[i] != '\n' ) 117 if ( lastSpace >= a && notes[i] != '\n' )
117 if (linew >= parentWidget()->width()) { 118 if (linew >= parentWidget()->width()) {
118 doBreak = TRUE; 119 doBreak = TRUE;
119 if ( lastSpace > a ) { 120 if ( lastSpace > a ) {
120 i = lastSpace; 121 i = lastSpace;
121 linew = lastw; 122 linew = lastw;
122 } 123 }
123 else 124 else
124 i = QMAX( a, i-1 ); 125 i = QMAX( a, i-1 );
125 } 126 }
126 127
127 if ( notes[i] == '\n' || doBreak ) { 128 if ( notes[i] == '\n' || doBreak ) {
128 s += notes.mid( a, i - a + (doBreak?1:0) ) +"\n"; 129 s += notes.mid( a, i - a + (doBreak?1:0) ) +"\n";
129 130
130 a = i + 1; 131 a = i + 1;
131 lastSpace = a; 132 lastSpace = a;
132 linew = 0; 133 linew = 0;
133 } 134 }
134 135
135 if ( notes[i].isSpace() ) { 136 if ( notes[i].isSpace() ) {
136 lastSpace = i; 137 lastSpace = i;
137 lastw = linew; 138 lastw = linew;
138 } 139 }
139 140
140 if ( lastSpace <= a ) { 141 if ( lastSpace <= a ) {
141 lastw = linew; 142 lastw = linew;
142 } 143 }
143 144
144 ++i; 145 ++i;
145 } 146 }
146 } 147 }
147 148
148 tip( r, s ); 149 tip( r, s );
149 } 150 }
150 else 151 else
151 hide(); 152 hide();
152 ishidden = !ishidden; 153 ishidden = !ishidden;
153 154
154} 155}
155 156
156/////////////////////////// 157///////////////////////////
157// ContactListViewItem Methods 158// ContactListViewItem Methods
158 159
159ContactListViewItem::ContactListViewItem(const KABC::Addressee &a, 160ContactListViewItem::ContactListViewItem(const KABC::Addressee &a,
160 ContactListView *parent, 161 ContactListView *parent,
161 KABC::AddressBook *doc, 162 KABC::AddressBook *doc,
162 const KABC::Field::List &fields ) 163 const KABC::Field::List &fields )
163 : KListViewItem(parent), mAddressee(a), mFields( fields ), 164 : KListViewItem(parent), mAddressee(a), mFields( fields ),
164 parentListView( parent ), mDocument(doc) 165 parentListView( parent ), mDocument(doc)
165{ 166{
166 refresh(); 167 refresh();
167} 168}
168 169
169QString ContactListViewItem::key(int column, bool ascending) const 170QString ContactListViewItem::key(int column, bool ascending) const
170{ 171{
171#ifndef DESKTOP_VERSION 172#ifndef DESKTOP_VERSION
172 int lan = KGlobal::locale()->language(); 173 int lan = KGlobal::locale()->language();
173 //qDebug("language %d ", lan); 174 //qDebug("language %d ", lan);
174 if ( lan == 1 ) { //GERMAN 175 if ( lan == 1 ) { //GERMAN
175 QString ret = QListViewItem::key(column, ascending).lower().utf8(); 176 QString ret = QListViewItem::key(column, ascending).lower().utf8();
176 int start = -1; 177 int start = -1;
177 while ( (start = ret.find( 'ä', start+1)) > 0 ) { 178 while ( (start = ret.find( 'ä', start+1)) > 0 ) {
178 ret.at(start-1) = 'a'; 179 ret.at(start-1) = 'a';
179 } 180 }
180 start = -1; 181 start = -1;
181 while ( (start = ret.find( 'ö', start+1)) > 0 ) { 182 while ( (start = ret.find( 'ö', start+1)) > 0 ) {
182 ret.at(start-1) = 'o'; 183 ret.at(start-1) = 'o';
183 } 184 }
184 start = -1; 185 start = -1;
185 while ( (start = ret.find( 'ü', start+1)) > 0 ) { 186 while ( (start = ret.find( 'ü', start+1)) > 0 ) {
186 ret.at(start-1) = 'o'; 187 ret.at(start-1) = 'o';
187 } 188 }
188 start = -1; 189 start = -1;
189 while ( (start = ret.find( 'ß', start+1)) > 0 ) { 190 while ( (start = ret.find( 'ß', start+1)) > 0 ) {
190 ret.at(start-1) = 's'; 191 ret.at(start-1) = 's';
191 } 192 }
192 //qDebug("conv string %s ", ret.latin1()); 193 //qDebug("conv string %s ", ret.latin1());
193 194
194 return ret; 195 return ret;
195 196
196 } 197 }
197 else 198 else
198#endif 199#endif
199 return QListViewItem::key(column, ascending).lower(); 200 return QListViewItem::key(column, ascending).lower();
200} 201}
201 202
202void ContactListViewItem::paintCell(QPainter * p, 203void ContactListViewItem::paintCell(QPainter * p,
203 const QColorGroup & cg, 204 const QColorGroup & cg,
204 int column, 205 int column,
205 int width, 206 int width,
206 int align) 207 int align)
207{ 208{
208 KListViewItem::paintCell(p, cg, column, width, align); 209 KListViewItem::paintCell(p, cg, column, width, align);
209 210
210 if ( !p ) 211 if ( !p )
211 return; 212 return;
212 213
213 if (parentListView->singleLine()) { 214 if (parentListView->singleLine()) {
214 p->setPen( parentListView->alternateColor() ); 215 p->setPen( parentListView->alternateColor() );
215 p->drawLine( 0, height() - 1, width, height() - 1 ); 216 p->drawLine( 0, height() - 1, width, height() - 1 );
216 } 217 }
217} 218}
218 219
219 220
220ContactListView *ContactListViewItem::parent() 221ContactListView *ContactListViewItem::parent()
221{ 222{
222 return parentListView; 223 return parentListView;
223} 224}
224 225
225 226
226void ContactListViewItem::refresh() 227void ContactListViewItem::refresh()
227{ 228{
228 // Update our addressee, since it may have changed else were 229 // Update our addressee, since it may have changed else were
229 mAddressee = mDocument->findByUid(mAddressee.uid()); 230 mAddressee = mDocument->findByUid(mAddressee.uid());
230 if (mAddressee.isEmpty()) 231 if (mAddressee.isEmpty())
231 return; 232 return;
232 233
233 int i = 0; 234 int i = 0;
234 KABC::Field::List::ConstIterator it; 235 KABC::Field::List::ConstIterator it;
235 for( it = mFields.begin(); it != mFields.end(); ++it ) { 236 for( it = mFields.begin(); it != mFields.end(); ++it ) {
236 setText( i++, (*it)->value( mAddressee ) ); 237 setText( i++, (*it)->value( mAddressee ) );
237 } 238 }
238} 239}
239 240
240/////////////////////////////// 241///////////////////////////////
241// ContactListView 242// ContactListView
242 243
243ContactListView::ContactListView(KAddressBookTableView *view, 244ContactListView::ContactListView(KAddressBookTableView *view,
244 KABC::AddressBook* /* doc */, 245 KABC::AddressBook* /* doc */,
245 QWidget *parent, 246 QWidget *parent,
246 const char *name ) 247 const char *name )
247 : KListView( parent, name ), 248 : KListView( parent, name ),
248 pabWidget( view ), 249 pabWidget( view ),
249 oldColumn( 0 ) 250 oldColumn( 0 )
250{ 251{
252 mFlagBlockKeyPressed = false;
253 mFlagKeyPressed = false;
251 mABackground = true; 254 mABackground = true;
252 mSingleLine = false; 255 mSingleLine = false;
253 mToolTips = true; 256 mToolTips = true;
254#ifndef KAB_EMBEDDED 257#ifndef KAB_EMBEDDED
255 mAlternateColor = KGlobalSettings::alternateBackgroundColor(); 258 mAlternateColor = KGlobalSettings::alternateBackgroundColor();
256#else //KAB_EMBEDDED 259#else //KAB_EMBEDDED
257 mAlternateColor = QColor(240, 240, 240); 260 mAlternateColor = QColor(240, 240, 240);
258#endif //KAB_EMBEDDED 261#endif //KAB_EMBEDDED
259 262
260 setAlternateBackgroundEnabled(mABackground); 263 setAlternateBackgroundEnabled(mABackground);
261 setAcceptDrops( true ); 264 setAcceptDrops( true );
262 viewport()->setAcceptDrops( true ); 265 viewport()->setAcceptDrops( true );
263 setAllColumnsShowFocus( true ); 266 setAllColumnsShowFocus( true );
264 setShowSortIndicator(true); 267 setShowSortIndicator(true);
265 268
266 setSelectionModeExt( KListView::Extended ); 269 setSelectionModeExt( KListView::Extended );
267 setDropVisualizer(false); 270 setDropVisualizer(false);
268 // setFrameStyle(QFrame::NoFrame); 271 // setFrameStyle(QFrame::NoFrame);
269 //setLineWidth ( 0 ); 272 //setLineWidth ( 0 );
270 //setMidLineWidth ( 0 ); 273 //setMidLineWidth ( 0 );
271 //setMargin ( 0 ); 274 //setMargin ( 0 );
272#ifndef KAB_EMBEDDED 275#ifndef KAB_EMBEDDED
273 connect(this, SIGNAL(dropped(QDropEvent*)), 276 connect(this, SIGNAL(dropped(QDropEvent*)),
274 this, SLOT(itemDropped(QDropEvent*))); 277 this, SLOT(itemDropped(QDropEvent*)));
275#endif //KAB_EMBEDDED 278#endif //KAB_EMBEDDED
276 279
277 280
278 new DynamicTip( this ); 281 new DynamicTip( this );
279} 282}
280void ContactListView::printMe() 283void ContactListView::printMe()
281{ 284{
282#ifdef DESKTOP_VERSION 285#ifdef DESKTOP_VERSION
283 QPrinter printer; 286 QPrinter printer;
284 if (!printer.setup() ) 287 if (!printer.setup() )
285 return; 288 return;
286 QPainter p; 289 QPainter p;
287 p.begin ( &printer ); 290 p.begin ( &printer );
288 QPaintDeviceMetrics m = QPaintDeviceMetrics ( &printer ); 291 QPaintDeviceMetrics m = QPaintDeviceMetrics ( &printer );
289 float dx, dy; 292 float dx, dy;
290 int wid = (m.width() * 9)/10; 293 int wid = (m.width() * 9)/10;
291 dx = (float) wid/(float)contentsWidth (); 294 dx = (float) wid/(float)contentsWidth ();
292 dy = (float)(m.height()) / (float)contentsHeight (); 295 dy = (float)(m.height()) / (float)contentsHeight ();
293 float scale; 296 float scale;
294 // scale to fit the width or height of the paper 297 // scale to fit the width or height of the paper
295 if ( dx < dy ) 298 if ( dx < dy )
296 scale = dx; 299 scale = dx;
297 else 300 else
298 scale = dy; 301 scale = dy;
299 p.translate( m.width()/10,0 ); 302 p.translate( m.width()/10,0 );
300 p.scale( scale, scale ); 303 p.scale( scale, scale );
301 qDebug("scale %f ", scale); 304 qDebug("scale %f ", scale);
302 drawContents ( &p, 0,0, contentsWidth (), contentsHeight () ); 305 drawContents ( &p, 0,0, contentsWidth (), contentsHeight () );
303 p.end(); 306 p.end();
304 qDebug("Why does it not print??? "); 307 qDebug("Why does it not print??? ");
305#endif 308#endif
306} 309}
307 310
308void ContactListView::setAlternateColor(const QColor &m_AlternateColor) 311void ContactListView::setAlternateColor(const QColor &m_AlternateColor)
309{ 312{
310 mAlternateColor = m_AlternateColor; 313 mAlternateColor = m_AlternateColor;
311} 314}
312 315
313void ContactListView::paintEmptyArea( QPainter * p, const QRect & rect ) 316void ContactListView::paintEmptyArea( QPainter * p, const QRect & rect )
314{ 317{
315 QBrush b = palette().brush(QPalette::Active, QColorGroup::Base); 318 QBrush b = palette().brush(QPalette::Active, QColorGroup::Base);
316 319
317 // Get the brush, which will have the background pixmap if there is one. 320 // Get the brush, which will have the background pixmap if there is one.
318 if (b.pixmap()) 321 if (b.pixmap())
319 { 322 {
320 p->drawTiledPixmap( rect.left(), rect.top(), rect.width(), rect.height(), 323 p->drawTiledPixmap( rect.left(), rect.top(), rect.width(), rect.height(),
321 *(b.pixmap()), 324 *(b.pixmap()),
322 rect.left() + contentsX(), 325 rect.left() + contentsX(),
323 rect.top() + contentsY() ); 326 rect.top() + contentsY() );
324 } 327 }
325 328
326 else 329 else
327 { 330 {
328 // Do a normal paint 331 // Do a normal paint
329 KListView::paintEmptyArea(p, rect); 332 KListView::paintEmptyArea(p, rect);
330 } 333 }
331} 334}
332 335
333void ContactListView::contentsMousePressEvent(QMouseEvent* e) 336void ContactListView::contentsMousePressEvent(QMouseEvent* e)
334{ 337{
335 presspos = e->pos(); 338 presspos = e->pos();
336 KListView::contentsMousePressEvent(e); 339 KListView::contentsMousePressEvent(e);
337} 340}
338 341
339 342
340// To initiate a drag operation 343// To initiate a drag operation
341void ContactListView::contentsMouseMoveEvent( QMouseEvent *e ) 344void ContactListView::contentsMouseMoveEvent( QMouseEvent *e )
342{ 345{
343 if ((e->state() & LeftButton) && (e->pos() - presspos).manhattanLength() > 4 ) { 346 if ((e->state() & LeftButton) && (e->pos() - presspos).manhattanLength() > 4 ) {
344 emit startAddresseeDrag(); 347 emit startAddresseeDrag();
345 } 348 }
346 else 349 else
347 KListView::contentsMouseMoveEvent( e ); 350 KListView::contentsMouseMoveEvent( e );
348} 351}
349 352
350bool ContactListView::acceptDrag(QDropEvent *e) const 353bool ContactListView::acceptDrag(QDropEvent *e) const
351{ 354{
352#ifndef KAB_EMBEDDED 355#ifndef KAB_EMBEDDED
353 return QTextDrag::canDecode(e); 356 return QTextDrag::canDecode(e);
354#else //KAB_EMBEDDED 357#else //KAB_EMBEDDED
355qDebug("ContactListView::acceptDrag has to be fixed"); 358qDebug("ContactListView::acceptDrag has to be fixed");
356 return false; 359 return false;
357#endif //KAB_EMBEDDED 360#endif //KAB_EMBEDDED
358} 361}
359 362
360void ContactListView::itemDropped(QDropEvent *e) 363void ContactListView::itemDropped(QDropEvent *e)
361{ 364{
362 contentsDropEvent(e); 365 contentsDropEvent(e);
363} 366}
364 367
365void ContactListView::contentsDropEvent( QDropEvent *e ) 368void ContactListView::contentsDropEvent( QDropEvent *e )
366{ 369{
367 emit addresseeDropped(e); 370 emit addresseeDropped(e);
368} 371}
369 372
370void ContactListView::setAlternateBackgroundEnabled(bool enabled) 373void ContactListView::setAlternateBackgroundEnabled(bool enabled)
371{ 374{
372 mABackground = enabled; 375 mABackground = enabled;
373 376
374 if (mABackground) 377 if (mABackground)
375 { 378 {
376 setAlternateBackground(mAlternateColor); 379 setAlternateBackground(mAlternateColor);
377 } 380 }
378 else 381 else
379 { 382 {
380 setAlternateBackground(QColor()); 383 setAlternateBackground(QColor());
381 } 384 }
382} 385}
383 386
384void ContactListView::setBackgroundPixmap(const QString &filename) 387void ContactListView::setBackgroundPixmap(const QString &filename)
385{ 388{
386 if (filename.isEmpty()) 389 if (filename.isEmpty())
387 { 390 {
388 unsetPalette(); 391 unsetPalette();
389 } 392 }
390 else 393 else
391 { 394 {
392 qDebug("ContactListView::setBackgroundPixmap has to be verified"); 395 qDebug("ContactListView::setBackgroundPixmap has to be verified");
393//US setPaletteBackgroundPixmap(QPixmap(filename)); 396//US setPaletteBackgroundPixmap(QPixmap(filename));
394 KListView::setBackgroundPixmap((const QPixmap&)QPixmap(filename)); 397 KListView::setBackgroundPixmap((const QPixmap&)QPixmap(filename));
395 } 398 }
396 399
397} 400}
401
402void ContactListView::keyPressEvent ( QKeyEvent * e )
403{
404 if ( mFlagBlockKeyPressed )
405 return;
406 qApp->processEvents();
407 if ( e->isAutoRepeat() && !mFlagKeyPressed ) {
408 e->accept();
409 return;
410 }
411 if (! e->isAutoRepeat() )
412 mFlagKeyPressed = true;
413 KListView::keyPressEvent ( e );
414}
415void ContactListView::keyReleaseEvent ( QKeyEvent * e )
416{
417 if ( mFlagBlockKeyPressed )
418 return;
419 if ( !e->isAutoRepeat() ) {
420 mFlagBlockKeyPressed = true;
421 qApp->processEvents();
422 mFlagBlockKeyPressed = false;
423 mFlagKeyPressed = false;
424 }
425 KListView::keyReleaseEvent ( e );
426}
398#ifndef KAB_EMBEDDED 427#ifndef KAB_EMBEDDED
399#include "contactlistview.moc" 428#include "contactlistview.moc"
400#endif //KAB_EMBEDDED 429#endif //KAB_EMBEDDED
diff --git a/kaddressbook/views/contactlistview.h b/kaddressbook/views/contactlistview.h
index 9d1a672..46477e1 100644
--- a/kaddressbook/views/contactlistview.h
+++ b/kaddressbook/views/contactlistview.h
@@ -1,130 +1,134 @@
1#ifndef CONTACTLISTVIEW_H 1#ifndef CONTACTLISTVIEW_H
2#define CONTACTLISTVIEW_H 2#define CONTACTLISTVIEW_H
3 3
4#include <qcolor.h> 4#include <qcolor.h>
5#include <qpixmap.h> 5#include <qpixmap.h>
6#include <qtooltip.h> 6#include <qtooltip.h>
7#include <qstring.h> 7#include <qstring.h>
8 8
9#include <klistview.h> 9#include <klistview.h>
10 10
11#include <kabc/field.h> 11#include <kabc/field.h>
12#include <kabc/addressee.h> 12#include <kabc/addressee.h>
13#include <kabc/addressbook.h> 13#include <kabc/addressbook.h>
14 14
15 15
16class QDropEvent; 16class QDropEvent;
17class KAddressBookTableView; 17class KAddressBookTableView;
18class ContactListView; 18class ContactListView;
19 19
20/** The whole tooltip design needs a lot of work. Currently it is 20/** The whole tooltip design needs a lot of work. Currently it is
21* hacked together to function. 21* hacked together to function.
22*/ 22*/
23class DynamicTip : public QToolTip 23class DynamicTip : public QToolTip
24{ 24{
25 public: 25 public:
26 DynamicTip( ContactListView * parent ); 26 DynamicTip( ContactListView * parent );
27 27
28 protected: 28 protected:
29 void maybeTip( const QPoint & ); 29 void maybeTip( const QPoint & );
30 30
31 private: 31 private:
32}; 32};
33 33
34class ContactListViewItem : public KListViewItem 34class ContactListViewItem : public KListViewItem
35{ 35{
36 36
37public: 37public:
38 ContactListViewItem(const KABC::Addressee &a, ContactListView* parent, 38 ContactListViewItem(const KABC::Addressee &a, ContactListView* parent,
39 KABC::AddressBook *doc, const KABC::Field::List &fields ); 39 KABC::AddressBook *doc, const KABC::Field::List &fields );
40 const KABC::Addressee &addressee() const { return mAddressee; } 40 const KABC::Addressee &addressee() const { return mAddressee; }
41 virtual void refresh(); 41 virtual void refresh();
42 virtual ContactListView* parent(); 42 virtual ContactListView* parent();
43 virtual QString key ( int, bool ) const; 43 virtual QString key ( int, bool ) const;
44 44
45 /** Adds the border around the cell if the user wants it. 45 /** Adds the border around the cell if the user wants it.
46 * This is how the single line config option is implemented. 46 * This is how the single line config option is implemented.
47 */ 47 */
48 virtual void paintCell(QPainter * p, const QColorGroup & cg, 48 virtual void paintCell(QPainter * p, const QColorGroup & cg,
49 int column, int width, int align ); 49 int column, int width, int align );
50 50
51private: 51private:
52 KABC::Addressee mAddressee; 52 KABC::Addressee mAddressee;
53 KABC::Field::List mFields; 53 KABC::Field::List mFields;
54 ContactListView *parentListView; 54 ContactListView *parentListView;
55 KABC::AddressBook *mDocument; 55 KABC::AddressBook *mDocument;
56}; 56};
57 57
58 58
59///////////////////////////////////////////// 59/////////////////////////////////////////////
60// ContactListView 60// ContactListView
61 61
62class ContactListView : public KListView 62class ContactListView : public KListView
63{ 63{
64 Q_OBJECT 64 Q_OBJECT
65 65
66public: 66public:
67 ContactListView(KAddressBookTableView *view, 67 ContactListView(KAddressBookTableView *view,
68 KABC::AddressBook *doc, 68 KABC::AddressBook *doc,
69 QWidget *parent, 69 QWidget *parent,
70 const char *name = 0L ); 70 const char *name = 0L );
71 virtual ~ContactListView() {} 71 virtual ~ContactListView() {}
72 //void resort(); 72 //void resort();
73 73
74 /** Returns true if tooltips should be displayed, false otherwise 74 /** Returns true if tooltips should be displayed, false otherwise
75 */ 75 */
76 bool tooltips() const { return mToolTips; } 76 bool tooltips() const { return mToolTips; }
77 void setToolTipsEnabled(bool enabled) { mToolTips = enabled; } 77 void setToolTipsEnabled(bool enabled) { mToolTips = enabled; }
78 78
79 bool alternateBackground() const { return mABackground; } 79 bool alternateBackground() const { return mABackground; }
80 void setAlternateBackgroundEnabled(bool enabled); 80 void setAlternateBackgroundEnabled(bool enabled);
81 81
82 bool singleLine() const { return mSingleLine; } 82 bool singleLine() const { return mSingleLine; }
83 void setSingleLineEnabled(bool enabled) { mSingleLine = enabled; } 83 void setSingleLineEnabled(bool enabled) { mSingleLine = enabled; }
84 84
85 const QColor &alternateColor() const { return mAlternateColor; } 85 const QColor &alternateColor() const { return mAlternateColor; }
86 void setAlternateColor(const QColor &mAlternateColor); 86 void setAlternateColor(const QColor &mAlternateColor);
87 87
88 /** Sets the background pixmap to <i>filename</i>. If the 88 /** Sets the background pixmap to <i>filename</i>. If the
89 * QString is empty (QString::isEmpty()), then the background 89 * QString is empty (QString::isEmpty()), then the background
90 * pixmap will be disabled. 90 * pixmap will be disabled.
91 */ 91 */
92 void setBackgroundPixmap(const QString &filename); 92 void setBackgroundPixmap(const QString &filename);
93 93
94protected: 94protected:
95 bool mFlagKeyPressed;
96 bool mFlagBlockKeyPressed;
97 virtual void keyPressEvent ( QKeyEvent * );
98 virtual void keyReleaseEvent ( QKeyEvent * );
95 /** Paints the background pixmap in the empty area. This method is needed 99 /** Paints the background pixmap in the empty area. This method is needed
96 * since Qt::FixedPixmap will not scroll with the list view. 100 * since Qt::FixedPixmap will not scroll with the list view.
97 */ 101 */
98 virtual void paintEmptyArea( QPainter * p, const QRect & rect ); 102 virtual void paintEmptyArea( QPainter * p, const QRect & rect );
99 virtual void contentsMousePressEvent(QMouseEvent*); 103 virtual void contentsMousePressEvent(QMouseEvent*);
100 void contentsMouseMoveEvent( QMouseEvent *e ); 104 void contentsMouseMoveEvent( QMouseEvent *e );
101 void contentsDropEvent( QDropEvent *e ); 105 void contentsDropEvent( QDropEvent *e );
102 virtual bool acceptDrag(QDropEvent *e) const; 106 virtual bool acceptDrag(QDropEvent *e) const;
103 107
104protected slots: 108protected slots:
105 void itemDropped(QDropEvent *e); 109 void itemDropped(QDropEvent *e);
106 110
107public slots: 111public slots:
108 void printMe(); 112 void printMe();
109 113
110signals: 114signals:
111 void startAddresseeDrag(); 115 void startAddresseeDrag();
112 void addresseeDropped(QDropEvent *); 116 void addresseeDropped(QDropEvent *);
113 117
114private: 118private:
115 KAddressBookTableView *pabWidget; 119 KAddressBookTableView *pabWidget;
116 int oldColumn; 120 int oldColumn;
117 int column; 121 int column;
118 bool ascending; 122 bool ascending;
119 123
120 bool mABackground; 124 bool mABackground;
121 bool mSingleLine; 125 bool mSingleLine;
122 bool mToolTips; 126 bool mToolTips;
123 127
124 QColor mAlternateColor; 128 QColor mAlternateColor;
125 129
126 QPoint presspos; 130 QPoint presspos;
127}; 131};
128 132
129 133
130#endif 134#endif
diff --git a/kaddressbook/views/kaddressbookcardview.cpp b/kaddressbook/views/kaddressbookcardview.cpp
index cce68b9..9c35fd6 100644
--- a/kaddressbook/views/kaddressbookcardview.cpp
+++ b/kaddressbook/views/kaddressbookcardview.cpp
@@ -1,472 +1,476 @@
1/* 1/*
2 This file is part of KAddressBook. 2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com> 3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23 23
24#include <qdragobject.h> 24#include <qdragobject.h>
25#include <qevent.h> 25#include <qevent.h>
26#include <qiconview.h> 26#include <qiconview.h>
27#include <qlayout.h> 27#include <qlayout.h>
28#include <qstringlist.h> 28#include <qstringlist.h>
29#include <qregexp.h> 29#include <qregexp.h>
30#include <qapplication.h> 30#include <qapplication.h>
31 31
32#include <kabc/addressbook.h> 32#include <kabc/addressbook.h>
33#include <kabc/addressee.h> 33#include <kabc/addressee.h>
34#include <kconfig.h> 34#include <kconfig.h>
35#include <kdebug.h> 35#include <kdebug.h>
36#include <klocale.h> 36#include <klocale.h>
37 37
38#include "kabprefs.h" 38#include "kabprefs.h"
39#include "viewmanager.h" 39#include "viewmanager.h"
40 40
41 41
42#include "kaddressbookcardview.h" 42#include "kaddressbookcardview.h"
43 43
44#ifndef KAB_EMBEDDED 44#ifndef KAB_EMBEDDED
45extern "C" { 45extern "C" {
46 void *init_libkaddrbk_cardview() 46 void *init_libkaddrbk_cardview()
47 { 47 {
48 return ( new CardViewFactory ); 48 return ( new CardViewFactory );
49 } 49 }
50} 50}
51#endif //KAB_EMBEDDED 51#endif //KAB_EMBEDDED
52 52
53//////////////////////////////// 53////////////////////////////////
54// AddresseeCardViewItem (internal class) 54// AddresseeCardViewItem (internal class)
55class AddresseeCardViewItem : public CardViewItem 55class AddresseeCardViewItem : public CardViewItem
56{ 56{
57 public: 57 public:
58 AddresseeCardViewItem(const KABC::Field::List &fields, 58 AddresseeCardViewItem(const KABC::Field::List &fields,
59 bool showEmptyFields, 59 bool showEmptyFields,
60 KABC::AddressBook *doc, const KABC::Addressee &a, 60 KABC::AddressBook *doc, const KABC::Addressee &a,
61 CardView *parent) 61 CardView *parent)
62 : CardViewItem(parent, a.realName() ), 62 : CardViewItem(parent, a.realName() ),
63 mFields( fields ), mShowEmptyFields(showEmptyFields), 63 mFields( fields ), mShowEmptyFields(showEmptyFields),
64 mDocument(doc), mAddressee(a) 64 mDocument(doc), mAddressee(a)
65 { 65 {
66 if ( mFields.isEmpty() ) { 66 if ( mFields.isEmpty() ) {
67 mFields = KABC::Field::defaultFields(); 67 mFields = KABC::Field::defaultFields();
68 } 68 }
69 refresh(); 69 refresh();
70 } 70 }
71 71
72 const KABC::Addressee &addressee() const { return mAddressee; } 72 const KABC::Addressee &addressee() const { return mAddressee; }
73 73
74 void refresh() 74 void refresh()
75 { 75 {
76 // Update our addressee, since it may have changed elsewhere 76 // Update our addressee, since it may have changed elsewhere
77 mAddressee = mDocument->findByUid(mAddressee.uid()); 77 mAddressee = mDocument->findByUid(mAddressee.uid());
78 78
79 if (!mAddressee.isEmpty()) 79 if (!mAddressee.isEmpty())
80 { 80 {
81 clearFields(); 81 clearFields();
82 82
83 // Try all the selected fields until we find one with text. 83 // Try all the selected fields until we find one with text.
84 // This will limit the number of unlabeled icons in the view 84 // This will limit the number of unlabeled icons in the view
85 KABC::Field::List::Iterator iter; 85 KABC::Field::List::Iterator iter;
86 for (iter = mFields.begin(); iter != mFields.end(); ++iter) 86 for (iter = mFields.begin(); iter != mFields.end(); ++iter)
87 { 87 {
88 // insert empty fields or not? not doing so saves a bit of memory and CPU 88 // insert empty fields or not? not doing so saves a bit of memory and CPU
89 // (during geometry calculations), but prevents having equally 89 // (during geometry calculations), but prevents having equally
90 // wide label columns in all cards, unless CardViewItem/CardView search 90 // wide label columns in all cards, unless CardViewItem/CardView search
91 // globally for the widest label. (anders) 91 // globally for the widest label. (anders)
92 //if (mShowEmptyFields || !(*iter)->value( mAddressee ).isEmpty()) 92 //if (mShowEmptyFields || !(*iter)->value( mAddressee ).isEmpty())
93 insertField((*iter)->label(), (*iter)->value( mAddressee )); 93 insertField((*iter)->label(), (*iter)->value( mAddressee ));
94 } 94 }
95 95
96 // We might want to make this the first field. hmm... -mpilone 96 // We might want to make this the first field. hmm... -mpilone
97 setCaption( mAddressee.realName() ); 97 setCaption( mAddressee.realName() );
98 } 98 }
99 } 99 }
100 100
101 private: 101 private:
102 KABC::Field::List mFields; 102 KABC::Field::List mFields;
103 bool mShowEmptyFields; 103 bool mShowEmptyFields;
104 KABC::AddressBook *mDocument; 104 KABC::AddressBook *mDocument;
105 KABC::Addressee mAddressee; 105 KABC::Addressee mAddressee;
106}; 106};
107 107
108/////////////////////////////// 108///////////////////////////////
109// AddresseeCardView 109// AddresseeCardView
110 110
111AddresseeCardView::AddresseeCardView(QWidget *parent, const char *name) 111AddresseeCardView::AddresseeCardView(QWidget *parent, const char *name)
112 : CardView(parent, name) 112 : CardView(parent, name)
113{ 113{
114 setAcceptDrops(true); 114 setAcceptDrops(true);
115} 115}
116 116
117AddresseeCardView::~AddresseeCardView() 117AddresseeCardView::~AddresseeCardView()
118{ 118{
119} 119}
120void AddresseeCardView::printMe() 120void AddresseeCardView::printMe()
121{ 121{
122#ifdef DESKTOP_VERSION 122#ifdef DESKTOP_VERSION
123 QPrinter printer; 123 QPrinter printer;
124 if (!printer.setup() ) 124 if (!printer.setup() )
125 return; 125 return;
126 QPainter p; 126 QPainter p;
127 p.begin ( &printer ); 127 p.begin ( &printer );
128 QPaintDeviceMetrics m = QPaintDeviceMetrics ( &printer ); 128 QPaintDeviceMetrics m = QPaintDeviceMetrics ( &printer );
129 float dx, dy; 129 float dx, dy;
130 int wid = (m.width() * 9)/10; 130 int wid = (m.width() * 9)/10;
131 dx = (float) wid/(float)contentsWidth (); 131 dx = (float) wid/(float)contentsWidth ();
132 dy = (float)(m.height()) / (float)contentsHeight (); 132 dy = (float)(m.height()) / (float)contentsHeight ();
133 float scale; 133 float scale;
134 // scale to fit the width or height of the paper 134 // scale to fit the width or height of the paper
135 if ( dx < dy ) 135 if ( dx < dy )
136 scale = dx; 136 scale = dx;
137 else 137 else
138 scale = dy; 138 scale = dy;
139 p.translate( m.width()/10,0 ); 139 p.translate( m.width()/10,0 );
140 p.scale( scale, scale ); 140 p.scale( scale, scale );
141 drawContents ( &p, 0,0, contentsWidth (), contentsHeight () ); 141 drawContents ( &p, 0,0, contentsWidth (), contentsHeight () );
142 p.end(); 142 p.end();
143 repaint(); 143 repaint();
144#endif 144#endif
145} 145}
146 146
147 147
148void AddresseeCardView::dragEnterEvent(QDragEnterEvent *e) 148void AddresseeCardView::dragEnterEvent(QDragEnterEvent *e)
149{ 149{
150#ifndef KAB_EMBEDDED 150#ifndef KAB_EMBEDDED
151 if (QTextDrag::canDecode(e)) 151 if (QTextDrag::canDecode(e))
152 e->accept(); 152 e->accept();
153#else //KAB_EMBEDDED 153#else //KAB_EMBEDDED
154qDebug("AddresseeCardView::dragEnterEvent drag&drop is not implemented"); 154qDebug("AddresseeCardView::dragEnterEvent drag&drop is not implemented");
155#endif //KAB_EMBEDDED 155#endif //KAB_EMBEDDED
156} 156}
157 157
158void AddresseeCardView::dropEvent(QDropEvent *e) 158void AddresseeCardView::dropEvent(QDropEvent *e)
159{ 159{
160 emit addresseeDropped(e); 160 emit addresseeDropped(e);
161} 161}
162 162
163void AddresseeCardView::startDrag() 163void AddresseeCardView::startDrag()
164{ 164{
165 emit startAddresseeDrag(); 165 emit startAddresseeDrag();
166} 166}
167 167
168 168
169/////////////////////////////// 169///////////////////////////////
170// KAddressBookCardView 170// KAddressBookCardView
171 171
172KAddressBookCardView::KAddressBookCardView( KABC::AddressBook *ab, 172KAddressBookCardView::KAddressBookCardView( KABC::AddressBook *ab,
173 QWidget *parent, const char *name ) 173 QWidget *parent, const char *name )
174 : KAddressBookView( ab, parent, name ) 174 : KAddressBookView( ab, parent, name )
175{ 175{
176 mShowEmptyFields = false; 176 mShowEmptyFields = false;
177 177
178 // Init the GUI 178 // Init the GUI
179 QVBoxLayout *layout = new QVBoxLayout(viewWidget()); 179 QVBoxLayout *layout = new QVBoxLayout(viewWidget());
180 180
181 mCardView = new AddresseeCardView(viewWidget(), "mCardView"); 181 mCardView = new AddresseeCardView(viewWidget(), "mCardView");
182 mCardView->setSelectionMode(CardView::Extended); 182 mCardView->setSelectionMode(CardView::Extended);
183 layout->addWidget(mCardView); 183 layout->addWidget(mCardView);
184 184
185 // Connect up the signals 185 // Connect up the signals
186 connect(mCardView, SIGNAL(executed(CardViewItem *)), 186 connect(mCardView, SIGNAL(executed(CardViewItem *)),
187 this, SLOT(addresseeExecuted(CardViewItem *))); 187 this, SLOT(addresseeExecuted(CardViewItem *)));
188 connect(mCardView, SIGNAL(selectionChanged()), 188 connect(mCardView, SIGNAL(selectionChanged()),
189 this, SLOT(addresseeSelected())); 189 this, SLOT(addresseeSelected()));
190 connect(mCardView, SIGNAL(addresseeDropped(QDropEvent*)), 190 connect(mCardView, SIGNAL(addresseeDropped(QDropEvent*)),
191 this, SIGNAL(dropped(QDropEvent*))); 191 this, SIGNAL(dropped(QDropEvent*)));
192 connect(mCardView, SIGNAL(startAddresseeDrag()), 192 connect(mCardView, SIGNAL(startAddresseeDrag()),
193 this, SIGNAL(startDrag())); 193 this, SIGNAL(startDrag()));
194 connect(this, SIGNAL(printView()), 194 connect(this, SIGNAL(printView()),
195 mCardView , SLOT(printMe())); 195 mCardView , SLOT(printMe()));
196} 196}
197 197
198KAddressBookCardView::~KAddressBookCardView() 198KAddressBookCardView::~KAddressBookCardView()
199{ 199{
200} 200}
201void KAddressBookCardView::setFocusAV() 201void KAddressBookCardView::setFocusAV()
202{ 202{
203 if ( mCardView ) 203 if ( mCardView )
204 mCardView->setFocus(); 204 mCardView->setFocus();
205 205
206} 206}
207void KAddressBookCardView::scrollUP() 207void KAddressBookCardView::scrollUP()
208{ 208{
209 QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Up, 0,0 ); 209 QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Up, 0,0 );
210 QApplication::postEvent( mCardView, ev ); 210 QApplication::postEvent( mCardView, ev );
211 ev = new QKeyEvent ( QEvent::KeyRelease, Qt::Key_Up, 0,0 );
212 QApplication::postEvent( mCardView, ev );
211 213
212} 214}
213void KAddressBookCardView::scrollDOWN() 215void KAddressBookCardView::scrollDOWN()
214{ 216{
215 QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Down, 0,0 ); 217 QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Down, 0,0 );
216 QApplication::postEvent( mCardView, ev ); 218 QApplication::postEvent( mCardView, ev );
219 ev = new QKeyEvent ( QEvent::KeyRelease, Qt::Key_Down, 0,0 );
220 QApplication::postEvent( mCardView, ev );
217} 221}
218void KAddressBookCardView::readConfig(KConfig *config) 222void KAddressBookCardView::readConfig(KConfig *config)
219{ 223{
220 KAddressBookView::readConfig(config); 224 KAddressBookView::readConfig(config);
221 225
222 // costum colors? 226 // costum colors?
223 if ( config->readBoolEntry( "EnableCustomColors", false ) ) 227 if ( config->readBoolEntry( "EnableCustomColors", false ) )
224 { 228 {
225 QPalette p( mCardView->palette() ); 229 QPalette p( mCardView->palette() );
226 QColor c = p.color(QPalette::Normal, QColorGroup::Base ); 230 QColor c = p.color(QPalette::Normal, QColorGroup::Base );
227 p.setColor( QPalette::Normal, QColorGroup::Base, config->readColorEntry( "BackgroundColor", &c ) ); 231 p.setColor( QPalette::Normal, QColorGroup::Base, config->readColorEntry( "BackgroundColor", &c ) );
228 c = p.color(QPalette::Normal, QColorGroup::Text ); 232 c = p.color(QPalette::Normal, QColorGroup::Text );
229 p.setColor( QPalette::Normal, QColorGroup::Text, config->readColorEntry( "TextColor", &c ) ); 233 p.setColor( QPalette::Normal, QColorGroup::Text, config->readColorEntry( "TextColor", &c ) );
230 c = p.color(QPalette::Normal, QColorGroup::Button ); 234 c = p.color(QPalette::Normal, QColorGroup::Button );
231 p.setColor( QPalette::Normal, QColorGroup::Button, config->readColorEntry( "HeaderColor", &c ) ); 235 p.setColor( QPalette::Normal, QColorGroup::Button, config->readColorEntry( "HeaderColor", &c ) );
232 c = p.color(QPalette::Normal, QColorGroup::ButtonText ); 236 c = p.color(QPalette::Normal, QColorGroup::ButtonText );
233 p.setColor( QPalette::Normal, QColorGroup::ButtonText, config->readColorEntry( "HeaderTextColor", &c ) ); 237 p.setColor( QPalette::Normal, QColorGroup::ButtonText, config->readColorEntry( "HeaderTextColor", &c ) );
234 c = p.color(QPalette::Normal, QColorGroup::Highlight ); 238 c = p.color(QPalette::Normal, QColorGroup::Highlight );
235 p.setColor( QPalette::Normal, QColorGroup::Highlight, config->readColorEntry( "HighlightColor", &c ) ); 239 p.setColor( QPalette::Normal, QColorGroup::Highlight, config->readColorEntry( "HighlightColor", &c ) );
236 c = p.color(QPalette::Normal, QColorGroup::HighlightedText ); 240 c = p.color(QPalette::Normal, QColorGroup::HighlightedText );
237 p.setColor( QPalette::Normal, QColorGroup::HighlightedText, config->readColorEntry( "HighlightedTextColor", &c ) ); 241 p.setColor( QPalette::Normal, QColorGroup::HighlightedText, config->readColorEntry( "HighlightedTextColor", &c ) );
238 mCardView->viewport()->setPalette( p ); 242 mCardView->viewport()->setPalette( p );
239 } 243 }
240 else 244 else
241 { 245 {
242 // needed if turned off during a session. 246 // needed if turned off during a session.
243 mCardView->viewport()->setPalette( mCardView->palette() ); 247 mCardView->viewport()->setPalette( mCardView->palette() );
244 } 248 }
245 249
246 //custom fonts? 250 //custom fonts?
247 QFont f( font() ); 251 QFont f( font() );
248 if ( config->readBoolEntry( "EnableCustomFonts", false ) ) 252 if ( config->readBoolEntry( "EnableCustomFonts", false ) )
249 { 253 {
250 mCardView->setFont( config->readFontEntry( "TextFont", &f) ); 254 mCardView->setFont( config->readFontEntry( "TextFont", &f) );
251 f.setBold( true ); 255 f.setBold( true );
252 mCardView->setHeaderFont( config->readFontEntry( "HeaderFont", &f ) ); 256 mCardView->setHeaderFont( config->readFontEntry( "HeaderFont", &f ) );
253 } 257 }
254 else 258 else
255 { 259 {
256 mCardView->setFont( f ); 260 mCardView->setFont( f );
257 f.setBold( true ); 261 f.setBold( true );
258 mCardView->setHeaderFont( f ); 262 mCardView->setHeaderFont( f );
259 } 263 }
260 264
261 mCardView->setDrawCardBorder(config->readBoolEntry("DrawBorder", true)); 265 mCardView->setDrawCardBorder(config->readBoolEntry("DrawBorder", true));
262 mCardView->setDrawColSeparators(config->readBoolEntry("DrawSeparators", 266 mCardView->setDrawColSeparators(config->readBoolEntry("DrawSeparators",
263 true)); 267 true));
264 mCardView->setDrawFieldLabels(config->readBoolEntry("DrawFieldLabels",false)); 268 mCardView->setDrawFieldLabels(config->readBoolEntry("DrawFieldLabels",false));
265 mShowEmptyFields = config->readBoolEntry("ShowEmptyFields", false); 269 mShowEmptyFields = config->readBoolEntry("ShowEmptyFields", false);
266 270
267 mCardView->setShowEmptyFields( mShowEmptyFields ); 271 mCardView->setShowEmptyFields( mShowEmptyFields );
268 272
269 mCardView->setItemWidth( config->readNumEntry( "ItemWidth", 200 ) ); 273 mCardView->setItemWidth( config->readNumEntry( "ItemWidth", 200 ) );
270 mCardView->setItemMargin( config->readNumEntry( "ItemMargin", 0 ) ); 274 mCardView->setItemMargin( config->readNumEntry( "ItemMargin", 0 ) );
271 mCardView->setItemSpacing( config->readNumEntry( "ItemSpacing", 10 ) ); 275 mCardView->setItemSpacing( config->readNumEntry( "ItemSpacing", 10 ) );
272 mCardView->setSeparatorWidth( config->readNumEntry( "SeparatorWidth", 2 ) ); 276 mCardView->setSeparatorWidth( config->readNumEntry( "SeparatorWidth", 2 ) );
273 277
274#if 0 278#if 0
275 // LR KABPrefs::instance()->mHonorSingleClick is handled and fixed in cardviews contentsMouseDoubleClickEven 279 // LR KABPrefs::instance()->mHonorSingleClick is handled and fixed in cardviews contentsMouseDoubleClickEven
276 disconnect(mCardView, SIGNAL(executed(CardViewItem *)), 280 disconnect(mCardView, SIGNAL(executed(CardViewItem *)),
277 this, SLOT(addresseeExecuted(CardViewItem *))); 281 this, SLOT(addresseeExecuted(CardViewItem *)));
278 282
279 if (KABPrefs::instance()->mHonorSingleClick) 283 if (KABPrefs::instance()->mHonorSingleClick)
280 connect(mCardView, SIGNAL(executed(CardViewItem *)), 284 connect(mCardView, SIGNAL(executed(CardViewItem *)),
281 this, SLOT(addresseeExecuted(CardViewItem *))); 285 this, SLOT(addresseeExecuted(CardViewItem *)));
282 else 286 else
283 connect(mCardView, SIGNAL(doubleClicked(CardViewItem *)), 287 connect(mCardView, SIGNAL(doubleClicked(CardViewItem *)),
284 this, SLOT(addresseeExecuted(CardViewItem *))); 288 this, SLOT(addresseeExecuted(CardViewItem *)));
285#endif 289#endif
286 290
287 connect(mCardView, SIGNAL(doubleClicked(CardViewItem *)), 291 connect(mCardView, SIGNAL(doubleClicked(CardViewItem *)),
288 this, SLOT(addresseeExecuted(CardViewItem *))); 292 this, SLOT(addresseeExecuted(CardViewItem *)));
289} 293}
290 294
291void KAddressBookCardView::writeConfig( KConfig *config ) 295void KAddressBookCardView::writeConfig( KConfig *config )
292{ 296{
293 config->writeEntry( "ItemWidth", mCardView->itemWidth() ); 297 config->writeEntry( "ItemWidth", mCardView->itemWidth() );
294 KAddressBookView::writeConfig( config ); 298 KAddressBookView::writeConfig( config );
295} 299}
296void KAddressBookCardView::doSearch( const QString& s,KABC::Field *field ) 300void KAddressBookCardView::doSearch( const QString& s,KABC::Field *field )
297{ 301{
298 mCardView->clear(); 302 mCardView->clear();
299 if ( s.isEmpty() || s == "*" ) { 303 if ( s.isEmpty() || s == "*" ) {
300 refresh(); 304 refresh();
301 return; 305 return;
302 } 306 }
303 QRegExp re = getRegExp( s ); 307 QRegExp re = getRegExp( s );
304 if (!re.isValid()) 308 if (!re.isValid())
305 return; 309 return;
306 mCardView->viewport()->setUpdatesEnabled( false ); 310 mCardView->viewport()->setUpdatesEnabled( false );
307 KABC::Addressee::List addresseeList = addressees(); 311 KABC::Addressee::List addresseeList = addressees();
308 KABC::Addressee::List::Iterator it; 312 KABC::Addressee::List::Iterator it;
309 if ( field ) { 313 if ( field ) {
310 for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { 314 for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) {
311 if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") ) 315 if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") )
312 continue; 316 continue;
313#if QT_VERSION >= 0x030000 317#if QT_VERSION >= 0x030000
314 if (re.search(field->value( *it ).lower()) != -1) 318 if (re.search(field->value( *it ).lower()) != -1)
315#else 319#else
316 if (re.match(field->value( *it ).lower()) != -1) 320 if (re.match(field->value( *it ).lower()) != -1)
317#endif 321#endif
318 new AddresseeCardViewItem(fields(), mShowEmptyFields, 322 new AddresseeCardViewItem(fields(), mShowEmptyFields,
319 addressBook(), *it, mCardView); 323 addressBook(), *it, mCardView);
320 324
321 } 325 }
322 } else { 326 } else {
323 KABC::Field::List fieldList = allFields(); 327 KABC::Field::List fieldList = allFields();
324 KABC::Field::List::ConstIterator fieldIt; 328 KABC::Field::List::ConstIterator fieldIt;
325 for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { 329 for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) {
326 if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") ) 330 if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") )
327 continue; 331 continue;
328 for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) { 332 for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) {
329#if QT_VERSION >= 0x030000 333#if QT_VERSION >= 0x030000
330 if (re.search((*fieldIt)->value( *it ).lower()) != -1) 334 if (re.search((*fieldIt)->value( *it ).lower()) != -1)
331#else 335#else
332 if (re.match((*fieldIt)->value( *it ).lower()) != -1) 336 if (re.match((*fieldIt)->value( *it ).lower()) != -1)
333#endif 337#endif
334 { 338 {
335 new AddresseeCardViewItem(fields(), mShowEmptyFields, 339 new AddresseeCardViewItem(fields(), mShowEmptyFields,
336 addressBook(), *it, mCardView); 340 addressBook(), *it, mCardView);
337 break; 341 break;
338 } 342 }
339 } 343 }
340 } 344 }
341 } 345 }
342 mCardView->viewport()->setUpdatesEnabled( true ); 346 mCardView->viewport()->setUpdatesEnabled( true );
343 mCardView->viewport()->update(); 347 mCardView->viewport()->update();
344 if ( mCardView->firstItem() ) { 348 if ( mCardView->firstItem() ) {
345 mCardView->setCurrentItem ( mCardView->firstItem() ); 349 mCardView->setCurrentItem ( mCardView->firstItem() );
346 mCardView->setSelected ( mCardView->firstItem() , true ); 350 mCardView->setSelected ( mCardView->firstItem() , true );
347 } 351 }
348 else 352 else
349 emit selected(QString::null); 353 emit selected(QString::null);
350} 354}
351QStringList KAddressBookCardView::selectedUids() 355QStringList KAddressBookCardView::selectedUids()
352{ 356{
353 QStringList uidList; 357 QStringList uidList;
354 CardViewItem *item; 358 CardViewItem *item;
355 AddresseeCardViewItem *aItem; 359 AddresseeCardViewItem *aItem;
356 360
357 for (item = mCardView->firstItem(); item; item = item->nextItem()) 361 for (item = mCardView->firstItem(); item; item = item->nextItem())
358 { 362 {
359 if (item->isSelected()) 363 if (item->isSelected())
360 { 364 {
361#ifndef KAB_EMBEDDED 365#ifndef KAB_EMBEDDED
362 aItem = dynamic_cast<AddresseeCardViewItem*>(item); 366 aItem = dynamic_cast<AddresseeCardViewItem*>(item);
363#else //KAB_EMBEDDED 367#else //KAB_EMBEDDED
364 aItem = (AddresseeCardViewItem*)(item); 368 aItem = (AddresseeCardViewItem*)(item);
365#endif //KAB_EMBEDDED 369#endif //KAB_EMBEDDED
366 if (aItem) 370 if (aItem)
367 uidList << aItem->addressee().uid(); 371 uidList << aItem->addressee().uid();
368 } 372 }
369 } 373 }
370 374
371 return uidList; 375 return uidList;
372} 376}
373 377
374void KAddressBookCardView::refresh(QString uid) 378void KAddressBookCardView::refresh(QString uid)
375{ 379{
376 CardViewItem *item; 380 CardViewItem *item;
377 AddresseeCardViewItem *aItem; 381 AddresseeCardViewItem *aItem;
378 382
379 if (uid.isNull()) 383 if (uid.isNull())
380 { 384 {
381 // Rebuild the view 385 // Rebuild the view
382 mCardView->viewport()->setUpdatesEnabled( false ); 386 mCardView->viewport()->setUpdatesEnabled( false );
383 mCardView->clear(); 387 mCardView->clear();
384 388
385 KABC::Addressee::List addresseeList = addressees(); 389 KABC::Addressee::List addresseeList = addressees();
386 KABC::Addressee::List::Iterator iter; 390 KABC::Addressee::List::Iterator iter;
387 for (iter = addresseeList.begin(); iter != addresseeList.end(); ++iter) 391 for (iter = addresseeList.begin(); iter != addresseeList.end(); ++iter)
388 { 392 {
389 if ( (*iter).uid().left(2) == "la" && (*iter).uid().left(19) == QString("last-syncAddressee-") ) 393 if ( (*iter).uid().left(2) == "la" && (*iter).uid().left(19) == QString("last-syncAddressee-") )
390 continue; 394 continue;
391 aItem = new AddresseeCardViewItem(fields(), mShowEmptyFields, 395 aItem = new AddresseeCardViewItem(fields(), mShowEmptyFields,
392 addressBook(), *iter, mCardView); 396 addressBook(), *iter, mCardView);
393 } 397 }
394 mCardView->viewport()->setUpdatesEnabled( true ); 398 mCardView->viewport()->setUpdatesEnabled( true );
395 mCardView->viewport()->update(); 399 mCardView->viewport()->update();
396 400
397 // by default nothing is selected 401 // by default nothing is selected
398 emit selected(QString::null); 402 emit selected(QString::null);
399 } 403 }
400 else 404 else
401 { 405 {
402 // Try to find the one to refresh 406 // Try to find the one to refresh
403 bool found = false; 407 bool found = false;
404 for (item = mCardView->firstItem(); item && !found; 408 for (item = mCardView->firstItem(); item && !found;
405 item = item->nextItem()) 409 item = item->nextItem())
406 { 410 {
407#ifndef KAB_EMBEDDED 411#ifndef KAB_EMBEDDED
408 aItem = dynamic_cast<AddresseeCardViewItem*>(item); 412 aItem = dynamic_cast<AddresseeCardViewItem*>(item);
409#else //KAB_EMBEDDED 413#else //KAB_EMBEDDED
410 aItem = (AddresseeCardViewItem*)(item); 414 aItem = (AddresseeCardViewItem*)(item);
411#endif //KAB_EMBEDDED 415#endif //KAB_EMBEDDED
412 416
413 if ((aItem) && (aItem->addressee().uid() == uid)) 417 if ((aItem) && (aItem->addressee().uid() == uid))
414 { 418 {
415 aItem->refresh(); 419 aItem->refresh();
416 found = true; 420 found = true;
417 } 421 }
418 } 422 }
419 } 423 }
420} 424}
421 425
422void KAddressBookCardView::setSelected(QString uid, bool selected) 426void KAddressBookCardView::setSelected(QString uid, bool selected)
423{ 427{
424 CardViewItem *item; 428 CardViewItem *item;
425 AddresseeCardViewItem *aItem; 429 AddresseeCardViewItem *aItem;
426 430
427 if (uid.isNull()) 431 if (uid.isNull())
428 { 432 {
429 mCardView->selectAll(selected); 433 mCardView->selectAll(selected);
430 } 434 }
431 else 435 else
432 { 436 {
433 bool found = false; 437 bool found = false;
434 for (item = mCardView->firstItem(); item && !found; 438 for (item = mCardView->firstItem(); item && !found;
435 item = item->nextItem()) 439 item = item->nextItem())
436 { 440 {
437#ifndef KAB_EMBEDDED 441#ifndef KAB_EMBEDDED
438 aItem = dynamic_cast<AddresseeCardViewItem*>(item); 442 aItem = dynamic_cast<AddresseeCardViewItem*>(item);
439#else //KAB_EMBEDDED 443#else //KAB_EMBEDDED
440 aItem = (AddresseeCardViewItem*)(item); 444 aItem = (AddresseeCardViewItem*)(item);
441#endif //KAB_EMBEDDED 445#endif //KAB_EMBEDDED
442 446
443 if ((aItem) && (aItem->addressee().uid() == uid)) 447 if ((aItem) && (aItem->addressee().uid() == uid))
444 { 448 {
445 mCardView->setSelected(aItem, selected); 449 mCardView->setSelected(aItem, selected);
446 mCardView->ensureItemVisible(item); 450 mCardView->ensureItemVisible(item);
447 found = true; 451 found = true;
448 } 452 }
449 } 453 }
450 } 454 }
451} 455}
452 456
453//US added an additional method without parameter 457//US added an additional method without parameter
454void KAddressBookCardView::setSelected() 458void KAddressBookCardView::setSelected()
455{ 459{
456 setSelected(QString::null, true); 460 setSelected(QString::null, true);
457} 461}
458 462
459void KAddressBookCardView::addresseeExecuted(CardViewItem *item) 463void KAddressBookCardView::addresseeExecuted(CardViewItem *item)
460{ 464{
461#ifndef KAB_EMBEDDED 465#ifndef KAB_EMBEDDED
462 AddresseeCardViewItem *aItem = dynamic_cast<AddresseeCardViewItem*>(item); 466 AddresseeCardViewItem *aItem = dynamic_cast<AddresseeCardViewItem*>(item);
463#else //KAB_EMBEDDED 467#else //KAB_EMBEDDED
464 AddresseeCardViewItem *aItem = (AddresseeCardViewItem*)(item); 468 AddresseeCardViewItem *aItem = (AddresseeCardViewItem*)(item);
465#endif //KAB_EMBEDDED 469#endif //KAB_EMBEDDED
466 if (aItem) 470 if (aItem)
467 { 471 {
468 //kdDebug()<<"... even has a valid item:)"<<endl; 472 //kdDebug()<<"... even has a valid item:)"<<endl;
469 emit executed(aItem->addressee().uid()); 473 emit executed(aItem->addressee().uid());
470 } 474 }
471} 475}
472 476
diff --git a/kaddressbook/views/kaddressbooktableview.cpp b/kaddressbook/views/kaddressbooktableview.cpp
index f4b008c..e322473 100644
--- a/kaddressbook/views/kaddressbooktableview.cpp
+++ b/kaddressbook/views/kaddressbooktableview.cpp
@@ -1,324 +1,328 @@
1// $Id$ 1// $Id$
2 2
3#include <qvbox.h> 3#include <qvbox.h>
4#include <qlistbox.h> 4#include <qlistbox.h>
5#include <qwidget.h> 5#include <qwidget.h>
6#include <qfile.h> 6#include <qfile.h>
7#include <qimage.h> 7#include <qimage.h>
8#include <qcombobox.h> 8#include <qcombobox.h>
9#include <qapplication.h> 9#include <qapplication.h>
10#include <qdragobject.h> 10#include <qdragobject.h>
11#include <qevent.h> 11#include <qevent.h>
12#include <qurl.h> 12#include <qurl.h>
13#include <qpixmap.h> 13#include <qpixmap.h>
14 14
15#include <kabc/addressbook.h> 15#include <kabc/addressbook.h>
16#include <kapplication.h> 16#include <kapplication.h>
17#include <kconfig.h> 17#include <kconfig.h>
18#include <kcolorbutton.h> 18#include <kcolorbutton.h>
19#include <kdebug.h> 19#include <kdebug.h>
20#include <kglobal.h> 20#include <kglobal.h>
21#include <kiconloader.h> 21#include <kiconloader.h>
22#include <klineedit.h> 22#include <klineedit.h>
23#include <klocale.h> 23#include <klocale.h>
24#include <kmessagebox.h> 24#include <kmessagebox.h>
25#include <kurl.h> 25#include <kurl.h>
26#include <kurlrequester.h> 26#include <kurlrequester.h>
27 27
28//US#include "configuretableviewdialog.h" 28//US#include "configuretableviewdialog.h"
29#include "contactlistview.h" 29#include "contactlistview.h"
30#include "kabprefs.h" 30#include "kabprefs.h"
31#include "undocmds.h" 31#include "undocmds.h"
32#include "viewmanager.h" 32#include "viewmanager.h"
33 33
34#include <qlayout.h> 34#include <qlayout.h>
35#include <qheader.h> 35#include <qheader.h>
36#include <qregexp.h> 36#include <qregexp.h>
37 37
38#include "kaddressbooktableview.h" 38#include "kaddressbooktableview.h"
39 39
40 40
41KAddressBookTableView::KAddressBookTableView( KABC::AddressBook *ab, 41KAddressBookTableView::KAddressBookTableView( KABC::AddressBook *ab,
42 QWidget *parent, const char *name ) 42 QWidget *parent, const char *name )
43 : KAddressBookView( ab, parent, name ) 43 : KAddressBookView( ab, parent, name )
44{ 44{
45 mainLayout = new QVBoxLayout( viewWidget(), 2 ); 45 mainLayout = new QVBoxLayout( viewWidget(), 2 );
46 46
47 // The list view will be created when the config is read. 47 // The list view will be created when the config is read.
48 mListView = 0; 48 mListView = 0;
49} 49}
50 50
51KAddressBookTableView::~KAddressBookTableView() 51KAddressBookTableView::~KAddressBookTableView()
52{ 52{
53} 53}
54void KAddressBookTableView::setFocusAV() 54void KAddressBookTableView::setFocusAV()
55{ 55{
56 if ( mListView ) 56 if ( mListView )
57 mListView->setFocus(); 57 mListView->setFocus();
58 58
59} 59}
60void KAddressBookTableView::scrollUP() 60void KAddressBookTableView::scrollUP()
61{ 61{
62 QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Up, 0,0 ); 62 QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Up, 0,0 );
63 QApplication::postEvent( mListView, ev ); 63 QApplication::postEvent( mListView, ev );
64 ev = new QKeyEvent ( QEvent::KeyRelease, Qt::Key_Up, 0,0 );
65 QApplication::postEvent( mListView, ev );
64} 66}
65void KAddressBookTableView::scrollDOWN() 67void KAddressBookTableView::scrollDOWN()
66{ 68{
67 QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Down, 0,0 ); 69 QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Down, 0,0 );
68 QApplication::postEvent( mListView, ev ); 70 QApplication::postEvent( mListView, ev );
71 ev = new QKeyEvent ( QEvent::KeyRelease, Qt::Key_Down, 0,0 );
72 QApplication::postEvent( mListView, ev );
69} 73}
70void KAddressBookTableView::reconstructListView() 74void KAddressBookTableView::reconstructListView()
71{ 75{
72 if (mListView) 76 if (mListView)
73 { 77 {
74 disconnect(mListView, SIGNAL(selectionChanged()), 78 disconnect(mListView, SIGNAL(selectionChanged()),
75 this, SLOT(addresseeSelected())); 79 this, SLOT(addresseeSelected()));
76 disconnect(mListView, SIGNAL(executed(QListViewItem*)), 80 disconnect(mListView, SIGNAL(executed(QListViewItem*)),
77 this, SLOT(addresseeExecuted(QListViewItem*))); 81 this, SLOT(addresseeExecuted(QListViewItem*)));
78 disconnect(mListView, SIGNAL(doubleClicked(QListViewItem*)), 82 disconnect(mListView, SIGNAL(doubleClicked(QListViewItem*)),
79 this, SLOT(addresseeExecuted(QListViewItem*))); 83 this, SLOT(addresseeExecuted(QListViewItem*)));
80 disconnect(mListView, SIGNAL(startAddresseeDrag()), this, 84 disconnect(mListView, SIGNAL(startAddresseeDrag()), this,
81 SIGNAL(startDrag())); 85 SIGNAL(startDrag()));
82 disconnect(mListView, SIGNAL(returnPressed(QListViewItem*)), 86 disconnect(mListView, SIGNAL(returnPressed(QListViewItem*)),
83 this, SLOT(addresseeExecuted(QListViewItem*))); 87 this, SLOT(addresseeExecuted(QListViewItem*)));
84 88
85 disconnect(mListView, SIGNAL(addresseeDropped(QDropEvent*)), this, 89 disconnect(mListView, SIGNAL(addresseeDropped(QDropEvent*)), this,
86 SIGNAL(dropped(QDropEvent*))); 90 SIGNAL(dropped(QDropEvent*)));
87 delete mListView; 91 delete mListView;
88 } 92 }
89 93
90 mListView = new ContactListView( this, addressBook(), viewWidget() ); 94 mListView = new ContactListView( this, addressBook(), viewWidget() );
91 95
92 connect(this, SIGNAL(printView()), 96 connect(this, SIGNAL(printView()),
93 mListView , SLOT(printMe())); 97 mListView , SLOT(printMe()));
94 //US set singleClick manually, because it is no global configparameter in embedded space 98 //US set singleClick manually, because it is no global configparameter in embedded space
95 mListView->setSingleClick(KABPrefs::instance()->mHonorSingleClick); 99 mListView->setSingleClick(KABPrefs::instance()->mHonorSingleClick);
96 100
97 // Add the columns 101 // Add the columns
98 KABC::Field::List fieldList = fields(); 102 KABC::Field::List fieldList = fields();
99 KABC::Field::List::ConstIterator it; 103 KABC::Field::List::ConstIterator it;
100 104
101 int c = 0; 105 int c = 0;
102 for( it = fieldList.begin(); it != fieldList.end(); ++it ) { 106 for( it = fieldList.begin(); it != fieldList.end(); ++it ) {
103 mListView->addColumn( (*it)->label() ); 107 mListView->addColumn( (*it)->label() );
104 mListView->setColumnWidthMode(c++, QListView::Manual); 108 mListView->setColumnWidthMode(c++, QListView::Manual);
105//US 109//US
106 // qDebug("KAddressBookTableView::reconstructListView: field %s", (*it)->label().latin1()); 110 // qDebug("KAddressBookTableView::reconstructListView: field %s", (*it)->label().latin1());
107 } 111 }
108 112
109 connect(mListView, SIGNAL(selectionChanged()), 113 connect(mListView, SIGNAL(selectionChanged()),
110 this, SLOT(addresseeSelected())); 114 this, SLOT(addresseeSelected()));
111 connect(mListView, SIGNAL(startAddresseeDrag()), this, 115 connect(mListView, SIGNAL(startAddresseeDrag()), this,
112 SIGNAL(startDrag())); 116 SIGNAL(startDrag()));
113 connect(mListView, SIGNAL(addresseeDropped(QDropEvent*)), this, 117 connect(mListView, SIGNAL(addresseeDropped(QDropEvent*)), this,
114 SIGNAL(dropped(QDropEvent*))); 118 SIGNAL(dropped(QDropEvent*)));
115 119
116 if (KABPrefs::instance()->mHonorSingleClick) { 120 if (KABPrefs::instance()->mHonorSingleClick) {
117 // qDebug("KAddressBookTableView::reconstructListView single"); 121 // qDebug("KAddressBookTableView::reconstructListView single");
118 connect(mListView, SIGNAL(executed(QListViewItem*)), 122 connect(mListView, SIGNAL(executed(QListViewItem*)),
119 this, SLOT(addresseeExecuted(QListViewItem*))); 123 this, SLOT(addresseeExecuted(QListViewItem*)));
120 } else { 124 } else {
121 // qDebug("KAddressBookTableView::reconstructListView double"); 125 // qDebug("KAddressBookTableView::reconstructListView double");
122 connect(mListView, SIGNAL(doubleClicked(QListViewItem*)), 126 connect(mListView, SIGNAL(doubleClicked(QListViewItem*)),
123 this, SLOT(addresseeExecuted(QListViewItem*))); 127 this, SLOT(addresseeExecuted(QListViewItem*)));
124 } 128 }
125 connect(mListView, SIGNAL(returnPressed(QListViewItem*)), 129 connect(mListView, SIGNAL(returnPressed(QListViewItem*)),
126 this, SLOT(addresseeExecuted(QListViewItem*))); 130 this, SLOT(addresseeExecuted(QListViewItem*)));
127 connect(mListView, SIGNAL(signalDelete()), 131 connect(mListView, SIGNAL(signalDelete()),
128 this, SLOT(addresseeDeleted())); 132 this, SLOT(addresseeDeleted()));
129 133
130//US performceimprovement. Refresh is done from the outside 134//US performceimprovement. Refresh is done from the outside
131//US refresh(); 135//US refresh();
132 136
133 mListView->setSorting( 0, true ); 137 mListView->setSorting( 0, true );
134 mainLayout->addWidget( mListView ); 138 mainLayout->addWidget( mListView );
135 mainLayout->activate(); 139 mainLayout->activate();
136 mListView->show(); 140 mListView->show();
137} 141}
138 142
139void KAddressBookTableView::doSearch( const QString& s, KABC::Field *field ) 143void KAddressBookTableView::doSearch( const QString& s, KABC::Field *field )
140{ 144{
141 mListView->clear(); 145 mListView->clear();
142 if ( s.isEmpty() || s == "*" ) { 146 if ( s.isEmpty() || s == "*" ) {
143 refresh(); 147 refresh();
144 return; 148 return;
145 } 149 }
146 QRegExp re = getRegExp( s ); 150 QRegExp re = getRegExp( s );
147 if (!re.isValid()) 151 if (!re.isValid())
148 return; 152 return;
149 KABC::Addressee::List addresseeList = addressees(); 153 KABC::Addressee::List addresseeList = addressees();
150 KABC::Addressee::List::Iterator it; 154 KABC::Addressee::List::Iterator it;
151 if ( field ) { 155 if ( field ) {
152 for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { 156 for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) {
153 if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") ) 157 if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") )
154 continue; 158 continue;
155#if QT_VERSION >= 0x030000 159#if QT_VERSION >= 0x030000
156 if (re.search(field->value( *it ).lower()) == 0) 160 if (re.search(field->value( *it ).lower()) == 0)
157#else 161#else
158 if (re.match(field->value( *it ).lower()) != -1) 162 if (re.match(field->value( *it ).lower()) != -1)
159#endif 163#endif
160 ContactListViewItem *item = new ContactListViewItem(*it, mListView, addressBook(), fields()); 164 ContactListViewItem *item = new ContactListViewItem(*it, mListView, addressBook(), fields());
161 165
162 } 166 }
163 } else { 167 } else {
164 KABC::Field::List fieldList = allFields(); 168 KABC::Field::List fieldList = allFields();
165 KABC::Field::List::ConstIterator fieldIt; 169 KABC::Field::List::ConstIterator fieldIt;
166 for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { 170 for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) {
167 if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") ) 171 if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") )
168 continue; 172 continue;
169 for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) { 173 for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) {
170#if QT_VERSION >= 0x030000 174#if QT_VERSION >= 0x030000
171 if (re.search((*fieldIt)->value( *it ).lower()) != -1) 175 if (re.search((*fieldIt)->value( *it ).lower()) != -1)
172#else 176#else
173 if (re.match((*fieldIt)->value( *it ).lower()) != -1) 177 if (re.match((*fieldIt)->value( *it ).lower()) != -1)
174#endif 178#endif
175 { 179 {
176 //qDebug("match %s %s %s", pattern.latin1(), (*fieldIt)->value( *it ).latin1(), (*fieldIt)->label().latin1() ); 180 //qDebug("match %s %s %s", pattern.latin1(), (*fieldIt)->value( *it ).latin1(), (*fieldIt)->label().latin1() );
177 ContactListViewItem *item = new ContactListViewItem(*it, mListView, addressBook(), fields()); 181 ContactListViewItem *item = new ContactListViewItem(*it, mListView, addressBook(), fields());
178 break; 182 break;
179 } 183 }
180 } 184 }
181 } 185 }
182 } 186 }
183 // Sometimes the background pixmap gets messed up when we add lots 187 // Sometimes the background pixmap gets messed up when we add lots
184 // of items. 188 // of items.
185 mListView->repaint(); 189 mListView->repaint();
186 if ( mListView->firstChild() ) { 190 if ( mListView->firstChild() ) {
187 mListView->setCurrentItem ( mListView->firstChild() ); 191 mListView->setCurrentItem ( mListView->firstChild() );
188 mListView->setSelected ( mListView->firstChild(), true ); 192 mListView->setSelected ( mListView->firstChild(), true );
189 } 193 }
190 else 194 else
191 emit selected(QString::null); 195 emit selected(QString::null);
192 196
193} 197}
194void KAddressBookTableView::writeConfig(KConfig *config) 198void KAddressBookTableView::writeConfig(KConfig *config)
195{ 199{
196 KAddressBookView::writeConfig(config); 200 KAddressBookView::writeConfig(config);
197 201
198 mListView->saveLayout(config, config->group()); 202 mListView->saveLayout(config, config->group());
199} 203}
200 204
201void KAddressBookTableView::readConfig(KConfig *config) 205void KAddressBookTableView::readConfig(KConfig *config)
202{ 206{
203 KAddressBookView::readConfig( config ); 207 KAddressBookView::readConfig( config );
204 // The config could have changed the fields, so we need to reconstruct 208 // The config could have changed the fields, so we need to reconstruct
205 // the listview. 209 // the listview.
206 reconstructListView(); 210 reconstructListView();
207 211
208 // costum colors? 212 // costum colors?
209 if ( config->readBoolEntry( "EnableCustomColors", false ) ) 213 if ( config->readBoolEntry( "EnableCustomColors", false ) )
210 { 214 {
211 QPalette p( mListView->palette() ); 215 QPalette p( mListView->palette() );
212 QColor c = p.color(QPalette::Normal, QColorGroup::Base ); 216 QColor c = p.color(QPalette::Normal, QColorGroup::Base );
213 p.setColor( QPalette::Normal, QColorGroup::Base, config->readColorEntry( "BackgroundColor", &c ) ); 217 p.setColor( QPalette::Normal, QColorGroup::Base, config->readColorEntry( "BackgroundColor", &c ) );
214 c = p.color(QPalette::Normal, QColorGroup::Text ); 218 c = p.color(QPalette::Normal, QColorGroup::Text );
215 p.setColor( QPalette::Normal, QColorGroup::Text, config->readColorEntry( "TextColor", &c ) ); 219 p.setColor( QPalette::Normal, QColorGroup::Text, config->readColorEntry( "TextColor", &c ) );
216 c = p.color(QPalette::Normal, QColorGroup::Button ); 220 c = p.color(QPalette::Normal, QColorGroup::Button );
217 p.setColor( QPalette::Normal, QColorGroup::Button, config->readColorEntry( "HeaderColor", &c ) ); 221 p.setColor( QPalette::Normal, QColorGroup::Button, config->readColorEntry( "HeaderColor", &c ) );
218 c = p.color(QPalette::Normal, QColorGroup::ButtonText ); 222 c = p.color(QPalette::Normal, QColorGroup::ButtonText );
219 p.setColor( QPalette::Normal, QColorGroup::ButtonText, config->readColorEntry( "HeaderTextColor", &c ) ); 223 p.setColor( QPalette::Normal, QColorGroup::ButtonText, config->readColorEntry( "HeaderTextColor", &c ) );
220 c = p.color(QPalette::Normal, QColorGroup::Highlight ); 224 c = p.color(QPalette::Normal, QColorGroup::Highlight );
221 p.setColor( QPalette::Normal, QColorGroup::Highlight, config->readColorEntry( "HighlightColor", &c ) ); 225 p.setColor( QPalette::Normal, QColorGroup::Highlight, config->readColorEntry( "HighlightColor", &c ) );
222 c = p.color(QPalette::Normal, QColorGroup::HighlightedText ); 226 c = p.color(QPalette::Normal, QColorGroup::HighlightedText );
223 p.setColor( QPalette::Normal, QColorGroup::HighlightedText, config->readColorEntry( "HighlightedTextColor", &c ) ); 227 p.setColor( QPalette::Normal, QColorGroup::HighlightedText, config->readColorEntry( "HighlightedTextColor", &c ) );
224#ifndef KAB_EMBEDDED 228#ifndef KAB_EMBEDDED
225 c = KGlobalSettings::alternateBackgroundColor(); 229 c = KGlobalSettings::alternateBackgroundColor();
226#else //KAB_EMBEDDED 230#else //KAB_EMBEDDED
227 c = QColor(240, 240, 240); 231 c = QColor(240, 240, 240);
228#endif //KAB_EMBEDDED 232#endif //KAB_EMBEDDED
229 c = config->readColorEntry ("AlternatingBackgroundColor", &c); 233 c = config->readColorEntry ("AlternatingBackgroundColor", &c);
230 mListView->setAlternateColor(c); 234 mListView->setAlternateColor(c);
231 235
232 236
233 //US mListView->viewport()->setPalette( p ); 237 //US mListView->viewport()->setPalette( p );
234 mListView->setPalette( p ); 238 mListView->setPalette( p );
235 } 239 }
236 else 240 else
237 { 241 {
238 // needed if turned off during a session. 242 // needed if turned off during a session.
239 //US mListView->viewport()->setPalette( mListView->palette() ); 243 //US mListView->viewport()->setPalette( mListView->palette() );
240 mListView->setPalette( mListView->palette() ); 244 mListView->setPalette( mListView->palette() );
241 } 245 }
242 246
243 //custom fonts? 247 //custom fonts?
244 QFont f( font() ); 248 QFont f( font() );
245 if ( config->readBoolEntry( "EnableCustomFonts", false ) ) 249 if ( config->readBoolEntry( "EnableCustomFonts", false ) )
246 { 250 {
247 mListView->setFont( config->readFontEntry( "TextFont", &f) ); 251 mListView->setFont( config->readFontEntry( "TextFont", &f) );
248 f.setBold( true ); 252 f.setBold( true );
249 //US mListView->setHeaderFont( config->readFontEntry( "HeaderFont", &f ) ); 253 //US mListView->setHeaderFont( config->readFontEntry( "HeaderFont", &f ) );
250 mListView->header()->setFont( config->readFontEntry( "HeaderFont", &f ) ); 254 mListView->header()->setFont( config->readFontEntry( "HeaderFont", &f ) );
251 } 255 }
252 else 256 else
253 { 257 {
254 mListView->setFont( f ); 258 mListView->setFont( f );
255 f.setBold( true ); 259 f.setBold( true );
256 //US mListView->setHeaderFont( f ); 260 //US mListView->setHeaderFont( f );
257 mListView->header()->setFont( f ); 261 mListView->header()->setFont( f );
258 } 262 }
259 263
260 // Set the list view options 264 // Set the list view options
261 mListView->setAlternateBackgroundEnabled(config->readBoolEntry("ABackground", 265 mListView->setAlternateBackgroundEnabled(config->readBoolEntry("ABackground",
262 true)); 266 true));
263 mListView->setSingleLineEnabled(config->readBoolEntry("SingleLine", false)); 267 mListView->setSingleLineEnabled(config->readBoolEntry("SingleLine", false));
264 mListView->setToolTipsEnabled(config->readBoolEntry("ToolTips", true)); 268 mListView->setToolTipsEnabled(config->readBoolEntry("ToolTips", true));
265 269
266 if (config->readBoolEntry("Background", false)) 270 if (config->readBoolEntry("Background", false))
267 mListView->setBackgroundPixmap(config->readEntry("BackgroundName")); 271 mListView->setBackgroundPixmap(config->readEntry("BackgroundName"));
268 272
269 // Restore the layout of the listview 273 // Restore the layout of the listview
270 mListView->restoreLayout(config, config->group()); 274 mListView->restoreLayout(config, config->group());
271} 275}
272 276
273void KAddressBookTableView::refresh(QString uid) 277void KAddressBookTableView::refresh(QString uid)
274{ 278{
275 // For now just repopulate. In reality this method should 279 // For now just repopulate. In reality this method should
276 // check the value of uid, and if valid iterate through 280 // check the value of uid, and if valid iterate through
277 // the listview to find the entry, then tell it to refresh. 281 // the listview to find the entry, then tell it to refresh.
278 282
279 if (uid.isNull()) { 283 if (uid.isNull()) {
280 // Clear the list view 284 // Clear the list view
281 QString currentUID, nextUID; 285 QString currentUID, nextUID;
282#ifndef KAB_EMBEDDED 286#ifndef KAB_EMBEDDED
283 ContactListViewItem *currentItem = dynamic_cast<ContactListViewItem*>( mListView->currentItem() ); 287 ContactListViewItem *currentItem = dynamic_cast<ContactListViewItem*>( mListView->currentItem() );
284#else //KAB_EMBEDDED 288#else //KAB_EMBEDDED
285 ContactListViewItem *currentItem = (ContactListViewItem*)( mListView->currentItem() ); 289 ContactListViewItem *currentItem = (ContactListViewItem*)( mListView->currentItem() );
286#endif //KAB_EMBEDDED 290#endif //KAB_EMBEDDED
287 291
288 if ( currentItem ) { 292 if ( currentItem ) {
289#ifndef KAB_EMBEDDED 293#ifndef KAB_EMBEDDED
290 ContactListViewItem *nextItem = dynamic_cast<ContactListViewItem*>( currentItem->itemBelow() ); 294 ContactListViewItem *nextItem = dynamic_cast<ContactListViewItem*>( currentItem->itemBelow() );
291#else //KAB_EMBEDDED 295#else //KAB_EMBEDDED
292 ContactListViewItem *nextItem = (ContactListViewItem*)( currentItem->itemBelow() ); 296 ContactListViewItem *nextItem = (ContactListViewItem*)( currentItem->itemBelow() );
293#endif //KAB_EMBEDDED 297#endif //KAB_EMBEDDED
294 if ( nextItem ) 298 if ( nextItem )
295 nextUID = nextItem->addressee().uid(); 299 nextUID = nextItem->addressee().uid();
296 currentUID = currentItem->addressee().uid(); 300 currentUID = currentItem->addressee().uid();
297 } 301 }
298 302
299 mListView->clear(); 303 mListView->clear();
300 304
301 currentItem = 0; 305 currentItem = 0;
302 KABC::Addressee::List addresseeList = addressees(); 306 KABC::Addressee::List addresseeList = addressees();
303 KABC::Addressee::List::Iterator it; 307 KABC::Addressee::List::Iterator it;
304 for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { 308 for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) {
305 if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") ) 309 if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") )
306 continue; 310 continue;
307 ContactListViewItem *item = new ContactListViewItem(*it, mListView, addressBook(), fields()); 311 ContactListViewItem *item = new ContactListViewItem(*it, mListView, addressBook(), fields());
308 if ( (*it).uid() == currentUID ) 312 if ( (*it).uid() == currentUID )
309 currentItem = item; 313 currentItem = item;
310 else if ( (*it).uid() == nextUID && !currentItem ) 314 else if ( (*it).uid() == nextUID && !currentItem )
311 currentItem = item; 315 currentItem = item;
312 } 316 }
313 317
314 // Sometimes the background pixmap gets messed up when we add lots 318 // Sometimes the background pixmap gets messed up when we add lots
315 // of items. 319 // of items.
316 mListView->repaint(); 320 mListView->repaint();
317 321
318 if ( currentItem ) { 322 if ( currentItem ) {
319 mListView->setCurrentItem( currentItem ); 323 mListView->setCurrentItem( currentItem );
320 mListView->ensureItemVisible( currentItem ); 324 mListView->ensureItemVisible( currentItem );
321 } 325 }
322 } else { 326 } else {
323 // Only need to update on entry. Iterate through and try to find it 327 // Only need to update on entry. Iterate through and try to find it
324 ContactListViewItem *ceItem; 328 ContactListViewItem *ceItem;
diff --git a/korganizer/komonthview.cpp b/korganizer/komonthview.cpp
index ca35a86..b9ce4f4 100644
--- a/korganizer/komonthview.cpp
+++ b/korganizer/komonthview.cpp
@@ -747,512 +747,513 @@ void MonthViewCell::insertTodo(Todo *todo)
747 if ( insertNewItem) 747 if ( insertNewItem)
748 insertItem( item ); 748 insertItem( item );
749 mToolTip.append( text ); 749 mToolTip.append( text );
750} 750}
751void MonthViewCell::repaintfinishUpdateCell() 751void MonthViewCell::repaintfinishUpdateCell()
752{ 752{
753 MonthViewItem *mitem = (MonthViewItem*) firstItem (); 753 MonthViewItem *mitem = (MonthViewItem*) firstItem ();
754 while ( mitem ) { 754 while ( mitem ) {
755 mitem->setBlockRepaint( false ); 755 mitem->setBlockRepaint( false );
756 updateItem ( mitem ); 756 updateItem ( mitem );
757 mitem = (MonthViewItem *)mitem->next(); 757 mitem = (MonthViewItem *)mitem->next();
758 } 758 }
759} 759}
760void MonthViewCell::finishUpdateCell() 760void MonthViewCell::finishUpdateCell()
761{ 761{
762 while ( mCurrentAvailItem ) { 762 while ( mCurrentAvailItem ) {
763 MonthViewItem *item = mCurrentAvailItem; 763 MonthViewItem *item = mCurrentAvailItem;
764 mCurrentAvailItem = (MonthViewItem *)item->next(); 764 mCurrentAvailItem = (MonthViewItem *)item->next();
765 mAvailItemList.append( item ); 765 mAvailItemList.append( item );
766 takeItem ( item ); 766 takeItem ( item );
767 } 767 }
768 768
769 769
770#ifdef DESKTOP_VERSION 770#ifdef DESKTOP_VERSION
771 if (mToolTip.count() > 0 ) { 771 if (mToolTip.count() > 0 ) {
772 mToolTip.sort(); 772 mToolTip.sort();
773 QToolTip::add(this,mToolTip.join("\n"),toolTipGroup(),""); 773 QToolTip::add(this,mToolTip.join("\n"),toolTipGroup(),"");
774 } 774 }
775#endif 775#endif
776 sort(); 776 sort();
777 //setMyPalette(); 777 //setMyPalette();
778 setMyPalette(); 778 setMyPalette();
779 779
780 resizeEvent( 0 ); 780 resizeEvent( 0 );
781 781
782} 782}
783void MonthViewCell::updateCell() 783void MonthViewCell::updateCell()
784{ 784{
785 //qDebug("MonthViewCell::updateCell() "); 785 //qDebug("MonthViewCell::updateCell() ");
786 if ( !mMonthView->isUpdatePossible() ) 786 if ( !mMonthView->isUpdatePossible() )
787 return; 787 return;
788 startUpdateCell(); 788 startUpdateCell();
789 //mLabel->setMaximumWidth( width() - mItemList->lineWidth()*2); 789 //mLabel->setMaximumWidth( width() - mItemList->lineWidth()*2);
790 QPtrList<Event> events = mMonthView->calendar()->events( mDate, true ); 790 QPtrList<Event> events = mMonthView->calendar()->events( mDate, true );
791 Event *event; 791 Event *event;
792 for( event = events.first(); event; event = events.next() ) { // for event 792 for( event = events.first(); event; event = events.next() ) { // for event
793 insertEvent(event); 793 insertEvent(event);
794 } 794 }
795 // insert due todos 795 // insert due todos
796 QPtrList<Todo> todos = mMonthView->calendar()->todos( mDate ); 796 QPtrList<Todo> todos = mMonthView->calendar()->todos( mDate );
797 Todo *todo; 797 Todo *todo;
798 for(todo = todos.first(); todo; todo = todos.next()) { 798 for(todo = todos.first(); todo; todo = todos.next()) {
799 insertTodo( todo ); 799 insertTodo( todo );
800 } 800 }
801 finishUpdateCell(); 801 finishUpdateCell();
802 // if ( isVisible()) 802 // if ( isVisible())
803 //qApp->processEvents(); 803 //qApp->processEvents();
804} 804}
805 805
806void MonthViewCell::updateConfig( bool bigFont ) // = false 806void MonthViewCell::updateConfig( bool bigFont ) // = false
807{ 807{
808 808
809 if ( bigFont ) { 809 if ( bigFont ) {
810 QFont fo = KOPrefs::instance()->mMonthViewFont; 810 QFont fo = KOPrefs::instance()->mMonthViewFont;
811 int ps = fo.pointSize() + 2; 811 int ps = fo.pointSize() + 2;
812 if ( ps < 18 ) 812 if ( ps < 18 )
813 ps += 2; 813 ps += 2;
814 fo.setPointSize( ps ); 814 fo.setPointSize( ps );
815 setFont( fo ); 815 setFont( fo );
816 } else 816 } else
817 setFont( KOPrefs::instance()->mMonthViewFont ); 817 setFont( KOPrefs::instance()->mMonthViewFont );
818 818
819 QFontMetrics fm( font() ); 819 QFontMetrics fm( font() );
820 mLabelSize = fm.size( 0, "30" ) + QSize( 4, 2 ); 820 mLabelSize = fm.size( 0, "30" ) + QSize( 4, 2 );
821 mLabelBigSize = fm.size( 0, "Mag 30" ) + QSize( 2, 2 ); 821 mLabelBigSize = fm.size( 0, "Mag 30" ) + QSize( 2, 2 );
822 mHolidayPalette = mStandardPalette; 822 mHolidayPalette = mStandardPalette;
823 mPrimaryPalette = mStandardPalette; 823 mPrimaryPalette = mStandardPalette;
824 mNonPrimaryPalette = mStandardPalette; 824 mNonPrimaryPalette = mStandardPalette;
825 if ( KOPrefs::instance()->mMonthViewUsesDayColors ) { 825 if ( KOPrefs::instance()->mMonthViewUsesDayColors ) {
826 mHolidayPalette.setColor(QColorGroup::Base, KOPrefs::instance()->mMonthViewHolidayColor ); 826 mHolidayPalette.setColor(QColorGroup::Base, KOPrefs::instance()->mMonthViewHolidayColor );
827 mHolidayPalette.setColor(QColorGroup::Background, KOPrefs::instance()->mMonthViewHolidayColor ); 827 mHolidayPalette.setColor(QColorGroup::Background, KOPrefs::instance()->mMonthViewHolidayColor );
828 mHolidayPalette.setColor(QColorGroup::Foreground, KOPrefs::instance()->mMonthViewHolidayColor.dark()); 828 mHolidayPalette.setColor(QColorGroup::Foreground, KOPrefs::instance()->mMonthViewHolidayColor.dark());
829 mPrimaryPalette.setColor(QColorGroup::Foreground,KOPrefs::instance()->mMonthViewOddColor.dark()); 829 mPrimaryPalette.setColor(QColorGroup::Foreground,KOPrefs::instance()->mMonthViewOddColor.dark());
830 mPrimaryPalette.setColor(QColorGroup::Base,KOPrefs::instance()->mMonthViewOddColor); 830 mPrimaryPalette.setColor(QColorGroup::Base,KOPrefs::instance()->mMonthViewOddColor);
831 mPrimaryPalette.setColor(QColorGroup::Background,KOPrefs::instance()->mMonthViewOddColor); 831 mPrimaryPalette.setColor(QColorGroup::Background,KOPrefs::instance()->mMonthViewOddColor);
832 mNonPrimaryPalette.setColor(QColorGroup::Foreground,KOPrefs::instance()->mMonthViewEvenColor.dark()); 832 mNonPrimaryPalette.setColor(QColorGroup::Foreground,KOPrefs::instance()->mMonthViewEvenColor.dark());
833 mNonPrimaryPalette.setColor(QColorGroup::Base,KOPrefs::instance()->mMonthViewEvenColor); 833 mNonPrimaryPalette.setColor(QColorGroup::Base,KOPrefs::instance()->mMonthViewEvenColor);
834 mNonPrimaryPalette.setColor(QColorGroup::Background,KOPrefs::instance()->mMonthViewEvenColor); 834 mNonPrimaryPalette.setColor(QColorGroup::Background,KOPrefs::instance()->mMonthViewEvenColor);
835 } 835 }
836 //updateCell(); 836 //updateCell();
837} 837}
838 838
839void MonthViewCell::enableScrollBars( bool enabled ) 839void MonthViewCell::enableScrollBars( bool enabled )
840{ 840{
841 if ( enabled ) { 841 if ( enabled ) {
842 QListBoxItem *fi = firstItem (); 842 QListBoxItem *fi = firstItem ();
843 if (fi ) { 843 if (fi ) {
844 int ihei = fi->height( this ); 844 int ihei = fi->height( this );
845 int hei = numRows () * ihei; 845 int hei = numRows () * ihei;
846 if ( hei < height() - horizontalScrollBar()->height () ) { 846 if ( hei < height() - horizontalScrollBar()->height () ) {
847 setVScrollBarMode(QScrollView::AlwaysOff); 847 setVScrollBarMode(QScrollView::AlwaysOff);
848 } 848 }
849 else 849 else
850 setVScrollBarMode(QScrollView::Auto); 850 setVScrollBarMode(QScrollView::Auto);
851 if ( ihei *3 > height() ) 851 if ( ihei *3 > height() )
852 setHScrollBarMode(QScrollView::AlwaysOff); 852 setHScrollBarMode(QScrollView::AlwaysOff);
853 else 853 else
854 setHScrollBarMode(QScrollView::Auto); 854 setHScrollBarMode(QScrollView::Auto);
855 } else { 855 } else {
856 setVScrollBarMode(QScrollView::Auto); 856 setVScrollBarMode(QScrollView::Auto);
857 setHScrollBarMode(QScrollView::Auto); 857 setHScrollBarMode(QScrollView::Auto);
858 } 858 }
859 } else { 859 } else {
860 setVScrollBarMode(QScrollView::AlwaysOff); 860 setVScrollBarMode(QScrollView::AlwaysOff);
861 setHScrollBarMode(QScrollView::AlwaysOff); 861 setHScrollBarMode(QScrollView::AlwaysOff);
862 } 862 }
863} 863}
864 864
865Incidence *MonthViewCell::selectedIncidence() 865Incidence *MonthViewCell::selectedIncidence()
866{ 866{
867 int index = currentItem(); 867 int index = currentItem();
868 if ( index < 0 ) return 0; 868 if ( index < 0 ) return 0;
869 869
870 MonthViewItem *mitem = 870 MonthViewItem *mitem =
871 static_cast<MonthViewItem *>( item( index ) ); 871 static_cast<MonthViewItem *>( item( index ) );
872 872
873 if ( !mitem ) return 0; 873 if ( !mitem ) return 0;
874 874
875 return mitem->incidence(); 875 return mitem->incidence();
876} 876}
877 877
878QDate MonthViewCell::selectedIncidenceDate() 878QDate MonthViewCell::selectedIncidenceDate()
879{ 879{
880 QDate qd; 880 QDate qd;
881 int index = currentItem(); 881 int index = currentItem();
882 if ( index < 0 ) return qd; 882 if ( index < 0 ) return qd;
883 883
884 MonthViewItem *mitem = 884 MonthViewItem *mitem =
885 static_cast<MonthViewItem *>( item( index ) ); 885 static_cast<MonthViewItem *>( item( index ) );
886 886
887 if ( !mitem ) return qd; 887 if ( !mitem ) return qd;
888 888
889 return mitem->incidenceDate(); 889 return mitem->incidenceDate();
890} 890}
891 891
892void MonthViewCell::deselect() 892void MonthViewCell::deselect()
893{ 893{
894 clearSelection(); 894 clearSelection();
895 enableScrollBars( false ); 895 enableScrollBars( false );
896 // updateCell(); 896 // updateCell();
897} 897}
898void MonthViewCell::select() 898void MonthViewCell::select()
899{ 899{
900 ;// updateCell(); 900 ;// updateCell();
901} 901}
902 902
903void MonthViewCell::resizeEvent ( QResizeEvent * e ) 903void MonthViewCell::resizeEvent ( QResizeEvent * e )
904{ 904{
905 if ( !mMonthView->isUpdatePossible() ) 905 if ( !mMonthView->isUpdatePossible() )
906 return; 906 return;
907 //qDebug("++++++++++++++MonthViewCell::resizeEvent %d %d ", width(), height()); 907 //qDebug("++++++++++++++MonthViewCell::resizeEvent %d %d ", width(), height());
908 deselect(); 908 deselect();
909 mLabel->setMaximumHeight( height() - lineWidth()*2 ); 909 mLabel->setMaximumHeight( height() - lineWidth()*2 );
910 910
911 QString text; 911 QString text;
912 mLabel->setText( text ); 912 mLabel->setText( text );
913 bool smallDisplay = QApplication::desktop()->width() < 320 && KOPrefs::instance()->mMonthViewSatSunTog; 913 bool smallDisplay = QApplication::desktop()->width() < 320 && KOPrefs::instance()->mMonthViewSatSunTog;
914 if ( KOPrefs::instance()->mMonthViewWeek || KOGlobals::self()->calendarSystem()->day( mDate ) == 1 || (mDate.dayOfWeek() == 7 && !smallDisplay ) || KOPrefs::instance()->mMonthShowShort) { 914 if ( KOPrefs::instance()->mMonthViewWeek || KOGlobals::self()->calendarSystem()->day( mDate ) == 1 || (mDate.dayOfWeek() == 7 && !smallDisplay ) || KOPrefs::instance()->mMonthShowShort) {
915 text = KOGlobals::self()->calendarSystem()->monthName( mDate, true ) + " "; 915 text = KOGlobals::self()->calendarSystem()->monthName( mDate, true ) + " ";
916 mLabel->resize( mLabelBigSize ); 916 mLabel->resize( mLabelBigSize );
917 text += QString::number( KOGlobals::self()->calendarSystem()->day(mDate) ); 917 text += QString::number( KOGlobals::self()->calendarSystem()->day(mDate) );
918 } else { 918 } else {
919 mLabel->resize( mLabelSize ); 919 mLabel->resize( mLabelSize );
920 text += QString::number( KOGlobals::self()->calendarSystem()->day(mDate) ); 920 text += QString::number( KOGlobals::self()->calendarSystem()->day(mDate) );
921 } 921 }
922 mLabel->setText( text ); 922 mLabel->setText( text );
923 923
924 int size = height() - mLabel->height() - lineWidth()-1; 924 int size = height() - mLabel->height() - lineWidth()-1;
925 //qDebug("LW %d ", lineWidth()); 925 //qDebug("LW %d ", lineWidth());
926 if ( size > 0 ) 926 if ( size > 0 )
927 verticalScrollBar()->setMaximumHeight( size ); 927 verticalScrollBar()->setMaximumHeight( size );
928 size = width() - mLabel->width() -lineWidth()-1; 928 size = width() - mLabel->width() -lineWidth()-1;
929 if ( size > 0 ) 929 if ( size > 0 )
930 horizontalScrollBar()->setMaximumWidth( size ); 930 horizontalScrollBar()->setMaximumWidth( size );
931 mLabel->move( width()-lineWidth() - mLabel->width(), height()-lineWidth() - mLabel->height() ); 931 mLabel->move( width()-lineWidth() - mLabel->width(), height()-lineWidth() - mLabel->height() );
932 //mLabel->setMaximumWidth( width() - mItemList->lineWidth()*2); 932 //mLabel->setMaximumWidth( width() - mItemList->lineWidth()*2);
933 // mItemList->resize ( width(), height () ); 933 // mItemList->resize ( width(), height () );
934 if ( e ) 934 if ( e )
935 KNoScrollListBox::resizeEvent ( e ); 935 KNoScrollListBox::resizeEvent ( e );
936} 936}
937 937
938void MonthViewCell::defaultAction( QListBoxItem *item ) 938void MonthViewCell::defaultAction( QListBoxItem *item )
939{ 939{
940 if ( !item ) return; 940 if ( !item ) return;
941 941
942 MonthViewItem *eventItem = static_cast<MonthViewItem *>( item ); 942 MonthViewItem *eventItem = static_cast<MonthViewItem *>( item );
943 Incidence *incidence = eventItem->incidence(); 943 Incidence *incidence = eventItem->incidence();
944 if ( incidence ) mMonthView->defaultAction( incidence ); 944 if ( incidence ) mMonthView->defaultAction( incidence );
945} 945}
946void MonthViewCell::showDay() 946void MonthViewCell::showDay()
947{ 947{
948 emit showDaySignal( date() ); 948 emit showDaySignal( date() );
949} 949}
950void MonthViewCell::newEvent() 950void MonthViewCell::newEvent()
951{ 951{
952 QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) ); 952 QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) );
953 emit newEventSignal( dt ); 953 emit newEventSignal( dt );
954} 954}
955void MonthViewCell::cellClicked( QListBoxItem *item ) 955void MonthViewCell::cellClicked( QListBoxItem *item )
956{ 956{
957 static QListBoxItem * lastClicked = 0; 957 static QListBoxItem * lastClicked = 0;
958 if ( item == 0 ) { 958 if ( item == 0 ) {
959 QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) ); 959 QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) );
960 emit newEventSignal( dt ); 960 emit newEventSignal( dt );
961 return; 961 return;
962 } 962 }
963 /* 963 /*
964 if ( lastClicked ) 964 if ( lastClicked )
965 if ( ! item ) { 965 if ( ! item ) {
966 if ( lastClicked->listBox() != item->listBox() ) 966 if ( lastClicked->listBox() != item->listBox() )
967 lastClicked->listBox()->clearSelection(); 967 lastClicked->listBox()->clearSelection();
968 } 968 }
969 */ 969 */
970 970
971 mMonthView->setSelectedCell( this ); 971 mMonthView->setSelectedCell( this );
972 if( KOPrefs::instance()->mEnableMonthScroll || KOPrefs::instance()->mMonthViewWeek ) enableScrollBars( true ); 972 if( KOPrefs::instance()->mEnableMonthScroll || KOPrefs::instance()->mMonthViewWeek ) enableScrollBars( true );
973 select(); 973 select();
974} 974}
975 975
976void MonthViewCell::contextMenu( QListBoxItem *item ) 976void MonthViewCell::contextMenu( QListBoxItem *item )
977{ 977{
978 if ( !item ) return; 978 if ( !item ) return;
979 979
980 MonthViewItem *eventItem = static_cast<MonthViewItem *>( item ); 980 MonthViewItem *eventItem = static_cast<MonthViewItem *>( item );
981 Incidence *incidence = eventItem->incidence(); 981 Incidence *incidence = eventItem->incidence();
982 if ( incidence ) mMonthView->showContextMenu( incidence ); 982 if ( incidence ) mMonthView->showContextMenu( incidence );
983} 983}
984 984
985void MonthViewCell::selection( QListBoxItem *item ) 985void MonthViewCell::selection( QListBoxItem *item )
986{ 986{
987 if ( !item ) return; 987 if ( !item ) return;
988 988
989 mMonthView->setSelectedCell( this ); 989 mMonthView->setSelectedCell( this );
990} 990}
991 991
992 992
993// ******************************************************************************* 993// *******************************************************************************
994// ******************************************************************************* 994// *******************************************************************************
995// ******************************************************************************* 995// *******************************************************************************
996 996
997 997
998KOMonthView::KOMonthView(Calendar *calendar, QWidget *parent, const char *name) 998KOMonthView::KOMonthView(Calendar *calendar, QWidget *parent, const char *name)
999 : KOEventView( calendar, parent, name ), 999 : KOEventView( calendar, parent, name ),
1000 mDaysPerWeek( 7 ), mNumWeeks( 6 ), mNumCells( mDaysPerWeek * mNumWeeks ), 1000 mDaysPerWeek( 7 ), mNumWeeks( 6 ), mNumCells( mDaysPerWeek * mNumWeeks ),
1001 mWidthLongDayLabel( 0 ), mSelectedCell( 0 ) 1001 mWidthLongDayLabel( 0 ), mSelectedCell( 0 )
1002{ 1002{
1003 mFlagKeyPressed = false;
1003 mShortDayLabelsM = false; 1004 mShortDayLabelsM = false;
1004 mShortDayLabelsW = false; 1005 mShortDayLabelsW = false;
1005 skipResize = false; 1006 skipResize = false;
1006 clPending = true; 1007 clPending = true;
1007 mNavigatorBar = new NavigatorBar( QDate::currentDate(), this, "useBigPixmaps" ); 1008 mNavigatorBar = new NavigatorBar( QDate::currentDate(), this, "useBigPixmaps" );
1008 mWidStack = new QWidgetStack( this ); 1009 mWidStack = new QWidgetStack( this );
1009 QVBoxLayout* hb = new QVBoxLayout( this ); 1010 QVBoxLayout* hb = new QVBoxLayout( this );
1010 mMonthView = new QWidget( mWidStack ); 1011 mMonthView = new QWidget( mWidStack );
1011 mWeekView = new QWidget( mWidStack ); 1012 mWeekView = new QWidget( mWidStack );
1012#if QT_VERSION >= 0x030000 1013#if QT_VERSION >= 0x030000
1013 mWidStack->addWidget(mMonthView ); 1014 mWidStack->addWidget(mMonthView );
1014 mWidStack->addWidget(mWeekView ); 1015 mWidStack->addWidget(mWeekView );
1015#else 1016#else
1016 mWidStack->addWidget( mMonthView, 1 ); 1017 mWidStack->addWidget( mMonthView, 1 );
1017 mWidStack->addWidget( mWeekView , 1 ); 1018 mWidStack->addWidget( mWeekView , 1 );
1018#endif 1019#endif
1019 hb->addWidget( mNavigatorBar ); 1020 hb->addWidget( mNavigatorBar );
1020 hb->addWidget( mWidStack ); 1021 hb->addWidget( mWidStack );
1021 mShowWeekView = KOPrefs::instance()->mMonthViewWeek; 1022 mShowWeekView = KOPrefs::instance()->mMonthViewWeek;
1022 updatePossible = false; 1023 updatePossible = false;
1023 //updatePossible = true; 1024 //updatePossible = true;
1024 mCells.setAutoDelete( true ); 1025 mCells.setAutoDelete( true );
1025 mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ; 1026 mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ;
1026 mDayLabels.resize( mDaysPerWeek ); 1027 mDayLabels.resize( mDaysPerWeek );
1027 mDayLabelsW.resize( mDaysPerWeek ); 1028 mDayLabelsW.resize( mDaysPerWeek );
1028 QFont bfont = font(); 1029 QFont bfont = font();
1029 if ( QApplication::desktop()->width() < 650 ) { 1030 if ( QApplication::desktop()->width() < 650 ) {
1030 bfont.setPointSize( bfont.pointSize() - 2 ); 1031 bfont.setPointSize( bfont.pointSize() - 2 );
1031 } 1032 }
1032 bfont.setBold( true ); 1033 bfont.setBold( true );
1033 int i; 1034 int i;
1034 1035
1035 for( i = 0; i < mDaysPerWeek; i++ ) { 1036 for( i = 0; i < mDaysPerWeek; i++ ) {
1036 QLabel *label = new QLabel( mMonthView ); 1037 QLabel *label = new QLabel( mMonthView );
1037 label->setFont(bfont); 1038 label->setFont(bfont);
1038 label->setFrameStyle(QFrame::Panel|QFrame::Raised); 1039 label->setFrameStyle(QFrame::Panel|QFrame::Raised);
1039 label->setLineWidth(1); 1040 label->setLineWidth(1);
1040 label->setAlignment(AlignCenter); 1041 label->setAlignment(AlignCenter);
1041 mDayLabels.insert( i, label ); 1042 mDayLabels.insert( i, label );
1042 label = new QLabel( mWeekView ); 1043 label = new QLabel( mWeekView );
1043 label->setFont(bfont); 1044 label->setFont(bfont);
1044 label->setFrameStyle(QFrame::Panel|QFrame::Raised); 1045 label->setFrameStyle(QFrame::Panel|QFrame::Raised);
1045 label->setLineWidth(1); 1046 label->setLineWidth(1);
1046 label->setAlignment(AlignCenter); 1047 label->setAlignment(AlignCenter);
1047 mDayLabelsW.insert( i, label ); 1048 mDayLabelsW.insert( i, label );
1048 } 1049 }
1049 1050
1050 bfont.setBold( false ); 1051 bfont.setBold( false );
1051 mWeekLabels.resize( mNumWeeks+1 ); 1052 mWeekLabels.resize( mNumWeeks+1 );
1052 mWeekLabelsW.resize( 2 ); 1053 mWeekLabelsW.resize( 2 );
1053 for( i = 0; i < mNumWeeks+1; i++ ) { 1054 for( i = 0; i < mNumWeeks+1; i++ ) {
1054 KOWeekButton *label = new KOWeekButton( mMonthView ); 1055 KOWeekButton *label = new KOWeekButton( mMonthView );
1055 label->setFocusPolicy(NoFocus); 1056 label->setFocusPolicy(NoFocus);
1056 label->setFont(bfont); 1057 label->setFont(bfont);
1057 connect( label, SIGNAL( selectWeekNum ( int )),this, SLOT( selectInternalWeekNum ( int )) ); 1058 connect( label, SIGNAL( selectWeekNum ( int )),this, SLOT( selectInternalWeekNum ( int )) );
1058 label->setFlat(true); 1059 label->setFlat(true);
1059 QWhatsThis::add(label,i18n("Click on the week number to\nshow week zoomed")); 1060 QWhatsThis::add(label,i18n("Click on the week number to\nshow week zoomed"));
1060 //label->setFrameStyle(QFrame::Panel|QFrame::Raised); 1061 //label->setFrameStyle(QFrame::Panel|QFrame::Raised);
1061 //label->setLineWidth(1); 1062 //label->setLineWidth(1);
1062 //label->setAlignment(AlignCenter); 1063 //label->setAlignment(AlignCenter);
1063 mWeekLabels.insert( i, label ); 1064 mWeekLabels.insert( i, label );
1064 } 1065 }
1065 mWeekLabels[mNumWeeks]->setText( i18n("W")); 1066 mWeekLabels[mNumWeeks]->setText( i18n("W"));
1066 mWeekLabels[0]->setFocusPolicy(WheelFocus); 1067 mWeekLabels[0]->setFocusPolicy(WheelFocus);
1067 QWhatsThis::add(mWeekLabels[mNumWeeks],i18n("Click on this to\nselect week number")); 1068 QWhatsThis::add(mWeekLabels[mNumWeeks],i18n("Click on this to\nselect week number"));
1068 1069
1069 for( i = 0; i < 1+1; i++ ) { 1070 for( i = 0; i < 1+1; i++ ) {
1070 KOWeekButton *label = new KOWeekButton( mWeekView ); 1071 KOWeekButton *label = new KOWeekButton( mWeekView );
1071 label->setFocusPolicy(NoFocus); 1072 label->setFocusPolicy(NoFocus);
1072 label->setFont(bfont); 1073 label->setFont(bfont);
1073 connect( label, SIGNAL( selectWeekNum ( int )),this, SLOT( selectInternalWeekNum ( int )) ); 1074 connect( label, SIGNAL( selectWeekNum ( int )),this, SLOT( selectInternalWeekNum ( int )) );
1074 label->setFlat(true); 1075 label->setFlat(true);
1075 QWhatsThis::add(label,i18n("Click on the week number to\nshow week zoomed")); 1076 QWhatsThis::add(label,i18n("Click on the week number to\nshow week zoomed"));
1076 //label->setFrameStyle(QFrame::Panel|QFrame::Raised); 1077 //label->setFrameStyle(QFrame::Panel|QFrame::Raised);
1077 //label->setLineWidth(1); 1078 //label->setLineWidth(1);
1078 //label->setAlignment(AlignCenter); 1079 //label->setAlignment(AlignCenter);
1079 mWeekLabelsW.insert( i, label ); 1080 mWeekLabelsW.insert( i, label );
1080 } 1081 }
1081 mWeekLabelsW[1]->setText( i18n("W")); 1082 mWeekLabelsW[1]->setText( i18n("W"));
1082 mWeekLabelsW[0]->setFocusPolicy(WheelFocus); 1083 mWeekLabelsW[0]->setFocusPolicy(WheelFocus);
1083 1084
1084 1085
1085 int row, col; 1086 int row, col;
1086 mCells.resize( mNumCells ); 1087 mCells.resize( mNumCells );
1087 for( row = 0; row < mNumWeeks; ++row ) { 1088 for( row = 0; row < mNumWeeks; ++row ) {
1088 for( col = 0; col < mDaysPerWeek; ++col ) { 1089 for( col = 0; col < mDaysPerWeek; ++col ) {
1089 MonthViewCell *cell = new MonthViewCell( this, mMonthView ); 1090 MonthViewCell *cell = new MonthViewCell( this, mMonthView );
1090 mCells.insert( row * mDaysPerWeek + col, cell ); 1091 mCells.insert( row * mDaysPerWeek + col, cell );
1091 1092
1092 connect( cell, SIGNAL( defaultAction( Incidence * ) ), 1093 connect( cell, SIGNAL( defaultAction( Incidence * ) ),
1093 SLOT( defaultAction( Incidence * ) ) ); 1094 SLOT( defaultAction( Incidence * ) ) );
1094 connect( cell, SIGNAL( newEventSignal( QDateTime ) ), 1095 connect( cell, SIGNAL( newEventSignal( QDateTime ) ),
1095 SIGNAL( newEventSignal( QDateTime ) ) ); 1096 SIGNAL( newEventSignal( QDateTime ) ) );
1096 connect( cell, SIGNAL( showDaySignal( QDate ) ), 1097 connect( cell, SIGNAL( showDaySignal( QDate ) ),
1097 SIGNAL( showDaySignal( QDate ) ) ); 1098 SIGNAL( showDaySignal( QDate ) ) );
1098 } 1099 }
1099 } 1100 }
1100 mCellsW.resize( mDaysPerWeek ); 1101 mCellsW.resize( mDaysPerWeek );
1101 for( col = 0; col < mDaysPerWeek; ++col ) { 1102 for( col = 0; col < mDaysPerWeek; ++col ) {
1102 MonthViewCell *cell = new MonthViewCell( this, mWeekView ); 1103 MonthViewCell *cell = new MonthViewCell( this, mWeekView );
1103 mCellsW.insert( col, cell ); 1104 mCellsW.insert( col, cell );
1104 1105
1105 connect( cell, SIGNAL( defaultAction( Incidence * ) ), 1106 connect( cell, SIGNAL( defaultAction( Incidence * ) ),
1106 SLOT( defaultAction( Incidence * ) ) ); 1107 SLOT( defaultAction( Incidence * ) ) );
1107 connect( cell, SIGNAL( newEventSignal( QDateTime ) ), 1108 connect( cell, SIGNAL( newEventSignal( QDateTime ) ),
1108 SIGNAL( newEventSignal( QDateTime ) ) ); 1109 SIGNAL( newEventSignal( QDateTime ) ) );
1109 connect( cell, SIGNAL( showDaySignal( QDate ) ), 1110 connect( cell, SIGNAL( showDaySignal( QDate ) ),
1110 SIGNAL( showDaySignal( QDate ) ) ); 1111 SIGNAL( showDaySignal( QDate ) ) );
1111 cell->updateConfig(KOPrefs::instance()->mMonthViewUsesBigFont ); 1112 cell->updateConfig(KOPrefs::instance()->mMonthViewUsesBigFont );
1112 } 1113 }
1113 1114
1114 //connect( mWeekLabels[mNumWeeks], SIGNAL( clicked() ), SLOT( switchView() ) ); 1115 //connect( mWeekLabels[mNumWeeks], SIGNAL( clicked() ), SLOT( switchView() ) );
1115 mContextMenu = eventPopup(); 1116 mContextMenu = eventPopup();
1116 // updateConfig(); //useless here... 1117 // updateConfig(); //useless here...
1117 // ... but we need mWidthLongDayLabel computed 1118 // ... but we need mWidthLongDayLabel computed
1118 QFontMetrics fontmetric(mDayLabels[0]->font()); 1119 QFontMetrics fontmetric(mDayLabels[0]->font());
1119 mWidthLongDayLabel = 0; 1120 mWidthLongDayLabel = 0;
1120 for (int i = 0; i < 7; i++) { 1121 for (int i = 0; i < 7; i++) {
1121 int width = fontmetric.width(KOGlobals::self()->calendarSystem()->weekDayName(i+1)); 1122 int width = fontmetric.width(KOGlobals::self()->calendarSystem()->weekDayName(i+1));
1122 if ( width > mWidthLongDayLabel ) mWidthLongDayLabel = width; 1123 if ( width > mWidthLongDayLabel ) mWidthLongDayLabel = width;
1123 } 1124 }
1124 1125
1125 //mWeekLabels[mNumWeeks]->setText( i18n("W")); 1126 //mWeekLabels[mNumWeeks]->setText( i18n("W"));
1126 1127
1127#if 0 1128#if 0
1128 if ( mShowWeekView ) 1129 if ( mShowWeekView )
1129 mWidStack->raiseWidget( mWeekView ); 1130 mWidStack->raiseWidget( mWeekView );
1130 else 1131 else
1131 mWidStack->raiseWidget( mMonthView ); 1132 mWidStack->raiseWidget( mMonthView );
1132#endif 1133#endif
1133 1134
1134 emit incidenceSelected( 0 ); 1135 emit incidenceSelected( 0 );
1135 1136
1136 mComputeLayoutTimer = new QTimer( this ); 1137 mComputeLayoutTimer = new QTimer( this );
1137 connect (mComputeLayoutTimer ,SIGNAL(timeout()), this, SLOT ( slotComputeLayout())); 1138 connect (mComputeLayoutTimer ,SIGNAL(timeout()), this, SLOT ( slotComputeLayout()));
1138 1139
1139 1140
1140#ifndef DESKTOP_VERSION 1141#ifndef DESKTOP_VERSION
1141 resize( QApplication::desktop()->size() ); 1142 resize( QApplication::desktop()->size() );
1142#else 1143#else
1143 resize(640, 480 ); 1144 resize(640, 480 );
1144 updatePossible = true; 1145 updatePossible = true;
1145#endif 1146#endif
1146 computeLayout(); 1147 computeLayout();
1147 1148
1148 if ( mShowWeekView ) 1149 if ( mShowWeekView )
1149 mWidStack->raiseWidget( mWeekView ); 1150 mWidStack->raiseWidget( mWeekView );
1150 else 1151 else
1151 mWidStack->raiseWidget( mMonthView ); 1152 mWidStack->raiseWidget( mMonthView );
1152} 1153}
1153 1154
1154KOMonthView::~KOMonthView() 1155KOMonthView::~KOMonthView()
1155{ 1156{
1156 delete mContextMenu; 1157 delete mContextMenu;
1157} 1158}
1158 1159
1159void KOMonthView::selectInternalWeekNum ( int n ) 1160void KOMonthView::selectInternalWeekNum ( int n )
1160{ 1161{
1161 switchView(); 1162 switchView();
1162 if ( !KOPrefs::instance()->mMonthViewWeek ) 1163 if ( !KOPrefs::instance()->mMonthViewWeek )
1163 emit selectMonth (); 1164 emit selectMonth ();
1164 else 1165 else
1165 emit selectWeekNum ( n ); 1166 emit selectWeekNum ( n );
1166} 1167}
1167 1168
1168int KOMonthView::currentWeek() 1169int KOMonthView::currentWeek()
1169{ 1170{
1170 if ( mShowWeekView ) 1171 if ( mShowWeekView )
1171 return mWeekLabelsW[0]->getWeekNum(); 1172 return mWeekLabelsW[0]->getWeekNum();
1172 return mWeekLabels[0]->getWeekNum(); 1173 return mWeekLabels[0]->getWeekNum();
1173} 1174}
1174void KOMonthView::switchView() 1175void KOMonthView::switchView()
1175{ 1176{
1176 if ( selectedCell( ) ) 1177 if ( selectedCell( ) )
1177 selectedCell()->deselect(); 1178 selectedCell()->deselect();
1178 mShowWeekView = !mShowWeekView; 1179 mShowWeekView = !mShowWeekView;
1179 KOPrefs::instance()->mMonthViewWeek = mShowWeekView; 1180 KOPrefs::instance()->mMonthViewWeek = mShowWeekView;
1180 if ( clPending ) { 1181 if ( clPending ) {
1181 computeLayout(); 1182 computeLayout();
1182 updateConfig(); 1183 updateConfig();
1183 } 1184 }
1184 if ( mShowWeekView ) 1185 if ( mShowWeekView )
1185 mWidStack->raiseWidget( mWeekView ); 1186 mWidStack->raiseWidget( mWeekView );
1186 else 1187 else
1187 mWidStack->raiseWidget( mMonthView ); 1188 mWidStack->raiseWidget( mMonthView );
1188 clPending = false; 1189 clPending = false;
1189} 1190}
1190 1191
1191int KOMonthView::maxDatesHint() 1192int KOMonthView::maxDatesHint()
1192{ 1193{
1193 return mNumCells; 1194 return mNumCells;
1194} 1195}
1195 1196
1196int KOMonthView::currentDateCount() 1197int KOMonthView::currentDateCount()
1197{ 1198{
1198 return mNumCells; 1199 return mNumCells;
1199} 1200}
1200 1201
1201QPtrList<Incidence> KOMonthView::selectedIncidences() 1202QPtrList<Incidence> KOMonthView::selectedIncidences()
1202{ 1203{
1203 QPtrList<Incidence> selected; 1204 QPtrList<Incidence> selected;
1204 1205
1205 if ( mSelectedCell ) { 1206 if ( mSelectedCell ) {
1206 Incidence *incidence = mSelectedCell->selectedIncidence(); 1207 Incidence *incidence = mSelectedCell->selectedIncidence();
1207 if ( incidence ) selected.append( incidence ); 1208 if ( incidence ) selected.append( incidence );
1208 } 1209 }
1209 1210
1210 return selected; 1211 return selected;
1211} 1212}
1212 1213
1213DateList KOMonthView::selectedDates() 1214DateList KOMonthView::selectedDates()
1214{ 1215{
1215 DateList selected; 1216 DateList selected;
1216 1217
1217 if ( mSelectedCell ) { 1218 if ( mSelectedCell ) {
1218 QDate qd = mSelectedCell->selectedIncidenceDate(); 1219 QDate qd = mSelectedCell->selectedIncidenceDate();
1219 if ( qd.isValid() ) selected.append( qd ); 1220 if ( qd.isValid() ) selected.append( qd );
1220 } 1221 }
1221 1222
1222 return selected; 1223 return selected;
1223} 1224}
1224 1225
1225void KOMonthView::printPreview(CalPrinter *calPrinter, const QDate &fd, 1226void KOMonthView::printPreview(CalPrinter *calPrinter, const QDate &fd,
1226 const QDate &td) 1227 const QDate &td)
1227{ 1228{
1228#ifndef KORG_NOPRINTER 1229#ifndef KORG_NOPRINTER
1229 calPrinter->preview(CalPrinter::Month, fd, td); 1230 calPrinter->preview(CalPrinter::Month, fd, td);
1230#endif 1231#endif
1231} 1232}
1232 1233
1233void KOMonthView::updateConfig() 1234void KOMonthView::updateConfig()
1234{ 1235{
1235 1236
1236 int mWeekStartsMonday = KGlobal::locale()->weekStartsMonday(); 1237 int mWeekStartsMonday = KGlobal::locale()->weekStartsMonday();
1237 1238
1238 if ( mShowWeekView || KOPrefs::instance()->mMonthViewSatSunTog ) { 1239 if ( mShowWeekView || KOPrefs::instance()->mMonthViewSatSunTog ) {
1239 mWeekStartsMonday = true; 1240 mWeekStartsMonday = true;
1240 } 1241 }
1241 QFontMetrics fontmetric(mDayLabels[0]->font()); 1242 QFontMetrics fontmetric(mDayLabels[0]->font());
1242 mWidthLongDayLabel = 0; 1243 mWidthLongDayLabel = 0;
1243 1244
1244 for (int i = 0; i < 7; i++) { 1245 for (int i = 0; i < 7; i++) {
1245 int width = fontmetric.width(KOGlobals::self()->calendarSystem()->weekDayName(i+1)); 1246 int width = fontmetric.width(KOGlobals::self()->calendarSystem()->weekDayName(i+1));
1246 if ( width > mWidthLongDayLabel ) mWidthLongDayLabel = width; 1247 if ( width > mWidthLongDayLabel ) mWidthLongDayLabel = width;
1247 } 1248 }
1248 bool temp = mShowSatSunComp ; 1249 bool temp = mShowSatSunComp ;
1249 mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ; 1250 mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ;
1250 if ( ! mShowWeekView ) { 1251 if ( ! mShowWeekView ) {
1251 if ( temp != KOPrefs::instance()->mMonthViewSatSunTog ) 1252 if ( temp != KOPrefs::instance()->mMonthViewSatSunTog )
1252 computeLayout(); 1253 computeLayout();
1253 } 1254 }
1254 updateDayLabels(); 1255 updateDayLabels();
1255 //qDebug("KOMonthView::updateConfig() %d %d %d ",height(), mDayLabels[0]->sizeHint().height() ,mNumWeeks); 1256 //qDebug("KOMonthView::updateConfig() %d %d %d ",height(), mDayLabels[0]->sizeHint().height() ,mNumWeeks);
1256 //int cellHeight = (height() - mDayLabels[0]->sizeHint().height()) /mNumWeeks; 1257 //int cellHeight = (height() - mDayLabels[0]->sizeHint().height()) /mNumWeeks;
1257 //resizeEvent( 0 ); 1258 //resizeEvent( 0 );
1258 for (uint i = 0; i < mCells.count(); ++i) { 1259 for (uint i = 0; i < mCells.count(); ++i) {
@@ -1584,303 +1585,319 @@ void KOMonthView::computeLayoutWeek()
1584 int i; 1585 int i;
1585 int x,y,w,h; 1586 int x,y,w,h;
1586 x= 0; 1587 x= 0;
1587 y= 0; 1588 y= 0;
1588 w = colWid; 1589 w = colWid;
1589 h = dayLabelHei ; 1590 h = dayLabelHei ;
1590 for ( i = 0; i < 7; i++) { 1591 for ( i = 0; i < 7; i++) {
1591 if ( i && !( i % daysToShow) && i < 6) { 1592 if ( i && !( i % daysToShow) && i < 6) {
1592 y += hei/(5-daysToShow); 1593 y += hei/(5-daysToShow);
1593 x = 0; 1594 x = 0;
1594 w = colWid; 1595 w = colWid;
1595 } 1596 }
1596 if ( ((i) % daysToShow) >= daysToShow-colModulo ) { 1597 if ( ((i) % daysToShow) >= daysToShow-colModulo ) {
1597 ++w; 1598 ++w;
1598 } 1599 }
1599 if ( i >= 5 ) { 1600 if ( i >= 5 ) {
1600 mDayLabelsW[i]->setGeometry( x+weeklabelwid,y,w/2+w%2,h); 1601 mDayLabelsW[i]->setGeometry( x+weeklabelwid,y,w/2+w%2,h);
1601 x -= (w/2 ); 1602 x -= (w/2 );
1602 } 1603 }
1603 else 1604 else
1604 mDayLabelsW[i]->setGeometry( x+weeklabelwid,y,w,h); 1605 mDayLabelsW[i]->setGeometry( x+weeklabelwid,y,w,h);
1605 x += w; 1606 x += w;
1606 } 1607 }
1607 x= 0; 1608 x= 0;
1608 y= dayLabelHei; 1609 y= dayLabelHei;
1609 w = colWid; 1610 w = colWid;
1610 h = cellHei; 1611 h = cellHei;
1611 int max = 0; 1612 int max = 0;
1612 for ( i = 0; i < mCellsW.count(); ++i) { 1613 for ( i = 0; i < mCellsW.count(); ++i) {
1613 if ( i > 6 ) { 1614 if ( i > 6 ) {
1614 mCellsW[i]->hide(); 1615 mCellsW[i]->hide();
1615 continue; 1616 continue;
1616 } 1617 }
1617 1618
1618 w = colWid; 1619 w = colWid;
1619 if ( ((i) % daysToShow) >= daysToShow-colModulo ) { 1620 if ( ((i) % daysToShow) >= daysToShow-colModulo ) {
1620 ++w; 1621 ++w;
1621 } 1622 }
1622 if ( i == (daysToShow-1-rowModulo)*7) 1623 if ( i == (daysToShow-1-rowModulo)*7)
1623 ++h; 1624 ++h;
1624 1625
1625 if ( i >= 5 ) { 1626 if ( i >= 5 ) {
1626 if ( i ==5 ) { 1627 if ( i ==5 ) {
1627 max = h/2; 1628 max = h/2;
1628 mCellsW[i]->setGeometry ( x+weeklabelwid,y,w,max ); 1629 mCellsW[i]->setGeometry ( x+weeklabelwid,y,w,max );
1629 x -= w ;y += h/2; 1630 x -= w ;y += h/2;
1630 } else { 1631 } else {
1631 if ( ((i-1) % daysToShow) >= daysToShow-colModulo ) { 1632 if ( ((i-1) % daysToShow) >= daysToShow-colModulo ) {
1632 ++w; 1633 ++w;
1633 } 1634 }
1634 max = h-h/2; 1635 max = h-h/2;
1635 mCellsW[i]->setGeometry ( x+weeklabelwid,y,w,max ); 1636 mCellsW[i]->setGeometry ( x+weeklabelwid,y,w,max );
1636 y -= h/2; 1637 y -= h/2;
1637 } 1638 }
1638 } else { 1639 } else {
1639 max = h; 1640 max = h;
1640 mCellsW[i]->setGeometry ( x+weeklabelwid,y,w,h ); 1641 mCellsW[i]->setGeometry ( x+weeklabelwid,y,w,h );
1641 } 1642 }
1642 1643
1643 1644
1644 x += w; 1645 x += w;
1645 if ( x + w/2 > wid ) { 1646 if ( x + w/2 > wid ) {
1646 x = 0; 1647 x = 0;
1647 y += h+dayLabelHei ; 1648 y += h+dayLabelHei ;
1648 } 1649 }
1649 //mCellsW[i]->dateLabel()->setMaximumHeight( max - mCellsW[i]->lineWidth()*2 ); 1650 //mCellsW[i]->dateLabel()->setMaximumHeight( max - mCellsW[i]->lineWidth()*2 );
1650 } 1651 }
1651 y= dayLabelHei; 1652 y= dayLabelHei;
1652 h = cellHei ; 1653 h = cellHei ;
1653 mWeekLabelsW[0]->setGeometry( 0,y,weeklabelwid,hei-dayLabelHei); 1654 mWeekLabelsW[0]->setGeometry( 0,y,weeklabelwid,hei-dayLabelHei);
1654 mWeekLabelsW[1]->setGeometry( 0,0,weeklabelwid,dayLabelHei); 1655 mWeekLabelsW[1]->setGeometry( 0,0,weeklabelwid,dayLabelHei);
1655 // qDebug("RRRRRRRRRRRRR %d %d old %d %d", e->size().width(),e->size().height() , e->oldSize().width(),e->oldSize().height()); 1656 // qDebug("RRRRRRRRRRRRR %d %d old %d %d", e->size().width(),e->size().height() , e->oldSize().width(),e->oldSize().height());
1656 //qDebug("parent %d %d ", topLevelWidget()->size().width(), topLevelWidget()->size().height()); 1657 //qDebug("parent %d %d ", topLevelWidget()->size().width(), topLevelWidget()->size().height());
1657 mShortDayLabelsW = mDayLabelsW[0]->width()-2 < mWidthLongDayLabel ; 1658 mShortDayLabelsW = mDayLabelsW[0]->width()-2 < mWidthLongDayLabel ;
1658 updateDayLabels(); 1659 updateDayLabels();
1659 //bool forceUpdate = !updatePossible; 1660 //bool forceUpdate = !updatePossible;
1660 updatePossible = true; 1661 updatePossible = true;
1661 //mWeekLabels[mNumWeeks]->setText( i18n("M")); 1662 //mWeekLabels[mNumWeeks]->setText( i18n("M"));
1662 //if ( forceUpdate ) 1663 //if ( forceUpdate )
1663 // updateView(); 1664 // updateView();
1664} 1665}
1665void KOMonthView::computeLayout() 1666void KOMonthView::computeLayout()
1666{ 1667{
1667 1668
1668 1669
1669 static int lastWid = 0; 1670 static int lastWid = 0;
1670 static int lastHei = 0; 1671 static int lastHei = 0;
1671 1672
1672 if ( mShowWeekView ){ 1673 if ( mShowWeekView ){
1673 computeLayoutWeek(); 1674 computeLayoutWeek();
1674 return; 1675 return;
1675 } 1676 }
1676 int daysToShow = 7; 1677 int daysToShow = 7;
1677 bool combinedSatSun = false; 1678 bool combinedSatSun = false;
1678 if (mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ) { 1679 if (mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ) {
1679 daysToShow = 6; 1680 daysToShow = 6;
1680 combinedSatSun = true; 1681 combinedSatSun = true;
1681 } 1682 }
1682 int tWid = topLevelWidget()->size().width(); 1683 int tWid = topLevelWidget()->size().width();
1683 int tHei = topLevelWidget()->size().height(); 1684 int tHei = topLevelWidget()->size().height();
1684 1685
1685 int wid = width();//e 1686 int wid = width();//e
1686 int hei = height()-1-mNavigatorBar->height(); 1687 int hei = height()-1-mNavigatorBar->height();
1687 1688
1688 if ( ((wid *3)/2) < tWid && (( hei *3) /2) < tHei ) { 1689 if ( ((wid *3)/2) < tWid && (( hei *3) /2) < tHei ) {
1689 return; 1690 return;
1690 } 1691 }
1691 if ( lastWid == width() && lastHei == height() ){ 1692 if ( lastWid == width() && lastHei == height() ){
1692 //qDebug("KOMonthview::No compute layout needed "); 1693 //qDebug("KOMonthview::No compute layout needed ");
1693 return; 1694 return;
1694 } 1695 }
1695 1696
1696 lastWid = width(); 1697 lastWid = width();
1697 lastHei = height(); 1698 lastHei = height();
1698 //qDebug("KOMonthView::computeLayout() MMM ------------------- "); 1699 //qDebug("KOMonthView::computeLayout() MMM ------------------- ");
1699 QFontMetrics fm ( mWeekLabels[0]->font() ); 1700 QFontMetrics fm ( mWeekLabels[0]->font() );
1700 int weeklabelwid = fm.width( "888" ); 1701 int weeklabelwid = fm.width( "888" );
1701 wid -= weeklabelwid; 1702 wid -= weeklabelwid;
1702 1703
1703 int colWid = wid / daysToShow; 1704 int colWid = wid / daysToShow;
1704 int lastCol = wid - ( colWid*6 ); 1705 int lastCol = wid - ( colWid*6 );
1705 int dayLabelHei = mDayLabels[0]->sizeHint().height(); 1706 int dayLabelHei = mDayLabels[0]->sizeHint().height();
1706 int cellHei = (hei - dayLabelHei) /6; 1707 int cellHei = (hei - dayLabelHei) /6;
1707 int colModulo = wid % daysToShow; 1708 int colModulo = wid % daysToShow;
1708 int rowModulo = (hei- dayLabelHei) % 6; 1709 int rowModulo = (hei- dayLabelHei) % 6;
1709 //qDebug("rowmod %d ", rowModulo); 1710 //qDebug("rowmod %d ", rowModulo);
1710 int i; 1711 int i;
1711 int x,y,w,h; 1712 int x,y,w,h;
1712 x= 0; 1713 x= 0;
1713 y= 0; 1714 y= 0;
1714 w = colWid; 1715 w = colWid;
1715 h = dayLabelHei ; 1716 h = dayLabelHei ;
1716 for ( i = 0; i < 7; i++) { 1717 for ( i = 0; i < 7; i++) {
1717 if ( i == daysToShow-colModulo ) 1718 if ( i == daysToShow-colModulo )
1718 ++w; 1719 ++w;
1719 if ( combinedSatSun ) { 1720 if ( combinedSatSun ) {
1720 if ( i >= daysToShow-1 ) { 1721 if ( i >= daysToShow-1 ) {
1721 mDayLabels[i]->setGeometry( x+weeklabelwid,y,w/2,h); 1722 mDayLabels[i]->setGeometry( x+weeklabelwid,y,w/2,h);
1722 x -= w/2 ; 1723 x -= w/2 ;
1723 } 1724 }
1724 else 1725 else
1725 mDayLabels[i]->setGeometry( x+weeklabelwid,y,w,h); 1726 mDayLabels[i]->setGeometry( x+weeklabelwid,y,w,h);
1726 } else 1727 } else
1727 mDayLabels[i]->setGeometry( x+weeklabelwid,y,w,h); 1728 mDayLabels[i]->setGeometry( x+weeklabelwid,y,w,h);
1728 x += w; 1729 x += w;
1729 } 1730 }
1730 x= 0; 1731 x= 0;
1731 y= dayLabelHei; 1732 y= dayLabelHei;
1732 w = colWid; 1733 w = colWid;
1733 h = cellHei ; 1734 h = cellHei ;
1734 int max = 0; 1735 int max = 0;
1735 for ( i = 0; i < mCells.count(); ++i) { 1736 for ( i = 0; i < mCells.count(); ++i) {
1736 //qDebug("iii %d ", i); 1737 //qDebug("iii %d ", i);
1737 w = colWid; 1738 w = colWid;
1738 if ( ((i) % 7) >= 7-colModulo ) { 1739 if ( ((i) % 7) >= 7-colModulo ) {
1739 ++w; 1740 ++w;
1740 } 1741 }
1741 if ( i == (6-rowModulo)*7) 1742 if ( i == (6-rowModulo)*7)
1742 ++h; 1743 ++h;
1743 if ( combinedSatSun ) { 1744 if ( combinedSatSun ) {
1744 if ( (i)%7 >= daysToShow-1 ) { 1745 if ( (i)%7 >= daysToShow-1 ) {
1745 if ( (i)%7 == daysToShow-1 ) { 1746 if ( (i)%7 == daysToShow-1 ) {
1746 max = h/2; 1747 max = h/2;
1747 mCells[i]->setGeometry ( x+weeklabelwid,y,w,max ); 1748 mCells[i]->setGeometry ( x+weeklabelwid,y,w,max );
1748 x -= w ;y += h/2; 1749 x -= w ;y += h/2;
1749 } else { 1750 } else {
1750 max = h-h/2; 1751 max = h-h/2;
1751 mCells[i]->setGeometry ( x+weeklabelwid,y,w,max ); 1752 mCells[i]->setGeometry ( x+weeklabelwid,y,w,max );
1752 y -= h/2; 1753 y -= h/2;
1753 } 1754 }
1754 } else { 1755 } else {
1755 max = h; 1756 max = h;
1756 mCells[i]->setGeometry ( x+weeklabelwid,y,w,h ); 1757 mCells[i]->setGeometry ( x+weeklabelwid,y,w,h );
1757 } 1758 }
1758 1759
1759 } 1760 }
1760 else { 1761 else {
1761 max = h; 1762 max = h;
1762 mCells[i]->setGeometry ( x+weeklabelwid,y,w,h ); 1763 mCells[i]->setGeometry ( x+weeklabelwid,y,w,h );
1763 } 1764 }
1764 x += w; 1765 x += w;
1765 if ( x + w/2 > wid ) { 1766 if ( x + w/2 > wid ) {
1766 x = 0; 1767 x = 0;
1767 y += h; 1768 y += h;
1768 } 1769 }
1769 //mCells[i]->dateLabel()->setMaximumHeight( max- mCells[i]->lineWidth()*2 ); 1770 //mCells[i]->dateLabel()->setMaximumHeight( max- mCells[i]->lineWidth()*2 );
1770 } 1771 }
1771 y= dayLabelHei; 1772 y= dayLabelHei;
1772 h = cellHei ; 1773 h = cellHei ;
1773 for ( i = 0; i < 6; i++) { 1774 for ( i = 0; i < 6; i++) {
1774 if ( i == (6-rowModulo)) 1775 if ( i == (6-rowModulo))
1775 ++h; 1776 ++h;
1776 mWeekLabels[i]->setGeometry( 0,y,weeklabelwid,h); 1777 mWeekLabels[i]->setGeometry( 0,y,weeklabelwid,h);
1777 y += h; 1778 y += h;
1778 } 1779 }
1779 mWeekLabels[6]->setGeometry( 0,0,weeklabelwid,dayLabelHei); 1780 mWeekLabels[6]->setGeometry( 0,0,weeklabelwid,dayLabelHei);
1780 // qDebug("RRRRRRRRRRRRR %d %d old %d %d", e->size().width(),e->size().height() , e->oldSize().width(),e->oldSize().height()); 1781 // qDebug("RRRRRRRRRRRRR %d %d old %d %d", e->size().width(),e->size().height() , e->oldSize().width(),e->oldSize().height());
1781 //qDebug("parent %d %d ", topLevelWidget()->size().width(), topLevelWidget()->size().height()); 1782 //qDebug("parent %d %d ", topLevelWidget()->size().width(), topLevelWidget()->size().height());
1782 mShortDayLabelsM = mDayLabels[0]->width()-2 < mWidthLongDayLabel ; 1783 mShortDayLabelsM = mDayLabels[0]->width()-2 < mWidthLongDayLabel ;
1783 updateDayLabels(); 1784 updateDayLabels();
1784 //bool forceUpdate = !updatePossible; 1785 //bool forceUpdate = !updatePossible;
1785 updatePossible = true; 1786 updatePossible = true;
1786 //mWeekLabels[mNumWeeks]->setText( i18n("W")); 1787 //mWeekLabels[mNumWeeks]->setText( i18n("W"));
1787} 1788}
1788 1789
1789void KOMonthView::showContextMenu( Incidence *incidence ) 1790void KOMonthView::showContextMenu( Incidence *incidence )
1790{ 1791{
1791 mContextMenu->showIncidencePopup(incidence); 1792 mContextMenu->showIncidencePopup(incidence);
1792 /* 1793 /*
1793 if( incidence && incidence->type() == "Event" ) { 1794 if( incidence && incidence->type() == "Event" ) {
1794 Event *event = static_cast<Event *>(incidence); 1795 Event *event = static_cast<Event *>(incidence);
1795 mContextMenu->showEventPopup(event); 1796 mContextMenu->showEventPopup(event);
1796 } else { 1797 } else {
1797 kdDebug() << "MonthView::showContextMenu(): cast failed." << endl; 1798 kdDebug() << "MonthView::showContextMenu(): cast failed." << endl;
1798 } 1799 }
1799 */ 1800 */
1800} 1801}
1801MonthViewCell * KOMonthView::selectedCell( ) 1802MonthViewCell * KOMonthView::selectedCell( )
1802{ 1803{
1803 return mSelectedCell; 1804 return mSelectedCell;
1804} 1805}
1805void KOMonthView::setSelectedCell( MonthViewCell *cell ) 1806void KOMonthView::setSelectedCell( MonthViewCell *cell )
1806{ 1807{
1807 //qDebug("KOMonthView::setSelectedCell "); 1808 //qDebug("KOMonthView::setSelectedCell ");
1808 if ( mSelectedCell && mSelectedCell != cell ) { 1809 if ( mSelectedCell && mSelectedCell != cell ) {
1809 MonthViewCell * mvc = mSelectedCell; 1810 MonthViewCell * mvc = mSelectedCell;
1810 mSelectedCell = cell; 1811 mSelectedCell = cell;
1811 mvc->deselect(); 1812 mvc->deselect();
1812 } else 1813 } else
1813 mSelectedCell = cell; 1814 mSelectedCell = cell;
1814 // if ( mSelectedCell ) 1815 // if ( mSelectedCell )
1815 // mSelectedCell->select(); 1816 // mSelectedCell->select();
1816 if ( !mSelectedCell ) 1817 if ( !mSelectedCell )
1817 emit incidenceSelected( 0 ); 1818 emit incidenceSelected( 0 );
1818 else 1819 else
1819 emit incidenceSelected( mSelectedCell->selectedIncidence() ); 1820 emit incidenceSelected( mSelectedCell->selectedIncidence() );
1820} 1821}
1821 1822
1822void KOMonthView::processSelectionChange() 1823void KOMonthView::processSelectionChange()
1823{ 1824{
1824 QPtrList<Incidence> incidences = selectedIncidences(); 1825 QPtrList<Incidence> incidences = selectedIncidences();
1825 if (incidences.count() > 0) { 1826 if (incidences.count() > 0) {
1826 emit incidenceSelected( incidences.first() ); 1827 emit incidenceSelected( incidences.first() );
1827 } else { 1828 } else {
1828 emit incidenceSelected( 0 ); 1829 emit incidenceSelected( 0 );
1829 clearSelection(); 1830 clearSelection();
1830 } 1831 }
1831} 1832}
1832 1833
1833void KOMonthView::clearSelection() 1834void KOMonthView::clearSelection()
1834{ 1835{
1835 if ( mSelectedCell ) { 1836 if ( mSelectedCell ) {
1836 mSelectedCell->deselect(); 1837 mSelectedCell->deselect();
1837 mSelectedCell = 0; 1838 mSelectedCell = 0;
1838 } 1839 }
1839} 1840}
1841
1842void KOMonthView::keyReleaseEvent ( QKeyEvent * e)
1843{
1844 if ( !e->isAutoRepeat() ) {
1845 mFlagKeyPressed = false;
1846 }
1847}
1848
1840void KOMonthView::keyPressEvent ( QKeyEvent * e ) 1849void KOMonthView::keyPressEvent ( QKeyEvent * e )
1841{ 1850{
1842 //qDebug("KOMonthView::keyPressEvent "); 1851
1852 qApp->processEvents();
1853 if ( e->isAutoRepeat() && !mFlagKeyPressed ) {
1854 //e->ignore();
1855 e->accept();
1856 return;
1857 }
1858 if (! e->isAutoRepeat() )
1859 mFlagKeyPressed = true;
1843 switch(e->key()) { 1860 switch(e->key()) {
1844 case Key_Up: 1861 case Key_Up:
1845 { 1862 {
1846 if ( mShowWeekView ) { 1863 if ( mShowWeekView ) {
1847 emit selectWeekNum ( currentWeek() - 1 ); 1864 emit selectWeekNum ( currentWeek() - 1 );
1848 } 1865 }
1849 else { 1866 else {
1850 emit prevMonth(); 1867 emit prevMonth();
1851 } 1868 }
1852 } 1869 }
1853 e->accept(); 1870 e->accept();
1854 break; 1871 break;
1855 case Key_Down: 1872 case Key_Down:
1856 { 1873 {
1857 if ( mShowWeekView ) { 1874 if ( mShowWeekView ) {
1858 emit selectWeekNum ( currentWeek() +1); 1875 emit selectWeekNum ( currentWeek() +1);
1859 } 1876 }
1860 else { 1877 else {
1861 emit nextMonth(); 1878 emit nextMonth();
1862 } 1879 }
1863 1880
1864 } 1881 }
1865 e->accept(); 1882 e->accept();
1866 break; 1883 break;
1867 case Key_Return: 1884 case Key_Return:
1868 case Key_Enter: 1885 case Key_Enter:
1869 { 1886 {
1870 selectInternalWeekNum ( currentWeek() ); 1887 selectInternalWeekNum ( currentWeek() );
1871 } 1888 }
1872 e->accept(); 1889 e->accept();
1873 break; 1890 break;
1874 case Key_D: 1891 case Key_D:
1875 if ( mSelectedCell ) { 1892 if ( mSelectedCell ) {
1876 mSelectedCell->showDay(); 1893 mSelectedCell->showDay();
1877 e->accept(); 1894 e->accept();
1878 } else { 1895 } else {
1879 e->ignore(); 1896 e->ignore();
1880 } 1897 }
1881 break; 1898 break;
1882 default: 1899 default:
1883 e->ignore(); 1900 e->ignore();
1884 break; 1901 break;
1885 } 1902 }
1886} 1903}
diff --git a/korganizer/komonthview.h b/korganizer/komonthview.h
index c1ca3d4..88050fe 100644
--- a/korganizer/komonthview.h
+++ b/korganizer/komonthview.h
@@ -58,263 +58,264 @@ class KOWeekButton : public QPushButton
58 void setWeekNum ( int num ) {mNumber = num; setText( QString::number ( num ));} 58 void setWeekNum ( int num ) {mNumber = num; setText( QString::number ( num ));}
59 int getWeekNum() { return mNumber;} 59 int getWeekNum() { return mNumber;}
60 signals: 60 signals:
61 void selectWeekNum ( int ); 61 void selectWeekNum ( int );
62private: 62private:
63 int mNumber; 63 int mNumber;
64 void keyPressEvent ( QKeyEvent * e ) 64 void keyPressEvent ( QKeyEvent * e )
65 { 65 {
66 e->ignore(); 66 e->ignore();
67 } 67 }
68 68
69private slots : 69private slots :
70 void bottonClicked() { if ( mNumber > 0 ) emit selectWeekNum ( mNumber ); } 70 void bottonClicked() { if ( mNumber > 0 ) emit selectWeekNum ( mNumber ); }
71}; 71};
72 72
73class KNoScrollListBox: public QListBox 73class KNoScrollListBox: public QListBox
74{ 74{
75 Q_OBJECT 75 Q_OBJECT
76 public: 76 public:
77 KNoScrollListBox(QWidget *parent=0, const char *name=0); 77 KNoScrollListBox(QWidget *parent=0, const char *name=0);
78 ~KNoScrollListBox(); 78 ~KNoScrollListBox();
79 QString getWhatsThisText(QPoint p) ; 79 QString getWhatsThisText(QPoint p) ;
80 80
81 signals: 81 signals:
82 void shiftDown(); 82 void shiftDown();
83 void shiftUp(); 83 void shiftUp();
84 void rightClick(); 84 void rightClick();
85 85
86 protected slots: 86 protected slots:
87 void oneDown(); 87 void oneDown();
88 void keyPressEvent(QKeyEvent *); 88 void keyPressEvent(QKeyEvent *);
89 void keyReleaseEvent(QKeyEvent *); 89 void keyReleaseEvent(QKeyEvent *);
90 void mousePressEvent(QMouseEvent *); 90 void mousePressEvent(QMouseEvent *);
91 91
92 private: 92 private:
93 KNOWhatsThis * mWT; 93 KNOWhatsThis * mWT;
94}; 94};
95 95
96 96
97class MonthViewItem: public QListBoxItem 97class MonthViewItem: public QListBoxItem
98{ 98{
99 public: 99 public:
100 MonthViewItem( Incidence *, QDate qd, const QString & title ); 100 MonthViewItem( Incidence *, QDate qd, const QString & title );
101 void recycle( Incidence *incidence, QDate qd, const QString & s); 101 void recycle( Incidence *incidence, QDate qd, const QString & s);
102 void setRecur(bool on) { mRecur = on; } 102 void setRecur(bool on) { mRecur = on; }
103 void setAlarm(bool on) { mAlarm = on; } 103 void setAlarm(bool on) { mAlarm = on; }
104 void setReply(bool on) { mReply = on; } 104 void setReply(bool on) { mReply = on; }
105 void setMoreInfo(bool on) { mInfo = on; } 105 void setMoreInfo(bool on) { mInfo = on; }
106 void setMultiDay(int type) { mMultiday = type; } 106 void setMultiDay(int type) { mMultiday = type; }
107 void setBlockRepaint(bool on) { mblockRepaint = on; } 107 void setBlockRepaint(bool on) { mblockRepaint = on; }
108 108
109 109
110 void setPalette(const QPalette &p) { mPalette = p; } 110 void setPalette(const QPalette &p) { mPalette = p; }
111 QPalette palette() const { return mPalette; } 111 QPalette palette() const { return mPalette; }
112 112
113 Incidence *incidence() const { return mIncidence; } 113 Incidence *incidence() const { return mIncidence; }
114 QDate incidenceDate() { return mDate; } 114 QDate incidenceDate() { return mDate; }
115 115
116 protected: 116 protected:
117 virtual void paint(QPainter *); 117 virtual void paint(QPainter *);
118 virtual int height(const QListBox *) const; 118 virtual int height(const QListBox *) const;
119 virtual int width(const QListBox *) const; 119 virtual int width(const QListBox *) const;
120 120
121 private: 121 private:
122 bool mblockRepaint; 122 bool mblockRepaint;
123 int mMultiday; 123 int mMultiday;
124 bool mRecur; 124 bool mRecur;
125 bool mAlarm; 125 bool mAlarm;
126 bool mReply; 126 bool mReply;
127 bool mInfo; 127 bool mInfo;
128 128
129 QPalette mPalette; 129 QPalette mPalette;
130 QDate mDate; 130 QDate mDate;
131 131
132 Incidence *mIncidence; 132 Incidence *mIncidence;
133}; 133};
134 134
135 135
136class KOMonthView; 136class KOMonthView;
137 137
138class MonthViewCell : public KNoScrollListBox 138class MonthViewCell : public KNoScrollListBox
139{ 139{
140 Q_OBJECT 140 Q_OBJECT
141 public: 141 public:
142 MonthViewCell(KOMonthView *,QWidget* ); 142 MonthViewCell(KOMonthView *,QWidget* );
143 ~MonthViewCell() {mAvailItemList.setAutoDelete( true );} 143 ~MonthViewCell() {mAvailItemList.setAutoDelete( true );}
144 144
145 void setDate( const QDate & ); 145 void setDate( const QDate & );
146 QDate date() const; 146 QDate date() const;
147 147
148 void setPrimary( bool ); 148 void setPrimary( bool );
149 bool isPrimary() const; 149 bool isPrimary() const;
150 150
151 void setHoliday( bool ); 151 void setHoliday( bool );
152 void setHoliday( const QString & ); 152 void setHoliday( const QString & );
153 153
154 void updateCell(); 154 void updateCell();
155 void startUpdateCell(); 155 void startUpdateCell();
156 void finishUpdateCell(); 156 void finishUpdateCell();
157 void repaintfinishUpdateCell(); 157 void repaintfinishUpdateCell();
158 void insertEvent(Event *); 158 void insertEvent(Event *);
159 void insertTodo(Todo *); 159 void insertTodo(Todo *);
160 160
161 void updateConfig( bool bigFont = false ); 161 void updateConfig( bool bigFont = false );
162 162
163 void enableScrollBars( bool ); 163 void enableScrollBars( bool );
164 164
165 Incidence *selectedIncidence(); 165 Incidence *selectedIncidence();
166 QDate selectedIncidenceDate(); 166 QDate selectedIncidenceDate();
167 QPushButton * dateLabel() { return mLabel; } 167 QPushButton * dateLabel() { return mLabel; }
168 168
169 void deselect(); 169 void deselect();
170 void select(); 170 void select();
171#ifdef DESKTOP_VERSION 171#ifdef DESKTOP_VERSION
172 static QToolTipGroup *toolTipGroup(); 172 static QToolTipGroup *toolTipGroup();
173#endif 173#endif
174 signals: 174 signals:
175 void defaultAction( Incidence * ); 175 void defaultAction( Incidence * );
176 void newEventSignal( QDateTime ); 176 void newEventSignal( QDateTime );
177 void showDaySignal( QDate ); 177 void showDaySignal( QDate );
178 178
179 protected: 179 protected:
180 QStringList mToolTip; 180 QStringList mToolTip;
181 void resizeEvent( QResizeEvent * ); 181 void resizeEvent( QResizeEvent * );
182 182
183 183
184public slots: 184public slots:
185 void showDay(); 185 void showDay();
186 186
187 protected slots: 187 protected slots:
188 void defaultAction( QListBoxItem * ); 188 void defaultAction( QListBoxItem * );
189 void contextMenu( QListBoxItem * ); 189 void contextMenu( QListBoxItem * );
190 void selection( QListBoxItem * ); 190 void selection( QListBoxItem * );
191 void cellClicked( QListBoxItem * ); 191 void cellClicked( QListBoxItem * );
192 void newEvent(); 192 void newEvent();
193 193
194 private: 194 private:
195 MonthViewItem* mCurrentAvailItem; 195 MonthViewItem* mCurrentAvailItem;
196 QPtrList <MonthViewItem> mAvailItemList; 196 QPtrList <MonthViewItem> mAvailItemList;
197 KOMonthView *mMonthView; 197 KOMonthView *mMonthView;
198 int currentPalette; 198 int currentPalette;
199 199
200 QDate mDate; 200 QDate mDate;
201 bool mPrimary; 201 bool mPrimary;
202 bool mHoliday; 202 bool mHoliday;
203 QString mHolidayString; 203 QString mHolidayString;
204 204
205 //QLabel *mLabel; 205 //QLabel *mLabel;
206 QPushButton *mLabel; 206 QPushButton *mLabel;
207 //QListBox *mItemList; 207 //QListBox *mItemList;
208#ifdef DESKTOP_VERSION 208#ifdef DESKTOP_VERSION
209 static QToolTipGroup *mToolTipGroup; 209 static QToolTipGroup *mToolTipGroup;
210#endif 210#endif
211 QSize mLabelSize; 211 QSize mLabelSize;
212 QSize mLabelBigSize; 212 QSize mLabelBigSize;
213 QPalette mHolidayPalette; 213 QPalette mHolidayPalette;
214 QPalette mStandardPalette; 214 QPalette mStandardPalette;
215 QPalette mPrimaryPalette; 215 QPalette mPrimaryPalette;
216 QPalette mNonPrimaryPalette; 216 QPalette mNonPrimaryPalette;
217 void setMyPalette(); 217 void setMyPalette();
218 QPalette getPalette (); 218 QPalette getPalette ();
219 219
220}; 220};
221 221
222 222
223class KOMonthView: public KOEventView 223class KOMonthView: public KOEventView
224{ 224{
225 Q_OBJECT 225 Q_OBJECT
226 public: 226 public:
227 KOMonthView(Calendar *cal, QWidget *parent = 0, const char *name = 0 ); 227 KOMonthView(Calendar *cal, QWidget *parent = 0, const char *name = 0 );
228 ~KOMonthView(); 228 ~KOMonthView();
229 229
230 /** Returns maximum number of days supported by the komonthview */ 230 /** Returns maximum number of days supported by the komonthview */
231 virtual int maxDatesHint(); 231 virtual int maxDatesHint();
232 232
233 /** Returns number of currently shown dates. */ 233 /** Returns number of currently shown dates. */
234 virtual int currentDateCount(); 234 virtual int currentDateCount();
235 235
236 /** returns the currently selected events */ 236 /** returns the currently selected events */
237 virtual QPtrList<Incidence> selectedIncidences(); 237 virtual QPtrList<Incidence> selectedIncidences();
238 238
239 /** returns dates of the currently selected events */ 239 /** returns dates of the currently selected events */
240 virtual DateList selectedDates(); 240 virtual DateList selectedDates();
241 241
242 virtual void printPreview(CalPrinter *calPrinter, 242 virtual void printPreview(CalPrinter *calPrinter,
243 const QDate &, const QDate &); 243 const QDate &, const QDate &);
244 bool isMonthView() { return !mShowWeekView; } 244 bool isMonthView() { return !mShowWeekView; }
245 bool isUpdatePossible() { return updatePossible; } 245 bool isUpdatePossible() { return updatePossible; }
246 246
247 MonthViewCell * selectedCell(); 247 MonthViewCell * selectedCell();
248 bool skipResize; 248 bool skipResize;
249 NavigatorBar* navigatorBar() { return mNavigatorBar ;} 249 NavigatorBar* navigatorBar() { return mNavigatorBar ;}
250 public slots: 250 public slots:
251 virtual void updateView(); 251 virtual void updateView();
252 virtual void updateConfig(); 252 virtual void updateConfig();
253 virtual void showDates(const QDate &start, const QDate &end); 253 virtual void showDates(const QDate &start, const QDate &end);
254 virtual void showEvents(QPtrList<Event> eventList); 254 virtual void showEvents(QPtrList<Event> eventList);
255 255
256 void changeEventDisplay(Event *, int); 256 void changeEventDisplay(Event *, int);
257 257
258 void clearSelection(); 258 void clearSelection();
259 259
260 void showContextMenu( Incidence * ); 260 void showContextMenu( Incidence * );
261 261
262 void setSelectedCell( MonthViewCell * ); 262 void setSelectedCell( MonthViewCell * );
263 void switchView(); 263 void switchView();
264 void setKeyBoardFocus(); 264 void setKeyBoardFocus();
265 void setKeyBFocus(); 265 void setKeyBFocus();
266 266
267 protected slots: 267 protected slots:
268 void slotComputeLayout(); 268 void slotComputeLayout();
269 void selectInternalWeekNum ( int ); 269 void selectInternalWeekNum ( int );
270 void processSelectionChange(); 270 void processSelectionChange();
271 signals: 271 signals:
272 void nextMonth(); 272 void nextMonth();
273 void prevMonth(); 273 void prevMonth();
274 void selectWeekNum ( int ); 274 void selectWeekNum ( int );
275 void selectMonth (); 275 void selectMonth ();
276 void showDaySignal( QDate ); 276 void showDaySignal( QDate );
277 protected: 277 protected:
278 void resizeEvent(QResizeEvent *); 278 void resizeEvent(QResizeEvent *);
279 void viewChanged(); 279 void viewChanged();
280 void updateDayLabels(); 280 void updateDayLabels();
281 281
282 private: 282 private:
283 QTimer* mComputeLayoutTimer; 283 QTimer* mComputeLayoutTimer;
284 NavigatorBar* mNavigatorBar; 284 NavigatorBar* mNavigatorBar;
285 int currentWeek(); 285 int currentWeek();
286 bool clPending; 286 bool clPending;
287 QWidgetStack * mWidStack; 287 QWidgetStack * mWidStack;
288 QWidget* mMonthView; 288 QWidget* mMonthView;
289 QWidget* mWeekView; 289 QWidget* mWeekView;
290 bool mShowWeekView; 290 bool mShowWeekView;
291 bool updatePossible; 291 bool updatePossible;
292 int mDaysPerWeek; 292 int mDaysPerWeek;
293 int mNumWeeks; 293 int mNumWeeks;
294 int mNumCells; 294 int mNumCells;
295 //bool mWeekStartsMonday; 295 //bool mWeekStartsMonday;
296 bool mShowSatSunComp; 296 bool mShowSatSunComp;
297 void computeLayout(); 297 void computeLayout();
298 void computeLayoutWeek(); 298 void computeLayoutWeek();
299 299
300 QPtrVector<MonthViewCell> mCells; 300 QPtrVector<MonthViewCell> mCells;
301 QPtrVector<QLabel> mDayLabels; 301 QPtrVector<QLabel> mDayLabels;
302 QPtrVector<KOWeekButton> mWeekLabels; 302 QPtrVector<KOWeekButton> mWeekLabels;
303 QPtrVector<MonthViewCell> mCellsW; 303 QPtrVector<MonthViewCell> mCellsW;
304 QPtrVector<QLabel> mDayLabelsW; 304 QPtrVector<QLabel> mDayLabelsW;
305 QPtrVector<KOWeekButton> mWeekLabelsW; 305 QPtrVector<KOWeekButton> mWeekLabelsW;
306 306
307 bool mShortDayLabelsM; 307 bool mShortDayLabelsM;
308 bool mShortDayLabelsW; 308 bool mShortDayLabelsW;
309 int mWidthLongDayLabel; 309 int mWidthLongDayLabel;
310 310
311 QDate mStartDate; 311 QDate mStartDate;
312 312
313 MonthViewCell *mSelectedCell; 313 MonthViewCell *mSelectedCell;
314 314 bool mFlagKeyPressed;
315 KOEventPopupMenu *mContextMenu; 315 KOEventPopupMenu *mContextMenu;
316 void keyPressEvent ( QKeyEvent * ) ; 316 void keyPressEvent ( QKeyEvent * ) ;
317 void keyReleaseEvent ( QKeyEvent * ) ;
317 318
318}; 319};
319 320
320#endif 321#endif
diff --git a/korganizer/mainwindow.cpp b/korganizer/mainwindow.cpp
index ae03a09..09a0880 100644
--- a/korganizer/mainwindow.cpp
+++ b/korganizer/mainwindow.cpp
@@ -1,460 +1,471 @@
1#include <stdlib.h> 1#include <stdlib.h>
2 2
3#include <qaction.h> 3#include <qaction.h>
4#include <qpopupmenu.h> 4#include <qpopupmenu.h>
5#include <qpainter.h> 5#include <qpainter.h>
6#include <qwhatsthis.h> 6#include <qwhatsthis.h>
7#include <qpushbutton.h> 7#include <qpushbutton.h>
8#include <qmessagebox.h> 8#include <qmessagebox.h>
9#include <qlineedit.h> 9#include <qlineedit.h>
10#include <qtextcodec.h> 10#include <qtextcodec.h>
11#include <qfile.h> 11#include <qfile.h>
12#include <qdir.h> 12#include <qdir.h>
13#include <qapp.h> 13#include <qapp.h>
14#include <qfileinfo.h> 14#include <qfileinfo.h>
15#include <qlabel.h> 15#include <qlabel.h>
16#include <qspinbox.h> 16#include <qspinbox.h>
17#include <qcheckbox.h> 17#include <qcheckbox.h>
18#include <qmap.h> 18#include <qmap.h>
19#include <qwmatrix.h> 19#include <qwmatrix.h>
20#include <qtextbrowser.h> 20#include <qtextbrowser.h>
21#include <qtextstream.h> 21#include <qtextstream.h>
22#ifndef DESKTOP_VERSION 22#ifndef DESKTOP_VERSION
23#include <qpe/global.h> 23#include <qpe/global.h>
24#include <qpe/qpemenubar.h> 24#include <qpe/qpemenubar.h>
25#include <qpe/qpetoolbar.h> 25#include <qpe/qpetoolbar.h>
26#include <qpe/resource.h> 26#include <qpe/resource.h>
27#include <qpe/qpeapplication.h> 27#include <qpe/qpeapplication.h>
28#include <qtopia/alarmserver.h> 28#include <qtopia/alarmserver.h>
29#include <qtopia/qcopenvelope_qws.h> 29#include <qtopia/qcopenvelope_qws.h>
30#include <unistd.h> // for sleep 30#include <unistd.h> // for sleep
31#else 31#else
32#include <qmenubar.h> 32#include <qmenubar.h>
33#include <qtoolbar.h> 33#include <qtoolbar.h>
34#include <qapplication.h> 34#include <qapplication.h>
35//#include <resource.h> 35//#include <resource.h>
36 36
37#endif 37#endif
38#include <libkcal/calendarlocal.h> 38#include <libkcal/calendarlocal.h>
39#include <libkcal/todo.h> 39#include <libkcal/todo.h>
40#include <libkcal/phoneformat.h> 40#include <libkcal/phoneformat.h>
41#include <libkdepim/ksyncprofile.h> 41#include <libkdepim/ksyncprofile.h>
42#include <libkdepim/phoneaccess.h> 42#include <libkdepim/phoneaccess.h>
43#include <libkcal/kincidenceformatter.h> 43#include <libkcal/kincidenceformatter.h>
44#include <libkdepim/kpimglobalprefs.h> 44#include <libkdepim/kpimglobalprefs.h>
45 45
46#include "calendarview.h" 46#include "calendarview.h"
47#include "koviewmanager.h" 47#include "koviewmanager.h"
48#include "datenavigator.h" 48#include "datenavigator.h"
49#include "koagendaview.h" 49#include "koagendaview.h"
50#include "koagenda.h" 50#include "koagenda.h"
51#include "kodialogmanager.h" 51#include "kodialogmanager.h"
52#include "kdialogbase.h" 52#include "kdialogbase.h"
53#include "kapplication.h" 53#include "kapplication.h"
54#include "kofilterview.h" 54#include "kofilterview.h"
55#include "kstandarddirs.h" 55#include "kstandarddirs.h"
56#include "koprefs.h" 56#include "koprefs.h"
57#include "kfiledialog.h" 57#include "kfiledialog.h"
58#include "koglobals.h" 58#include "koglobals.h"
59#include "kglobal.h" 59#include "kglobal.h"
60#include "ktoolbar.h" 60#include "ktoolbar.h"
61#include "klocale.h" 61#include "klocale.h"
62#include "kconfig.h" 62#include "kconfig.h"
63#include "simplealarmclient.h" 63#include "simplealarmclient.h"
64#include "externalapphandler.h" 64#include "externalapphandler.h"
65 65
66using namespace KCal; 66using namespace KCal;
67#ifndef _WIN32_ 67#ifndef _WIN32_
68#include <unistd.h> 68#include <unistd.h>
69#else 69#else
70#ifdef _OL_IMPORT_ 70#ifdef _OL_IMPORT_
71#include "koimportoldialog.h" 71#include "koimportoldialog.h"
72#endif 72#endif
73#endif 73#endif
74#include "mainwindow.h" 74#include "mainwindow.h"
75 75
76 76
77class KOex2phonePrefs : public QDialog 77class KOex2phonePrefs : public QDialog
78{ 78{
79 public: 79 public:
80 KOex2phonePrefs( QWidget *parent=0, const char *name=0 ) : 80 KOex2phonePrefs( QWidget *parent=0, const char *name=0 ) :
81 QDialog( parent, name, true ) 81 QDialog( parent, name, true )
82 { 82 {
83 setCaption( i18n("Export to phone options") ); 83 setCaption( i18n("Export to phone options") );
84 QVBoxLayout* lay = new QVBoxLayout( this ); 84 QVBoxLayout* lay = new QVBoxLayout( this );
85 lay->setSpacing( 3 ); 85 lay->setSpacing( 3 );
86 lay->setMargin( 3 ); 86 lay->setMargin( 3 );
87 QLabel *lab; 87 QLabel *lab;
88 lay->addWidget(lab = new QLabel( i18n("Please read Help-Sync Howto\nto know what settings to use."), this ) ); 88 lay->addWidget(lab = new QLabel( i18n("Please read Help-Sync Howto\nto know what settings to use."), this ) );
89 lab->setAlignment (AlignHCenter ); 89 lab->setAlignment (AlignHCenter );
90 QHBox* temphb; 90 QHBox* temphb;
91 temphb = new QHBox( this ); 91 temphb = new QHBox( this );
92 new QLabel( i18n("I/O device: "), temphb ); 92 new QLabel( i18n("I/O device: "), temphb );
93 mPhoneDevice = new QLineEdit( temphb); 93 mPhoneDevice = new QLineEdit( temphb);
94 lay->addWidget( temphb ); 94 lay->addWidget( temphb );
95 temphb = new QHBox( this ); 95 temphb = new QHBox( this );
96 new QLabel( i18n("Connection: "), temphb ); 96 new QLabel( i18n("Connection: "), temphb );
97 mPhoneConnection = new QLineEdit( temphb); 97 mPhoneConnection = new QLineEdit( temphb);
98 lay->addWidget( temphb ); 98 lay->addWidget( temphb );
99 temphb = new QHBox( this ); 99 temphb = new QHBox( this );
100 new QLabel( i18n("Model(opt.): "), temphb ); 100 new QLabel( i18n("Model(opt.): "), temphb );
101 mPhoneModel = new QLineEdit( temphb); 101 mPhoneModel = new QLineEdit( temphb);
102 lay->addWidget( temphb ); 102 lay->addWidget( temphb );
103 mWriteBackFuture= new QCheckBox( i18n("Write back events in future only"), this ); 103 mWriteBackFuture= new QCheckBox( i18n("Write back events in future only"), this );
104 mWriteBackFuture->setChecked( true ); 104 mWriteBackFuture->setChecked( true );
105 lay->addWidget( mWriteBackFuture ); 105 lay->addWidget( mWriteBackFuture );
106 temphb = new QHBox( this ); 106 temphb = new QHBox( this );
107 new QLabel( i18n("Max. weeks in future: ") , temphb ); 107 new QLabel( i18n("Max. weeks in future: ") , temphb );
108 mWriteBackFutureWeeks= new QSpinBox(1,104, 1, temphb); 108 mWriteBackFutureWeeks= new QSpinBox(1,104, 1, temphb);
109 mWriteBackFutureWeeks->setValue( 8 ); 109 mWriteBackFutureWeeks->setValue( 8 );
110 lay->addWidget( temphb ); 110 lay->addWidget( temphb );
111 lay->addWidget(lab = new QLabel( i18n("NOTE: This will remove all old\ntodo/calendar data on phone!"), this ) ); 111 lay->addWidget(lab = new QLabel( i18n("NOTE: This will remove all old\ntodo/calendar data on phone!"), this ) );
112 lab->setAlignment (AlignHCenter ); 112 lab->setAlignment (AlignHCenter );
113 QPushButton * ok = new QPushButton( i18n("Export to mobile phone!"), this ); 113 QPushButton * ok = new QPushButton( i18n("Export to mobile phone!"), this );
114 lay->addWidget( ok ); 114 lay->addWidget( ok );
115 QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); 115 QPushButton * cancel = new QPushButton( i18n("Cancel"), this );
116 lay->addWidget( cancel ); 116 lay->addWidget( cancel );
117 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); 117 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) );
118 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); 118 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) );
119 resize( 220, 240 ); 119 resize( 220, 240 );
120 qApp->processEvents(); 120 qApp->processEvents();
121 int dw = QApplication::desktop()->width(); 121 int dw = QApplication::desktop()->width();
122 int dh = QApplication::desktop()->height(); 122 int dh = QApplication::desktop()->height();
123 move( (dw-width())/2, (dh - height() )/2 ); 123 move( (dw-width())/2, (dh - height() )/2 );
124 } 124 }
125 125
126public: 126public:
127 QLineEdit* mPhoneConnection, *mPhoneDevice, *mPhoneModel; 127 QLineEdit* mPhoneConnection, *mPhoneDevice, *mPhoneModel;
128 QCheckBox* mWriteBackFuture; 128 QCheckBox* mWriteBackFuture;
129 QSpinBox* mWriteBackFutureWeeks; 129 QSpinBox* mWriteBackFutureWeeks;
130}; 130};
131 131
132int globalFlagBlockStartup; 132int globalFlagBlockStartup;
133MainWindow::MainWindow( QWidget *parent, const char *name, QString msg) : 133MainWindow::MainWindow( QWidget *parent, const char *name, QString msg) :
134 QMainWindow( parent, name ) 134 QMainWindow( parent, name )
135{ 135{
136 136
137 mClosed = false; 137 mClosed = false;
138 //QString confFile = KStandardDirs::appDir() + "config/korganizerrc"; 138 //QString confFile = KStandardDirs::appDir() + "config/korganizerrc";
139 QString confFile = locateLocal("config","korganizerrc"); 139 QString confFile = locateLocal("config","korganizerrc");
140 QFileInfo finf ( confFile ); 140 QFileInfo finf ( confFile );
141 bool showWarning = !finf.exists(); 141 bool showWarning = !finf.exists();
142 setIcon(SmallIcon( "ko24" ) ); 142 setIcon(SmallIcon( "ko24" ) );
143 mBlockAtStartup = true; 143 mBlockAtStartup = true;
144 mFlagKeyPressed = false; 144 mFlagKeyPressed = false;
145 setCaption("KO/Pi"); 145 setCaption("KO/Pi");
146 KOPrefs *p = KOPrefs::instance(); 146 KOPrefs *p = KOPrefs::instance();
147 KPimGlobalPrefs::instance()->setGlobalConfig(); 147 KPimGlobalPrefs::instance()->setGlobalConfig();
148 if ( p->mHourSize > 22 ) 148 if ( p->mHourSize > 22 )
149 p->mHourSize = 22; 149 p->mHourSize = 22;
150 QMainWindow::ToolBarDock tbd; 150 QMainWindow::ToolBarDock tbd;
151 if ( p->mToolBarHor ) { 151 if ( p->mToolBarHor ) {
152 if ( p->mToolBarUp ) 152 if ( p->mToolBarUp )
153 tbd = Bottom; 153 tbd = Bottom;
154 else 154 else
155 tbd = Top; 155 tbd = Top;
156 } 156 }
157 else { 157 else {
158 if ( p->mToolBarUp ) 158 if ( p->mToolBarUp )
159 tbd = Right; 159 tbd = Right;
160 else 160 else
161 tbd = Left; 161 tbd = Left;
162 } 162 }
163 if ( KOPrefs::instance()->mUseAppColors ) 163 if ( KOPrefs::instance()->mUseAppColors )
164 QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true ); 164 QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true );
165 globalFlagBlockStartup = 1; 165 globalFlagBlockStartup = 1;
166 iconToolBar = new QPEToolBar( this ); 166 iconToolBar = new QPEToolBar( this );
167 addToolBar (iconToolBar , tbd ); 167 addToolBar (iconToolBar , tbd );
168 168
169 if ( KOPrefs::instance()->mShowIconFilter ) { 169#ifdef DESKTOP_VERSION
170 if ( KOPrefs::instance()->mShowIconFilter )
171#else
172 if ( KOPrefs::instance()->mShowIconFilter || !p->mShowIconOnetoolbar )
173#endif
174
175{
170 if ( p->mToolBarHorF ) { 176 if ( p->mToolBarHorF ) {
171 if ( p->mToolBarUpF ) 177 if ( p->mToolBarUpF )
172 tbd = Bottom; 178 tbd = Bottom;
173 else 179 else
174 tbd = Top; 180 tbd = Top;
175 } 181 }
176 else { 182 else {
177 if ( p->mToolBarUpF ) 183 if ( p->mToolBarUpF )
178 tbd = Right; 184 tbd = Right;
179 else 185 else
180 tbd = Left; 186 tbd = Left;
181 } 187 }
182 filterToolBar = new QPEToolBar ( this ); 188 filterToolBar = new QPEToolBar ( this );
183 filterMenubar = new QPEMenuBar( filterToolBar ); 189 filterMenubar = new QPEMenuBar( filterToolBar );
184 QFontMetrics fm ( filterMenubar->font() ); 190 QFontMetrics fm ( filterMenubar->font() );
185 191
186 filterPopupMenu = new QPopupMenu( this ); 192 filterPopupMenu = new QPopupMenu( this );
187 filterMenubar->insertItem( i18n("No Filter"), filterPopupMenu,0 ); 193 filterMenubar->insertItem( i18n("No Filter"), filterPopupMenu,0 );
188 QString addTest = "Ax"; 194 QString addTest = "Ax";
189#ifdef DESKTOP_VERSION 195#ifdef DESKTOP_VERSION
190 addTest = "AAAx"; 196 addTest = "AAAx";
191#endif 197#endif
192 filterMenubar->setFixedWidth( fm.width( i18n("No Filter")+addTest ) ); 198 filterMenubar->setFixedWidth( fm.width( i18n("No Filter")+addTest ) );
193 addToolBar (filterToolBar , tbd ); 199 addToolBar (filterToolBar , tbd );
194 connect ( filterPopupMenu , SIGNAL( activated ( int ) ), this, SLOT (selectFilterPopup( int ) ) ); 200 connect ( filterPopupMenu , SIGNAL( activated ( int ) ), this, SLOT (selectFilterPopup( int ) ) );
195 connect ( filterPopupMenu , SIGNAL( aboutToShow() ), this, SLOT (fillFilterMenuPopup() ) ); 201 connect ( filterPopupMenu , SIGNAL( aboutToShow() ), this, SLOT (fillFilterMenuPopup() ) );
202 if ( !KOPrefs::instance()->mShowIconFilter && !p->mShowIconOnetoolbar )
203 filterToolBar->hide();
196 } else { 204 } else {
197 filterToolBar = 0; 205 filterToolBar = 0;
198 filterMenubar = 0; 206 filterMenubar = 0;
199 filterPopupMenu = 0; 207 filterPopupMenu = 0;
200 } 208 }
201 if ( p->mShowIconOnetoolbar ) { 209 if ( p->mShowIconOnetoolbar ) {
202 viewToolBar = iconToolBar ; 210 viewToolBar = iconToolBar ;
203 navigatorToolBar = iconToolBar ; 211 navigatorToolBar = iconToolBar ;
204 } else { 212 } else {
213#ifndef DESKTOP_VERSION
214 setToolBarsMovable( false );
215#endif
205 if ( p->mToolBarHorV ) { 216 if ( p->mToolBarHorV ) {
206 if ( p->mToolBarUpV ) 217 if ( p->mToolBarUpV )
207 tbd = Bottom; 218 tbd = Bottom;
208 else 219 else
209 tbd = Top; 220 tbd = Top;
210 } 221 }
211 else { 222 else {
212 if ( p->mToolBarUpV ) 223 if ( p->mToolBarUpV )
213 tbd = Right; 224 tbd = Right;
214 else 225 else
215 tbd = Left; 226 tbd = Left;
216 } 227 }
217 viewToolBar = new QPEToolBar( this ); 228 viewToolBar = new QPEToolBar( this );
218 addToolBar (viewToolBar , tbd ); 229 addToolBar (viewToolBar , tbd );
219 if ( p->mToolBarHorN ) { 230 if ( p->mToolBarHorN ) {
220 if ( p->mToolBarUpN ) 231 if ( p->mToolBarUpN )
221 tbd = Bottom; 232 tbd = Bottom;
222 else 233 else
223 tbd = Top; 234 tbd = Top;
224 } 235 }
225 else { 236 else {
226 if ( p->mToolBarUpN ) 237 if ( p->mToolBarUpN )
227 tbd = Right; 238 tbd = Right;
228 else 239 else
229 tbd = Left; 240 tbd = Left;
230 } 241 }
231 navigatorToolBar = new QPEToolBar( this ); 242 navigatorToolBar = new QPEToolBar( this );
232 addToolBar (navigatorToolBar , tbd ); 243 addToolBar (navigatorToolBar , tbd );
233 } 244 }
234 245
235 246
236 247
237 mCalendarModifiedFlag = false; 248 mCalendarModifiedFlag = false;
238 QLabel* splash = new QLabel(i18n("KO/Pi is starting ... "), this ); 249 QLabel* splash = new QLabel(i18n("KO/Pi is starting ... "), this );
239 splash->setAlignment ( AlignCenter ); 250 splash->setAlignment ( AlignCenter );
240 setCentralWidget( splash ); 251 setCentralWidget( splash );
241#ifndef DESKTOP_VERSION 252#ifndef DESKTOP_VERSION
242 showMaximized(); 253 showMaximized();
243#endif 254#endif
244 255
245 //qDebug("Mainwidget x %d y %d w %d h %d", x(), y(), width(), height ()); 256 //qDebug("Mainwidget x %d y %d w %d h %d", x(), y(), width(), height ());
246 setDefaultPreferences(); 257 setDefaultPreferences();
247 mCalendar = new CalendarLocal(); 258 mCalendar = new CalendarLocal();
248 mView = new CalendarView( mCalendar, this,"mCalendar " ); 259 mView = new CalendarView( mCalendar, this,"mCalendar " );
249 mView->hide(); 260 mView->hide();
250 //mView->resize(splash->size() ); 261 //mView->resize(splash->size() );
251 initActions(); 262 initActions();
252 mSyncManager = new KSyncManager((QWidget*)this, (KSyncInterface*)mView, KSyncManager::KOPI, KOPrefs::instance(), syncMenu); 263 mSyncManager = new KSyncManager((QWidget*)this, (KSyncInterface*)mView, KSyncManager::KOPI, KOPrefs::instance(), syncMenu);
253 mSyncManager->setBlockSave(false); 264 mSyncManager->setBlockSave(false);
254 mView->setSyncManager(mSyncManager); 265 mView->setSyncManager(mSyncManager);
255#ifndef DESKTOP_VERSION 266#ifndef DESKTOP_VERSION
256 iconToolBar->show(); 267 iconToolBar->show();
257 qApp->processEvents(); 268 qApp->processEvents();
258#endif 269#endif
259 //qDebug("Splashwidget x %d y %d w %d h %d", splash-> x(), splash->y(), splash->width(),splash-> height ()); 270 //qDebug("Splashwidget x %d y %d w %d h %d", splash-> x(), splash->y(), splash->width(),splash-> height ());
260 int vh = height() ; 271 int vh = height() ;
261 int vw = width(); 272 int vw = width();
262 //qDebug("Toolbar hei %d ",iconToolBar->height() ); 273 //qDebug("Toolbar hei %d ",iconToolBar->height() );
263 if ( iconToolBar->orientation () == Qt:: Horizontal ) { 274 if ( iconToolBar->orientation () == Qt:: Horizontal ) {
264 vh -= iconToolBar->height(); 275 vh -= iconToolBar->height();
265 } else { 276 } else {
266 vw -= iconToolBar->height(); 277 vw -= iconToolBar->height();
267 } 278 }
268 //mView->setMaximumSize( splash->size() ); 279 //mView->setMaximumSize( splash->size() );
269 //mView->resize( splash->size() ); 280 //mView->resize( splash->size() );
270 //qDebug("MainView x %d y %d w %d h %d", mView->x(),mView-> y(), mView->width(), mView->height ()); 281 //qDebug("MainView x %d y %d w %d h %d", mView->x(),mView-> y(), mView->width(), mView->height ());
271 mView->readSettings(); 282 mView->readSettings();
272 bool newFile = false; 283 bool newFile = false;
273 if( !QFile::exists( defaultFileName() ) ) { 284 if( !QFile::exists( defaultFileName() ) ) {
274 QFileInfo finfo ( defaultFileName() ); 285 QFileInfo finfo ( defaultFileName() );
275 QString oldFile = QDir::convertSeparators( QDir::homeDirPath()+"/Applications/korganizer/mycalendar.ics"); 286 QString oldFile = QDir::convertSeparators( QDir::homeDirPath()+"/Applications/korganizer/mycalendar.ics");
276 qDebug("oldfile %s ", oldFile.latin1()); 287 qDebug("oldfile %s ", oldFile.latin1());
277 QString message = "You are starting KO/Pi for the\nfirst time after updating to a\nversion >= 1.9.1. The location of the\ndefault calendar file has changed.\nA mycalendar.ics file was detected\nat the old location.\nThis file will be loaded now\nand stored at the new location!\n(Config file location has changed, too!)\nPlease read menu Help-What's New!\n"; 288 QString message = "You are starting KO/Pi for the\nfirst time after updating to a\nversion >= 1.9.1. The location of the\ndefault calendar file has changed.\nA mycalendar.ics file was detected\nat the old location.\nThis file will be loaded now\nand stored at the new location!\n(Config file location has changed, too!)\nPlease read menu Help-What's New!\n";
278 finfo.setFile( oldFile ); 289 finfo.setFile( oldFile );
279 if (finfo.exists() ) { 290 if (finfo.exists() ) {
280 KMessageBox::information( this, message); 291 KMessageBox::information( this, message);
281 mView->openCalendar( oldFile ); 292 mView->openCalendar( oldFile );
282 qApp->processEvents(); 293 qApp->processEvents();
283 } else { 294 } else {
284 oldFile = QDir::convertSeparators( QDir::homeDirPath()+"/korganizer/mycalendar.ics"); 295 oldFile = QDir::convertSeparators( QDir::homeDirPath()+"/korganizer/mycalendar.ics");
285 finfo.setFile( oldFile ); 296 finfo.setFile( oldFile );
286 if (finfo.exists() ) { 297 if (finfo.exists() ) {
287 KMessageBox::information( this, message); 298 KMessageBox::information( this, message);
288 mView->openCalendar( oldFile ); 299 mView->openCalendar( oldFile );
289 qApp->processEvents(); 300 qApp->processEvents();
290 } 301 }
291 } 302 }
292 mView->saveCalendar( defaultFileName() ); 303 mView->saveCalendar( defaultFileName() );
293 newFile = true; 304 newFile = true;
294 } 305 }
295 306
296 QTime neededSaveTime = QDateTime::currentDateTime().time(); 307 QTime neededSaveTime = QDateTime::currentDateTime().time();
297 mView->openCalendar( defaultFileName() ); 308 mView->openCalendar( defaultFileName() );
298 int msNeeded = neededSaveTime.msecsTo( QDateTime::currentDateTime().time() ); 309 int msNeeded = neededSaveTime.msecsTo( QDateTime::currentDateTime().time() );
299 qDebug("KO: Calendar loading time: %d ms",msNeeded ); 310 qDebug("KO: Calendar loading time: %d ms",msNeeded );
300 311
301 if ( KPimGlobalPrefs::instance()->mPreferredLanguage != KOPrefs::instance()->mOldLoadedLanguage ) { 312 if ( KPimGlobalPrefs::instance()->mPreferredLanguage != KOPrefs::instance()->mOldLoadedLanguage ) {
302 KOPrefs::instance()->setAllDefaults(); 313 KOPrefs::instance()->setAllDefaults();
303 int count = mView->addCategories(); 314 int count = mView->addCategories();
304 } 315 }
305 processIncidenceSelection( 0 ); 316 processIncidenceSelection( 0 );
306 connect( mView, SIGNAL( incidenceSelected( Incidence * ) ), 317 connect( mView, SIGNAL( incidenceSelected( Incidence * ) ),
307 SLOT( processIncidenceSelection( Incidence * ) ) ); 318 SLOT( processIncidenceSelection( Incidence * ) ) );
308 connect( mView, SIGNAL( modifiedChanged( bool ) ), 319 connect( mView, SIGNAL( modifiedChanged( bool ) ),
309 SLOT( slotModifiedChanged( bool ) ) ); 320 SLOT( slotModifiedChanged( bool ) ) );
310 321
311 322
312 connect( mView, SIGNAL( tempDisableBR(bool) ), 323 connect( mView, SIGNAL( tempDisableBR(bool) ),
313 SLOT( disableBR(bool) ) ); 324 SLOT( disableBR(bool) ) );
314 connect( &mSaveTimer, SIGNAL( timeout() ), SLOT( save() ) ); 325 connect( &mSaveTimer, SIGNAL( timeout() ), SLOT( save() ) );
315 mView->setModified( false ); 326 mView->setModified( false );
316 mBlockAtStartup = false; 327 mBlockAtStartup = false;
317 mView->setModified( false ); 328 mView->setModified( false );
318 setCentralWidget( mView ); 329 setCentralWidget( mView );
319 globalFlagBlockStartup = 0; 330 globalFlagBlockStartup = 0;
320 mView->show(); 331 mView->show();
321 delete splash; 332 delete splash;
322 if ( newFile ) 333 if ( newFile )
323 mView->updateConfig(); 334 mView->updateConfig();
324 // qApp->processEvents(); 335 // qApp->processEvents();
325 //qDebug("MainView x %d y %d w %d h %d", mView->x(),mView-> y(), mView->width(), mView->height ()); 336 //qDebug("MainView x %d y %d w %d h %d", mView->x(),mView-> y(), mView->width(), mView->height ());
326 //fillSyncMenu(); 337 //fillSyncMenu();
327 338
328 339
329 connect(mSyncManager , SIGNAL( save() ), this, SLOT( save() ) ); 340 connect(mSyncManager , SIGNAL( save() ), this, SLOT( save() ) );
330 connect(mView , SIGNAL( save() ), this, SLOT( save() ) ); 341 connect(mView , SIGNAL( save() ), this, SLOT( save() ) );
331 connect(mView , SIGNAL( saveStopTimer() ), this, SLOT( saveStopTimer() ) ); 342 connect(mView , SIGNAL( saveStopTimer() ), this, SLOT( saveStopTimer() ) );
332 connect(mSyncManager , SIGNAL( request_file() ), this, SLOT( syncFileRequest() ) ); 343 connect(mSyncManager , SIGNAL( request_file() ), this, SLOT( syncFileRequest() ) );
333 connect(mSyncManager , SIGNAL( getFile( bool )), this, SLOT(getFile( bool ) ) ); 344 connect(mSyncManager , SIGNAL( getFile( bool )), this, SLOT(getFile( bool ) ) );
334 mSyncManager->setDefaultFileName( sentSyncFile()); 345 mSyncManager->setDefaultFileName( sentSyncFile());
335 connect ( syncMenu, SIGNAL( activated ( int ) ), mSyncManager, SLOT (slotSyncMenu( int ) ) ); 346 connect ( syncMenu, SIGNAL( activated ( int ) ), mSyncManager, SLOT (slotSyncMenu( int ) ) );
336 mSyncManager->fillSyncMenu(); 347 mSyncManager->fillSyncMenu();
337 348
338 349
339 350
340 mView->viewManager()->agendaView()->setStartHour( KOPrefs::instance()->mDayBegins ); 351 mView->viewManager()->agendaView()->setStartHour( KOPrefs::instance()->mDayBegins );
341 if ( showWarning ) { 352 if ( showWarning ) {
342 KMessageBox::information( this, 353 KMessageBox::information( this,
343 "You are starting KO/Pi for the first time.\nPlease read menu: Help-What's New,\nif you did an update!\nPlease choose your timezone in the \nConfigure Dialog TAB Time Zone!\nPlease choose your language\nin the TAB Locale!\nYou get the Configure Dialog\nvia Menu: Actions - Configure....\nClick OK to show the Configure Dialog!\n", "KO/Pi information"); 354 "You are starting KO/Pi for the first time.\nPlease read menu: Help-What's New,\nif you did an update!\nPlease choose your timezone in the \nConfigure Dialog TAB Time Zone!\nPlease choose your language\nin the TAB Locale!\nYou get the Configure Dialog\nvia Menu: Actions - Configure....\nClick OK to show the Configure Dialog!\n", "KO/Pi information");
344 qApp->processEvents(); 355 qApp->processEvents();
345 mView->dialogManager()->showSyncOptions(); 356 mView->dialogManager()->showSyncOptions();
346 } 357 }
347 358
348 //US listen for result adressed from Ka/Pi 359 //US listen for result adressed from Ka/Pi
349#ifndef DESKTOP_VERSION 360#ifndef DESKTOP_VERSION
350 connect(qApp, SIGNAL (appMessage ( const QCString &, const QByteArray & )), ExternalAppHandler::instance(), SLOT (appMessage ( const QCString &, const QByteArray & ))); 361 connect(qApp, SIGNAL (appMessage ( const QCString &, const QByteArray & )), ExternalAppHandler::instance(), SLOT (appMessage ( const QCString &, const QByteArray & )));
351#endif 362#endif
352#ifndef DESKTOP_VERSION 363#ifndef DESKTOP_VERSION
353 infrared = 0; 364 infrared = 0;
354#endif 365#endif
355 updateFilterToolbar(); 366 updateFilterToolbar();
356 updateWeek( mView->startDate() ); 367 updateWeek( mView->startDate() );
357 connect( mView->dateNavigator(), SIGNAL( datesSelected( const KCal::DateList & ) ), 368 connect( mView->dateNavigator(), SIGNAL( datesSelected( const KCal::DateList & ) ),
358 SLOT( updateWeekNum( const KCal::DateList & ) ) ); 369 SLOT( updateWeekNum( const KCal::DateList & ) ) );
359 mBRdisabled = false; 370 mBRdisabled = false;
360 //toggleBeamReceive(); 371 //toggleBeamReceive();
361} 372}
362MainWindow::~MainWindow() 373MainWindow::~MainWindow()
363{ 374{
364 //qDebug("MainWindow::~MainWindow() "); 375 //qDebug("MainWindow::~MainWindow() ");
365 //save toolbar location 376 //save toolbar location
366 delete mCalendar; 377 delete mCalendar;
367 delete mSyncManager; 378 delete mSyncManager;
368#ifndef DESKTOP_VERSION 379#ifndef DESKTOP_VERSION
369 if ( infrared ) 380 if ( infrared )
370 delete infrared; 381 delete infrared;
371#endif 382#endif
372 383
373 384
374} 385}
375 386
376void MainWindow::disableBR(bool b) 387void MainWindow::disableBR(bool b)
377{ 388{
378#ifndef DESKTOP_VERSION 389#ifndef DESKTOP_VERSION
379 if ( b ) { 390 if ( b ) {
380 if ( infrared ) { 391 if ( infrared ) {
381 toggleBeamReceive(); 392 toggleBeamReceive();
382 mBRdisabled = true; 393 mBRdisabled = true;
383 } 394 }
384 mBRdisabled = true; 395 mBRdisabled = true;
385 } else { 396 } else {
386 if ( mBRdisabled ) { 397 if ( mBRdisabled ) {
387 mBRdisabled = false; 398 mBRdisabled = false;
388 //makes no sense,because other cal ap is probably running 399 //makes no sense,because other cal ap is probably running
389 // toggleBeamReceive(); 400 // toggleBeamReceive();
390 } 401 }
391 } 402 }
392#endif 403#endif
393 404
394} 405}
395bool MainWindow::beamReceiveEnabled() 406bool MainWindow::beamReceiveEnabled()
396{ 407{
397#ifndef DESKTOP_VERSION 408#ifndef DESKTOP_VERSION
398 return ( infrared != 0 ); 409 return ( infrared != 0 );
399#endif 410#endif
400 return false; 411 return false;
401} 412}
402 413
403void MainWindow::toggleBeamReceive() 414void MainWindow::toggleBeamReceive()
404{ 415{
405 if ( mBRdisabled ) 416 if ( mBRdisabled )
406 return; 417 return;
407#ifndef DESKTOP_VERSION 418#ifndef DESKTOP_VERSION
408 if ( infrared ) { 419 if ( infrared ) {
409 qDebug("disable BeamReceive "); 420 qDebug("disable BeamReceive ");
410 delete infrared; 421 delete infrared;
411 infrared = 0; 422 infrared = 0;
412 brAction->setOn(false); 423 brAction->setOn(false);
413 return; 424 return;
414 } 425 }
415 qDebug("enable BeamReceive "); 426 qDebug("enable BeamReceive ");
416 brAction->setOn(true); 427 brAction->setOn(true);
417 infrared = new QCopChannel("QPE/Application/datebook",this, "channel" ) ; 428 infrared = new QCopChannel("QPE/Application/datebook",this, "channel" ) ;
418 QObject::connect( infrared, SIGNAL (received ( const QCString &, const QByteArray & )),this, SLOT(recieve( const QCString&, const QByteArray& ))); 429 QObject::connect( infrared, SIGNAL (received ( const QCString &, const QByteArray & )),this, SLOT(recieve( const QCString&, const QByteArray& )));
419#endif 430#endif
420} 431}
421void MainWindow::showMaximized () 432void MainWindow::showMaximized ()
422{ 433{
423#ifndef DESKTOP_VERSION 434#ifndef DESKTOP_VERSION
424 if ( ! globalFlagBlockStartup ) 435 if ( ! globalFlagBlockStartup )
425 if ( mClosed ) 436 if ( mClosed )
426 mView->goToday(); 437 mView->goToday();
427#endif 438#endif
428 QWidget::showMaximized () ; 439 QWidget::showMaximized () ;
429 mClosed = false; 440 mClosed = false;
430} 441}
431void MainWindow::closeEvent( QCloseEvent* ce ) 442void MainWindow::closeEvent( QCloseEvent* ce )
432{ 443{
433 444
434 445
435 446
436 if ( ! KOPrefs::instance()->mAskForQuit ) { 447 if ( ! KOPrefs::instance()->mAskForQuit ) {
437 saveOnClose(); 448 saveOnClose();
438 mClosed = true; 449 mClosed = true;
439 ce->accept(); 450 ce->accept();
440 return; 451 return;
441 452
442 } 453 }
443 454
444 switch( QMessageBox::information( this, "KO/Pi", 455 switch( QMessageBox::information( this, "KO/Pi",
445 i18n("Do you really want\nto close KO/Pi?"), 456 i18n("Do you really want\nto close KO/Pi?"),
446 i18n("Close"), i18n("No"), 457 i18n("Close"), i18n("No"),
447 0, 0 ) ) { 458 0, 0 ) ) {
448 case 0: 459 case 0:
449 saveOnClose(); 460 saveOnClose();
450 mClosed = true; 461 mClosed = true;
451 ce->accept(); 462 ce->accept();
452 break; 463 break;
453 case 1: 464 case 1:
454 ce->ignore(); 465 ce->ignore();
455 break; 466 break;
456 case 2: 467 case 2:
457 468
458 default: 469 default:
459 break; 470 break;
460 } 471 }
@@ -2157,256 +2168,269 @@ void MainWindow::setCaptionToDates()
2157 setCaption( i18n("Dates: ") + selDates ); 2168 setCaption( i18n("Dates: ") + selDates );
2158 2169
2159} 2170}
2160void MainWindow::showConfigureAgenda( ) 2171void MainWindow::showConfigureAgenda( )
2161{ 2172{
2162 int iii; 2173 int iii;
2163 for ( iii = 1;iii<= 10 ;++iii ){ 2174 for ( iii = 1;iii<= 10 ;++iii ){
2164 configureAgendaMenu->setItemChecked( (iii+1)*2, false ); 2175 configureAgendaMenu->setItemChecked( (iii+1)*2, false );
2165 } 2176 }
2166 configureAgendaMenu->setItemChecked( (KOPrefs::instance()->mHourSize/2)*2, true ); 2177 configureAgendaMenu->setItemChecked( (KOPrefs::instance()->mHourSize/2)*2, true );
2167} 2178}
2168void MainWindow::configureAgenda( int item ) 2179void MainWindow::configureAgenda( int item )
2169{ 2180{
2170 if ( KOPrefs::instance()->mHourSize == item ) 2181 if ( KOPrefs::instance()->mHourSize == item )
2171 return; 2182 return;
2172 KOPrefs::instance()->mHourSize=item; 2183 KOPrefs::instance()->mHourSize=item;
2173 mView->viewManager()->agendaView()->updateConfig(); 2184 mView->viewManager()->agendaView()->updateConfig();
2174} 2185}
2175 2186
2176void MainWindow::saveCalendar() 2187void MainWindow::saveCalendar()
2177{ 2188{
2178 QString fn = KOPrefs::instance()->mLastSaveFile; 2189 QString fn = KOPrefs::instance()->mLastSaveFile;
2179 fn = KFileDialog::getSaveFileName( fn, i18n("Save backup filename"), this ); 2190 fn = KFileDialog::getSaveFileName( fn, i18n("Save backup filename"), this );
2180 2191
2181 if ( fn == "" ) 2192 if ( fn == "" )
2182 return; 2193 return;
2183 QFileInfo info; 2194 QFileInfo info;
2184 info.setFile( fn ); 2195 info.setFile( fn );
2185 QString mes; 2196 QString mes;
2186 bool createbup = true; 2197 bool createbup = true;
2187 if ( info. exists() ) { 2198 if ( info. exists() ) {
2188 mes = i18n("Backup file\nalready exists!\nOld backup file from:\n%1\nOverwrite?\n").arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )) ; 2199 mes = i18n("Backup file\nalready exists!\nOld backup file from:\n%1\nOverwrite?\n").arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )) ;
2189 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),mes, 2200 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),mes,
2190 i18n("Overwrite!"), i18n("Cancel"), 0, 2201 i18n("Overwrite!"), i18n("Cancel"), 0,
2191 0, 1 ); 2202 0, 1 );
2192 if ( result != 0 ) { 2203 if ( result != 0 ) {
2193 createbup = false; 2204 createbup = false;
2194 } 2205 }
2195 } 2206 }
2196 if ( createbup ) { 2207 if ( createbup ) {
2197 mView->saveCalendar( fn ); 2208 mView->saveCalendar( fn );
2198 mes = i18n("KO/Pi:Saved %1").arg(fn); 2209 mes = i18n("KO/Pi:Saved %1").arg(fn);
2199 KOPrefs::instance()->mLastSaveFile = fn; 2210 KOPrefs::instance()->mLastSaveFile = fn;
2200 setCaption(mes); 2211 setCaption(mes);
2201 } 2212 }
2202} 2213}
2203void MainWindow::loadCalendar() 2214void MainWindow::loadCalendar()
2204{ 2215{
2205 2216
2206 QString fn = KOPrefs::instance()->mLastLoadFile; 2217 QString fn = KOPrefs::instance()->mLastLoadFile;
2207 fn = KFileDialog::getOpenFileName( fn, i18n("Load backup filename"), this ); 2218 fn = KFileDialog::getOpenFileName( fn, i18n("Load backup filename"), this );
2208 2219
2209 if ( fn == "" ) 2220 if ( fn == "" )
2210 return; 2221 return;
2211 QFileInfo info; 2222 QFileInfo info;
2212 info.setFile( fn ); 2223 info.setFile( fn );
2213 QString mess; 2224 QString mess;
2214 bool loadbup = true; 2225 bool loadbup = true;
2215 if ( info. exists() ) { 2226 if ( info. exists() ) {
2216 mess = i18n("Backup file from:\n%1\nLoading backup\nfile will delete\nyour current Data!\n").arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); 2227 mess = i18n("Backup file from:\n%1\nLoading backup\nfile will delete\nyour current Data!\n").arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false ));
2217 int result = QMessageBox::warning( this, "KO/Pi: Warning!", 2228 int result = QMessageBox::warning( this, "KO/Pi: Warning!",
2218 mess, 2229 mess,
2219 i18n("Load!"), i18n("Cancel"), 0, 2230 i18n("Load!"), i18n("Cancel"), 0,
2220 0, 1 ); 2231 0, 1 );
2221 if ( result != 0 ) { 2232 if ( result != 0 ) {
2222 loadbup = false; 2233 loadbup = false;
2223 } 2234 }
2224 } else { 2235 } else {
2225 QMessageBox::warning( this, i18n("KO/Pi: Warning!"), 2236 QMessageBox::warning( this, i18n("KO/Pi: Warning!"),
2226 i18n("Backup file\ndoes not exist!\nNothing loaded!"), 0, 0, 2237 i18n("Backup file\ndoes not exist!\nNothing loaded!"), 0, 0,
2227 0, 1 ); 2238 0, 1 );
2228 2239
2229 return; 2240 return;
2230 } 2241 }
2231 if ( loadbup ) { 2242 if ( loadbup ) {
2232 mView->openCalendar( fn ); 2243 mView->openCalendar( fn );
2233 KOPrefs::instance()->mLastLoadFile = fn; 2244 KOPrefs::instance()->mLastLoadFile = fn;
2234 mess = i18n("KO/Pi:Loaded %1").arg(fn) ; 2245 mess = i18n("KO/Pi:Loaded %1").arg(fn) ;
2235 setCaption(mess); 2246 setCaption(mess);
2236 } 2247 }
2237 2248
2238} 2249}
2239void MainWindow::quickImportIcal() 2250void MainWindow::quickImportIcal()
2240{ 2251{
2241 importFile( KOPrefs::instance()->mLastImportFile, false ); 2252 importFile( KOPrefs::instance()->mLastImportFile, false );
2242} 2253}
2243void MainWindow::importFile( QString fn, bool quick ) 2254void MainWindow::importFile( QString fn, bool quick )
2244{ 2255{
2245 QFileInfo info; 2256 QFileInfo info;
2246 info.setFile( fn ); 2257 info.setFile( fn );
2247 QString mess; 2258 QString mess;
2248 bool loadbup = true; 2259 bool loadbup = true;
2249 if ( !info. exists() ) { 2260 if ( !info. exists() ) {
2250 mess = i18n("Import file \n...%1\ndoes not exist!\nNothing imported!\n").arg(fn.right( 30)); 2261 mess = i18n("Import file \n...%1\ndoes not exist!\nNothing imported!\n").arg(fn.right( 30));
2251 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), 2262 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),
2252 mess ); 2263 mess );
2253 return; 2264 return;
2254 } 2265 }
2255 int result = 0; 2266 int result = 0;
2256 if ( !quick ) { 2267 if ( !quick ) {
2257 mess = i18n( "Import file \n...%1\nfrom:\n%2\nDuplicated entries\nwill not be imported!\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); 2268 mess = i18n( "Import file \n...%1\nfrom:\n%2\nDuplicated entries\nwill not be imported!\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false ));
2258 result = QMessageBox::warning( this, "KO/Pi: Warning!", 2269 result = QMessageBox::warning( this, "KO/Pi: Warning!",
2259 mess, 2270 mess,
2260 "Import", "Cancel", 0, 2271 "Import", "Cancel", 0,
2261 0, 1 ); 2272 0, 1 );
2262 } 2273 }
2263 if ( result == 0 ) { 2274 if ( result == 0 ) {
2264 if ( mView->openCalendar( fn, true )) { 2275 if ( mView->openCalendar( fn, true )) {
2265 KOPrefs::instance()->mLastImportFile = fn; 2276 KOPrefs::instance()->mLastImportFile = fn;
2266 setCaption(i18n("Imported file successfully")); 2277 setCaption(i18n("Imported file successfully"));
2267 } else { 2278 } else {
2268 setCaption(i18n("Error importing file")); 2279 setCaption(i18n("Error importing file"));
2269 } 2280 }
2270 } 2281 }
2271} 2282}
2272 2283
2273void MainWindow::importIcal() 2284void MainWindow::importIcal()
2274{ 2285{
2275 2286
2276 QString fn =KOPrefs::instance()->mLastImportFile; 2287 QString fn =KOPrefs::instance()->mLastImportFile;
2277 2288
2278 fn =KFileDialog:: getOpenFileName( fn, i18n("Import filename(*.ics/*.vcs)"), this ); 2289 fn =KFileDialog:: getOpenFileName( fn, i18n("Import filename(*.ics/*.vcs)"), this );
2279 if ( fn == "" ) 2290 if ( fn == "" )
2280 return; 2291 return;
2281 importFile( fn, true ); 2292 importFile( fn, true );
2282 2293
2283} 2294}
2284 2295
2285void MainWindow::exportVCalendar() 2296void MainWindow::exportVCalendar()
2286{ 2297{
2287 QString fn = KOPrefs::instance()->mLastVcalFile; 2298 QString fn = KOPrefs::instance()->mLastVcalFile;
2288 fn = KFileDialog::getSaveFileName( fn, i18n("Export vcal filename(*.vcs)"), this ); 2299 fn = KFileDialog::getSaveFileName( fn, i18n("Export vcal filename(*.vcs)"), this );
2289 if ( fn == "" ) 2300 if ( fn == "" )
2290 return; 2301 return;
2291 QFileInfo info; 2302 QFileInfo info;
2292 info.setFile( fn ); 2303 info.setFile( fn );
2293 QString mes; 2304 QString mes;
2294 bool createbup = true; 2305 bool createbup = true;
2295 if ( info. exists() ) { 2306 if ( info. exists() ) {
2296 mes = i18n("Save file\nalready exists!\nOld save file from:\n%1\nOverwrite?\n").arg (KGlobal::locale()->formatDateTime(info.lastModified (), true, false ) ); 2307 mes = i18n("Save file\nalready exists!\nOld save file from:\n%1\nOverwrite?\n").arg (KGlobal::locale()->formatDateTime(info.lastModified (), true, false ) );
2297 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),mes, 2308 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),mes,
2298 i18n("Overwrite!"), i18n("Cancel"), 0, 2309 i18n("Overwrite!"), i18n("Cancel"), 0,
2299 0, 1 ); 2310 0, 1 );
2300 if ( result != 0 ) { 2311 if ( result != 0 ) {
2301 createbup = false; 2312 createbup = false;
2302 } 2313 }
2303 } 2314 }
2304 if ( createbup ) { 2315 if ( createbup ) {
2305 if ( mView->exportVCalendar( fn ) ) { 2316 if ( mView->exportVCalendar( fn ) ) {
2306 KOPrefs::instance()->mLastVcalFile = fn; 2317 KOPrefs::instance()->mLastVcalFile = fn;
2307 if ( fn.length() > 20 ) 2318 if ( fn.length() > 20 )
2308 mes = i18n("KO/Pi:Exported to ...%1").arg(fn.right(20)) ; 2319 mes = i18n("KO/Pi:Exported to ...%1").arg(fn.right(20)) ;
2309 else 2320 else
2310 mes = i18n("KO/Pi:Exported to %1").arg(fn ); 2321 mes = i18n("KO/Pi:Exported to %1").arg(fn );
2311 setCaption(mes); 2322 setCaption(mes);
2312 } 2323 }
2313 } 2324 }
2314 2325
2315} 2326}
2316QString MainWindow::sentSyncFile() 2327QString MainWindow::sentSyncFile()
2317{ 2328{
2318#ifdef DESKTOP_VERSION 2329#ifdef DESKTOP_VERSION
2319 return locateLocal( "tmp", "copysynccal.ics" ); 2330 return locateLocal( "tmp", "copysynccal.ics" );
2320#else 2331#else
2321 return QString( "/tmp/copysynccal.ics" ); 2332 return QString( "/tmp/copysynccal.ics" );
2322#endif 2333#endif
2323} 2334}
2324 2335
2325void MainWindow::syncFileRequest() 2336void MainWindow::syncFileRequest()
2326{ 2337{
2327 if ( KOPrefs::instance()->mPassiveSyncWithDesktop ) { 2338 if ( KOPrefs::instance()->mPassiveSyncWithDesktop ) {
2328 mSyncManager->slotSyncMenu( 999 ); 2339 mSyncManager->slotSyncMenu( 999 );
2329 } 2340 }
2330 2341
2331 setCaption(i18n("Saving Data to temp file ..." )); 2342 setCaption(i18n("Saving Data to temp file ..." ));
2332 mView->saveCalendar( sentSyncFile() ); 2343 mView->saveCalendar( sentSyncFile() );
2333 setCaption(i18n("Data saved to temp file!" )); 2344 setCaption(i18n("Data saved to temp file!" ));
2334 2345
2335} 2346}
2336void MainWindow::getFile( bool success ) 2347void MainWindow::getFile( bool success )
2337{ 2348{
2338 if ( ! success ) { 2349 if ( ! success ) {
2339 setCaption( i18n("Error receiving file. Nothing changed!") ); 2350 setCaption( i18n("Error receiving file. Nothing changed!") );
2340 return; 2351 return;
2341 } 2352 }
2342 mView->openCalendar( sentSyncFile() ); 2353 mView->openCalendar( sentSyncFile() );
2343 if ( KOPrefs::instance()->mPassiveSyncWithDesktop ) { 2354 if ( KOPrefs::instance()->mPassiveSyncWithDesktop ) {
2344 mSyncManager->slotSyncMenu( 999 ); 2355 mSyncManager->slotSyncMenu( 999 );
2345 } 2356 }
2346 setCaption( i18n("Pi-Sync successful!") ); 2357 setCaption( i18n("Pi-Sync successful!") );
2347} 2358}
2348 2359
2349void MainWindow::printSel( ) 2360void MainWindow::printSel( )
2350{ 2361{
2351 mView->viewManager()->agendaView()->agenda()->printSelection(); 2362 mView->viewManager()->agendaView()->agenda()->printSelection();
2352} 2363}
2353 2364
2354void MainWindow::printCal() 2365void MainWindow::printCal()
2355{ 2366{
2356 mView->print();//mCp->showDialog(); 2367 mView->print();//mCp->showDialog();
2357} 2368}
2358 2369
2359 2370
2360#include "libkdepim/kdatepicker.h" 2371#include "libkdepim/kdatepicker.h"
2361#include <kdatetbl.h> 2372#include <kdatetbl.h>
2362 2373
2363void MainWindow::weekAction() 2374void MainWindow::weekAction()
2364{ 2375{
2365 int month; 2376 int month;
2366 KPopupFrame* popup = new KPopupFrame(this); 2377 KPopupFrame* popup = new KPopupFrame(this);
2367 KDateInternalWeekPicker* picker = new KDateInternalWeekPicker(popup); 2378 KDateInternalWeekPicker* picker = new KDateInternalWeekPicker(popup);
2368 // ----- 2379 // -----
2369 picker->resize(picker->sizeHint()); 2380 picker->resize(picker->sizeHint());
2370 popup->setMainWidget(picker); 2381 popup->setMainWidget(picker);
2371 picker->setFocus(); 2382 picker->setFocus();
2372 connect(picker, SIGNAL(closeMe(int)), popup, SLOT(close(int))); 2383 connect(picker, SIGNAL(closeMe(int)), popup, SLOT(close(int)));
2373 int x = 0; 2384 int x = 0;
2374 int y = iconToolBar->height(); 2385 int y = iconToolBar->height();
2375 int dX = 0; 2386 int dX = 0;
2376 int dY = 0; 2387 int dY = 0;
2377 if ( iconToolBar->orientation () == Qt:: Horizontal ) { 2388 if ( iconToolBar->orientation () == Qt:: Horizontal ) {
2378 if ( iconToolBar->y() > height()/2 ) { 2389 if ( iconToolBar->y() > height()/2 ) {
2379 dY = picker->sizeHint().height()+8; 2390 dY = picker->sizeHint().height()+8;
2380 y = 0; 2391 y = 0;
2381 } 2392 }
2382 } else { 2393 } else {
2383 if ( iconToolBar->x() > width()/2 ) { // right side 2394 if ( iconToolBar->x() > width()/2 ) { // right side
2384 x=0; 2395 x=0;
2385 dX= picker->sizeHint().width()+8; 2396 dX= picker->sizeHint().width()+8;
2386 y = 0; 2397 y = 0;
2387 } else { 2398 } else {
2388 x= iconToolBar->width(); 2399 x= iconToolBar->width();
2389 y = 0; 2400 y = 0;
2390 } 2401 }
2391 } 2402 }
2392 //qDebug("dax %d dy %d %d %d ", dX, dY, iconToolBar->x(), iconToolBar->y() ); 2403 //qDebug("dax %d dy %d %d %d ", dX, dY, iconToolBar->x(), iconToolBar->y() );
2393 if(popup->exec(iconToolBar->mapToGlobal(QPoint(x,y)-QPoint( dX,dY)))) 2404 if(popup->exec(iconToolBar->mapToGlobal(QPoint(x,y)-QPoint( dX,dY))))
2394 { 2405 {
2395 month = picker->getResult(); 2406 month = picker->getResult();
2396 emit selectWeek ( month ); 2407 emit selectWeek ( month );
2397 //qDebug("weekSelected %d ", month); 2408 //qDebug("weekSelected %d ", month);
2398 } 2409 }
2399 delete popup; 2410 delete popup;
2400} 2411}
2401 2412
2402void MainWindow::hideEvent ( QHideEvent * ) 2413void MainWindow::hideEvent ( QHideEvent * )
2403{ 2414{
2404 QString message; 2415 QString message;
2405 QDateTime nextA = mCalendar->nextAlarmEventDateTime(); 2416 QDateTime nextA = mCalendar->nextAlarmEventDateTime();
2406 if ( nextA.isValid() ) { 2417 if ( nextA.isValid() ) {
2407 QString sum = mCalendar->nextSummary(); 2418 QString sum = mCalendar->nextSummary();
2408 2419
2409 message = i18n("%1 %2 - %3 (next event/todo with alarm)").arg( KGlobal::locale()->formatTime(nextA.time() , false)).arg(sum ).arg( KGlobal::locale()->formatDate(nextA.date() , false)); 2420 message = i18n("%1 %2 - %3 (next event/todo with alarm)").arg( KGlobal::locale()->formatTime(nextA.time() , false)).arg(sum ).arg( KGlobal::locale()->formatDate(nextA.date() , false));
2410 setCaption( message ); 2421 setCaption( message );
2411 } 2422 }
2412} 2423}
2424
2425void MainWindow::resizeEvent( QResizeEvent* e)
2426{
2427#ifndef DESKTOP_VERSION
2428 if ( !KOPrefs::instance()->mShowIconFilter && !KOPrefs::instance()->mShowIconOnetoolbar ) {
2429 if (QApplication::desktop()->width() > QApplication::desktop()->height() )
2430 filterToolBar->hide();
2431 else
2432 filterToolBar->show();
2433 }
2434#endif
2435 QMainWindow::resizeEvent( e);
2436}
diff --git a/korganizer/mainwindow.h b/korganizer/mainwindow.h
index 7c16aeb..4d1753f 100644
--- a/korganizer/mainwindow.h
+++ b/korganizer/mainwindow.h
@@ -1,172 +1,173 @@
1#ifndef KORGE_MAINWINDOW_H 1#ifndef KORGE_MAINWINDOW_H
2#define KORGE_MAINWINDOW_H 2#define KORGE_MAINWINDOW_H
3 3
4#include <qmainwindow.h> 4#include <qmainwindow.h>
5#include <qtimer.h> 5#include <qtimer.h>
6#include <qdict.h> 6#include <qdict.h>
7#include <qfile.h> 7#include <qfile.h>
8#include <qmenubar.h> 8#include <qmenubar.h>
9#include <qtextstream.h> 9#include <qtextstream.h>
10#include <qregexp.h> 10#include <qregexp.h>
11 11
12#include <libkcal/incidence.h> 12#include <libkcal/incidence.h>
13#include "simplealarmclient.h" 13#include "simplealarmclient.h"
14#include <ksyncmanager.h> 14#include <ksyncmanager.h>
15#ifndef DESKTOP_VERSION 15#ifndef DESKTOP_VERSION
16#include <qcopchannel_qws.h> 16#include <qcopchannel_qws.h>
17#endif 17#endif
18class QAction; 18class QAction;
19class CalendarView; 19class CalendarView;
20class KSyncProfile; 20class KSyncProfile;
21#ifdef DESKTOP_VERSION 21#ifdef DESKTOP_VERSION
22 22
23#define QPEToolBar QToolBar 23#define QPEToolBar QToolBar
24#define QPEMenuBar QMenuBar 24#define QPEMenuBar QMenuBar
25#endif 25#endif
26class QPEToolBar; 26class QPEToolBar;
27class QPEMenuBar; 27class QPEMenuBar;
28 28
29 29
30namespace KCal { 30namespace KCal {
31class CalendarLocal; 31class CalendarLocal;
32} 32}
33 33
34class KOMenuBar : public QMenuBar 34class KOMenuBar : public QMenuBar
35{ 35{
36 public: 36 public:
37 KOMenuBar( QWidget *parent=0 ): QMenuBar (parent ) {;} 37 KOMenuBar( QWidget *parent=0 ): QMenuBar (parent ) {;}
38 QSize sizeHint () const{ qDebug("sizejint ");return QSize ( 40,25 );} 38 QSize sizeHint () const{ qDebug("sizejint ");return QSize ( 40,25 );}
39}; 39};
40 40
41using namespace KCal; 41using namespace KCal;
42 42
43class MainWindow : public QMainWindow 43class MainWindow : public QMainWindow
44{ 44{
45 Q_OBJECT 45 Q_OBJECT
46 public: 46 public:
47 MainWindow( QWidget *parent = 0, const char *name = 0, QString command = ""); 47 MainWindow( QWidget *parent = 0, const char *name = 0, QString command = "");
48 ~MainWindow(); 48 ~MainWindow();
49 bool beamReceiveEnabled(); 49 bool beamReceiveEnabled();
50 static QString defaultFileName(); 50 static QString defaultFileName();
51 static QString syncFileName(); 51 static QString syncFileName();
52 static QString resourcePath(); 52 static QString resourcePath();
53 public slots: 53 public slots:
54 void setCaption ( const QString & ); 54 void setCaption ( const QString & );
55 void updateWeekNum(const KCal::DateList &); 55 void updateWeekNum(const KCal::DateList &);
56 void updateWeek(QDate); 56 void updateWeek(QDate);
57 void updateFilterToolbar(); 57 void updateFilterToolbar();
58 virtual void showMaximized (); 58 virtual void showMaximized ();
59 void configureAgenda( int ); 59 void configureAgenda( int );
60 void recieve( const QCString& msg, const QByteArray& data ); 60 void recieve( const QCString& msg, const QByteArray& data );
61 protected slots: 61 protected slots:
62 void setCaptionToDates(); 62 void setCaptionToDates();
63 void weekAction(); 63 void weekAction();
64 void about(); 64 void about();
65 void licence(); 65 void licence();
66 void faq(); 66 void faq();
67 void usertrans(); 67 void usertrans();
68 void features(); 68 void features();
69 void synchowto(); 69 void synchowto();
70 void kdesynchowto(); 70 void kdesynchowto();
71 void multisynchowto(); 71 void multisynchowto();
72 void whatsNew(); 72 void whatsNew();
73 void keyBindings(); 73 void keyBindings();
74 void aboutAutoSaving();; 74 void aboutAutoSaving();;
75 void aboutKnownBugs(); 75 void aboutKnownBugs();
76 76
77 void processIncidenceSelection( Incidence * ); 77 void processIncidenceSelection( Incidence * );
78 78
79 void importQtopia(); 79 void importQtopia();
80 void importBday(); 80 void importBday();
81 void importOL(); 81 void importOL();
82 void importIcal(); 82 void importIcal();
83 void importFile( QString, bool ); 83 void importFile( QString, bool );
84 void quickImportIcal(); 84 void quickImportIcal();
85 85
86 void slotModifiedChanged( bool ); 86 void slotModifiedChanged( bool );
87 87
88 void save(); 88 void save();
89 void saveStopTimer(); 89 void saveStopTimer();
90 void configureToolBar( int ); 90 void configureToolBar( int );
91 void printSel(); 91 void printSel();
92 void printCal(); 92 void printCal();
93 void saveCalendar(); 93 void saveCalendar();
94 void loadCalendar(); 94 void loadCalendar();
95 void exportVCalendar(); 95 void exportVCalendar();
96 void fillFilterMenu(); 96 void fillFilterMenu();
97 void fillFilterMenuTB(); 97 void fillFilterMenuTB();
98 void selectFilter( int ); 98 void selectFilter( int );
99 void fillFilterMenuPopup(); 99 void fillFilterMenuPopup();
100 void selectFilterPopup( int ); 100 void selectFilterPopup( int );
101 void exportToPhone( int ); 101 void exportToPhone( int );
102 void toggleBeamReceive(); 102 void toggleBeamReceive();
103 void disableBR(bool); 103 void disableBR(bool);
104 signals: 104 signals:
105 void selectWeek ( int ); 105 void selectWeek ( int );
106 private slots: 106 private slots:
107 void showConfigureAgenda(); 107 void showConfigureAgenda();
108 void getFile( bool ); 108 void getFile( bool );
109 void syncFileRequest(); 109 void syncFileRequest();
110 110
111 protected: 111 protected:
112 void hideEvent ( QHideEvent * ); 112 void hideEvent ( QHideEvent * );
113 QString sentSyncFile(); 113 QString sentSyncFile();
114 void displayText( QString, QString); 114 void displayText( QString, QString);
115 void enableIncidenceActions( bool ); 115 void enableIncidenceActions( bool );
116 116
117 private: 117 private:
118 bool mBRdisabled; 118 bool mBRdisabled;
119#ifndef DESKTOP_VERSION 119#ifndef DESKTOP_VERSION
120 QCopChannel* infrared; 120 QCopChannel* infrared;
121#endif 121#endif
122 QAction* brAction; 122 QAction* brAction;
123 KSyncManager* mSyncManager; 123 KSyncManager* mSyncManager;
124 bool mClosed; 124 bool mClosed;
125 void saveOnClose(); 125 void saveOnClose();
126 bool mFlagKeyPressed; 126 bool mFlagKeyPressed;
127 bool mBlockAtStartup; 127 bool mBlockAtStartup;
128 QPEToolBar *iconToolBar; 128 QPEToolBar *iconToolBar;
129 QPEToolBar *viewToolBar; 129 QPEToolBar *viewToolBar;
130 QPEToolBar *navigatorToolBar; 130 QPEToolBar *navigatorToolBar;
131 QPEToolBar *filterToolBar; 131 QPEToolBar *filterToolBar;
132 QPEMenuBar *filterMenubar; 132 QPEMenuBar *filterMenubar;
133 QPopupMenu * filterPopupMenu; 133 QPopupMenu * filterPopupMenu;
134 void initActions(); 134 void initActions();
135 void setDefaultPreferences(); 135 void setDefaultPreferences();
136 void resizeEvent( QResizeEvent* e);
136 void keyPressEvent ( QKeyEvent * ) ; 137 void keyPressEvent ( QKeyEvent * ) ;
137 void keyReleaseEvent ( QKeyEvent * ) ; 138 void keyReleaseEvent ( QKeyEvent * ) ;
138 QPopupMenu *configureToolBarMenu; 139 QPopupMenu *configureToolBarMenu;
139 QPopupMenu *selectFilterMenu; 140 QPopupMenu *selectFilterMenu;
140 QPopupMenu *selectFilterMenuTB; 141 QPopupMenu *selectFilterMenuTB;
141 QPopupMenu *configureAgendaMenu, *syncMenu; 142 QPopupMenu *configureAgendaMenu, *syncMenu;
142 CalendarLocal *mCalendar; 143 CalendarLocal *mCalendar;
143 CalendarView *mView; 144 CalendarView *mView;
144 QAction *mNewSubTodoAction; 145 QAction *mNewSubTodoAction;
145 QAction *mWeekAction; 146 QAction *mWeekAction;
146 QFont mWeekFont; 147 QFont mWeekFont;
147 QPixmap mWeekPixmap; 148 QPixmap mWeekPixmap;
148 QColor mWeekBgColor; 149 QColor mWeekBgColor;
149 150
150 QAction *mShowAction; 151 QAction *mShowAction;
151 QAction *mEditAction; 152 QAction *mEditAction;
152 QAction *mDeleteAction; 153 QAction *mDeleteAction;
153 QAction *mCloneAction; 154 QAction *mCloneAction;
154 QAction *mMoveAction; 155 QAction *mMoveAction;
155 QAction *mBeamAction; 156 QAction *mBeamAction;
156 QAction *mCancelAction; 157 QAction *mCancelAction;
157 158
158 QAction *mToggleNav; 159 QAction *mToggleNav;
159 QAction *mToggleFilter; 160 QAction *mToggleFilter;
160 QAction *mToggleAllday; 161 QAction *mToggleAllday;
161 QAction *actionFilterMenuTB; 162 QAction *actionFilterMenuTB;
162 163
163 void closeEvent( QCloseEvent* ce ); 164 void closeEvent( QCloseEvent* ce );
164 SimpleAlarmClient mAlarmClient; 165 SimpleAlarmClient mAlarmClient;
165 QTimer mSaveTimer; 166 QTimer mSaveTimer;
166 //bool mBlockSaveFlag; 167 //bool mBlockSaveFlag;
167 bool mCalendarModifiedFlag; 168 bool mCalendarModifiedFlag;
168 QPixmap loadPixmap( QString ); 169 QPixmap loadPixmap( QString );
169}; 170};
170 171
171 172
172#endif 173#endif