1 | /* smplayer, GUI front-end for mplayer.
|
---|
2 | Copyright (C) 2006-2017 Ricardo Villalba <rvm@users.sourceforge.net>
|
---|
3 |
|
---|
4 | This program is free software; you can redistribute it and/or modify
|
---|
5 | it under the terms of the GNU General Public License as published by
|
---|
6 | the Free Software Foundation; either version 2 of the License, or
|
---|
7 | (at your option) any later version.
|
---|
8 |
|
---|
9 | This program is distributed in the hope that it will be useful,
|
---|
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
12 | GNU General Public License for more details.
|
---|
13 |
|
---|
14 | You should have received a copy of the GNU General Public License
|
---|
15 | along with this program; if not, write to the Free Software
|
---|
16 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
17 | */
|
---|
18 |
|
---|
19 | #include "minigui.h"
|
---|
20 | #include "widgetactions.h"
|
---|
21 | #include "autohidewidget.h"
|
---|
22 | #include "myaction.h"
|
---|
23 | #include "mplayerwindow.h"
|
---|
24 | #include "global.h"
|
---|
25 | #include "helper.h"
|
---|
26 | #include "desktopinfo.h"
|
---|
27 | #include "editabletoolbar.h"
|
---|
28 | #include "images.h"
|
---|
29 | #include <QStatusBar>
|
---|
30 | #include <QMenu>
|
---|
31 |
|
---|
32 | using namespace Global;
|
---|
33 |
|
---|
34 | MiniGui::MiniGui( QWidget * parent, Qt::WindowFlags flags )
|
---|
35 | : BaseGuiPlus( parent, flags )
|
---|
36 | {
|
---|
37 | createActions();
|
---|
38 | createControlWidget();
|
---|
39 | createFloatingControl();
|
---|
40 | populateMainMenu();
|
---|
41 |
|
---|
42 | #if USE_CONFIGURABLE_TOOLBARS
|
---|
43 | connect( editControlAct, SIGNAL(triggered()), controlwidget, SLOT(edit()) );
|
---|
44 | EditableToolbar * iw = static_cast<EditableToolbar *>(floating_control->internalWidget());
|
---|
45 | iw->takeAvailableActionsFrom(this);
|
---|
46 | connect( editFloatingControlAct, SIGNAL(triggered()), iw, SLOT(edit()) );
|
---|
47 | #endif
|
---|
48 |
|
---|
49 | statusBar()->hide();
|
---|
50 |
|
---|
51 | retranslateStrings();
|
---|
52 |
|
---|
53 | loadConfig();
|
---|
54 |
|
---|
55 | if (pref->compact_mode) {
|
---|
56 | controlwidget->hide();
|
---|
57 | }
|
---|
58 |
|
---|
59 | applyStyles();
|
---|
60 | }
|
---|
61 |
|
---|
62 | MiniGui::~MiniGui() {
|
---|
63 | saveConfig();
|
---|
64 | }
|
---|
65 |
|
---|
66 | #if USE_CONFIGURABLE_TOOLBARS
|
---|
67 | QMenu * MiniGui::createPopupMenu() {
|
---|
68 | QMenu * m = new QMenu(this);
|
---|
69 | m->addAction(editControlAct);
|
---|
70 | m->addAction(editFloatingControlAct);
|
---|
71 | return m;
|
---|
72 | }
|
---|
73 | #endif
|
---|
74 |
|
---|
75 | void MiniGui::createActions() {
|
---|
76 | timeslider_action = createTimeSliderAction(this);
|
---|
77 |
|
---|
78 | #if USE_VOLUME_BAR
|
---|
79 | volumeslider_action = createVolumeSliderAction(this);
|
---|
80 | #endif
|
---|
81 |
|
---|
82 | #if AUTODISABLE_ACTIONS
|
---|
83 | timeslider_action->disable();
|
---|
84 | #if USE_VOLUME_BAR
|
---|
85 | volumeslider_action->disable();
|
---|
86 | #endif
|
---|
87 | #endif
|
---|
88 |
|
---|
89 | time_label_action = createTimeLabelAction(TimeLabelAction::CurrentAndTotalTime, this);
|
---|
90 | time_label_action->setObjectName("timelabel_action");
|
---|
91 |
|
---|
92 | #if USE_CONFIGURABLE_TOOLBARS
|
---|
93 | editControlAct = new MyAction( this, "edit_control_minigui" );
|
---|
94 | editFloatingControlAct = new MyAction( this, "edit_floating_control_minigui" );
|
---|
95 | #endif
|
---|
96 | }
|
---|
97 |
|
---|
98 |
|
---|
99 | void MiniGui::createControlWidget() {
|
---|
100 | controlwidget = new EditableToolbar( this );
|
---|
101 | controlwidget->setObjectName("controlwidget");
|
---|
102 | controlwidget->setLayoutDirection(Qt::LeftToRight);
|
---|
103 | controlwidget->setMovable(true);
|
---|
104 | controlwidget->setAllowedAreas(Qt::TopToolBarArea | Qt::BottomToolBarArea);
|
---|
105 | addToolBar(Qt::BottomToolBarArea, controlwidget);
|
---|
106 |
|
---|
107 | #if USE_CONFIGURABLE_TOOLBARS
|
---|
108 | QStringList controlwidget_actions;
|
---|
109 | controlwidget_actions << "play_or_pause" << "stop" << "separator" << "timeslider_action" << "separator"
|
---|
110 | << "fullscreen" << "mute" << "volumeslider_action";
|
---|
111 | controlwidget->setDefaultActions(controlwidget_actions);
|
---|
112 | #else
|
---|
113 | controlwidget->addAction(playOrPauseAct);
|
---|
114 | controlwidget->addAction(stopAct);
|
---|
115 | controlwidget->addSeparator();
|
---|
116 | controlwidget->addAction(timeslider_action);
|
---|
117 | controlwidget->addSeparator();
|
---|
118 | controlwidget->addAction(fullscreenAct);
|
---|
119 | controlwidget->addAction(muteAct);
|
---|
120 | #if USE_VOLUME_BAR
|
---|
121 | controlwidget->addAction(volumeslider_action);
|
---|
122 | #endif
|
---|
123 | #endif // USE_CONFIGURABLE_TOOLBARS
|
---|
124 | }
|
---|
125 |
|
---|
126 | void MiniGui::createFloatingControl() {
|
---|
127 | // Floating control
|
---|
128 | floating_control = new AutohideWidget(mplayerwindow);
|
---|
129 | floating_control->setAutoHide(true);
|
---|
130 |
|
---|
131 | EditableToolbar * iw = new EditableToolbar(floating_control);
|
---|
132 | iw->setObjectName("floating_control");
|
---|
133 | connect(iw, SIGNAL(iconSizeChanged(const QSize &)), this, SLOT(adjustFloatingControlSize()));
|
---|
134 |
|
---|
135 | #if USE_CONFIGURABLE_TOOLBARS
|
---|
136 | QStringList floatingcontrol_actions;
|
---|
137 | floatingcontrol_actions << "play_or_pause" << "stop" << "separator" << "timeslider_action" << "separator"
|
---|
138 | << "fullscreen" << "mute";
|
---|
139 | #if USE_VOLUME_BAR
|
---|
140 | floatingcontrol_actions << "volumeslider_action";
|
---|
141 | #endif
|
---|
142 | floatingcontrol_actions << "separator" << "timelabel_action";
|
---|
143 | iw->setDefaultActions(floatingcontrol_actions);
|
---|
144 | #else
|
---|
145 | iw->addAction(playOrPauseAct);
|
---|
146 | iw->addAction(stopAct);
|
---|
147 | iw->addSeparator();
|
---|
148 | iw->addAction(timeslider_action);
|
---|
149 | iw->addSeparator();
|
---|
150 | iw->addAction(fullscreenAct);
|
---|
151 | iw->addAction(muteAct);
|
---|
152 | #if USE_VOLUME_BAR
|
---|
153 | iw->addAction(volumeslider_action);
|
---|
154 | #endif
|
---|
155 | #endif // USE_CONFIGURABLE_TOOLBARS
|
---|
156 |
|
---|
157 | floating_control->setInternalWidget(iw);
|
---|
158 |
|
---|
159 | #if !USE_CONFIGURABLE_TOOLBARS
|
---|
160 | floating_control->adjustSize();
|
---|
161 | #endif
|
---|
162 |
|
---|
163 | floating_control->hide();
|
---|
164 | }
|
---|
165 |
|
---|
166 | void MiniGui::retranslateStrings() {
|
---|
167 | BaseGuiPlus::retranslateStrings();
|
---|
168 |
|
---|
169 | // Change the icon of the play/pause action
|
---|
170 | playOrPauseAct->setIcon(Images::icon("play"));
|
---|
171 |
|
---|
172 | controlwidget->setWindowTitle( tr("Control bar") );
|
---|
173 |
|
---|
174 | #if USE_CONFIGURABLE_TOOLBARS
|
---|
175 | editControlAct->change( tr("Edit &control bar") );
|
---|
176 | editFloatingControlAct->change( tr("Edit &floating control") );
|
---|
177 | #endif
|
---|
178 | }
|
---|
179 |
|
---|
180 | #if AUTODISABLE_ACTIONS
|
---|
181 | void MiniGui::enableActionsOnPlaying() {
|
---|
182 | BaseGuiPlus::enableActionsOnPlaying();
|
---|
183 |
|
---|
184 | timeslider_action->enable();
|
---|
185 | #if USE_VOLUME_BAR
|
---|
186 | volumeslider_action->enable();
|
---|
187 | #endif
|
---|
188 | }
|
---|
189 |
|
---|
190 | void MiniGui::disableActionsOnStop() {
|
---|
191 | BaseGuiPlus::disableActionsOnStop();
|
---|
192 |
|
---|
193 | timeslider_action->disable();
|
---|
194 | #if USE_VOLUME_BAR
|
---|
195 | volumeslider_action->disable();
|
---|
196 | #endif
|
---|
197 | }
|
---|
198 | #endif // AUTODISABLE_ACTIONS
|
---|
199 |
|
---|
200 | void MiniGui::togglePlayAction(Core::State state) {
|
---|
201 | qDebug("MiniGui::togglePlayAction");
|
---|
202 | BaseGui::togglePlayAction(state);
|
---|
203 |
|
---|
204 | if (state == Core::Playing) {
|
---|
205 | playOrPauseAct->setIcon(Images::icon("pause"));
|
---|
206 | } else {
|
---|
207 | playOrPauseAct->setIcon(Images::icon("play"));
|
---|
208 | }
|
---|
209 | }
|
---|
210 |
|
---|
211 | void MiniGui::aboutToEnterFullscreen() {
|
---|
212 | BaseGuiPlus::aboutToEnterFullscreen();
|
---|
213 |
|
---|
214 | floating_control->setMargin(pref->floating_control_margin);
|
---|
215 | floating_control->setPercWidth(pref->floating_control_width);
|
---|
216 | floating_control->setAnimated(pref->floating_control_animated);
|
---|
217 | floating_control->setActivationArea( (AutohideWidget::Activation) pref->floating_activation_area);
|
---|
218 | floating_control->setHideDelay(pref->floating_hide_delay);
|
---|
219 | QTimer::singleShot(100, floating_control, SLOT(activate()));
|
---|
220 |
|
---|
221 | if (!pref->compact_mode) {
|
---|
222 | controlwidget->hide();
|
---|
223 | }
|
---|
224 | }
|
---|
225 |
|
---|
226 | void MiniGui::aboutToExitFullscreen() {
|
---|
227 | BaseGuiPlus::aboutToExitFullscreen();
|
---|
228 |
|
---|
229 | floating_control->deactivate();
|
---|
230 | //floating_control->hide();
|
---|
231 |
|
---|
232 | if (!pref->compact_mode) {
|
---|
233 | statusBar()->hide();
|
---|
234 | controlwidget->show();
|
---|
235 | }
|
---|
236 | }
|
---|
237 |
|
---|
238 | void MiniGui::aboutToEnterCompactMode() {
|
---|
239 | BaseGuiPlus::aboutToEnterCompactMode();
|
---|
240 |
|
---|
241 | controlwidget->hide();
|
---|
242 | }
|
---|
243 |
|
---|
244 | void MiniGui::aboutToExitCompactMode() {
|
---|
245 | BaseGuiPlus::aboutToExitCompactMode();
|
---|
246 |
|
---|
247 | statusBar()->hide();
|
---|
248 |
|
---|
249 | controlwidget->show();
|
---|
250 | }
|
---|
251 |
|
---|
252 | #if USE_MINIMUMSIZE
|
---|
253 | QSize MiniGui::minimumSizeHint() const {
|
---|
254 | return QSize(controlwidget->sizeHint().width(), 0);
|
---|
255 | }
|
---|
256 | #endif
|
---|
257 |
|
---|
258 | void MiniGui::adjustFloatingControlSize() {
|
---|
259 | qDebug("MiniGui::adjustFloatingControlSize");
|
---|
260 | //floating_control->adjustSize();
|
---|
261 | QWidget *iw = floating_control->internalWidget();
|
---|
262 | QSize iws = iw->size();
|
---|
263 | QMargins m = floating_control->contentsMargins();
|
---|
264 | int new_height = iws.height() + m.top() + m.bottom();
|
---|
265 | if (new_height < 32) new_height = 32;
|
---|
266 | floating_control->resize(floating_control->width(), new_height);
|
---|
267 | }
|
---|
268 |
|
---|
269 | void MiniGui::saveConfig() {
|
---|
270 | QSettings * set = settings;
|
---|
271 |
|
---|
272 | set->beginGroup( "mini_gui");
|
---|
273 |
|
---|
274 | if (pref->save_window_size_on_exit) {
|
---|
275 | qDebug("MiniGui::saveConfig: w: %d h: %d", width(), height());
|
---|
276 | set->setValue( "pos", pos() );
|
---|
277 | set->setValue( "size", size() );
|
---|
278 | set->setValue( "state", (int) windowState() );
|
---|
279 | }
|
---|
280 |
|
---|
281 | set->setValue( "toolbars_state", saveState(Helper::qtVersion()) );
|
---|
282 |
|
---|
283 | #if USE_CONFIGURABLE_TOOLBARS
|
---|
284 | set->beginGroup( "actions" );
|
---|
285 | set->setValue("controlwidget", controlwidget->actionsToStringList() );
|
---|
286 | EditableToolbar * iw = static_cast<EditableToolbar *>(floating_control->internalWidget());
|
---|
287 | set->setValue("floating_control", iw->actionsToStringList() );
|
---|
288 | set->endGroup();
|
---|
289 |
|
---|
290 | set->beginGroup("toolbars_icon_size");
|
---|
291 | set->setValue("controlwidget", controlwidget->iconSize());
|
---|
292 | set->setValue("floating_control", iw->iconSize());
|
---|
293 | set->endGroup();
|
---|
294 | #endif
|
---|
295 |
|
---|
296 | set->endGroup();
|
---|
297 | }
|
---|
298 |
|
---|
299 | void MiniGui::loadConfig() {
|
---|
300 | QSettings * set = settings;
|
---|
301 |
|
---|
302 | set->beginGroup( "mini_gui");
|
---|
303 |
|
---|
304 | if (pref->save_window_size_on_exit) {
|
---|
305 | QPoint p = set->value("pos", pos()).toPoint();
|
---|
306 | QSize s = set->value("size", size()).toSize();
|
---|
307 |
|
---|
308 | if ( (s.height() < 200) && (!pref->use_mplayer_window) ) {
|
---|
309 | s = pref->default_size;
|
---|
310 | }
|
---|
311 |
|
---|
312 | move(p);
|
---|
313 | resize(s);
|
---|
314 |
|
---|
315 | setWindowState( (Qt::WindowStates) set->value("state", 0).toInt() );
|
---|
316 |
|
---|
317 | if (!DesktopInfo::isInsideScreen(this)) {
|
---|
318 | QPoint tl = DesktopInfo::topLeftPrimaryScreen();
|
---|
319 | move(tl);
|
---|
320 | qWarning("DefaultGui::loadConfig: window is outside of the screen, moved to %d x %d", tl.x(), tl.y());
|
---|
321 | }
|
---|
322 | }
|
---|
323 |
|
---|
324 | #if USE_CONFIGURABLE_TOOLBARS
|
---|
325 | set->beginGroup( "actions" );
|
---|
326 | controlwidget->setActionsFromStringList( set->value("controlwidget", controlwidget->defaultActions()).toStringList() );
|
---|
327 | EditableToolbar * iw = static_cast<EditableToolbar *>(floating_control->internalWidget());
|
---|
328 | iw->setActionsFromStringList( set->value("floating_control", iw->defaultActions()).toStringList() );
|
---|
329 | set->endGroup();
|
---|
330 |
|
---|
331 | set->beginGroup("toolbars_icon_size");
|
---|
332 | controlwidget->setIconSize(set->value("controlwidget", controlwidget->iconSize()).toSize());
|
---|
333 | iw->setIconSize(set->value("floating_control", iw->iconSize()).toSize());
|
---|
334 | set->endGroup();
|
---|
335 |
|
---|
336 | floating_control->adjustSize();
|
---|
337 | #endif
|
---|
338 |
|
---|
339 | restoreState( set->value( "toolbars_state" ).toByteArray(), Helper::qtVersion() );
|
---|
340 |
|
---|
341 | set->endGroup();
|
---|
342 | }
|
---|
343 |
|
---|
344 | #include "moc_minigui.cpp"
|
---|
345 |
|
---|