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