16
16
#include < QDebug>
17
17
18
18
#include < vector>
19
+ #include < iostream>
20
+ using namespace std ;
21
+
22
+ #include < QAbstractItemView>
23
+ #include < QFontMetrics>
24
+ #include < QVBoxLayout>
25
+ #include < QWidget>
26
+
27
+ class ElidedComboBox : public QComboBox {
28
+ public:
29
+ using QComboBox::QComboBox;
30
+
31
+ protected:
32
+ void paintEvent (QPaintEvent *event) override {
33
+ QStyleOptionComboBox opt;
34
+ initStyleOption (&opt);
35
+ QPainter painter (this );
36
+
37
+ // Draw the combo box background and frame
38
+ style ()->drawComplexControl (QStyle::CC_ComboBox, &opt, &painter, this );
39
+
40
+ // Get the selected text and elide if necessary
41
+ QString text = currentText ();
42
+ QFontMetrics fm (font ());
43
+ opt.currentText = fm.elidedText (text, Qt::ElideRight, width () - 20 ); // Leave space for arrow
44
+
45
+ // Draw the elided text inside the box
46
+ style ()->drawControl (QStyle::CE_ComboBoxLabel, &opt, &painter, this );
47
+ }
48
+
49
+ void showPopup () override {
50
+ view ()->setMinimumWidth (view ()->sizeHintForColumn (0 ) + 20 ); // Ensure full text is visible
51
+ QComboBox::showPopup ();
52
+ }
53
+ };
54
+
19
55
20
56
DomePanel::DomePanel (QWidget *parent): QFrame(parent) {
21
57
22
58
// setContentsMargins(10, 10, 10, 10);
23
59
QHBoxLayout *content = new QHBoxLayout (this );
24
60
// content->setHorizontalSpacing(20);
25
61
62
+ {
63
+ sphere_frame = new QFrame;
64
+ sphere_frame->setFrameShape (QFrame::Panel);
65
+ sphere_frame->setAutoFillBackground (true );
66
+
67
+ QHBoxLayout *sphere_layout = new QHBoxLayout (sphere_frame);
68
+ {
69
+ sphere_button = new QPushButton (QIcon::fromTheme (" highlight" ), " Use reflective spheres" );
70
+ sphere_button->setProperty (" class" , " large" );
71
+ sphere_button->setMinimumWidth (200 );
72
+ sphere_button->setMaximumWidth (300 );
73
+ connect (sphere_button, SIGNAL (clicked ()), this , SLOT (setSpheres ()));
74
+
75
+ sphere_layout->addWidget (sphere_button);
76
+ }
77
+ content->addWidget (sphere_frame, 0 , Qt::AlignTop);
78
+ }
79
+
80
+ {
81
+ dome_frame = new QFrame;
82
+ dome_frame->setFrameShape (QFrame::Panel);
83
+ dome_frame->setAutoFillBackground (true );
84
+
85
+ QHBoxLayout *dome_layout = new QHBoxLayout (dome_frame);
86
+ {
87
+ QPushButton *load = new QPushButton (QIcon::fromTheme (" folder" ), " Load dome file..." );
88
+ load->setProperty (" class" , " large" );
89
+ load->setMinimumWidth (200 );
90
+ load->setMaximumWidth (300 );
91
+ connect (load, SIGNAL (clicked ()), this , SLOT (loadDomeFile ()));
92
+
93
+ dome_layout->addWidget (load);
94
+
95
+ dome_list = new ElidedComboBox;
96
+ dome_list->setMinimumWidth (200 );
97
+ dome_list->setMaximumWidth (300 );
98
+ dome_list->setProperty (" class" , " large" );
99
+ connect (dome_list, SIGNAL (currentIndexChanged (int )), this , SLOT (setDome (int )));
100
+
101
+ dome_layout->addWidget (dome_list);
102
+ }
103
+ content->addWidget (dome_frame, 0 , Qt::AlignTop);
104
+ }
105
+
106
+
26
107
27
108
QPushButton *save = new QPushButton (QIcon::fromTheme (" save" ), " Export dome..." );
28
109
save->setProperty (" class" , " large" );
@@ -31,27 +112,28 @@ DomePanel::DomePanel(QWidget *parent): QFrame(parent) {
31
112
connect (save, SIGNAL (clicked ()), this , SLOT (exportDome ()));
32
113
content->addWidget (save, 0 , Qt::AlignTop);
33
114
34
- QPushButton *load = new QPushButton (QIcon::fromTheme (" folder" ), " Load dome file..." );
35
- load->setProperty (" class" , " large" );
36
- load->setMinimumWidth (200 );
37
- load->setMaximumWidth (300 );
38
- connect (load, SIGNAL (clicked ()), this , SLOT (loadDomeFile ()));
39
- content->addWidget (load, 0 , Qt::AlignTop);
40
-
41
115
42
- dome_list = new QComboBox;
43
- dome_list->setProperty (" class" , " large" );
44
- content->addWidget (dome_list, 1 , Qt::AlignTop);
45
- connect (dome_list, SIGNAL (currentIndexChanged (int )), this , SLOT (setDome (int )));
46
116
init ();
47
117
}
48
118
119
+ void DomePanel::setSphereSelected () {
120
+ bool use_sphere = qRelightApp->project ().dome .label .isEmpty ();
121
+ QPalette pal = palette ();
122
+ QColor highlightColor = pal.color (QPalette::Highlight); // Theme-defined highlight color
123
+ QColor normalColor = pal.color (QPalette::Window);
124
+ sphere_frame->setPalette (QPalette (use_sphere? highlightColor : normalColor));
125
+ dome_frame->setPalette (QPalette (use_sphere? normalColor : highlightColor));
126
+ }
127
+
49
128
void DomePanel::init () {
50
129
dome = qRelightApp->project ().dome ;
130
+ // TODO something more explicit than the dome label would be better.
131
+ setSphereSelected ();
51
132
updateDomeList ();
52
133
}
53
134
54
- void DomePanel::updateDomeList () {
135
+ void DomePanel::updateDomeList (QString path) {
136
+ // if path is present and not current
55
137
// dome_labels.clear();
56
138
dome_paths.clear ();
57
139
dome_list->clear ();
@@ -75,12 +157,41 @@ void DomePanel::updateDomeList() {
75
157
dome_paths.append (path);
76
158
dome_list->addItem (dome.label );
77
159
}
160
+ if (!path.isNull ()) {
161
+ int index = dome_paths.indexOf (path);
162
+ assert (index != -1 );
163
+
164
+ if (dome_list->currentIndex () != index +1 ) {
165
+ dome_list->blockSignals (true );
166
+ dome_list->setCurrentIndex (index +1 );
167
+ dome_list->blockSignals (false );
168
+ }
169
+ }
170
+ }
171
+
172
+ void DomePanel::setSpheres () {
173
+ dome_list->blockSignals (true );
174
+ dome_list->setCurrentIndex (0 );
175
+ dome_list->blockSignals (false );
176
+
177
+ emit useSpheres ();
178
+ setSphereSelected ();
78
179
}
79
180
80
181
void DomePanel::setDome (int index) {
81
182
if (index <= 0 )
82
183
return ;
83
- loadDomeFile (dome_paths[index -1 ]); // First index is "Seelect a recent dome..."
184
+ try {
185
+ loadDomeFile (dome_paths[index -1 ]); // First index is "Seelect a recent dome..."
186
+ } catch (QString error) {
187
+ QMessageBox::critical (this , " Could not load this dome:" , error);
188
+ Dome &dome = qRelightApp->project ().dome ;
189
+ int index = dome_paths.indexOf (dome.label ) +1 ; // if not found returns -1 and goes to 0. Lucky!
190
+ dome_list->blockSignals (true );
191
+ dome_list->setCurrentIndex (index );
192
+ dome_list->blockSignals (false );
193
+ }
194
+ setSphereSelected ();
84
195
}
85
196
void DomePanel::loadDomeFile () {
86
197
QString path = QFileDialog::getOpenFileName (this , " Load a .lp or .dome file" , QDir::currentPath (), " Light directions and domes (*.lp *.dome )" );
@@ -132,37 +243,26 @@ void DomePanel::loadLP(QString path) {
132
243
std::vector<QString> filenames;
133
244
std::vector<Eigen::Vector3f> directions;
134
245
135
- try {
136
- parseLP (path, directions, filenames);
137
- qRelightApp->project ().validateDome (directions.size ());
246
+ parseLP (path, directions, filenames);
247
+ qRelightApp->project ().validateDome (directions.size ());
138
248
139
- } catch (QString error) {
140
- QMessageBox::critical (this , " Loading .lp file failed" , error);
141
- return ;
142
- }
143
249
Dome &dome = qRelightApp->project ().dome ;
144
250
dome.lightConfiguration = Dome::DIRECTIONAL;
145
251
dome.directions = directions;
146
252
QFileInfo info (path);
147
253
dome.label = info.filePath ();
148
254
qRelightApp->addDome (path);
149
255
150
- updateDomeList ();
151
-
256
+ updateDomeList (path);
152
257
emit updated ();
153
258
}
154
259
155
260
void DomePanel::loadDome (QString path) {
156
261
float imageWidth = dome.imageWidth ;
157
262
Dome new_dome;
158
- try {
159
- new_dome.load (path);
160
- qRelightApp->project ().validateDome (new_dome.directions .size ());
263
+ new_dome.load (path);
264
+ qRelightApp->project ().validateDome (new_dome.directions .size ());
161
265
162
- } catch (QString error) {
163
- QMessageBox::critical (this , " Loading .dome file failed" , error);
164
- return ;
165
- }
166
266
Dome &dome = qRelightApp->project ().dome ;
167
267
dome = new_dome;
168
268
@@ -172,16 +272,6 @@ void DomePanel::loadDome(QString path) {
172
272
// preserve image width if we actually have a measurement.
173
273
if (imageWidth != 0 && qRelightApp->project ().measures .size () != 0 )
174
274
dome.imageWidth = imageWidth;
175
- updateDomeList ();
275
+ updateDomeList (path );
176
276
emit updated ();
177
277
}
178
-
179
-
180
-
181
- /* void DomePanel::setSelectedDome() {
182
- auto list = dome_list->selectedItems();
183
- if(!list.size())
184
- return;
185
- int pos = dome_list->row(list[0]);
186
- loadDomeFile(dome_paths[pos]);
187
- }*/
0 commit comments