slidewindow.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. * Project PhotoBunny
  3. * 2014 Gwilyn Saunders
  4. */
  5. #include "slidewindow.h"
  6. #include <QtGui>
  7. #include <QDesktopWidget>
  8. SlideWindow::SlideWindow(QWidget *parent)
  9. : QMainWindow(parent) {
  10. //housekeeping
  11. setWindowTitle("PhotoBunny");
  12. setWindowIcon(QIcon(":/img/icon.png"));
  13. QDesktopWidget *desktop = new QDesktopWidget();
  14. setFixedWidth(desktop->width());
  15. setFixedHeight(desktop->height());
  16. setWindowState(Qt::WindowFullScreen);
  17. setWindowFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint);
  18. setPalette(QPalette(QColor().black()));
  19. //set default pixmap
  20. QPixmap pix(":/img/homepage.png");
  21. pix = pix.scaled(this->width(), this->height(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
  22. //set label widget
  23. img = new QLabel(this);
  24. img->setPixmap(pix);
  25. img->setMaximumHeight(this->height());
  26. img->setMaximumWidth(this->width());
  27. img->setAlignment(Qt::AlignCenter | Qt::AlignHCenter);
  28. setCentralWidget(img);
  29. //set keyboard shortcuts
  30. QAction *escAction = new QAction(this);
  31. QAction *aboutAction = new QAction(this);
  32. QAction *pauseAction = new QAction(this);
  33. QAction *blankAction = new QAction(this);
  34. escAction->setShortcut(Qt::Key_Escape);
  35. aboutAction->setShortcut(Qt::Key_F1);
  36. pauseAction->setShortcut(Qt::Key_Space);
  37. blankAction->setShortcut(Qt::Key_Return);
  38. addAction(escAction);
  39. addAction(aboutAction);
  40. addAction(pauseAction);
  41. addAction(blankAction);
  42. //load settings
  43. st = new QSettings("GwillzCorp", "fbslideshow");
  44. timeout = st->value("timeout").toInt();
  45. //stuff
  46. timer = new QTimer();
  47. fb = new FbApi(this);
  48. fb->id = "1402768076653253"; //TODO: change to #define
  49. //events
  50. connect(escAction, SIGNAL(triggered()), qApp, SLOT(quit()));
  51. connect(aboutAction, SIGNAL(triggered()), this, SLOT(about()));
  52. connect(pauseAction, SIGNAL(triggered()), this, SLOT(pause()));
  53. connect(blankAction, SIGNAL(triggered()), this, SLOT(blank()));
  54. connect(timer, SIGNAL(timeout()), this, SLOT(photoChange()));
  55. connect(fb, SIGNAL(picsLoaded()), this, SLOT(photoChange()));
  56. connect(fb, SIGNAL(picLoaded(QString*)), this, SLOT(setImage(QString*)));
  57. connect(fb, SIGNAL(loginResult(bool)), this, SLOT(loggedIn()));
  58. }
  59. void SlideWindow::openDialogs() {
  60. //open login dialog
  61. loginDiag = new LoginDialog(this);
  62. loginDiag->exec();
  63. //open album dialog
  64. albumDiag = new AlbumDialog(this);
  65. albumDiag->exec();
  66. qApp->setOverrideCursor(Qt::BlankCursor);
  67. //fb stuff
  68. fb->aid = st->value("albums").toStringList();
  69. fb->saveCredentials(st->value("user").toString(), st->value("pass").toString());
  70. fb->authenticate();
  71. qDebug() << "slideshow started with a" << timeout << "ms timeout";
  72. }
  73. void SlideWindow::about() {
  74. QMessageBox::about(this,
  75. "PhotoBunny",
  76. "A fullscreen app that displays a slideshow of photos from selected facebook albums. \n"
  77. "Made for Lincoln College, North Adelaide SA, Australia \n"
  78. "www.lincoln.edu.au \n"
  79. "Licenced under GPL 3 \n"
  80. "Gwilyn Saunders 2014");
  81. }
  82. void SlideWindow::pause() {
  83. if (timer->isActive()) {
  84. qDebug() << "paused";
  85. timer->stop();
  86. } else {
  87. qDebug() << "unpaused";
  88. photoChange();
  89. }
  90. }
  91. void SlideWindow::blank() {
  92. pause();
  93. img->setPixmap(QPixmap(":/img/black.png"));
  94. }
  95. void SlideWindow::photoChange() {
  96. timer->stop();
  97. if (fb->nextPicture()) {
  98. timer->start(timeout);
  99. }
  100. }
  101. void SlideWindow::setImage(QString *path) {
  102. QPixmap pix(*path);
  103. pix = pix.scaled(this->width(), this->height(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
  104. img->setPixmap(pix);
  105. }
  106. void SlideWindow::loggedIn() {
  107. fb->getPicsId();
  108. }