-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQTUtils.cpp
115 lines (95 loc) · 4.46 KB
/
QTUtils.cpp
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// **************************************************
// QTUtils module.
// Author : Tamy Boubekeur ([email protected]).
// Copyright (C) 2008 Tamy Boubekeur.
// All rights reserved.
// **************************************************
#include "QTUtils.h"
#include <cmath>
#include <QHBoxLayout>
IntegerWidget::IntegerWidget (const QString & name,
int minValue,
int maxValue,
int value,
QWidget * parent) : QWidget (parent) {
label = new QLabel (name, parent);
slider = new QSlider (Qt::Horizontal, this);
slider->setMinimum (minValue);
slider->setMaximum (maxValue);
slider->setValue (value);
unsigned int numOfDigits = static_cast<unsigned int>(log10 (maxValue)) + 1;
LCDNumber = new QLCDNumber (numOfDigits, this);
LCDNumber->display (value);
LCDNumber->setSegmentStyle (QLCDNumber::Flat);
LCDNumber->setFrameShape (QFrame::NoFrame);
QHBoxLayout * layout = new QHBoxLayout (this);
layout->addWidget (label);
layout->addWidget (slider);
layout->addWidget (LCDNumber);
connect (slider, SIGNAL (valueChanged (int)),
LCDNumber, SLOT (display (int)));
connect (slider, SIGNAL (valueChanged (int)),
this, SIGNAL (valueChanged (int)));
}
IntegerWidget::~IntegerWidget () {
}
DoubleWidget::DoubleWidget (const QString & name,
double minValue,
double maxValue,
double value,
QWidget * parent) : QWidget (parent) {
label = new QLabel (name, parent);
slider = new QSlider (Qt::Horizontal, this);
slider->setMinimum (1000*minValue);
slider->setMaximum (1000*maxValue);
slider->setValue (1000*value);
unsigned int numOfDigits = 3;
LCDNumber = new QLCDNumber (numOfDigits, this);
LCDNumber->setSegmentStyle (QLCDNumber::Flat);
LCDNumber->setFrameShape (QFrame::NoFrame);
LCDNumber->setSmallDecimalPoint (true);
LCDNumber->display (value);
QHBoxLayout * layout = new QHBoxLayout (this);
layout->addWidget (label);
layout->addWidget (slider);
layout->addWidget (LCDNumber);
connect (slider, SIGNAL (valueChanged (int)),
this, SLOT (changeValue (int)));
}
DoubleWidget::~DoubleWidget () {
}
void DoubleWidget::changeValue (int i) {
double s = i/1000.0;
LCDNumber->display (s);
emit valueChanged (s);
}
void setBoubekQTStyle (QApplication & app) {
QPalette p (app.palette());
#ifdef _MSC_VER
p.setColor (QPalette::Background, QColor (240, 240, 255)); // general background
p.setColor (QPalette::WindowText, QColor (50, 50, 50)); // general foreground
p.setColor (QPalette::Base, QColor (60, 60, 60)); // text entry widget
p.setColor (QPalette::AlternateBase, QColor (238, 112, 0)); // Text used on 'Base'
p.setColor (QPalette::Text, QColor (145, 145, 0)); // Text used on 'Base'
p.setColor (QPalette::Button, QColor (240, 240, 255)); // general bg button color
p.setColor (QPalette::ButtonText, QColor (48, 48, 48)); // general foreground button color
p.setColor (QPalette::BrightText, QColor (238, 112, 0)); // to ensure contrast
p.setColor (QPalette::Highlight, QColor (0, 0, 255)); // marked element
p.setColor (QPalette::HighlightedText, QColor (255, 255, 0)); // marked element text
#else
p.setColor (QPalette::Background, QColor (48, 48, 48/*39, 39, 39*/)); // general background
p.setColor (QPalette::WindowText, QColor (203, 203, 203)); // general foreground
p.setColor (QPalette::Base, QColor (60, 60, 60)); // text entry widget
p.setColor (QPalette::AlternateBase, QColor (238, 112, 0)); // Text used on 'Base'
p.setColor (QPalette::ToolTipBase, QColor (48, 48, 48));
p.setColor (QPalette::ToolTipText, QColor (48, 48, 48));
p.setColor (QPalette::Text, QColor (145, 145, 145)); // Text used on 'Base'
p.setColor (QPalette::Button, QColor (48, 48, 48)); // general bg button color
p.setColor (QPalette::ButtonText, QColor (203, 203, 203)); // general foreground button color
p.setColor (QPalette::BrightText, QColor (238, 112, 0)); // to ensure contrast
p.setColor (QPalette::Highlight, QColor (238, 112, 0)); // marked element
p.setColor (QPalette::HighlightedText, QColor (31, 13, 0)); // marked element text
p.setColor (QPalette::Light, QColor (100, 100, 100)); // marked element
#endif
app.setPalette(p);
}