Browse Source

added screen selection dialog

gwillz 5 years ago
parent
commit
012a8472d5
9 changed files with 311 additions and 71 deletions
  1. 4 2
      FBSlideshow.pro
  2. 2 0
      common.h
  3. 99 0
      dialogs.cpp
  4. 33 4
      dialogs.h
  5. 1 1
      main.cpp
  6. 91 0
      screenutils.cpp
  7. 57 0
      screenutils.h
  8. 19 8
      slidewindow.cpp
  9. 5 56
      slidewindow.h

+ 4 - 2
FBSlideshow.pro

@@ -8,12 +8,14 @@ TEMPLATE = app
 SOURCES += main.cpp\
            slidewindow.cpp \
            fbApi.cpp \
-           dialogs.cpp
+           dialogs.cpp \
+    screenutils.cpp
 
 HEADERS  += slidewindow.h \
             fbApi.h \
             dialogs.h \
-    common.h
+    common.h \
+    screenutils.h
 
 RESOURCES += \
             resources.qrc

+ 2 - 0
common.h

@@ -2,6 +2,8 @@
 #define company_str "GwillzCorp"
 #define app_str "fbslideshow"
 
+#define box_scale 20
+
 //facebook application id
 #define APP_ID = "1402768076653253" //photoBunny
 

+ 99 - 0
dialogs.cpp

@@ -150,3 +150,102 @@ void AlbumDialog::loadAlbums() {
         list->addItem(item);
     }
 }
+
+
+ScreenDialog::ScreenDialog(QWidget *parent)
+        : QDialog(parent) {
+    //housekeeping
+//    setFixedWidth(desktop.width() / box_scale + 50);
+//    setFixedHeight(desktop.height() / box_scale + 100);
+    setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
+    setWindowTitle("Select a Screen | PhotoBunny");
+    QVBoxLayout *layout = new QVBoxLayout(this);
+    setLayout(layout);
+    
+    st = new QSettings(company_str, app_str);
+    
+    //read screen sizes
+    QMap<int, QRect> rects;
+    int offsetX = 0, offsetY = 0;
+    for (int i=0; i<desktop.screenCount(); i++) {
+        QRect r = desktop.screenGeometry(i);
+        rects.insert(i, r);
+        if (r.x() < 0 && r.x() < offsetX) offsetX = r.x();
+        if (r.y() < 0 && r.y() < offsetY) offsetY = r.y();
+    }
+    
+    //adjust for positive integers
+    for (int i=0; i<rects.size(); i++) {
+        QRect r = rects.take(i).adjusted(-offsetX, -offsetY, -offsetX, -offsetY);
+        rects.insert(i, r);
+    }
+    
+    //create screen grid (relative to total screen size)
+    QWidget *screenBox = new QWidget(this);
+    screenBox->setFixedWidth(desktop.width()/box_scale + box_scale);
+    screenBox->setFixedHeight(desktop.height()/box_scale + box_scale);
+    QGridLayout *screenGrid = new QGridLayout(screenBox);
+    screenBox->setLayout(screenGrid);
+    
+    //load screens into widgets
+    foreach (int i, rects.keys()) {
+        QRect r = rects.value(i);
+        DesktopBox *box = new DesktopBox(i, r.width()/box_scale, r.height()/box_scale);
+        box->setIdentifier(desktop.screenGeometry(i));
+        boxes.append(box);
+        screenGrid->addWidget(box, r.y(), r.x());
+        connect(box, SIGNAL(clicked()), this, SLOT(clearHighlights()));
+        connect(box, SIGNAL(clicked()), box, SLOT(highlight()));
+        connect(box, SIGNAL(clicked(int)), this, SLOT(selectScreen(int)));
+        connect(box, SIGNAL(doubleClicked()), box, SLOT(identify()));
+    }
+    
+    //button bar
+    screenLabel = new QLabel("?", this);
+    screenLabel->setFont(QFont("Arial", 12, QFont::Normal));
+    okButton = new QPushButton("Select", this);
+    okButton->setMaximumWidth(70);
+    okButton->setEnabled(false);
+    QPushButton *cancelButton = new QPushButton("Cancel", this);
+    cancelButton->setMaximumWidth(70);
+    
+    //mix it up!
+    QHBoxLayout *buttons = new QHBoxLayout(this);
+    buttons->addStretch();
+    buttons->addWidget(screenLabel);
+    buttons->addWidget(okButton);
+    buttons->addWidget(cancelButton);
+    
+    layout->addWidget(screenBox);
+    layout->addLayout(buttons);
+    
+    //events
+    connect(okButton, SIGNAL(clicked()), this, SLOT(okClicked()));
+    connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
+}
+
+void ScreenDialog::okClicked() {
+    st->setValue("screen", selectedScreen);
+    st->sync();
+    accept();
+}
+
+void ScreenDialog::identify() {
+    foreach(DesktopBox *d, boxes) {
+        d->identify();
+    }
+}
+
+void ScreenDialog::selectScreen(int screen) {
+    selectedScreen = screen;
+    okButton->setEnabled(true);
+    screenLabel->setText(QString::number(screen));
+    
+}
+
+void ScreenDialog::clearHighlights() {
+    foreach (DesktopBox *b, boxes) {
+        b->highlight(false);
+    }
+}
+

