Subversion Repositories svn1-original

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
107 - 1
#include "qmconfwinners.h"
178 - 2
#include "qmconfig.h"
107 - 3
#include "ui_qmconfwinners.h"
185 - 4
#include "mainwindow.h"
107 - 5
 
108 - 6
#include    "consts.h"
7
#include    "structs.h"
8
#include    "proto.h"
9
 
294 david 10
#include <QDialogButtonBox>
11
#include <QTableWidgetItem>
12
#include <QVBoxLayout>
108 - 13
 
107 - 14
QmConfWinners::QmConfWinners(QWidget *parent) :
294 david 15
    QWidget(parent)
107 - 16
{
108 - 17
 
185 - 18
    dirty = true;
19
    populating = false;
20
 
294 david 21
    QVBoxLayout *verticalLayout = new QVBoxLayout(this);
22
    verticalLayout->setContentsMargins(0, 0, 0, 0);
185 - 23
 
294 david 24
    QGroupBox *groupBox = new QGroupBox("Hall of Fame");
25
    verticalLayout->addWidget(groupBox);
26
    QVBoxLayout *verticalLayout2 = new QVBoxLayout(groupBox);
27
    tableWidget = new QTableWidget(groupBox);
28
 
29
    tableWidget->setAlternatingRowColors(true);
30
    tableWidget->setRowCount(MAX_FAME);
31
    tableWidget->setColumnCount(1);
32
    tableWidget->horizontalHeader()->setVisible(false);
33
    tableWidget->horizontalHeader()->setCascadingSectionResizes(false);
34
    tableWidget->horizontalHeader()->setStretchLastSection(true);
35
    tableWidget->verticalHeader()->setDefaultSectionSize(20);
36
    tableWidget->verticalHeader()->setStretchLastSection(false);
37
    verticalLayout2->addWidget(tableWidget);
38
 
39
    QSpacerItem *verticalSpacer1;
40
    verticalSpacer1 = new QSpacerItem(0, 10, QSizePolicy::Expanding, QSizePolicy::Expanding);
41
    verticalLayout2->addItem(verticalSpacer1);
42
 
43
    QHBoxLayout *horizontalLayout;
44
    horizontalLayout = new QHBoxLayout();
45
    horizontalLayout->setContentsMargins(0, 0, 5, 5);
46
    verticalLayout->addLayout(horizontalLayout);
47
 
48
    QDialogButtonBox *buttonBox = new QDialogButtonBox();
49
    pushButtonRestore = buttonBox->addButton("Restore",QDialogButtonBox::ActionRole );
50
    pushButtonSave = buttonBox->addButton("Save",QDialogButtonBox::ActionRole );
51
    horizontalLayout->addWidget(buttonBox);
52
 
53
    connect(pushButtonSave, SIGNAL(clicked()), this, SLOT(save()) );
54
    connect(pushButtonRestore, SIGNAL(clicked()), this, SLOT(cancel()) );
55
    connect(tableWidget, SIGNAL(cellChanged(int,int)), this, SLOT(changed()));
56
 
108 - 57
    populate();
107 - 58
}
59
 
60
QmConfWinners::~QmConfWinners()
61
{
62
}
63
 
108 - 64
void QmConfWinners::populate(void)
65
{
185 - 66
    populating = true;
108 - 67
    for ( int ii = 0; ii < MAX_FAME; ii++)
68
    {
294 david 69
        tableWidget->setItem(ii, 0, new QTableWidgetItem(config.hall_fame[ii] ));
108 - 70
    }
185 - 71
    populating = false;
72
    updateChanged(false);
108 - 73
}
74
 
75
void QmConfWinners::save(void)
76
{
77
    /*
78
    **    Copy original data
79
    */
180 - 80
     QmConfig newcfg(config);
108 - 81
 
82
    /*
83
    **  Extract the data from the Widgets
84
    */
85
    for ( int ii = 0; ii < MAX_FAME; ii++)
86
    {
294 david 87
        QTableWidgetItem *item = tableWidget->item ( ii, 0 );
108 - 88
        if ( item )
89
        {
90
            strncpy(newcfg.hall_fame[ii], qPrintable(item->text()), sizeof(newcfg.hall_fame[ii])-1);
91
        }
92
    }
93
 
94
    newcfg.num_fame = 0;
95
    for( int i = 0; i < MAX_FAME; i++ )
96
        if( newcfg.hall_fame[i][0] )
97
            newcfg.num_fame++;
98
 
185 - 99
    // Sanity Check
100
    try
108 - 101
    {
185 - 102
        MainWindow::showMessage( "Saving Config");
103
        for( int i = newcfg.num_fame; i < MAX_FAME; i++ )
104
            if( newcfg.hall_fame[i][0] )
105
            {
106
                throw ( "Configuration error: Missing Fame name. Gaps not allowed" );
107
            }
108
 
108 - 109
        config = newcfg;
180 - 110
        config.write_config();
185 - 111
        updateChanged(false);
108 - 112
    }
185 - 113
    catch ( const char * str)
114
    {
115
        MainWindow::showMessage(str);
116
    }
117
 
108 - 118
}
119
 
120
void QmConfWinners::cancel(void)
121
{
122
    populate();
123
}
185 - 124
 
125
void QmConfWinners::changed(void)
126
{
127
    if ( populating )
128
        return;
129
    updateChanged(true);
130
}
131
 
132
void QmConfWinners::updateChanged(bool newDirty)
133
{
134
    if (newDirty != dirty)
135
    {
136
        dirty = newDirty;
137
        if (dirty)
138
        {
294 david 139
            pushButtonSave->setEnabled(true);
140
            pushButtonSave->setStyleSheet("background-color: rgb(255, 0, 0);");
141
            MainWindow::showMessage("Winners Data Changed");
185 - 142
        }
143
        else
144
        {
294 david 145
            pushButtonSave->setEnabled(false);
146
            pushButtonSave->setStyleSheet("");
147
            MainWindow::showMessage("");
185 - 148
        }
149
    }
150
}
151