master
parent
3be17f267e
commit
e773095afb
@ -0,0 +1,41 @@
|
||||
#include "calbum.h"
|
||||
|
||||
|
||||
cAlbum::cAlbum(const QString& szAlbum, const QString &szLeadArtist) :
|
||||
m_szAlbum(szAlbum),
|
||||
m_szLeadArtist(szLeadArtist)
|
||||
{
|
||||
}
|
||||
|
||||
void cAlbum::setAlbum(const QString& szAlbum)
|
||||
{
|
||||
m_szAlbum = szAlbum;
|
||||
}
|
||||
|
||||
QString cAlbum::album()
|
||||
{
|
||||
return(m_szAlbum);
|
||||
}
|
||||
|
||||
void cAlbum::setLeadArtist(const QString& szLeadArtist)
|
||||
{
|
||||
m_szLeadArtist = szLeadArtist;
|
||||
}
|
||||
|
||||
QString cAlbum::leadArtist()
|
||||
{
|
||||
return(m_szLeadArtist);
|
||||
}
|
||||
|
||||
cAlbum* cAlbumList::add(const QString& szAlbum, const QString& szLeadArtist)
|
||||
{
|
||||
for(int x = 0;x < count();x++)
|
||||
{
|
||||
if(at(x)->album() == szAlbum && at(x)->leadArtist() == szLeadArtist)
|
||||
return(at(x));
|
||||
}
|
||||
|
||||
cAlbum* lpAlbumNew = new cAlbum(szAlbum, szLeadArtist);
|
||||
append(lpAlbumNew);
|
||||
return(lpAlbumNew);
|
||||
}
|
||||
@ -0,0 +1,34 @@
|
||||
#ifndef CALBUM_H
|
||||
#define CALBUM_H
|
||||
|
||||
|
||||
#include <QMetaType>
|
||||
#include <QString>
|
||||
#include <QList>
|
||||
|
||||
|
||||
class cAlbum
|
||||
{
|
||||
public:
|
||||
cAlbum(const QString& szAlbum, const QString& szLeadArtist);
|
||||
|
||||
void setAlbum(const QString& szAlbum);
|
||||
QString album();
|
||||
|
||||
void setLeadArtist(const QString& szLeadArtist);
|
||||
QString leadArtist();
|
||||
private:
|
||||
QString m_szAlbum;
|
||||
QString m_szLeadArtist;
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(cAlbum*)
|
||||
|
||||
class cAlbumList : public QList<cAlbum*>
|
||||
{
|
||||
public:
|
||||
cAlbum* add(const QString& szAlbum, const QString &szLeadArtist);
|
||||
};
|
||||
|
||||
|
||||
#endif // CALBUM_H
|
||||
@ -1,24 +1,52 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>cMainWindow</class>
|
||||
<widget class="QMainWindow" name="cMainWindow" >
|
||||
<property name="geometry" >
|
||||
<widget class="QMainWindow" name="cMainWindow">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
<width>1124</width>
|
||||
<height>682</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle" >
|
||||
<property name="windowTitle">
|
||||
<string>cMainWindow</string>
|
||||
</property>
|
||||
<widget class="QMenuBar" name="menuBar" />
|
||||
<widget class="QToolBar" name="mainToolBar" />
|
||||
<widget class="QWidget" name="centralWidget" />
|
||||
<widget class="QStatusBar" name="statusBar" />
|
||||
<widget class="QWidget" name="centralWidget">
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QSplitter" name="m_lpSplitter">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<widget class="QTreeView" name="m_lpMusicListOriginal"/>
|
||||
<widget class="QTreeView" name="m_lpMusicListNew"/>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QMenuBar" name="menuBar">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1124</width>
|
||||
<height>21</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QToolBar" name="mainToolBar">
|
||||
<attribute name="toolBarArea">
|
||||
<enum>TopToolBarArea</enum>
|
||||
</attribute>
|
||||
<attribute name="toolBarBreak">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusBar"/>
|
||||
</widget>
|
||||
<layoutDefault spacing="6" margin="11" />
|
||||
<pixmapfunction></pixmapfunction>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
||||
@ -0,0 +1,74 @@
|
||||
#include "cmusicviewitemdelegate.h"
|
||||
|
||||
#include <QPainter>
|
||||
#include <QTextDocument>
|
||||
#include <QAbstractTextDocumentLayout>
|
||||
#include <QAbstractItemModel>
|
||||
#include <QStandardItemModel>
|
||||
#include <QTreeView>
|
||||
|
||||
|
||||
void cMusicViewItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem & option, const QModelIndex &index) const
|
||||
{
|
||||
QStyleOptionViewItem options = option;
|
||||
initStyleOption(&options, index);
|
||||
|
||||
int iLevel = 0;
|
||||
QModelIndex index1 = index;
|
||||
|
||||
while(index1.parent().isValid())
|
||||
{
|
||||
iLevel++;
|
||||
index1 = index1.parent();
|
||||
}
|
||||
|
||||
QTreeView* lpTreeView = (QTreeView*)parent();
|
||||
int indentation = 20;
|
||||
if(lpTreeView)
|
||||
indentation = lpTreeView->indentation();
|
||||
|
||||
indentation *= iLevel;
|
||||
|
||||
painter->save();
|
||||
|
||||
QTextDocument doc;
|
||||
|
||||
doc.setHtml(QString("%1").arg(options.text));
|
||||
|
||||
options.text = "";
|
||||
options.widget->style()->drawControl(QStyle::CE_ItemViewItem, &options, painter);
|
||||
|
||||
QRect clip;
|
||||
|
||||
// shift text right to make icon visible
|
||||
if(index.column() == 1)
|
||||
{
|
||||
painter->translate(options.rect.left()+indentation, options.rect.top());
|
||||
clip = QRect(0, 0, options.rect.width()+indentation, options.rect.height());
|
||||
}
|
||||
else
|
||||
{
|
||||
painter->translate(options.rect.left(), options.rect.top());
|
||||
clip = QRect(0, 0, options.rect.width(), options.rect.height());
|
||||
}
|
||||
|
||||
painter->setClipRect(clip);
|
||||
|
||||
QAbstractTextDocumentLayout::PaintContext ctx;
|
||||
|
||||
ctx.clip = clip;
|
||||
doc.documentLayout()->draw(painter, ctx);
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
QSize cMusicViewItemDelegate::sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const
|
||||
{
|
||||
QStyleOptionViewItem options = option;
|
||||
initStyleOption(&options, index);
|
||||
|
||||
QTextDocument doc;
|
||||
doc.setHtml(options.text);
|
||||
doc.setTextWidth(options.rect.width());
|
||||
return QSize(doc.idealWidth(), doc.size().height());
|
||||
}
|
||||
@ -0,0 +1,17 @@
|
||||
#ifndef CMUSICVIEWITEMDELEGATE_H
|
||||
#define CMUSICVIEWITEMDELEGATE_H
|
||||
|
||||
|
||||
#include <QStyledItemDelegate>
|
||||
|
||||
|
||||
class cMusicViewItemDelegate : public QStyledItemDelegate
|
||||
{
|
||||
public:
|
||||
cMusicViewItemDelegate(QWidget *parent = 0) : QStyledItemDelegate(parent) {}
|
||||
protected:
|
||||
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||
};
|
||||
|
||||
#endif // CMUSICVIEWITEMDELEGATE_H
|
||||
Loading…
Reference in New Issue