Skip to content

Commit c4c44ae

Browse files
author
ThePBone
committed
Add 2 new graph styles: Outline, Gradient Line
1 parent 21b8763 commit c4c44ae

File tree

8 files changed

+134
-24
lines changed

8 files changed

+134
-24
lines changed

config/appconfigwrapper.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,14 @@ void AppConfigWrapper::setSpectrumTheme(int number){
206206
emit spectrumChanged();
207207
saveAppConfig();
208208
}
209+
int AppConfigWrapper::getSpectrumShape(){
210+
return appconf->getInt("visualizer.spectrum.shape");
211+
}
212+
void AppConfigWrapper::setSpectrumShape(int number){
213+
appconf->setValue("visualizer.spectrum.shape",QVariant(number));
214+
emit spectrumChanged();
215+
saveAppConfig();
216+
}
209217
void AppConfigWrapper::setSpectrumInput(const QString& npath){
210218
appconf->setValue("visualizer.spectrum.device",QVariant(npath));
211219
emit spectrumReloadRequired();

config/appconfigwrapper.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ class AppConfigWrapper : public QObject
9090
bool getIntroShown();
9191
QString getTrayContextMenu();
9292
void setTrayContextMenu(const QString &ctx);
93-
93+
void setSpectrumShape(int number);
94+
int getSpectrumShape();
9495
signals:
9596
void spectrumChanged();
9697
void spectrumReloadRequired();

dialog/settings.ui

Lines changed: 67 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113
<item>
114114
<widget class="QStackedWidget" name="stackedWidget">
115115
<property name="currentIndex">
116-
<number>4</number>
116+
<number>6</number>
117117
</property>
118118
<widget class="QWidget" name="general">
119119
<layout class="QVBoxLayout" name="verticalLayout_2">
@@ -875,57 +875,75 @@
875875
<item>
876876
<layout class="QFormLayout" name="formLayout_4">
877877
<property name="horizontalSpacing">
878-
<number>61</number>
878+
<number>120</number>
879879
</property>
880880
<property name="leftMargin">
881881
<number>0</number>
882882
</property>
883883
<property name="topMargin">
884884
<number>0</number>
885885
</property>
886-
<item row="0" column="0">
886+
<item row="1" column="0">
887887
<widget class="QLabel" name="label_6">
888888
<property name="text">
889889
<string>Number of bands</string>
890890
</property>
891891
</widget>
892892
</item>
893-
<item row="0" column="1">
893+
<item row="1" column="1">
894894
<widget class="QSpinBox" name="sa_bands">
895+
<property name="maximumSize">
896+
<size>
897+
<width>120</width>
898+
<height>16777215</height>
899+
</size>
900+
</property>
901+
<property name="suffix">
902+
<string> bands</string>
903+
</property>
895904
<property name="minimum">
896905
<number>5</number>
897906
</property>
898907
<property name="maximum">
899908
<number>300</number>
900909
</property>
910+
<property name="singleStep">
911+
<number>5</number>
912+
</property>
901913
<property name="value">
902914
<number>50</number>
903915
</property>
904916
</widget>
905917
</item>
906-
<item row="1" column="0">
918+
<item row="2" column="0">
907919
<widget class="QLabel" name="label_5">
908920
<property name="text">
909921
<string>Minimum frequency</string>
910922
</property>
911923
</widget>
912924
</item>
913-
<item row="2" column="0">
925+
<item row="3" column="0">
914926
<widget class="QLabel" name="label_7">
915927
<property name="text">
916928
<string>Maximum frequency</string>
917929
</property>
918930
</widget>
919931
</item>
920-
<item row="3" column="0">
932+
<item row="4" column="0">
921933
<widget class="QLabel" name="label_8">
922934
<property name="text">
923935
<string>Audio input sink</string>
924936
</property>
925937
</widget>
926938
</item>
927-
<item row="1" column="1">
939+
<item row="2" column="1">
928940
<widget class="QSpinBox" name="sa_minfreq">
941+
<property name="maximumSize">
942+
<size>
943+
<width>120</width>
944+
<height>16777215</height>
945+
</size>
946+
</property>
929947
<property name="suffix">
930948
<string>Hz</string>
931949
</property>
@@ -937,8 +955,14 @@
937955
</property>
938956
</widget>
939957
</item>
940-
<item row="2" column="1">
958+
<item row="3" column="1">
941959
<widget class="QSpinBox" name="sa_maxfreq">
960+
<property name="maximumSize">
961+
<size>
962+
<width>120</width>
963+
<height>16777215</height>
964+
</size>
965+
</property>
942966
<property name="suffix">
943967
<string>Hz</string>
944968
</property>
@@ -956,7 +980,7 @@
956980
</property>
957981
</widget>
958982
</item>
959-
<item row="3" column="1">
983+
<item row="4" column="1">
960984
<widget class="QComboBox" name="sa_input">
961985
<property name="maximumSize">
962986
<size>
@@ -966,12 +990,44 @@
966990
</property>
967991
</widget>
968992
</item>
993+
<item row="0" column="0">
994+
<widget class="QLabel" name="label_13">
995+
<property name="text">
996+
<string>Graph Type</string>
997+
</property>
998+
</widget>
999+
</item>
1000+
<item row="0" column="1">
1001+
<widget class="QComboBox" name="sa_type">
1002+
<property name="maximumSize">
1003+
<size>
1004+
<width>120</width>
1005+
<height>16777215</height>
1006+
</size>
1007+
</property>
1008+
<item>
1009+
<property name="text">
1010+
<string>Bars</string>
1011+
</property>
1012+
</item>
1013+
<item>
1014+
<property name="text">
1015+
<string>Outline</string>
1016+
</property>
1017+
</item>
1018+
<item>
1019+
<property name="text">
1020+
<string>Line (gradient)</string>
1021+
</property>
1022+
</item>
1023+
</widget>
1024+
</item>
9691025
</layout>
9701026
</item>
9711027
<item>
9721028
<widget class="QLabel" name="label_10">
9731029
<property name="text">
974-
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;Note:&lt;/span&gt; If the selected audio source sink is unavailable, the visualizer will automatically switch to the system default input device (e.g. internal microphone). In order to reconnect to the sink you've selected above, you can use the 'Reload visualizer' option in the 3-dot menu.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
1030+
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;Note:&lt;/span&gt; If the selected audio source sink is unavailable, the visualizer will automatically switch to the system default input device (e.g. internal microphone).&lt;/p&gt;&lt;p&gt;If you use the line or outline graph type, you should set the number of bands &lt;span style=&quot; font-weight:600;&quot;&gt;to at least 100&lt;/span&gt;.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
9751031
</property>
9761032
<property name="wordWrap">
9771033
<bool>true</bool>

dialog/settingsdlg.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,10 @@ SettingsDlg::SettingsDlg(MainWindow* mainwin,QWidget *parent) :
256256
if(lockslot)return;
257257
appconf->setSpectrumInput(str);
258258
});
259-
259+
connect(ui->sa_type,static_cast<void (QComboBox::*)(const QString&)>(&QComboBox::currentIndexChanged), this, [this](const QString&){
260+
if(lockslot)return;
261+
appconf->setSpectrumShape(ui->sa_type->currentIndex());
262+
});
260263
/*
261264
* Connect all signals for SA/Design
262265
*/
@@ -470,6 +473,7 @@ void SettingsDlg::refreshAll(){
470473
ui->spectrum_theme->setEnabled(appconf->getSpetrumEnable());
471474
ui->spectrum_advanced->setEnabled(appconf->getSpetrumEnable());
472475

476+
ui->sa_type->setCurrentIndex(appconf->getSpectrumShape());
473477
ui->sa_bands->setValue(bands);
474478
ui->sa_minfreq->setValue(minfreq);
475479
ui->sa_maxfreq->setValue(maxfreq);

mainwindow.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,13 +302,19 @@ void MainWindow::RefreshSpectrumParameters(){
302302
outline = palette().window().color().lighter(140);
303303

304304
if(m_appwrapper->getSpectrumTheme() == 0)
305-
m_spectrograph->setTheme(Qt::black,QColor(51,204,201),QColor(51,204,201).darker(),QColor(255,255,0),m_appwrapper->getSpetrumGrid());
305+
m_spectrograph->setTheme(Qt::black,
306+
QColor(51,204,201),
307+
QColor(51,204,201).darker(),
308+
QColor(255,255,0),
309+
m_appwrapper->getSpetrumGrid(),
310+
(Spectrograph::Mode)m_appwrapper->getSpectrumShape());
306311
else
307312
m_spectrograph->setTheme(palette().window().color().lighter(),
308313
palette().highlight().color(),
309314
palette().text().color(),
310315
outline.lighter(108),
311-
m_appwrapper->getSpetrumGrid());
316+
m_appwrapper->getSpetrumGrid(),
317+
(Spectrograph::Mode)m_appwrapper->getSpectrumShape());
312318

313319

314320

misc/stylehelper.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ namespace ColorStyleProvider {
6565
static QMap<CS_UNIT> TABLE(){
6666
InitializableQMap<CS_UNIT> map;
6767
map << QPair<CS_UNIT>("dark",ColorStyle(true,QColor(25,25,25),QColor(53,53,53),Qt::white,QColor(42, 130, 218)))
68-
<< QPair<CS_UNIT>("gray",ColorStyle(true,QColor(83,83,125),QColor(49,49,74),Qt::white,QColor(85,85,127),QColor(144,144,179)))
68+
<< QPair<CS_UNIT>("gray",ColorStyle(true,QColor(83,83,125),QColor(49,49,74),Qt::white,QColor(151, 151, 184),QColor(144,144,179)))
6969
<< QPair<CS_UNIT>("white",ColorStyle(false,Qt::white,Qt::white,Qt::black,QColor(56,161,227)))
7070
<< QPair<CS_UNIT>("blue",ColorStyle(true,QColor(0,0,38),QColor(0,0,50),Qt::white,QColor(85,0,255)))
7171
<< QPair<CS_UNIT>("darkblue",ColorStyle(true,QColor(14,19,29),QColor(19,25,38),Qt::white,QColor(70,79,89)))
7272
<< QPair<CS_UNIT>("honeycomb",ColorStyle(false,QColor(185,188,182),QColor(212,215,208),Qt::black,QColor(243,193,41),Qt::white))
7373
<< QPair<CS_UNIT>("black",ColorStyle(true,Qt::black,QColor(16,16,16),QColor(222,222,222),QColor(132,132,132)))
74-
<< QPair<CS_UNIT>("darkgreen",ColorStyle(true,QColor(30,30,30),QColor(27,34,36),QColor(197,209,217),QColor(21,67,58)))
74+
<< QPair<CS_UNIT>("darkgreen",ColorStyle(true,QColor(30,30,30),QColor(27,34,36),QColor(197,209,217),QColor(153, 199, 190)))
7575
<< QPair<CS_UNIT>("green",ColorStyle(true,QColor(6,29,12),QColor(0,12,0),Qt::white,QColor(86,191,121)))
7676
<< QPair<CS_UNIT>("stone",ColorStyle(true,QColor(27,36,40),QColor(34,45,50),Qt::white,QColor(165,206,255)));
7777
return std::move(map);

visualization/spectrograph.cpp

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,14 @@ void Spectrograph::setParams(int numBars, qreal lowFreq, qreal highFreq)
8383
updateBars();
8484
}
8585

86-
void Spectrograph::setTheme(QColor background, QColor bar, QColor bar_max, QColor outline, bool grid)
86+
void Spectrograph::setTheme(QColor background, QColor bar, QColor bar_max, QColor outline, bool grid, Mode mode)
8787
{
8888
m_background = background;
8989
m_bar = bar;
9090
m_bar_max = bar_max;
9191
m_grid = grid;
9292
m_outline = outline;
93+
m_mode = mode;
9394
}
9495

9596
void Spectrograph::timerEvent(QTimerEvent *event)
@@ -159,12 +160,15 @@ void Spectrograph::paintEvent(QPaintEvent *event)
159160
}
160161
}
161162

