1 | /* smplayer, GUI front-end for mplayer.
|
---|
2 | Copyright (C) 2006-2014 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 <QStatusBar>
|
---|
29 | #include <QMenu>
|
---|
30 |
|
---|
31 | using namespace Global;
|
---|
32 |
|
---|
33 | MiniGui::MiniGui( QWidget * parent, Qt::WindowFlags flags )
|
---|
34 | : BaseGuiPlus( parent, flags )
|
---|
35 | {
|
---|
36 | createActions();
|
---|
37 | createControlWidget();
|
---|
38 | createFloatingControl();
|
---|
39 |
|
---|
40 | #if USE_CONFIGURABLE_TOOLBARS
|
---|
41 | connect( editControlAct, SIGNAL(triggered()), controlwidget, SLOT(edit()) );
|
---|
42 | EditableToolbar * iw = static_cast<EditableToolbar *>(floating_control->internalWidget());
|
---|
43 | iw->takeAvailableActionsFrom(this);
|
---|
44 | connect( editFloatingControlAct, SIGNAL(triggered()), iw, SLOT(edit()) );
|
---|
45 | #endif
|
---|
46 |
|
---|
47 | statusBar()->hide();
|
---|
48 |
|
---|
49 | retranslateStrings();
|
---|
50 |
|
---|
51 | loadConfig();
|
---|
52 |
|
---|
53 | if (pref->compact_mode) {
|
---|
54 | controlwidget->hide();
|
---|
55 | }
|
---|
56 | }
|
---|
57 |
|
---|
58 | MiniGui::~MiniGui() {
|
---|
59 | saveConfig();
|
---|
60 | }
|
---|
61 |
|
---|
62 | #if USE_CONFIGURABLE_TOOLBARS
|
---|
63 | QMenu * MiniGui::createPopupMenu() {
|
---|
64 | QMenu * m = new QMenu(this);
|
---|
65 | m->addAction(editControlAct);
|
---|
66 | m->addAction(editFloatingControlAct);
|
---|
67 | return m;
|
---|
68 | }
|
---|
69 | #endif
|
---|
70 |
|
---|
71 | void MiniGui::createActions() {
|
---|
72 | timeslider_action = createTimeSliderAction(this);
|
---|
73 | timeslider_action->disable();
|
---|
74 |
|
---|
75 | #if USE_VOLUME_BAR
|
---|
76 | volumeslider_action = createVolumeSliderAction(this);
|
---|
77 | volumeslider_action->disable();
|
---|
78 | #endif
|
---|
79 |
|
---|
80 | time_label_action = new TimeLabelAction(this);
|
---|
81 | time_label_action->setObjectName("timelabel_action");
|
---|
82 |
|
---|
83 | connect( this, SIGNAL(timeChanged(QString)),
|
---|
84 | time_label_action, SLOT(setText(QString)) );
|
---|
85 |
|
---|
86 | #if USE_CONFIGURABLE_TOOLBARS
|
---|
87 | editControlAct = new MyAction( this, "edit_control_minigui" );
|
---|
88 | editFloatingControlAct = new MyAction( this, "edit_floating_control_minigui" );
|
---|
89 | #endif
|
---|
90 | }
|
---|
91 |
|
---|
92 |
|
---|
93 | void MiniGui::createControlWidget() {
|
---|
94 | controlwidget = new EditableToolbar( this );
|
---|
95 | controlwidget->setObjectName("controlwidget");
|
---|
96 | controlwidget->setLayoutDirection(Qt::LeftToRight);
|
---|
97 | controlwidget->setMovable(true);
|
---|
98 | controlwidget->setAllowedAreas(Qt::TopToolBarArea | Qt::BottomToolBarArea);
|
---|
99 | addToolBar(Qt::BottomToolBarArea, controlwidget);
|
---|
100 |
|
---|
101 | #if USE_CONFIGURABLE_TOOLBARS
|
---|
102 | QStringList controlwidget_actions;
|
---|
103 | controlwidget_actions << "play_or_pause" << "stop" << "separator" << "timeslider_action" << "separator"
|
---|
104 | << "fullscreen" << "mute" << "volumeslider_action";
|
---|
105 | controlwidget->setDefaultActions(controlwidget_actions);
|
---|
106 | #else
|
---|
107 | controlwidget->addAction(playOrPauseAct);
|
---|
108 | controlwidget->addAction(stopAct);
|
---|
109 | controlwidget->addSeparator();
|
---|
110 | controlwidget->addAction(timeslider_action);
|
---|
111 | controlwidget->addSeparator();
|
---|
112 | controlwidget->addAction(fullscreenAct);
|
---|
113 | controlwidget->addAction(muteAct);
|
---|
114 | #if USE_VOLUME_BAR
|
---|
115 | controlwidget->addAction(volumeslider_action);
|
---|
116 | #endif
|
---|
117 | #endif // USE_CONFIGURABLE_TOOLBARS
|
---|
118 | }
|
---|
119 |
|
---|
120 | void MiniGui::createFloatingControl() {
|
---|
121 | // Floating control
|
---|
122 | floating_control = new AutohideWidget(panel);
|
---|
123 | floating_control->setAutoHide(true);
|
---|
124 |
|
---|
125 | EditableToolbar * iw = new EditableToolbar(floating_control);
|
---|
126 | iw->setObjectName("floating_control");
|
---|
127 |
|
---|
128 | #if USE_CONFIGURABLE_TOOLBARS
|
---|
129 | QStringList floatingcontrol_actions;
|
---|
130 | floatingcontrol_actions << "play_or_pause" << "stop" << "separator" << "timeslider_action" << "separator"
|
---|
131 | << "fullscreen" << "mute";
|
---|
132 | #if USE_VOLUME_BAR
|
---|
133 | floatingcontrol_actions << "volumeslider_action";
|
---|
134 | #endif
|
---|
135 | floatingcontrol_actions << "separator" << "timelabel_action";
|
---|
136 | iw->setDefaultActions(floatingcontrol_actions);
|
---|
137 | #else
|
---|
138 | iw->addAction(playOrPauseAct);
|
---|
139 | iw->addAction(stopAct);
|
---|
140 | iw->addSeparator();
|
---|
141 | iw->addAction(timeslider_action);
|
---|
142 | iw->addSeparator();
|
---|
143 | iw->addAction(fullscreenAct);
|
---|
144 | iw->addAction(muteAct);
|
---|
145 | #if USE_VOLUME_BAR
|
---|
146 | iw->addAction(volumeslider_action);
|
---|
147 | #endif
|
---|
148 | #endif // USE_CONFIGURABLE_TOOLBARS
|
---|
149 |
|
---|
150 | floating_control->setInternalWidget(iw);
|
---|
151 |
|
---|
152 | #if !USE_CONFIGURABLE_TOOLBARS
|
---|
153 | floating_control->adjustSize();
|
---|
154 | #endif
|
---|
155 |
|
---|
156 | floating_control->hide();
|
---|
157 | }
|
---|
158 |
|
---|
159 | void MiniGui::retranslateStrings() {
|
---|
160 | BaseGuiPlus::retranslateStrings();
|
---|
161 |
|
---|
162 | controlwidget->setWindowTitle( tr("Control bar") );
|
---|
163 |
|
---|
164 | #if USE_CONFIGURABLE_TOOLBARS
|
---|
165 | editControlAct->change( tr("Edit &control bar") );
|
---|
166 | editFloatingControlAct->change( tr("Edit &floating control") );
|
---|
167 | #endif
|
---|
168 | }
|
---|
169 |
|
---|
170 | #if AUTODISABLE_ACTIONS
|
---|
171 | void MiniGui::enableActionsOnPlaying() {
|
---|
172 | BaseGuiPlus::enableActionsOnPlaying();
|
---|
173 |
|
---|
174 | timeslider_action->enable();
|
---|
175 | #if USE_VOLUME_BAR
|
---|
176 | volumeslider_action->enable();
|
---|
177 | #endif
|
---|
178 | }
|
---|
179 |
|
---|
180 | void MiniGui::disableActionsOnStop() {
|
---|
181 | BaseGuiPlus::disableActionsOnStop();
|
---|
182 |
|
---|
183 | timeslider_action->disable();
|
---|
184 | #if USE_VOLUME_BAR
|
---|
185 | volumeslider_action->disable();
|
---|
186 | #endif
|
---|
187 | }
|
---|
188 | #endif // AUTODISABLE_ACTIONS
|
---|
189 |
|
---|
190 | void MiniGui::aboutToEnterFullscreen() {
|
---|
191 | BaseGuiPlus::aboutToEnterFullscreen();
|
---|
192 |
|
---|
193 | floating_control->setMargin(pref->floating_control_margin);
|
---|
194 | floating_control->setPercWidth(pref->floating_control_width);
|
---|
195 | floating_control->setAnimated(pref->floating_control_animated);
|
---|
196 | floating_control->setActivationArea( (AutohideWidget::Activation) pref->floating_activation_area);
|
---|
197 | floating_control->setHideDelay(pref->floating_hide_delay);
|
---|
198 | QTimer::singleShot(500, floating_control, SLOT(activate()));
|
---|
199 |
|
---|
200 | if (!pref->compact_mode) {
|
---|
201 | controlwidget->hide();
|
---|
202 | }
|
---|
203 | }
|
---|
204 |
|
---|
205 | void MiniGui::aboutToExitFullscreen() {
|
---|
206 | BaseGuiPlus::aboutToExitFullscreen();
|
---|
207 |
|
---|
208 | floating_control->deactivate();
|
---|
209 | //floating_control->hide();
|
---|
210 |
|
---|
211 | if (!pref->compact_mode) {
|
---|
212 | statusBar()->hide();
|
---|
213 | controlwidget->show();
|
---|
214 | }
|
---|
215 | }
|
---|
216 |
|
---|
217 | void MiniGui::aboutToEnterCompactMode() {
|
---|
218 | BaseGuiPlus::aboutToEnterCompactMode();
|
---|
219 |
|
---|
220 | controlwidget->hide();
|
---|
221 | }
|
---|
222 |
|
---|
223 | void MiniGui::aboutToExitCompactMode() {
|
---|
224 | BaseGuiPlus::aboutToExitCompactMode();
|
---|
225 |
|
---|
226 | statusBar()->hide();
|
---|
227 |
|
---|
228 | controlwidget->show();
|
---|
229 | }
|
---|
230 |
|
---|
231 | #if USE_MINIMUMSIZE
|
---|
232 | QSize MiniGui::minimumSizeHint() const {
|
---|
233 | return QSize(controlwidget->sizeHint().width(), 0);
|
---|
234 | }
|
---|
235 | #endif
|
---|
236 |
|
---|
237 |
|
---|
238 | void MiniGui::saveConfig() {
|
---|
239 | QSettings * set = settings;
|
---|
240 |
|
---|
241 | set->beginGroup( "mini_gui");
|
---|
242 |
|
---|
243 | if (pref->save_window_size_on_exit) {
|
---|
244 | qDebug("MiniGui::saveConfig: w: %d h: %d", width(), height());
|
---|
245 | set->setValue( "pos", pos() );
|
---|
246 | set->setValue( "size", size() );
|
---|
247 | set->setValue( "state", (int) windowState() );
|
---|
248 | }
|
---|
249 |
|
---|
250 | set->setValue( "toolbars_state", saveState(Helper::qtVersion()) );
|
---|
251 |
|
---|
252 | #if USE_CONFIGURABLE_TOOLBARS
|
---|
253 | set->beginGroup( "actions" );
|
---|
254 | set->setValue("controlwidget", controlwidget->actionsToStringList() );
|
---|
255 | EditableToolbar * iw = static_cast<EditableToolbar *>(floating_control->internalWidget());
|
---|
256 | set->setValue("floating_control", iw->actionsToStringList() );
|
---|
257 | set->endGroup();
|
---|
258 | #endif
|
---|
259 |
|
---|
260 | set->endGroup();
|
---|
261 | }
|
---|
262 |
|
---|
263 | void MiniGui::loadConfig() {
|
---|
264 | QSettings * set = settings;
|
---|
265 |
|
---|
266 | set->beginGroup( "mini_gui");
|
---|
267 |
|
---|
268 | if (pref->save_window_size_on_exit) {
|
---|
269 | QPoint p = set->value("pos", pos()).toPoint();
|
---|
270 | QSize s = set->value("size", size()).toSize();
|
---|
271 |
|
---|
272 | if ( (s.height() < 200) && (!pref->use_mplayer_window) ) {
|
---|
273 | s = pref->default_size;
|
---|
274 | }
|
---|
275 |
|
---|
276 | move(p);
|
---|
277 | resize(s);
|
---|
278 |
|
---|
279 | setWindowState( (Qt::WindowStates) set->value("state", 0).toInt() );
|
---|
280 |
|
---|
281 | if (!DesktopInfo::isInsideScreen(this)) {
|
---|
282 | move(0,0);
|
---|
283 | qWarning("MiniGui::loadConfig: window is outside of the screen, moved to 0x0");
|
---|
284 | }
|
---|
285 | }
|
---|
286 |
|
---|
287 | #if USE_CONFIGURABLE_TOOLBARS
|
---|
288 | set->beginGroup( "actions" );
|
---|
289 | controlwidget->setActionsFromStringList( set->value("controlwidget", controlwidget->defaultActions()).toStringList() );
|
---|
290 | EditableToolbar * iw = static_cast<EditableToolbar *>(floating_control->internalWidget());
|
---|
291 | iw->setActionsFromStringList( set->value("floating_control", iw->defaultActions()).toStringList() );
|
---|
292 | floating_control->adjustSize();
|
---|
293 | set->endGroup();
|
---|
294 | #endif
|
---|
295 |
|
---|
296 | restoreState( set->value( "toolbars_state" ).toByteArray(), Helper::qtVersion() );
|
---|
297 |
|
---|
298 | set->endGroup();
|
---|
299 | }
|
---|
300 |
|
---|
301 | #include "moc_minigui.cpp"
|
---|
302 |
|
---|