b790a92fc273f70169ae173c4a4bc6babd6dcae2
[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"));
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("Select game mode"));
46     introLabel->setWordWrap(true);
47
48     QVBoxLayout* leftLayout = new QVBoxLayout;
49     leftLayout->addWidget(titleLabel);
50     leftLayout->addWidget(copyLabel);
51     leftLayout->addWidget(logoLabel);
52     leftLayout->addWidget(introLabel);
53
54     modeSelect_ = new QListWidget();
55     modeSelect_->setViewMode(QListView::IconMode);
56     modeSelect_->setMovement(QListView::Static);
57     modeSelect_->setSelectionMode(QAbstractItemView::NoSelection);
58     modeSelect_->setIconSize(QSize(64,64 ));
59
60     connect( modeSelect_, SIGNAL(itemClicked(QListWidgetItem*)),this,SLOT(selectControl(QListWidgetItem*)));
61
62     QHBoxLayout* layout = new QHBoxLayout;
63     layout->addLayout(leftLayout);
64     layout->addWidget(modeSelect_);
65
66
67     setLayout( layout );
68 }
69
70 void StartWidget::addTimeControl(TimeControl *tc)
71 {
72     timeControls_.append(tc);
73     QListWidgetItem* item = new QListWidgetItem(modeSelect_);
74     item->setText( tc->getName());
75     item->setIcon( tc->getIcon());
76     // Store index to UserRole
77     item->setData(Qt::UserRole, timeControls_.size()-1);
78
79 }
80
81 void StartWidget::selectControl(QListWidgetItem *item)
82 {
83     int index=item->data(Qt::UserRole).toInt();
84     TimeControl* tc=timeControls_.at(index);
85     emit selected(tc);
86
87 }
88