Diffstat (limited to 'korganizer/koeventpopupmenu.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | korganizer/koeventpopupmenu.cpp | 44 |
1 files changed, 41 insertions, 3 deletions
diff --git a/korganizer/koeventpopupmenu.cpp b/korganizer/koeventpopupmenu.cpp index 17ef81e..90caaf4 100644 --- a/korganizer/koeventpopupmenu.cpp +++ b/korganizer/koeventpopupmenu.cpp | |||
@@ -1,130 +1,168 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of KOrganizer. | 2 | This file is part of KOrganizer. |
3 | Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> | 3 | Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> |
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 <qcursor.h> | 24 | #include <qcursor.h> |
25 | 25 | ||
26 | #include <klocale.h> | 26 | #include <klocale.h> |
27 | #include <kdebug.h> | 27 | #include <kdebug.h> |
28 | #include <kiconloader.h> | 28 | #include <kiconloader.h> |
29 | 29 | ||
30 | #include <libkcal/event.h> | 30 | #include <libkcal/event.h> |
31 | 31 | ||
32 | #include "koeventpopupmenu.h" | 32 | #include "koeventpopupmenu.h" |
33 | #include "koprefs.h" | ||
33 | 34 | ||
34 | KOEventPopupMenu::KOEventPopupMenu() | 35 | KOEventPopupMenu::KOEventPopupMenu(): QPopupMenu() |
35 | { | 36 | { |
36 | mCurrentIncidence = 0; | 37 | mCurrentIncidence = 0; |
37 | mHasAdditionalItems = false; | 38 | mHasAdditionalItems = false; |
38 | 39 | ||
39 | 40 | ||
40 | mSingleOnlyItems.append( insertItem (i18n("&Show"),this,SLOT(popupShow()))); | 41 | mSingleOnlyItems.append( insertItem (i18n("&Show"),this,SLOT(popupShow()))); |
41 | mEditOnlyItems.append(insertItem (i18n("&Edit..."),this,SLOT(popupEdit()))); | 42 | mEditOnlyItems.append(insertItem (i18n("&Edit..."),this,SLOT(popupEdit()))); |
42 | mEditOnlyItems.append(insertItem (i18n("&Delete"), | 43 | mEditOnlyItems.append(insertItem (i18n("&Delete"), |
43 | this,SLOT(popupDelete()))); | 44 | this,SLOT(popupDelete()))); |
44 | mEditOnlyItems.append(insertItem (i18n("&Clone..."), | 45 | mEditOnlyItems.append(insertItem (i18n("&Clone..."), |
45 | this,SLOT(popupClone()))); | 46 | this,SLOT(popupClone()))); |
46 | mEditOnlyItems.append(insertItem (i18n("&Move..."), | 47 | mEditOnlyItems.append(insertItem (i18n("&Move..."), |
47 | this,SLOT(popupMove()))); | 48 | this,SLOT(popupMove()))); |
48 | #ifndef DESKTOP_VERSION | 49 | #ifndef DESKTOP_VERSION |
49 | mEditOnlyItems.append(insertItem (i18n("&Beam..."), | 50 | mEditOnlyItems.append(insertItem (i18n("&Beam..."), |
50 | this,SLOT(popupBeam()))); | 51 | this,SLOT(popupBeam()))); |
51 | #endif | 52 | #endif |
52 | mEditOnlyItems.append(insertItem (i18n("&Toggle Cancel"), | 53 | mEditOnlyItems.append(insertItem (i18n("&Toggle Cancel"), |
53 | this,SLOT(popupCancel()))); | 54 | this,SLOT(popupCancel()))); |
54 | isDisabled = false; | 55 | isDisabled = false; |
56 | mCatPopup = new QPopupMenu ( this ); | ||
57 | mCatPopup->setCheckable (true); | ||
58 | connect(mCatPopup,SIGNAL( aboutToShow ()), this ,SLOT( fillCatPopup())); | ||
59 | connect(mCatPopup,SIGNAL( activated ( int ) ), this ,SLOT( computeCatPopup( int ))); | ||
60 | mEditOnlyItems.append(insertItem (i18n("Categories"),mCatPopup )); | ||
55 | QValueList<int>::Iterator it; | 61 | QValueList<int>::Iterator it; |
56 | for( it = mEditOnlyItems.begin(); it != mEditOnlyItems.end(); ++it ) { | 62 | for( it = mEditOnlyItems.begin(); it != mEditOnlyItems.end(); ++it ) { |
57 | mSingleOnlyItems.append(*it); | 63 | mSingleOnlyItems.append(*it); |
58 | } | 64 | } |
65 | |||
59 | } | 66 | } |
60 | void KOEventPopupMenu::enableDefault( bool enable ) | 67 | void KOEventPopupMenu::enableDefault( bool enable ) |
61 | { | 68 | { |
62 | isDisabled = !enable; | 69 | isDisabled = !enable; |
63 | QValueList<int>::Iterator it; | 70 | QValueList<int>::Iterator it; |
64 | for( it = mSingleOnlyItems.begin(); it != mSingleOnlyItems.end(); ++it ) { | 71 | for( it = mSingleOnlyItems.begin(); it != mSingleOnlyItems.end(); ++it ) { |
65 | setItemEnabled(*it,enable); | 72 | setItemEnabled(*it,enable); |
66 | } | 73 | } |
67 | 74 | ||
68 | } | 75 | } |
69 | 76 | ||
77 | void KOEventPopupMenu::fillCatPopup() | ||
78 | { | ||
79 | mCatPopup->clear(); | ||
80 | QStringList checkedCategories = mCurrentIncidence->categories(); | ||
81 | int index = 0; | ||
82 | for (QStringList::Iterator it = KOPrefs::instance()->mCustomCategories.begin (); | ||
83 | it != KOPrefs::instance()->mCustomCategories.end (); | ||
84 | ++it) { | ||
85 | mCatPopup->insertItem (*it, index ); | ||
86 | if (checkedCategories.find (*it) != checkedCategories.end ()) { | ||
87 | mCatPopup->setItemChecked (index, true); | ||
88 | } | ||
89 | ++index; | ||
90 | } | ||
91 | } | ||
92 | void KOEventPopupMenu::computeCatPopup( int index ) | ||
93 | { | ||
94 | QStringList categories = mCurrentIncidence->categories(); | ||
95 | QString colcat = categories.first(); | ||
96 | if (categories.find (KOPrefs::instance()->mCustomCategories[index]) != categories.end ()) | ||
97 | categories.remove (KOPrefs::instance()->mCustomCategories[index]); | ||
98 | else | ||
99 | categories.insert (categories.end(), KOPrefs::instance()->mCustomCategories[index]); | ||
100 | categories.sort (); | ||
101 | if ( !colcat.isEmpty() ) { | ||
102 | if ( categories.find ( colcat ) != categories.end () ) { | ||
103 | categories.remove( colcat ); | ||
104 | categories.prepend( colcat ); | ||
105 | } | ||
106 | } | ||
107 | mCurrentIncidence->setCategories( categories ); | ||
108 | emit categoryChanged( mCurrentIncidence ); | ||
109 | } | ||
70 | void KOEventPopupMenu::showIncidencePopup(Incidence *incidence) | 110 | void KOEventPopupMenu::showIncidencePopup(Incidence *incidence) |
71 | { | 111 | { |
72 | mCurrentIncidence = incidence; | 112 | mCurrentIncidence = incidence; |
73 | 113 | ||
74 | if (mCurrentIncidence) { | 114 | if (mCurrentIncidence) { |
75 | // Enable/Disabled menu items only valid for editable events. | 115 | // Enable/Disabled menu items only valid for editable events. |
76 | if ( !isDisabled ) { | 116 | if ( !isDisabled ) { |
77 | QValueList<int>::Iterator it; | 117 | QValueList<int>::Iterator it; |
78 | for( it = mEditOnlyItems.begin(); it != mEditOnlyItems.end(); ++it ) { | 118 | for( it = mEditOnlyItems.begin(); it != mEditOnlyItems.end(); ++it ) { |
79 | setItemEnabled(*it,!mCurrentIncidence->isReadOnly()); | 119 | setItemEnabled(*it,!mCurrentIncidence->isReadOnly()); |
80 | } | 120 | } |
81 | } | 121 | } |
82 | popup(QCursor::pos()); | 122 | popup(QCursor::pos()); |
83 | } else { | ||
84 | kdDebug() << "KOEventPopupMenu::showEventPopup(): No event selected" << endl; | ||
85 | } | 123 | } |
86 | } | 124 | } |
87 | 125 | ||
88 | void KOEventPopupMenu::addAdditionalItem(const QIconSet &icon,const QString &text, | 126 | void KOEventPopupMenu::addAdditionalItem(const QIconSet &icon,const QString &text, |
89 | const QObject *receiver, const char *member, | 127 | const QObject *receiver, const char *member, |
90 | bool editOnly) | 128 | bool editOnly) |
91 | { | 129 | { |
92 | if (!mHasAdditionalItems) { | 130 | if (!mHasAdditionalItems) { |
93 | mHasAdditionalItems = true; | 131 | mHasAdditionalItems = true; |
94 | insertSeparator(); | 132 | insertSeparator(); |
95 | } | 133 | } |
96 | int id = insertItem(icon,text,receiver,member); | 134 | int id = insertItem(icon,text,receiver,member); |
97 | if (editOnly) mEditOnlyItems.append(id); | 135 | if (editOnly) mEditOnlyItems.append(id); |
98 | } | 136 | } |
99 | 137 | ||
100 | void KOEventPopupMenu::popupShow() | 138 | void KOEventPopupMenu::popupShow() |
101 | { | 139 | { |
102 | if (mCurrentIncidence) emit showIncidenceSignal(mCurrentIncidence); | 140 | if (mCurrentIncidence) emit showIncidenceSignal(mCurrentIncidence); |
103 | } | 141 | } |
104 | 142 | ||
105 | void KOEventPopupMenu::popupEdit() | 143 | void KOEventPopupMenu::popupEdit() |
106 | { | 144 | { |
107 | if (mCurrentIncidence) emit editIncidenceSignal(mCurrentIncidence); | 145 | if (mCurrentIncidence) emit editIncidenceSignal(mCurrentIncidence); |
108 | } | 146 | } |
109 | 147 | ||
110 | void KOEventPopupMenu::popupDelete() | 148 | void KOEventPopupMenu::popupDelete() |
111 | { | 149 | { |
112 | if (mCurrentIncidence) emit deleteIncidenceSignal(mCurrentIncidence); | 150 | if (mCurrentIncidence) emit deleteIncidenceSignal(mCurrentIncidence); |
113 | } | 151 | } |
114 | void KOEventPopupMenu::popupClone() | 152 | void KOEventPopupMenu::popupClone() |
115 | { | 153 | { |
116 | if (mCurrentIncidence) emit cloneIncidenceSignal(mCurrentIncidence); | 154 | if (mCurrentIncidence) emit cloneIncidenceSignal(mCurrentIncidence); |
117 | } | 155 | } |
118 | void KOEventPopupMenu::popupCancel() | 156 | void KOEventPopupMenu::popupCancel() |
119 | { | 157 | { |
120 | if (mCurrentIncidence) emit cancelIncidenceSignal(mCurrentIncidence); | 158 | if (mCurrentIncidence) emit cancelIncidenceSignal(mCurrentIncidence); |
121 | } | 159 | } |
122 | void KOEventPopupMenu::popupMove() | 160 | void KOEventPopupMenu::popupMove() |
123 | { | 161 | { |
124 | if (mCurrentIncidence) emit moveIncidenceSignal(mCurrentIncidence); | 162 | if (mCurrentIncidence) emit moveIncidenceSignal(mCurrentIncidence); |
125 | } | 163 | } |
126 | 164 | ||
127 | void KOEventPopupMenu::popupBeam() | 165 | void KOEventPopupMenu::popupBeam() |
128 | { | 166 | { |
129 | if (mCurrentIncidence) emit beamIncidenceSignal(mCurrentIncidence); | 167 | if (mCurrentIncidence) emit beamIncidenceSignal(mCurrentIncidence); |
130 | } | 168 | } |