Diffstat (limited to 'noncore/games/backgammon/themedialog.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/games/backgammon/themedialog.cpp | 163 |
1 files changed, 163 insertions, 0 deletions
diff --git a/noncore/games/backgammon/themedialog.cpp b/noncore/games/backgammon/themedialog.cpp new file mode 100644 index 0000000..dcb957c --- a/dev/null +++ b/noncore/games/backgammon/themedialog.cpp | |||
@@ -0,0 +1,163 @@ | |||
1 | #include "themedialog.h" | ||
2 | |||
3 | #include <qdir.h> | ||
4 | #include <qfileinfo.h> | ||
5 | #include <qlabel.h> | ||
6 | #include <qpushbutton.h> | ||
7 | #include <qpe/qpeapplication.h> | ||
8 | |||
9 | |||
10 | ThemeDialog::ThemeDialog(QWidget* parent,const char* name,bool modal,WFlags f) | ||
11 | :QDialog(parent,name,modal,f) | ||
12 | { | ||
13 | setCaption("Theme Dialog"); | ||
14 | QLabel* labelname=new QLabel("name",this); | ||
15 | labelname->setGeometry(0,5,40,20); | ||
16 | lineName=new QLineEdit("user",this); | ||
17 | lineName->setGeometry(40,5,195,20); | ||
18 | |||
19 | QLabel* labelboard=new QLabel("board",this); | ||
20 | labelboard->setGeometry(0,30,40,20); | ||
21 | boxboard=new QComboBox(this,""); | ||
22 | boxboard->setGeometry(40,30,195,20); | ||
23 | fillBox("boards",boxboard); | ||
24 | |||
25 | QLabel* labelpiecesA=new QLabel("pieces1",this); | ||
26 | labelpiecesA->setGeometry(0,70,40,20); | ||
27 | boxpiecesA=new QComboBox(this); | ||
28 | boxpiecesA->setGeometry(40,70,195,20); | ||
29 | fillBox("pieces",boxpiecesA); | ||
30 | |||
31 | QLabel* labelpiecesB=new QLabel("pieces2",this); | ||
32 | labelpiecesB->setGeometry(0,95,40,20); | ||
33 | boxpiecesB=new QComboBox(this); | ||
34 | boxpiecesB->setGeometry(40,95,195,20); | ||
35 | fillBox("pieces",boxpiecesB); | ||
36 | |||
37 | QLabel* labeldiceA=new QLabel("dice1",this); | ||
38 | labeldiceA->setGeometry(0,135,40,20); | ||
39 | boxdiceA=new QComboBox(this); | ||
40 | boxdiceA->setGeometry(40,135,195,20); | ||
41 | fillBox("dice",boxdiceA); | ||
42 | |||
43 | QLabel* labeldiceB=new QLabel("dice2",this); | ||
44 | labeldiceB->setGeometry(0,160,40,20); | ||
45 | boxdiceB=new QComboBox(this); | ||
46 | boxdiceB->setGeometry(40,160,195,20); | ||
47 | fillBox("dice",boxdiceB); | ||
48 | |||
49 | QLabel* labelodds=new QLabel("odds",this); | ||
50 | labelodds->setGeometry(0,200,40,20); | ||
51 | boxodds=new QComboBox(this); | ||
52 | boxodds->setGeometry(40,200,195,20); | ||
53 | fillBox("odds",boxodds); | ||
54 | boxodds->setEnabled(false); | ||
55 | |||
56 | QLabel* labeltable=new QLabel("table",this); | ||
57 | labeltable->setGeometry(0,225,40,20); | ||
58 | boxtable=new QComboBox(this); | ||
59 | boxtable->setGeometry(40,225,195,20); | ||
60 | fillBox("table",boxtable); | ||
61 | |||
62 | showMaximized(); | ||
63 | } | ||
64 | |||
65 | ThemeDialog::~ThemeDialog() | ||
66 | {} | ||
67 | |||
68 | |||
69 | ImageNames ThemeDialog::getNames() | ||
70 | { | ||
71 | ImageNames names; | ||
72 | names.theme=lineName->text(); | ||
73 | names.board=boxboard->currentText(); | ||
74 | names.pieces1=boxpiecesA->currentText(); | ||
75 | names.pieces2=boxpiecesB->currentText(); | ||
76 | names.dice1=boxdiceA->currentText(); | ||
77 | names.dice2=boxdiceB->currentText(); | ||
78 | names.odds=boxodds->currentText(); | ||
79 | names.table=boxtable->currentText(); | ||
80 | return names; | ||
81 | } | ||
82 | |||
83 | void ThemeDialog::setCurrent(const ImageNames& current) | ||
84 | { | ||
85 | int a=0; | ||
86 | lineName->setText(current.theme); | ||
87 | for(a=0;a<boxboard->count();a++) | ||
88 | { | ||
89 | if(boxboard->text(a)==current.board) | ||
90 | { | ||
91 | boxboard->setCurrentItem(a); | ||
92 | break; | ||
93 | } | ||
94 | } | ||
95 | for(a=0;a<boxpiecesA->count();a++) | ||
96 | { | ||
97 | if(boxpiecesA->text(a)==current.pieces1) | ||
98 | { | ||
99 | boxpiecesA->setCurrentItem(a); | ||
100 | break; | ||
101 | } | ||
102 | } | ||
103 | for(a=0;a<boxpiecesB->count();a++) | ||
104 | { | ||
105 | if(boxpiecesB->text(a)==current.pieces2) | ||
106 | { | ||
107 | boxpiecesB->setCurrentItem(a); | ||
108 | break; | ||
109 | } | ||
110 | } | ||
111 | for(a=0;a<boxdiceA->count();a++) | ||
112 | { | ||
113 | if(boxdiceA->text(a)==current.dice1) | ||
114 | { | ||
115 | boxdiceA->setCurrentItem(a); | ||
116 | break; | ||
117 | } | ||
118 | } | ||
119 | for(a=0;a<boxdiceB->count();a++) | ||
120 | { | ||
121 | if(boxdiceB->text(a)==current.dice2) | ||
122 | { | ||
123 | boxdiceB->setCurrentItem(a); | ||
124 | break; | ||
125 | } | ||
126 | } | ||
127 | for(a=0;a<boxodds->count();a++) | ||
128 | { | ||
129 | if(boxodds->text(a)==current.odds) | ||
130 | { | ||
131 | boxodds->setCurrentItem(a); | ||
132 | break; | ||
133 | } | ||
134 | } | ||
135 | for(a=0;a<boxtable->count();a++) | ||
136 | { | ||
137 | if(boxtable->text(a)==current.table) | ||
138 | { | ||
139 | boxtable->setCurrentItem(a); | ||
140 | break; | ||
141 | } | ||
142 | } | ||
143 | } | ||
144 | |||
145 | void ThemeDialog::fillBox(QString dirname,QComboBox* thebox) | ||
146 | { | ||
147 | thebox->clear(); | ||
148 | QDir dir(QPEApplication::qpeDir()+"/pics/backgammon/"+dirname); | ||
149 | dir.setFilter(QDir::Dirs | QDir::Files); | ||
150 | QFileInfoListIterator it(*(dir.entryInfoList())); | ||
151 | QFileInfo* fi; | ||
152 | |||
153 | while((fi=it.current())) // go through all file and subdirs | ||
154 | { | ||
155 | QString file=fi->fileName(); | ||
156 | if(file.right(4)==".png") | ||
157 | { | ||
158 | thebox->insertItem(file.left(file.find(".png"))); | ||
159 | } | ||
160 | ++it; | ||
161 | } | ||
162 | delete fi; | ||
163 | } | ||