LunaSysMgr
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
StatusBarClock.h
Go to the documentation of this file.
1 /* @@@LICENSE
2 *
3 * Copyright (c) 2010-2013 Hewlett-Packard Development Company, L.P.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 * LICENSE@@@ */
18 
19 
20 
21 
22 #ifndef STATUSBARCLOCK_H
23 #define STATUSBARCLOCK_H
24 
25 #include "StatusBarItem.h"
26 #include <QGraphicsObject>
27 #include <QTextLayout>
28 
30 {
31  Q_OBJECT
32 
33 public:
34 
35  StatusBarClock(unsigned int padding = 0);
36  virtual ~StatusBarClock();
37 
38  QRectF boundingRect() const;
39  void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget);
40 
41  void updateTimeFormat(const char* format);
42 
43  void setDisplayDate(bool date);
44 
45  int width() const { return m_bounds.width(); }
46  int height() const { return m_bounds.height(); }
47 
48  void setPadding( unsigned int padding);
49 
50 private Q_SLOTS:
51  void tick();
52  void slotSystemTimeChanged();
53 
54 private:
55  static const int kMaxTimeChars = 10;
56 
57  void setTimeText(const char *time, bool doUpdate = true);
58  void setTimeText(const QString& time, bool doUpdate = true);
59 
60  QString m_timeText;
61  QRectF m_textRect;
62  QFont* m_font;
63 #if defined TARGET_DESKTOP && (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
64  QPixmap m_textPixmap;
65 #endif
66 
67  bool m_twelveHour;
68  bool m_displayDate;
69  char m_timeBuf[kMaxTimeChars];
70  char* m_curTimeStr;
71  unsigned int m_textPadding;
72 
73  struct {
74  int year;
75  int month;
76  int day;
77  int hour;
78  int min;
79  } m_lastUpdateTime;
80 
81  // TODO: use QBasicTimer instead? (may be more lightweight)
82  QTimer *m_clockTimer;
83 };
84 
85 
86 
87 #endif /* STATUSBARCLOCK_H */