zz_addObjectDialog.cpp

changeset 51
94c434a56961
parent 42
499c25af0303
child 68
c637b172d565
equal deleted inserted replaced
50:7fd213c6b844 51:94c434a56961
18 18
19 #include <qgridlayout.h> 19 #include <qgridlayout.h>
20 #include "gui.h" 20 #include "gui.h"
21 #include "zz_addObjectDialog.h" 21 #include "zz_addObjectDialog.h"
22 #include "file.h" 22 #include "file.h"
23 #include "colors.h"
24 #include "zz_colorSelectDialog.h"
23 25
24 #define APPLY_COORDS(OBJ, N) \ 26 #define APPLY_COORDS(OBJ, N) \
25 for (short i = 0; i < N; ++i) { \ 27 for (short i = 0; i < N; ++i) { \
26 OBJ->vaCoords[i].x = dlg.qaCoordinates[(i * 3) + 0]->value (); \ 28 OBJ->vaCoords[i].x = dlg.qaCoordinates[(i * 3) + 0]->value (); \
27 OBJ->vaCoords[i].y = dlg.qaCoordinates[(i * 3) + 1]->value (); \ 29 OBJ->vaCoords[i].y = dlg.qaCoordinates[(i * 3) + 1]->value (); \
58 dCoordCount = 3; 60 dCoordCount = 3;
59 default: 61 default:
60 break; 62 break;
61 } 63 }
62 64
65 // Show a color edit dialog for the types that actually use the color
66 bool bUsesColor = false;
67 switch (type) {
68 case OBJ_CondLine:
69 case OBJ_Line:
70 case OBJ_Quad:
71 case OBJ_Triangle:
72 case OBJ_Vertex:
73 case OBJ_Subfile:
74 bUsesColor = true;
75 break;
76 default:
77 break;
78 }
79
80 if (bUsesColor) {
81 dColor = (type == OBJ_CondLine || type == OBJ_Line) ? dEdgeColor : dMainColor;
82
83 qColorButton = new QPushButton;
84 setButtonBackground (qColorButton, g_LDColors[dColor]->zColor);
85 connect (qColorButton, SIGNAL (clicked ()), this, SLOT (slot_colorButtonClicked ()));
86 }
87
63 for (short i = 0; i < dCoordCount; ++i) { 88 for (short i = 0; i < dCoordCount; ++i) {
64 qaCoordinates[i] = new QDoubleSpinBox; 89 qaCoordinates[i] = new QDoubleSpinBox;
65 qaCoordinates[i]->setMaximumWidth (96); 90 qaCoordinates[i]->setMaximumWidth (96);
66 qaCoordinates[i]->setMinimum (-fMaxCoord); 91 qaCoordinates[i]->setMinimum (-fMaxCoord);
67 qaCoordinates[i]->setMaximum (fMaxCoord); 92 qaCoordinates[i]->setMaximum (fMaxCoord);
78 break; 103 break;
79 default: 104 default:
80 break; 105 break;
81 } 106 }
82 107
108 if (bUsesColor)
109 qLayout->addWidget (qColorButton, 1, 0);
110
83 if (dCoordCount > 0) { 111 if (dCoordCount > 0) {
84 QGridLayout* const qCoordLayout = new QGridLayout; 112 QGridLayout* const qCoordLayout = new QGridLayout;
85 113
86 for (short i = 0; i < dCoordCount; ++i) 114 for (short i = 0; i < dCoordCount; ++i)
87 qCoordLayout->addWidget (qaCoordinates[i], (i / 3), (i % 3)); 115 qCoordLayout->addWidget (qaCoordinates[i], (i / 3), (i % 3));
88 116
89 qLayout->addLayout (qCoordLayout, 0, 1); 117 qLayout->addLayout (qCoordLayout, 0, 1, 2, 1);
90 } 118 }
91 119
92 qLayout->addWidget (qButtons, 1, 1); 120 qLayout->addWidget (qButtons, 2, 1);
93 setLayout (qLayout); 121 setLayout (qLayout);
94 setWindowTitle (str::mkfmt (APPNAME_DISPLAY " - new %s", 122 setWindowTitle (str::mkfmt (APPNAME_DISPLAY " - new %s",
95 g_saObjTypeNames[type]).chars()); 123 g_saObjTypeNames[type]).chars());
96 124
97 setWindowIcon (QIcon (zIconName.chars ())); 125 setWindowIcon (QIcon (zIconName.chars ()));
98 } 126 }
99 127
100 // ============================================================================= 128 // =============================================================================
101 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 129 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
102 // ============================================================================= 130 // =============================================================================
131 void AddObjectDialog::setButtonBackground (QPushButton* qButton, str zValue) {
132 qButton->setIcon (QIcon ("icons/palette.png"));
133 qButton->setAutoFillBackground (true);
134 qButton->setStyleSheet (
135 str::mkfmt ("background-color: %s", zValue.chars()).chars()
136 );
137 }
138
139 // =============================================================================
140 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
141 // =============================================================================
142 void AddObjectDialog::slot_colorButtonClicked () {
143 ColorSelectDialog::staticDialog (dColor, dColor, this);
144 setButtonBackground (qColorButton, g_LDColors[dColor]->zColor);
145 }
146
147 // =============================================================================
148 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
149 // =============================================================================
103 void AddObjectDialog::staticDialog (const LDObjectType_e type, ForgeWindow* window) { 150 void AddObjectDialog::staticDialog (const LDObjectType_e type, ForgeWindow* window) {
104 AddObjectDialog dlg (type, window); 151 AddObjectDialog dlg (type, window);
105 152
106 if (dlg.exec ()) { 153 if (dlg.exec ()) {
107 switch (type) { 154 switch (type) {
115 break; 162 break;
116 163
117 case OBJ_Line: 164 case OBJ_Line:
118 { 165 {
119 LDLine* line = new LDLine; 166 LDLine* line = new LDLine;
120 line->dColor = dEdgeColor; 167 line->dColor = dlg.dColor;
121 168
122 APPLY_COORDS (line, 2) 169 APPLY_COORDS (line, 2)
123 170
124 g_CurrentFile->addObject (line); 171 g_CurrentFile->addObject (line);
125 window->refresh (); 172 window->refresh ();
127 break; 174 break;
128 175
129 case OBJ_Triangle: 176 case OBJ_Triangle:
130 { 177 {
131 LDTriangle* tri = new LDTriangle; 178 LDTriangle* tri = new LDTriangle;
132 tri->dColor = dMainColor; 179 tri->dColor = dlg.dColor;
133 180
134 APPLY_COORDS (tri, 3) 181 APPLY_COORDS (tri, 3)
135 182
136 g_CurrentFile->addObject (tri); 183 g_CurrentFile->addObject (tri);
137 window->refresh (); 184 window->refresh ();
139 break; 186 break;
140 187
141 case OBJ_Quad: 188 case OBJ_Quad:
142 { 189 {
143 LDQuad* quad = new LDQuad; 190 LDQuad* quad = new LDQuad;
144 quad->dColor = dMainColor; 191 quad->dColor = dlg.dColor;
145 192
146 APPLY_COORDS (quad, 4) 193 APPLY_COORDS (quad, 4)
147 194
148 g_CurrentFile->addObject (quad); 195 g_CurrentFile->addObject (quad);
149 window->refresh (); 196 window->refresh ();
151 break; 198 break;
152 199
153 case OBJ_CondLine: 200 case OBJ_CondLine:
154 { 201 {
155 LDCondLine* line = new LDCondLine; 202 LDCondLine* line = new LDCondLine;
156 line->dColor = dEdgeColor; 203 line->dColor = dlg.dColor;
157 204
158 APPLY_COORDS (line, 4) 205 APPLY_COORDS (line, 4)
159 206
160 g_CurrentFile->addObject (line); 207 g_CurrentFile->addObject (line);
161 window->refresh (); 208 window->refresh ();
163 break; 210 break;
164 211
165 case OBJ_Vertex: 212 case OBJ_Vertex:
166 { 213 {
167 LDVertex* vert = new LDVertex; 214 LDVertex* vert = new LDVertex;
168 vert->dColor = dMainColor; 215 vert->dColor = dlg.dColor;
169 vert->vPosition.x = dlg.qaCoordinates[0]->value (); 216 vert->vPosition.x = dlg.qaCoordinates[0]->value ();
170 vert->vPosition.y = dlg.qaCoordinates[1]->value (); 217 vert->vPosition.y = dlg.qaCoordinates[1]->value ();
171 vert->vPosition.z = dlg.qaCoordinates[2]->value (); 218 vert->vPosition.z = dlg.qaCoordinates[2]->value ();
172 219
173 g_CurrentFile->addObject (vert); 220 g_CurrentFile->addObject (vert);

mercurial