Kstars

unitspinboxwidget.h
1/*
2 SPDX-FileCopyrightText: 2015 Utkarsh Simha <utkarshsimha@gmail.com>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#ifndef UNITSPINBOXWIDGET_H
8#define UNITSPINBOXWIDGET_H
9
10#include "ui_unitspinboxwidget.h"
11
12/**
13 * @brief The UnitSpinBoxWidget class
14 * It is a widget that provides a DoubleSpinBox
15 * and a ComboBox for conversions from different
16 * units.
17 * @author Utkarsh Simha
18 */
20{
22
23 public:
24 QComboBox *comboBox;
25 QDoubleSpinBox *doubleSpinBox;
26
27 explicit UnitSpinBoxWidget(QWidget *parent = nullptr);
28 ~UnitSpinBoxWidget() override;
29
30 /**
31 * @brief addUnit Adds a item to the combo box
32 * @param unitName The name of the unit to be displayed
33 * @param conversionFactor The factor the value of a unit must be multiplied by
34 */
35 void addUnit(const QString &unitName, double conversionFactor);
36
37 /** @return whether the widget is enabled */
38 inline bool enabled()
39 {
40 Q_ASSERT(comboBox->isEnabled() == doubleSpinBox->isEnabled());
41 return doubleSpinBox->isEnabled();
42 }
43
44 /** @brief value Returns value upon conversion */
45 double value() const;
46
47 public slots:
48 /**
49 * @brief Sets the given value
50 * @param value The value to set
51 * @note Automatically optimizes the display to use the best unit for the given value
52 */
53 void setValue(const double value);
54
55 /** @brief Enables the widget */
57 {
58 comboBox->setEnabled(enabled);
59 doubleSpinBox->setEnabled(enabled);
60 }
61
62 private:
63 Ui::UnitSpinBoxWidget *ui;
64};
65
66#endif // UNITSPINBOXWIDGET_H
The UnitSpinBoxWidget class It is a widget that provides a DoubleSpinBox and a ComboBox for conversio...
void setEnabled(bool enabled)
Enables the widget.
double value() const
value Returns value upon conversion
void setValue(const double value)
Sets the given value.
void addUnit(const QString &unitName, double conversionFactor)
addUnit Adds a item to the combo box
Q_OBJECTQ_OBJECT
QObject * parent() const const
bool isEnabled() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:38:44 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.