b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame^] | 1 | #include "StatusBar.h" |
| 2 | #include <ui/HBoxLayout.h> |
| 3 | #include <ui/Spacer.h> |
| 4 | |
| 5 | namespace MGUI |
| 6 | { |
| 7 | |
| 8 | StatusBar::StatusBar(ilixi::Widget* parent) |
| 9 | : ContainerBase(parent), |
| 10 | _batteryIcon(NULL) |
| 11 | { |
| 12 | ilixi::HBoxLayout* layout = new ilixi::HBoxLayout(); |
| 13 | layout->setSpacing(0); |
| 14 | layout->setVerticalAlignment(ilixi::Alignment::Middle); |
| 15 | setLayout(layout); |
| 16 | |
| 17 | _clock = new ilixi::Label("00:00"); |
| 18 | addWidget(_clock); |
| 19 | |
| 20 | addWidget(new ilixi::Spacer()); |
| 21 | |
| 22 | _simIcon = new SimIcon(); |
| 23 | addWidget(_simIcon); |
| 24 | |
| 25 | _sdcardIcon = new SDCardIcon(); |
| 26 | addWidget(_sdcardIcon); |
| 27 | |
| 28 | _wifiIcon = new WiFiIcon(); |
| 29 | addWidget(_wifiIcon); |
| 30 | |
| 31 | _cellularTechIcon = new CellularTechIcon(); |
| 32 | addWidget(_cellularTechIcon); |
| 33 | |
| 34 | _cellularIcon = new CellularIcon(); |
| 35 | addWidget(_cellularIcon); |
| 36 | |
| 37 | _gpsIcon = new GPSIcon(); |
| 38 | addWidget(_gpsIcon); |
| 39 | |
| 40 | _bluetoothIcon = new BTIcon(); |
| 41 | addWidget(_bluetoothIcon); |
| 42 | |
| 43 | _batteryIcon = new BatteryIcon(); |
| 44 | addWidget(_batteryIcon); |
| 45 | |
| 46 | _timer = new ilixi::Timer(); |
| 47 | _timer->sigExec.connect(sigc::mem_fun(this, &StatusBar::updateTime)); |
| 48 | _timer->start(10000); |
| 49 | updateTime(); |
| 50 | } |
| 51 | |
| 52 | StatusBar::~StatusBar() |
| 53 | { |
| 54 | delete _timer; |
| 55 | } |
| 56 | |
| 57 | void |
| 58 | StatusBar::compose(const ilixi::PaintEvent& event) |
| 59 | { |
| 60 | } |
| 61 | |
| 62 | void |
| 63 | StatusBar::setBatteryState(BatteryState state) |
| 64 | { |
| 65 | _batteryIcon->setBatteryState(state); |
| 66 | } |
| 67 | |
| 68 | void |
| 69 | StatusBar::setBluetoothState(BluetoothState state) |
| 70 | { |
| 71 | _bluetoothIcon->setBluetoothState(state); |
| 72 | } |
| 73 | |
| 74 | void |
| 75 | StatusBar::setCellularState(CellularState state) |
| 76 | { |
| 77 | _cellularIcon->setCellularState(state); |
| 78 | } |
| 79 | |
| 80 | void |
| 81 | StatusBar::setCellularTechState(CellularTechState state) |
| 82 | { |
| 83 | _cellularTechIcon->setCellularTechState(state); |
| 84 | } |
| 85 | |
| 86 | void |
| 87 | StatusBar::setGPSState(GpsState state) |
| 88 | { |
| 89 | _gpsIcon->setGpsState(state); |
| 90 | } |
| 91 | |
| 92 | void |
| 93 | StatusBar::setSDCardState(SDCardState state) |
| 94 | { |
| 95 | _sdcardIcon->setSdcardState(state); |
| 96 | } |
| 97 | |
| 98 | void |
| 99 | StatusBar::setSimState(SimState state) |
| 100 | { |
| 101 | _simIcon->setSimState(state); |
| 102 | } |
| 103 | |
| 104 | void |
| 105 | StatusBar::setWifiState(WifiState state) |
| 106 | { |
| 107 | _wifiIcon->setWifiState(state); |
| 108 | } |
| 109 | |
| 110 | void |
| 111 | StatusBar::updateTime() |
| 112 | { |
| 113 | struct timeval tv; |
| 114 | struct tm* tm; |
| 115 | gettimeofday(&tv, NULL); |
| 116 | tm = localtime(&tv.tv_sec); |
| 117 | |
| 118 | _clock->setText(ilixi::PrintF("%02d:%02d", tm->tm_hour, tm->tm_min)); |
| 119 | } |
| 120 | |
| 121 | } /* namespace MGUI */ |