Skip to content

Commit a63ae8c

Browse files
committed
highlight current status of light directions (spheres vs dome).
Needs testing.
1 parent f6e46ec commit a63ae8c

8 files changed

+149
-58
lines changed

relightlab/domepanel.cpp

+130-40
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,94 @@
1616
#include <QDebug>
1717

1818
#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+
1955

2056
DomePanel::DomePanel(QWidget *parent): QFrame(parent) {
2157

2258
// setContentsMargins(10, 10, 10, 10);
2359
QHBoxLayout *content = new QHBoxLayout(this);
2460
//content->setHorizontalSpacing(20);
2561

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+
26107

27108
QPushButton *save = new QPushButton(QIcon::fromTheme("save"), "Export dome...");
28109
save->setProperty("class", "large");
@@ -31,27 +112,28 @@ DomePanel::DomePanel(QWidget *parent): QFrame(parent) {
31112
connect(save, SIGNAL(clicked()), this, SLOT(exportDome()));
32113
content->addWidget(save, 0, Qt::AlignTop);
33114

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-
41115

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)));
46116
init();
47117
}
48118

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+
49128
void DomePanel::init() {
50129
dome = qRelightApp->project().dome;
130+
//TODO something more explicit than the dome label would be better.
131+
setSphereSelected();
51132
updateDomeList();
52133
}
53134

54-
void DomePanel::updateDomeList() {
135+
void DomePanel::updateDomeList(QString path) {
136+
//if path is present and not current
55137
//dome_labels.clear();
56138
dome_paths.clear();
57139
dome_list->clear();
@@ -75,12 +157,41 @@ void DomePanel::updateDomeList() {
75157
dome_paths.append(path);
76158
dome_list->addItem(dome.label);
77159
}
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();
78179
}
79180

80181
void DomePanel::setDome(int index) {
81182
if(index <= 0)
82183
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();
84195
}
85196
void DomePanel::loadDomeFile() {
86197
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) {
132243
std::vector<QString> filenames;
133244
std::vector<Eigen::Vector3f> directions;
134245

135-
try {
136-
parseLP(path, directions, filenames);
137-
qRelightApp->project().validateDome(directions.size());
246+
parseLP(path, directions, filenames);
247+
qRelightApp->project().validateDome(directions.size());
138248

139-
} catch(QString error) {
140-
QMessageBox::critical(this, "Loading .lp file failed", error);
141-
return;
142-
}
143249
Dome &dome = qRelightApp->project().dome;
144250
dome.lightConfiguration = Dome::DIRECTIONAL;
145251
dome.directions = directions;
146252
QFileInfo info(path);
147253
dome.label = info.filePath();
148254
qRelightApp->addDome(path);
149255

150-
updateDomeList();
151-
256+
updateDomeList(path);
152257
emit updated();
153258
}
154259

155260
void DomePanel::loadDome(QString path) {
156261
float imageWidth = dome.imageWidth;
157262
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());
161265

162-
} catch (QString error) {
163-
QMessageBox::critical(this, "Loading .dome file failed", error);
164-
return;
165-
}
166266
Dome &dome = qRelightApp->project().dome;
167267
dome = new_dome;
168268

@@ -172,16 +272,6 @@ void DomePanel::loadDome(QString path) {
172272
//preserve image width if we actually have a measurement.
173273
if(imageWidth != 0 && qRelightApp->project().measures.size() != 0)
174274
dome.imageWidth = imageWidth;
175-
updateDomeList();
275+
updateDomeList(path);
176276
emit updated();
177277
}
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-
}*/

relightlab/domepanel.h

+10-3
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,38 @@
88

99
class QLabel;
1010
class QComboBox;
11+
class QPushButton;
1112

