リビジョン | a03cd312d994b5340e41e6658ca884d01b69c7b3 (tree) |
---|---|
日時 | 2010-11-13 03:28:33 |
作者 | satofumi |
コミッター | satofumi |
充電済みのときに描画しないオプションを追加
@@ -27,369 +27,472 @@ | ||
27 | 27 | |
28 | 28 | namespace |
29 | 29 | { |
30 | - const char* Organization = "Hyakuren Soft LTD."; | |
31 | - const char* Application = "qlm_batmon"; | |
30 | + const char* Organization = "Hyakuren Soft LTD."; | |
31 | + const char* Application = "qlm_batmon"; | |
32 | 32 | }; |
33 | 33 | |
34 | 34 | |
35 | 35 | struct BatmonWidget::pImpl |
36 | 36 | { |
37 | - enum { | |
38 | - IntervalMsec = 2000, // [msec] | |
39 | - }; | |
40 | - | |
41 | - BatmonWidget* widget_; | |
42 | - BatteryState battery_; | |
43 | - ChargingState battery_state_; | |
44 | - ChargingState previous_battery_state_; | |
45 | - size_t percent_; | |
46 | - size_t previous_percent_; | |
47 | - QTimer update_timer_; | |
48 | - vector<character_t> characters_; | |
49 | - size_t character_index_; | |
50 | - DrawCharacter draw_character_; | |
51 | - QPoint drag_position_; | |
52 | - | |
53 | - bool hide_checked_; | |
54 | - QAction* hide_action_; | |
55 | - vector<QAction*> skin_actions_; | |
56 | - bool is_masked_; | |
57 | - | |
58 | - bool is_tray_available_; | |
59 | - QSystemTrayIcon tray_icon_; | |
60 | - | |
61 | - | |
62 | - pImpl(BatmonWidget* widget) | |
63 | - : widget_(widget), | |
64 | - battery_state_(Unknown), previous_battery_state_(Unknown), | |
65 | - percent_(0), previous_percent_(0), character_index_(0), | |
66 | - hide_checked_(false), hide_action_(NULL), is_masked_(false), | |
67 | - is_tray_available_(QSystemTrayIcon::isSystemTrayAvailable()) | |
68 | - { | |
69 | - } | |
70 | - | |
71 | - | |
72 | - void initialize(void) | |
73 | - { | |
74 | - // アイコンを適用 | |
75 | - widget_->setWindowIcon(QIcon(":icons/qlm_batmon_icon")); | |
76 | - | |
77 | - // 背景を灰色にし、アンチエイリアスの効果を期待して少しだけ透明にする | |
78 | - QColor color(128, 128, 128, 223); | |
79 | - widget_->setPalette(color); | |
80 | - | |
81 | - update(); | |
82 | - | |
83 | - // 更新用のタイマーを初期化 | |
84 | - update_timer_.setInterval(IntervalMsec); | |
85 | - connect(&update_timer_, SIGNAL(timeout()), widget_, SLOT(updateTimeout())); | |
86 | - update_timer_.start(); | |
87 | - } | |
88 | - | |
37 | + enum { | |
38 | + IntervalMsec = 2000, // [msec] | |
39 | + }; | |
89 | 40 | |
90 | - void initializeCharacters(void) | |
91 | - { | |
92 | - // 女の子 | |
93 | - character_t girl; | |
94 | - girl.name = tr("girl"); | |
95 | - girl.picture_unknown = ":picture/girl_unknown"; | |
96 | - girl.picture_charging = ":picture/girl_charging"; | |
97 | - girl.picture_discharging = ":picture/girl_discharging"; | |
98 | - girl.percent_bar = ":picture/percent_bar"; | |
99 | - girl.bar_position = QPoint(4, 43); | |
100 | - characters_.push_back(girl); | |
101 | - | |
102 | - // りもペンギン | |
103 | - character_t penguin; | |
104 | - penguin.name = tr("pengui"); | |
105 | - penguin.picture_unknown = ":picture/penguin_unknown"; | |
106 | - penguin.picture_charging = ":picture/penguin_charging"; | |
107 | - penguin.picture_discharging = ":picture/penguin_discharging"; | |
108 | - penguin.percent_bar = ":picture/percent_bar"; | |
109 | - penguin.bar_position = QPoint(5, 44); | |
110 | - characters_.push_back(penguin); | |
111 | - } | |
112 | - | |
41 | + BatmonWidget* widget_; | |
42 | + BatteryState battery_; | |
43 | + ChargingState battery_state_; | |
44 | + ChargingState previous_battery_state_; | |
45 | + size_t percent_; | |
46 | + size_t previous_percent_; | |
47 | + QTimer update_timer_; | |
48 | + vector<character_t> characters_; | |
49 | + size_t character_index_; | |
50 | + DrawCharacter draw_character_; | |
51 | + QPoint drag_position_; | |
113 | 52 | |
114 | - void initializeMenu(void) | |
115 | - { | |
116 | - // キャラクタ選択メニューの作成 | |
117 | - size_t n = characters_.size(); | |
118 | - for (size_t i = 0; i < n; ++i) { | |
119 | - QAction* action = new QAction(characters_[i].name, widget_); | |
120 | - action->setCheckable(true); | |
121 | - widget_->addAction(action); | |
122 | - skin_actions_.push_back(action); | |
123 | - } | |
124 | - connect(skin_actions_[0], SIGNAL(triggered()), | |
125 | - widget_, SLOT(girlSkinSelected())); | |
126 | - connect(skin_actions_[1], SIGNAL(triggered()), | |
127 | - widget_, SLOT(limoSkinSelected())); | |
128 | - setSkin(character_index_); | |
129 | - | |
130 | - widget_->addAction(newSeparator()); | |
131 | - | |
132 | - // 充電中に非表示にするかのチェックボックス | |
133 | - hide_action_ = new QAction(tr("Hide while charging"), widget_); | |
134 | - hide_action_->setCheckable(true); | |
135 | - hide_action_->setChecked(hide_checked_); | |
136 | - widget_->addAction(hide_action_); | |
137 | - connect(hide_action_, SIGNAL(triggered()), widget_, SLOT(hideSpecified())); | |
53 | + bool show_always_checked_; | |
54 | + bool hide_charging_checked_; | |
55 | + bool hide_charged_checked_; | |
138 | 56 | |
139 | - widget_->addAction(newSeparator()); | |
140 | - | |
141 | - // 終了 | |
142 | - QAction* quit_action = new QAction(QAction::tr("Quit"), widget_); | |
143 | - quit_action->setShortcut(tr("Ctrl+Q")); | |
144 | - connect(quit_action, SIGNAL(triggered()), qApp, SLOT(quit())); | |
145 | - widget_->addAction(quit_action); | |
146 | - | |
147 | - widget_->setContextMenuPolicy(Qt::ActionsContextMenu); | |
148 | - } | |
149 | - | |
57 | + QAction* show_always_action_; | |
58 | + QAction* hide_charging_action_; | |
59 | + QAction* hide_charged_action_; | |
60 | + vector<QAction*> skin_actions_; | |
61 | + bool is_masked_; | |
150 | 62 | |
151 | - void initializeSystemTray(void) | |
152 | - { | |
153 | - // システムトレイにアイコンを配置 | |
154 | - tray_icon_.setIcon(widget_->windowIcon()); | |
155 | - tray_icon_.setToolTip(tr("APM Battery Monitor")); | |
156 | - | |
157 | - QMenu* menu = new QMenu(widget_); | |
158 | - QList<QAction*> actions = widget_->actions(); | |
159 | - for (int i = 0; i < actions.size(); ++i) { | |
160 | - menu->addAction(actions.at(i)); | |
161 | - } | |
162 | - tray_icon_.setContextMenu(menu); | |
163 | - tray_icon_.hide(); | |
164 | - } | |
63 | + bool is_tray_available_; | |
64 | + QSystemTrayIcon tray_icon_; | |
165 | 65 | |
166 | 66 | |
167 | - QAction* newSeparator(void) | |
168 | - { | |
169 | - QAction* separator = new QAction(widget_); | |
170 | - separator->setSeparator(true); | |
171 | - return separator; | |
172 | - } | |
173 | - | |
174 | - | |
175 | - void loadSettings(bool restore_geometry) | |
176 | - { | |
177 | - QSettings settings(Organization, Application); | |
178 | - | |
179 | - character_index_ = settings.value("character_index", 0).toInt(); | |
180 | - hide_checked_ = settings.value("hide_checked", false).toBool(); | |
181 | - | |
182 | - if (restore_geometry) { | |
183 | - widget_->restoreGeometry(settings.value("geometry").toByteArray()); | |
67 | + pImpl(BatmonWidget* widget) | |
68 | + : widget_(widget), | |
69 | + battery_state_(Unknown), previous_battery_state_(Unknown), | |
70 | + percent_(0), previous_percent_(0), character_index_(0), | |
71 | + show_always_checked_(true), hide_charging_checked_(false), | |
72 | + hide_charged_checked_(false), | |
73 | + show_always_action_(NULL), hide_charging_action_(NULL), | |
74 | + hide_charged_action_(NULL), is_masked_(false), | |
75 | + is_tray_available_(QSystemTrayIcon::isSystemTrayAvailable()) | |
76 | + { | |
184 | 77 | } |
185 | - } | |
186 | - | |
187 | - | |
188 | - void saveSettings(void) | |
189 | - { | |
190 | - QSettings settings(Organization, Application); | |
191 | - | |
192 | - settings.setValue("geometry", widget_->saveGeometry()); | |
193 | - settings.setValue("character_index", character_index_); | |
194 | - settings.setValue("hide_checked", hide_action_->isChecked()); | |
195 | - } | |
196 | - | |
197 | - | |
198 | - ChargingState batteryState(void) | |
199 | - { | |
200 | - if (! battery_.isAvailable()) { | |
201 | - return Unknown; | |
202 | - } | |
203 | - return (battery_.isCharging() ? Charging : Discharging); | |
204 | - } | |
205 | 78 | |
206 | 79 | |
207 | - void update(void) | |
208 | - { | |
209 | - // 描画する状態の取得 | |
210 | - battery_state_ = batteryState(); | |
211 | - percent_ = battery_.remainingPercent(); | |
80 | + void initialize(void) | |
81 | + { | |
82 | + // アイコンを適用 | |
83 | + widget_->setWindowIcon(QIcon(":icons/qlm_batmon_icon")); | |
212 | 84 | |
213 | - // フォーカス時に表示する情報の更新 | |
214 | - QString message = updateMessage(); | |
215 | - widget_->setToolTip(message); | |
85 | + // メニュー項目を作成 | |
86 | + show_always_action_ = new QAction(tr("Show always"), widget_); | |
87 | + hide_charging_action_ = new QAction(tr("Hide while charging"), widget_); | |
88 | + hide_charged_action_ = new QAction(tr("Hide while charged"), widget_); | |
89 | + connect(show_always_action_, SIGNAL(triggered()), | |
90 | + widget_, SLOT(showAlwaysSpecified())); | |
91 | + connect(hide_charging_action_, SIGNAL(triggered()), | |
92 | + widget_, SLOT(hideChargingSpecified())); | |
93 | + connect(hide_charged_action_, SIGNAL(triggered()), | |
94 | + widget_, SLOT(hideChargedSpecified())); | |
216 | 95 | |
217 | - bool repainted = false; | |
218 | - if ((battery_state_ != previous_battery_state_) || | |
219 | - percent_ != previous_percent_) { | |
220 | - repainted = true; | |
221 | - widget_->repaint(); | |
96 | + // 背景を灰色にし、アンチエイリアスの効果を期待して少しだけ透明にする | |
97 | + QColor color(128, 128, 128, 223); | |
98 | + widget_->setPalette(color); | |
99 | + | |
100 | + update(); | |
101 | + | |
102 | + // 更新用のタイマーを初期化 | |
103 | + update_timer_.setInterval(IntervalMsec); | |
104 | + connect(&update_timer_, SIGNAL(timeout()), widget_, SLOT(updateTimeout())); | |
105 | + update_timer_.start(); | |
222 | 106 | } |
223 | - previous_battery_state_ = battery_state_; | |
224 | - previous_percent_ = percent_; | |
225 | - | |
226 | - if (hide_checked_ && (battery_state_ == Charging)) { | |
227 | - // 充電中に描画しないよう指定されているときは隠す | |
228 | - widget_->hide(); | |
229 | - if (is_tray_available_) { | |
230 | - tray_icon_.show(); | |
231 | - } | |
232 | - } else { | |
233 | - if ((! repainted) && widget_->isHidden()) { | |
234 | - widget_->show(); | |
235 | - if (is_tray_available_) { | |
236 | - tray_icon_.hide(); | |
237 | - } | |
238 | - } | |
239 | - } | |
240 | - } | |
241 | 107 | |
242 | 108 | |
243 | - // マスコットの再描画 | |
244 | - void repaint(void) | |
245 | - { | |
246 | - // 再描画 | |
247 | - QPainter painter(widget_); | |
248 | - QRect base_rect; | |
249 | - QRegion region; | |
250 | - if (draw_character_.draw(painter, base_rect, region, | |
251 | - characters_[character_index_], | |
252 | - battery_state_, percent_)) { | |
253 | - widget_->resize(base_rect.width(), base_rect.height()); | |
254 | - if (is_masked_) { | |
255 | - widget_->clearMask(); | |
256 | - } | |
257 | - widget_->setMask(region); | |
258 | - is_masked_ = true; | |
109 | + void initializeCharacters(void) | |
110 | + { | |
111 | + // 女の子 | |
112 | + character_t girl; | |
113 | + girl.name = tr("girl"); | |
114 | + girl.picture_unknown = ":picture/girl_unknown"; | |
115 | + girl.picture_charging = ":picture/girl_charging"; | |
116 | + girl.picture_discharging = ":picture/girl_discharging"; | |
117 | + girl.percent_bar = ":picture/percent_bar"; | |
118 | + girl.bar_position = QPoint(4, 43); | |
119 | + characters_.push_back(girl); | |
120 | + | |
121 | + // りもペンギン | |
122 | + character_t penguin; | |
123 | + penguin.name = tr("pengui"); | |
124 | + penguin.picture_unknown = ":picture/penguin_unknown"; | |
125 | + penguin.picture_charging = ":picture/penguin_charging"; | |
126 | + penguin.picture_discharging = ":picture/penguin_discharging"; | |
127 | + penguin.percent_bar = ":picture/percent_bar"; | |
128 | + penguin.bar_position = QPoint(5, 44); | |
129 | + characters_.push_back(penguin); | |
259 | 130 | } |
260 | - } | |
261 | - | |
262 | - | |
263 | - double remainingTime(size_t total_second) | |
264 | - { | |
265 | - return total_second / (60.0 * 60.0); | |
266 | - } | |
267 | 131 | |
268 | 132 | |
269 | - QString updateMessage(void) | |
270 | - { | |
271 | - double remaining_time = remainingTime(battery_.remainingSecond()); | |
272 | - if (remaining_time > 1.0) { | |
273 | - remaining_time = floor(remaining_time); | |
133 | + void initializeMenu(void) | |
134 | + { | |
135 | + // キャラクタ選択メニューの作成 | |
136 | + size_t n = characters_.size(); | |
137 | + for (size_t i = 0; i < n; ++i) { | |
138 | + QAction* action = new QAction(characters_[i].name, widget_); | |
139 | + action->setCheckable(true); | |
140 | + widget_->addAction(action); | |
141 | + skin_actions_.push_back(action); | |
142 | + } | |
143 | + connect(skin_actions_[0], SIGNAL(triggered()), | |
144 | + widget_, SLOT(girlSkinSelected())); | |
145 | + connect(skin_actions_[1], SIGNAL(triggered()), | |
146 | + widget_, SLOT(limoSkinSelected())); | |
147 | + setSkin(character_index_); | |
148 | + | |
149 | + widget_->addAction(newSeparator()); | |
150 | + | |
151 | + // 常に表示させるためのチェックボックス | |
152 | + show_always_action_->setCheckable(true); | |
153 | + show_always_action_->setChecked(show_always_checked_); | |
154 | + widget_->addAction(show_always_action_); | |
155 | + | |
156 | + // 充電中に非表示にするかのチェックボックス | |
157 | + hide_charging_action_->setCheckable(true); | |
158 | + hide_charging_action_->setChecked(hide_charging_checked_); | |
159 | + widget_->addAction(hide_charging_action_); | |
160 | + | |
161 | + // 充電されるまで表示するかのチェックボックス | |
162 | + hide_charged_action_->setCheckable(true); | |
163 | + hide_charged_action_->setChecked(hide_charged_checked_); | |
164 | + widget_->addAction(hide_charged_action_); | |
165 | + | |
166 | + widget_->addAction(newSeparator()); | |
167 | + | |
168 | + // 終了 | |
169 | + QAction* quit_action = new QAction(QAction::tr("Quit"), widget_); | |
170 | + quit_action->setShortcut(tr("Ctrl+Q")); | |
171 | + connect(quit_action, SIGNAL(triggered()), qApp, SLOT(quit())); | |
172 | + widget_->addAction(quit_action); | |
173 | + | |
174 | + widget_->setContextMenuPolicy(Qt::ActionsContextMenu); | |
274 | 175 | } |
275 | 176 | |
276 | - switch (battery_state_) { | |
277 | - case Charging: | |
278 | - return QString(tr("charging: %1 [%]")).arg(percent_); | |
279 | - break; | |
280 | 177 | |
281 | - case Discharging: | |
282 | - if (remaining_time == 0.0) { | |
283 | - return QString(tr("remaining: %1 [%]")).arg(percent_); | |
284 | - } else { | |
285 | - return QString(tr("remaining: %1 [h] (%2 [%])")).arg(remaining_time, 0, 'g', 1).arg(percent_); | |
286 | - } | |
287 | - break; | |
178 | + void initializeSystemTray(void) | |
179 | + { | |
180 | + // システムトレイにアイコンを配置 | |
181 | + tray_icon_.setIcon(widget_->windowIcon()); | |
182 | + tray_icon_.setToolTip(tr("APM Battery Monitor")); | |
288 | 183 | |
289 | - default: | |
290 | - case Unknown: | |
291 | - return QString(tr("unknown system")); | |
292 | - break; | |
184 | + QMenu* menu = new QMenu(widget_); | |
185 | + QList<QAction*> actions = widget_->actions(); | |
186 | + for (int i = 0; i < actions.size(); ++i) { | |
187 | + menu->addAction(actions.at(i)); | |
188 | + } | |
189 | + tray_icon_.setContextMenu(menu); | |
190 | + tray_icon_.hide(); | |
293 | 191 | } |
294 | - } | |
295 | 192 | |
296 | 193 | |
297 | - void setSkin(size_t index) | |
298 | - { | |
299 | - character_index_ = index; | |
194 | + QAction* newSeparator(void) | |
195 | + { | |
196 | + QAction* separator = new QAction(widget_); | |
197 | + separator->setSeparator(true); | |
198 | + return separator; | |
199 | + } | |
300 | 200 | |
301 | - size_t n = skin_actions_.size(); | |
302 | - for (size_t i = 0; i < n; ++i) { | |
303 | - bool checked = (i == index) ? true : false; | |
304 | - skin_actions_[i]->setChecked(checked); | |
201 | + | |
202 | + void loadSettings(bool restore_geometry) | |
203 | + { | |
204 | + QSettings settings(Organization, Application); | |
205 | + | |
206 | + character_index_ = settings.value("character_index", 0).toInt(); | |
207 | + show_always_checked_ = | |
208 | + settings.value("show_always_checked", false).toBool(); | |
209 | + if (show_always_checked_) { | |
210 | + show_always_action_->setChecked(true); | |
211 | + } | |
212 | + | |
213 | + hide_charging_checked_ = | |
214 | + settings.value("hide_charging_checked", false).toBool(); | |
215 | + if (hide_charging_checked_) { | |
216 | + hide_charging_action_->setChecked(true); | |
217 | + } | |
218 | + | |
219 | + hide_charged_checked_ = | |
220 | + settings.value("hide_charged_checked", false).toBool(); | |
221 | + if (hide_charged_checked_) { | |
222 | + hide_charged_action_->setChecked(true); | |
223 | + } | |
224 | + | |
225 | + if (restore_geometry) { | |
226 | + widget_->restoreGeometry(settings.value("geometry").toByteArray()); | |
227 | + } | |
305 | 228 | } |
306 | - } | |
229 | + | |
230 | + | |
231 | + void saveSettings(void) | |
232 | + { | |
233 | + QSettings settings(Organization, Application); | |
234 | + | |
235 | + settings.setValue("geometry", widget_->saveGeometry()); | |
236 | + settings.setValue("character_index", character_index_); | |
237 | + settings.setValue("show_always_checked", | |
238 | + show_always_action_->isChecked()); | |
239 | + settings.setValue("hide_charging_checked", | |
240 | + hide_charging_action_->isChecked()); | |
241 | + settings.setValue("hide_charged_checked", | |
242 | + hide_charged_action_->isChecked()); | |
243 | + } | |
244 | + | |
245 | + | |
246 | + ChargingState batteryState(void) | |
247 | + { | |
248 | + if (!battery_.isAvailable()) { | |
249 | + return Unknown; | |
250 | + } | |
251 | + if (battery_.isCharged()) { | |
252 | + return Charged; | |
253 | + } | |
254 | + return (battery_.isCharging() ? Charging : Discharging); | |
255 | + } | |
256 | + | |
257 | + | |
258 | + void update(void) | |
259 | + { | |
260 | + // 描画する状態の取得 | |
261 | + battery_state_ = batteryState(); | |
262 | + percent_ = battery_.remainingPercent(); | |
263 | + | |
264 | + // フォーカス時に表示する情報の更新 | |
265 | + QString message = updateMessage(); | |
266 | + widget_->setToolTip(message); | |
267 | + | |
268 | + bool repainted = false; | |
269 | + if ((battery_state_ != previous_battery_state_) || | |
270 | + percent_ != previous_percent_) { | |
271 | + repainted = true; | |
272 | + widget_->repaint(); | |
273 | + } | |
274 | + previous_battery_state_ = battery_state_; | |
275 | + previous_percent_ = percent_; | |
276 | + | |
277 | + if (hide_charging_checked_ && | |
278 | + ((battery_state_ == Charging) || (battery_state_ == Charged))) { | |
279 | + // 充電中に描画しないよう指定されているときは隠す | |
280 | + hideCharacter(); | |
281 | + | |
282 | + } else if (hide_charged_checked_ && (battery_state_ == Charged)) { | |
283 | + // 充電済みで描画しないよう指定されているときは隠す | |
284 | + hideCharacter(); | |
285 | + | |
286 | + } else { | |
287 | + if ((!repainted) && widget_->isHidden()) { | |
288 | + widget_->show(); | |
289 | + if (is_tray_available_) { | |
290 | + tray_icon_.hide(); | |
291 | + } | |
292 | + } | |
293 | + } | |
294 | + } | |
295 | + | |
296 | + | |
297 | + void hideCharacter(void) | |
298 | + { | |
299 | + widget_->hide(); | |
300 | + if (is_tray_available_) { | |
301 | + tray_icon_.show(); | |
302 | + } | |
303 | + } | |
304 | + | |
305 | + | |
306 | + // マスコットの再描画 | |
307 | + void repaint(void) | |
308 | + { | |
309 | + // 再描画 | |
310 | + QPainter painter(widget_); | |
311 | + QRect base_rect; | |
312 | + QRegion region; | |
313 | + if (draw_character_.draw(painter, base_rect, region, | |
314 | + characters_[character_index_], | |
315 | + battery_state_, percent_)) { | |
316 | + widget_->resize(base_rect.width(), base_rect.height()); | |
317 | + if (is_masked_) { | |
318 | + widget_->clearMask(); | |
319 | + } | |
320 | + widget_->setMask(region); | |
321 | + is_masked_ = true; | |
322 | + } | |
323 | + } | |
324 | + | |
325 | + | |
326 | + double remainingTime(size_t total_second) | |
327 | + { | |
328 | + return total_second / (60.0 * 60.0); | |
329 | + } | |
330 | + | |
331 | + | |
332 | + QString updateMessage(void) | |
333 | + { | |
334 | + double remaining_time = remainingTime(battery_.remainingSecond()); | |
335 | + if (remaining_time > 1.0) { | |
336 | + remaining_time = floor(remaining_time); | |
337 | + } | |
338 | + | |
339 | + switch (battery_state_) { | |
340 | + case Charging: | |
341 | + return QString(tr("charging: %1 [%]")).arg(percent_); | |
342 | + break; | |
343 | + | |
344 | + case Charged: | |
345 | + return QString(tr("charged")); | |
346 | + break; | |
347 | + | |
348 | + case Discharging: | |
349 | + if (remaining_time == 0.0) { | |
350 | + return QString(tr("remaining: %1 [%]")).arg(percent_); | |
351 | + } else { | |
352 | + return QString(tr("remaining: %1 [h] (%2 [%])")). | |
353 | + arg(remaining_time, 0, 'g', 1).arg(percent_); | |
354 | + } | |
355 | + break; | |
356 | + | |
357 | + default: | |
358 | + case Unknown: | |
359 | + return QString(tr("unknown system")); | |
360 | + break; | |
361 | + } | |
362 | + } | |
363 | + | |
364 | + | |
365 | + void setSkin(size_t index) | |
366 | + { | |
367 | + character_index_ = index; | |
368 | + | |
369 | + size_t n = skin_actions_.size(); | |
370 | + for (size_t i = 0; i < n; ++i) { | |
371 | + bool checked = (i == index) ? true : false; | |
372 | + skin_actions_[i]->setChecked(checked); | |
373 | + } | |
374 | + } | |
375 | + | |
376 | + | |
377 | + void clearChecked(void) | |
378 | + { | |
379 | + show_always_action_->setChecked(false); | |
380 | + hide_charging_action_->setChecked(false); | |
381 | + hide_charged_action_->setChecked(false); | |
382 | + | |
383 | + hide_charged_checked_ = false; | |
384 | + show_always_checked_ = false; | |
385 | + hide_charging_checked_ = false; | |
386 | + } | |
307 | 387 | }; |
308 | 388 | |
309 | 389 | |
310 | 390 | BatmonWidget::BatmonWidget(bool geometry_specified, QWidget* widget) |
311 | - : QWidget(widget), pimpl(new pImpl(this)) | |
391 | + : QWidget(widget), pimpl(new pImpl(this)) | |
312 | 392 | { |
313 | - pimpl->initialize(); | |
314 | - pimpl->loadSettings(! geometry_specified); | |
315 | - pimpl->initializeCharacters(); | |
316 | - pimpl->initializeMenu(); | |
317 | - if (pimpl->is_tray_available_) { | |
318 | - // システムトレイが利用可能ならば登録 | |
319 | - pimpl->initializeSystemTray(); | |
320 | - } | |
393 | + pimpl->initialize(); | |
394 | + pimpl->loadSettings(!geometry_specified); | |
395 | + pimpl->initializeCharacters(); | |
396 | + pimpl->initializeMenu(); | |
397 | + if (pimpl->is_tray_available_) { | |
398 | + // システムトレイが利用可能ならば登録 | |
399 | + pimpl->initializeSystemTray(); | |
400 | + } | |
321 | 401 | |
322 | - if (geometry_specified) { | |
323 | - // 位置がコマンドラインで指定され直したため、それを保存する | |
324 | - pimpl->saveSettings(); | |
325 | - } | |
402 | + if (geometry_specified) { | |
403 | + // 位置がコマンドラインで指定され直したため、それを保存する | |
404 | + pimpl->saveSettings(); | |
405 | + } | |
326 | 406 | } |
327 | 407 | |
328 | 408 | |
329 | 409 | BatmonWidget::~BatmonWidget(void) |
330 | 410 | { |
331 | - pimpl->saveSettings(); | |
411 | + pimpl->saveSettings(); | |
332 | 412 | } |
333 | 413 | |
334 | 414 | |
335 | 415 | void BatmonWidget::paintEvent(QPaintEvent* event) |
336 | 416 | { |
337 | - static_cast<void>(event); | |
417 | + static_cast<void>(event); | |
338 | 418 | |
339 | - pimpl->repaint(); | |
419 | + pimpl->repaint(); | |
340 | 420 | } |
341 | 421 | |
342 | 422 | |
343 | 423 | void BatmonWidget::updateTimeout(void) |
344 | 424 | { |
345 | - pimpl->update(); | |
425 | + pimpl->update(); | |
346 | 426 | } |
347 | 427 | |
348 | 428 | |
349 | 429 | // 左クリックでのフォーム移動 |
350 | 430 | void BatmonWidget::mousePressEvent(QMouseEvent* event) |
351 | 431 | { |
352 | - if (event->button() == Qt::LeftButton) { | |
353 | - pimpl->drag_position_ = event->globalPos() - frameGeometry().topLeft(); | |
354 | - event->accept(); | |
355 | - } | |
432 | + if (event->button() == Qt::LeftButton) { | |
433 | + pimpl->drag_position_ = event->globalPos() - frameGeometry().topLeft(); | |
434 | + event->accept(); | |
435 | + } | |
356 | 436 | } |
357 | 437 | |
358 | 438 | |
359 | 439 | // 左クリックでのフォーム移動 |
360 | 440 | void BatmonWidget::mouseMoveEvent(QMouseEvent* event) |
361 | 441 | { |
362 | - if (event->buttons() & Qt::LeftButton) { | |
363 | - move(event->globalPos() - pimpl->drag_position_); | |
364 | - pimpl->saveSettings(); | |
365 | - event->accept(); | |
366 | - } | |
442 | + if (event->buttons() & Qt::LeftButton) { | |
443 | + move(event->globalPos() - pimpl->drag_position_); | |
444 | + pimpl->saveSettings(); | |
445 | + event->accept(); | |
446 | + } | |
367 | 447 | } |
368 | 448 | |
369 | 449 | |
370 | -void BatmonWidget::hideSpecified(void) | |
450 | +void BatmonWidget::showAlwaysSpecified(void) | |
371 | 451 | { |
372 | - bool check = pimpl->hide_action_->isChecked(); | |
373 | - pimpl->hide_action_->setChecked(check); | |
452 | + pimpl->clearChecked(); | |
374 | 453 | |
375 | - pimpl->hide_checked_ = check; | |
376 | - pimpl->saveSettings(); | |
454 | + pimpl->show_always_action_->setChecked(true); | |
455 | + pimpl->show_always_checked_ = true; | |
456 | + | |
457 | + pimpl->saveSettings(); | |
458 | +} | |
459 | + | |
460 | + | |
461 | +void BatmonWidget::hideChargingSpecified(void) | |
462 | +{ | |
463 | + pimpl->clearChecked(); | |
464 | + | |
465 | + pimpl->hide_charging_action_->setChecked(true); | |
466 | + pimpl->hide_charging_checked_ = true; | |
467 | + | |
468 | + pimpl->saveSettings(); | |
469 | +} | |
470 | + | |
471 | + | |
472 | +void BatmonWidget::hideChargedSpecified(void) | |
473 | +{ | |
474 | + pimpl->clearChecked(); | |
475 | + | |
476 | + pimpl->hide_charged_action_->setChecked(true); | |
477 | + pimpl->hide_charged_checked_ = true; | |
478 | + | |
479 | + pimpl->saveSettings(); | |
377 | 480 | } |
378 | 481 | |
379 | 482 | |
380 | 483 | void BatmonWidget::girlSkinSelected(void) |
381 | 484 | { |
382 | - pimpl->setSkin(0); | |
383 | - update(); | |
384 | - repaint(); | |
385 | - pimpl->saveSettings(); | |
485 | + pimpl->setSkin(0); | |
486 | + update(); | |
487 | + repaint(); | |
488 | + pimpl->saveSettings(); | |
386 | 489 | } |
387 | 490 | |
388 | 491 | |
389 | 492 | void BatmonWidget::limoSkinSelected(void) |
390 | 493 | { |
391 | - pimpl->setSkin(1); | |
392 | - update(); | |
393 | - repaint(); | |
394 | - pimpl->saveSettings(); | |
494 | + pimpl->setSkin(1); | |
495 | + update(); | |
496 | + repaint(); | |
497 | + pimpl->saveSettings(); | |
395 | 498 | } |
@@ -18,29 +18,31 @@ | ||
18 | 18 | //! バッテリーモニター Widget |
19 | 19 | class BatmonWidget : public QWidget |
20 | 20 | { |
21 | - Q_OBJECT; | |
21 | + Q_OBJECT; | |
22 | 22 | |
23 | 23 | public: |
24 | - //! コンストラクタ | |
25 | - explicit BatmonWidget(bool geometry_specified, QWidget* widget = NULL); | |
26 | - ~BatmonWidget(void); | |
24 | + //! コンストラクタ | |
25 | + explicit BatmonWidget(bool geometry_specified, QWidget* widget = NULL); | |
26 | + ~BatmonWidget(void); | |
27 | 27 | |
28 | 28 | private slots: |
29 | - void paintEvent(QPaintEvent* event); | |
30 | - void updateTimeout(void); | |
31 | - void hideSpecified(void); | |
32 | - void girlSkinSelected(void); | |
33 | - void limoSkinSelected(void); | |
29 | + void paintEvent(QPaintEvent* event); | |
30 | + void updateTimeout(void); | |
31 | + void showAlwaysSpecified(void); | |
32 | + void hideChargingSpecified(void); | |
33 | + void hideChargedSpecified(void); | |
34 | + void girlSkinSelected(void); | |
35 | + void limoSkinSelected(void); | |
34 | 36 | |
35 | 37 | private: |
36 | - void mousePressEvent(QMouseEvent* event); | |
37 | - void mouseMoveEvent(QMouseEvent* event); | |
38 | + void mousePressEvent(QMouseEvent* event); | |
39 | + void mouseMoveEvent(QMouseEvent* event); | |
38 | 40 | |
39 | - BatmonWidget(const BatmonWidget& rhs); | |
40 | - BatmonWidget& operator = (const BatmonWidget& rhs); | |
41 | + BatmonWidget(const BatmonWidget& rhs); | |
42 | + BatmonWidget& operator = (const BatmonWidget& rhs); | |
41 | 43 | |
42 | - struct pImpl; | |
43 | - std::auto_ptr<pImpl> pimpl; | |
44 | + struct pImpl; | |
45 | + std::auto_ptr<pImpl> pimpl; | |
44 | 46 | }; |
45 | 47 | |
46 | 48 | #endif /* !BATMON_WIDGET_H */ |
@@ -25,197 +25,221 @@ | ||
25 | 25 | #if defined(WINDOWS_OS) |
26 | 26 | struct BatteryState::pImpl |
27 | 27 | { |
28 | - bool isAvailable(void) | |
29 | - { | |
30 | - SYSTEM_POWER_STATUS status; | |
31 | - if (! GetSystemPowerStatus(&status)) { | |
32 | - return false; | |
28 | + bool isAvailable(void) | |
29 | + { | |
30 | + SYSTEM_POWER_STATUS status; | |
31 | + if (!GetSystemPowerStatus(&status)) { | |
32 | + return false; | |
33 | + } | |
34 | + return (status.BatteryLifePercent == 255) ? false : true; | |
33 | 35 | } |
34 | - return (status.BatteryLifePercent == 255) ? false : true; | |
35 | - } | |
36 | 36 | |
37 | 37 | |
38 | - bool isCharging(void) | |
39 | - { | |
40 | - SYSTEM_POWER_STATUS status; | |
41 | - if (! GetSystemPowerStatus(&status)) { | |
42 | - return false; | |
38 | + bool isCharging(void) | |
39 | + { | |
40 | + SYSTEM_POWER_STATUS status; | |
41 | + if (!GetSystemPowerStatus(&status)) { | |
42 | + return false; | |
43 | + } | |
44 | + return (static_cast<int>(status.ACLineStatus) == 1) ? true : false; | |
43 | 45 | } |
44 | - return (static_cast<int>(status.ACLineStatus) == 1) ? true : false; | |
45 | - } | |
46 | 46 | |
47 | 47 | |
48 | - size_t remainingPercent(void) | |
49 | - { | |
50 | - SYSTEM_POWER_STATUS status; | |
51 | - if (! GetSystemPowerStatus(&status)) { | |
52 | - return 0; | |
48 | + bool isCharged(void) const | |
49 | + { | |
50 | + return !isCharging(); | |
53 | 51 | } |
54 | - return status.BatteryLifePercent; | |
55 | - } | |
56 | 52 | |
57 | 53 | |
58 | - size_t remainingSecond(void) | |
59 | - { | |
60 | - SYSTEM_POWER_STATUS status; | |
61 | - if (! GetSystemPowerStatus(&status)) { | |
62 | - return 0; | |
54 | + size_t remainingPercent(void) | |
55 | + { | |
56 | + SYSTEM_POWER_STATUS status; | |
57 | + if (!GetSystemPowerStatus(&status)) { | |
58 | + return 0; | |
59 | + } | |
60 | + return status.BatteryLifePercent; | |
63 | 61 | } |
64 | - return max(0, static_cast<int>(status.BatteryLifeTime)); | |
65 | - } | |
62 | + | |
63 | + | |
64 | + size_t remainingSecond(void) | |
65 | + { | |
66 | + SYSTEM_POWER_STATUS status; | |
67 | + if (!GetSystemPowerStatus(&status)) { | |
68 | + return 0; | |
69 | + } | |
70 | + return max(0, static_cast<int>(status.BatteryLifeTime)); | |
71 | + } | |
66 | 72 | }; |
67 | 73 | #else |
68 | 74 | |
69 | 75 | struct BatteryState::pImpl |
70 | 76 | { |
71 | - bool is_available_; | |
72 | - size_t full_capacity_; | |
73 | - string state_file_; | |
74 | - string info_file_; | |
75 | - | |
76 | - | |
77 | - pImpl(void) : is_available_(false), full_capacity_(1) | |
78 | - { | |
79 | - // BAT0, BAT1 を順番に試す | |
80 | - for (size_t id = 0; id < 2; ++id) { | |
81 | - char buffer[] = "BAT0"; | |
82 | - snprintf(buffer, sizeof(buffer), "BAT%d", id); | |
83 | - | |
84 | - state_file_ = "/proc/acpi/battery/" + string(buffer) + "/state"; | |
85 | - info_file_ = "/proc/acpi/battery/" + string(buffer) + "/info"; | |
86 | - | |
87 | - if (loadFullCapacity()) { | |
88 | - break; | |
89 | - } | |
90 | - } | |
91 | - } | |
77 | + bool is_available_; | |
78 | + size_t full_capacity_; | |
79 | + string state_file_; | |
80 | + string info_file_; | |
92 | 81 | |
93 | 82 | |
94 | - bool matchData(string& value, const char* file, const char* pattern) const | |
95 | - { | |
96 | - ifstream fin(file); | |
97 | - if (! fin.is_open()) { | |
98 | - return false; | |
99 | - } | |
83 | + pImpl(void) : is_available_(false), full_capacity_(1) | |
84 | + { | |
85 | + // BAT0, BAT1 を順番に試す | |
86 | + for (size_t id = 0; id < 2; ++id) { | |
87 | + char buffer[] = "BAT0"; | |
88 | + snprintf(buffer, sizeof(buffer), "BAT%d", id); | |
100 | 89 | |
101 | - // トークンの区切りを ':' とし、得られた結果からは空白を除去して返す | |
102 | - string line; | |
103 | - while (getline(fin, line)) { | |
104 | - vector<string> tokens; | |
105 | - if (split(tokens, line, ":") >= 2) { | |
106 | - if (! tokens[0].compare(pattern)) { | |
107 | - string& token = tokens[1]; | |
108 | - size_t first_index = 0; | |
109 | - while (token[first_index] == ' ') { | |
110 | - ++first_index; | |
111 | - } | |
112 | - value = &token[first_index]; | |
113 | - return true; | |
90 | + state_file_ = "/proc/acpi/battery/" + string(buffer) + "/state"; | |
91 | + info_file_ = "/proc/acpi/battery/" + string(buffer) + "/info"; | |
92 | + | |
93 | + if (loadFullCapacity()) { | |
94 | + break; | |
95 | + } | |
114 | 96 | } |
115 | - } | |
116 | - } | |
117 | - return false; | |
118 | - } | |
119 | - | |
120 | - | |
121 | - bool matchData(size_t& value, const char* file, const char* pattern) const | |
122 | - { | |
123 | - string string_value; | |
124 | - if (! matchData(string_value, file, pattern)) { | |
125 | - return false; | |
126 | - } | |
127 | - | |
128 | - value = atoi(string_value.c_str()); | |
129 | - return true; | |
130 | - } | |
131 | - | |
132 | - | |
133 | - bool loadFullCapacity(void) | |
134 | - { | |
135 | - // /proc/acpi/battery/BATx/info ファイルの "last full capacity" を読み出す | |
136 | - if ((matchData(full_capacity_, info_file_.c_str(), "last full capacity")) && | |
137 | - (full_capacity_ > 0)) { | |
138 | - is_available_ = true; | |
139 | - return true; | |
140 | 97 | } |
141 | 98 | |
142 | - return false; | |
143 | - } | |
144 | - | |
145 | - | |
146 | - bool isAvailable(void) const | |
147 | - { | |
148 | - return is_available_; | |
149 | - } | |
150 | - | |
151 | - | |
152 | - bool isCharging(void) const | |
153 | - { | |
154 | - if (! is_available_) { | |
155 | - return false; | |
156 | - } | |
157 | 99 | |
158 | - // 電源が接続されていないときに false を返す | |
159 | - // /proc/acpi/battery/BATx/state ファイルの "charging state" を読み出す | |
160 | - string state; | |
161 | - if (matchData(state, state_file_.c_str(), "charging state") && | |
162 | - ((! state.compare("charged")) || (! state.compare("charging")))) { | |
163 | - return true; | |
164 | - } | |
100 | + bool matchData(string& value, const char* file, const char* pattern) const | |
101 | + { | |
102 | + ifstream fin(file); | |
103 | + if (!fin.is_open()) { | |
104 | + return false; | |
105 | + } | |
165 | 106 | |
166 | - return false; | |
167 | - } | |
168 | - | |
169 | - | |
170 | - size_t remainingPercent(void) const | |
171 | - { | |
172 | - if (! is_available_) { | |
173 | - return 0; | |
107 | + // トークンの区切りを ':' とし、得られた結果からは空白を除去して返す | |
108 | + string line; | |
109 | + while (getline(fin, line)) { | |
110 | + vector<string> tokens; | |
111 | + if (split(tokens, line, ":") >= 2) { | |
112 | + if (!tokens[0].compare(pattern)) { | |
113 | + string& token = tokens[1]; | |
114 | + size_t first_index = 0; | |
115 | + while (token[first_index] == ' ') { | |
116 | + ++first_index; | |
117 | + } | |
118 | + value = &token[first_index]; | |
119 | + return true; | |
120 | + } | |
121 | + } | |
122 | + } | |
123 | + return false; | |
174 | 124 | } |
175 | 125 | |
176 | - // "/proc/acpi/battery/BATx/state" ファイルの | |
177 | - // "remaining capacity" を読み出し full_capacity_ から残量を計算する | |
178 | - size_t remaining_capacity = 0; | |
179 | - if (! matchData(remaining_capacity, | |
180 | - state_file_.c_str(), "remaining capacity")) { | |
181 | - return 0; | |
182 | - } | |
183 | 126 | |
184 | - size_t percent = | |
185 | - min(static_cast<size_t>(100), 100 * remaining_capacity / full_capacity_); | |
127 | + bool matchData(size_t& value, const char* file, const char* pattern) const | |
128 | + { | |
129 | + string string_value; | |
130 | + if (!matchData(string_value, file, pattern)) { | |
131 | + return false; | |
132 | + } | |
186 | 133 | |
187 | - return percent; | |
188 | - } | |
189 | - | |
190 | - | |
191 | - size_t remainingSecond(void) const | |
192 | - { | |
193 | - if (! is_available_) { | |
194 | - return 0; | |
134 | + value = atoi(string_value.c_str()); | |
135 | + return true; | |
195 | 136 | } |
196 | 137 | |
197 | - if (isCharging()) { | |
198 | - return 0; | |
138 | + | |
139 | + bool loadFullCapacity(void) | |
140 | + { | |
141 | + // /proc/acpi/battery/BATx/info ファイルの "last full capacity" を読み出す | |
142 | + if ((matchData(full_capacity_, info_file_.c_str(), "last full capacity")) && | |
143 | + (full_capacity_ > 0)) { | |
144 | + is_available_ = true; | |
145 | + return true; | |
146 | + } | |
147 | + | |
148 | + return false; | |
199 | 149 | } |
200 | 150 | |
201 | - // "/proc/acpi/battery/BATx/state" ファイルの | |
202 | - // "present rate" [mW] と "remaining capacity" [mWh] を読み出し、 | |
203 | - // バッテリーが使える時間を計算する | |
204 | - size_t present_rate = 0; | |
205 | - if (! matchData(present_rate, state_file_.c_str(), "present rate")) { | |
206 | - return 0; | |
151 | + | |
152 | + bool isAvailable(void) const | |
153 | + { | |
154 | + return is_available_; | |
207 | 155 | } |
208 | 156 | |
209 | - size_t remaining_capacity = 0; | |
210 | - if (! matchData(remaining_capacity, | |
211 | - state_file_.c_str(), "remaining capacity")) { | |
212 | - return 0; | |
157 | + | |
158 | + bool isCharging(void) const | |
159 | + { | |
160 | + if (!is_available_) { | |
161 | + return false; | |
162 | + } | |
163 | + | |
164 | + // 電源が接続されていないときに false を返す | |
165 | + // /proc/acpi/battery/BATx/state ファイルの "charging state" を読み出す | |
166 | + string state; | |
167 | + if (matchData(state, state_file_.c_str(), "charging state") && | |
168 | + ((!state.compare("charged")) || (!state.compare("charging")))) { | |
169 | + return true; | |
170 | + } | |
171 | + | |
172 | + return false; | |
213 | 173 | } |
214 | 174 | |
215 | - size_t second = 60 * 60 * remaining_capacity / max(present_rate, | |
216 | - static_cast<size_t>(1)); | |
217 | - return second; | |
218 | - } | |
175 | + | |
176 | + bool isCharged(void) const | |
177 | + { | |
178 | + if (!is_available_) { | |
179 | + return false; | |
180 | + } | |
181 | + | |
182 | + // 電源が接続されていないときに false を返す | |
183 | + // /proc/acpi/battery/BATx/state ファイルの "charging state" を読み出す | |
184 | + string state; | |
185 | + if (matchData(state, state_file_.c_str(), "charging state") && | |
186 | + (!state.compare("charged"))) { | |
187 | + return true; | |
188 | + } | |
189 | + | |
190 | + return false; | |
191 | + } | |
192 | + | |
193 | + | |
194 | + size_t remainingPercent(void) const | |
195 | + { | |
196 | + if (!is_available_) { | |
197 | + return 0; | |
198 | + } | |
199 | + | |
200 | + // "/proc/acpi/battery/BATx/state" ファイルの | |
201 | + // "remaining capacity" を読み出し full_capacity_ から残量を計算する | |
202 | + size_t remaining_capacity = 0; | |
203 | + if (!matchData(remaining_capacity, | |
204 | + state_file_.c_str(), "remaining capacity")) { | |
205 | + return 0; | |
206 | + } | |
207 | + | |
208 | + size_t percent = | |
209 | + min(static_cast<size_t>(100), 100 * remaining_capacity / full_capacity_); | |
210 | + | |
211 | + return percent; | |
212 | + } | |
213 | + | |
214 | + | |
215 | + size_t remainingSecond(void) const | |
216 | + { | |
217 | + if (!is_available_) { | |
218 | + return 0; | |
219 | + } | |
220 | + | |
221 | + if (isCharging()) { | |
222 | + return 0; | |
223 | + } | |
224 | + | |
225 | + // "/proc/acpi/battery/BATx/state" ファイルの | |
226 | + // "present rate" [mW] と "remaining capacity" [mWh] を読み出し、 | |
227 | + // バッテリーが使える時間を計算する | |
228 | + size_t present_rate = 0; | |
229 | + if (!matchData(present_rate, state_file_.c_str(), "present rate")) { | |
230 | + return 0; | |
231 | + } | |
232 | + | |
233 | + size_t remaining_capacity = 0; | |
234 | + if (!matchData(remaining_capacity, | |
235 | + state_file_.c_str(), "remaining capacity")) { | |
236 | + return 0; | |
237 | + } | |
238 | + | |
239 | + size_t second = 60 * 60 * remaining_capacity / max(present_rate, | |
240 | + static_cast<size_t>(1)); | |
241 | + return second; | |
242 | + } | |
219 | 243 | }; |
220 | 244 | #endif |
221 | 245 |
@@ -232,23 +256,29 @@ | ||
232 | 256 | |
233 | 257 | bool BatteryState::isAvailable(void) const |
234 | 258 | { |
235 | - return pimpl->isAvailable(); | |
259 | + return pimpl->isAvailable(); | |
236 | 260 | } |
237 | 261 | |
238 | 262 | |
239 | 263 | bool BatteryState::isCharging(void) const |
240 | 264 | { |
241 | - return pimpl->isCharging(); | |
265 | + return pimpl->isCharging(); | |
266 | +} | |
267 | + | |
268 | + | |
269 | +bool BatteryState::isCharged(void) const | |
270 | +{ | |
271 | + return pimpl->isCharged(); | |
242 | 272 | } |
243 | 273 | |
244 | 274 | |
245 | 275 | size_t BatteryState::remainingPercent(void) const |
246 | 276 | { |
247 | - return pimpl->remainingPercent(); | |
277 | + return pimpl->remainingPercent(); | |
248 | 278 | } |
249 | 279 | |
250 | 280 | |
251 | 281 | size_t BatteryState::remainingSecond(void) const |
252 | 282 | { |
253 | - return pimpl->remainingSecond(); | |
283 | + return pimpl->remainingSecond(); | |
254 | 284 | } |
@@ -15,54 +15,63 @@ | ||
15 | 15 | |
16 | 16 | namespace qrk |
17 | 17 | { |
18 | - //! PC バッテリー状態の取得 | |
19 | - class BatteryState | |
20 | - { | |
21 | - public: | |
22 | - BatteryState(void); | |
23 | - ~BatteryState(void); | |
24 | - | |
25 | - | |
26 | - /*! | |
27 | - \brief バッテリー状態が取得可能か | |
28 | - | |
29 | - \retval true 取得可能 | |
30 | - \retval false システムからバッテリー状態を取得できない | |
31 | - */ | |
32 | - bool isAvailable(void) const; | |
18 | + //! PC バッテリー状態の取得 | |
19 | + class BatteryState | |
20 | + { | |
21 | + public: | |
22 | + BatteryState(void); | |
23 | + ~BatteryState(void); | |
33 | 24 | |
34 | 25 | |
35 | - /*! | |
36 | - \brief 充電中か | |
26 | + /*! | |
27 | + \brief バッテリー状態が取得可能か | |
37 | 28 | |
38 | - \retval true 充電中 | |
39 | - \retval false 放電中 | |
40 | - */ | |
41 | - bool isCharging(void) const; | |
29 | + \retval true 取得可能 | |
30 | + \retval false システムからバッテリー状態を取得できない | |
31 | + */ | |
32 | + bool isAvailable(void) const; | |
42 | 33 | |
43 | 34 | |
44 | - /*! | |
45 | - \brief バッテリー充電率 | |
35 | + /*! | |
36 | + \brief 充電中か | |
46 | 37 | |
47 | - \return バッテリー充電率 [%] | |
48 | - */ | |
49 | - size_t remainingPercent(void) const; | |
38 | + \retval true 充電中 | |
39 | + \retval false 放電中 | |
40 | + */ | |
41 | + bool isCharging(void) const; | |
50 | 42 | |
51 | 43 | |
52 | - /*! | |
53 | - \brief バッテリーの推定残り時間 | |
54 | - | |
55 | - \return バッテリーの推定残り時間 [sec] | |
56 | - */ | |
57 | - size_t remainingSecond(void) const; | |
44 | + /*! | |
45 | + \brief 充電済みか | |
58 | 46 | |
59 | - private: | |
60 | - BatteryState(const BatteryState& rhs); | |
61 | - BatteryState& operator = (const BatteryState& rhs); | |
47 | + \retval true 充電済み | |
48 | + \retval false 放電済み | |
49 | + */ | |
50 | + bool isCharged(void) const; | |
62 | 51 | |
63 | - struct pImpl; | |
64 | - std::auto_ptr<pImpl> pimpl; | |
65 | - }; | |
52 | + | |
53 | + /*! | |
54 | + \brief バッテリー充電率 | |
55 | + | |
56 | + \return バッテリー充電率 [%] | |
57 | + */ | |
58 | + size_t remainingPercent(void) const; | |
59 | + | |
60 | + | |
61 | + /*! | |
62 | + \brief バッテリーの推定残り時間 | |
63 | + | |
64 | + \return バッテリーの推定残り時間 [sec] | |
65 | + */ | |
66 | + size_t remainingSecond(void) const; | |
67 | + | |
68 | + private: | |
69 | + BatteryState(const BatteryState& rhs); | |
70 | + BatteryState& operator = (const BatteryState& rhs); | |
71 | + | |
72 | + struct pImpl; | |
73 | + std::auto_ptr<pImpl> pimpl; | |
74 | + }; | |
66 | 75 | } |
67 | 76 | |
68 | 77 | #endif /* !QRK_BATTERY_STATE_H */ |
@@ -12,9 +12,10 @@ | ||
12 | 12 | |
13 | 13 | //! 充電状態の定義 |
14 | 14 | typedef enum { |
15 | - Unknown, //!< 対象外のシステム | |
16 | - Charging, //!< 充電中 | |
17 | - Discharging, //!< バッテリ駆動中 | |
15 | + Unknown, //!< 対象外のシステム | |
16 | + Charged, //!< 充電済み | |
17 | + Charging, //!< 充電中 | |
18 | + Discharging, //!< バッテリ駆動中 | |
18 | 19 | } ChargingState; |
19 | 20 | |
20 | 21 | #endif /* !CHARGING_STATE_H */ |
@@ -15,27 +15,28 @@ | ||
15 | 15 | |
16 | 16 | struct DrawCharacter::pImpl |
17 | 17 | { |
18 | - QString previous_base_name_; | |
19 | - QPixmap bar_pixmap_; | |
18 | + QString previous_base_name_; | |
19 | + QPixmap bar_pixmap_; | |
20 | 20 | |
21 | 21 | |
22 | - QString baseName(character_t& character, ChargingState state) | |
23 | - { | |
24 | - switch (state) { | |
25 | - case Charging: | |
26 | - return character.picture_charging; | |
27 | - break; | |
22 | + QString baseName(character_t& character, ChargingState state) | |
23 | + { | |
24 | + switch (state) { | |
25 | + case Charging: | |
26 | + case Charged: | |
27 | + return character.picture_charging; | |
28 | + break; | |
28 | 29 | |
29 | - case Discharging: | |
30 | - return character.picture_discharging; | |
31 | - break; | |
30 | + case Discharging: | |
31 | + return character.picture_discharging; | |
32 | + break; | |
32 | 33 | |
33 | - default: | |
34 | - case Unknown: | |
35 | - return character.picture_unknown; | |
36 | - break; | |
34 | + default: | |
35 | + case Unknown: | |
36 | + return character.picture_unknown; | |
37 | + break; | |
38 | + } | |
37 | 39 | } |
38 | - } | |
39 | 40 | }; |
40 | 41 | |
41 | 42 |
@@ -54,36 +55,36 @@ | ||
54 | 55 | character_t& character, |
55 | 56 | ChargingState state, size_t percent) |
56 | 57 | { |
57 | - QString base_name = pimpl->baseName(character, state); | |
58 | - | |
59 | - // ベース画像の描画 | |
60 | - QPixmap base_pixmap(base_name); | |
61 | - painter.drawPixmap(QPoint(0, 0), base_pixmap); | |
62 | - base_rect = base_pixmap.rect(); | |
63 | - | |
64 | - // 前回の描画画像と異なっていたら、背景の透過設定を更新する | |
65 | - bool update_background = false; | |
66 | - if (pimpl->previous_base_name_.compare(base_name)) { | |
67 | - region = base_pixmap.mask(); | |
68 | - update_background = true; | |
69 | - } | |
58 | + QString base_name = pimpl->baseName(character, state); | |
70 | 59 | |
71 | - // システム情報が不定でなければ、バッテリーの充電率を表示する | |
72 | - if (state != Unknown) { | |
60 | + // ベース画像の描画 | |
61 | + QPixmap base_pixmap(base_name); | |
62 | + painter.drawPixmap(QPoint(0, 0), base_pixmap); | |
63 | + base_rect = base_pixmap.rect(); | |
73 | 64 | |
74 | - // バッテリー充電率を描画 | |
75 | - if (pimpl->bar_pixmap_.isNull()) { | |
76 | - pimpl->bar_pixmap_.load(character.percent_bar); | |
65 | + // 前回の描画画像と異なっていたら、背景の透過設定を更新する | |
66 | + bool update_background = false; | |
67 | + if (pimpl->previous_base_name_.compare(base_name)) { | |
68 | + region = base_pixmap.mask(); | |
69 | + update_background = true; | |
77 | 70 | } |
78 | - QRect bar_rect(character.bar_position.x(), | |
79 | - character.bar_position.y(), | |
80 | - pimpl->bar_pixmap_.width(), | |
81 | - pimpl->bar_pixmap_.height()); | |
82 | - size_t offset = bar_rect.height() * (100 - percent) / 100; | |
83 | - bar_rect.setY(bar_rect.y() + offset); | |
84 | - painter.drawPixmap(bar_rect, pimpl->bar_pixmap_); | |
85 | - } | |
86 | 71 | |
87 | - pimpl->previous_base_name_ = base_name; | |
88 | - return update_background; | |
72 | + // システム情報が不定でなければ、バッテリーの充電率を表示する | |
73 | + if (state != Unknown) { | |
74 | + | |
75 | + // バッテリー充電率を描画 | |
76 | + if (pimpl->bar_pixmap_.isNull()) { | |
77 | + pimpl->bar_pixmap_.load(character.percent_bar); | |
78 | + } | |
79 | + QRect bar_rect(character.bar_position.x(), | |
80 | + character.bar_position.y(), | |
81 | + pimpl->bar_pixmap_.width(), | |
82 | + pimpl->bar_pixmap_.height()); | |
83 | + size_t offset = bar_rect.height() * (100 - percent) / 100; | |
84 | + bar_rect.setY(bar_rect.y() + offset); | |
85 | + painter.drawPixmap(bar_rect, pimpl->bar_pixmap_); | |
86 | + } | |
87 | + | |
88 | + pimpl->previous_base_name_ = base_name; | |
89 | + return update_background; | |
89 | 90 | } |
@@ -23,19 +23,19 @@ | ||
23 | 23 | class DrawCharacter |
24 | 24 | { |
25 | 25 | public: |
26 | - DrawCharacter(void); | |
27 | - ~DrawCharacter(void); | |
26 | + DrawCharacter(void); | |
27 | + ~DrawCharacter(void); | |
28 | 28 | |
29 | - //! 描画 | |
30 | - bool draw(QPainter& painter, QRect& base_rect, QRegion& region, | |
31 | - character_t& character, ChargingState state, size_t percent); | |
29 | + //! 描画 | |
30 | + bool draw(QPainter& painter, QRect& base_rect, QRegion& region, | |
31 | + character_t& character, ChargingState state, size_t percent); | |
32 | 32 | |
33 | 33 | private: |
34 | - DrawCharacter(const DrawCharacter& rhs); | |
35 | - DrawCharacter& operator = (const DrawCharacter& rhs); | |
34 | + DrawCharacter(const DrawCharacter& rhs); | |
35 | + DrawCharacter& operator = (const DrawCharacter& rhs); | |
36 | 36 | |
37 | - struct pImpl; | |
38 | - std::auto_ptr<pImpl> pimpl; | |
37 | + struct pImpl; | |
38 | + std::auto_ptr<pImpl> pimpl; | |
39 | 39 | }; |
40 | 40 | |
41 | 41 | #endif /* !DRAW_CHARACTER_H */ |
@@ -17,13 +17,13 @@ | ||
17 | 17 | //! キャラクター情報の管理 |
18 | 18 | typedef struct |
19 | 19 | { |
20 | - QString name; //!< 表示名 | |
20 | + QString name; //!< 表示名 | |
21 | 21 | |
22 | - QString picture_unknown; //!< システム情報が取得できないときの画像 | |
23 | - QString picture_charging; //!< 充電中の画像 | |
24 | - QString picture_discharging; //!< 充電していないときの画像 | |
25 | - QString percent_bar; //!< 充電率を表示するためのバー | |
26 | - QPoint bar_position; //!< バーの表示位置 | |
22 | + QString picture_unknown; //!< システム情報が取得できないときの画像 | |
23 | + QString picture_charging; //!< 充電中の画像 | |
24 | + QString picture_discharging; //!< 充電していないときの画像 | |
25 | + QString percent_bar; //!< 充電率を表示するためのバー | |
26 | + QPoint bar_position; //!< バーの表示位置 | |
27 | 27 | } character_t; |
28 | 28 | |
29 | 29 | #endif /* !CHARACTER_T_H */ |
@@ -22,86 +22,87 @@ | ||
22 | 22 | |
23 | 23 | namespace |
24 | 24 | { |
25 | - class ArgsInformation | |
26 | - { | |
27 | - public: | |
28 | - bool geometry_specified; | |
29 | - | |
30 | - | |
31 | - ArgsInformation(void) | |
32 | - : geometry_specified(false) | |
25 | + class ArgsInformation | |
33 | 26 | { |
34 | - } | |
35 | - }; | |
27 | + public: | |
28 | + bool geometry_specified; | |
36 | 29 | |
37 | 30 | |
38 | - void printHelp(const char* program_name) | |
39 | - { | |
40 | - const QString message = | |
41 | - QString("usage:\n" | |
42 | - "\t%1 [options]\n" | |
43 | - "\n" | |
44 | - "options\n" | |
45 | - " --help, -h print this message.\n" | |
46 | - " --version, -v output version infromation.\n" | |
47 | - " --geometry <position> Place to <position>.\n" | |
48 | - "\n" | |
49 | - "Report bugs to <satofumi@users.sourceforge.jp>.") | |
50 | - .arg(program_name); | |
51 | - | |
52 | - cout << message.toStdString() << endl; | |
53 | - } | |
31 | + ArgsInformation(void) | |
32 | + : geometry_specified(false) | |
33 | + { | |
34 | + } | |
35 | + }; | |
54 | 36 | |
55 | 37 | |
56 | - void printVersion(void) | |
57 | - { | |
58 | - cout << "qlm_batmon " << VersionString << endl; | |
59 | - } | |
38 | + void printHelp(const char* program_name) | |
39 | + { | |
40 | + const QString message = | |
41 | + QString("usage:\n" | |
42 | + "\t%1 [options]\n" | |
43 | + "\n" | |
44 | + "options\n" | |
45 | + " --help, -h print this message.\n" | |
46 | + " --version, -v output version infromation.\n" | |
47 | + " --geometry <position> Place to <position>.\n" | |
48 | + "\n" | |
49 | + "Report bugs to <satofumi@users.sourceforge.jp>.") | |
50 | + .arg(program_name); | |
51 | + | |
52 | + cout << message.toStdString() << endl; | |
53 | + } | |
60 | 54 | |
61 | 55 | |
62 | - bool parseArgs(ArgsInformation& args, int argc, char *argv[]) | |
63 | - { | |
64 | - for (int i = 1; i < argc; ++i) { | |
65 | - char* token = argv[i]; | |
66 | - | |
67 | - if ((! strcmp(token, "-h") || (! strcmp(token, "--help")))) { | |
68 | - printHelp(argv[0]); | |
69 | - return false; | |
70 | - | |
71 | - } else if ((! strcmp(token, "-v") || (! strcmp(token, "--version")))) { | |
72 | - printVersion(); | |
73 | - return false; | |
74 | - | |
75 | - } else if ((! strcmp("--geometry", token)) || | |
76 | - (! strcmp("-geometry", token))) { | |
77 | - // 位置指定があれば、その位置に描画するようにする | |
78 | - args.geometry_specified = true; | |
79 | - } | |
56 | + void printVersion(void) | |
57 | + { | |
58 | + cout << "qlm_batmon " << VersionString << endl; | |
80 | 59 | } |
81 | 60 | |
82 | - return true; | |
83 | - } | |
61 | + | |
62 | + bool parseArgs(ArgsInformation& args, int argc, char *argv[]) | |
63 | + { | |
64 | + for (int i = 1; i < argc; ++i) { | |
65 | + char* token = argv[i]; | |
66 | + | |
67 | + if ((!strcmp(token, "-h") || (!strcmp(token, "--help")))) { | |
68 | + printHelp(argv[0]); | |
69 | + return false; | |
70 | + | |
71 | + } else if ((!strcmp(token, "-v") || | |
72 | + (!strcmp(token, "--version")))) { | |
73 | + printVersion(); | |
74 | + return false; | |
75 | + | |
76 | + } else if ((!strcmp("--geometry", token)) || | |
77 | + (!strcmp("-geometry", token))) { | |
78 | + // 位置指定があれば、その位置に描画するようにする | |
79 | + args.geometry_specified = true; | |
80 | + } | |
81 | + } | |
82 | + | |
83 | + return true; | |
84 | + } | |
84 | 85 | } |
85 | 86 | |
86 | 87 | |
87 | 88 | //! main |
88 | 89 | int main(int argc, char *argv[]) |
89 | 90 | { |
90 | - ArgsInformation args; | |
91 | - if (! parseArgs(args, argc, argv)) { | |
92 | - return 1; | |
93 | - } | |
94 | - | |
95 | - QApplication app(argc, argv); | |
91 | + ArgsInformation args; | |
92 | + if (!parseArgs(args, argc, argv)) { | |
93 | + return 1; | |
94 | + } | |
96 | 95 | |
97 | - // ロケールの適用 | |
98 | - QString locale = QLocale::system().name(); | |
99 | - QTranslator translator; | |
100 | - translator.load("qlm_batmon_" + locale); | |
101 | - app.installTranslator(&translator); | |
96 | + QApplication app(argc, argv); | |
102 | 97 | |
103 | - BatmonWidget widget(args.geometry_specified); | |
104 | - widget.show(); | |
98 | + // ロケールの適用 | |
99 | + QString locale = QLocale::system().name(); | |
100 | + QTranslator translator; | |
101 | + translator.load("qlm_batmon_" + locale); | |
102 | + app.installTranslator(&translator); | |
105 | 103 | |
106 | - return app.exec(); | |
104 | + BatmonWidget widget(args.geometry_specified); | |
105 | + widget.show(); | |
106 | + | |
107 | + return app.exec(); | |
107 | 108 | } |
@@ -7,7 +7,7 @@ | ||
7 | 7 | |
8 | 8 | TEMPLATE = app |
9 | 9 | TARGET = |
10 | -VERSION = -0.0.4 | |
10 | +VERSION = -0.0.5 | |
11 | 11 | DEPENDPATH += . |
12 | 12 | INCLUDEPATH += . |
13 | 13 |
@@ -4,47 +4,62 @@ | ||
4 | 4 | <context> |
5 | 5 | <name>BatmonWidget</name> |
6 | 6 | <message> |
7 | - <location filename="BatmonWidget.cpp" line="94"/> | |
7 | + <location filename="BatmonWidget.cpp" line="102"/> | |
8 | 8 | <source>girl</source> |
9 | 9 | <translation>女の子</translation> |
10 | 10 | </message> |
11 | 11 | <message> |
12 | - <location filename="BatmonWidget.cpp" line="104"/> | |
12 | + <location filename="BatmonWidget.cpp" line="112"/> | |
13 | 13 | <source>pengui</source> |
14 | 14 | <translation>りもペンギン</translation> |
15 | 15 | </message> |
16 | 16 | <message> |
17 | - <location filename="BatmonWidget.cpp" line="133"/> | |
17 | + <location filename="BatmonWidget.cpp" line="141"/> | |
18 | + <source>Show always</source> | |
19 | + <translation>常に表示する</translation> | |
20 | + </message> | |
21 | + <message> | |
22 | + <location filename="BatmonWidget.cpp" line="148"/> | |
18 | 23 | <source>Hide while charging</source> |
19 | 24 | <translation>充電中は表示しない</translation> |
20 | 25 | </message> |
21 | 26 | <message> |
22 | - <location filename="BatmonWidget.cpp" line="143"/> | |
27 | + <location filename="BatmonWidget.cpp" line="156"/> | |
28 | + <source>Hide while charged</source> | |
29 | + <translation>充電が完了したら隠す</translation> | |
30 | + </message> | |
31 | + <message> | |
32 | + <location filename="BatmonWidget.cpp" line="166"/> | |
23 | 33 | <source>Ctrl+Q</source> |
24 | 34 | <translation></translation> |
25 | 35 | </message> |
26 | 36 | <message> |
27 | - <location filename="BatmonWidget.cpp" line="155"/> | |
37 | + <location filename="BatmonWidget.cpp" line="178"/> | |
28 | 38 | <source>APM Battery Monitor</source> |
29 | 39 | <translation>APM ばってりーもにたー</translation> |
30 | 40 | </message> |
31 | 41 | <message> |
32 | - <location filename="BatmonWidget.cpp" line="278"/> | |
42 | + <location filename="BatmonWidget.cpp" line="326"/> | |
33 | 43 | <source>charging: %1 [%]</source> |
34 | 44 | <translation>充電中: %1 [%]</translation> |
35 | 45 | </message> |
36 | 46 | <message> |
37 | - <location filename="BatmonWidget.cpp" line="283"/> | |
47 | + <location filename="BatmonWidget.cpp" line="330"/> | |
48 | + <source>charged</source> | |
49 | + <translation>充電済み</translation> | |
50 | + </message> | |
51 | + <message> | |
52 | + <location filename="BatmonWidget.cpp" line="335"/> | |
38 | 53 | <source>remaining: %1 [%]</source> |
39 | 54 | <translation>容量: %1 [%]</translation> |
40 | 55 | </message> |
41 | 56 | <message> |
42 | - <location filename="BatmonWidget.cpp" line="285"/> | |
57 | + <location filename="BatmonWidget.cpp" line="337"/> | |
43 | 58 | <source>remaining: %1 [h] (%2 [%])</source> |
44 | 59 | <translation>残り: %1 [h] (%2 [%])</translation> |
45 | 60 | </message> |
46 | 61 | <message> |
47 | - <location filename="BatmonWidget.cpp" line="291"/> | |
62 | + <location filename="BatmonWidget.cpp" line="344"/> | |
48 | 63 | <source>unknown system</source> |
49 | 64 | <translation>不明なシステム</translation> |
50 | 65 | </message> |
@@ -52,7 +67,7 @@ | ||
52 | 67 | <context> |
53 | 68 | <name>QAction</name> |
54 | 69 | <message> |
55 | - <location filename="BatmonWidget.cpp" line="142"/> | |
70 | + <location filename="BatmonWidget.cpp" line="165"/> | |
56 | 71 | <source>Quit</source> |
57 | 72 | <translation>終了</translation> |
58 | 73 | </message> |
@@ -19,24 +19,24 @@ | ||
19 | 19 | const std::string& line, const char* split_pattern, |
20 | 20 | bool continious_pattern) |
21 | 21 | { |
22 | - string buffer = line; | |
23 | - char* q = &buffer[0]; | |
24 | - size_t n = line.size(); | |
25 | - for (size_t i = 0; i < n; ++i, ++q) { | |
26 | - for (const char* p = split_pattern; *p != '\0'; ++p) { | |
27 | - if (*q == *p) { | |
28 | - *q = '\0'; | |
29 | - break; | |
30 | - } | |
22 | + string buffer = line; | |
23 | + char* q = &buffer[0]; | |
24 | + size_t n = line.size(); | |
25 | + for (size_t i = 0; i < n; ++i, ++q) { | |
26 | + for (const char* p = split_pattern; *p != '\0'; ++p) { | |
27 | + if (*q == *p) { | |
28 | + *q = '\0'; | |
29 | + break; | |
30 | + } | |
31 | + } | |
31 | 32 | } |
32 | - } | |
33 | 33 | |
34 | - for (size_t i = 0; i < n; ++i) { | |
35 | - if ((buffer[i] != '\0') || (! continious_pattern)) { | |
36 | - string line = &buffer[i]; | |
37 | - tokens.push_back(line); | |
38 | - i += line.size(); | |
34 | + for (size_t i = 0; i < n; ++i) { | |
35 | + if ((buffer[i] != '\0') || (! continious_pattern)) { | |
36 | + string line = &buffer[i]; | |
37 | + tokens.push_back(line); | |
38 | + i += line.size(); | |
39 | + } | |
39 | 40 | } |
40 | - } | |
41 | - return tokens.size(); | |
41 | + return tokens.size(); | |
42 | 42 | } |
@@ -16,19 +16,19 @@ | ||
16 | 16 | |
17 | 17 | namespace qrk |
18 | 18 | { |
19 | - /*! | |
20 | - \brief 指定文字による分割 | |
19 | + /*! | |
20 | + \brief 指定文字による分割 | |
21 | 21 | |
22 | - \param[out] tokens 分割後の文字列 | |
23 | - \param[in] original 分割対象の文字列 | |
24 | - \param[in] split_pattern 分割を行う文字の列 | |
25 | - \param[in] continious_pattern 連続したセパレータを1つのセパレータとして扱う | |
22 | + \param[out] tokens 分割後の文字列 | |
23 | + \param[in] original 分割対象の文字列 | |
24 | + \param[in] split_pattern 分割を行う文字の列 | |
25 | + \param[in] continious_pattern 連続したセパレータを1つのセパレータとして扱う | |
26 | 26 | |
27 | - \return 分割後のトークン数 | |
28 | - */ | |
29 | - size_t split(std::vector<std::string>& tokens, | |
30 | - const std::string& original, const char* split_pattern = " \t", | |
31 | - bool continious_pattern = true); | |
27 | + \return 分割後のトークン数 | |
28 | + */ | |
29 | + size_t split(std::vector<std::string>& tokens, | |
30 | + const std::string& original, const char* split_pattern = " \t", | |
31 | + bool continious_pattern = true); | |
32 | 32 | } |
33 | 33 | |
34 | 34 | #endif /* !QRK_SPLIT_H */ |