Skip to content

Commit

Permalink
Merge pull request #4501 from ronso0/fxrfct-chain-selector
Browse files Browse the repository at this point in the history
Tweak WEffectChainPresetSelector
  • Loading branch information
daschuer authored Nov 7, 2021
2 parents 5738739 + 7806776 commit 83f2342
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 14 deletions.
3 changes: 0 additions & 3 deletions res/skins/LateNight/style.qss
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,6 @@ WTrackMenu QMenu::right-arrow {
}

WEffectSelector QAbstractScrollArea {
/* This would set the maximum width only. The minimum seems to be
defined by the widget itself. Unfortunately, the widget width
is also used to calculate the text elide (center) TODO(ronso0) */
min-width: 160px;
}
#fadeModeCombobox QAbstractScrollArea {
Expand Down
17 changes: 12 additions & 5 deletions res/skins/default.qss
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ WTrackMenu QMenu,
QLineEdit QMenu,
WCueMenuPopup,
WCoverArtMenu,
WEffectChainPresetButton QMenu,
WEffectSelector QAbstractScrollArea,
WEffectChainPresetSelector QAbstractScrollArea,
#fadeModeCombobox QAbstractScrollArea {
padding: 0.15em;
}
Expand All @@ -111,7 +113,8 @@ WLibrarySidebar QMenu::separator,
WTrackMenu::separator,
WTrackMenu QMenu::separator,
QLineEdit QMenu::separator,
WLibraryTextBrowser QMenu::separator {
WLibraryTextBrowser QMenu::separator,
WEffectChainPresetButton QMenu::separator {
height: 0px;
margin: 0.25em;
}
Expand All @@ -120,7 +123,8 @@ WLibraryTextBrowser QMenu::separator {
/* All menus that have at least one item with a checkbox*/
WLibrarySidebar QMenu::item,
WTrackTableViewHeader QMenu::item,
#CratesMenu::item {
#CratesMenu::item,
WEffectChainPresetButton QMenu::item {
/* padding-right reserves space for the submenu expand arrow
padding-left should be bigger than the menu icon width +
icon margin-left/-right */
Expand All @@ -137,7 +141,8 @@ WTrackMenu QMenu::item,
QLineEdit QMenu::item,
WCoverArtMenu::item,
/* for the sake of completeness: html root view of Crates, Rec etc. */
WLibraryTextBrowser QMenu::item {
WLibraryTextBrowser QMenu::item,
WEffectChainPresetButton QMenu::item {
padding: 0.17em 0.6em 0.17em 0.6em;
}

Expand All @@ -158,13 +163,15 @@ WTrackTableViewHeader QMenu::indicator {
}

/* items in Crate sub menu */
WTrackMenu QMenu QCheckBox {
WTrackMenu QMenu QCheckBox,
WEffectChainPresetButton QMenu QCheckBox {
padding: 0.17em 0.6em 0.17em 0.25em;
}

WLibrarySidebar QMenu::indicator,
WTrackTableViewHeader QMenu::indicator,
WTrackMenu QMenu QCheckBox::indicator {
WTrackMenu QMenu QCheckBox::indicator,
WEffectChainPresetButton QMenu QCheckBox::indicator {
width: 0.7em;
height: 0.7em;
}
1 change: 0 additions & 1 deletion src/widget/weffectchainpresetbutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ void WEffectChainPresetButton::setup(const QDomNode& node, const SkinContext& co
&WEffectChainPresetButton::populateMenu);
}
populateMenu();
// TODO: enable applying external stylesheets
}

void WEffectChainPresetButton::populateMenu() {
Expand Down
50 changes: 46 additions & 4 deletions src/widget/weffectchainpresetselector.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#include "widget/weffectchainpresetselector.h"

#include <QAbstractItemView>
#include <QApplication>
#include <QPaintEvent>
#include <QStyleOption>
#include <QStylePainter>
#include <QtDebug>

#include "effects/chains/quickeffectchain.h"
Expand All @@ -13,9 +18,11 @@ WEffectChainPresetSelector::WEffectChainPresetSelector(
m_bQuickEffectChain(false),
m_pChainPresetManager(pEffectsManager->getChainPresetManager()),
m_pEffectsManager(pEffectsManager) {
// Prevent this widget from getting focused to avoid
// interfering with using the library via keyboard.
setFocusPolicy(Qt::NoFocus);
// Prevent this widget from getting focused by Tab/Shift+Tab
// to avoid interfering with using the library via keyboard.
// Allow click focus though so the list can always be opened by mouse,
// see https://bugs.launchpad.net/mixxx/+bug/1902125
setFocusPolicy(Qt::ClickFocus);
}

void WEffectChainPresetSelector::setup(const QDomNode& node, const SkinContext& context) {
Expand Down Expand Up @@ -67,7 +74,7 @@ void WEffectChainPresetSelector::populate() {
auto pChainPreset = presetList.at(i);
QString elidedDisplayName = metrics.elidedText(pChainPreset->name(),
Qt::ElideMiddle,
width() - 2);
view()->width() - 2);
addItem(elidedDisplayName, QVariant(pChainPreset->name()));
setItemData(i, pChainPreset->name(), Qt::ToolTipRole);
}
Expand All @@ -81,6 +88,12 @@ void WEffectChainPresetSelector::slotEffectChainPresetSelected(int index) {
m_pChain->loadChainPreset(
m_pChainPresetManager->getPreset(currentData().toString()));
setBaseTooltip(itemData(index, Qt::ToolTipRole).toString());
// After selecting an effect send Shift+Tab to move focus to the next
// keyboard-focusable widget (tracks table in official skins) in order
// to immediately allow keyboard shortcuts again.
QKeyEvent backwardFocusKeyEvent =
QKeyEvent{QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier};
QApplication::sendEvent(this, &backwardFocusKeyEvent);
}

void WEffectChainPresetSelector::slotChainPresetChanged(const QString& name) {
Expand All @@ -98,3 +111,32 @@ bool WEffectChainPresetSelector::event(QEvent* pEvent) {

return QComboBox::event(pEvent);
}

void WEffectChainPresetSelector::paintEvent(QPaintEvent* e) {
Q_UNUSED(e);
// The default paint implementation aligns the text based on the layout direction.
// Override to allow qss to align the text of the closed combobox with the
// Quick effect controls in the mixer.
QStylePainter painter(this);
QStyleOptionComboBox comboStyle;
// Inititialize the style and draw the frame, down-arrow etc.
// Note: using 'comboStyle.initFrom(this)' and 'painter.drawComplexControl(...)
// here would not paint the hover style of the down arrow.
initStyleOption(&comboStyle);
style()->drawComplexControl(QStyle::CC_ComboBox, &comboStyle, &painter, this);

QStyleOptionButton buttonStyle;
buttonStyle.initFrom(this);
QRect buttonRect = style()->subControlRect(
QStyle::CC_ComboBox, &comboStyle, QStyle::SC_ComboBoxEditField, this);
buttonStyle.rect = buttonRect;
QFontMetrics metrics(font());
// Since the chain selector and the popup can differ in width,
// elide the button text independently from the popup display name.
buttonStyle.text = metrics.elidedText(
currentData().toString(),
Qt::ElideRight,
buttonRect.width() - 2);
// Draw the text for the selector button. Alternative: painter.drawControl(...)
style()->drawControl(QStyle::CE_PushButtonLabel, &buttonStyle, &painter, this);
}
1 change: 1 addition & 0 deletions src/widget/weffectchainpresetselector.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class WEffectChainPresetSelector : public QComboBox, public WBaseWidget {
void slotEffectChainPresetSelected(int index);
void slotChainPresetChanged(const QString& name);
bool event(QEvent* pEvent) override;
void paintEvent(QPaintEvent* e) override;

private:
bool m_bQuickEffectChain;
Expand Down
3 changes: 2 additions & 1 deletion src/widget/weffectselector.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "widget/weffectselector.h"

#include <QAbstractItemView>
#include <QApplication>
#include <QtDebug>

Expand Down Expand Up @@ -66,7 +67,7 @@ void WEffectSelector::populate() {
const EffectManifestPointer pManifest = visibleEffectManifests.at(i);
QString elidedDisplayName = metrics.elidedText(pManifest->displayName(),
Qt::ElideMiddle,
width() - 2);
view()->width() - 2);
addItem(elidedDisplayName, QVariant(pManifest->uniqueId()));

QString name = pManifest->name();
Expand Down

0 comments on commit 83f2342

Please sign in to comment.