Skip to content

Commit 0ff5092

Browse files
committed
Qt UI tweaks
1 parent b0b83b2 commit 0ff5092

File tree

13 files changed

+81
-32
lines changed

13 files changed

+81
-32
lines changed

ui/app/platforms/windows/WindowsHarpoonLocker.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#endif
2121

2222
#include <cstdint>
23+
#include <spdlog/spdlog.h>
2324

2425
#include "ui/windows/WindowsHarpoonLocker.hh"
2526

ui/app/toolkits/qt/BreakWindow.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,6 @@ BreakWindow::get_operation_name_and_icon(System::SystemOperation::SystemOperatio
200200
name = tr("Suspend hybrid");
201201
icon_name = "shutdown.png";
202202
break;
203-
default:
204-
throw "System::execute: Unknown system operation";
205203
};
206204
}
207205

ui/app/toolkits/qt/preferences/GeneralUiPreferencesPanel.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ constexpr auto RUNKEY = R"(Software\Microsoft\Windows\CurrentVersion\Run)";
4646
GeneralUiPreferencesPanel::GeneralUiPreferencesPanel(std::shared_ptr<IApplicationContext> app)
4747
{
4848
connector = std::make_shared<DataConnector>(app);
49+
size_group = std::make_shared<SizeGroup>(Qt::Horizontal);
4950

5051
// Block types
5152
block_button = new QComboBox;
@@ -74,7 +75,7 @@ GeneralUiPreferencesPanel::GeneralUiPreferencesPanel(std::shared_ptr<IApplicatio
7475
auto *layout = new QVBoxLayout;
7576
setLayout(layout);
7677

77-
UiUtil::add_widget(layout, tr("Block mode:"), block_button);
78+
UiUtil::add_widget(layout, tr("Block mode:"), block_button, size_group);
7879

7980
#if defined(HAVE_LANGUAGE_SELECTION)
8081
std::string current_locale_name = GUIConfig::locale()();
@@ -146,7 +147,7 @@ GeneralUiPreferencesPanel::GeneralUiPreferencesPanel(std::shared_ptr<IApplicatio
146147

147148
languages_view->setColumnHidden(2, true);
148149
languages_combo->setCurrentIndex(selected);
149-
UiUtil::add_widget(layout, tr("Language:"), languages_combo);
150+
UiUtil::add_widget(layout, tr("Language:"), languages_combo, size_group);
150151
#endif
151152

152153
#if defined(PLATFORM_OS_WINDOWS)

ui/app/toolkits/qt/preferences/GeneralUiPreferencesPanel.hh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <QtWidgets>
2323

2424
#include "DataConnector.hh"
25+
#include "SizeGroup.hh"
2526
#include "ui/prefwidgets/qt/BoxWidget.hh"
2627

2728
class GeneralUiPreferencesPanel : public QWidget
@@ -34,7 +35,6 @@ public:
3435

3536
private:
3637
void on_block_changed();
37-
3838

3939
#if defined(PLATFORM_OS_WINDOWS)
4040
void on_autostart_toggled();
@@ -58,6 +58,7 @@ private:
5858
QCheckBox *autostart_cb{nullptr};
5959
#endif
6060

61+
std::shared_ptr<SizeGroup> size_group;
6162
std::shared_ptr<ui::prefwidgets::qt::BoxWidget> plugin_frame;
6263
};
6364

ui/app/toolkits/qt/preferences/TimerBoxPreferencesPanel.cc

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ TimerBoxPreferencesPanel::TimerBoxPreferencesPanel(std::shared_ptr<IApplicationC
4141
, name(name)
4242
{
4343
connector = std::make_shared<DataConnector>(app);
44+
size_group = std::make_shared<SizeGroup>(Qt::Horizontal);
4445

4546
ontop_cb = new QCheckBox;
4647
enabled_cb = new QCheckBox();
@@ -53,7 +54,7 @@ TimerBoxPreferencesPanel::TimerBoxPreferencesPanel(std::shared_ptr<IApplicationC
5354
applet_fallback_enabled_cb = new QCheckBox;
5455
applet_icon_enabled_cb = new QCheckBox;
5556

56-
init();
57+
init();
5758
}
5859

5960
void
@@ -161,7 +162,7 @@ TimerBoxPreferencesPanel::init_fallback_applet()
161162
void
162163
TimerBoxPreferencesPanel::init_status_icon()
163164
{
164-
applet_icon_enabled_cb->setText(tr("Fallback applet enabled"));
165+
applet_icon_enabled_cb->setText(tr("Show status icon"));
165166
connector->connect(GUIConfig::applet_icon_enabled(), dc::wrap(applet_icon_enabled_cb));
166167
}
167168

@@ -203,17 +204,17 @@ TimerBoxPreferencesPanel::init()
203204
display_layout->addWidget(applet_icon_enabled_cb);
204205
}
205206

206-
UiUtil::add_widget(display_layout, tr("Placement:"), place_button);
207-
UiUtil::add_widget(display_layout, tr("Cycle time:"), cycle_entry);
207+
UiUtil::add_widget(display_layout, tr("Placement:"), place_button, size_group);
208+
UiUtil::add_widget(display_layout, tr("Cycle time:"), cycle_entry, size_group);
208209

209210
auto *timers_box = new QGroupBox(tr("Timers"));
210211
layout->addWidget(timers_box);
211212
auto *timers_layout = new QVBoxLayout;
212213
timers_box->setLayout(timers_layout);
213214

214-
UiUtil::add_widget(timers_layout, Ui::get_break_name(BREAK_ID_MICRO_BREAK), timer_display_button[0]);
215-
UiUtil::add_widget(timers_layout, Ui::get_break_name(BREAK_ID_REST_BREAK), timer_display_button[1]);
216-
UiUtil::add_widget(timers_layout, Ui::get_break_name(BREAK_ID_DAILY_LIMIT), timer_display_button[2]);
215+
UiUtil::add_widget(timers_layout, Ui::get_break_name(BREAK_ID_MICRO_BREAK), timer_display_button[0], size_group);
216+
UiUtil::add_widget(timers_layout, Ui::get_break_name(BREAK_ID_REST_BREAK), timer_display_button[1], size_group);
217+
UiUtil::add_widget(timers_layout, Ui::get_break_name(BREAK_ID_DAILY_LIMIT), timer_display_button[2], size_group);
217218

218219
layout->addStretch();
219220

ui/app/toolkits/qt/preferences/TimerBoxPreferencesPanel.hh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <QtGui>
2222
#include <QtWidgets>
2323

24+
#include "SizeGroup.hh"
2425
#include "core/CoreTypes.hh"
2526
#include "utils/Signals.hh"
2627
#include "ui/IApplicationContext.hh"
@@ -68,6 +69,8 @@ private:
6869
QSpinBox *cycle_entry{nullptr};
6970
QCheckBox *applet_fallback_enabled_cb{nullptr};
7071
QCheckBox *applet_icon_enabled_cb{nullptr};
72+
std::shared_ptr<SizeGroup> size_group;
73+
7174
};
7275

7376
#endif // TIMERBOXUIPREFERENCESPANEL_HH

ui/app/toolkits/qt/utils/UiUtil.cc

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,34 +62,61 @@ UiUtil::clear_layout(QLayout *layout)
6262
}
6363

6464
void
65-
UiUtil::add_widget(QBoxLayout *layout, const QString &text, QWidget *widget)
65+
UiUtil::add_widget(QBoxLayout *layout, const QString &text, QWidget *widget, std::shared_ptr<SizeGroup> size_group)
6666
{
6767
auto *box = new QHBoxLayout;
6868
auto *lab = new QLabel(text);
6969

70+
if (size_group)
71+
{
72+
size_group->add_widget(lab);
73+
}
74+
7075
box->addWidget(lab);
71-
box->addWidget(widget);
76+
box->addWidget(widget, 1);
7277
layout->addLayout(box);
7378
}
7479

7580
void
76-
UiUtil::add_widget(QBoxLayout *layout, QLabel *label, QWidget *widget)
81+
UiUtil::add_widget(QBoxLayout *layout, QLabel *label, QWidget *widget, std::shared_ptr<SizeGroup> size_group)
7782
{
7883
auto *box = new QHBoxLayout;
7984

85+
if (size_group)
86+
{
87+
size_group->add_widget(label);
88+
}
89+
8090
box->addWidget(label);
81-
box->addWidget(widget);
91+
box->addWidget(widget, 1);
8292
layout->addLayout(box);
8393
}
8494

8595
auto
86-
UiUtil::add_label(QBoxLayout *layout, const QString &text, bool bold) -> QLabel *
96+
UiUtil::add_label(QBoxLayout *layout, const QString &text, bool bold, std::shared_ptr<SizeGroup> size_group) -> QLabel *
8797
{
8898
QLabel *label = create_label(text, bold);
99+
if (size_group)
100+
{
101+
size_group->add_widget(label);
102+
}
103+
89104
layout->addWidget(label);
90105
return label;
91106
}
92107

108+
auto
109+
UiUtil::add_label(QBoxLayout *layout, const QString &text, std::shared_ptr<SizeGroup> size_group) -> QLabel *
110+
{
111+
return add_label(layout, text, false, size_group);
112+
}
113+
114+
auto
115+
UiUtil::add_bold_label(QBoxLayout *layout, const QString &text, std::shared_ptr<SizeGroup> size_group) -> QLabel *
116+
{
117+
return add_label(layout, text, true, size_group);
118+
}
119+
93120
auto
94121
UiUtil::create_label(const QString &text, bool bold) -> QLabel *
95122
{

ui/app/toolkits/qt/utils/UiUtil.hh

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
#define UIUTIL_HH
2020

2121
#include <QtWidgets>
22+
#include <memory>
2223

24+
#include "SizeGroup.hh"
2325
#include "core/CoreTypes.hh"
2426

2527
class UiUtil
@@ -38,9 +40,15 @@ public:
3840

3941
static void clear_layout(QLayout *layout);
4042

41-
static void add_widget(QBoxLayout *layout, const QString &text, QWidget *widget);
42-
static void add_widget(QBoxLayout *layout, QLabel *label, QWidget *widget);
43-
static auto add_label(QBoxLayout *layout, const QString &text, bool bold = false) -> QLabel *;
43+
static void add_widget(QBoxLayout *layout,
44+
const QString &text,
45+
QWidget *widget,
46+
std::shared_ptr<SizeGroup> size_group = nullptr);
47+
static void add_widget(QBoxLayout *layout, QLabel *label, QWidget *widget, std::shared_ptr<SizeGroup> size_group = nullptr);
48+
static auto add_label(QBoxLayout *layout, const QString &text, bool bold, std::shared_ptr<SizeGroup> size_group) -> QLabel *;
49+
static auto add_label(QBoxLayout *layout, const QString &text, std::shared_ptr<SizeGroup> size_group = nullptr) -> QLabel *;
50+
static auto add_bold_label(QBoxLayout *layout, const QString &text, std::shared_ptr<SizeGroup> size_group = nullptr)
51+
-> QLabel *;
4452

4553
static auto create_icon(const QString &filename) -> QIcon;
4654
static auto create_pixmap(const QString &filename, int height) -> QPixmap;

ui/app/toolkits/qt/widgets/TimeBar.cc

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,17 +130,18 @@ TimeBar::paintEvent(QPaintEvent * /* event */)
130130

131131
// Draw background
132132
painter.fillRect(0, 0, width() - 1, height() - 1, QColor("white"));
133-
painter.setPen(QColor("black"));
134-
painter.drawRect(0, 0, width() - 1, height() - 1);
133+
134+
QRect fr = contentsRect();
135+
fr.adjust(-border_size, -border_size, border_size, border_size);
135136

136137
QStyleOptionFrame option;
137138
option.initFrom(this);
138-
option.features = QStyleOptionFrame::Flat;
139-
option.frameShape = QFrame::Panel;
140-
option.lineWidth = 2;
139+
option.rect = fr;
140+
option.lineWidth = 1;
141141
option.midLineWidth = 0;
142-
143-
painter.drawPrimitive(QStyle::PE_Frame, option);
142+
option.state |= QStyle::State_Raised;
143+
option.frameShape = QFrame::Panel;
144+
painter.drawControl(QStyle::CE_ShapedFrame, option);
144145

145146
// Bar
146147
int bar_width = 0;

ui/libs/prefwidgets/toolkits/qt/include/ui/prefwidgets/qt/FrameWidget.hh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ namespace ui::prefwidgets::qt
4646
QGroupBox *panel{};
4747
QVBoxLayout *layout{};
4848
std::list<std::shared_ptr<Widget>> children;
49+
std::shared_ptr<ui::prefwidgets::qt::SizeGroup> size_group;
4950
};
5051
} // namespace ui::prefwidgets::qt
5152

0 commit comments

Comments
 (0)