oopapidocs  2.0
metadatawidget.cpp
00001 #include <QDataWidgetMapper>
00002 #include <QDialogButtonBox>
00003 #include "metadataobject.h"
00004 #include "metadatawidget.h"
00005 #include "preference.h"
00006 
00007 
00008 QTextStream cout(stdout);
00009 
00010 MetaDataWidget::MetaDataWidget(QWidget* parent) : QWidget(parent) {
00011     Preference pref;
00012 
00013     setupUi(this);
00014     m_model = new MetaDataObject(this);
00015 
00016     connect(buttonBox, SIGNAL(clicked ( QAbstractButton *  )),
00017         this, SLOT(processButton( QAbstractButton *  )));
00018 
00019     // Type-specific customizations here
00020     preferenceCombo->addItems(pref.names());
00021     QStringList props = m_model->propertyNames();
00022 
00023     // We are not using this yet...
00024     m_Mapper = new QDataWidgetMapper(this);
00025 
00026     m_Mapper->addMapping(genreLineEdit, props.indexOf("Genre") );
00027     m_Mapper->addMapping(commentLineEdit, props.indexOf("Comment"));
00028     m_Mapper->addMapping(titleLineEdit, props.indexOf("TrackTitle"));
00029     m_Mapper->addMapping(albumLineEdit, props.indexOf("AlbumTitle"));
00030     m_Mapper->addMapping(trackSpinBox, props.indexOf("TrackNumber"));
00031     m_Mapper->addMapping(preferenceCombo, props.indexOf("Preference"));
00032     m_Mapper->addMapping(artistLineEdit, props.indexOf("Artist"));
00033     m_Mapper->addMapping(timeDisplay, props.indexOf("TrackTime"));
00034 
00035     // connect(previousButton, SIGNAL(clicked()), m_Mapper, SLOT(toPrevious()));
00036     // connect(nextButton, SIGNAL(clicked()), m_Mapper, SLOT(toNext()));
00037     // connect(spinBox, SIGNAL(valueChanged(int)), m_Mapper, SLOT(setCurrentIndex(int)));
00038     // connect(m_Mapper, SIGNAL(currentIndexChanged(int)), spinBox, SLOT(setValue(int)));
00039 
00040     connect(buttonBox, SIGNAL(accepted()), this, SLOT(submit()));
00041     connect(buttonBox, SIGNAL(rejected()), this, SLOT(revert()));
00042 
00043 }
00044 
00045 
00046 MetaDataObject* MetaDataWidget::model() const {
00047     return m_model;
00048 }
00049 
00050 void MetaDataWidget::display(const MetaDataValue &mdv) {
00051     *m_model = mdv;
00052     revert();
00053 
00054 
00055 }
00056 
00057 void MetaDataWidget::processButton ( QAbstractButton * button ) {
00058         QDialogButtonBox::ButtonRole role = buttonBox->buttonRole(button);
00059         cout << role << endl;
00060 }
00061 
00062 void MetaDataWidget::clear() {
00063 /*      int rows = m_Model->rowCount();
00064         m_Model->removeRows(0, rows); */
00065 }
00066 
00067 void MetaDataWidget::revert() {
00068         m_Mapper->revert();
00069     artistLineEdit->setText(m_model->artist());
00070     commentLineEdit->setText(m_model->comment());
00071     titleLineEdit->setText(m_model->trackTitle());
00072     albumLineEdit->setText(m_model->albumTitle());
00073     trackSpinBox->setValue(m_model->trackNumber().toInt());
00074     preferenceCombo->setCurrentIndex(m_model->preference().intValue());
00075     timeDisplay->setTime(m_model->trackTime());
00076     genreLineEdit->setText(m_model->genre());
00077 
00078     QImage img = m_model->image();
00079     if (!img.isNull()) {
00080         QPixmap pm = QPixmap::fromImage(img);
00081         imageLabel->setPixmap(pm);
00082     }
00083         cout << "revert" << endl;
00084 }
00085 
00086 void MetaDataWidget::submit() {
00087         m_Mapper->submit();
00088         cout << "submit" << endl;
00089 }
 All Classes Namespaces Functions Enumerations