Mercurial > projects > qtd
comparison examples/widgets/calculator/calculator.d @ 350:31520b2c0b3c
Removed dependency on parent trait and stringof
author | Max Samukha <maxter@spambox.com> |
---|---|
date | Thu, 20 May 2010 15:49:08 +0300 |
parents | 7a3c43424dca |
children |
comparison
equal
deleted
inserted
replaced
349:925386e0e780 | 350:31520b2c0b3c |
---|---|
47 import qt.gui.QLineEdit; | 47 import qt.gui.QLineEdit; |
48 import qt.gui.QFont; | 48 import qt.gui.QFont; |
49 | 49 |
50 import std.math; | 50 import std.math; |
51 import std.conv; | 51 import std.conv; |
52 import std.string; | 52 import std.string : format, indexOf; |
53 | 53 |
54 class Calculator : public QDialog | 54 class Calculator : public QDialog |
55 { | 55 { |
56 | 56 |
57 public: | 57 public: |
58 | |
59 this(QWidget parent = null) | 58 this(QWidget parent = null) |
60 { | 59 { |
61 super(parent); | 60 super(parent); |
62 | 61 |
63 sumInMemory = 0.0; | 62 sumInMemory = 0.0; |
68 display = new QLineEdit("0"); | 67 display = new QLineEdit("0"); |
69 display.setReadOnly(true); | 68 display.setReadOnly(true); |
70 display.setAlignment(Qt.AlignRight); | 69 display.setAlignment(Qt.AlignRight); |
71 display.setMaxLength(15); | 70 display.setMaxLength(15); |
72 | 71 |
73 auto font = new QFont(display.font()); | 72 auto font = new QFont(display.font()); |
74 font.setPointSize(font.pointSize() + 8); | 73 font.setPointSize(font.pointSize() + 8); |
75 display.setFont(font); | 74 display.setFont(font); |
76 | 75 |
77 for (int i = 0; i < NumDigitButtons; ++i) { | 76 for (int i = 0; i < NumDigitButtons; ++i) { |
78 digitButtons[i] = createButton(format("%d", i), "digitClicked"); | 77 digitButtons[i] = createButton(format("%d", i), "digitClicked"); |
148 | 147 |
149 if (waitingForOperand) { | 148 if (waitingForOperand) { |
150 display.clear(); | 149 display.clear(); |
151 waitingForOperand = false; | 150 waitingForOperand = false; |
152 } | 151 } |
153 display.setText(display.text() ~ format("%g", digitValue)); | 152 |
153 display.setText(display.text() ~ format("%s", digitValue)); | |
154 } | 154 } |
155 | 155 |
156 void slot_unaryOperatorClicked() | 156 void slot_unaryOperatorClicked() |
157 { | 157 { |
158 Button clickedButton = cast(Button) sender(); | 158 Button clickedButton = cast(Button) sender(); |
265 if (waitingForOperand) | 265 if (waitingForOperand) |
266 display.setText("0"); | 266 display.setText("0"); |
267 | 267 |
268 if (indexOf(text, '.') >= text.length) | 268 if (indexOf(text, '.') >= text.length) |
269 display.setText(text ~ tr(".")); | 269 display.setText(text ~ tr(".")); |
270 | 270 |
271 waitingForOperand = false; | 271 waitingForOperand = false; |
272 } | 272 } |
273 | 273 |
274 void slot_changeSignClicked() | 274 void slot_changeSignClicked() |
275 { | 275 { |