Mixxx

/home/maxime/Projets/Mixxx/1.10/mixxx/src/controlgroupdelegate.cpp

Go to the documentation of this file.
00001 /*
00002  * controlgroupdelegate.cpp
00003  *
00004  *  Created on: 18-Mar-2009
00005  *      Author: Albert Santoni
00006  */
00007 
00008 #include <QtCore>
00009 #include <QtGui>
00010 #include "configobject.h"
00011 #include "midi/midiinputmappingtablemodel.h" //Need this to know MIDIINPUTTABLEINDEX_CONTROLOBJECTVALUE
00012 #include "controlvaluedelegate.h"
00013 #include "controlgroupdelegate.h"
00014 
00016 QStringList ControlGroupDelegate::m_controlGroups;
00017 
00018 ControlGroupDelegate::ControlGroupDelegate(QObject *parent)
00019          : QItemDelegate(parent)
00020 {
00021     //This QList is static, so it's shared across all objects of this class. We only want to
00022     //fill it once then...
00023     if (m_controlGroups.isEmpty())
00024     {
00025         m_controlGroups.append(CONTROLGROUP_CHANNEL1_STRING);
00026         m_controlGroups.append(CONTROLGROUP_CHANNEL2_STRING);
00027         m_controlGroups.append(CONTROLGROUP_SAMPLER1_STRING);
00028         m_controlGroups.append(CONTROLGROUP_SAMPLER2_STRING);
00029         m_controlGroups.append(CONTROLGROUP_SAMPLER3_STRING);
00030         m_controlGroups.append(CONTROLGROUP_SAMPLER4_STRING);
00031         m_controlGroups.append(CONTROLGROUP_MASTER_STRING);
00032         m_controlGroups.append(CONTROLGROUP_PLAYLIST_STRING);
00033         m_controlGroups.append(CONTROLGROUP_FLANGER_STRING);
00034         m_controlGroups.append(CONTROLGROUP_MICROPHONE_STRING);
00035     }
00036 }
00037 
00038 void ControlGroupDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
00039                          const QModelIndex &index) const
00040 {
00041     if (index.data().canConvert<QString>()) {
00042         QString value = index.data().value<QString>();
00043 
00044         if (option.state & QStyle::State_Selected)
00045             painter->fillRect(option.rect, option.palette.highlight());
00046 
00047         //starRating.paint(painter, option.rect, option.palette,
00048         //                 StarRating::ReadOnly);
00049 
00050         QString text;
00051         text = value;
00052 
00053         painter->drawText(option.rect, text, QTextOption(Qt::AlignCenter));
00054         //Note that Qt::AlignCenter does both vertical and horizontal alignment.
00055     } else {
00056         QItemDelegate::paint(painter, option, index);
00057     }
00058 }
00059 
00060 QWidget *ControlGroupDelegate::createEditor(QWidget *parent,
00061         const QStyleOptionViewItem &/* option */,
00062         const QModelIndex &/* index */) const
00063 {
00064     QComboBox *editor = new QComboBox(parent);
00065     editor->addItem(CONTROLGROUP_CHANNEL1_STRING);
00066     editor->addItem(CONTROLGROUP_CHANNEL2_STRING);
00067     editor->addItem(CONTROLGROUP_SAMPLER1_STRING);
00068     editor->addItem(CONTROLGROUP_SAMPLER2_STRING);
00069     editor->addItem(CONTROLGROUP_SAMPLER3_STRING);
00070     editor->addItem(CONTROLGROUP_SAMPLER4_STRING);
00071     editor->addItem(CONTROLGROUP_MASTER_STRING);
00072     editor->addItem(CONTROLGROUP_PLAYLIST_STRING);
00073     editor->addItem(CONTROLGROUP_FLANGER_STRING);
00074     editor->addItem(CONTROLGROUP_MICROPHONE_STRING);
00075 
00076     return editor;
00077 }
00078 
00079 void ControlGroupDelegate::setEditorData(QWidget *editor,
00080                                     const QModelIndex &index) const
00081 {
00082     QString value = index.model()->data(index, Qt::EditRole).toString();
00083 
00084     QComboBox *comboBox = static_cast<QComboBox*>(editor);
00085     comboBox->setCurrentIndex(comboBox->findText(value));
00086 }
00087 
00088 void ControlGroupDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
00089                                     const QModelIndex &index) const
00090 {
00091     QString midiType = 0;
00092     QComboBox *comboBox = static_cast<QComboBox*>(editor);
00093     //comboBox->interpretText();
00094 
00095     //Get the text from the combobox and shoot it into the data model.
00096     QString group = comboBox->currentText();
00097 
00098     model->setData(index, group, Qt::EditRole);
00099 
00100     //Verify that the ControlValue in the next column is valid for the
00101     //newly selected ControlGroup. For example, switching from "[Channel1]"
00102     //to "[Master]" means that a ControlValue of "play" is no longer valid.
00103     //If it isn't, then blank that column's value.
00104     QModelIndex nextDoor = index.sibling(index.row(), MIDIINPUTTABLEINDEX_CONTROLOBJECTVALUE);
00105     ControlValueDelegate::verifyControlValueValidity(group, model, nextDoor);
00106 }
00107 
00108 void ControlGroupDelegate::updateEditorGeometry(QWidget *editor,
00109                                            const QStyleOptionViewItem &option,
00110                                            const QModelIndex &/* index */) const
00111 {
00112     editor->setGeometry(option.rect);
00113 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines