Skip to content

Commit 40c6c0a

Browse files
author
Gin
committed
fixing UI layout
1 parent 559c349 commit 40c6c0a

File tree

6 files changed

+35
-12
lines changed

6 files changed

+35
-12
lines changed

Common/Qt/Options/ConfigWidget.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@
1212
namespace PokemonAutomation{
1313

1414

15+
// Base class for all config widgets that control a program option.
16+
//
17+
// It is intuitive to let ConfigWidget inherit QWidget, base class of Qt UI element,
18+
// But some derived classes of ConfigWidget, e.g. StringCellWidget, needs to inherit
19+
// QWidget's derived classes, e.g. QLineEdit. To avoid nasty diamond inheritance,
20+
// ConfigWidget does not inherit QWidget. User has to call ConfigWidget::widget()
21+
// to get the actual QWidget.
22+
//
23+
// ConfigWidget's derived classes need to inherit a QWidget or its derived class
24+
// and pass *this as the widget in ConfigWidget(m_valuie, widget) so a ConfigWidget
25+
// pointer can get the actual QWidget.
1526
class ConfigWidget : protected ConfigOption::Listener{
1627
public:
1728
virtual ~ConfigWidget();

SerialPrograms/Source/CommonTools/Options/StringSelectOption.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ class StringSelectDatabase{
6565
};
6666

6767

68-
68+
// Config option that creates a cell where users can select a string from
69+
// its dropdown menu. It is best to put this cell in a table widget.
6970
class StringSelectCell : public ConfigOption{
7071
public:
7172
~StringSelectCell();
@@ -117,7 +118,10 @@ class StringSelectCell : public ConfigOption{
117118
};
118119

119120

120-
121+
// Config option that creates a dropdown menu for users to select
122+
// a sring. Different from StringSelectCell which is typically used
123+
// in a table, StringSelectOption is considered a standalone option
124+
// that comes with its own label.
121125
class StringSelectOption : public StringSelectCell{
122126
public:
123127
StringSelectOption(

SerialPrograms/Source/ML/Programs/ML_LabelImages.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,7 @@ LabelImages_Widget::LabelImages_Widget(
492492

493493
m_embedding_info_label = new QLabel(this);
494494

495+
// Main layout
495496
QVBoxLayout* layout = new QVBoxLayout(this);
496497
layout->setContentsMargins(0, 0, 0, 0);
497498
layout->addWidget(make_header(*this));
@@ -513,6 +514,8 @@ LabelImages_Widget::LabelImages_Widget(
513514
embedding_info_row->addWidget(new QLabel("<b>Image Embedding File:</b> ", this));
514515
embedding_info_row->addWidget(m_embedding_info_label);
515516

517+
// add a row for buttons
518+
516519
QHBoxLayout* button_row = new QHBoxLayout();
517520
scroll_layout->addLayout(button_row);
518521

@@ -525,10 +528,15 @@ LabelImages_Widget::LabelImages_Widget(
525528
QPushButton* next_anno_button = new QPushButton("Next Annotation", scroll_inner);
526529
button_row->addWidget(next_anno_button, 1);
527530

531+
// add a row for user annotation
532+
QHBoxLayout* annotation_row = new QHBoxLayout();
533+
scroll_layout->addLayout(annotation_row);
534+
annotation_row->addWidget(new QLabel("<b>Select Label:</b>", scroll_inner), 0);
535+
536+
ConfigWidget* option_widget = program.FORM_LABEL.make_QtWidget(*scroll_inner);
537+
annotation_row->addWidget(&option_widget->widget(), 5);
528538

529-
// Add all option UI elements defined by LabelImage program.
530-
m_option_widget = program.m_options.make_QtWidget(*scroll_inner);
531-
scroll_layout->addWidget(&m_option_widget->widget());
539+
// add compute embedding button
532540

533541
QPushButton* compute_embedding_button = new QPushButton("Compute Image Embeddings (SLOW!)", scroll_inner);
534542
scroll_layout->addWidget(compute_embedding_button);

SerialPrograms/Source/ML/Programs/ML_LabelImages.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,9 @@ class LabelImages_Widget : public PanelWidget,
191191
// show the info about the loaded image embedding data corresponding to the currently
192192
// displayed image
193193
QLabel* m_embedding_info_label = nullptr;
194-
// a UI widget that holds all the editable UI elements defined in LabelImage program.
195-
ConfigWidget* m_option_widget;
194+
195+
// TODO: see if we can use
196+
// Common/Cpp/Options/BoxFloatOption.h and Common/Qt/Options/BoxFloatWidget.h as UI options
196197

197198
std::optional<std::pair<double, double>> m_mouse_start;
198199
std::optional<std::pair<double, double>> m_mouse_end;

SerialPrograms/Source/ML/UI/ML_ImageAnnotationDisplayWidget.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ ImageAnnotationDisplayWidget::ImageAnnotationDisplayWidget(
4646
, m_session(session)
4747
, m_command_receiver(command_receiver)
4848
{
49-
5049
QVBoxLayout* layout = new QVBoxLayout(this);
5150
layout->setContentsMargins(0, 0, 0, 0);
5251
layout->setAlignment(Qt::AlignTop);

SerialPrograms/Source/ML/UI/ML_ImageAnnotationSourceSelectorWidget.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ ImageAnnotationSourceSelectorWidget::ImageAnnotationSourceSelectorWidget(ImageAn
3939
QVBoxLayout* layout = new QVBoxLayout(this);
4040
layout->setContentsMargins(0, 0, 0, 0);
4141

42-
QHBoxLayout* image_path_row = new QHBoxLayout(this);
42+
QHBoxLayout* image_path_row = new QHBoxLayout();
4343
layout->addLayout(image_path_row);
4444

4545
image_path_row->setContentsMargins(0, 0, 0, 0);
@@ -60,12 +60,12 @@ ImageAnnotationSourceSelectorWidget::ImageAnnotationSourceSelectorWidget(ImageAn
6060
QPushButton* reload_image_button = new QPushButton("Reload Image", this);
6161
image_path_row->addWidget(reload_image_button, 0);
6262

63-
QHBoxLayout* folder_info_row = new QHBoxLayout(this);
63+
// add folder info row to show the index of the current image in the folder and buttons to move between images in this folder
64+
QHBoxLayout* folder_info_row = new QHBoxLayout();
6465
layout->addLayout(folder_info_row);
6566

6667
m_folder_info_label = new QLabel(this);
67-
folder_info_row->addWidget(m_folder_info_label, 3);
68-
folder_info_row->addSpacing(3);
68+
folder_info_row->addWidget(m_folder_info_label, 1);
6969

7070
QPushButton* prev_image_button = new QPushButton("Prev Image in Folder", this);
7171
QPushButton* next_image_button = new QPushButton("Next Image in Folder", this);

0 commit comments

Comments
 (0)