81
82
// event filter to block ugly toolbar tooltips
82
83
qApp->installEventFilter(this);
85
setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
84
87
// restore window position
90
// fix stacked widget minimum size
91
for (int i = 0; i < views->count(); i++) {
92
QWidget* view = views->widget(i);
93
if (view) view->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
87
97
// show the initial view
89
99
QWidget *demoStartupView = new DemoStartupView(this);
116
126
setAcceptDrops(true);
128
mouseTimer = new QTimer(this);
129
mouseTimer->setInterval(5000);
130
mouseTimer->setSingleShot(true);
131
connect(mouseTimer, SIGNAL(timeout()), SLOT(hideMouse()));
118
133
QTimer::singleShot(0, this, SLOT(checkForUpdate()));
135
150
bool MainWindow::eventFilter(QObject *obj, QEvent *event) {
137
if (event->type() == QEvent::MouseMove && this->m_fullscreen) {
152
if (m_fullscreen && event->type() == QEvent::MouseMove) {
138
154
QMouseEvent *mouseEvent = static_cast<QMouseEvent*> (event);
139
int x = mouseEvent->pos().x();
140
int y = mouseEvent->pos().y();
142
if (y < 0 && (obj == this->mainToolBar || !(y <= 10-this->mainToolBar->height() && y >= 0-this->mainToolBar->height() )))
143
this->mainToolBar->setVisible(false);
145
this->mediaView->setPlaylistVisible(false);
155
const int x = mouseEvent->pos().x();
156
const QString className = QString(obj->metaObject()->className());
157
const bool isHoveringVideo = (className == "QGLWidget") || (className == "VideoAreaWidget");
159
// qDebug() << obj << mouseEvent->pos() << isHoveringVideo << mediaView->isPlaylistVisible();
161
if (mediaView->isPlaylistVisible()) {
162
if (isHoveringVideo && x > 5) mediaView->setPlaylistVisible(false);
164
if (isHoveringVideo && x >= 0 && x < 5) mediaView->setPlaylistVisible(true);
168
const int y = mouseEvent->pos().y();
169
if (mainToolBar->isVisible()) {
170
if (isHoveringVideo && y > 5) mainToolBar->setVisible(false);
172
if (isHoveringVideo && y >= 0 && y < 5) mainToolBar->setVisible(true);
176
// show the normal cursor
178
// then hide it again after a few seconds
149
183
if (event->type() == QEvent::ToolTip) {
153
187
// standard event processing
154
return QObject::eventFilter(obj, event);
188
return QMainWindow::eventFilter(obj, event);
157
191
void MainWindow::createActions() {
379
413
connect(action, SIGNAL(triggered()), mediaView, SLOT(downloadVideo()));
380
414
actions->insert("download", action);
417
action = new QAction(tr("&Snapshot"), this);
418
action->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_S));
419
actions->insert("snapshot", action);
420
connect(action, SIGNAL(triggered()), mediaView, SLOT(snapshot()));
382
423
QString shareTip = tr("Share the current video using %1");
384
425
action = new QAction("&Twitter", this);
391
432
actions->insert("facebook", action);
392
433
connect(action, SIGNAL(triggered()), mediaView, SLOT(shareViaFacebook()));
435
action = new QAction("&Buffer", this);
436
action->setStatusTip(shareTip.arg("Buffer"));
437
actions->insert("buffer", action);
438
connect(action, SIGNAL(triggered()), mediaView, SLOT(shareViaBuffer()));
394
440
action = new QAction(tr("&Email"), this);
395
441
action->setStatusTip(shareTip.arg(tr("Email")));
396
442
actions->insert("email", action);
401
447
actions->insert("close", action);
402
448
connect(action, SIGNAL(triggered()), SLOT(close()));
450
action = new QAction(Constants::NAME, this);
451
action->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_1));
452
actions->insert("restore", action);
453
connect(action, SIGNAL(triggered()), SLOT(restore()));
404
455
action = new QAction(QtIconLoader::icon("go-top"), tr("&Float on Top"), this);
405
456
action->setCheckable(true);
406
457
actions->insert("ontop", action);
413
464
actions->insert("stopafterthis", action);
414
465
connect(action, SIGNAL(toggled(bool)), SLOT(showStopAfterThisInStatusBar(bool)));
467
action = new QAction(tr("&Report an Issue..."), this);
468
actions->insert("report-issue", action);
469
connect(action, SIGNAL(triggered()), SLOT(reportIssue()));
471
action = new QAction(tr("&Refine Search..."), this);
472
action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_R));
473
action->setCheckable(true);
474
actions->insert("refine-search", action);
416
476
// common action properties
417
477
foreach (QAction *action, actions->values()) {
476
536
playlistMenu->addSeparator();
477
537
playlistMenu->addAction(moveUpAct);
478
538
playlistMenu->addAction(moveDownAct);
539
playlistMenu->addSeparator();
540
playlistMenu->addAction(The::globalActions()->value("refine-search"));
480
542
QMenu* videoMenu = menuBar()->addMenu(tr("&Video"));
481
543
menus->insert("video", videoMenu);
482
544
videoMenu->addAction(findVideoPartsAct);
483
545
videoMenu->addSeparator();
484
546
videoMenu->addAction(webPageAct);
547
videoMenu->addSeparator();
485
548
#ifndef APP_NO_DOWNLOADS
486
videoMenu->addSeparator();
487
549
videoMenu->addAction(The::globalActions()->value("download"));
488
videoMenu->addAction(copyLinkAct);
550
// videoMenu->addAction(copyLinkAct);
552
// videoMenu->addAction(The::globalActions()->value("snapshot"));
491
554
QMenu* viewMenu = menuBar()->addMenu(tr("&View"));
492
555
menus->insert("view", viewMenu);
501
564
shareMenu->addSeparator();
502
565
shareMenu->addAction(The::globalActions()->value("twitter"));
503
566
shareMenu->addAction(The::globalActions()->value("facebook"));
567
shareMenu->addAction(The::globalActions()->value("buffer"));
568
shareMenu->addSeparator();
504
569
shareMenu->addAction(The::globalActions()->value("email"));
642
708
void MainWindow::readSettings() {
643
709
QSettings settings;
644
restoreGeometry(settings.value("geometry").toByteArray());
710
if (settings.contains("geometry")) {
711
restoreGeometry(settings.value("geometry").toByteArray());
646
713
MacSupport::fixGeometry(this);
716
setGeometry(100, 100, 1000, 500);
648
718
setDefinitionMode(settings.value("definition", VideoDefinition::getDefinitionNames().first()).toString());
649
719
audioOutput->setVolume(settings.value("volume", 1).toDouble());
650
720
audioOutput->setMuted(settings.value("volumeMute").toBool());
654
724
void MainWindow::writeSettings() {
656
725
QSettings settings;
658
// do not save geometry when in full screen
660
settings.setValue("geometry", saveGeometry());
727
settings.setValue("geometry", saveGeometry());
728
mediaView->saveSplitterState();
663
730
settings.setValue("volume", audioOutput->volume());
664
731
settings.setValue("volumeMute", audioOutput->isMuted());
665
732
settings.setValue("manualplay", The::globalActions()->value("manualplay")->isChecked());
666
mediaView->saveSplitterState();
669
735
void MainWindow::goBack() {
677
743
void MainWindow::showWidget ( QWidget* widget ) {
745
if (compactViewAct->isChecked())
746
compactViewAct->toggle();
679
748
setUpdatesEnabled(false);
681
750
// call hide method on the current view
716
785
The::globalActions()->value("twitter")->setEnabled(widget == mediaView);
717
786
The::globalActions()->value("facebook")->setEnabled(widget == mediaView);
787
The::globalActions()->value("buffer")->setEnabled(widget == mediaView);
718
788
The::globalActions()->value("email")->setEnabled(widget == mediaView);
720
790
aboutAct->setEnabled(widget != aboutView);
729
799
setUpdatesEnabled(true);
731
801
QWidget *oldWidget = views->currentWidget();
803
oldWidget->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
732
805
views->setCurrentWidget(widget);
806
widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
735
810
Extra::fadeInWidget(oldWidget, widget);
758
833
QDesktopServices::openUrl(url);
836
void MainWindow::reportIssue() {
837
QUrl url("http://flavio.tordini.org/forums/forum/minitube-forums/minitube-troubleshooting");
838
QDesktopServices::openUrl(url);
761
841
void MainWindow::quit() {
763
843
if (!confirmQuit()) {
847
// do not save geometry when in full screen or in compact mode
848
if (!m_fullscreen && !compactViewAct->isChecked()) {
768
851
Temporary::deleteAll();
876
959
if (mac::CanGoFullScreen(winId())) {
877
960
bool isFullscreen = mac::IsFullScreen(winId());
878
961
if (isFullscreen != m_fullscreen) {
962
if (compactViewAct->isChecked()) {
963
compactViewAct->setChecked(false);
879
966
m_fullscreen = isFullscreen;
880
967
updateUIForFullscreen();
983
1075
static QList<QKeySequence> compactShortcuts;
984
1076
static QList<QKeySequence> stopShortcuts;
987
1078
const static QString key = "compactGeometry";
988
1079
QSettings settings;
992
1082
menuBar()->setVisible(!enable);
1086
setMinimumSize(160, 120);
1088
mac::RemoveFullScreenWindow(winId());
997
1090
writeSettings();
998
restoreGeometry(settings.value(key).toByteArray());
1092
if (settings.contains(key))
1093
restoreGeometry(settings.value(key).toByteArray());
1097
mainToolBar->setVisible(!enable);
1098
mediaView->setPlaylistVisible(!enable);
1099
statusBar()->setVisible(!enable);
1001
1101
compactShortcuts = compactViewAct->shortcuts();
1002
1102
stopShortcuts = stopAct->shortcuts();
1009
1109
// ensure focus does not end up to the search box
1010
1110
// as it would steal the Space shortcut
1011
1111
mediaView->setFocus();
1114
// unset minimum size
1115
setMinimumSize(0, 0);
1117
mac::SetupFullScreenWindow(winId());
1014
1119
settings.setValue(key, saveGeometry());
1120
mainToolBar->setVisible(!enable);
1121
mediaView->setPlaylistVisible(!enable);
1122
statusBar()->setVisible(!enable);
1015
1123
readSettings();
1018
1125
compactViewAct->setShortcuts(compactShortcuts);
1019
1126
stopAct->setShortcuts(stopShortcuts);
1022
mainToolBar->setVisible(!enable);
1023
mediaView->setPlaylistVisible(!enable);
1024
statusBar()->setVisible(!enable);
1129
// auto float on top
1028
1133
void MainWindow::searchFocus() {
1029
QWidget *view = views->currentWidget();
1030
1134
toolbarSearch->selectAll();
1031
1135
toolbarSearch->setFocus();
1443
void MainWindow::restore() {
1445
mac::uncloseWindow(window()->winId());
1340
1449
void MainWindow::messageReceived(const QString &message) {
1341
if (!message.isEmpty()) {
1450
if (message == "--toggle-playing") {
1451
if (pauseAct->isEnabled()) pauseAct->trigger();
1452
} else if (message == "--next") {
1453
if (skipAct->isEnabled()) skipAct->trigger();
1454
} else if (message == "--previous") {
1455
if (skipBackwardAct->isEnabled()) skipBackwardAct->trigger();
1456
} else if (message.startsWith("--")) {
1457
MainWindow::printHelp();
1458
} else if (!message.isEmpty()) {
1342
1459
SearchParams *searchParams = new SearchParams();
1343
1460
searchParams->setKeywords(message);
1344
1461
showMedia(searchParams);
1465
void MainWindow::hideMouse() {
1466
setCursor(Qt::BlankCursor);
1467
mediaView->setPlaylistVisible(false);
1469
mainToolBar->setVisible(false);
1473
void MainWindow::printHelp() {
1474
QString msg = QString("%1 %2\n\n").arg(Constants::NAME, Constants::VERSION);
1475
msg += "Usage: minitube [options]\n";
1476
msg += "Options:\n";
1477
msg += " --toggle-playing\t";
1478
msg += "Start or pause playback.\n";
1479
msg += " --next\t\t";
1480
msg += "Skip to the next video.\n";
1481
msg += " --previous\t\t";
1482
msg += "Go back to the previous video.\n";
1483
std::cout << msg.toLocal8Bit().data();