1 // Copyright (C) 2012-2019 The VPaint Developers.
2 // See the COPYRIGHT file at the top-level directory of this distribution
3 // and at https://github.com/dalboris/vpaint/blob/master/COPYRIGHT
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 
17 #include "SpinBox.h"
18 
19 #include <QVBoxLayout>
20 
SpinBox(QWidget * parent)21 SpinBox::SpinBox(QWidget *parent) :
22     QWidget(parent),
23     caption_(0),
24     spinBox_(0)
25 {
26     // Caption
27     caption_ = new QLabel();
28     QFont labelFont = font();
29     labelFont.setPixelSize(11);
30     caption_->setFont(labelFont);
31     caption_->setAlignment(Qt::AlignCenter);
32 
33     // Spin box
34     spinBox_ = new QDoubleSpinBox();
35     spinBox_->setRange(0.0, 999.99);
36 
37     // Layout
38     QVBoxLayout * layout = new QVBoxLayout();
39     layout->addWidget(caption_);
40     layout->addWidget(spinBox_);
41     layout->setSpacing(0);
42     layout->setContentsMargins(0,0,0,0);
43     setLayout(layout);
44     setFixedHeight(40);
45 
46     // Signal forwarding
47     connect(spinBox_, SIGNAL(valueChanged(double)), this, SIGNAL(valueChanged(double)));
48 }
49 
caption() const50 QString SpinBox::caption() const
51 {
52     return caption_->text();
53 }
54 
setCaption(const QString & caption)55 void SpinBox::setCaption(const QString & caption)
56 {
57     caption_->setText(caption);
58 }
59 
value() const60 double SpinBox::value() const
61 {
62     return spinBox_->value();
63 }
64 
setValue(double val)65 void SpinBox::setValue(double val)
66 {
67     spinBox_->setValue(val);
68 }
69