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 | |||
@@ -27,14 +27,15 @@ | |||
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()))); |
@@ -49,27 +50,66 @@ KOEventPopupMenu::KOEventPopupMenu() | |||
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. |
@@ -77,14 +117,12 @@ void KOEventPopupMenu::showIncidencePopup(Incidence *incidence) | |||
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) |