Code refactoring
Added documentation
This commit is contained in:
@@ -69,7 +69,7 @@ void InputsPanel::update()
|
||||
curDest++;
|
||||
AddInputLine(-curDest-1);
|
||||
}
|
||||
if (AddInputLine(i, md)) {
|
||||
if (AddInputLine(i)) {
|
||||
curDest++;
|
||||
}
|
||||
|
||||
@@ -84,13 +84,29 @@ void InputsPanel::update()
|
||||
}
|
||||
|
||||
|
||||
bool InputsPanel::AddInputLine(int dest, const ExpoData * md)
|
||||
/**
|
||||
@brief Creates new input line (list item) and adds it to the list widget
|
||||
|
||||
@note Input lines are now HTML formated because they use same widget as mixers.
|
||||
|
||||
@param[in] dest defines which input line to create.
|
||||
If dest < 0 then create empty input slot for input -dest ( dest=-6 -> Input05)
|
||||
if dest >=0 then create used input based on model input data from slot dest (dest=4 -> model expoData[4])
|
||||
|
||||
@retval true created input number is different from the previous list item
|
||||
false created input number is the same as previous list item
|
||||
*/
|
||||
bool InputsPanel::AddInputLine(int dest)
|
||||
{
|
||||
bool new_ch;
|
||||
QString str = getInputText(dest, &new_ch);
|
||||
QListWidgetItem *itm = new QListWidgetItem(str);
|
||||
QByteArray qba(1, (quint8)dest);
|
||||
if (md) qba.append((const char*)md, sizeof(ExpoData));
|
||||
if (dest >= 0) {
|
||||
//add input data
|
||||
ExpoData *md = &model.expoData[dest];
|
||||
qba.append((const char*)md, sizeof(ExpoData));
|
||||
}
|
||||
itm->setData(Qt::UserRole, qba);
|
||||
#if MIX_ROW_HEIGHT_INCREASE > 0
|
||||
if (new_ch && !firstLine) {
|
||||
@@ -105,6 +121,15 @@ bool InputsPanel::AddInputLine(int dest, const ExpoData * md)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@brief Returns HTML formated input representation
|
||||
|
||||
@param[in] dest defines which input line to create.
|
||||
If dest < 0 then create empty input slot for input -dest ( dest=-6 -> Input05)
|
||||
if dest >=0 then create used input based on model input data from slot dest (dest=4 -> model expoData[4])
|
||||
|
||||
@retval string input line in HTML
|
||||
*/
|
||||
QString InputsPanel::getInputText(int dest, bool * new_ch)
|
||||
{
|
||||
QString str;
|
||||
|
||||
@@ -44,7 +44,7 @@ class InputsPanel : public ModelPanel
|
||||
QList<int> createExpoListFromSelected();
|
||||
void setSelectedByExpoList(QList<int> list);
|
||||
void pasteExpoMimeData(const QMimeData * mimeData, int destIdx);
|
||||
bool AddInputLine(int dest, const ExpoData * md = 0);
|
||||
bool AddInputLine(int dest);
|
||||
QString getInputText(int dest, bool * new_ch);
|
||||
|
||||
};
|
||||
|
||||
@@ -10,7 +10,7 @@ MixersList::MixersList(QWidget *parent, bool expo) :
|
||||
setDragEnabled(true);
|
||||
setAcceptDrops(true);
|
||||
setDropIndicatorShown(true);
|
||||
setItemDelegate(new MixersDelegate(parent));
|
||||
setItemDelegate(new MixersDelegate(parent)); //set custom paint handler
|
||||
}
|
||||
|
||||
void MixersList::keyPressEvent(QKeyEvent *event)
|
||||
@@ -52,10 +52,11 @@ bool MixersList::dropMimeData( int index, const QMimeData * data, Qt::DropAction
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Paints our HTML formated list item text
|
||||
*/
|
||||
void MixersDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
{
|
||||
//Custom paint handler
|
||||
//we paint HTML formated text inside list item
|
||||
QStyleOptionViewItemV4 options = option;
|
||||
initStyleOption(&options, index);
|
||||
|
||||
@@ -83,11 +84,11 @@ void MixersDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
@brief Returns needed size for our HTML formated list item text
|
||||
*/
|
||||
QSize MixersDelegate::sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const
|
||||
{
|
||||
//custom size handler
|
||||
//returns needed size for each HTML formated list item
|
||||
QStyleOptionViewItemV4 options = option;
|
||||
initStyleOption(&options, index);
|
||||
|
||||
@@ -117,4 +118,4 @@ void MixersDelegate::SetupDocument(QTextDocument & doc, const QStyleOptionViewIt
|
||||
QTextFrameFormat tff = tf->frameFormat();
|
||||
tff.setMargin(0);
|
||||
tf->setFrameFormat(tff);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <QtGui>
|
||||
|
||||
|
||||
#define MIX_ROW_HEIGHT_INCREASE 8 //how much space is added above mixer row (for new channel), if 0 space adding is disabled
|
||||
#define MIX_ROW_HEIGHT_INCREASE 8 //how much space is added above mixer row (for new channel), if 0 space adding is disabled
|
||||
const int GroupHeaderRole = (Qt::UserRole+2); //defines new user role for list items. If value is > 0, then space is added before that item
|
||||
|
||||
class MixersList : public QListWidget
|
||||
@@ -28,6 +28,11 @@ class MixersList : public QListWidget
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
@brief Provides sizing and painting of items for our mixes and inputs lists
|
||||
|
||||
This class draws HTML formated strings into QListWidget class
|
||||
*/
|
||||
class MixersDelegate : public QStyledItemDelegate
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@@ -62,7 +62,7 @@ QString MixesPanel::getChannelLabel(int curDest)
|
||||
|
||||
void MixesPanel::update()
|
||||
{
|
||||
// curDest -> destination channel4
|
||||
// curDest -> destination channel
|
||||
// i -> mixer number
|
||||
QByteArray qba;
|
||||
MixerlistWidget->clear();
|
||||
@@ -74,16 +74,13 @@ void MixesPanel::update()
|
||||
for (i=0; i<firmware->getCapability(Mixes); i++) {
|
||||
MixData *md = &model.mixData[i];
|
||||
// qDebug() << "md->destCh: " << md->destCh;
|
||||
if (md->destCh==0 || md->destCh>outputs) {
|
||||
qDebug() << "WARNING: possible mixer corrupiton at i" << i << "destCh" << md->destCh;
|
||||
continue;
|
||||
}
|
||||
if (md->destCh==0 || md->destCh>outputs) continue;
|
||||
QString str = "";
|
||||
while (curDest < md->destCh-1) {
|
||||
curDest++;
|
||||
AddMixerLine(-curDest);
|
||||
}
|
||||
if (AddMixerLine(i, md)) {
|
||||
if (AddMixerLine(i)) {
|
||||
curDest++;
|
||||
}
|
||||
}
|
||||
@@ -94,13 +91,29 @@ void MixesPanel::update()
|
||||
}
|
||||
}
|
||||
|
||||
bool MixesPanel::AddMixerLine(int dest, const MixData * md)
|
||||
/**
|
||||
@brief Creates new mixer line (list item) and adds it to the list widget
|
||||
|
||||
@note Mixer lines are now HTML formated in order to support bold text.
|
||||
|
||||
@param[in] dest defines which mixer line to create.
|
||||
If dest < 0 then create empty channel slotr fo channel -dest ( dest=-2 -> CH2)
|
||||
if dest >=0 then create used channel based on model mix data from slot dest (dest=4 -> model mix[4])
|
||||
|
||||
@retval true destination channel is different from the previous list item
|
||||
false destination channle is the same as previous list item
|
||||
*/
|
||||
bool MixesPanel::AddMixerLine(int dest)
|
||||
{
|
||||
bool new_ch;
|
||||
QString str = getMixerText(dest, &new_ch);
|
||||
QListWidgetItem *itm = new QListWidgetItem(str);
|
||||
QByteArray qba(1, (quint8)dest);
|
||||
if (md) qba.append((const char*)md, sizeof(MixData));
|
||||
if (dest >= 0) {
|
||||
//add mix data
|
||||
MixData *md = &model.mixData[dest];
|
||||
qba.append((const char*)md, sizeof(MixData));
|
||||
}
|
||||
itm->setData(Qt::UserRole, qba);
|
||||
#if MIX_ROW_HEIGHT_INCREASE > 0
|
||||
//if ((new_ch && (dest > 0)) || (dest < -1)) {
|
||||
@@ -115,6 +128,15 @@ bool MixesPanel::AddMixerLine(int dest, const MixData * md)
|
||||
return new_ch;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Returns HTML formated mixer representation
|
||||
|
||||
@param[in] dest defines which mixer line to create.
|
||||
If dest < 0 then create empty channel slot for channel -dest ( dest=-2 -> CH2)
|
||||
if dest >=0 then create used channel based on model mix data from slot dest (dest=4 -> model mix[4])
|
||||
|
||||
@retval string mixer line in HTML
|
||||
*/
|
||||
QString MixesPanel::getMixerText(int dest, bool * new_ch)
|
||||
{
|
||||
QString str;
|
||||
@@ -339,7 +361,6 @@ void MixesPanel::mixersCopy()
|
||||
|
||||
void MixesPanel::pasteMixerMimeData(const QMimeData * mimeData, int destIdx)
|
||||
{
|
||||
qDebug() << "void MixesPanel::pasteMixerMimeData" << destIdx;
|
||||
if(mimeData->hasFormat("application/x-companion-mix")) {
|
||||
int idx; // mixer index
|
||||
int dch;
|
||||
@@ -352,7 +373,6 @@ void MixesPanel::pasteMixerMimeData(const QMimeData * mimeData, int destIdx)
|
||||
dch = model.mixData[idx].destCh;
|
||||
}
|
||||
|
||||
qDebug() << "void MixesPanel::pasteMixerMimeData() dch" << dch;
|
||||
QByteArray mxData = mimeData->data("application/x-companion-mix");
|
||||
|
||||
int i = 0;
|
||||
@@ -365,7 +385,6 @@ void MixesPanel::pasteMixerMimeData(const QMimeData * mimeData, int destIdx)
|
||||
MixData *md = &model.mixData[idx];
|
||||
memcpy(md,mxData.mid(i,sizeof(MixData)).constData(),sizeof(MixData));
|
||||
md->destCh = dch;
|
||||
qDebug() << "void MixesPanel::pasteMixerMimeData() dch1" << dch;
|
||||
i += sizeof(MixData);
|
||||
}
|
||||
|
||||
@@ -476,7 +495,7 @@ void MixesPanel::mixerlistWidget_customContextMenuRequested(QPoint pos)
|
||||
void MixesPanel::mimeMixerDropped(int index, const QMimeData *data, Qt::DropAction /*action*/)
|
||||
{
|
||||
int idx= MixerlistWidget->item(index > 0 ? index-1 : 0)->data(Qt::UserRole).toByteArray().at(0);
|
||||
qDebug() << "MixesPanel::mimeMixerDropped()" << index << data;
|
||||
//qDebug() << "MixesPanel::mimeMixerDropped()" << index << data;
|
||||
pasteMixerMimeData(data, idx);
|
||||
}
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ class MixesPanel : public ModelPanel
|
||||
QList<int> createMixListFromSelected();
|
||||
void setSelectedByMixList(QList<int> list);
|
||||
QString getChannelLabel(int curDest);
|
||||
bool AddMixerLine(int dest, const MixData * md = 0);
|
||||
bool AddMixerLine(int dest);
|
||||
QString getMixerText(int dest, bool * new_ch);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user