Skip to content

Commit 15ee02e

Browse files
authored
Enhanced quantize in PianoRoll (LMMS#5946)
* Button with menu has split highlight * Add menu with more action to quantize button * Style changes * Fix CSS length-zero-no-unit warning * Add combo button to classic theme
1 parent ea2c7ce commit 15ee02e

File tree

4 files changed

+70
-9
lines changed

4 files changed

+70
-9
lines changed

data/themes/classic/style.css

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ QToolButton#stopButton {
484484

485485
/* all tool buttons */
486486

487-
QToolButton {
487+
QToolButton, QToolButton::menu-button {
488488
padding: 1px 1px 1px 1px;
489489
border-radius: 5px;
490490
border: 1px solid rgba(63, 63, 63, 128);
@@ -510,6 +510,22 @@ QToolButton:checked {
510510
color: black;
511511
}
512512

513+
/* buttons with combined menu */
514+
515+
QToolButton[popupMode="1"] {
516+
margin-right: 11px;
517+
border-top-right-radius: 0;
518+
border-bottom-right-radius: 0;
519+
}
520+
521+
QToolButton::menu-button {
522+
subcontrol-origin: margin;
523+
width: 11px;
524+
padding: 0;
525+
border-top-left-radius: 0;
526+
border-bottom-left-radius: 0;
527+
}
528+
513529
/* track label buttons - the part that contains the icon and track title */
514530

515531
TrackLabelButton {

data/themes/default/style.css

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ QToolBar::separator {
490490

491491
/* all tool buttons */
492492

493-
QToolButton {
493+
QToolButton, QToolButton::menu-button {
494494
margin: 1px;
495495
padding: 2px 2px 2px 2px;
496496
border-top: 1px solid #778394;
@@ -522,6 +522,22 @@ QToolButton:checked {
522522
background-image: url(resources:shadow_p.png);
523523
}
524524

525+
/* buttons with combined menu */
526+
527+
QToolButton[popupMode="1"] {
528+
margin-right: 13px;
529+
border-top-right-radius: 0;
530+
border-bottom-right-radius: 0;
531+
}
532+
533+
QToolButton::menu-button {
534+
subcontrol-origin: margin;
535+
width: 13px;
536+
padding: 0;
537+
border-top-left-radius: 0;
538+
border-bottom-left-radius: 0;
539+
}
540+
525541
/* track label buttons - the part that contains the icon and track title */
526542

527543
TrackLabelButton {

include/PianoRoll.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,13 @@ class PianoRoll : public QWidget
142142
int quantization() const;
143143

144144
protected:
145+
enum QuantizeActions
146+
{
147+
QuantizeBoth,
148+
QuantizePos,
149+
QuantizeLength
150+
};
151+
145152
void keyPressEvent( QKeyEvent * ke ) override;
146153
void keyReleaseEvent( QKeyEvent * ke ) override;
147154
void leaveEvent( QEvent * e ) override;
@@ -198,7 +205,7 @@ protected slots:
198205
void quantizeChanged();
199206
void noteLengthChanged();
200207
void keyChanged();
201-
void quantizeNotes();
208+
void quantizeNotes(QuantizeActions mode = QuantizeBoth);
202209

203210
void updateSemiToneMarkerMenu();
204211

src/gui/editors/PianoRoll.cpp

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4554,7 +4554,7 @@ int PianoRoll::quantization() const
45544554
}
45554555

45564556

4557-
void PianoRoll::quantizeNotes()
4557+
void PianoRoll::quantizeNotes(QuantizeActions mode)
45584558
{
45594559
if( ! hasValidPattern() )
45604560
{
@@ -4582,8 +4582,15 @@ void PianoRoll::quantizeNotes()
45824582

45834583
Note copy(*n);
45844584
m_pattern->removeNote( n );
4585-
copy.quantizePos( quantization() );
4586-
m_pattern->addNote( copy );
4585+
if (mode == QuantizeBoth || mode == QuantizePos)
4586+
{
4587+
copy.quantizePos(quantization());
4588+
}
4589+
if (mode == QuantizeBoth || mode == QuantizeLength)
4590+
{
4591+
copy.quantizeLength(quantization());
4592+
}
4593+
m_pattern->addNote(copy, false);
45874594
}
45884595

45894596
update();
@@ -4704,15 +4711,30 @@ PianoRollWindow::PianoRollWindow() :
47044711

47054712
connect( editModeGroup, SIGNAL( triggered( int ) ), m_editor, SLOT( setEditMode( int ) ) );
47064713

4707-
QAction* quantizeAction = new QAction(embed::getIconPixmap( "quantize" ), tr( "Quantize" ), this );
4708-
connect( quantizeAction, SIGNAL( triggered() ), m_editor, SLOT( quantizeNotes() ) );
4714+
// Quantize combo button
4715+
QToolButton* quantizeButton = new QToolButton(notesActionsToolBar);
4716+
QMenu* quantizeButtonMenu = new QMenu(quantizeButton);
4717+
4718+
QAction* quantizeAction = new QAction(embed::getIconPixmap("quantize"), tr("Quantize"), this);
4719+
QAction* quantizePosAction = new QAction(tr("Quantize positions"), this);
4720+
QAction* quantizeLengthAction = new QAction(tr("Quantize lengths"), this);
4721+
4722+
connect(quantizeAction, &QAction::triggered, [this](){ m_editor->quantizeNotes(); });
4723+
connect(quantizePosAction, &QAction::triggered, [this](){ m_editor->quantizeNotes(PianoRoll::QuantizePos); });
4724+
connect(quantizeLengthAction, &QAction::triggered, [this](){ m_editor->quantizeNotes(PianoRoll::QuantizeLength); });
4725+
4726+
quantizeButton->setPopupMode(QToolButton::MenuButtonPopup);
4727+
quantizeButton->setDefaultAction(quantizeAction);
4728+
quantizeButton->setMenu(quantizeButtonMenu);
4729+
quantizeButtonMenu->addAction(quantizePosAction);
4730+
quantizeButtonMenu->addAction(quantizeLengthAction);
47094731

47104732
notesActionsToolBar->addAction( drawAction );
47114733
notesActionsToolBar->addAction( eraseAction );
47124734
notesActionsToolBar->addAction( selectAction );
47134735
notesActionsToolBar->addAction( pitchBendAction );
47144736
notesActionsToolBar->addSeparator();
4715-
notesActionsToolBar->addAction( quantizeAction );
4737+
notesActionsToolBar->addWidget(quantizeButton);
47164738

47174739
// Copy + paste actions
47184740
DropToolBar *copyPasteActionsToolBar = addDropToolBarToTop( tr( "Copy paste controls" ) );

0 commit comments

Comments
 (0)