Subversion Repositories svn1

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
126 david 1
#include "mainwindow.h"
2
#include "ui_mainwindow.h"
3
#include "qmconfigure.h"
4
#include "qmconfclass.h"
5
#include "qmconfwinners.h"
6
#include "qmteamdisplay.h"
7
#include "QMessageBox"
129 david 8
#include "QInputDialog"
130 - 9
#include "QTime"
10
#include "qmdialoglegstarttimes.h"
134 david 11
#include "qmdisqualified.h"
137 - 12
#include "qmdatacheck.h"
144 - 13
#include "qmdialogloadexternalteams.h"
145 - 14
#include "QFileDialog"
15
#include "QDir"
126 david 16
 
17
#include    "consts.h"
18
#include    "structs.h"
19
#include    "proto.h"
20
 
21
MainWindow *mw = NULL;
22
 
23
MainWindow::MainWindow(QWidget *parent) :
24
    QMainWindow(parent),
25
    ui(new Ui::MainWindow)
26
{
27
    ui->setupUi(this);
28
    mw = this;
29
 
144 - 30
    ui->tabWidget->addTab( new QmConfigure,    "Configure");
31
    ui->tabWidget->addTab( new QmConfClass,    "Class");
32
    ui->tabWidget->addTab( new QmConfWinners,  "Winners");
33
    ui->tabWidget->addTab( new qmTeamDisplay,  "Team Data");
134 david 34
    ui->tabWidget->addTab( new qmDisqualified, "Disqual");
144 - 35
    ui->tabWidget->addTab( new qmDataCheck,    "Data Check");
126 david 36
 
140 david 37
    QMenu *m0 = new QMenu ("Team");
38
    ui->menuBar->addMenu(m0);
39
    m0->addAction("Reset All Team Data", this, SLOT(resetTeamData()));
40
    m0->addAction("Generate dummy team names", this, SLOT(generateDummyTeamNames()));
41
 
127 - 42
    QMenu *m1 = new QMenu ("Leg Time Setup");
43
    ui->menuBar->addMenu(m1);
44
    m1->addAction("Clear ALL Leg Times", this, SLOT(clearLegTimes()));
129 david 45
    m1->addAction("Clear single leg start times", this, SLOT(ClearOneLegTimes()));
140 david 46
    m1->addSeparator();
47
    m1->addAction("Set Start Times", this, SLOT(setStartTimes()));
129 david 48
    m1->addAction("Set calculated leg start", this, SLOT(setCalcLegStart()));
131 david 49
    m1->addAction("Set ordered incremental leg start", this, SLOT(setOrderedIncLegStart()));
50
    m1->addAction("Set staggered start time", this, SLOT(setStaggeredLegStart()));
51
    m1->addAction("Set fixed start time", this, SLOT(setFixedLegStart()));
140 david 52
 
53
    QMenu *m2 = new QMenu ("Upload");
54
    ui->menuBar->addMenu(m2);
144 - 55
    m2->addAction("Load team information from external file", this, SLOT(loadExternalTeams()));
140 david 56
 
126 david 57
}
58
 
59
MainWindow::~MainWindow()
60
{
61
    delete ui;
62
}
63
 
133 david 64
void MainWindow::showMessage( const QString & msg, int timeout)
65
{
66
    if ( mw )
67
    {
68
        mw->ui->statusBar->showMessage(msg, timeout);
69
    }
70
}
71
 
126 david 72
void MainWindow::changeEvent(QEvent *e)
73
{
74
    QMainWindow::changeEvent(e);
75
    switch (e->type()) {
76
    case QEvent::LanguageChange:
77
        ui->retranslateUi(this);
78
        break;
79
    default:
80
        break;
81
    }
82
}
83
 
84
void MainWindow::setStartTimes(void)
85
{
127 - 86
    if ( QMessageBox::Ok == QMessageBox::warning(this, tr("Mara"),
131 david 87
                                    tr("This will reset the start times for all teams based on the Category configuration.\n"
126 david 88
                                       "Are you sure you want to do this?"),
89
                                    QMessageBox::Cancel,
90
                                    QMessageBox::Ok))
91
    {
127 - 92
        leg_start();
126 david 93
    }
127 - 94
 
126 david 95
}
96
 
127 - 97
void MainWindow::clearLegTimes(void)
98
{
99
    if ( QMessageBox::Ok == QMessageBox::warning(this, tr("Mara"),
100
                                    tr("This will clear ALL leg times for ALL teams.\n"
101
                                       "Are you sure you want to do this?"),
102
                                    QMessageBox::Cancel,
103
                                    QMessageBox::Ok))
104
    {
105
        leg_ini();
106
    }
107
}
108
 
109
void MainWindow::resetTeamData(void)
110
{
111
    if ( QMessageBox::Ok == QMessageBox::warning(this, tr("Mara"),
112
                                    tr("This will clear ALL team information.\n"
113
                                       "Are you sure you want to do this?"),
114
                                    QMessageBox::Cancel,
115
                                    QMessageBox::Ok))
116
    {
117
        tm_init();
118
    }
119
}
120
 
