Updated the web pages
[chessclock] / classes / startwidget.cpp
1  /**************************************************************************
2
3     Chess Clock
4
5     Copyright (c) Arto Hyvättinen 2010
6
7     This file is part of Chess Clock software.
8
9     Chess Clock is free software: you can redistribute it and/or modify
10     it under the terms of the GNU General Public License as published by
11     the Free Software Foundation, either version 3 of the License, or
12     (at your option) any later version.
13
14     Chess Clock is distributed in the hope that it will be useful,
15     but WITHOUT ANY WARRANTY; without even the implied warranty of
16     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17     GNU General Public License for more details.
18
19
20 **************************************************************************/
21
22 #include "startwidget.h"
23 #include "timecontrol.h"
24
25 #include <QVBoxLayout>
26 #include <QHBoxLayout>
27 #include <QApplication>
28 #include <QFont>
29 #include <QLabel>
30 #include <QListWidgetItem>
31
32 StartWidget::StartWidget(QWidget *parent) :
33     QWidget(parent)
34 {
35     QLabel* titleLabel = new QLabel( qApp->applicationName() );
36     titleLabel->setFont(QFont("Helvetica",32,QFont::Bold));
37
38     QLabel* copyLabel = new QLabel( tr("&copy; Arto Hyv&auml;ttinen 2010<br>Free software GPL3"));
39     copyLabel->setTextFormat(Qt::RichText);
40     copyLabel->setWordWrap(true);
41
42     QLabel* logoLabel = new QLabel;
43     logoLabel->setPixmap( QPixmap(":/rc/pic/logo.png"));
44
45     QLabel* introLabel = new QLabel( tr("<b>Select game mode &rarr;</b>"));
46     introLabel->setWordWrap(true);
47
48     QVBoxLayout* leftLayout = new QVBoxLayout;
49     leftLayout->addWidget(titleLabel);
50     leftLayout->addWidget(introLabel);
51     leftLayout->addWidget(logoLabel);
52     leftLayout->addWidget(copyLabel);
53
54     modeSelect_ = new QListWidget();
55     modeSelect_->setViewMode(QListView::ListMode);
56     modeSelect_->setMovement(QListView::Static);
57     modeSelect_->setSelectionMode(QAbstractItemView::NoSelection);
58     modeSelect_->setIconSize(QSize(40,40 ));
59
60     connect( modeSelect_, SIGNAL(itemClicked(QListWidgetItem*)),this,SLOT(selectControl(QListWidgetItem*)));
61
62 //    QVBoxLayout* rightLayout = new QVBoxLayout;
63 //    rightLayout->addWidget(introLabel);
64 //    rightLayout->addWidget(modeSelect_);
65
66     QHBoxLayout* layout = new QHBoxLayout;
67     layout->addLayout(leftLayout);
68     layout->addWidget(modeSelect_);
69
70
71     setLayout( layout );
72 }
73
74 void StartWidget::addTimeControl(TimeControl *tc)
75 {
76     timeControls_.append(tc);
77     QListWidgetItem* item = new QListWidgetItem(modeSelect_);
78     item->setText( tc->getName());
79     item->setIcon( tc->getIcon());
80     // Store index to UserRole
81     item->setData(Qt::UserRole, timeControls_.size()-1);
82
83 }
84
85 void StartWidget::selectControl(QListWidgetItem *item)
86 {
87     int index=item->data(Qt::UserRole).toInt();
88     TimeControl* tc=timeControls_.at(index);
89     emit selected(tc);
90
91 }
92