+ 33 - 4
dialogs.h

@@ -29,8 +29,6 @@ class LoginDialog
     public:
         explicit LoginDialog(QWidget *parent = 0);
         
-    signals:
-        
     public slots:
         void okClicked();
 };
@@ -58,8 +56,6 @@ class AlbumDialog
     public:
         explicit AlbumDialog(QWidget *parent = 0);
         
-    signals:
-        
     public slots:
         void okClicked();
         
@@ -70,3 +66,36 @@ class AlbumDialog
 #endif // ALBUMDIALOG_H
 
 
+#ifndef SCREENDIALOG_H
+#define SCREENDIALOG_H
+#include "common.h"
+#include "screenutils.h"
+#include <QDesktopWidget>
+#include <QList>
+class QPushButton;
+class QLabel;
+
+class ScreenDialog
+        : public QDialog {
+    Q_OBJECT
+    
+    QSettings *st;
+    QDesktopWidget desktop;
+    QList<DesktopBox*> boxes;
+    int selectedScreen;
+    QPushButton *okButton;
+    QLabel *screenLabel;
+    
+    public:
+        explicit ScreenDialog(QWidget *parent = 0);
+        
+    public slots:
+        void okClicked();
+        void identify();
+        void clearHighlights();
+        void selectScreen(int screen);
+};
+
+#endif // SCREENDIALOG_H
+
+

+ 1 - 1
main.cpp

@@ -54,7 +54,7 @@ int main(int argc, char *argv[]) {
     
     QApplication a(argc, argv);
     SlideWindow w;
-    w.show();
+//    w.show();
     
     return a.exec();
 }

+ 91 - 0
screenutils.cpp

