krita

kis_cmb_idlist.cc

00001 /*
00002  *  kis_cmb_idlist.cc - part of KImageShop/Krayon/Krita
00003  *
00004  *  Copyright (c) 2005 Boudewijn Rempt (boud@valdyas.org)
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  */
00020 
00021 #include <qcombobox.h>
00022 
00023 #include <klocale.h>
00024 #include <kdebug.h>
00025 
00026 #include "kis_id.h"
00027 #include "kis_cmb_idlist.h"
00028 
00029 KisCmbIDList::KisCmbIDList(QWidget * parent, const char * name)
00030     : super( false, parent, name )
00031 {
00032     connect(this, SIGNAL(activated(int)), this, SLOT(slotIDActivated(int)));
00033     connect(this, SIGNAL(highlighted(int)), this, SLOT(slotIDHighlighted(int)));
00034 }
00035 
00036 KisCmbIDList::~KisCmbIDList()
00037 {
00038 }
00039 
00040 
00041 void KisCmbIDList::setIDList(const KisIDList & list)
00042 {
00043     m_list = list;
00044     KisIDList::iterator it;
00045         for( it = m_list.begin(); it != m_list.end(); ++it )
00046         insertItem((*it).name());
00047 }
00048 
00049 
00050 KisID KisCmbIDList::currentItem() const
00051 {
00052     Q_UINT32 i = super::currentItem();
00053     if (i > m_list.count()) return KisID();
00054 
00055     return m_list[i];
00056 }
00057 
00058 void KisCmbIDList::setCurrent(const KisID id)
00059 {
00060     if (m_list.find(id) != m_list.end()) 
00061         super::setCurrentText(id.name());
00062     else {
00063         m_list.push_back(id);
00064         insertItem(id.name());
00065         super::setCurrentText(id.name());
00066     }
00067 }
00068 
00069 void KisCmbIDList::setCurrentText(const QString & s)
00070 {
00071     KisIDList::iterator it;
00072         for( it = m_list.begin(); it != m_list.end(); ++it )
00073         if ((*it).id() == s) {
00074             super::setCurrentText((*it).name());
00075         }
00076 }
00077 
00078 void KisCmbIDList::slotIDActivated(int i)
00079 {
00080     if ((uint)i > m_list.count()) return;
00081 
00082     emit activated(m_list[i]);
00083 
00084 }
00085 
00086 void KisCmbIDList::slotIDHighlighted(int i)
00087 {
00088     if ((uint)i > m_list.count()) return;
00089 
00090     emit highlighted(m_list[i]);
00091 
00092 }
00093 
00094 
00095 
00096 #include "kis_cmb_idlist.moc"
00097 
KDE Home | KDE Accessibility Home | Description of Access Keys