Diffstat (limited to 'noncore/applets/autorotateapplet/autorotate.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/applets/autorotateapplet/autorotate.cpp | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/noncore/applets/autorotateapplet/autorotate.cpp b/noncore/applets/autorotateapplet/autorotate.cpp new file mode 100644 index 0000000..4733860 --- a/dev/null +++ b/noncore/applets/autorotateapplet/autorotate.cpp | |||
@@ -0,0 +1,110 @@ | |||
1 | /* | ||
2 | * copyright : (c) 2003 by Greg Gilbert | ||
3 | * email : greg@treke.net | ||
4 | * based on the cardmon applet by Max Reiss | ||
5 | * * | ||
6 | * This program is free software; you can redistribute it and/or modify * | ||
7 | * it under the terms of the GNU General Public License as published by * | ||
8 | * the Free Software Foundation; either version 2 of the License, or * | ||
9 | * (at your option) any later version. * | ||
10 | * * | ||
11 | *************************************************************************/ | ||
12 | |||
13 | |||
14 | #include "autorotate.h" | ||
15 | |||
16 | #include <qpe/resource.h> | ||
17 | |||
18 | #include <opie/odevice.h> | ||
19 | |||
20 | #include <qpe/applnk.h> | ||
21 | #include <qpe/config.h> | ||
22 | |||
23 | #include <qcopchannel_qws.h> | ||
24 | #include <qpainter.h> | ||
25 | #include <qmessagebox.h> | ||
26 | #include <qfile.h> | ||
27 | #include <qtextstream.h> | ||
28 | #include <qtimer.h> | ||
29 | #include <qapplication.h> | ||
30 | |||
31 | using namespace Opie; | ||
32 | |||
33 | AutoRotate::AutoRotate(QWidget * parent):QWidget(parent), | ||
34 | enabledPm( Resource::loadPixmap("autorotate/rotate") ), | ||
35 | disabledPm( Resource::loadPixmap("autorotate/norotate") ) | ||
36 | { | ||
37 | setFixedWidth ( AppLnk::smallIconSize() ); | ||
38 | setFixedHeight ( AppLnk::smallIconSize() ); | ||
39 | |||
40 | repaint(true); | ||
41 | popupMenu = 0; | ||
42 | show(); | ||
43 | } | ||
44 | |||
45 | AutoRotate::~AutoRotate() | ||
46 | { | ||
47 | if (popupMenu) { | ||
48 | delete popupMenu; | ||
49 | } | ||
50 | } | ||
51 | |||
52 | void AutoRotate::mousePressEvent(QMouseEvent *) | ||
53 | { | ||
54 | QPopupMenu *menu = new QPopupMenu(this); | ||
55 | |||
56 | if (isRotateEnabled()) | ||
57 | menu->insertItem("Disable Rotation",1); | ||
58 | else | ||
59 | menu->insertItem("Enable Rotation",1); | ||
60 | |||
61 | |||
62 | QPoint p = mapToGlobal(QPoint(0, 0)); | ||
63 | QSize s = menu->sizeHint(); | ||
64 | int opt = menu->exec(QPoint(p.x() + (width() / 2) - (s.width() / 2), | ||
65 | p.y() - s.height()), 0); | ||
66 | |||
67 | if (opt==1) { | ||
68 | if (isRotateEnabled()) | ||
69 | setRotateEnabled(false); | ||
70 | else | ||
71 | setRotateEnabled(true); | ||
72 | |||
73 | repaint(true); | ||
74 | } | ||
75 | |||
76 | delete menu; | ||
77 | } | ||
78 | |||
79 | void AutoRotate::paintEvent(QPaintEvent *) | ||
80 | { | ||
81 | QPainter p(this); | ||
82 | |||
83 | if ( isRotateEnabled() ) { | ||
84 | p.drawPixmap(0, 0, enabledPm ); | ||
85 | } else { | ||
86 | p.drawPixmap(0, 0, disabledPm ); | ||
87 | } | ||
88 | } | ||
89 | |||
90 | void AutoRotate::setRotateEnabled(bool status) | ||
91 | { | ||
92 | Config cfg( "qpe" ); | ||
93 | cfg.setGroup( "Appearance" ); | ||
94 | cfg.writeEntry( "rotateEnabled",status ); | ||
95 | |||
96 | } | ||
97 | bool AutoRotate::isRotateEnabled() | ||
98 | { | ||
99 | Config cfg( "qpe" ); | ||
100 | cfg.setGroup( "Appearance" ); | ||
101 | |||
102 | bool res = cfg.readBoolEntry( "rotateEnabled" ); | ||
103 | |||
104 | if (res ) | ||
105 | qDebug("Enabled"); | ||
106 | else | ||
107 | qDebug("Disabled"); | ||
108 | return res; | ||
109 | } | ||
110 | |||