1213
class DomePanel: public QFrame {
1314
Q_OBJECT
1415
public:
1516
DomePanel(QWidget *parent = nullptr);
1617
void init();
1718
void loadDomeFile(QString path);
19+
void setSphereSelected();
1820

1921
public slots:
2022
void loadDomeFile();
2123
void exportDome();
2224
void setDome(int);
23-
void updateDomeList();
25+
void setSpheres();
26+
void updateDomeList(QString path = QString());
2427

2528
signals:
2629
void updated();
30+
void useSpheres();
2731

2832
private:
2933
Dome dome;
3034
QStringList dome_labels;
3135
QStringList dome_paths;
32-
QComboBox *dome_list;
3336

37+
QPushButton *sphere_button = nullptr;
38+
QComboBox *dome_list = nullptr;
39+
40+
QFrame *sphere_frame = nullptr;
41+
QFrame *dome_frame = nullptr;
3442

35-
//QListWidget *dome_list;
3643

3744
void loadLP(QString filename);
3845
void loadDome(QString filename);

relightlab/lightgeometry.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ LightsGeometry::LightsGeometry(QWidget *parent): QFrame(parent) {
2626

2727
QVBoxLayout *page = new QVBoxLayout(this);
2828

29-
page->addWidget(new QLabel("<h3>Current dome configuration<h3>"));
29+
page->addWidget(new QLabel("<h3>Current lights configuration<h3>"));
3030
//page->addSpacing(10);
3131

3232
QGridLayout * content = new QGridLayout();

relightlab/lightsframe.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,16 @@ LightsFrame::LightsFrame() {
3737

3838
// connect(sphere_panel, SIGNAL(updated()), geometry, SLOT(setFromSpheres()));
3939
connect(dome_panel, SIGNAL(updated()), geometry, SLOT(init()));
40+
connect(dome_panel, SIGNAL(useSpheres()), this, SLOT(updateSphere()));
4041
}
4142

4243
void LightsFrame::clear() {
4344
// sphere_panel->clear();
4445
}
4546

47+
void LightsFrame::updateSphere() {
48+
geometry->setFromSpheres();
49+
}
4650

4751
void LightsFrame::init() {
4852
// bool useSphere = qRelightApp->project().spheres.size();

relightlab/lightsframe.h

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public slots:
2424
void clear();
2525
void init();
2626
void setPixelSize();
27+
void updateSphere();
2728

2829
private:
2930
QTabWidget *choice = nullptr;

relightlab/mainwindow.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ MainWindow::MainWindow() {
4444
tabs->addTab(normals_frame = new NormalsFrame, "Normals");
4545
tabs->addTab(queue_frame = new QueueFrame, "Queue");
4646

47+
4748
connect(scale_frame, SIGNAL(pixelSizeChanged()), lights_frame, SLOT(setPixelSize()));
49+
connect(sphere_frame, SIGNAL(updated()), lights_frame, SLOT(updateSphere()));
4850
connect(rti_frame, SIGNAL(processStarted()), this, SLOT(showQueue()));
4951
connect(normals_frame, SIGNAL(processStarted()), this, SLOT(showQueue()));
5052

relightlab/sphereframe.cpp

-14
Original file line numberDiff line numberDiff line change
@@ -102,20 +102,6 @@ void SphereFrame::newSphere() {
102102
stack->setCurrentIndex(1);
103103
provisional_sphere = new Sphere(qRelightApp->project().images.size());
104104
marker_dialog->setSphere(provisional_sphere);
105-
106-
/*if(!sphere_dialog)
107-
sphere_dialog = new SphereDialog(this);
108-
109-
Sphere *sphere = new Sphere(qRelightApp->project().images.size());
110-
sphere_dialog->setSphere(sphere);
111-
int answer = sphere_dialog->exec();
112-
if(answer == QDialog::Rejected) {
113-
delete sphere;
114-
return;
115-
}
116-
qRelightApp->project().spheres.push_back(sphere);
117-
SphereRow *row = addSphere(sphere);
118-
row->detectHighlights(); */
119105
}
120106

121107

relightlab/sphererow.h

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class SphereRow: public QWidget {
4242
void stopDetecting();
4343

4444
signals:
45+
void edit(SphereRow *row);
4546
void removeme(SphereRow *row);
4647
void updated(); //emit when status changes
4748

0 commit comments

Comments
 (0)