| 1 | /* smplayer, GUI front-end for mplayer.
|
|---|
| 2 | Copyright (C) 2006-2011 Ricardo Villalba <rvm@escomposlinux.org>
|
|---|
| 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 "toolbareditor.h"
|
|---|
| 27 | #include "desktopinfo.h"
|
|---|
| 28 |
|
|---|
| 29 | #include <QToolBar>
|
|---|
| 30 | #include <QStatusBar>
|
|---|
| 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 | connect( this, SIGNAL(cursorNearBottom(QPoint)),
|
|---|
| 42 | this, SLOT(showFloatingControl(QPoint)) );
|
|---|
| 43 |
|
|---|
| 44 | connect( this, SIGNAL(cursorFarEdges()),
|
|---|
| 45 | this, SLOT(hideFloatingControl()) );
|
|---|
| 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 | void MiniGui::createActions() {
|
|---|
| 63 | timeslider_action = createTimeSliderAction(this);
|
|---|
| 64 | timeslider_action->disable();
|
|---|
| 65 |
|
|---|
| 66 | #if USE_VOLUME_BAR
|
|---|
| 67 | volumeslider_action = createVolumeSliderAction(this);
|
|---|
| 68 | volumeslider_action->disable();
|
|---|
| 69 | #endif
|
|---|
| 70 |
|
|---|
| 71 | time_label_action = new TimeLabelAction(this);
|
|---|
| 72 | time_label_action->setObjectName("timelabel_action");
|
|---|
| 73 |
|
|---|
| 74 | connect( this, SIGNAL(timeChanged(QString)),
|
|---|
| 75 | time_label_action, SLOT(setText(QString)) );
|
|---|
| 76 | }
|
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 | void MiniGui::createControlWidget() {
|
|---|
| 80 | controlwidget = new QToolBar( this );
|
|---|
| 81 | controlwidget->setObjectName("controlwidget");
|
|---|
| 82 | controlwidget->setMovable(true);
|
|---|
| 83 | controlwidget->setAllowedAreas(Qt::TopToolBarArea | Qt::BottomToolBarArea);
|
|---|
| 84 | addToolBar(Qt::BottomToolBarArea, controlwidget);
|
|---|
| 85 |
|
|---|
| 86 | #if !USE_CONFIGURABLE_TOOLBARS
|
|---|
| 87 | controlwidget->addAction(playOrPauseAct);
|
|---|
| 88 | controlwidget->addAction(stopAct);
|
|---|
| 89 | controlwidget->addSeparator();
|
|---|
| 90 | controlwidget->addAction(timeslider_action);
|
|---|
| 91 | controlwidget->addSeparator();
|
|---|
| 92 | controlwidget->addAction(fullscreenAct);
|
|---|
| 93 | controlwidget->addAction(muteAct);
|
|---|
| 94 |
|
|---|
| 95 | #if USE_VOLUME_BAR
|
|---|
| 96 | controlwidget->addAction(volumeslider_action);
|
|---|
| 97 | #endif
|
|---|
| 98 |
|
|---|
| 99 | #endif // USE_CONFIGURABLE_TOOLBARS
|
|---|
| 100 | }
|
|---|
| 101 |
|
|---|
| 102 | void MiniGui::createFloatingControl() {
|
|---|
| 103 | // Floating control
|
|---|
| 104 | floating_control = new FloatingWidget(this);
|
|---|
| 105 |
|
|---|
| 106 | #if !USE_CONFIGURABLE_TOOLBARS
|
|---|
| 107 | floating_control->toolbar()->addAction(playOrPauseAct);
|
|---|
| 108 | floating_control->toolbar()->addAction(stopAct);
|
|---|
| 109 | floating_control->toolbar()->addSeparator();
|
|---|
| 110 | floating_control->toolbar()->addAction(timeslider_action);
|
|---|
| 111 | floating_control->toolbar()->addSeparator();
|
|---|
| 112 | floating_control->toolbar()->addAction(fullscreenAct);
|
|---|
| 113 | floating_control->toolbar()->addAction(muteAct);
|
|---|
| 114 | #if USE_VOLUME_BAR
|
|---|
| 115 | floating_control->toolbar()->addAction(volumeslider_action);
|
|---|
| 116 | #endif
|
|---|
| 117 |
|
|---|
| 118 | floating_control->adjustSize();
|
|---|
| 119 | #endif // USE_CONFIGURABLE_TOOLBARS
|
|---|
| 120 | }
|
|---|
| 121 |
|
|---|
| 122 | void MiniGui::retranslateStrings() {
|
|---|
| 123 | BaseGuiPlus::retranslateStrings();
|
|---|
| 124 |
|
|---|
| 125 | controlwidget->setWindowTitle( tr("Control bar") );
|
|---|
| 126 | }
|
|---|
| 127 |
|
|---|
| 128 | #if AUTODISABLE_ACTIONS
|
|---|
| 129 | void MiniGui::enableActionsOnPlaying() {
|
|---|
| 130 | BaseGuiPlus::enableActionsOnPlaying();
|
|---|
| 131 |
|
|---|
| 132 | timeslider_action->enable();
|
|---|
| 133 | #if USE_VOLUME_BAR
|
|---|
| 134 | volumeslider_action->enable();
|
|---|
| 135 | #endif
|
|---|
| 136 | }
|
|---|
| 137 |
|
|---|
| 138 | void MiniGui::disableActionsOnStop() {
|
|---|
| 139 | BaseGuiPlus::disableActionsOnStop();
|
|---|
| 140 |
|
|---|
| 141 | timeslider_action->disable();
|
|---|
| 142 | #if USE_VOLUME_BAR
|
|---|
| 143 | volumeslider_action->disable();
|
|---|
| 144 | #endif
|
|---|
| 145 | }
|
|---|
| 146 | #endif // AUTODISABLE_ACTIONS
|
|---|
| 147 |
|
|---|
| 148 | void MiniGui::aboutToEnterFullscreen() {
|
|---|
| 149 | BaseGuiPlus::aboutToEnterFullscreen();
|
|---|
| 150 |
|
|---|
| 151 | if (!pref->compact_mode) {
|
|---|
| 152 | controlwidget->hide();
|
|---|
| 153 | }
|
|---|
| 154 | }
|
|---|
| 155 |
|
|---|
| 156 | void MiniGui::aboutToExitFullscreen() {
|
|---|
| 157 | BaseGuiPlus::aboutToExitFullscreen();
|
|---|
| 158 |
|
|---|
| 159 | floating_control->hide();
|
|---|
| 160 |
|
|---|
| 161 | if (!pref->compact_mode) {
|
|---|
| 162 | statusBar()->hide();
|
|---|
| 163 | controlwidget->show();
|
|---|
| 164 | }
|
|---|
| 165 | }
|
|---|
| 166 |
|
|---|
| 167 | void MiniGui::aboutToEnterCompactMode() {
|
|---|
| 168 | BaseGuiPlus::aboutToEnterCompactMode();
|
|---|
| 169 |
|
|---|
| 170 | controlwidget->hide();
|
|---|
| 171 | }
|
|---|
| 172 |
|
|---|
| 173 | void MiniGui::aboutToExitCompactMode() {
|
|---|
| 174 | BaseGuiPlus::aboutToExitCompactMode();
|
|---|
| 175 |
|
|---|
| 176 | statusBar()->hide();
|
|---|
| 177 |
|
|---|
| 178 | controlwidget->show();
|
|---|
| 179 | }
|
|---|
| 180 |
|
|---|
| 181 | void MiniGui::showFloatingControl(QPoint /*p*/) {
|
|---|
| 182 | #ifndef Q_OS_WIN
|
|---|
| 183 | floating_control->setBypassWindowManager(pref->bypass_window_manager);
|
|---|
| 184 | #endif
|
|---|
| 185 | floating_control->setAnimated( pref->floating_control_animated );
|
|---|
| 186 | floating_control->setMargin(pref->floating_control_margin);
|
|---|
| 187 | floating_control->showOver(panel,
|
|---|
| 188 | pref->floating_control_width,
|
|---|
| 189 | FloatingWidget::Bottom);
|
|---|
| 190 | }
|
|---|
| 191 |
|
|---|
| 192 | void MiniGui::hideFloatingControl() {
|
|---|
| 193 | floating_control->hide();
|
|---|
| 194 | }
|
|---|
| 195 |
|
|---|
| 196 | #if USE_MINIMUMSIZE
|
|---|
| 197 | QSize MiniGui::minimumSizeHint() const {
|
|---|
| 198 | return QSize(controlwidget->sizeHint().width(), 0);
|
|---|
| 199 | }
|
|---|
| 200 | #endif
|
|---|
| 201 |
|
|---|
| 202 |
|
|---|
| 203 | void MiniGui::saveConfig() {
|
|---|
| 204 | QSettings * set = settings;
|
|---|
| 205 |
|
|---|
| 206 | set->beginGroup( "mini_gui");
|
|---|
| 207 |
|
|---|
| 208 | if (pref->save_window_size_on_exit) {
|
|---|
| 209 | qDebug("MiniGui::saveConfig: w: %d h: %d", width(), height());
|
|---|
| 210 | set->setValue( "pos", pos() );
|
|---|
| 211 | set->setValue( "size", size() );
|
|---|
| 212 | }
|
|---|
| 213 |
|
|---|
| 214 | set->setValue( "toolbars_state", saveState(Helper::qtVersion()) );
|
|---|
| 215 |
|
|---|
| 216 | #if USE_CONFIGURABLE_TOOLBARS
|
|---|
| 217 | set->beginGroup( "actions" );
|
|---|
| 218 | set->setValue("controlwidget", ToolbarEditor::save(controlwidget) );
|
|---|
| 219 | set->setValue("floating_control", ToolbarEditor::save(floating_control->toolbar()) );
|
|---|
| 220 | set->endGroup();
|
|---|
| 221 | #endif
|
|---|
| 222 |
|
|---|
| 223 | set->endGroup();
|
|---|
| 224 | }
|
|---|
| 225 |
|
|---|
| 226 | void MiniGui::loadConfig() {
|
|---|
| 227 | QSettings * set = settings;
|
|---|
| 228 |
|
|---|
| 229 | set->beginGroup( "mini_gui");
|
|---|
| 230 |
|
|---|
| 231 | if (pref->save_window_size_on_exit) {
|
|---|
| 232 | QPoint p = set->value("pos", pos()).toPoint();
|
|---|
| 233 | QSize s = set->value("size", size()).toSize();
|
|---|
| 234 |
|
|---|
| 235 | if ( (s.height() < 200) && (!pref->use_mplayer_window) ) {
|
|---|
| 236 | s = pref->default_size;
|
|---|
| 237 | }
|
|---|
| 238 |
|
|---|
| 239 | move(p);
|
|---|
| 240 | resize(s);
|
|---|
| 241 |
|
|---|
| 242 | if (!DesktopInfo::isInsideScreen(this)) {
|
|---|
| 243 | move(0,0);
|
|---|
| 244 | qWarning("MiniGui::loadConfig: window is outside of the screen, moved to 0x0");
|
|---|
| 245 | }
|
|---|
| 246 | }
|
|---|
| 247 |
|
|---|
| 248 | #if USE_CONFIGURABLE_TOOLBARS
|
|---|
| 249 | QList<QAction *> actions_list = findChildren<QAction *>();
|
|---|
| 250 | QStringList controlwidget_actions;
|
|---|
| 251 | controlwidget_actions << "play_or_pause" << "stop" << "separator" << "timeslider_action" << "separator"
|
|---|
| 252 | << "fullscreen" << "mute" << "volumeslider_action";
|
|---|
| 253 |
|
|---|
| 254 | QStringList floatingcontrol_actions;
|
|---|
| 255 | floatingcontrol_actions << "play_or_pause" << "stop" << "separator" << "timeslider_action" << "separator"
|
|---|
| 256 | << "fullscreen" << "mute";
|
|---|
| 257 | #if USE_VOLUME_BAR
|
|---|
| 258 | floatingcontrol_actions << "volumeslider_action";
|
|---|
| 259 | #endif
|
|---|
| 260 |
|
|---|
| 261 | floatingcontrol_actions << "separator" << "timelabel_action";
|
|---|
| 262 |
|
|---|
| 263 | set->beginGroup( "actions" );
|
|---|
| 264 | ToolbarEditor::load(controlwidget, set->value("controlwidget", controlwidget_actions).toStringList(), actions_list );
|
|---|
| 265 | ToolbarEditor::load(floating_control->toolbar(), set->value("floating_control", floatingcontrol_actions).toStringList(), actions_list );
|
|---|
| 266 | floating_control->adjustSize();
|
|---|
| 267 | set->endGroup();
|
|---|
| 268 | #endif
|
|---|
| 269 |
|
|---|
| 270 | restoreState( set->value( "toolbars_state" ).toByteArray(), Helper::qtVersion() );
|
|---|
| 271 |
|
|---|
| 272 | set->endGroup();
|
|---|
| 273 | }
|
|---|
| 274 |
|
|---|
| 275 | #include "moc_minigui.cpp"
|
|---|
| 276 |
|
|---|