162-
QColor m_bar_l = m_bar;
163-
m_bar_l.setAlphaF(0.75);
164-
m_bar_max.setAlphaF(0.75);
165-
166163
// Draw the bars
167164
if (numBars) {
165+
QColor m_bar_l = m_bar;
166+
m_bar_l.setAlphaF(0.75);
167+
m_bar_max.setAlphaF(0.75);
168+
169+
QPainterPath frequencyResponse;
170+
painter.setRenderHint(QPainter::RenderHint::Antialiasing,true);
171+
168172
// Calculate width of bars and gaps
169173
const int widgetWidth = rect().width();
170174
const int barPlusGapWidth = widgetWidth / numBars;
@@ -187,7 +191,30 @@ void Spectrograph::paintEvent(QPaintEvent *event)
187191
if (m_bars[i].clipped)
188192
color = m_bar_max;
189193

190-
painter.fillRect(bar, color);
194+
if (i == 0) frequencyResponse.moveTo(bar.topLeft().x(),
195+
bar.topLeft().y()+1);
196+
else frequencyResponse.lineTo(bar.topLeft().x(),
197+
bar.topLeft().y()+1);
198+
199+
if(m_mode == Mode::Bars)
200+
painter.fillRect(bar, color);
201+
}
202+
203+
if(m_mode == Mode::LineGradient){
204+
frequencyResponse.lineTo(width(),height());
205+
frequencyResponse.lineTo(0, height());
206+
QColor light = m_bar_l;
207+
light.setAlpha(60);
208+
QLinearGradient gradient(QPoint(width(),0),QPoint(width(),height()));
209+
gradient.setColorAt(0.0,m_bar_l);
210+
gradient.setColorAt(1.0,light);
211+
painter.setBrush(gradient);
212+
painter.setPen(QPen(Qt::PenStyle::NoPen));
213+
painter.drawPath(frequencyResponse);
214+
}
215+
if(m_mode == Mode::Line){
216+
painter.setPen(QPen(QBrush(m_bar_l),1,Qt::PenStyle::SolidLine,Qt::PenCapStyle::SquareCap));
217+
painter.drawPath(frequencyResponse);
191218
}
192219
}
193220
}

