1 /*  smplayer, GUI front-end for mplayer.
2     Copyright (C) 2006-2021 Ricardo Villalba <ricardo@smplayer.info>
3     umplayer, Copyright (C) 2010 Ori Rejwan
4 
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9 
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14 
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18 */
19 
20 #include "volumecontrolpanel.h"
21 #include <QHBoxLayout>
22 #include <QVBoxLayout>
23 #include <QEvent>
24 #include "widgetactions.h"
25 #include "myaction.h"
26 #include "actiontools.h"
27 
VolumeControlPanel(QWidget * parent)28 VolumeControlPanel::VolumeControlPanel(QWidget *parent) :
29     QWidget(parent)
30 {
31     setAttribute(Qt::WA_StyledBackground, true);
32     setFixedWidth(108);
33     muteButton = new MyButton(this);
34     maxButton = new MyButton(this);
35     playlistButton = new MyButton(this);
36     equalizerButton = new MyButton(this);
37     fullscreenButton = new MyButton(this);
38     playlistButton->setCheckable(true);
39     equalizerButton->setCheckable(true);
40     fullscreenButton->setCheckable(true);
41     volumeBar = new PanelSeeker(this);
42     volumeBar->setLeftRightMargin(8);
43     volumeBar->setMinimum(0);
44     volumeBar->setMaximum(100);
45     volumeBar->setDelayPeriod(1);
46     volumeBar->setFrozenPeriod(10);
47     QHBoxLayout* upperLayout = new QHBoxLayout;
48     QHBoxLayout* lowerLayout = new QHBoxLayout;
49     QVBoxLayout* mainLayout = new QVBoxLayout;
50     upperLayout->addWidget(muteButton);
51     upperLayout->addWidget(volumeBar);
52     upperLayout->addWidget(maxButton);
53     upperLayout->setContentsMargins(0, 0, 0, 0);
54     upperLayout->setSpacing(0);
55     QSpacerItem* sp1 = new QSpacerItem(1, 10, QSizePolicy::Expanding, QSizePolicy::Preferred);
56     lowerLayout->addSpacerItem(sp1);
57     lowerLayout->addWidget(fullscreenButton);
58     lowerLayout->addWidget(playlistButton);
59     lowerLayout->addWidget(equalizerButton);
60     QSpacerItem* sp2 = new QSpacerItem(1, 10, QSizePolicy::Expanding, QSizePolicy::Preferred);
61     lowerLayout->addSpacerItem(sp2);
62     lowerLayout->setContentsMargins(0, 0, 0, 0);
63     lowerLayout->setSpacing(0);
64     mainLayout->addLayout(upperLayout);
65     mainLayout->addLayout(lowerLayout);
66     mainLayout->setContentsMargins(0,8,5,8);
67     mainLayout->setSpacing(2);
68     setLayout(mainLayout);
69 
70     connect(muteButton, SIGNAL(clicked()), this, SLOT(setVolumeMin()));
71     connect(maxButton, SIGNAL(clicked()), this, SLOT(setVolumeMax()));
72 
73 	connect(volumeBar, SIGNAL(valueChanged(int)), this, SIGNAL(volumeChanged(int)));
74 	connect(volumeBar, SIGNAL(sliderMoved(int)), this, SIGNAL(volumeSliderMoved(int)));
75 }
76 
setButtonIcons(MyButton * button,QPixmap pix)77 void VolumeControlPanel::setButtonIcons( MyButton* button, QPixmap pix)
78 {
79     MyIcon icon;
80     int w = pix.width();
81     int h = pix.height();
82     icon.setPixmap(pix.copy(0, 0, w, h/4 ), MyIcon::Normal, MyIcon::Off);
83     icon.setPixmap(pix.copy(0, h/4, w, h/4 ), MyIcon::MouseOver, MyIcon::Off);
84     icon.setPixmap(pix.copy(0, h/2, w, h/4 ), MyIcon::MouseDown, MyIcon::Off);
85     icon.setPixmap(pix.copy(0, 3*h/4, w, h/4 ), MyIcon::Disabled, MyIcon::Off);
86     icon.setPixmap(pix.copy(0, 0, w, h/4 ), MyIcon::Normal, MyIcon::On);
87     icon.setPixmap(pix.copy(0, h/4, w, h/4 ), MyIcon::MouseOver, MyIcon::On);
88     icon.setPixmap(pix.copy(0, h/2, w, h/4 ), MyIcon::MouseDown, MyIcon::On);
89     icon.setPixmap(pix.copy(0, 3*h/4, w, h/4 ), MyIcon::Disabled, MyIcon::On);
90     button->setMyIcon(icon);
91     button->setFixedSize(icon.size(MyIcon::Normal, MyIcon::Off));
92 }
93 
setActionCollection(QList<QAction * > actions)94 void VolumeControlPanel::setActionCollection(QList<QAction*> actions)
95 {
96 	//ActionTools::findAction("aaa", actions);
97 	volumeBar->setEnabled(true);
98 	/* volumeSliderAction->installEventFilter(this); */
99 	SETACTIONTOBUTTON(playlistButton, "show_playlist");
100 	SETACTIONTOBUTTON(fullscreenButton, "fullscreen");
101 	SETACTIONTOBUTTON(equalizerButton, "video_equalizer");
102 
103 	retranslateStrings();
104 }
105 
setVolume(int value)106 void VolumeControlPanel::setVolume(int value)
107 {
108     volumeBar->setSliderValue(value);
109 }
110 
111 /*
112 bool VolumeControlPanel::eventFilter(QObject *watched, QEvent *event)
113 {
114     if(watched == volumeSliderAction && event->type() == QEvent::EnabledChange)
115     {
116         volumeBar->setEnabled(volumeSliderAction->isEnabled());
117     }
118     return false;
119 }
120 */
121 
122 // Language change stuff
changeEvent(QEvent * e)123 void VolumeControlPanel::changeEvent(QEvent *e) {
124 	if (e->type() == QEvent::LanguageChange) {
125 		retranslateStrings();
126 	} else {
127 		QWidget::changeEvent(e);
128 	}
129 }
130 
retranslateStrings()131 void VolumeControlPanel::retranslateStrings() {
132 	if (playlistButton) playlistButton->setToolTip(tr("Playlist"));
133 	if (fullscreenButton) fullscreenButton->setToolTip(tr("Fullscreen on/off"));
134 	if (equalizerButton) equalizerButton->setToolTip(tr("Video equalizer"));
135 }
136 
137 #include "moc_volumecontrolpanel.cpp"
138