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