| 1 | /* smplayer, GUI front-end for mplayer.
|
|---|
| 2 | Copyright (C) 2006-2012 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 "floatingwidget.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()),
|
|---|
| 42 | controlwidget, SLOT(edit()) );
|
|---|
| 43 | floating_control->toolbar()->takeAvailableActionsFrom(this);
|
|---|
| 44 | connect( editFloatingControlAct, SIGNAL(triggered()),
|
|---|
| 45 | floating_control->toolbar(), SLOT(edit()) );
|
|---|
| 46 | #endif
|
|---|
| 47 |
|
|---|
| 48 | connect( this, SIGNAL(cursorNearBottom(QPoint)),
|
|---|
| 49 | this, SLOT(showFloatingControl(QPoint)) );
|
|---|
| 50 |
|
|---|
| 51 | connect( this, SIGNAL(cursorFarEdges()),
|
|---|
| 52 | this, SLOT(hideFloatingControl()) );
|
|---|
| 53 |
|
|---|
| 54 | statusBar()->hide();
|
|---|
| 55 |
|
|---|
| 56 | retranslateStrings();
|
|---|
| 57 |
|
|---|
| 58 | loadConfig();
|
|---|
| 59 |
|
|---|
| 60 | if (pref->compact_mode) {
|
|---|
| 61 | controlwidget->hide();
|
|---|
| 62 | }
|
|---|
| 63 | }
|
|---|
| 64 |
|
|---|
| 65 | MiniGui::~MiniGui() {
|
|---|
| 66 | saveConfig();
|
|---|
| 67 | }
|
|---|
| 68 |
|
|---|
| 69 | #if USE_CONFIGURABLE_TOOLBARS
|
|---|
| 70 | QMenu * MiniGui::createPopupMenu() {
|
|---|
| 71 | QMenu * m = new QMenu(this);
|
|---|
| 72 | m->addAction(editControlAct);
|
|---|
| 73 | m->addAction(editFloatingControlAct);
|
|---|
| 74 | return m;
|
|---|
| 75 | }
|
|---|
| 76 | #endif
|
|---|
| 77 |
|
|---|
| 78 | void MiniGui::createActions() {
|
|---|
| 79 | timeslider_action = createTimeSliderAction(this);
|
|---|
| 80 | timeslider_action->disable();
|
|---|
| 81 |
|
|---|
| 82 | #if USE_VOLUME_BAR
|
|---|
| 83 | volumeslider_action = createVolumeSliderAction(this);
|
|---|
| 84 | volumeslider_action->disable();
|
|---|
| 85 | #endif
|
|---|
| 86 |
|
|---|
| 87 | time_label_action = new TimeLabelAction(this);
|
|---|
| 88 | time_label_action->setObjectName("timelabel_action");
|
|---|
| 89 |
|
|---|
| 90 | connect( this, SIGNAL(timeChanged(QString)),
|
|---|
| 91 | time_label_action, SLOT(setText(QString)) );
|
|---|
| 92 |
|
|---|
| 93 | #if USE_CONFIGURABLE_TOOLBARS
|
|---|
| 94 | editControlAct = new MyAction( this, "edit_control_minigui" );
|
|---|
| 95 | editFloatingControlAct = new MyAction( this, "edit_floating_control_minigui" );
|
|---|
| 96 | #endif
|
|---|
| 97 | }
|
|---|
| 98 |
|
|---|
| 99 |
|
|---|
| 100 | void MiniGui::createControlWidget() {
|
|---|
| 101 | controlwidget = new EditableToolbar( this );
|
|---|
| 102 | controlwidget->setObjectName("controlwidget");
|
|---|
| 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 FloatingWidget(this);
|
|---|
| 129 |
|
|---|
| 130 | #if USE_CONFIGURABLE_TOOLBARS
|
|---|
| 131 | QStringList floatingcontrol_actions;
|
|---|
| 132 | floatingcontrol_actions << "play_or_pause" << "stop" << "separator" << "timeslider_action" << "separator"
|
|---|
| 133 | << "fullscreen" << "mute";
|
|---|
| 134 | #if USE_VOLUME_BAR
|
|---|
| 135 | floatingcontrol_actions << "volumeslider_action";
|
|---|
| 136 | #endif
|
|---|
| 137 | floatingcontrol_actions << "separator" << "timelabel_action";
|
|---|
| 138 | floating_control->toolbar()->setDefaultActions(floatingcontrol_actions);
|
|---|
| 139 | #else
|
|---|
| 140 | floating_control->toolbar()->addAction(playOrPauseAct);
|
|---|
| 141 | floating_control->toolbar()->addAction(stopAct);
|
|---|
| 142 | floating_control->toolbar()->addSeparator();
|
|---|
| 143 | floating_control->toolbar()->addAction(timeslider_action);
|
|---|
| 144 | floating_control->toolbar()->addSeparator();
|
|---|
| 145 | floating_control->toolbar()->addAction(fullscreenAct);
|
|---|
| 146 | floating_control->toolbar()->addAction(muteAct);
|
|---|
| 147 | #if USE_VOLUME_BAR
|
|---|
| 148 | floating_control->toolbar()->addAction(volumeslider_action);
|
|---|
| 149 | #endif
|
|---|
| 150 | floating_control->adjustSize();
|
|---|
| 151 | #endif // USE_CONFIGURABLE_TOOLBARS
|
|---|
| 152 | }
|
|---|
| 153 |
|
|---|
| 154 | void MiniGui::retranslateStrings() {
|
|---|
| 155 | BaseGuiPlus::retranslateStrings();
|
|---|
| 156 |
|
|---|
| 157 | controlwidget->setWindowTitle( tr("Control bar") );
|
|---|
| 158 |
|
|---|
| 159 | #if USE_CONFIGURABLE_TOOLBARS
|
|---|
| 160 | editControlAct->change( tr("Edit &control bar") );
|
|---|
| 161 | editFloatingControlAct->change( tr("Edit &floating control") );
|
|---|
| 162 | #endif
|
|---|
| 163 | }
|
|---|
| 164 |
|
|---|
| 165 | #if AUTODISABLE_ACTIONS
|
|---|
| 166 | void MiniGui::enableActionsOnPlaying() {
|
|---|
| 167 | BaseGuiPlus::enableActionsOnPlaying();
|
|---|
| 168 |
|
|---|
| 169 | timeslider_action->enable();
|
|---|
| 170 | #if USE_VOLUME_BAR
|
|---|
| 171 | volumeslider_action->enable();
|
|---|
| 172 | #endif
|
|---|
| 173 | }
|
|---|
| 174 |
|
|---|
| 175 | void MiniGui::disableActionsOnStop() {
|
|---|
| 176 | BaseGuiPlus::disableActionsOnStop();
|
|---|
| 177 |
|
|---|
| 178 | timeslider_action->disable();
|
|---|
| 179 | #if USE_VOLUME_BAR
|
|---|
| 180 | volumeslider_action->disable();
|
|---|
| 181 | #endif
|
|---|
| 182 | }
|
|---|
| 183 | #endif // AUTODISABLE_ACTIONS
|
|---|
| 184 |
|
|---|
| 185 | void MiniGui::aboutToEnterFullscreen() {
|
|---|
| 186 | BaseGuiPlus::aboutToEnterFullscreen();
|
|---|
| 187 |
|
|---|
| 188 | if (!pref->compact_mode) {
|
|---|
| 189 | controlwidget->hide();
|
|---|
| 190 | }
|
|---|
| 191 | }
|
|---|
| 192 |
|
|---|
| 193 | void MiniGui::aboutToExitFullscreen() {
|
|---|
| 194 | BaseGuiPlus::aboutToExitFullscreen();
|
|---|
| 195 |
|
|---|
| 196 | floating_control->hide();
|
|---|
| 197 |
|
|---|
| 198 | if (!pref->compact_mode) {
|
|---|
| 199 | statusBar()->hide();
|
|---|
| 200 | controlwidget->show();
|
|---|
| 201 | }
|
|---|
| 202 | }
|
|---|
| 203 |
|
|---|
| 204 | void MiniGui::aboutToEnterCompactMode() {
|
|---|
| 205 | BaseGuiPlus::aboutToEnterCompactMode();
|
|---|
| 206 |
|
|---|
| 207 | controlwidget->hide();
|
|---|
| 208 | }
|
|---|
| 209 |
|
|---|
| 210 | void MiniGui::aboutToExitCompactMode() {
|
|---|
| 211 | BaseGuiPlus::aboutToExitCompactMode();
|
|---|
| 212 |
|
|---|
| 213 | statusBar()->hide();
|
|---|
| 214 |
|
|---|
| 215 | controlwidget->show();
|
|---|
| 216 | }
|
|---|
| 217 |
|
|---|
| 218 | void MiniGui::showFloatingControl(QPoint /*p*/) {
|
|---|
| 219 | #ifndef Q_OS_WIN
|
|---|
| 220 | floating_control->setBypassWindowManager(pref->bypass_window_manager);
|
|---|
| 221 | #endif
|
|---|
| 222 | floating_control->setAnimated( pref->floating_control_animated );
|
|---|
| 223 | floating_control->setMargin(pref->floating_control_margin);
|
|---|
| 224 | floating_control->showOver(panel,
|
|---|
| 225 | pref->floating_control_width,
|
|---|
| 226 | FloatingWidget::Bottom);
|
|---|
| 227 | }
|
|---|
| 228 |
|
|---|
| 229 | void MiniGui::hideFloatingControl() {
|
|---|
| 230 | floating_control->hide();
|
|---|
| 231 | }
|
|---|
| 232 |
|
|---|
| 233 | #if USE_MINIMUMSIZE
|
|---|
| 234 | QSize MiniGui::minimumSizeHint() const {
|
|---|
| 235 | return QSize(controlwidget->sizeHint().width(), 0);
|
|---|
| 236 | }
|
|---|
| 237 | #endif
|
|---|
| 238 |
|
|---|
| 239 |
|
|---|
| 240 | void MiniGui::saveConfig() {
|
|---|
| 241 | QSettings * set = settings;
|
|---|
| 242 |
|
|---|
| 243 | set->beginGroup( "mini_gui");
|
|---|
| 244 |
|
|---|
| 245 | if (pref->save_window_size_on_exit) {
|
|---|
| 246 | qDebug("MiniGui::saveConfig: w: %d h: %d", width(), height());
|
|---|
| 247 | set->setValue( "pos", pos() );
|
|---|
| 248 | set->setValue( "size", size() );
|
|---|
| 249 | }
|
|---|
| 250 |
|
|---|
| 251 | set->setValue( "toolbars_state", saveState(Helper::qtVersion()) );
|
|---|
| 252 |
|
|---|
| 253 | #if USE_CONFIGURABLE_TOOLBARS
|
|---|
| 254 | set->beginGroup( "actions" );
|
|---|
| 255 | set->setValue("controlwidget", controlwidget->actionsToStringList() );
|
|---|
| 256 | set->setValue("floating_control", floating_control->toolbar()->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 | if (!DesktopInfo::isInsideScreen(this)) {
|
|---|
| 280 | move(0,0);
|
|---|
| 281 | qWarning("MiniGui::loadConfig: window is outside of the screen, moved to 0x0");
|
|---|
| 282 | }
|
|---|
| 283 | }
|
|---|
| 284 |
|
|---|
| 285 | #if USE_CONFIGURABLE_TOOLBARS
|
|---|
| 286 | set->beginGroup( "actions" );
|
|---|
| 287 | controlwidget->setActionsFromStringList( set->value("controlwidget", controlwidget->defaultActions()).toStringList() );
|
|---|
| 288 | floating_control->toolbar()->setActionsFromStringList( set->value("floating_control", floating_control->toolbar()->defaultActions()).toStringList() );
|
|---|
| 289 | floating_control->adjustSize();
|
|---|
| 290 | set->endGroup();
|
|---|
| 291 | #endif
|
|---|
| 292 |
|
|---|
| 293 | restoreState( set->value( "toolbars_state" ).toByteArray(), Helper::qtVersion() );
|
|---|
| 294 |
|
|---|
| 295 | set->endGroup();
|
|---|
| 296 | }
|
|---|
| 297 |
|
|---|
| 298 | #include "moc_minigui.cpp"
|
|---|
| 299 |
|
|---|