Add two signals to propagate the URLs when the buttons are clicked
This commit is contained in:
parent
ad89dd5db9
commit
9373508bc3
2 changed files with 77 additions and 2 deletions
|
@ -36,6 +36,7 @@
|
||||||
|
|
||||||
#include <KPushButton>
|
#include <KPushButton>
|
||||||
|
|
||||||
|
|
||||||
namespace Danbooru {
|
namespace Danbooru {
|
||||||
|
|
||||||
const int DanbooruPostDelegate::MARGIN = 5;
|
const int DanbooruPostDelegate::MARGIN = 5;
|
||||||
|
@ -73,6 +74,13 @@ namespace Danbooru {
|
||||||
m_downloadButton->resize(m_buttonSize, m_buttonSize);
|
m_downloadButton->resize(m_buttonSize, m_buttonSize);
|
||||||
m_viewButton->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,
|
void DanbooruPostDelegate::paint(QPainter* painter,
|
||||||
|
@ -154,4 +162,41 @@ namespace Danbooru {
|
||||||
return m_itemView->indexAt(pos);
|
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
|
} // namespace Danbooru
|
||||||
|
|
|
@ -31,22 +31,27 @@
|
||||||
|
|
||||||
#include <QStyledItemDelegate>
|
#include <QStyledItemDelegate>
|
||||||
|
|
||||||
|
#include <KUrl>
|
||||||
|
|
||||||
class QListView;
|
class QListView;
|
||||||
class QPainter;
|
class QPainter;
|
||||||
class KPushButton;
|
class KPushButton;
|
||||||
|
|
||||||
|
|
||||||
namespace Danbooru {
|
namespace Danbooru {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Specific delegate for Danbooru items.
|
* @brief Specific delegate for Danbooru items.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
class DanbooruPost;
|
||||||
|
|
||||||
class DanbooruPostDelegate : public QStyledItemDelegate
|
class DanbooruPostDelegate : public QStyledItemDelegate
|
||||||
{
|
{
|
||||||
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DanbooruPostDelegate(QListView* itemView);
|
DanbooruPostDelegate(QListView* itemView);
|
||||||
|
|
||||||
|
@ -57,7 +62,6 @@ namespace Danbooru {
|
||||||
|
|
||||||
QModelIndex hoveredIndex() const;
|
QModelIndex hoveredIndex() const;
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
QListView* m_itemView;
|
QListView* m_itemView;
|
||||||
|
@ -70,6 +74,32 @@ namespace Danbooru {
|
||||||
|
|
||||||
static const int MARGIN;
|
static const int MARGIN;
|
||||||
|
|
||||||
|
Q_SIGNALS:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Emitted when the view button is clicked.
|
||||||
|
*
|
||||||
|
* @param postUrl the URL to the full picture.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void postViewRequested(KUrl postUrl);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Emitted when the download button is clicked.
|
||||||
|
*
|
||||||
|
* @param postUrl the URL to the full picture.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void postDownloadRequested(KUrl postUrl);
|
||||||
|
|
||||||
|
|
||||||
|
private Q_SLOTS:
|
||||||
|
void viewButtonClicked();
|
||||||
|
void downloadButtonClicked();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Danbooru
|
} // namespace Danbooru
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue