File: texttospeechsliderwidget.cpp

package info (click to toggle)
ktextaddons 1.9.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 17,856 kB
  • sloc: cpp: 62,045; ansic: 6,520; xml: 2,630; sh: 11; makefile: 7
file content (60 lines) | stat: -rw-r--r-- 1,632 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
   SPDX-FileCopyrightText: 2022-2026 Laurent Montel <montel@kde.org>

   SPDX-License-Identifier: LGPL-2.0-or-later
*/

#include "texttospeechsliderwidget.h"

#include <QFontMetrics>
#include <QHBoxLayout>
#include <QLabel>
#include <QSlider>

using namespace Qt::Literals::StringLiterals;
using namespace TextEditTextToSpeech;
TextToSpeechSliderWidget::TextToSpeechSliderWidget(const QString &labelInfo, QWidget *parent)
    : QWidget{parent}
    , mLabelInfo(labelInfo)
    , mLabel(new QLabel(this))
    , mSlider(new QSlider(this))
{
    auto mainLayout = new QHBoxLayout(this);
    mainLayout->setContentsMargins({});
    mainLayout->setObjectName(u"mainLayout"_s);
    mSlider->setObjectName(u"mSlider"_s);
    mLabel->setObjectName(u"mLabel"_s);
    mSlider->setOrientation(Qt::Horizontal);
    mainLayout->addWidget(mSlider);
    mainLayout->addWidget(mLabel);

    const QFontMetrics f(mLabel->font());
    mLabel->setMinimumWidth(f.horizontalAdvance(u"MMMM"_s));
    connect(mSlider, &QSlider::valueChanged, this, &TextToSpeechSliderWidget::slotValueChanged);
}

TextToSpeechSliderWidget::~TextToSpeechSliderWidget() = default;

void TextToSpeechSliderWidget::setValue(int value)
{
    mSlider->setValue(value);
    slotValueChanged(value);
}

void TextToSpeechSliderWidget::setRange(int min, int max)
{
    mSlider->setRange(min, max);
}

int TextToSpeechSliderWidget::value() const
{
    return mSlider->value();
}

void TextToSpeechSliderWidget::slotValueChanged(int value)
{
    Q_EMIT valueChanged(value);
    mLabel->setText(mLabelInfo.arg(QString::number(value)));
}

#include "moc_texttospeechsliderwidget.cpp"