Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track operations widget with layout #7537

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions data/themes/classic/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ lmms--gui--TrackContentWidget {

/* gear button in tracks */

lmms--gui--TrackOperationsWidget > QPushButton {
lmms--gui--TrackOperationsWidget QPushButton {
max-height: 26px;
max-width: 26px;
min-height: 26px;
Expand All @@ -384,20 +384,20 @@ lmms--gui--TrackOperationsWidget > QPushButton {
border: none;
}

lmms--gui--TrackOperationsWidget > QPushButton::menu-indicator {
lmms--gui--TrackOperationsWidget QPushButton::menu-indicator {
image: url("resources:trackop.png");
subcontrol-origin: padding;
subcontrol-position: center;
position: relative;
top: 1px;
}

lmms--gui--TrackOperationsWidget > QPushButton::menu-indicator:hover {
lmms--gui--TrackOperationsWidget QPushButton::menu-indicator:hover {
image: url("resources:trackop_h.png");
}

lmms--gui--TrackOperationsWidget > QPushButton::menu-indicator:pressed,
lmms--gui--TrackOperationsWidget > QPushButton::menu-indicator:checked {
lmms--gui--TrackOperationsWidget QPushButton::menu-indicator:pressed,
lmms--gui--TrackOperationsWidget QPushButton::menu-indicator:checked {
image: url("resources:trackop_c.png");
position: relative;
top: 2px;
Expand Down
8 changes: 4 additions & 4 deletions data/themes/default/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ lmms--gui--TrackContentWidget {

/* gear button in tracks */

lmms--gui--TrackOperationsWidget > QPushButton {
lmms--gui--TrackOperationsWidget QPushButton {
max-height: 26px;
max-width: 26px;
min-height: 26px;
Expand All @@ -420,16 +420,16 @@ lmms--gui--TrackOperationsWidget > QPushButton {
border: none;
}

lmms--gui--TrackOperationsWidget > QPushButton::menu-indicator {
lmms--gui--TrackOperationsWidget QPushButton::menu-indicator {
image: url("resources:trackop.png");
subcontrol-origin: padding;
subcontrol-position: center;
position: relative;
top: 1px;
}

lmms--gui--TrackOperationsWidget > QPushButton::menu-indicator:pressed,
lmms--gui--TrackOperationsWidget > QPushButton::menu-indicator:checked {
lmms--gui--TrackOperationsWidget QPushButton::menu-indicator:pressed,
lmms--gui--TrackOperationsWidget QPushButton::menu-indicator:checked {
image: url("resources:trackop.png");
position: relative;
top: 2px;
Expand Down
1 change: 1 addition & 0 deletions include/PixmapButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class LMMS_EXPORT PixmapButton : public AutomatableButton
void setInactiveGraphic( const QPixmap & _pm, bool _update = true );

QSize sizeHint() const override;
QSize minimumSizeHint() const override;

signals:
void doubleClicked();
Expand Down
68 changes: 68 additions & 0 deletions include/TrackGrip.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* TrackGrip.h - Grip that can be used to move tracks
*
* Copyright (c) 2024- Michael Gregorius
*
* This file is part of LMMS - https://lmms.io
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program (see COPYING); if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
*/

#ifndef LMMS_GUI_TRACK_GRIP_H
#define LMMS_GUI_TRACK_GRIP_H

#include <QWidget>


class QPixmap;

namespace lmms
{

class Track;

namespace gui
{

class TrackGrip : public QWidget
{
Q_OBJECT
public:
TrackGrip(Track* track, QWidget* parent = 0);
~TrackGrip() override = default;

signals:
void grabbed();
void released();

protected:
void mousePressEvent(QMouseEvent*) override;
void mouseReleaseEvent(QMouseEvent*) override;
void paintEvent(QPaintEvent*) override;

private:
Track* m_track = nullptr;
bool m_isGrabbed = false;
static QPixmap* s_grabbedPixmap;
static QPixmap* s_releasedPixmap;
sakertooth marked this conversation as resolved.
Show resolved Hide resolved
};

} // namespace gui

} // namespace lmms

#endif // LMMS_GUI_TRACK_GRIP_H
3 changes: 3 additions & 0 deletions include/TrackOperationsWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ namespace lmms::gui
{

class PixmapButton;
class TrackGrip;
class TrackView;

class TrackOperationsWidget : public QWidget
Expand All @@ -42,6 +43,7 @@ class TrackOperationsWidget : public QWidget
TrackOperationsWidget( TrackView * parent );
~TrackOperationsWidget() override = default;

TrackGrip* getTrackGrip() const { return m_trackGrip; }

protected:
void mousePressEvent( QMouseEvent * me ) override;
Expand All @@ -65,6 +67,7 @@ private slots:
private:
TrackView * m_trackView;

TrackGrip* m_trackGrip;
QPushButton * m_trackOps;
PixmapButton * m_muteBtn;
PixmapButton * m_soloBtn;
Expand Down
3 changes: 2 additions & 1 deletion include/TrackView.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ public slots:
private slots:
void createClipView( lmms::Clip * clip );
void muteChanged();

void onTrackGripGrabbed();
void onTrackGripReleased();
} ;


Expand Down
1 change: 1 addition & 0 deletions src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ SET(LMMS_SRCS
gui/tracks/TrackLabelButton.cpp
gui/tracks/TrackOperationsWidget.cpp
gui/tracks/TrackRenameLineEdit.cpp
gui/tracks/TrackGrip.cpp
gui/tracks/TrackView.cpp

gui/widgets/AutomatableButton.cpp
Expand Down
106 changes: 106 additions & 0 deletions src/gui/tracks/TrackGrip.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* TrackGrip.cpp - Grip that can be used to move tracks
*
* Copyright (c) 2024- Michael Gregorius
*
* This file is part of LMMS - https://lmms.io
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program (see COPYING); if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
*/

#include "TrackGrip.h"

#include "embed.h"
#include "Track.h"

#include <QPainter>
#include <QPixmap>
#include <QMouseEvent>


namespace lmms::gui
{

QPixmap* TrackGrip::s_grabbedPixmap = nullptr;
QPixmap* TrackGrip::s_releasedPixmap = nullptr;

constexpr int c_margin = 2;

TrackGrip::TrackGrip(Track* track, QWidget* parent) :
QWidget(parent),
m_track(track)
{
if (!s_grabbedPixmap)
{
s_grabbedPixmap = new QPixmap(embed::getIconPixmap("track_op_grip_c"));
}

if (!s_releasedPixmap)
{
s_releasedPixmap = new QPixmap(embed::getIconPixmap("track_op_grip"));
}

setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Expanding);

setCursor(Qt::OpenHandCursor);

setFixedWidth(std::max(s_grabbedPixmap->width(), s_releasedPixmap->width()) + 2 * c_margin);
}

void TrackGrip::mousePressEvent(QMouseEvent* m)
{
m->accept();

m_isGrabbed = true;
setCursor(Qt::ClosedHandCursor);

emit grabbed();

update();
}

void TrackGrip::mouseReleaseEvent(QMouseEvent* m)
{
m->accept();

m_isGrabbed = false;
setCursor(Qt::OpenHandCursor);

emit released();

update();
}

void TrackGrip::paintEvent(QPaintEvent*)
{
QPainter p(this);

// Check if the color of the track should be used for the background
const auto color = m_track->color();
const auto muted = m_track->getMutedModel()->value();

if (color.has_value() && !muted)
{
p.fillRect(rect(), color.value());
}

// Paint the pixmap
auto r = rect().marginsRemoved(QMargins(c_margin, c_margin, c_margin, c_margin));
p.drawTiledPixmap(r, m_isGrabbed ? *s_grabbedPixmap : *s_releasedPixmap);
}

} // namespace lmms::gui
Loading
Loading