@@ -0,0 +1,91 @@
+#include "screenutils.h"
+#include <QWidget>
+#include <QRect>
+#include <QLabel>
+#include <QTimer>
+#include <QGridLayout>
+#include <QStyleOption>
+#include <QMouseEvent>
+#include <QPainter>
+
+DesktopBox::DesktopBox(int screen, int w, int h)
+        : QWidget() {
+    this->screen = screen;
+    setStyleSheet(base_style);
+    setFixedSize(w, h);
+}
+
+void DesktopBox::mousePressEvent(QMouseEvent *event) {
+    if (event->button() == Qt::LeftButton) {
+        emit clicked();
+        emit clicked(screen);
+    }
+}
+
+void DesktopBox::mouseDoubleClickEvent(QMouseEvent *event) {
+    if (event->button() == Qt::LeftButton) {
+        emit doubleClicked();
+    }
+}
+
+void DesktopBox::paintEvent(QPaintEvent *) {
+    QStyleOption opt;
+    opt.init(this);
+    QPainter p(this);
+    style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
+}
+
+void DesktopBox::highlight() {
+    highlight(true);
+}
+
+void DesktopBox::highlight(bool h) {
+    if (h)
+        setStyleSheet(QString(base_style) + "background-color: rbg(255, 0, 0);");
+    else
+        setStyleSheet(base_style);
+}
+
+void DesktopBox::setIdentifier(QRect dimensions) {
+    ident = new ScreenIdentifier(screen, dimensions);
+}
+
+void DesktopBox::identify() {
+    if (ident!=NULL) {
+        ident->show();
+    }
+}
+
+
+ScreenIdentifier::ScreenIdentifier(int number, QRect dimensions, int timeout, QWidget *parent)
+        : QWidget(parent) {
+    //housework
+    setWindowFlags(Qt::SplashScreen | Qt::WindowStaysOnTopHint);
+    setCursor(Qt::BlankCursor);
+    setStyleSheet("background-color: rgb(0, 0, 0);");
+//    setAttribute(Qt::WA_TranslucentBackground);
+    
+    //set attributes
+    this->timeout = timeout;
+    setBaseSize(dimensions.width(), dimensions.height());
+    setGeometry(dimensions.x(), dimensions.y(), dimensions.width(), dimensions.height());
+    
+    //the visuals
+    QLabel *label = new QLabel(QString::number(number));
+    label->setFont(QFont("Arial", 340, QFont::Bold));
+    label->setStyleSheet("color: rgb(255, 255, 255);");
+    
+    QGridLayout *layout = new QGridLayout(this);
+    layout->setAlignment(Qt::AlignCenter);
+    layout->addWidget(label, 0, 0);
+    
+    //do the timeout
+    timer = new QTimer();
+    timer->setSingleShot(true);
+    connect(timer, SIGNAL(timeout()), this, SLOT(hide()));
+}
+
+void ScreenIdentifier::show() {
+    timer->start(timeout);
+    QWidget::show();
+}

+ 57 - 0
screenutils.h

@@ -0,0 +1,57 @@
+#ifndef DESKTOPBOX_H
+#define DESKTOPBOX_H
+#include "common.h"
+#include <QWidget>
+#define base_style "border: 2px solid rbg(0,0,0);"
+
+class ScreenIdentifier;
+
+class DesktopBox 
+        : public QWidget {
+    Q_OBJECT
+    
+    int screen;
+    ScreenIdentifier *ident;
+    
+    public:
+        explicit DesktopBox(int screen, int w, int h);
+        void mousePressEvent(QMouseEvent *event);
+        void mouseDoubleClickEvent(QMouseEvent *event);
+        void paintEvent(QPaintEvent *);
+        void setIdentifier(QRect dimensions);
+        
+    public slots:
+        void highlight(bool h);
+        void highlight();
+        void identify();
+        
+    signals:
+        void clicked();
+        void clicked(int);
+        void doubleClicked();
+};
+
+#endif // DESKTOPBOX_H
+
+#ifndef SCREENIDENTIFIER_H
+#define SCREENIDENTIFIER_H
+#include <QWidget>
+class QLabel;
+class QTimer;
+class QRect;
+
+class ScreenIdentifier : public QWidget {
+        Q_OBJECT
+        
+        QLabel *label;
+        QTimer *timer;
+        int timeout;
+        
+    public:
+        explicit ScreenIdentifier(int number, QRect dimensions, int timeout = 1500, QWidget *parent = 0);
+        
+    public slots:
+        void show();
+};
+
+#endif // SCREENIDENTIFIER_H

+ 19 - 8
slidewindow.cpp

@@ -14,8 +14,14 @@ SlideWindow::SlideWindow(QWidget *parent)
     st = new QSettings(company_str, app_str);
     timeout = st->value("timeout").toInt();
     
