00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "categorymenu.h"
00022 #include "backend/categories.h"
00023 #include "categoryselect.h"
00024
00054 CategoryMenu::CategoryMenu( const QString &n, bool ig = TRUE,
00055 QWidget *parent, const char *name ) :
00056 QPopupMenu(parent, name),
00057 appName(n),
00058 includeGlobal(ig)
00059 {
00060 currentMid = 1;
00061 reload();
00062 connect(this, SIGNAL(activated(int)), this, SLOT(mapMenuId(int)));
00063 }
00064
00068 CategoryMenu::~CategoryMenu( )
00069 {
00070 }
00071
00075 void CategoryMenu::reload()
00076 {
00077 clear();
00078 Categories c;
00079
00080 c.load(categoryFileName());
00081
00082 QStringList sl = c.labels(appName, includeGlobal);
00083 int mid = 1;
00084
00085 insertItem(tr("All"), mid);
00086 mid++;
00087 insertItem(tr("Unfiled"), mid);
00088 mid++;
00089
00090 for (QStringList::Iterator it = sl.begin();
00091 it != sl.end(); ++it ) {
00092 int cid = c.id(appName, *it);
00093 insertItem(*it, mid);
00094 menuToId.insert(mid, cid);
00095 idToMenu.insert(cid, mid);
00096 mid++;
00097 }
00098
00099 setItemChecked(currentMid, TRUE );
00100 }
00101
00105 void CategoryMenu::mapMenuId(int id)
00106 {
00107 if (id == currentMid)
00108 return;
00109 setItemChecked( currentMid, FALSE );
00110 setItemChecked( id, TRUE );
00111 currentMid = id;
00112
00113 emit categoryChange();
00114 }
00115
00121 bool CategoryMenu::isSelected(const QArray<int> &cUids) const
00122 {
00123 if (currentMid == 1)
00124 return TRUE;
00125
00126 if (currentMid == 2 && cUids.count() == 0)
00127 return TRUE;
00128
00129 if (cUids.contains(menuToId[currentMid]))
00130 return TRUE;
00131
00132 return FALSE;
00133 }
00134
00138 void CategoryMenu::setCurrentCategory( int newCatUid )
00139 {
00140 if (!idToMenu.contains(newCatUid))
00141 return;
00142
00143 mapMenuId(idToMenu[newCatUid]);
00144 }
00145
00149 void CategoryMenu::setCurrentCategoryAll( )
00150 {
00151 mapMenuId(1);
00152 }
00153
00157 void CategoryMenu::setCurrentCategoryUnfiled( )
00158 {
00159 mapMenuId(2);
00160 }