krita/ui
kis_cmb_composite.ccGo to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "widgets/kis_cmb_composite.h"
00022
00023 #include <QItemDelegate>
00024
00025 #include <klocale.h>
00026 #include <kis_debug.h>
00027 #include <KoCompositeOp.h>
00028 #include "../kis_composite_ops_model.h"
00029 #include <KCategorizedSortFilterProxyModel>
00030 #include <kis_categorized_item_delegate.h>
00031
00032 KisCmbComposite::KisCmbComposite(QWidget * parent, const char * name)
00033 : KComboBox(parent), m_lastModel(0), m_sortModel(0)
00034 {
00035 setObjectName(name);
00036 setEditable(false);
00037 connect(this, SIGNAL(activated(int)), this, SLOT(slotOpActivated(int)));
00038 connect(this, SIGNAL(highlighted(int)), this, SLOT(slotOpHighlighted(int)));
00039 setItemDelegate(new KisCategorizedItemDelegate(new QItemDelegate));
00040 m_sortModel = new KCategorizedSortFilterProxyModel;
00041 m_sortModel->setSortRole(KisCompositeOpsModel::CompositeOpSortRole);
00042 m_sortModel->setCategorizedModel(true);
00043 setModel(m_sortModel);
00044 }
00045
00046 KisCmbComposite::~KisCmbComposite()
00047 {
00048 }
00049
00050 void KisCmbComposite::setCompositeOpList(const QList<KoCompositeOp*> & list)
00051 {
00052 KisCompositeOpsModel* model = new KisCompositeOpsModel(list);
00053 m_sortModel->setSourceModel(model);
00054 m_sortModel->sort(0);
00055
00056 delete m_lastModel;
00057 m_lastModel = model;
00058 }
00059
00060 const QString& KisCmbComposite::itemAt(int idx) const
00061 {
00062 return m_lastModel->itemAt(m_sortModel->mapToSource(m_sortModel->index(idx, 0)));
00063 }
00064
00065 const QString& KisCmbComposite::currentItem() const
00066 {
00067 return itemAt(currentIndex());
00068 }
00069
00070 void KisCmbComposite::setCurrent(const KoCompositeOp* op)
00071 {
00072 QModelIndex index = m_sortModel->mapFromSource(m_lastModel->indexOf(op));
00073 if (index.isValid()) {
00074 KComboBox::setCurrentIndex(index.row());
00075 }
00076 }
00077
00078 void KisCmbComposite::setCurrent(const QString & s)
00079 {
00080 QModelIndex index = m_sortModel->mapFromSource(m_lastModel->indexOf(s));
00081 if (index.isValid()) {
00082 KComboBox::setCurrentIndex(index.row());
00083 }
00084 }
00085
00086 void KisCmbComposite::slotOpActivated(int i)
00087 {
00088 if (i >= m_lastModel->rowCount()) return;
00089
00090 emit activated(itemAt(i));
00091 }
00092
00093 void KisCmbComposite::slotOpHighlighted(int i)
00094 {
00095 if (i >= m_lastModel->rowCount()) return;
00096
00097 emit activated(itemAt(i));
00098 }
00099
00100
00101 #include "kis_cmb_composite.moc"
00102
|