Skip to content

Commit 072aa5f

Browse files
committed
Fix optimize panel layout for long domain names and narrow textboxes
- Add ElidedLabel class that truncates long domain names with "..." when column space is tight, while reporting full-text sizeHint so the layout allocates natural width when available. Full name shown as tooltip. - Cap optimize textboxes to 50-100px (min/max) so they don't expand and crowd out the label column; ensures values like "0.05" aren't truncated.
1 parent 940bb23 commit 072aa5f

2 files changed

Lines changed: 215 additions & 1 deletion

File tree

Studio/Optimize/OptimizeTool.cpp

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
// qt
44
#include <QFileDialog>
5+
#include <QFontMetrics>
56
#include <QIntValidator>
7+
#include <QLabel>
68
#include <QMessageBox>
9+
#include <QResizeEvent>
710
#include <QThread>
811
#include <QTimer>
912

@@ -22,6 +25,47 @@
2225

2326
using namespace shapeworks;
2427

28+
namespace {
29+
// QLabel that elides its text with "..." when it's narrower than the text.
30+
// The full text is kept as a tooltip so the user can see it on hover.
31+
// sizeHint() reports the full-text width so the layout gives the label its natural
32+
// space when available; elision only happens when the layout must shrink it.
33+
class ElidedLabel : public QLabel {
34+
public:
35+
explicit ElidedLabel(const QString& text, QWidget* parent = nullptr) : QLabel(parent), full_text_(text) {
36+
setToolTip(text);
37+
updateElidedText();
38+
}
39+
40+
QSize sizeHint() const override {
41+
QFontMetrics metrics(font());
42+
return QSize(metrics.horizontalAdvance(full_text_) + 4, QLabel::sizeHint().height());
43+
}
44+
45+
QSize minimumSizeHint() const override {
46+
// Minimum: enough for ellipsis plus a couple characters so the label can shrink
47+
// further if the panel is very narrow, but not to zero width.
48+
QFontMetrics metrics(font());
49+
return QSize(metrics.horizontalAdvance(QStringLiteral("X...")), QLabel::minimumSizeHint().height());
50+
}
51+
52+
protected:
53+
void resizeEvent(QResizeEvent* event) override {
54+
QLabel::resizeEvent(event);
55+
updateElidedText();
56+
}
57+
58+
private:
59+
void updateElidedText() {
60+
QFontMetrics metrics(font());
61+
QString elided = metrics.elidedText(full_text_, Qt::ElideRight, width());
62+
QLabel::setText(elided);
63+
}
64+
65+
QString full_text_;
66+
};
67+
} // namespace
68+
2569
//---------------------------------------------------------------------------
2670
OptimizeTool::OptimizeTool(Preferences& prefs, Telemetry& telemetry) : preferences_(prefs), telemetry_(telemetry) {
2771
ui_ = new Ui_OptimizeTool;
@@ -473,6 +517,8 @@ void OptimizeTool::setup_domain_boxes() {
473517
QLineEdit* box = new QLineEdit(this);
474518
last_box = box;
475519
box->setAlignment(Qt::AlignHCenter);
520+
box->setMinimumWidth(50);
521+
box->setMaximumWidth(100);
476522
box->setValidator(above_zero);
477523
box->setText(ui_->number_of_particles->text());
478524
connect(box, &QLineEdit::textChanged, this, &OptimizeTool::update_run_button);
@@ -482,7 +528,7 @@ void OptimizeTool::setup_domain_boxes() {
482528
} else {
483529
auto domain_names = session_->get_project()->get_domain_names();
484530
for (int i = 0; i < domain_names.size(); i++) {
485-
auto label = new QLabel(QString::fromStdString(domain_names[i]), this);
531+
auto label = new ElidedLabel(QString::fromStdString(domain_names[i]), this);
486532
label->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
487533
grid->addWidget(label, i, 1);
488534
domain_grid_widgets_.push_back(label);

Studio/Optimize/OptimizeTool.ui

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,18 @@ QWidget#optimize_panel {
320320
<property name="text">
321321
<string>0.05</string>
322322
</property>
323+
<property name="minimumSize">
324+
<size>
325+
<width>50</width>
326+
<height>0</height>
327+
</size>
328+
</property>
329+
<property name="maximumSize">
330+
<size>
331+
<width>100</width>
332+
<height>16777215</height>
333+
</size>
334+
</property>
323335
<property name="alignment">
324336
<set>Qt::AlignCenter</set>
325337
</property>
@@ -338,6 +350,18 @@ QWidget#optimize_panel {
338350
<property name="text">
339351
<string>1.0</string>
340352
</property>
353+
<property name="minimumSize">
354+
<size>
355+
<width>50</width>
356+
<height>0</height>
357+
</size>
358+
</property>
359+
<property name="maximumSize">
360+
<size>
361+
<width>100</width>
362+
<height>16777215</height>
363+
</size>
364+
</property>
341365
<property name="alignment">
342366
<set>Qt::AlignCenter</set>
343367
</property>
@@ -356,6 +380,18 @@ QWidget#optimize_panel {
356380
<property name="text">
357381
<string>10</string>
358382
</property>
383+
<property name="minimumSize">
384+
<size>
385+
<width>50</width>
386+
<height>0</height>
387+
</size>
388+
</property>
389+
<property name="maximumSize">
390+
<size>
391+
<width>100</width>
392+
<height>16777215</height>
393+
</size>
394+
</property>
359395
<property name="alignment">
360396
<set>Qt::AlignCenter</set>
361397
</property>
@@ -374,6 +410,18 @@ QWidget#optimize_panel {
374410
<property name="text">
375411
<string>1.0</string>
376412
</property>
413+
<property name="minimumSize">
414+
<size>
415+
<width>50</width>
416+
<height>0</height>
417+
</size>
418+
</property>
419+
<property name="maximumSize">
420+
<size>
421+
<width>100</width>
422+
<height>16777215</height>
423+
</size>
424+
</property>
377425
<property name="alignment">
378426
<set>Qt::AlignCenter</set>
379427
</property>
@@ -392,6 +440,18 @@ QWidget#optimize_panel {
392440
<property name="text">
393441
<string>1000</string>
394442
</property>
443+
<property name="minimumSize">
444+
<size>
445+
<width>50</width>
446+
<height>0</height>
447+
</size>
448+
</property>
449+
<property name="maximumSize">
450+
<size>
451+
<width>100</width>
452+
<height>16777215</height>
453+
</size>
454+
</property>
395455
<property name="alignment">
396456
<set>Qt::AlignCenter</set>
397457
</property>
@@ -410,6 +470,18 @@ QWidget#optimize_panel {
410470
<property name="text">
411471
<string>1000</string>
412472
</property>
473+
<property name="minimumSize">
474+
<size>
475+
<width>50</width>
476+
<height>0</height>
477+
</size>
478+
</property>
479+
<property name="maximumSize">
480+
<size>
481+
<width>100</width>
482+
<height>16777215</height>
483+
</size>
484+
</property>
413485
<property name="alignment">
414486
<set>Qt::AlignCenter</set>
415487
</property>
@@ -428,6 +500,18 @@ QWidget#optimize_panel {
428500
<property name="text">
429501
<string>000</string>
430502
</property>
503+
<property name="minimumSize">
504+
<size>
505+
<width>50</width>
506+
<height>0</height>
507+
</size>
508+
</property>
509+
<property name="maximumSize">
510+
<size>
511+
<width>100</width>
512+
<height>16777215</height>
513+
</size>
514+
</property>
431515
<property name="alignment">
432516
<set>Qt::AlignCenter</set>
433517
</property>
@@ -464,6 +548,18 @@ QWidget#optimize_panel {
464548
<property name="text">
465549
<string>100</string>
466550
</property>
551+
<property name="minimumSize">
552+
<size>
553+
<width>50</width>
554+
<height>0</height>
555+
</size>
556+
</property>
557+
<property name="maximumSize">
558+
<size>
559+
<width>100</width>
560+
<height>16777215</height>
561+
</size>
562+
</property>
467563
<property name="alignment">
468564
<set>Qt::AlignCenter</set>
469565
</property>
@@ -492,6 +588,18 @@ QWidget#optimize_panel {
492588
<property name="text">
493589
<string>10</string>
494590
</property>
591+
<property name="minimumSize">
592+
<size>
593+
<width>50</width>
594+
<height>0</height>
595+
</size>
596+
</property>
597+
<property name="maximumSize">
598+
<size>
599+
<width>100</width>
600+
<height>16777215</height>
601+
</size>
602+
</property>
495603
<property name="alignment">
496604
<set>Qt::AlignCenter</set>
497605
</property>
@@ -520,6 +628,18 @@ QWidget#optimize_panel {
520628
<property name="text">
521629
<string>1</string>
522630
</property>
631+
<property name="minimumSize">
632+
<size>
633+
<width>50</width>
634+
<height>0</height>
635+
</size>
636+
</property>
637+
<property name="maximumSize">
638+
<size>
639+
<width>100</width>
640+
<height>16777215</height>
641+
</size>
642+
</property>
523643
<property name="alignment">
524644
<set>Qt::AlignCenter</set>
525645
</property>
@@ -548,6 +668,18 @@ QWidget#optimize_panel {
548668
<property name="text">
549669
<string>32</string>
550670
</property>
671+
<property name="minimumSize">
672+
<size>
673+
<width>50</width>
674+
<height>0</height>
675+
</size>
676+
</property>
677+
<property name="maximumSize">
678+
<size>
679+
<width>100</width>
680+
<height>16777215</height>
681+
</size>
682+
</property>
551683
<property name="alignment">
552684
<set>Qt::AlignCenter</set>
553685
</property>
@@ -576,6 +708,18 @@ QWidget#optimize_panel {
576708
<property name="text">
577709
<string>0.1</string>
578710
</property>
711+
<property name="minimumSize">
712+
<size>
713+
<width>50</width>
714+
<height>0</height>
715+
</size>
716+
</property>
717+
<property name="maximumSize">
718+
<size>
719+
<width>100</width>
720+
<height>16777215</height>
721+
</size>
722+
</property>
579723
<property name="alignment">
580724
<set>Qt::AlignCenter</set>
581725
</property>
@@ -620,6 +764,18 @@ QWidget#optimize_panel {
620764
<property name="text">
621765
<string>10</string>
622766
</property>
767+
<property name="minimumSize">
768+
<size>
769+
<width>50</width>
770+
<height>0</height>
771+
</size>
772+
</property>
773+
<property name="maximumSize">
774+
<size>
775+
<width>100</width>
776+
<height>16777215</height>
777+
</size>
778+
</property>
623779
<property name="alignment">
624780
<set>Qt::AlignCenter</set>
625781
</property>
@@ -705,6 +861,18 @@ QWidget#optimize_panel {
705861
<property name="text">
706862
<string>1.0</string>
707863
</property>
864+
<property name="minimumSize">
865+
<size>
866+
<width>50</width>
867+
<height>0</height>
868+
</size>
869+
</property>
870+
<property name="maximumSize">
871+
<size>
872+
<width>100</width>
873+
<height>16777215</height>
874+
</size>
875+
</property>
708876
<property name="alignment">
709877
<set>Qt::AlignCenter</set>
710878
</property>

0 commit comments

Comments
 (0)