Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

categorymenu.cpp

Go to the documentation of this file.
00001 /**********************************************************************
00002 ** Copyright (C) 2001 Trolltech AS.  All rights reserved.
00003 **
00004 ** This file is part of Qtopia Environment.
00005 **
00006 ** This file may be distributed and/or modified under the terms of the
00007 ** GNU General Public License version 2 as published by the Free Software
00008 ** Foundation and appearing in the file LICENSE.GPL included in the
00009 ** packaging of this file.
00010 **
00011 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013 **
00014 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00015 **
00016 ** Contact info@trolltech.com if any conditions of this licensing are
00017 ** not clear to you.
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 }

Generated on Sat Nov 5 16:16:34 2005 for OPIE by  doxygen 1.4.2