Skip to content

Commit

Permalink
Merge pull request #2352 from hoffie/levelmeter-small-led-width-fix
Browse files Browse the repository at this point in the history
Audiomixerboard: Auto-adjust size when switching between meter styles
  • Loading branch information
hoffie committed Feb 7, 2022
2 parents ebb1e9f + 01b0c3a commit 1dd683d
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 23 deletions.
4 changes: 2 additions & 2 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

### 3.8.2beta1dev <- NOTE: the release version number will be 3.8.2 ###

- Client: Added selection option for level meter style (#1688).
(contributed by @henkdegroot)
- Client: Added selection option for level meter style (#1688, #2352).
(contributed by @henkdegroot, @hoffie, @pgScorpio)

- Client: On Windows, if no driver found while installing, the "Run Jamulus"
option will not be checked (#2103).
Expand Down
23 changes: 7 additions & 16 deletions src/levelmeter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ CLevelMeter::CLevelMeter ( QWidget* parent ) : QWidget ( parent ), eLevelMeterTy
pBarMeter->setFormat ( "" ); // suppress percent numbers

// setup stacked layout for meter type switching mechanism
pStackedLayout = new QStackedLayout ( this );
pStackedLayout->addWidget ( pLEDMeter );
pStackedLayout->addWidget ( pBarMeter );
pMinStackedLayout = new CMinimumStackedLayout ( this );
pMinStackedLayout->addWidget ( pLEDMeter );
pMinStackedLayout->addWidget ( pBarMeter );

// according to QScrollArea description: "When using a scroll area to display the
// contents of a custom widget, it is important to ensure that the size hint of
Expand Down Expand Up @@ -103,7 +103,7 @@ void CLevelMeter::SetLevelMeterType ( const ELevelMeterType eNType )
{
vecpLEDs[iLEDIdx]->SetColor ( cLED::RL_BLACK );
}
pStackedLayout->setCurrentIndex ( 0 );
pMinStackedLayout->setCurrentIndex ( 0 );
break;

case MT_SLIM_LED:
Expand All @@ -112,7 +112,7 @@ void CLevelMeter::SetLevelMeterType ( const ELevelMeterType eNType )
{
vecpLEDs[iLEDIdx]->SetColor ( cLED::RL_SLIM_BLACK );
}
pStackedLayout->setCurrentIndex ( 0 );
pMinStackedLayout->setCurrentIndex ( 0 );
break;

case MT_SMALL_LED:
Expand All @@ -121,21 +121,12 @@ void CLevelMeter::SetLevelMeterType ( const ELevelMeterType eNType )
{
vecpLEDs[iLEDIdx]->SetColor ( cLED::RL_SMALL_BLACK );
}
pStackedLayout->setCurrentIndex ( 0 );
pMinStackedLayout->setCurrentIndex ( 0 );
break;

case MT_BAR:
pStackedLayout->setCurrentIndex ( 1 );
break;

case MT_SLIM_BAR:
// set all LEDs to disabled, otherwise we would not get our desired small width
for ( int iLEDIdx = 0; iLEDIdx < NUM_LEDS_INCL_CLIP_LED; iLEDIdx++ )
{
vecpLEDs[iLEDIdx]->SetColor ( cLED::RL_DISABLED );
}

pStackedLayout->setCurrentIndex ( 1 );
pMinStackedLayout->setCurrentIndex ( 1 );
break;
}

Expand Down
9 changes: 4 additions & 5 deletions src/levelmeter.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include <QTimer>
#include <QLayout>
#include <QProgressBar>
#include <QStackedLayout>
#include "util.h"
#include "global.h"

Expand Down Expand Up @@ -107,10 +106,10 @@ class CLevelMeter : public QWidget

void SetBarMeterStyleAndClipStatus ( const ELevelMeterType eNType, const bool bIsClip );

QStackedLayout* pStackedLayout;
ELevelMeterType eLevelMeterType;
CVector<cLED*> vecpLEDs;
QProgressBar* pBarMeter;
CMinimumStackedLayout* pMinStackedLayout;
ELevelMeterType eLevelMeterType;
CVector<cLED*> vecpLEDs;
QProgressBar* pBarMeter;

QTimer TimerClip;

Expand Down
10 changes: 10 additions & 0 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,16 @@ QString TruncateString ( QString str, int position )
}
return str.left ( position );
}

QSize CMinimumStackedLayout::sizeHint() const
{
// always use the size of the currently visible widget:
if ( currentWidget() )
{
return currentWidget()->sizeHint();
}
return QStackedLayout::sizeHint();
}
#endif

/******************************************************************************\
Expand Down
10 changes: 10 additions & 0 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
# include <QDesktopServices>
# include <QKeyEvent>
# include <QTextBoundaryFinder>
# include <QStackedLayout>
# include "ui_aboutdlgbase.h"
#endif
#include <QFile>
Expand Down Expand Up @@ -445,6 +446,15 @@ public slots:
signals:
void LanguageChanged ( QString strLanguage );
};

// StackedLayout which auto-reduces to the size of the currently visible widget
class CMinimumStackedLayout : public QStackedLayout
{
Q_OBJECT
public:
CMinimumStackedLayout ( QWidget* parent = nullptr ) : QStackedLayout ( parent ) {}
virtual QSize sizeHint() const override;
};
#endif

/******************************************************************************\
Expand Down

0 comments on commit 1dd683d

Please sign in to comment.