128 - 121
void MainWindow::generateDummyTeamNames(void)
122
{
123
    if ( QMessageBox::Ok == QMessageBox::warning(this, tr("Mara"),
124
                                    tr("This will generate DUMMY team names.\n"
125
                                       "Are you sure you want to do this?"),
126
                                    QMessageBox::Cancel,
127
                                    QMessageBox::Ok))
128
    {
129
        tm_gen();
130
    }
131
}
132
 
129 david 133
void MainWindow::ClearOneLegTimes(void)
134
{
135
    bool ok;
136
    int leg = QInputDialog::getInt(this, tr("Clear One Leg Start Time"),
137
                                              tr("Leg:"), 0, 0, config.num_legs, 1, &ok);
138
    if ( ok && leg)
139
    {
133 david 140
        tm_clearleg_specified(leg, FALSE);
129 david 141
    }
142
}
143
 
144
void MainWindow::setCalcLegStart(void)
145
{
130 - 146
    QmDialogLegStartTimes dialog("Calculate Leg Start Time",this);
131 david 147
    dialog.setDeltaTimeLabel("Delta Time");
148
qDebug ("Must disable stuff");
130 - 149
    if ( QDialog::Accepted == dialog.exec() )
129 david 150
    {
130 - 151
        if ( dialog.getLeg() )
152
        {
153
            tm_lgs(dialog.getLeg(),
131 david 154
                   dialog.getDeltaTime(),
155
                   dialog.getReport(),
156
                   dialog.getClear() );
157
        }
158
    }
159
}
160
 
161
void MainWindow::setOrderedIncLegStart(void)
162
{
163
    QmDialogLegStartTimes dialog("Ordered Incremental Leg Start Time",this);
164
    dialog.setTimeLabel("Start Time");
165
    dialog.setDeltaTimeLabel("Delta Time");
166
    if ( QDialog::Accepted == dialog.exec() )
167
    {
168
        if ( dialog.getLeg() )
169
        {
170
            tm_lgs1(dialog.getLeg(),
130 - 171
                   dialog.getTime(),
131 david 172
                   dialog.getDeltaTime(),
130 - 173
                   dialog.getReport(),
174
                   dialog.getClear() );
175
        }
129 david 176
    }
131 david 177
}
130 - 178
 
131 david 179
void MainWindow::setStaggeredLegStart(void)
180
{
181
    QmDialogLegStartTimes dialog("Staggered Leg Start Time",this);
182
    dialog.setTimeLabel("Start Time");
183
    dialog.setDeltaTimeLabel("Stagger Time");
184
    if ( QDialog::Accepted == dialog.exec() )
185
    {
186
        if ( dialog.getLeg() )
187
        {
188
            tm_staggered(dialog.getLeg(),
189
                   dialog.getTime(),
190
                   dialog.getDeltaTime(),
191
                   dialog.getReport(),
192
                   dialog.getClear() );
193
        }
194
    }
129 david 195
}
131 david 196
 
197
void MainWindow::setFixedLegStart(void)
198
{
199
    QmDialogLegStartTimes dialog("Fixed Leg Start Time",this);
200
    dialog.setTimeLabel("Start Time");
201
    //dialog.setDeltaTimeLabel("Stagger Time");
202
qDebug ("Must Hide stagger time");
203
    if ( QDialog::Accepted == dialog.exec() )
204
    {
205
        if ( dialog.getLeg() )
206
        {
207
            tm_fixedstart(dialog.getLeg(),
208
                   dialog.getTime(),
209
                   //dialog.getDeltaTime(),
210
                   dialog.getReport(),
211
                   dialog.getClear() );
212
        }
213
    }
214
}
144 - 215
 
216
void MainWindow::loadExternalTeams(void)
217
{
145 - 218
    QString fileName = QFileDialog::getOpenFileName(this, tr("Load File"),
219
                                                     QDir::currentPath(),
220
                                                     tr("Data (*.csv);;All (*.*)"),
221
                                                     0,
222
                                                     QFileDialog::ReadOnly);
223
    if ( fileName.isEmpty() )
224
    {
225
        return;
226
    }
227
 
228
    QmDialogLoadExternalTeams dialog(fileName,this);
144 - 229
    dialog.exec();
230
}
231
 
126 david 232
/*========================================================================
233
 *
234
 *  Position the cursor on the screen
235
 *
236
 *  Purpose:
237
 *      This function is called to Position the cursor on the screen
238
 *
239
 *  Parameters:
240
 *      x               col number
241
 *      y               line number
242
 *
243
 *  Returns:
244
 *      Nothing
245
 *
246
 *========================================================================*/
247
 
248
void cur( int x, int y )
249
{
250
}
251
 
252
/*========================================================================
253
 *
254
 *  Clears the vdu screen
255
 *
256
 *  Purpose:
257
 *      This function is called to Clears the vdu screen
258
 *      From the Microsoft Web Site
259
 *
260
 *  Parameters:
261
 *      None
262
 *
263
 *  Returns:
264
 *      Nothing
265
 *
266
 *========================================================================*/
267
 
268
void clearscreen( void )
269
{
270
}
271
#include    <stdio.h>
272
int printf( const char *format, ... )
273
{
274
    va_list     ap;
275
    char        pp[200];
276
    int         len;
277
 
278
 
279
 
280
    va_start( ap, format );
281
    len = vsprintf( pp, format, ap );
282
    va_end( ap );
283
    qDebug("%s",pp);
284
    return ( len );
285
}
286