File: askDiversification.cpp

package info (click to toggle)
attal 0.9.2-1.2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 2,992 kB
  • ctags: 5,972
  • sloc: cpp: 44,510; sh: 160; makefile: 45
file content (191 lines) | stat: -rw-r--r-- 4,390 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/****************************************************************
**
** Attal : Lords of Doom
**
** askDiversification.cpp
** Displays and asks diversification of tiles

**
** Version : $Id: askDiversification.cpp,v 1.2 2004/01/15 18:07:19 audoux Exp $
**
** Author(s) : Pascal Audoux
**
** Date : 12/01/2004
**
** Licence :    
**	This program is free software; you can redistribute it and/or modify
**   	it under the terms of the GNU General Public License as published by
**     	the Free Software Foundation; either version 2, or (at your option)
**      any later version.
**
**	This program is distributed in the hope that it will be useful,
** 	but WITHOUT ANY WARRANTY; without even the implied warranty of
**	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
**	GNU General Public License for more details.
**
****************************************************************/

#include "askDiversification.h"
 
// generic include files
// include files for QT
#include <qlayout.h>
#include <qlistbox.h>
#include <qpushbutton.h>
// application specific include files
#include "libCommon/dataTheme.h"
#include "libCommon/genericCell.h"
#include "libCommon/log.h"

#include "libClient/askWidget.h"
#include "libClient/gui.h"
#include "libClient/imageTheme.h"

extern QString DATA_PATH;
extern QString IMAGE_PATH;
extern ImageTheme ImageTheme;
extern DataTheme DataTheme;

//
// ----- AskDiversification -----
//


AskDiversification::AskDiversification( const QString & destination, QWidget * parent, const char * name )
: QDialog( parent, name, true )
{
	_pixmap = new AskPixmap( true, destination, "Tile: ", this );
	_weight = new AskInt( "Weight: ", this );

	QPushButton * pbOk = new QPushButton( "Ok", this );
	FIXEDSIZE( pbOk );

	QPushButton * pbCan = new QPushButton( "Cancel", this );
	FIXEDSIZE( pbCan );

	QHBoxLayout * layH1 = new QHBoxLayout();
	layH1->addStretch( 1 );
	layH1->addWidget( pbCan );
	layH1->addStretch( 1 );
	layH1->addWidget( pbOk );
	layH1->addStretch( 1 );

	QVBoxLayout * layout = new QVBoxLayout( this );
	layout->setSpacing( 5 );
	layout->setMargin( 5 );
	layout->addWidget( _pixmap );
	layout->addWidget( _weight );
	layout->addStretch( 1 );
	layout->addLayout( layH1 );
	layout->activate();

	connect( pbOk, SIGNAL( clicked() ), SLOT( accept() ) );
	connect( pbCan, SIGNAL( clicked() ), SLOT( reject() ) );
}

uint AskDiversification::getWeight()
{
	return _weight->getValue();
}


void AskDiversification::setWeight( uint weight )
{
	_weight->setValue( weight );
}


QString AskDiversification::getPixmapPath()
{
	return _pixmap->getValue();
}


void AskDiversification::setPixmapPath( const QString & path )
{
	_pixmap->setValue( path );
}

void AskDiversification::accept()
{
	_pixmap->save();
}

//
// ----- AskDiversificationList -----
//

AskDiversificationList::AskDiversificationList( QWidget * parent, const char * name )
:QWidget( parent, name )
{
	_cell = 0;
	_list = new QListBox( this );

	_pbNew = new QPushButton( tr("New"), this );
	FIXEDSIZE( _pbNew );

	_pbDel = new QPushButton( tr("Del"), this );
	FIXEDSIZE( _pbDel );

	QVBoxLayout * layV1 = new QVBoxLayout();
	layV1->setMargin( 5 );
	layV1->setSpacing( 5 );
	layV1->addWidget( _pbNew );
	layV1->addWidget( _pbDel );
	layV1->addStretch( 1 );

	QHBoxLayout * layout = new QHBoxLayout( this );
	layout->setMargin( 5 );
	layout->setSpacing( 5 );
	layout->addWidget( _list, 1 );
	layout->addLayout( layV1 );
	layout->activate();

	connect( _pbNew, SIGNAL( clicked() ), SLOT( slot_new() ) );
	connect( _pbDel, SIGNAL( clicked() ), SLOT( slot_del() ) );
}

void AskDiversificationList::slot_new()
{
	AskDiversification dialog( IMAGE_PATH + "/tiles/new.png", this );
	if( dialog.exec() ) {
	}
}

void AskDiversificationList::slot_del()
{
	if( _list->count() > 1 ) {
	}
}

void AskDiversificationList::setValue( CellModel * cell )
{
	uint nb, val, index = 0;
	QString text;

	_cell = cell;
	_list->clear();
	nb = _cell->getDiversificationNumber();
	for( uint j = 0; j < DataTheme.tiles.count(); j++ ) {
		if( DataTheme.tiles.at(j) == cell ) {
			index = j;
			break;
		}
	}
	for( uint i = 0; i < nb; i++ ) {
		val = _cell->getDiversification( i );
		text.sprintf( "(weight = %d)", val );
		new QListBoxPixmap( _list, * ImageTheme.cells[index]->image( i ), text );
	}
}

void AskDiversificationList::save()
{

}

void AskDiversificationList::clear()
{
	_list->clear();
}