Mixxx

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

Go to the documentation of this file.
00001 /***************************************************************************
00002 *                                                                         *
00003 *   This program is free software; you can redistribute it and/or modify  *
00004 *   it under the terms of the GNU General Public License as published by  *
00005 *   the Free Software Foundation; either version 2 of the License, or     *
00006 *   (at your option) any later version.                                   *
00007 *                                                                         *
00008 ***************************************************************************/
00009 
00010 #include <QtCore>
00011 #include <QtGui>
00012 
00013 #include "ladspaview.h"
00014 #include "ladspa/ladspapresetmanager.h"
00015 #include "ladspa/ladspapresetinstance.h"
00016 #include "ladspa/ladspapresetslot.h"
00017 
00018 #include "widget/wknob.h"
00019 #include "widget/wskincolor.h"
00020 #include "widget/wpixmapstore.h"
00021 
00022 LADSPAView::LADSPAView(QWidget * parent) : QWidget(parent)
00023 {
00024     setObjectName("LADSPA");
00025     m_pGridLayout = new QGridLayout();
00026     this->setLayout(m_pGridLayout);
00027 
00028     QDomDocument skin("LADSPASkin");
00029     QFile file(WWidget::getPath("ladspa_skin.xml"));
00030     if (!file.open(IO_ReadOnly))
00031     {
00032         qDebug() << "Could not open skin definition file: " << file.fileName();
00033     }
00034     if (!skin.setContent(&file))
00035     {
00036         qDebug() << "Error parsing skin definition file: " << file.fileName();
00037     }
00038     file.close();
00039     QDomElement docElement = skin.documentElement();
00040 
00041     QDomElement bgElement = docElement.firstChildElement("Background");
00042     QString filename = bgElement.firstChildElement("Path").text();
00043     QPixmap *background = WPixmapStore::getPixmapNoCache(WWidget::getPath(filename));
00044     //QLabel *bg = new QLabel(this);
00045 
00046     //bg->move(0, 0);
00047     //bg->setPixmap(*background);
00048     //bg->lower();
00049     //this->setFixedSize(background->width(), background->height());
00050     //parent->setMinimumSize(background->width(), background->height());
00051     
00052     QDomElement bgColorNode = docElement.firstChildElement("BgColor");
00053     QDomElement fgColorNode = docElement.firstChildElement("FgColor");
00054 
00055     QPalette palette;
00056     QColor c(0,0,0);
00057     c.setNamedColor(bgColorNode.text());
00058     palette.setBrush(QPalette::Window, WSkinColor::getCorrectColor(c));
00059     QColor c2(255,255,255);
00060     c2.setNamedColor(fgColorNode.text());
00061     palette.setBrush(foregroundRole(), WSkinColor::getCorrectColor(c2));
00062     setBackgroundRole(QPalette::Window);
00063     setPalette(palette);
00064     setAutoFillBackground(true);
00065 
00066     palette.setColor(QPalette::Base, WSkinColor::getCorrectColor(c));
00067     palette.setColor(QPalette::Text, WSkinColor::getCorrectColor(c2));
00068 
00069     m_pPresetList = new QListWidget(this);
00070     m_pPresetList->setDragEnabled(true);
00071 
00072 
00073     QDomElement presetListElement = docElement.firstChildElement("PresetList");
00074 
00075     QDomElement posElement = presetListElement.firstChildElement("Pos");
00076     QString pos = posElement.text();
00077     int x = pos.left(pos.indexOf(",")).toInt();
00078     int y = pos.mid(pos.indexOf(",") + 1).toInt();
00079     if (x < 0)
00080     {
00081         x = this->width() + x;
00082     }
00083     if (y < 0)
00084     {
00085         y = this->height() + y;
00086     }
00087     //m_pPresetList->move(x, y);
00088 
00089     QDomElement sizeElement = presetListElement.firstChildElement("Size");
00090     QString size = sizeElement.text();
00091     int width = size.left(size.indexOf(",")).toInt();
00092     int height = size.mid(size.indexOf(",") + 1).toInt();
00093     if (width <= 0)
00094     {
00095         width = this->width() + width;
00096     }
00097     if (height <= 0)
00098     {
00099         height = this->height() + height;
00100     }    
00101     
00102     //m_pPresetList->resize(width, height);
00103     m_pPresetList->setMinimumSize(65, 200);
00104     m_pPresetList->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::MinimumExpanding);
00105     
00106     
00107     m_pPresetManager = new LADSPAPresetManager();
00108 
00109     for (unsigned int i = 0; i < m_pPresetManager->getPresetCount(); i++)
00110     {
00111         LADSPAPreset *preset = m_pPresetManager->getPreset(i);
00112         if (preset->isValid())
00113             m_pPresetList->addItem(preset->getName());
00114         else
00115             m_pPresetList->addItem("-" + preset->getName());        
00116     }
00117 
00118     m_pSlotTable = new QWidget(this);
00119     
00120     QDomElement slotTableElement = docElement.firstChildElement("SlotTable");
00121     
00122     posElement = slotTableElement.firstChildElement("Pos");
00123     pos = posElement.text();
00124     x = pos.left(pos.indexOf(",")).toInt();
00125     y = pos.mid(pos.indexOf(",") + 1).toInt();
00126     if (x < 0)
00127     {
00128         x = this->width() + x;
00129     }
00130     if (y < 0)
00131     {
00132         y = this->height() + y;
00133     }
00134     m_pSlotTable->move(x, y);
00135 
00136     sizeElement = slotTableElement.firstChildElement("Size");
00137     size = sizeElement.text();
00138     width = size.left(size.indexOf(",")).toInt();
00139     height = size.mid(size.indexOf(",") + 1).toInt();
00140     if (width <= 0)
00141     {
00142         width = this->width() + width;
00143     }
00144     if (height <= 0)
00145     {
00146         height = this->height() + height;
00147     }    
00148     //m_pSlotTable->resize(width, height);
00149     m_pSlotTable->setMinimumSize(400, 200);
00150     m_pSlotTable->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
00151     m_pSlotTable->show();
00152 
00153     QDomElement slotsElement = slotTableElement.firstChildElement("Slots");
00154     int numberOfSlots = slotsElement.text().toInt();
00155 
00156     QDomElement slotElement = slotTableElement.firstChildElement("Slot");
00157     for (int i = 0; i < numberOfSlots; i++)
00158     {
00159         LADSPAPresetSlot *p = new LADSPAPresetSlot(m_pSlotTable, slotElement, i, m_pPresetManager, palette);
00160         p->show();
00161     }
00162 
00163     m_pPresetList->updateGeometry(); //Notify Qt that the preset list has changed.
00164     m_pPresetList->setBackgroundRole(QPalette::Window);
00165     m_pPresetList->setPalette(palette);
00166     m_pPresetList->setAutoFillBackground(true);
00167     //parent->setPalette(palette);
00168 
00169     m_pGridLayout->addWidget(m_pPresetList, 0, 0);//,   //row 0, col 0
00170                                             //1, 1);  //span 1 row, span 1 col
00171     m_pGridLayout->addWidget(m_pSlotTable, 0, 1);//,   //row 0, col 1
00172                                            //1, 2);  //span 1 row, span 2 cols
00173 }
00174 
00175 LADSPAView::~LADSPAView()
00176 {
00177     delete m_pGridLayout;
00178 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines