KTextAddons

texttospeechsliderwidget.cpp
1/*
2 SPDX-FileCopyrightText: 2022-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "texttospeechsliderwidget.h"
8#include <QFontMetrics>
9#include <QHBoxLayout>
10#include <QLabel>
11#include <QSlider>
12
13using namespace TextEditTextToSpeech;
14TextToSpeechSliderWidget::TextToSpeechSliderWidget(const QString &labelInfo, QWidget *parent)
15 : QWidget{parent}
16 , mLabelInfo(labelInfo)
17 , mLabel(new QLabel(this))
18 , mSlider(new QSlider(this))
19{
20 auto mainLayout = new QHBoxLayout(this);
21 mainLayout->setContentsMargins({});
22 mainLayout->setObjectName(QStringLiteral("mainLayout"));
23 mSlider->setObjectName(QStringLiteral("mSlider"));
24 mLabel->setObjectName(QStringLiteral("mLabel"));
25 mSlider->setOrientation(Qt::Horizontal);
26 mainLayout->addWidget(mSlider);
27 mainLayout->addWidget(mLabel);
28
29 const QFontMetrics f(mLabel->font());
30 mLabel->setMinimumWidth(f.horizontalAdvance(QStringLiteral("MMMM")));
31 connect(mSlider, &QSlider::valueChanged, this, &TextToSpeechSliderWidget::slotValueChanged);
32}
33
34TextToSpeechSliderWidget::~TextToSpeechSliderWidget() = default;
35
36void TextToSpeechSliderWidget::setValue(int value)
37{
38 mSlider->setValue(value);
39 slotValueChanged(value);
40}
41
42void TextToSpeechSliderWidget::setRange(int min, int max)
43{
44 mSlider->setRange(min, max);
45}
46
47int TextToSpeechSliderWidget::value() const
48{
49 return mSlider->value();
50}
51
52void TextToSpeechSliderWidget::slotValueChanged(int value)
53{
54 Q_EMIT valueChanged(value);
55 mLabel->setText(mLabelInfo.arg(QString::number(value)));
56}
57
58#include "moc_texttospeechsliderwidget.cpp"
void setRange(int min, int max)
void setValue(int)
void valueChanged(int value)
void setText(const QString &)
Q_EMITQ_EMIT
QString arg(Args &&... args) const const
QString number(double n, char format, int precision)
Horizontal
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:56:02 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.