Add two signals to propagate the URLs when the buttons are clicked

This commit is contained in:
Luca Beltrame 2013-06-09 22:00:41 +02:00
commit 9373508bc3
2 changed files with 77 additions and 2 deletions

View file

@ -36,6 +36,7 @@
#include <KPushButton>
namespace Danbooru {
const int DanbooruPostDelegate::MARGIN = 5;
@ -73,6 +74,13 @@ namespace Danbooru {
m_downloadButton->resize(m_buttonSize, m_buttonSize);
m_viewButton->resize(m_buttonSize, m_buttonSize);
// Signal-slot connections
connect(m_viewButton, SIGNAL(clicked()), this,
SLOT(viewButtonClicked()));
connect(m_downloadButton, SIGNAL(clicked()), this,
SLOT(downloadButtonClicked()));
}
void DanbooruPostDelegate::paint(QPainter* painter,
@ -154,4 +162,41 @@ namespace Danbooru {
return m_itemView->indexAt(pos);
}
void DanbooruPostDelegate::downloadButtonClicked()
{
QModelIndex index = hoveredIndex();
if (!index.isValid()) {
return;
}
QVariant data = index.data(Qt::DisplayRole);
const DanbooruPost* post = data.value<DanbooruPost*>();
if (post) {
KUrl url = post->fileUrl();
Q_EMIT(postViewRequested(url));
}
}
void DanbooruPostDelegate::viewButtonClicked()
{
QModelIndex index = hoveredIndex();
if (!index.isValid()) {
return;
}
QVariant data = index.data(Qt::DisplayRole);
const DanbooruPost* post = data.value<DanbooruPost*>();
if (post) {
KUrl url = post->fileUrl();
Q_EMIT(postViewRequested(url));
}
}
} // namespace Danbooru