-    setupUi();
-    setupLogin();
+    setupScreens();
+}
+
+void SlideWindow::setupScreens() {
+    ScreenDialog *diag = new ScreenDialog(this);
+    connect(diag, SIGNAL(accepted()), this, SLOT(setupLogin()));
+    connect(diag, SIGNAL(rejected()), qApp, SLOT(quit()));
+    diag->show();
 }
 
 void SlideWindow::setupUi() {
@@ -23,9 +29,11 @@ void SlideWindow::setupUi() {
     setWindowTitle("PhotoBunny");
     setWindowIcon(QIcon(":/img/icon.png"));
     
-    QDesktopWidget *desktop = new QDesktopWidget();
-    setFixedWidth(desktop->width());
-    setFixedHeight(desktop->height());
+    QDesktopWidget desktop;
+    QRect d = desktop.screenGeometry(st->value("screen").toInt());
+    setFixedWidth(d.width());
+    setFixedHeight(d.height());
+    setGeometry(d);
     
     setWindowState(Qt::WindowFullScreen);
     setWindowFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint);
@@ -65,12 +73,15 @@ void SlideWindow::setupUi() {
     connect(aboutAction, SIGNAL(triggered()), this, SLOT(about()));
     connect(pauseAction, SIGNAL(triggered()), this, SLOT(pause()));
     connect(blankAction, SIGNAL(triggered()), this, SLOT(blank()));
+    
+    show();
+    setupFB();
 }
 
 void SlideWindow::setupLogin() {
     
     //open login dialog
-    loginDiag = new LoginDialog(this);
+    LoginDialog *loginDiag = new LoginDialog(this);
     loginDiag->show();
     
     connect(loginDiag, SIGNAL(accepted()), this, SLOT(setupAlbums()));
@@ -78,9 +89,9 @@ void SlideWindow::setupLogin() {
 }
 
 void SlideWindow::setupAlbums() {
-    albumDiag = new AlbumDialog(this);
+    AlbumDialog *albumDiag = new AlbumDialog(this);
     albumDiag->show();
-    connect(albumDiag, SIGNAL(accepted()), this, SLOT(setupFB()));
+    connect(albumDiag, SIGNAL(accepted()), this, SLOT(setupUi()));
     connect(albumDiag, SIGNAL(rejected()), qApp, SLOT(quit()));
 }
 

+ 5 - 56
slidewindow.h

@@ -1,53 +1,3 @@
-<<<<<<< HEAD
-/* 
- * Project PhotoBunny
- * 2014 Gwilyn Saunders
- */
-
-#ifndef SLIDEWINDOW_H
-#define SLIDEWINDOW_H
-
-#include <QMainWindow>
-#include <QPixmap>
-#include <QLabel>
-#include <QTimer>
-#include <QSettings>
-#include "common.h"
-#include "fbApi.h"
-#include "dialogs.h"
-
-class SlideWindow 
-        : public QMainWindow {
-    Q_OBJECT
-    
-    int timeout;
-    
-    QLabel *img;
-    QTimer *timer;
-    FbApi *fb;
-    LoginDialog *loginDiag;
-    AlbumDialog *albumDiag;
-    QSettings *st;
-    
-    public:
-        SlideWindow(QWidget *parent = 0);
-        
-    public slots:
-        void photoChange();
-        void setImage(QString path);
-        void loggedIn();
-        void pause();
-        void blank();
-        void about();
-        void setupUi();
-        void setupLogin();
-        void setupAlbums();
-        void setupFB();
-};
-
-#endif // SLIDEWINDOW_H
-
-=======
 /* 
  * Project PhotoBunny
  * 2014 Gwilyn Saunders
@@ -74,14 +24,11 @@ class SlideWindow
     QLabel *img;
     QTimer *timer;
     FbApi *fb;
-    LoginDialog *loginDiag;
-    AlbumDialog *albumDiag;
     QSettings *st;
     
     public:
         SlideWindow(QWidget *parent = 0);
         
-        
     public slots:
         void photoChange();
         void setImage(QString path);
@@ -89,9 +36,11 @@ class SlideWindow
         void pause();
         void blank();
         void about();
-        void openDialogs();
+        void setupScreens();
+        void setupUi();
+        void setupLogin();
+        void setupAlbums();
+        void setupFB();
 };
 
 #endif // SLIDEWINDOW_H
-
->>>>>>> 8c94ba006c0fe0ef23a00b031e91a4988533b4fe