Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ find_package(Qt${MAJOR_QT_VERSION} REQUIRED
Gui
Network
Svg
SvgWidgets
Concurrent
)
if(CHATTERINO_ALLOW_PRIVATE_QT_API)
Expand Down
42 changes: 42 additions & 0 deletions resources/settings/hint.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,7 @@ target_link_libraries(${LIBRARY_PROJECT}
Qt${MAJOR_QT_VERSION}::Gui
Qt${MAJOR_QT_VERSION}::Network
Qt${MAJOR_QT_VERSION}::Svg
Qt${MAJOR_QT_VERSION}::SvgWidgets
Qt${MAJOR_QT_VERSION}::Concurrent

LibCommuni::LibCommuni
Expand Down
35 changes: 34 additions & 1 deletion src/widgets/settingspages/SettingWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
#include <QFormLayout>
#include <QLabel>
#include <QLineEdit>
#include <QPixmap>
#include <QSvgRenderer>
#include <QSvgWidget>
#include <Qt>

#include <algorithm>

namespace {

Expand All @@ -33,7 +39,8 @@ const QRegularExpression MAX_TOOLTIP_LINE_LENGTH_REGEX(
namespace chatterino {

SettingWidget::SettingWidget(const QString &mainKeyword)
: vLayout(new QVBoxLayout(this))
: tooltipIcon(new QSvgWidget(this))
, vLayout(new QVBoxLayout(this))
, hLayout(new QHBoxLayout)
{
this->vLayout->setContentsMargins(0, 0, 0, 0);
Expand All @@ -42,6 +49,7 @@ SettingWidget::SettingWidget(const QString &mainKeyword)
this->vLayout->addLayout(this->hLayout);

this->keywords.append(mainKeyword);
this->tooltipIcon->setVisible(false);
}

SettingWidget *SettingWidget::checkbox(const QString &label,
Expand All @@ -52,6 +60,8 @@ SettingWidget *SettingWidget::checkbox(const QString &label,
auto *check = new SCheckBox(label);

widget->hLayout->addWidget(check);
widget->hLayout->addWidget(widget->tooltipIcon);
widget->hLayout->addStretch(1);

// update when setting changes
setting.connect(
Expand Down Expand Up @@ -80,6 +90,8 @@ SettingWidget *SettingWidget::inverseCheckbox(const QString &label,
auto *check = new SCheckBox(label);

widget->hLayout->addWidget(check);
widget->hLayout->addWidget(widget->tooltipIcon);
widget->hLayout->addStretch(1);

// update when setting changes
setting.connect(
Expand Down Expand Up @@ -109,6 +121,8 @@ SettingWidget *SettingWidget::customCheckbox(
auto *check = new SCheckBox(label);

widget->hLayout->addWidget(check);
widget->hLayout->addWidget(widget->tooltipIcon);
widget->hLayout->addStretch(1);

check->setChecked(initialValue);

Expand Down Expand Up @@ -147,6 +161,7 @@ SettingWidget *SettingWidget::intInput(const QString &label,
}

widget->hLayout->addWidget(lbl);
widget->hLayout->addWidget(widget->tooltipIcon);
widget->hLayout->addStretch(1);
widget->hLayout->addWidget(input);

Expand Down Expand Up @@ -192,6 +207,7 @@ SettingWidget *SettingWidget::dropdown(const QString &label,
widget->label = lbl;

widget->hLayout->addWidget(lbl);
widget->hLayout->addWidget(widget->tooltipIcon);
widget->hLayout->addStretch(1);
widget->hLayout->addWidget(combo);

Expand Down Expand Up @@ -265,6 +281,7 @@ SettingWidget *SettingWidget::dropdown(const QString &label,
widget->label = lbl;

widget->hLayout->addWidget(lbl);
widget->hLayout->addWidget(widget->tooltipIcon);
widget->hLayout->addStretch(1);
widget->hLayout->addWidget(combo);

Expand Down Expand Up @@ -343,6 +360,7 @@ SettingWidget *SettingWidget::dropdown(
widget->label = lbl;

widget->hLayout->addWidget(lbl);
widget->hLayout->addWidget(widget->tooltipIcon);
widget->hLayout->addStretch(1);
widget->hLayout->addWidget(combo);

Expand Down Expand Up @@ -395,6 +413,7 @@ SettingWidget *SettingWidget::colorButton(const QString &label,
auto *colorButton = new ColorButton(color);

widget->hLayout->addWidget(lbl);
widget->hLayout->addWidget(widget->tooltipIcon);
widget->hLayout->addStretch(1);
widget->hLayout->addWidget(colorButton);

Expand Down Expand Up @@ -442,6 +461,7 @@ SettingWidget *SettingWidget::lineEdit(const QString &label,
}

widget->hLayout->addWidget(lbl);
widget->hLayout->addWidget(widget->tooltipIcon);
widget->hLayout->addWidget(edit);

// Update the setting when the widget changes.
Expand Down Expand Up @@ -480,6 +500,7 @@ SettingWidget *SettingWidget::fontButton(const QString &label,
auto *button = new SPushButton(currentFont().family());

widget->hLayout->addWidget(lbl);
widget->hLayout->addWidget(widget->tooltipIcon);
widget->hLayout->addStretch(1);
widget->hLayout->addWidget(button);

Expand Down Expand Up @@ -519,16 +540,28 @@ SettingWidget *SettingWidget::setTooltip(QString tooltip)
tooltip.replace(MAX_TOOLTIP_LINE_LENGTH_REGEX, "\n");
}

int sz = 0;
if (this->label != nullptr)
{
this->label->setToolTip(tooltip);
sz = this->label->sizeHint().height();
}

if (this->actionWidget != nullptr)
{
this->actionWidget->setToolTip(tooltip);
sz = std::max(sz, this->actionWidget->sizeHint().height());
}

this->tooltipIcon->setVisible(true);
this->tooltipIcon->load(u":/settings/hint.svg"_qs);
this->tooltipIcon->setToolTip(tooltip);
auto *r = this->tooltipIcon->renderer();
auto vb = r->viewBox();
this->tooltipIcon->setFixedHeight(sz);
this->tooltipIcon->setFixedWidth(
int(double(sz) / double(vb.height()) * double(vb.width())));

this->keywords.append(tooltip);

return this;
Expand Down
2 changes: 2 additions & 0 deletions src/widgets/settingspages/SettingWidget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

class QFormLayout;
class QLayout;
class QSvgWidget;

namespace chatterino {

Expand Down Expand Up @@ -135,6 +136,7 @@ class SettingWidget : public QWidget

QWidget *label = nullptr;
QWidget *actionWidget = nullptr;
QSvgWidget *tooltipIcon;

QVBoxLayout *vLayout;
QHBoxLayout *hLayout;
Expand Down
Loading