Skip to content

Commit

Permalink
finished feature double click on Album (#253)
Browse files Browse the repository at this point in the history
* finished feature double click on Album. With these changes the labels for name and artist of a song are clickable and you can go directly with one click to the album or artist

* added forgotten files
  • Loading branch information
jojopet committed Jul 6, 2024
1 parent 62037fc commit d0151f1
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/view/context/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ target_sources(${PROJECT_NAME} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/smallcontent.cpp
${CMAKE_CURRENT_SOURCE_DIR}/title.cpp
${CMAKE_CURRENT_SOURCE_DIR}/titleinfo.cpp
${CMAKE_CURRENT_SOURCE_DIR}/view.cpp)
${CMAKE_CURRENT_SOURCE_DIR}/view.cpp
${CMAKE_CURRENT_SOURCE_DIR}/clickableLabel.cpp)
15 changes: 15 additions & 0 deletions src/view/context/clickableLabel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "clickableLabel.hpp"

ClickableLabel::ClickableLabel(QWidget* parent, Qt::WindowFlags f)
: QLabel(parent) {

}

ClickableLabel::~ClickableLabel() {}

void ClickableLabel::mousePressEvent(QMouseEvent* event) {
if(event->button() == Qt::LeftButton){
emit clicked();
}
QLabel::mousePressEvent(event);
}
24 changes: 24 additions & 0 deletions src/view/context/clickableLabel.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#ifndef CLICKABLELABEL_H
#define CLICKABLELABEL_H

#include <QLabel>
#include <QWidget>
#include <Qt>
#include <QMouseEvent>

class ClickableLabel : public QLabel {
Q_OBJECT

public:
explicit ClickableLabel(QWidget* parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags());
~ClickableLabel();

signals:
void clicked();

protected:
void mousePressEvent(QMouseEvent* event) override;

};

#endif // CLICKABLELABEL_H
26 changes: 25 additions & 1 deletion src/view/context/nowplaying.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#include "nowplaying.hpp"
#include "clickableLabel.hpp"
#include <QMenu>
#include <QGraphicsDropShadowEffect>

#include "mainwindow.hpp"


Context::NowPlaying::NowPlaying(QWidget *parent)
: QWidget(parent)
{
Expand All @@ -23,17 +28,21 @@ void Context::NowPlaying::setTrack(const lib::spt::track &track)
{
if (name != nullptr)
{
track_id = track.id;
album_id = track.album.id;
name->setVisible(true);
setText(name, track.name);
}

if (artist != nullptr)
{
artist_id = track.artists[0].id;
const auto names = lib::spt::entity::combine_names(track.artists);
setText(artist, names);
}
}


void Context::NowPlaying::setNoPlaying()
{
if (name != nullptr)
Expand All @@ -49,7 +58,7 @@ void Context::NowPlaying::setNoPlaying()

auto Context::NowPlaying::newLabel(float scale) -> QLabel *
{
auto *label = new QLabel(this);
auto *label = new ClickableLabel(this);
label->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed);

auto font = label->font();
Expand All @@ -58,9 +67,15 @@ auto Context::NowPlaying::newLabel(float scale) -> QLabel *
label->setFont(font);

layout->addWidget(label);

connect(label, &ClickableLabel::clicked, this, [this, label](){
handleLabelClick(label);
});
return label;
}



void Context::NowPlaying::setText(QLabel *label, const std::string &text)
{
auto qText = QString::fromStdString(text);
Expand Down Expand Up @@ -128,3 +143,12 @@ void Context::NowPlaying::onMenu(const QPoint &pos)

menu->popup(mapToGlobal(pos));
}

void Context::NowPlaying::handleLabelClick(QLabel *clickedLabel){
if(clickedLabel == artist){
MainWindow::find(parentWidget())->openArtist(artist_id);
}
else if(clickedLabel == name){
MainWindow::find(parentWidget())->loadAlbum(album_id, track_id);
}
}
12 changes: 12 additions & 0 deletions src/view/context/nowplaying.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
#include <QLabel>
#include <QVBoxLayout>

#include "clickableLabel.hpp"
#include <string>


namespace Context
{
class NowPlaying: public QWidget
Expand All @@ -21,6 +25,10 @@ namespace Context
auto getTextShadow() const -> bool;
void setTextShadow(bool value);

std::string artist_id;
std::string album_id;
std::string track_id;

private:
static constexpr float nameScale = 1.1F;
static constexpr float artistScale = 0.9F;
Expand All @@ -37,5 +45,9 @@ namespace Context
static void removeTextShadow(QLabel *label);

void onMenu(const QPoint &pos);

public slots:
void handleLabelClick(QLabel *clickedLabel);
};
}

0 comments on commit d0151f1

Please sign in to comment.