source: smplayer/trunk/src/skingui/playcontrol.cpp@ 176

Last change on this file since 176 was 176, checked in by Silvan Scherrer, 9 years ago

smplayer: update trunk to version 16.4

File size: 6.3 KB
Line 
1/* smplayer, GUI front-end for mplayer.
2 Copyright (C) 2006-2016 Ricardo Villalba <rvm@users.sourceforge.net>
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 "playcontrol.h"
21#include <QResizeEvent>
22#include "myaction.h"
23#include "actiontools.h"
24
25PlayControl::PlayControl(QWidget *parent) :
26 QWidget(parent), playOrPause(true)
27{
28 setAttribute(Qt::WA_StyledBackground, true);
29 setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred);
30 backwardButton = new MyButton(this);
31 previousButton = new MyButton(this);
32 playPauseButton = new MyButton(this);
33 stopButton = new MyButton(this);
34 nextButton = new MyButton(this);
35 forwardButton = new MyButton(this);
36 recordButton = new MyButton(this);
37 layout = new QHBoxLayout;
38 QSpacerItem* spacer1 = new QSpacerItem(9, 10, QSizePolicy::MinimumExpanding, QSizePolicy::Maximum);
39 QSpacerItem* spacer2 = new QSpacerItem(9, 10, QSizePolicy::MinimumExpanding, QSizePolicy::Maximum);
40 layout->addSpacerItem(spacer1);
41 layout->addWidget(previousButton);
42 layout->addWidget(backwardButton);
43 layout->addWidget(playPauseButton);
44 layout->addWidget(stopButton);
45 layout->addWidget(recordButton);
46 layout->addWidget(forwardButton);
47 layout->addWidget(nextButton);
48 layout->addSpacerItem(spacer2);
49 layout->setSpacing(0);
50 layout->setContentsMargins( 0, 0, 0, 0);
51 setRecordEnabled(false);
52 setLayout(layout);
53 recordButton->installEventFilter(this);
54 nextButton->installEventFilter(this);
55 previousButton->installEventFilter(this);
56}
57
58
59void PlayControl::resizeEvent(QResizeEvent *e)
60{
61 updateSize();
62}
63
64void PlayControl::updateSize()
65{
66 backwardButton->hide();
67 previousButton->hide();
68 playPauseButton->hide();
69 stopButton->hide();
70 recordButton->hide();
71 nextButton->hide();
72 forwardButton->hide();
73 int totalWidth = 18;
74 totalWidth += playPauseButton->minimumWidth();
75 playPauseButton->show();
76 if(recordButton->isEnabled())
77 {
78 totalWidth += recordButton->minimumWidth();
79 recordButton->show();
80 }
81 else
82 {
83 recordButton->hide();
84 }
85 if(nextButton->isEnabled())
86 {
87 totalWidth += nextButton->minimumWidth();
88 if(width() < totalWidth ) { nextButton->hide(); return; }
89 else nextButton->show();
90 }
91 else
92 {
93 nextButton->hide();
94 }
95
96 if(previousButton->isEnabled())
97 {
98 totalWidth += previousButton->minimumWidth();
99 if(width() < totalWidth ) { previousButton->hide(); return; }
100 else previousButton->show();
101 }
102 else
103 {
104 previousButton->hide();
105 }
106 totalWidth += stopButton->minimumWidth();
107 if(width() < totalWidth) { stopButton->hide(); return; }
108 else stopButton->show();
109 totalWidth += forwardButton->minimumWidth();
110 if(width() < totalWidth) { forwardButton->hide(); return; }
111 else forwardButton->show();
112 totalWidth += backwardButton->minimumWidth();
113 if(width() < totalWidth) { backwardButton->hide(); return; }
114 else backwardButton->show();
115 if(!nextButton->isEnabled()) totalWidth += nextButton->minimumWidth();
116 if(width() < totalWidth) { nextButton->hide(); return; }
117 else nextButton->show();
118 if(!previousButton->isEnabled()) totalWidth += previousButton->minimumWidth();
119 if(width() < totalWidth) { previousButton->hide(); return; }
120 else previousButton->show();
121
122}
123
124void PlayControl::updateWidths()
125{
126 int maxWidth = 18;
127 int totalWidth = 18;
128 totalWidth += playPauseButton->minimumWidth();
129 if(recordButton->isEnabled())
130 {
131 totalWidth += recordButton->minimumWidth();
132 }
133 setMinimumWidth(totalWidth);
134 maxWidth += backwardButton->minimumWidth();
135 maxWidth += previousButton->minimumWidth();
136 maxWidth += playPauseButton->minimumWidth();
137 maxWidth += stopButton->minimumWidth();
138 maxWidth += nextButton->minimumWidth();
139 maxWidth += recordButton->minimumWidth();
140 maxWidth += forwardButton->minimumWidth();
141 if(recordButton->isEnabled())
142 setMaximumWidth(maxWidth);
143 else
144 setMaximumWidth(maxWidth - recordButton->minimumWidth());
145 updateSize();
146}
147
148void PlayControl::setActionCollection(QList<QAction *> actions)
149{
150 /*
151 MyAction *a = static_cast<MyAction*>(actions.at(2));
152 qDebug("*** action: %s", a->objectName().toLatin1().constData());
153 */
154
155 SETACTIONTOBUTTON(backwardButton, "rewind1");
156 SETACTIONTOBUTTON(previousButton, "play_prev");
157 SETACTIONTOBUTTON(playPauseButton, "play_or_pause");
158 SETACTIONTOBUTTON(stopButton, "stop");
159 SETACTIONTOBUTTON(recordButton, "record");
160 SETACTIONTOBUTTON(nextButton, "play_next");
161 SETACTIONTOBUTTON(forwardButton, "forward1");
162
163 retranslateStrings();
164}
165
166bool PlayControl::eventFilter(QObject *watched, QEvent *event)
167{
168 if((watched == recordButton || watched == previousButton || watched == nextButton ) && event->type() == QEvent::EnabledChange)
169 {
170 updateWidths();
171 }
172 return false;
173}
174
175// Language change stuff
176void PlayControl::changeEvent(QEvent *e) {
177 if (e->type() == QEvent::LanguageChange) {
178 retranslateStrings();
179 } else {
180 QWidget::changeEvent(e);
181 }
182}
183
184void PlayControl::retranslateStrings() {
185 if (backwardButton) backwardButton->setToolTip(tr("Rewind"));
186 if (forwardButton) forwardButton->setToolTip(tr("Forward"));
187 if (playPauseButton) playPauseButton->setToolTip(tr("Play / Pause"));
188 if (stopButton) stopButton->setToolTip(tr("Stop"));
189 if (recordButton) recordButton->setToolTip(tr("Record"));
190 if (nextButton) nextButton->setToolTip(tr("Next file in playlist"));
191 if (previousButton) previousButton->setToolTip(tr("Previous file in playlist"));
192}
193
194#include "moc_playcontrol.cpp"
Note: See TracBrowser for help on using the repository browser.