visualization/spectrograph.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,19 @@ class Spectrograph : public QWidget
6363
{
6464
Q_OBJECT
6565

66+
6667
public:
68+
typedef enum{
69+
Bars,
70+
Line,
71+
LineGradient
72+
}Mode;
73+
6774
explicit Spectrograph(QWidget *parent = 0);
6875
~Spectrograph();
6976

7077
void setParams(int numBars, qreal lowFreq, qreal highFreq);
71-
void setTheme(QColor background=Qt::black, QColor bar=QColor(51, 204, 102), QColor bar_max=QColor(255, 255, 0), QColor outline=QColor(51, 204, 102).darker(), bool grid=true);
78+
void setTheme(QColor background=Qt::black, QColor bar=QColor(51, 204, 102), QColor bar_max=QColor(255, 255, 0), QColor outline=QColor(51, 204, 102).darker(), bool grid=true, Mode mode = Mode::Bars);
7279

7380
// QObject
7481
void timerEvent(QTimerEvent *event) override;
@@ -110,6 +117,7 @@ public slots:
110117
QColor m_bar_max = QColor(255, 255, 0);
111118
QColor m_outline = QColor(51, 204, 102).darker();
112119
bool m_grid = true;
120+
Mode m_mode = Mode::Bars;
113121
};
114122

115123
#endif // SPECTROGRAPH_H

0 commit comments

Comments
 (0)