forked from community-ssu/osso-calculator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathosso-calculator-button.cpp
90 lines (61 loc) · 2.3 KB
/
osso-calculator-button.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
/*
osso-calculator-button.cpp - OSSO Calculator
Copyright (C) 2011 Pali Rohár <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QString>
#include <QWidget>
#include <QPushButton>
#include <QPalette>
#ifdef Q_WS_MAEMO_5
#include <QMaemo5Style>
#endif
#include "osso-calculator-button.h"
#include "osso-intl.h"
OssoCalculatorButton::OssoCalculatorButton(const QString &name, QWidget * parent) : QPushButton(parent) {
setText(_(name));
setMinimumWidth(86);
setMinimumHeight(55);
buttonName = name;
if ( name == "calc_bv_desk_ac" || name == "calc_bv_desk_c" )
textColor = "AttentionColor";
else if ( name == "calc_bv_tr_min" || name == "calc_bv_tr_mplus" || name == "calc_bv_tr_mminus" || name == "calc_bv_tr_mr" )
textColor = "AccentColor1";
#ifdef Q_WS_MAEMO_5
if ( name.at(0).isDigit() || name == "calc_bv_tr_decimal" )
setObjectName("HILDON-WIDGET-hildon-accent-button");
else
setObjectName("HILDON-WIDGET-hildon-button-stylus");
#endif
connect ( this, SIGNAL( clicked(bool) ), this, SLOT( clicked() ) );
}
void OssoCalculatorButton::clicked() {
emit clicked(buttonName);
}
void OssoCalculatorButton::paintEvent(QPaintEvent * event) {
if ( ! textColor.isEmpty() ) {
QPalette palette = this->palette();
#ifdef Q_WS_MAEMO_5
palette.setColor(QPalette::ButtonText, QMaemo5Style::standardColor(textColor));
#else
if ( textColor == "AttentionColor" )
palette.setColor(QPalette::ButtonText, QColor(227, 0, 42));
else if ( textColor == "AccentColor1" )
palette.setColor(QPalette::ButtonText, QColor(134, 213, 252));
#endif
setPalette(palette);
}
QPushButton::paintEvent(event);
}
const QString & OssoCalculatorButton::name() {
return buttonName;
}