1 /* |
|
2 * Hedgewars, a free turn based strategy game |
|
3 * Copyright (c) 2006-2011 Andrey Korotaev <unC0Rr@gmail.com> |
|
4 * |
|
5 * This program is free software; you can redistribute it and/or modify |
|
6 * it under the terms of the GNU General Public License as published by |
|
7 * the Free Software Foundation; version 2 of the License |
|
8 * |
|
9 * This program is distributed in the hope that it will be useful, |
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 * GNU General Public License for more details. |
|
13 * |
|
14 * You should have received a copy of the GNU General Public License |
|
15 * along with this program; if not, write to the Free Software |
|
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
17 */ |
|
18 |
|
19 #include "AbstractPage.h" |
|
20 |
|
21 AbstractPage::AbstractPage(QWidget* parent) |
|
22 { |
|
23 Q_UNUSED(parent); |
|
24 |
|
25 font14 = new QFont("MS Shell Dlg", 14); |
|
26 } |
|
27 |
|
28 void AbstractPage::initPage() |
|
29 { |
|
30 QGridLayout * pageLayout = new QGridLayout(this); |
|
31 |
|
32 // stretch grid space for body and footer |
|
33 pageLayout->setColumnStretch(0,0); |
|
34 pageLayout->setColumnStretch(1,1); |
|
35 pageLayout->setRowStretch(0,1); |
|
36 pageLayout->setRowStretch(1,0); |
|
37 |
|
38 // add back/exit button |
|
39 btnBack = formattedButton(":/res/Exit.png", true); |
|
40 pageLayout->addWidget(btnBack, 1, 0, 1, 1, Qt::AlignLeft | Qt::AlignBottom); |
|
41 |
|
42 // add body layout as defined by the subclass |
|
43 pageLayout->addLayout(bodyLayoutDefinition(), 0, 0, 1, 2); |
|
44 |
|
45 // add footer layout |
|
46 QLayout * fld = footerLayoutDefinition(); |
|
47 if (fld != NULL) |
|
48 pageLayout->addLayout(fld, 1, 1); |
|
49 |
|
50 // connect signals |
|
51 connect(btnBack, SIGNAL(clicked()), this, SIGNAL(goBack())); |
|
52 connectSignals(); |
|
53 } |
|
54 |
|
55 QPushButton * AbstractPage::formattedButton(const QString & btname, bool hasIcon) |
|
56 { |
|
57 QPushButton * btn = new QPushButton(this); |
|
58 |
|
59 if (hasIcon) |
|
60 { |
|
61 const QIcon& lp=QIcon(btname); |
|
62 QSize sz = lp.actualSize(QSize(65535, 65535)); |
|
63 btn->setIcon(lp); |
|
64 btn->setFixedSize(sz); |
|
65 btn->setIconSize(sz); |
|
66 btn->setFlat(true); |
|
67 btn->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); |
|
68 } |
|
69 else |
|
70 { |
|
71 btn->setFont(*font14); |
|
72 btn->setText(btname); |
|
73 } |
|
74 return btn; |
|
75 } |
|
76 |
|
77 QPushButton * AbstractPage::addButton(const QString & btname, QGridLayout* grid, int wy, int wx, bool hasIcon) |
|
78 { |
|
79 QPushButton * btn = formattedButton(btname, hasIcon); |
|
80 grid->addWidget(btn, wy, wx); |
|
81 return btn; |
|
82 } |
|
83 |
|
84 QPushButton * AbstractPage::addButton(const QString & btname, QGridLayout* grid, int wy, int wx, int rowSpan, int columnSpan, bool hasIcon) |
|
85 { |
|
86 QPushButton * btn = formattedButton(btname, hasIcon); |
|
87 grid->addWidget(btn, wy, wx, rowSpan, columnSpan); |
|
88 return btn; |
|
89 } |
|
90 |
|
91 QPushButton * AbstractPage::addButton(const QString & btname, QBoxLayout* box, int where, bool hasIcon) |
|
92 { |
|
93 QPushButton * btn = formattedButton(btname, hasIcon); |
|
94 box->addWidget(btn, where); |
|
95 return btn; |
|
96 } |
|
97 |
|
98 void AbstractPage::setBackButtonVisible(bool visible) |
|
99 { |
|
100 btnBack->setVisible(visible); |
|
101 } |
|