Skip to content
/ mixxx Public
forked from mixxxdj/mixxx

Commit

Permalink
Merge branch 'star-co' of https://github.com/ronso0/mixxx into qopeng…
Browse files Browse the repository at this point in the history
…lwidget
  • Loading branch information
daschuer committed Feb 24, 2019
2 parents 4de038f + 0dba444 commit bd90b75
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/controllers/controlpickermenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,20 @@ ControlPickerMenu::ControlPickerMenu(QWidget* pParent)
addDeckControl("waveform_zoom", tr("Waveform Zoom"), tr("Waveform zoom"), guiMenu);
addDeckControl("waveform_zoom_down", tr("Waveform Zoom In"), tr("Zoom waveform in"), guiMenu);
addDeckControl("waveform_zoom_up", tr("Waveform Zoom Out"), tr("Zoom waveform out"), guiMenu);

// Controls to change a deck's star rating
QString starsUpTitle = tr("Star Rating Up");
QString starsUpDescription = tr("Increase the track rating by one star");
QString starsDownTitle = tr("Star Rating Down");
QString starsDownDescription = tr("Decrease the track rating by one star");
for (int i = 1; i <= iNumDecks; ++i) {
addControl(QString("[Deck%1]").arg(i), "stars_up",
QString("%1: %2").arg(m_deckStr.arg(i), starsUpTitle),
QString("%1: %2").arg(m_deckStr.arg(i), starsUpDescription), guiMenu);
addControl(QString("[Deck%1]").arg(i), "stars_down",
QString("%1: %2").arg(m_deckStr.arg(i), starsDownTitle),
QString("%1: %2").arg(m_deckStr.arg(i), starsDownDescription), guiMenu);
}
}

ControlPickerMenu::~ControlPickerMenu() {
Expand Down
14 changes: 13 additions & 1 deletion src/library/starrating.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,26 @@
#include "library/starrating.h"
#include "util/math.h"

// Magic number? Explain what this factor affects and how
const int PaintingScaleFactor = 15;

StarRating::StarRating(int starCount, int maxStarCount)
: m_myStarCount(starCount),
m_myMaxStarCount(maxStarCount) {
// 1st star cusp at 0° of the unit circle whose center is shifted to adapt the 0,0-based paint area
m_starPolygon << QPointF(1.0, 0.5);
for (int i = 1; i < 5; ++i)
for (int i = 1; i < 5; ++i) {
// add QPointF 2-5 to polygon point array, equally distributed on a circumference.
// To create a star (not a pentagon) we need to connect every second point.
//
// understand those equations
m_starPolygon << QPointF(0.5 + 0.5 * cos(0.8 * i * 3.14), 0.5 + 0.5 * sin(0.8 * i * 3.14));
float QPointFx = 0.5 + 0.5 * cos(0.8 * i * 3.14);
float QPointFy = 0.5 + 0.5 * sin(0.8 * i * 3.14);
// qDebug() << "Debug: star point #" << i << ": " << QPointFx << ", " << QPointFy;
}
// creates 5 points for a tiny diamond/rhombe (square turned by 45°)
// why do we need 5 cusps here? 4 should suffice as the polygon is closed automatically for the star above..
m_diamondPolygon << QPointF(0.4, 0.5) << QPointF(0.5, 0.4) << QPointF(0.6, 0.5) << QPointF(0.5, 0.6) << QPointF(0.4, 0.5);
}

Expand Down
31 changes: 31 additions & 0 deletions src/widget/wstarrating.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ WStarRating::WStarRating(QString group, QWidget* pParent)
m_starRating(0,5),
m_pGroup(group),
m_focused(false) {
// Controls to change the star rating with controllers
m_pStarsUp = std::make_unique<ControlPushButton>(ConfigKey(group, "stars_up"));
m_pStarsDown = std::make_unique<ControlPushButton>(ConfigKey(group, "stars_down"));
connect(m_pStarsUp.get(), SIGNAL(valueChanged(double)),this, SLOT(slotStarsUp(double)));
connect(m_pStarsDown.get(), SIGNAL(valueChanged(double)),this, SLOT(slotStarsDown(double)));
}

void WStarRating::setup(const QDomNode& node, const SkinContext& context) {
Expand Down Expand Up @@ -87,6 +92,32 @@ void WStarRating::mouseMoveEvent(QMouseEvent *event) {
}
}

void WStarRating::slotStarsUp(double v) {
if (!m_pCurrentTrack) {
return;
}
if (v > 0 && m_starRating.starCount() < m_starRating.maxStarCount()) {
int star = m_starRating.starCount() + 1;
qDebug() << " stars " << m_starRating.starCount() << " > " << star;
m_starRating.setStarCount(star);
update();
m_pCurrentTrack->setRating(star);
}
}

void WStarRating::slotStarsDown(double v) {
if (!m_pCurrentTrack) {
return;
}
if (v > 0 && m_starRating.starCount() > 0) {
int star = m_starRating.starCount() - 1;
qDebug() << " stars " << m_starRating.starCount() << " > " << star;
m_starRating.setStarCount(star);
update();
m_pCurrentTrack->setRating(star);
}
}

void WStarRating::leaveEvent(QEvent* /*unused*/) {
m_focused = false;
updateRating();
Expand Down
9 changes: 9 additions & 0 deletions src/widget/wstarrating.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
#include "library/starrating.h"
#include "widget/wwidget.h"

#include "control/controlpushbutton.h"

class ControlObject;
class ControlPushButton;

class WStarRating : public WWidget {
Q_OBJECT
public:
Expand All @@ -24,6 +29,8 @@ class WStarRating : public WWidget {

private slots:
void updateRating(Track*);
void slotStarsUp(double v);
void slotStarsDown(double v);

protected:
void paintEvent(QPaintEvent* e) override;
Expand All @@ -41,6 +48,8 @@ class WStarRating : public WWidget {
private:
void updateRating();
int starAtPosition(int x);
std::unique_ptr<ControlPushButton> m_pStarsUp;
std::unique_ptr<ControlPushButton> m_pStarsDown;
};

#endif /* WSTARRATING_H */

0 comments on commit bd90b75

Please sign in to comment.