Skip to content
This repository
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 246 lines (197 sloc) 7.513 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
/*
* Copyright (c) 2011 Nokia Corporation
*
* This file is part of the Push Snowboarding Project, More info at:
* www.pushsnowboading.com
*
* Author: Clovis Scotti <scotti@ieee.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/

#include "graphicssettings.h"

GraphicsSettings::GraphicsSettings(PushDevicesHolder* devs, QObject* parent=0) : configuredDevices(devs)
{
    this->setParent(parent);
    this->setZValue(0.2);

    homeBt = new GraphicPixmapBt(":/buttons/home_bt.png", this);
    homeBt->setPos(0,0);
    connect(homeBt, SIGNAL(activated()), this, SIGNAL(home_bt_clicked()));

    liveView = 0;

    startLiveViewBt = new GraphicTextBt("LIVE VIEW (DEBUG)", this);
    startLiveViewBt->setPos(110+5,0);
    connect(startLiveViewBt, SIGNAL(activated()), this, SLOT(start_live_view()));

    //Settings form:

    userNameField = 0;
    proxy2edit = 0;

    soundEffectsCheck = 0;
    proxy2soundEffects = 0;


    serverAddress = 0;
    proxy2Addr = 0;
    serverPort = 0;
    proxy2Port = 0;
    connectPushBt = 0;
    proxy2connect = 0;

    buildForm();

}

GraphicsSettings::~GraphicsSettings()
{
    if(liveView)
        liveView->deleteLater();
}

QRectF GraphicsSettings::boundingRect() const
{
    return QRectF(0,0,340,382+6+54);
}

void GraphicsSettings::paint(QPainter *painter, const QStyleOptionGraphicsItem * option,QWidget *widget)
{
    Q_UNUSED(option);
    Q_UNUSED(widget);

    painter->setBrush(Qt::white);
    painter->drawRect(QRect(0,60,340,382));

// painter->setPen(QColor(17,83,161));

// painter->setFont(QFont("Nokia Standard Bold", 6));

// painter->drawText(QRect(0,60,340,382), Qt::AlignCenter, "Woohoo, nothing creepy here!\n We set it all up for you!");
}

void GraphicsSettings::start_live_view()
{
    if(liveView)
        liveView->deleteLater();

    for(int i=0;i<configuredDevices->count();i++) {
        configuredDevices->at(i)->start_readings();
    }

    qDebug() << "Opening up live viewer";

    liveView = new LiveView(configuredDevices);

    connect(liveView, SIGNAL(leaving()), this, SLOT(end_live_view()));

    liveView->showMaximized();
}

void GraphicsSettings::end_live_view()
{
// for(int i=0;i<devicesHolder.count();i++) {
// configuredDevices->at(i)->stop_readings();
// }
    liveView->deleteLater();
    liveView = 0;
}


void GraphicsSettings::update_soundEffects(bool checked)
{
    if(configuredDevices) {
        for(int i=0;i< configuredDevices->size();i++) {
            PushBurtonGenericDevice * dev = configuredDevices->at(i);
            if(typeid(*dev) == typeid(VirtualBrosDevice)) {
                ((VirtualBrosDevice*)dev)->setEnabled(checked);
                break;
            }
        }
    }
}

bool GraphicsSettings::get_soundEffects()
{
    if(configuredDevices) {
        for(int i=0;i< configuredDevices->size();i++) {
            PushBurtonGenericDevice * dev = configuredDevices->at(i);
            if(typeid(*dev) == typeid(VirtualBrosDevice)) {
                return ((VirtualBrosDevice*)dev)->getEnabled();
            }
        }
    }
    return false;
}


void GraphicsSettings::buildForm()
{
    QString widStyle("color: blue;"
                      "background-color: transparent;"
                      "border-color: blue;"
                      "border-style: solid;"
                      "border-width: 1px;");

    QRect widGeom(0,0,180, 30);

    //Username field
    userNameField = new QLineEdit("Username");
    userNameField->setStyleSheet(widStyle);
    proxy2edit = new QGraphicsProxyWidget(this);
    proxy2edit->setWidget(userNameField);
    userNameField->setGeometry(widGeom);
    proxy2edit->setVisible(true);
    proxy2edit->setZValue(2);
    proxy2edit->setPos(40, 120);



    //Sound Effects Field
    soundEffectsCheck = new QCheckBox("Sound Effects");
    soundEffectsCheck->setStyleSheet("color: blue;"
                                     "background-color: transparent;"
                                     "border-width: 0px;");
    proxy2soundEffects = new QGraphicsProxyWidget(this);
    proxy2soundEffects->setWidget(soundEffectsCheck);
    soundEffectsCheck->setGeometry(widGeom);
    proxy2soundEffects->setVisible(true);
    proxy2soundEffects->setZValue(2);
    proxy2soundEffects->setPos(40,160);
    soundEffectsCheck->setChecked(get_soundEffects());
    connect(soundEffectsCheck, SIGNAL(toggled(bool)), this, SLOT(update_soundEffects(bool)));

    //Address and Port line edits
    serverAddress = new QLineEdit("Address");
    serverAddress->setStyleSheet(widStyle);
    proxy2Addr = new QGraphicsProxyWidget(this);
    proxy2Addr->setWidget(serverAddress);
    serverAddress->setGeometry(0,0,150,30);
    proxy2Addr->setVisible(true);
    proxy2Addr->setZValue(2);
    proxy2Addr->setPos(40,200);

    serverPort = new QLineEdit("Port");
    serverPort->setStyleSheet(widStyle);
    proxy2Port = new QGraphicsProxyWidget(this);
    proxy2Port->setWidget(serverPort);
    serverPort->setGeometry(0,0,80, 30);
    proxy2Port->setVisible(true);
    proxy2Port->setZValue(2);
    proxy2Port->setPos(200, 200);


    connectPushBt = new QPushButton("Connect");
    connectPushBt->setStyleSheet(widStyle);
    proxy2connect = new QGraphicsProxyWidget(this);
    proxy2connect->setWidget(connectPushBt);
    connectPushBt->setGeometry(widGeom);
    proxy2connect->setVisible(true);
    proxy2connect->setZValue(2);
    proxy2connect->setPos(40,240);

    connect(connectPushBt, SIGNAL(released()), this, SLOT(connectBroadcaster()));


}

void GraphicsSettings::connectBroadcaster()
{
    if(configuredDevices) {
        for(int i=0;i< configuredDevices->size();i++) {
            PushBurtonGenericDevice * dev = configuredDevices->at(i);
            if(typeid(*dev) == typeid(BroadcasterDevice)) {
                BroadcasterDevice * bdev = (BroadcasterDevice*)dev;
                connect(bdev, SIGNAL(connectionUpdate(bool)), this, SLOT(updateConnectionState(bool)));

                bdev->setServerAddress(serverAddress->text());
                bdev->setServerPort((quint16)serverPort->text().toInt());

                return bdev->tryToConnect();
            }
        }
    }

}

void GraphicsSettings::updateConnectionState(bool connected)
{
    if(connectPushBt) {
        if(connected) {
            connectPushBt->setText("Disconnect");
            connectPushBt->setEnabled(false);
        } else {
            connectPushBt->setText("Connect");
        }
    }
}
Something went wrong with that request. Please try again.