krita/ui

kis_cmb_idlist.cc

Go to the documentation of this file.
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 "widgets/kis_cmb_idlist.h"
00022 
00023 #include <klocale.h>
00024 #include <kis_debug.h>
00025 
00026 #include "KoID.h"
00027 
00028 
00029 KisCmbIDList::KisCmbIDList(QWidget * parent, const char * name)
00030         : KComboBox(parent)
00031 {
00032     setObjectName(name);
00033     setEditable(false);
00034     connect(this, SIGNAL(activated(int)), this, SLOT(slotIDActivated(int)));
00035     connect(this, SIGNAL(highlighted(int)), this, SLOT(slotIDHighlighted(int)));
00036 }
00037 
00038 KisCmbIDList::~KisCmbIDList()
00039 {
00040 }
00041 
00042 
00043 void KisCmbIDList::setIDList(const QList<KoID>  & list)
00044 {
00045     m_list = list;
00046     for (qint32 i = 0; i < m_list.count(); ++i) {
00047         addItem(m_list.at(i).name());
00048     }
00049 }
00050 
00051 
00052 KoID KisCmbIDList::currentItem() const
00053 {
00054     qint32 i = KComboBox::currentIndex();
00055     if (i > m_list.count() - 1) return KoID();
00056 
00057     return m_list[i];
00058 }
00059 
00060 void KisCmbIDList::setCurrent(const KoID id)
00061 {
00062     qint32 index = m_list.indexOf(id);
00063 
00064     if (index >= 0) {
00065         KComboBox::setCurrentIndex(index);
00066     } else {
00067         m_list.push_back(id);
00068         addItem(id.name());
00069         KComboBox::setCurrentIndex(m_list.count() - 1);
00070     }
00071 }
00072 
00073 void KisCmbIDList::setCurrent(const QString & s)
00074 {
00075     for (qint32 i = 0; i < m_list.count(); ++i) {
00076         if (m_list.at(i).id() == s) {
00077             KComboBox::setCurrentIndex(i);
00078             break;
00079         }
00080     }
00081 }
00082 
00083 void KisCmbIDList::slotIDActivated(int i)
00084 {
00085     if (i > m_list.count() - 1) return;
00086 
00087     emit activated(m_list[i]);
00088 
00089 }
00090 
00091 void KisCmbIDList::slotIDHighlighted(int i)
00092 {
00093     if (i > m_list.count() - 1) return;
00094 
00095     emit highlighted(m_list[i]);
00096 
00097 }
00098 
00099 #include "kis_cmb_idlist.moc"
00100