1 #include "MainWindow.h"
4 #include "iconloader/qticonloader.h"
7 MainWindow::MainWindow() :
15 history = new QStack<QWidget*>();
16 views = new QStackedWidget(this);
19 searchView = new SearchView(this);
20 connect(searchView, SIGNAL(search(QString)), this, SLOT(showMedia(QString)));
21 views->addWidget(searchView);
23 mediaView = new MediaView(this);
24 views->addWidget(mediaView);
26 toolbarSearch = new SearchLineEdit(this);
27 toolbarSearch->setFont(qApp->font());
28 toolbarSearch->setMinimumWidth(toolbarSearch->fontInfo().pixelSize()*15);
29 connect(toolbarSearch, SIGNAL(search(const QString&)), searchView, SLOT(watch(const QString&)));
38 mediaView->setMediaObject(mediaObject);
40 // remove that useless menu/toolbar context menu
41 this->setContextMenuPolicy(Qt::NoContextMenu);
43 // mediaView init stuff thats needs actions
44 mediaView->initialize();
46 // restore window position
49 // show the initial view
50 showWidget(searchView);
52 setCentralWidget(views);
55 MainWindow::~MainWindow() {
59 void MainWindow::createActions() {
61 QMap<QString, QAction*> *actions = The::globalActions();
64 settingsAct = new QAction(tr("&Preferences..."), this);
65 settingsAct->setStatusTip(tr(QString("Configure ").append(Constants::APP_NAME).toUtf8()));
67 settingsAct->setMenuRole(QAction::PreferencesRole);
68 actions->insert("settings", settingsAct);
69 connect(settingsAct, SIGNAL(triggered()), this, SLOT(showSettings()));
72 backAct = new QAction(tr("&Back"), this);
73 backAct->setEnabled(false);
74 backAct->setShortcut(QKeySequence(Qt::ALT + Qt::Key_Left));
75 backAct->setStatusTip(tr("Go to the previous view"));
76 actions->insert("back", backAct);
77 connect(backAct, SIGNAL(triggered()), this, SLOT(goBack()));
79 stopAct = new QAction(QtIconLoader::icon("media-playback-stop", QIcon(":/images/media-playback-stop.png")), tr("&Stop"), this);
80 stopAct->setStatusTip(tr("Stop playback and go back to the search view"));
81 stopAct->setShortcuts(QList<QKeySequence>() << QKeySequence(Qt::Key_Escape) << QKeySequence(Qt::Key_MediaStop));
82 actions->insert("stop", stopAct);
83 connect(stopAct, SIGNAL(triggered()), this, SLOT(stop()));
85 skipAct = new QAction(QtIconLoader::icon("media-skip-forward", QIcon(":/images/media-skip-forward.png")), tr("S&kip"), this);
86 skipAct->setStatusTip(tr("Skip to the next video"));
87 skipAct->setShortcuts(QList<QKeySequence>() << QKeySequence(Qt::CTRL + Qt::Key_Right) << QKeySequence(Qt::Key_MediaNext));
88 skipAct->setEnabled(false);
89 actions->insert("skip", skipAct);
90 connect(skipAct, SIGNAL(triggered()), mediaView, SLOT(skip()));
92 pauseAct = new QAction(QtIconLoader::icon("media-playback-pause", QIcon(":/images/media-playback-pause.png")), tr("&Pause"), this);
93 pauseAct->setStatusTip(tr("Pause playback"));
94 pauseAct->setShortcuts(QList<QKeySequence>() << QKeySequence(Qt::Key_Space) << QKeySequence(Qt::Key_MediaPlay));
95 pauseAct->setEnabled(false);
96 actions->insert("pause", pauseAct);
97 connect(pauseAct, SIGNAL(triggered()), mediaView, SLOT(pause()));
99 fullscreenAct = new QAction(QtIconLoader::icon("view-fullscreen", QIcon(":/images/view-fullscreen.png")), tr("&Full Screen"), this);
100 fullscreenAct->setStatusTip(tr("Go full screen"));
101 fullscreenAct->setShortcut(QKeySequence(Qt::ALT + Qt::Key_Return));
102 fullscreenAct->setShortcutContext(Qt::ApplicationShortcut);
103 actions->insert("fullscreen", fullscreenAct);
104 connect(fullscreenAct, SIGNAL(triggered()), this, SLOT(fullscreen()));
106 compactViewAct = new QAction(tr("&Compact mode"), this);
107 compactViewAct->setStatusTip(tr("Hide the playlist and the toolbar"));
108 compactViewAct->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Return));
109 compactViewAct->setCheckable(true);
110 compactViewAct->setChecked(false);
111 compactViewAct->setEnabled(false);
112 actions->insert("compactView", compactViewAct);
113 connect(compactViewAct, SIGNAL(toggled(bool)), this, SLOT(compactView(bool)));
116 // icon should be document-save but it is ugly
117 downloadAct = new QAction(QtIconLoader::icon("go-down", QIcon(":/images/go-down.png")), tr("&Download"), this);
118 downloadAct->setStatusTip(tr("Download this video"));
119 downloadAct->setShortcut(tr("Ctrl+S"));
120 downloadAct->setEnabled(false);
121 actions->insert("download", downloadAct);
122 connect(downloadAct, SIGNAL(triggered()), this, SLOT(download()));
125 webPageAct = new QAction(tr("&YouTube"), this);
126 webPageAct->setStatusTip(tr("Open the YouTube video page"));
127 webPageAct->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Y));
128 webPageAct->setEnabled(false);
129 actions->insert("webpage", webPageAct);
130 connect(webPageAct, SIGNAL(triggered()), mediaView, SLOT(openWebPage()));
132 removeAct = new QAction(tr("&Remove"), this);
133 removeAct->setStatusTip(tr("Remove the selected videos from the playlist"));
134 removeAct->setShortcuts(QList<QKeySequence>() << QKeySequence("Del") << QKeySequence("Backspace"));
135 removeAct->setEnabled(false);
136 actions->insert("remove", removeAct);
137 connect(removeAct, SIGNAL(triggered()), mediaView, SLOT(removeSelected()));
139 moveUpAct = new QAction(tr("Move &Up"), this);
140 moveUpAct->setStatusTip(tr("Move up the selected videos in the playlist"));
141 moveUpAct->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Up));
142 moveUpAct->setEnabled(false);
143 actions->insert("moveUp", moveUpAct);
144 connect(moveUpAct, SIGNAL(triggered()), mediaView, SLOT(moveUpSelected()));
146 moveDownAct = new QAction(tr("Move &Down"), this);
147 moveDownAct->setStatusTip(tr("Move down the selected videos in the playlist"));
148 moveDownAct->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Down));
149 moveDownAct->setEnabled(false);
150 actions->insert("moveDown", moveDownAct);
151 connect(moveDownAct, SIGNAL(triggered()), mediaView, SLOT(moveDownSelected()));
153 clearAct = new QAction(tr("&Clear recent keywords"), this);
154 clearAct->setMenuRole(QAction::ApplicationSpecificRole);
155 clearAct->setShortcuts(QList<QKeySequence>() << QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Delete) << QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Backspace));
156 clearAct->setEnabled(true);
157 actions->insert("clearRecentKeywords", clearAct);
158 connect(clearAct, SIGNAL(triggered()), searchView, SLOT(clearRecentKeywords()));
160 quitAct = new QAction(tr("&Quit"), this);
161 quitAct->setMenuRole(QAction::QuitRole);
162 quitAct->setShortcuts(QList<QKeySequence>() << QKeySequence(tr("Ctrl+Q")) << QKeySequence(Qt::CTRL + Qt::Key_W));
163 quitAct->setStatusTip(tr("Bye"));
164 actions->insert("quit", quitAct);
165 connect(quitAct, SIGNAL(triggered()), this, SLOT(quit()));
167 siteAct = new QAction(tr("&Website"), this);
168 siteAct->setShortcut(QKeySequence::HelpContents);
169 siteAct->setStatusTip(tr("%1 on the Web").arg(Constants::APP_NAME));
170 actions->insert("site", siteAct);
171 connect(siteAct, SIGNAL(triggered()), this, SLOT(visitSite()));
173 donateAct = new QAction(tr("&Donate via PayPal"), this);
174 donateAct->setStatusTip(tr("Please support the continued development of %1").arg(Constants::APP_NAME));
175 actions->insert("donate", donateAct);
176 connect(donateAct, SIGNAL(triggered()), this, SLOT(donate()));
178 aboutAct = new QAction(tr("&About"), this);
179 aboutAct->setMenuRole(QAction::AboutRole);
180 aboutAct->setStatusTip(tr("Info about %1").arg(Constants::APP_NAME));
181 actions->insert("about", aboutAct);
182 connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
186 searchFocusAct = new QAction(this);
187 searchFocusAct->setShortcut(QKeySequence::Find);
188 searchFocusAct->setStatusTip(tr("Search"));
189 actions->insert("search", searchFocusAct);
190 connect(searchFocusAct, SIGNAL(triggered()), this, SLOT(searchFocus()));
191 addAction(searchFocusAct);
193 volumeUpAct = new QAction(this);
194 volumeUpAct->setShortcuts(QList<QKeySequence>() << QKeySequence(Qt::CTRL + Qt::Key_Plus) << QKeySequence(Qt::Key_VolumeUp));
195 actions->insert("volume-up", volumeUpAct);
196 connect(volumeUpAct, SIGNAL(triggered()), this, SLOT(volumeUp()));
197 addAction(volumeUpAct);
199 volumeDownAct = new QAction(this);
200 volumeDownAct->setShortcuts(QList<QKeySequence>() << QKeySequence(Qt::CTRL + Qt::Key_Minus) << QKeySequence(Qt::Key_VolumeDown));
201 actions->insert("volume-down", volumeDownAct);
202 connect(volumeDownAct, SIGNAL(triggered()), this, SLOT(volumeDown()));
203 addAction(volumeDownAct);
205 volumeMuteAct = new QAction(this);
206 volumeMuteAct->setStatusTip(tr("Mute volume"));
207 volumeMuteAct->setShortcuts(QList<QKeySequence>() << QKeySequence(tr("Ctrl+M")) << QKeySequence(Qt::Key_VolumeMute));
208 actions->insert("volume-mute", volumeMuteAct);
209 connect(volumeMuteAct, SIGNAL(triggered()), this, SLOT(volumeMute()));
210 addAction(volumeMuteAct);
212 QAction *hdAct = new QAction(this);
213 hdAct->setShortcuts(QList<QKeySequence>() << QKeySequence(Qt::CTRL + Qt::Key_D));
214 hdAct->setIcon(createHDIcon());
215 hdAct->setCheckable(true);
216 actions->insert("hd", hdAct);
217 connect(hdAct, SIGNAL(toggled(bool)), this, SLOT(hdMode(bool)));
220 // common action properties
221 foreach (QAction *action, actions->values()) {
223 // add actions to the MainWindow so that they work
224 // when the menu is hidden
228 // unexperienced users tend to keep keys pressed for a "long" time
229 action->setAutoRepeat(false);
231 // set to something more meaningful then the toolbar text
232 // HELP! how to remove tooltips altogether?!
233 if (!action->statusTip().isEmpty())
234 action->setToolTip(action->statusTip());
236 // show keyboard shortcuts in the status bar
237 if (!action->shortcut().isEmpty())
238 action->setStatusTip(action->statusTip() + " (" + action->shortcut().toString(QKeySequence::NativeText) + ")");
240 // make the actions work when video is fullscreen
241 action->setShortcutContext(Qt::ApplicationShortcut);
244 action->setIconVisibleInMenu(false);
250 void MainWindow::createMenus() {
252 QMap<QString, QMenu*> *menus = The::globalMenus();
254 fileMenu = menuBar()->addMenu(tr("&Application"));
255 // menus->insert("file", fileMenu);
256 // fileMenu->addAction(settingsAct);
257 fileMenu->addAction(clearAct);
259 fileMenu->addSeparator();
261 fileMenu->addAction(quitAct);
263 playlistMenu = menuBar()->addMenu(tr("&Playlist"));
264 menus->insert("playlist", playlistMenu);
265 playlistMenu->addAction(removeAct);
266 playlistMenu->addSeparator();
267 playlistMenu->addAction(moveUpAct);
268 playlistMenu->addAction(moveDownAct);
270 viewMenu = menuBar()->addMenu(tr("&Video"));
271 menus->insert("video", viewMenu);
272 // viewMenu->addAction(backAct);
273 viewMenu->addAction(stopAct);
274 viewMenu->addAction(pauseAct);
275 viewMenu->addAction(skipAct);
276 viewMenu->addSeparator();
277 viewMenu->addAction(webPageAct);
278 viewMenu->addSeparator();
279 // viewMenu->addAction(downloadAct);
280 viewMenu->addAction(compactViewAct);
281 viewMenu->addAction(fullscreenAct);
283 helpMenu = menuBar()->addMenu(tr("&Help"));
284 helpMenu->addAction(siteAct);
285 helpMenu->addAction(donateAct);
286 helpMenu->addAction(aboutAct);
289 void MainWindow::createToolBars() {
291 mainToolBar = new QToolBar(this);
292 mainToolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
293 mainToolBar->setFloatable(false);
294 mainToolBar->setMovable(false);
295 // cool toolbar on the Mac
296 // setUnifiedTitleAndToolBarOnMac(true);
299 smallerFont.setPointSize(smallerFont.pointSize()*.85);
300 QFontInfo fontInfo(smallerFont);
301 if (fontInfo.pixelSize() < 10) {
302 smallerFont.setPixelSize(10);
304 mainToolBar->setFont(smallerFont);
306 mainToolBar->setIconSize(QSize(32,32));
307 // mainToolBar->addAction(backAct);
308 mainToolBar->addAction(stopAct);
309 mainToolBar->addAction(pauseAct);
310 mainToolBar->addAction(skipAct);
311 mainToolBar->addAction(fullscreenAct);
313 seekSlider = new Phonon::SeekSlider(this);
314 seekSlider->setIconVisible(false);
315 Spacer *seekSliderSpacer = new Spacer(mainToolBar, seekSlider);
316 seekSliderSpacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
317 mainToolBar->addWidget(seekSliderSpacer);
319 volumeSlider = new Phonon::VolumeSlider(this);
320 // qDebug() << volumeSlider->children();
321 // status tip for the volume slider
322 QSlider* volumeQSlider = volumeSlider->findChild<QSlider*>();
324 volumeQSlider->setStatusTip(tr("Press %1 to raise the volume, %2 to lower it").arg(
325 volumeUpAct->shortcut().toString(QKeySequence::NativeText), volumeDownAct->shortcut().toString(QKeySequence::NativeText)));
326 // status tip for the mute button
327 QToolButton* muteToolButton = volumeSlider->findChild<QToolButton*>();
329 muteToolButton->setStatusTip(volumeMuteAct->statusTip());
330 // this makes the volume slider smaller
331 volumeSlider->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
332 mainToolBar->addWidget(new Spacer(mainToolBar, volumeSlider));
334 toolbarSearch->setStatusTip(searchFocusAct->statusTip());
335 mainToolBar->addWidget(new Spacer(mainToolBar, toolbarSearch));
337 addToolBar(mainToolBar);
340 void MainWindow::createStatusBar() {
341 currentTime = new QLabel(this);
342 statusBar()->addPermanentWidget(currentTime);
344 totalTime = new QLabel(this);
345 statusBar()->addPermanentWidget(totalTime);
347 // remove ugly borders on OSX
348 // and remove some excessive padding
349 statusBar()->setStyleSheet("::item{border:0 solid} "
350 "QStatusBar, QToolBar, QToolButton {spacing:0;padding:0;margin:0} "
353 QToolBar *toolBar = new QToolBar(this);
354 int iconHeight = 24; // statusBar()->height();
355 int iconWidth = 36; // iconHeight * 3 / 2;
356 toolBar->setIconSize(QSize(iconWidth, iconHeight));
357 toolBar->setToolButtonStyle(Qt::ToolButtonIconOnly);
358 toolBar->addAction(The::globalActions()->value("hd"));
359 statusBar()->addPermanentWidget(toolBar);
364 void MainWindow::readSettings() {
366 restoreGeometry(settings.value("geometry").toByteArray());
367 hdMode(settings.value("hd").toBool());
368 audioOutput->setVolume(settings.value("volume", 1).toDouble());
369 audioOutput->setMuted(settings.value("volumeMute").toBool());
372 void MainWindow::writeSettings() {
373 // do not save geometry when in full screen
377 settings.setValue("geometry", saveGeometry());
378 settings.setValue("hd", The::globalActions()->value("hd")->isChecked());
379 settings.setValue("volume", audioOutput->volume());
380 settings.setValue("volumeMute", audioOutput->isMuted());
381 mediaView->saveSplitterState();
384 void MainWindow::goBack() {
385 if ( history->size() > 1 ) {
387 QWidget *widget = history->pop();
392 void MainWindow::showWidget ( QWidget* widget ) {
394 setUpdatesEnabled(false);
396 // call hide method on the current view
397 View* oldView = dynamic_cast<View *> (views->currentWidget());
399 oldView->disappear();
402 // call show method on the new view
403 View* newView = dynamic_cast<View *> (widget);
406 QMap<QString,QVariant> metadata = newView->metadata();
407 QString windowTitle = metadata.value("title").toString();
408 if (windowTitle.length())
409 windowTitle += " - ";
410 setWindowTitle(windowTitle + Constants::APP_NAME);
411 statusBar()->showMessage((metadata.value("description").toString()));
414 // backAct->setEnabled(history->size() > 1);
415 // settingsAct->setEnabled(widget != settingsView);
416 stopAct->setEnabled(widget == mediaView);
417 fullscreenAct->setEnabled(widget == mediaView);
418 compactViewAct->setEnabled(widget == mediaView);
419 webPageAct->setEnabled(widget == mediaView);
420 aboutAct->setEnabled(widget != aboutView);
423 // this is not the best place to enable downloads, but the user is informed
424 // if there really is no video is playing
425 downloadAct->setEnabled(widget == mediaView);
428 // toolbar only for the mediaView
429 mainToolBar->setVisible(widget == mediaView && !compactViewAct->isChecked());
431 setUpdatesEnabled(true);
433 QWidget *oldWidget = views->currentWidget();
434 views->setCurrentWidget(widget);
437 // crossfade only on OSX
438 // where we can be sure of video performance
439 fadeInWidget(oldWidget, widget);
442 history->push(widget);
445 void MainWindow::fadeInWidget(QWidget *oldWidget, QWidget *newWidget) {
446 if (faderWidget) faderWidget->close();
447 if (!oldWidget || !newWidget) {
448 qDebug() << "no widgets";
451 faderWidget = new FaderWidget(newWidget);
452 faderWidget->start(QPixmap::grabWidget(oldWidget));
455 void MainWindow::about() {
457 aboutView = new AboutView(this);
458 views->addWidget(aboutView);
460 showWidget(aboutView);
463 void MainWindow::visitSite() {
464 QUrl url(Constants::WEBSITE);
465 statusBar()->showMessage(QString(tr("Opening %1").arg(url.toString())));
466 QDesktopServices::openUrl(url);
469 void MainWindow::donate() {
470 QUrl url(QString(Constants::WEBSITE) + "#donate");
471 statusBar()->showMessage(QString(tr("Opening %1").arg(url.toString())));
472 QDesktopServices::openUrl(url);
475 void MainWindow::quit() {
480 void MainWindow::closeEvent(QCloseEvent *event) {
482 QWidget::closeEvent(event);
486 void MainWindow::showSettings() {
488 settingsView = new SettingsView(this);
489 views->addWidget(settingsView);
491 showWidget(settingsView);
494 void MainWindow::showSearch() {
495 showWidget(searchView);
496 currentTime->clear();
500 void MainWindow::showMedia(QString query) {
501 SearchParams *searchParams = new SearchParams();
502 searchParams->setKeywords(query);
503 mediaView->search(searchParams);
504 showWidget(mediaView);
507 void MainWindow::stateChanged(Phonon::State newState, Phonon::State /* oldState */) {
509 // qDebug() << "Phonon state: " << newState;
513 case Phonon::ErrorState:
514 if (mediaObject->errorType() == Phonon::FatalError) {
515 statusBar()->showMessage(tr("Fatal error: %1").arg(mediaObject->errorString()));
517 statusBar()->showMessage(tr("Error: %1").arg(mediaObject->errorString()));
521 case Phonon::PlayingState:
522 pauseAct->setEnabled(true);
523 pauseAct->setIcon(QtIconLoader::icon("media-playback-pause", QIcon(":/images/media-playback-pause.png")));
524 pauseAct->setText(tr("&Pause"));
525 pauseAct->setStatusTip(tr("Pause playback") + " (" + pauseAct->shortcut().toString(QKeySequence::NativeText) + ")");
526 skipAct->setEnabled(true);
529 case Phonon::StoppedState:
530 pauseAct->setEnabled(false);
531 skipAct->setEnabled(false);
534 case Phonon::PausedState:
535 skipAct->setEnabled(true);
536 pauseAct->setEnabled(true);
537 pauseAct->setIcon(QtIconLoader::icon("media-playback-start", QIcon(":/images/media-playback-start.png")));
538 pauseAct->setText(tr("&Play"));
539 pauseAct->setStatusTip(tr("Resume playback") + " (" + pauseAct->shortcut().toString(QKeySequence::NativeText) + ")");
542 case Phonon::BufferingState:
543 case Phonon::LoadingState:
544 skipAct->setEnabled(true);
545 pauseAct->setEnabled(false);
546 currentTime->clear();
555 void MainWindow::stop() {
560 void MainWindow::fullscreen() {
562 setUpdatesEnabled(false);
565 // use setShortucs instead of setShortcut
566 // the latter seems not to work
567 fullscreenAct->setShortcuts(QList<QKeySequence>() << QKeySequence(Qt::ALT + Qt::Key_Return));
568 fullscreenAct->setText(tr("&Full Screen"));
569 stopAct->setShortcuts(QList<QKeySequence>() << QKeySequence(Qt::Key_Escape) << QKeySequence(Qt::Key_MediaStop));
570 if (m_maximized) showMaximized();
572 // Make sure the window has focus (Mac)
575 stopAct->setShortcuts(QList<QKeySequence>() << QKeySequence(Qt::Key_MediaStop));
576 fullscreenAct->setShortcuts(QList<QKeySequence>() << QKeySequence(Qt::Key_Escape) << QKeySequence(Qt::ALT + Qt::Key_Return));
577 fullscreenAct->setText(tr("Exit &Full Screen"));
578 m_maximized = isMaximized();
580 // save geometry now, if the user quits when in full screen
581 // geometry won't be saved
587 // No compact view action when in full screen
588 compactViewAct->setVisible(m_fullscreen);
589 compactViewAct->setChecked(false);
591 // Also no Youtube action since it opens a new window
592 webPageAct->setVisible(m_fullscreen);
593 stopAct->setVisible(m_fullscreen);
595 // Hide anything but the video
596 mediaView->setPlaylistVisible(m_fullscreen);
597 mainToolBar->setVisible(m_fullscreen);
598 statusBar()->setVisible(m_fullscreen);
599 menuBar()->setVisible(m_fullscreen);
601 // workaround: prevent focus on the search bar
602 // it steals the Space key needed for Play/Pause
603 mainToolBar->setEnabled(m_fullscreen);
605 m_fullscreen = !m_fullscreen;
607 setUpdatesEnabled(true);
610 void MainWindow::compactView(bool enable) {
612 setUpdatesEnabled(false);
614 // setUnifiedTitleAndToolBarOnMac(!enable);
615 mediaView->setPlaylistVisible(!enable);
616 mainToolBar->setVisible(!enable);
617 statusBar()->setVisible(!enable);
618 menuBar()->setVisible(!enable);
620 // ensure focus does not end up to the search box
621 // as it would steal the Space shortcut
622 toolbarSearch->setEnabled(!enable);
625 stopAct->setShortcut(QString(""));
626 QList<QKeySequence> shortcuts;
627 // for some reason it is important that ESC comes first
628 shortcuts << QKeySequence(Qt::CTRL + Qt::Key_Return) << QKeySequence(Qt::Key_Escape);
629 compactViewAct->setShortcuts(shortcuts);
631 compactViewAct->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Return));
632 stopAct->setShortcut(QKeySequence(Qt::Key_Escape));
635 setUpdatesEnabled(true);
638 void MainWindow::searchFocus() {
639 QWidget *view = views->currentWidget();
640 if (view == mediaView) {
641 toolbarSearch->selectAll();
642 toolbarSearch->setFocus();
646 void MainWindow::initPhonon() {
647 // Phonon initialization
648 if (mediaObject) delete mediaObject;
649 if (audioOutput) delete audioOutput;
650 mediaObject = new Phonon::MediaObject(this);
651 mediaObject->setTickInterval(100);
652 connect(mediaObject, SIGNAL(stateChanged(Phonon::State, Phonon::State)),
653 this, SLOT(stateChanged(Phonon::State, Phonon::State)));
654 connect(mediaObject, SIGNAL(tick(qint64)), this, SLOT(tick(qint64)));
655 connect(mediaObject, SIGNAL(totalTimeChanged(qint64)), this, SLOT(totalTimeChanged(qint64)));
656 seekSlider->setMediaObject(mediaObject);
657 audioOutput = new Phonon::AudioOutput(Phonon::VideoCategory, this);
658 connect(audioOutput, SIGNAL(volumeChanged(qreal)), this, SLOT(volumeChanged(qreal)));
659 connect(audioOutput, SIGNAL(mutedChanged(bool)), this, SLOT(volumeMutedChanged(bool)));
660 volumeSlider->setAudioOutput(audioOutput);
661 Phonon::createPath(mediaObject, audioOutput);
664 void MainWindow::tick(qint64 time) {
666 currentTime->clear();
670 currentTime->setText(formatTime(time));
673 const qint64 remainingTime = mediaObject->remainingTime();
674 currentTime->setStatusTip(tr("Remaining time: %1").arg(formatTime(remainingTime)));
678 void MainWindow::totalTimeChanged(qint64 time) {
683 totalTime->setText("/ " + formatTime(time));
686 QString MainWindow::formatTime(qint64 time) {
688 displayTime = displayTime.addMSecs(time);
690 // 60 * 60 * 1000 = 3600000
692 timeString = displayTime.toString("h:mm:ss");
694 timeString = displayTime.toString("m:ss");
698 void MainWindow::volumeUp() {
699 qreal newVolume = volumeSlider->audioOutput()->volume() + .1;
700 if (newVolume > volumeSlider->maximumVolume())
701 newVolume = volumeSlider->maximumVolume();
702 volumeSlider->audioOutput()->setVolume(newVolume);
705 void MainWindow::volumeDown() {
706 qreal newVolume = volumeSlider->audioOutput()->volume() - .1;
709 volumeSlider->audioOutput()->setVolume(newVolume);
712 void MainWindow::volumeMute() {
713 volumeSlider->audioOutput()->setMuted(!volumeSlider->audioOutput()->isMuted());
716 void MainWindow::volumeChanged(qreal newVolume) {
717 // automatically unmute when volume changes
718 if (volumeSlider->audioOutput()->isMuted())
719 volumeSlider->audioOutput()->setMuted(false);
720 statusBar()->showMessage(tr("Volume at %1%").arg(newVolume*100));
723 void MainWindow::volumeMutedChanged(bool muted) {
725 statusBar()->showMessage(tr("Volume is muted"));
727 statusBar()->showMessage(tr("Volume is unmuted"));
730 QPixmap MainWindow::createHDPixmap(bool enabled) {
731 QPixmap pixmap = QPixmap(24,24);
732 pixmap.fill(Qt::transparent);
733 QPainter painter(&pixmap);
734 painter.setRenderHints(QPainter::Antialiasing, true);
736 QRect rect(0, 3, 24, 18);
739 pen.setColor(Qt::black);
744 painter.setBrush(palette().highlight());
746 QLinearGradient gradient(QPointF(0, 0), QPointF(0, rect.height() / 2));
747 gradient.setColorAt(0, QColor(0x6d, 0x6d, 0x6d));
748 gradient.setColorAt(1, QColor(0x25, 0x25, 0x25));
749 painter.setBrush(QBrush(gradient));
751 painter.drawRoundedRect(rect, 5, 5);
754 pen.setColor(palette().highlightedText().color());
756 pen.setColor(Qt::white);
761 font.setPixelSize(12);
763 painter.setFont(font);
764 painter.drawText(rect, Qt::AlignCenter, "HD");
769 static QIcon hdOnIcon;
770 static QIcon hdOffIcon;
772 QIcon MainWindow::createHDIcon() {
773 hdOffIcon.addPixmap(createHDPixmap(false));
774 hdOnIcon.addPixmap(createHDPixmap(true));
778 void MainWindow::hdMode(bool enabled) {
779 QAction *hdAct = The::globalActions()->value("hd");
780 hdAct->setChecked(enabled);
782 hdAct->setStatusTip(tr("High Definition video is enabled") + " (" + hdAct->shortcut().toString(QKeySequence::NativeText) + ")");
784 hdAct->setStatusTip(tr("High Definition video is not enabled") + " (" + hdAct->shortcut().toString(QKeySequence::NativeText) + ")");
786 statusBar()->showMessage(hdAct->statusTip());
788 settings.setValue("hd", enabled);
791 void MainWindow::hdIndicator(bool isHd) {
792 QAction *hdAct = The::globalActions()->value("hd");
794 hdAct->setIcon(hdOnIcon);
795 hdAct->setToolTip(tr("The current video is in High Definition"));
797 hdAct->setIcon(hdOffIcon);
798 hdAct->setToolTip(tr("The current video is not in High Definition"));
802 void MainWindow::showFullscreenToolbar(bool show) {
803 if (!m_fullscreen) return;
810 mainToolBar->setEnabled(show);
813 void MainWindow::showFullscreenPlaylist(bool show) {
814 if (!m_fullscreen) return;
815 mediaView->setPlaylistVisible(show);