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) { |
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); |